diff --git a/server/api-test/user/signup.rb b/server/api-test/user/signup.rb deleted file mode 100644 index 5be05330..00000000 --- a/server/api-test/user/signup.rb +++ /dev/null @@ -1,12 +0,0 @@ -describe '/user/signup' do - it 'should create user in database' do - response = request('/user/signup', { - 'email' => 'steve@jobs.com', - 'password' => 'custom' - }) - - userRow = $database.getRow('users', response['data']['userId']) - - (userRow['email']).should.equal('steve@jobs.com') - end -end diff --git a/server/controllers/user/signup.php b/server/controllers/user/signup.php index 2a143e3b..a38559d3 100644 --- a/server/controllers/user/signup.php +++ b/server/controllers/user/signup.php @@ -19,7 +19,7 @@ class SignUpController extends Controller { $userInstance = new User(); $userInstance->setProperties(array( 'email' => $email, - 'password' => User::hashPassword($password) + 'password' => Hashing::hashPassword($password) )); return $userInstance->store(); diff --git a/server/database.sh b/server/database.sh deleted file mode 100755 index 08a1bcae..00000000 --- a/server/database.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash - -# DELETE ALL TABLES -TABLES=$(mysql -u os_dev -pos_dev os_dev -e "SHOW TABLES IN os_dev;" | awk '{ print $1}' | grep -v '^Tables') - -for t in $TABLES -do - mysql -u os_dev -pos_dev os_dev -e "DROP TABLE $t" -done diff --git a/server/index.php b/server/index.php index ba5ea782..d4617e88 100644 --- a/server/index.php +++ b/server/index.php @@ -10,6 +10,11 @@ RedBean::setup('mysql:host='. $mysql_host .';dbname=' . $mysql_database, $mysql_ \Slim\Slim::registerAutoLoader(); $app = new \Slim\Slim(); +// LOAD LIBRARIES +include_once 'libs/Controller.php'; +include_once 'libs/ControllerGroup.php'; +include_once 'libs/Hashing.php'; + // LOAD MODELS spl_autoload_register(function ($class) { $classPath = "models/{$class}.php"; @@ -20,9 +25,6 @@ spl_autoload_register(function ($class) { }); // LOAD CONTROLLERS -include_once 'libs/Controller.php'; -include_once 'libs/ControllerGroup.php'; - foreach (glob('controllers/*.php') as $controller) { include $controller; } diff --git a/server/libs/FileUploader.php b/server/libs/FileUploader.php new file mode 100644 index 00000000..55eb9bbc --- /dev/null +++ b/server/libs/FileUploader.php @@ -0,0 +1,18 @@ +_bean = RedBean::dispense(static::TABLE); - $defaultProperties = $this->getDefaultProperties(); + $defaultProperties = $this->getDefaultProps(); foreach ($defaultProperties as $PROP => $VALUE) { $this->_bean[$PROP] = $VALUE; @@ -29,15 +29,9 @@ abstract class DataStore { } } - protected static function deleteDataStore($dataStore) { - if ($dataStore instanceof DataStore) { - RedBean::trash($dataStore->getBeanInstance()); - unset($dataStore); - return true; - } - else { - return false; - } + public function delete() { + RedBean::trash($this->getBeanInstance()); + unset($this); } public function getBeanInstance() { diff --git a/server/models/Ticket.php b/server/models/Ticket.php new file mode 100644 index 00000000..f1bbe75a --- /dev/null +++ b/server/models/Ticket.php @@ -0,0 +1,26 @@ +password)) ? $user : null; + return ($user && Hashing::verifyPassword($userPassword, $user->password)) ? $user : null; } public static function getProps() { return array( 'email', - 'password' + 'password', + 'name', + 'verificationToken', + 'ownTickets' ); } - public function getDefaultProperties() { - return array(); + public function getDefaultProps() { + return array( + 'ownTickets' => [] + ); + } + + public function addTicket($ticket) { + $this->ownTickets[] = $ticket; } public static function getUser($value, $property = 'id') { return parent::getDataStore($value, $property); } - - public static function deleteUser($user) { - parent::deleteDataStore($user); - } - - public function showUserDetails() { - return $this->_user; - } } diff --git a/server/tests/models/DataStoreTest.php b/server/tests/models/DataStoreTest.php index 07c02de7..ebccd886 100644 --- a/server/tests/models/DataStoreTest.php +++ b/server/tests/models/DataStoreTest.php @@ -17,16 +17,12 @@ class DataStoreMock extends DataStore { ); } - public function getDefaultProperties() { + public function getDefaultProps() { return array( 'prop1' => 0, 'prop2' => 'hello' ); } - - public static function deleteDataStore($dataStore) { - return parent::deleteDataStore($dataStore); - } } class DataStoreTest extends PHPUnit_Framework_TestCase { @@ -78,9 +74,8 @@ class DataStoreTest extends PHPUnit_Framework_TestCase { } public function testDeleteDataStore() { - $beanInstance = $this->instance->getBeanInstance(); - DataStoreMock::deleteDataStore($this->instance); + $this->instance->delete(); - $this->assertTrue(RedBean::get('trash')->hasBeenCalledWithArgs($beanInstance)); + $this->assertTrue(RedBean::get('trash')->hasBeenCalledWithArgs($this->instance->getBeanInstance())); } } diff --git a/server/api-test/Gemfile b/tests/Gemfile similarity index 100% rename from server/api-test/Gemfile rename to tests/Gemfile diff --git a/tests/clean_db.sh b/tests/clean_db.sh new file mode 100755 index 00000000..e0b432ae --- /dev/null +++ b/tests/clean_db.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +# DELETE ALL TABLES +TABLES=$(mysql -u root development -e "SHOW TABLES IN os_dev;" | awk '{ print $1}' | grep -v '^Tables') + +for t in $TABLES +do + mysql -u root development -e "DROP TABLE $t" +done diff --git a/server/api-test/run-test.rb b/tests/init.rb similarity index 86% rename from server/api-test/run-test.rb rename to tests/init.rb index d54a219f..f09d7691 100644 --- a/server/api-test/run-test.rb +++ b/tests/init.rb @@ -5,6 +5,7 @@ require 'uri' require 'mysql' require 'json' require './libs.rb' +require './scripts.rb' # TESTS require './user/signup.rb' diff --git a/server/api-test/libs.rb b/tests/libs.rb similarity index 100% rename from server/api-test/libs.rb rename to tests/libs.rb diff --git a/tests/run-tests.sh b/tests/run-tests.sh new file mode 100755 index 00000000..e87ac4ca --- /dev/null +++ b/tests/run-tests.sh @@ -0,0 +1,2 @@ +./clean_db.sh +bacon init.rb \ No newline at end of file diff --git a/server/api-test/scripts.rb b/tests/scripts.rb similarity index 96% rename from server/api-test/scripts.rb rename to tests/scripts.rb index e7dccfb1..52956341 100644 --- a/server/api-test/scripts.rb +++ b/tests/scripts.rb @@ -7,5 +7,6 @@ class Scripts if response['status'] === 'fail' raise "Could not create user" + end end end diff --git a/server/api-test/user/login.rb b/tests/user/login.rb similarity index 99% rename from server/api-test/user/login.rb rename to tests/user/login.rb index 61bb33ac..398e90c5 100644 --- a/server/api-test/user/login.rb +++ b/tests/user/login.rb @@ -22,3 +22,4 @@ describe '/user/login' do it 'should fail if already logged in' do end +end \ No newline at end of file diff --git a/tests/user/signup.rb b/tests/user/signup.rb new file mode 100644 index 00000000..51c3885f --- /dev/null +++ b/tests/user/signup.rb @@ -0,0 +1,12 @@ +describe '/user/signup' do + it 'should create user in database' do + response = request('/user/signup', { + 'email' => 'steve@jobs.com', + 'password' => 'custom' + }) + + userRow = $database.getRow('users', response['data']['userId']) + + (userRow['email']).should.equal('steve@jobs.com') + end +end