public function removeById(Uuid $id)
 {
     foreach ($this->users as $i => $user) {
         /** @var \Notes\Domain\Entity\User $user*/
         if ($user->getId()->__toString() === $id->__toString()) {
             unset($this->users[$i]);
             return true;
         }
     }
     return false;
 }
 * Time: 11:29 PM
 */
use Notes\Domain\Entity\UserGroup\Admin;
use Notes\Domain\ValueObject\Uuid;
use Notes\Domain\Entity\User;
use Notes\Domain\ValueObject\StringLiteral;
use Notes\Domain\Entity\Roles\AdminRole;
describe('Notes\\Domain\\Entity\\Roles\\AdminRole', function () {
    describe('->__construct()', function () {
        it('should return a Admin object', function () {
            $actual = new AdminRole();
            expect($actual)->to->be->instanceof('Notes\\Domain\\Entity\\Roles\\AdminRole');
        });
    });
    // this tests what exists of this class atm im not sure if i will  have to add the other methods to it later or if im on the right track
    describe('->__construct(params)', function () {
        it('should return a AdminRole object', function () {
            $roleID = new Uuid();
            $name = "Full admins";
            $createPermission = true;
            $deletePermission = true;
            $permissions = array("Can Create" => $createPermission, "Can Delete" => $deletePermission);
            $actual = new AdminRole($roleID, $name, $createPermission, $deletePermission);
            expect($actual)->to->be->instanceof('Notes\\Domain\\Entity\\Roles\\AdminRole');
            expect($actual->getID())->equal($roleID->__toString());
            expect($actual->getPermissions())->equal($permissions);
            expect($actual->getName())->equal($name);
        });
    });
});
// end tests
Beispiel #3
0
 */
use Notes\Domain\Entity\User;
use Notes\Domain\ValueObject\StringLiteral;
use Notes\Domain\ValueObject\Uuid;
describe('Notes\\Domain\\Entity\\User', function () {
    describe('->__construct()', function () {
        it('should return a User object', function () {
            $actual = new User(new Uuid());
            expect($actual)->to->be->instanceof('\\Notes\\Domain\\Entity\\User');
        });
    });
    describe('->getId()', function () {
        it('should return the user\'s username', function () {
            $uuid = new Uuid();
            expect($uuid->isValidV4())->to->be->true();
            $user = new User($uuid);
            $actual = $user->getId();
            expect($actual)->to->be->instanceof('\\Notes\\Domain\\ValueObject\\Uuid');
            expect($actual->__toString())->equal($uuid->__toString());
        });
    });
    describe('->get/setUsername', function () {
        it('should get/set the correct the user\'s username', function () {
            $user = new User(new Uuid());
            $user->setUsername(new StringLiteral('Joe'));
            $actual = $user->getUsername();
            expect($actual)->to->be->instanceof('\\Notes\\Domain\\ValueObject\\StringLiteral');
            expect($actual->__toString())->equal('Joe');
        });
    });
});
Beispiel #4
0
<?php

