/** * @param User $user * @return mixed */ public function add(User $user) { $userID = $user->getUserID(); $userName = $user->getUserName(); $userPassword = $user->getPassword(); $userFirst = $user->getFirstName(); $userLast = $user->getLastName(); $userEmail = $user->getEmail(); $query = "INSERT INTO USERS(UserID, UserName, UserPassword, UserFirst, UserLast, UserEmail) VALUES('{$userID}', '{$userName}', '{$userPassword}', '{$userFirst}', '{$userLast}', '{$userEmail}') "; mysql_query($query) or die("Database access failed: " . mysql_error()); }
$user->setPassword($invalidPass); } catch (exception $e) { $exception = $e; } expect($exception)->to->be->instanceof('\\InvalidArgumentException'); }); }); // tests set and get password describe('->getEmail()', function () { it('should return the users email address', function () { $faker = \Faker\Factory::create(); $email = $faker->freeEmail; $user = new User(); $user->setEmail($email); // setPassword would likely only be used for empty user objects made by an admin or to reset a password expect($user->getEmail())->equal($email); }); }); // tests email validation describe('->setEmail()', function () { it('should throw an invalid argument exception', function () { $invalidEmail = "IAmNotGivingMyEmailToAMachine"; $user = new User(); $exception = null; try { $user->setEmail($invalidEmail); } catch (exception $e) { $exception = $e; } expect($exception)->to->be->instanceof('\\InvalidArgumentException'); });
$actual = new Owner(); $userKey = new Uuid(); $username = "******"; $password = "******"; $email = "*****@*****.**"; $firstName = "Gary"; $lastName = "Grice"; $user1 = new User($userKey, $username, $password, $email, $firstName, $lastName); $user1Key = $user1->getUserID(); $actual->addUser($user1); expect($actual->getUser($user1Key))->equal($user1); $passwordU = "OldDannyBrown12\$"; $emailU = "*****@*****.**"; $updatedUser1 = new User($userKey, $username, $passwordU, $emailU, $firstName, $lastName); $actual->updateUser($user1Key, '', '', $passwordU, $emailU, ''); expect($actual->getUser($user1Key)->getEmail())->equal($updatedUser1->getEmail()); }); }); /* describe('->setCanManipulateNotes()', function(){ it('determines whether or not a group can create/edit notes if a user is added to the banned owner group then they cant create or edit notes', function() { $actual = new Owner(); $actual->setName("banned"); $actual->setCanManipulateNotes(false); expect($actual->canManipulateNotes())->to->be->false;
$userName = new StringLiteral($faker->userName); $user = new User($uuid, $userName); $actual = $user->getUsername(); expect($actual)->to->be->instanceof('Notes\\Domain\\ValueObject\\StringLiteral'); expect($actual->__toString())->equal($userName->__toString()); }); }); describe('->get/setEmail()', function () { it('should set & get the correct email', function () { $faker = \Faker\Factory::create(); $uuid = new Uuid(); $userName = new StringLiteral($faker->userName); $user = new User($uuid, $userName); $email = new StringLiteral($faker->email); $user->setEmail($email); $actual = $user->getEmail(); expect($actual)->to->be->instanceof('Notes\\Domain\\ValueObject\\StringLiteral'); expect($actual->__toString())->equal($email->__toString()); }); }); describe('->get/setFirstName()', function () { it('should get/set the user\' first name', function () { $faker = \Faker\Factory::create(); $uuid = new Uuid(); $userName = new StringLiteral($faker->userName); $user = new User($uuid, $userName); $firstName = new StringLiteral($faker->firstName); $user->setFirstName($firstName); $actual = $user->getFirstName(); expect($actual)->to->be->instanceof('Notes\\Domain\\ValueObject\\StringLiteral'); expect($actual->__toString())->equal($firstName->__toString());