Пример #1
0
 /**
  * @param User $data
  */
 public function CreateUser(User $data)
 {
     $sql = 'INSERT INTO user (uuid, username, is_admin, is_owner)
             VALUES (:uuid, :username, :is_admin, :is_owner)';
     $sth = $this->conn->prepare($sql, array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY));
     $sth->execute(array(':uuid' => $data->getId()->__toString(), ':username' => $data->getUsername()->__toString(), ':is_admin' => $data->getIsAdmin(), ':is_owner' => $data->getIsOwner()));
 }
 public function modifyById(Uuid $id, User $user)
 {
     mysqli_query($this->connection, "UPDATE `user` SET `id`='" . $user->getId() . "'," . "`username`='" . $user->getUsername() . "',`firstName`='" . $user->getFirstName() . "',`lastName`='" . $user->getLastName() . "' WHERE `id` = '{$id}';");
     if (mysqli_affected_rows($this->connection) > 0) {
         return true;
     }
     return false;
 }
Пример #3
0
 /**
  * @param \Notes\Domain\Entity\User $user
  * @return mixed
  */
 public function addUserInRole(User $user)
 {
     // TODO: Implement addRole() method.
     if (!$user instanceof User) {
         throw new InvalidArgumentException(__METHOD__ . '(): $user has to be a User object');
     }
     $this->id = $user->getId();
     $this->name = $user->getUsername();
     $this->adminRoles[] = $user;
 }
Пример #4
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');
        });
    });
});
         } catch (exception $e) {
             $exception = $e;
         }
         expect($exception)->to->be->instanceof('\\InvalidArgumentException');
     });
 });
 // tests set and get user
 describe('->getUsername()', function () {
     it('should return the users user name', function () {
         $faker = \Faker\Factory::create();
         $username = $faker->userName;
         $user = new User();
         $user->setUsername($username);
         // set method would likely be used by an admin to change the user's name if they have an inappropriate username
         //or if a user account is created by an admin without information it can be set later
         expect($user->getUsername())->equal($username);
     });
 });
 // tests set and get password
 describe('->getPassword()', function () {
     it('shoud return the users hashed password', function () {
         //$faker = \Faker\Factory::create(); wasnt creating the properly formatted password
         $password = '******';
         $user = new User();
         $user->setPassword($password);
         // setPassword would likely only be used for empty user objects made by an admin or to reset a password
         $hashpass = hash(sha256, $password);
         expect($user->getPassword())->equal($hashpass);
     });
 });
 // tests password validation
Пример #6
0
            $user->setUsername("Bazil900");
            $newUserRecord = $this->pdo->insert("users", [$user->getId()->__toString(), $user->getUsername()]);
            $actual = $this->pdo->delete("users", [$user->getId()->__toString()]);
            expect($actual)->to->be->true;
        });
    });
    describe('->select($table, $criteria = [])', function () {
        it('should retrieve (select) data from the database', function () {
            $user = new User(new Uuid());
            $user->setUsername("Bazil Alrashed001");
            $newUserRecord = $this->pdo->insert("users", [$user->getId()->__toString(), $user->getUsername()]);
            $actual = $this->pdo->select("users", [$user->getId()->__toString()]);
            expect(count($actual))->equal(1);
        });
    });
    describe('->sql($sql, $data = [])', function () {
        it('should execute any sql command against the database', function () {
            $user = new User(new Uuid());
            $user->setUsername("Bazil---999");
            $newUserRecord = $this->pdo->insert("users", [$user->getId()->__toString(), $user->getUsername()]);
            $actual = $this->pdo->sql("UPDATE users SET username=? WHERE userID=?", ["Basil999", $user->getId()->__toString()]);
            expect($actual)->to->be->true;
        });
    });
    describe('->close()', function () {
        it('should close the connection of the database', function () {
            $actual = $this->pdo->close();
            expect($actual)->to->be->null;
        });
    });
});
         $faker = \Faker\Factory::create();
         $uuid = new Uuid();
         $username = new StringLiteral($faker->userName);
         $user = new User($uuid, $username);
         expect($user->getUsername())->equal($username);
         expect($user->getUsername())->to->be->instanceof('Notes\\Domain\\ValueObject\\StringLiteral');
     });
 });
 describe('->setUsername()', function () {
     it('should set the user\'s username', function () {
         $faker = \Faker\Factory::create();
         $username = new StringLiteral($faker->userName);
         $uuid = new Uuid();
         $user = new User($uuid, StringLiteral::EMPTY_STR);
         $user->setUsername($username);
         expect($user->getUsername())->equal($username);
         expect($user->getUsername())->to->be->instanceof('Notes\\Domain\\ValueObject\\StringLiteral');
     });
 });
 describe('->getId()', function () {
     it('should return the user\'s id', function () {
         $faker = \Faker\Factory::create();
         $uuid = new Uuid();
         expect($uuid->isValidV4())->to->be->true();
         $username = new StringLiteral($faker->userName);
         $user = new User($uuid, $username);
         $actual = $user->getId();
         expect($actual)->to->be->instanceof('Notes\\Domain\\ValueObject\\Uuid');
         expect($actual->__toString())->equal($uuid->__toString());
     });
 });
 /**
  * @param \Notes\Domain\Entity\User $user
  * @return mixed
  */
 public function add(User $user)
 {
     // TODO: Implement add() method.
     $this->adapter->insert("users", [$user->getId(), $user->getUsername()]);
 }
Пример #9
0
 public function encodeUser(User $user)
 {
     $userInformation = [];
     $userInformation[] = [$user->getId()->__toString() => ['username' => $user->getUsername()->__toString()]];
     return json_encode($userInformation);
 }