use Notes\Domain\ValueObject\Uuid;
describe('ValueObject\\Uuid', function () {
    describe('->__construct()', function () {
        it('should return a Uuid object', function () {
            $actual = new Uuid();
            expect($actual)->to->be->instanceof('Notes\\Domain\\ValueObject\\Uuid');
        });
    });
    describe('->__toString()', function () {
        it('should return a valid V4 UUID identifier', function () {
            $actual = new Uuid();
            $uuid = $actual->__toString();
            expect(is_string($uuid))->true();
            expect(preg_match('/[a-f0-9]{8}\\-[a-f0-9]{4}\\-4[a-f0-9]{3}\\-(8|9|a|b)[a-f0-9]{3}\\-[a-f0-9]{12}/', $uuid))->equal(1);
        });
    });
});
         $lastName5 = "Kelly";
         $user2 = new User(new Uuid(), $username1, $password2, $email3, $firstName4, $lastName5);
         $user1Key = $user1->getUserID();
         $user2Key = $user2->getUserID();
         $initialUsers = array($user1Key => $user1, $user2Key => $user2);
         $groupName = "cs3620";
         $actual = new owner($groupID, $groupName, $initialUsers);
         // create new owner group with name cs3620 and add an array with 2 users as initial users
         expect($actual)->to->be->instanceof('Notes\\Domain\\Entity\\UserGroup\\owner');
         expect($actual->getName())->equal($groupName);
         // test get name
         expect($actual->getUsers())->equal($initialUsers);
         // test getUsers() could return the array or loop through the array a list each user. Not sure how id test that
         expect($actual->getUser($user1Key))->equal($user1);
         //test getUser with the key for user1
         expect($actual->getGroupID())->equal($groupID->__toString());
         expect($actual->count())->equal(2);
     });
 });
 describe('->addUser(swagzilla)', function () {
     it('should add a user to an empty owner usergroup', function () {
         $actual = new Owner();
         $username = "******";
         $password = "******";
         $email = "*****@*****.**";
         $firstName = "Gary";
         $lastName = "Grice";
         $user1 = new User(new Uuid(), $username, $password, $email, $firstName, $lastName);
         $user1Key = $user1->getUserID();
         $actual->addUser($user1);
         expect($actual->getUser($user1Key))->equal($user1);
 /**
  * @param \Notes\Domain\ValueObject\Uuid $id
  * @return bool
  */
 public function removeById(Uuid $id)
 {
     $userID = $id->__toString();
     $query = "DELETE FROM USERS WHERE UserID = '{$userID}'";
     mysql_query($query);
     return $this;
 }
Beispiel #7
0
         $userID = new Uuid();
         $username = "******";
         $password = "******";
         $email = "*****@*****.**";
         $firstName = "Gary";
         $lastName = "Grice";
         $actual = new User($userID, $username, $password, $email, $firstName, $lastName);
         expect($actual)->to->be->instanceof('Notes\\Domain\\Entity\\User');
         expect($actual->getUsername())->equal($username);
         expect($actual->getEmail())->equal($email);
         $hashpass = hash(sha256, $password);
         // the costructor will hash the password im not adding a random salt at this point so it will be easier to implement and test
         expect($actual->getPassword())->equal($password);
         expect($actual->getFirstName())->equal($firstName);
         expect($actual->getLastName())->equal($lastName);
         expect($actual->getUserID())->equal($userID->__toString());
         echo $actual->__toString();
     });
 });
 // anything should be allowed to be passed into username aslong as its original this will be implemented later.
 // except escape characters but i wont check for that here.
 // inputs an invalid password that isnt long enough and doesn't have any numbers or special characters
 // inputs and invalid email. these invalid arguments should create an error
 describe('->construct("Andrew", "pass", "Idontneedtoinputanemail")', function () {
     it('Should return an invalid argument exception', function () {
         $username = "******";
         $invalidPassword = "******";
         $invalidEmail = "IDontNeedToInputAnEmail";
         $exception = null;
         try {
             new User($username, $invalidPassword, $invalidEmail);
 /**
  * @param Uuid $uuid
  * @return User|\PDOStatement
  */
 public function GetUser(Uuid $uuid)
 {
     $sql = 'SELECT * FROM user WHERE uuid = :uuid';
     $sth = $this->conn->prepare($sql, array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY));
     $sth->execute(array(':uuid' => $uuid->__toString()));
     foreach ($sth as $row) {
         return $this->generateUserFromRow($row);
     }
 }
 /**
  * @param Uuid $uuid
  * @return boolean
  */
 public function removeById(Uuid $uuid)
 {
     /** @var User $user */
     foreach ($this->users as $i => $user) {
         if ($user->getId()->__toString() === $uuid->__toString()) {
             unset($this->users[$i]);
             return true;
         }
     }
     return false;
 }
 public function removeById(Uuid $id)
 {
     $results = [];
     foreach ($this->users as $i => $user) {
         if ($user->getId()->__toString() === $id->__toString()) {
             unset($this->users[$i]);
             return true;
         }
     }
     return false;
 }