コード例 #1
0
 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;
 }
コード例 #2
0
 /**
  * @param User $user
  * @return mixed
  */
 public function add(User $user)
 {
     if (!$user instanceof User) {
         throw new \InvalidArgumentException(__METHOD__ . '():$user has to be a User Object');
     }
     $userID = $user->getUserID();
     $this->users["{$userID}"] = $user;
     return $this;
 }
コード例 #3
0
 public function modify(User $user)
 {
     foreach ($this->users as $user) {
         /**
          * @var \Notes\Domain\Entity\User $user
          */
         if ($user->getUserID() === $user->getUserID()) {
         }
     }
 }
コード例 #4
0
ファイル: AdminRole.php プロジェクト: basil100/project-final
 /**
  * @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;
 }
コード例 #5
0
 public function getUsers()
 {
     $query = "SELECT * FROM USERS";
     $result = mysql_query($query);
     if (!result) {
         die("Database access failed: " . mysql_error());
     }
     $users = [];
     while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
         $userID = new Uuid($row['UserID']);
         $user = new User($userID, $row['UserName'], $row['UserPassword'], $row['UserEmail'], $row['UserFirst'], $row['UserLast']);
         $users[$user->getUserID()] = $user;
         //die(print_r(json_encode($users,true)));
     }
     return $users;
 }
コード例 #6
0
 public function decodeUpdateUser(Request $request, $id)
 {
     if (!(0 === strpos($request->headers->get('Content-Type'), 'application/json'))) {
         return false;
     }
     $data = json_decode($request->getContent(), true);
     if (!array_key_exists('username', $data)) {
         return false;
     }
     $newUser = new User(new Uuid($id));
     $newUser->setUsername(new StringLiteral($data['username']));
     if (array_key_exists('is_admin', $data)) {
         $newUser->setIsAdmin($data['is_admin']);
     }
     if (array_key_exists('is_owner', $data)) {
         $newUser->setIsOwner($data['is_owner']);
     }
     return $newUser;
 }
コード例 #7
0
 /**
  * @param \Notes\Domain\ValueObject\Uuid $id
  * @param \Notes\Domain\Entity\User $user
  * @return bool
  */
 public function modifyById(Uuid $id, User $user)
 {
     foreach ($this->users as $i => $user) {
         /** @var \Notes\Domain\Entity\User $user */
         if ($user->getId()->__toString() === $id->__toString()) {
             unset($this->users[$i]);
             return true;
         }
     }
 }
コード例 #8
0
            $user = new User(new Uuid());
            $user->setUsername(new StringLiteral($faker->userName));
            $users = array($user);
            $admin = new Admins();
            $admin->addUser($user);
            expect($admin->getUsers())->equal($users);
        });
    });
    describe('->getName', function () {
        it('should get the correct the admin\'s username', function () {
            $user = new User(new Uuid());
            $user->setUsername(new StringLiteral('Joe'));
            $admin = new Admins();
            $admin->addUser($user);
            $actual = $admin->getName();
            expect($actual->__toString())->equal('Joe');
        });
    });
    describe('->RemoveUser()', function () {
        it('should delete a user that the admin is responsible for', function () {
            $actual = new Admins();
            $user = new User(new Uuid());
            $user->setUsername(new StringLiteral('Joe'));
            $before = $actual->getUsers();
            $actual->removeUser();
            $after = $actual->getUsers();
            expect(!in_array($user, $before));
            expect(in_array($user, $after));
        });
    });
});
コード例 #9
0
 public function encodeUser(User $user)
 {
     $userInformation = [];
     $userInformation[] = [$user->getId()->__toString() => ['username' => $user->getUsername()->__toString()]];
     return json_encode($userInformation);
 }
コード例 #10
0
 /**
  * @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()]);
 }
コード例 #11
0
            $user = new User($id, $firstName, $lastName, $email);
            expect($user->getEmail())->equal($email);
        });
    });
    describe('-->setFirstName()', function () {
        it('should change the userFirstName to the given value.', function () {
            $faker = \Faker\Factory::create();
            $id = new Uuid();
            $firstName = new StringLiteral($faker->firstName);
            $lastName = new StringLiteral($faker->lastName);
            $email = new StringLiteral($faker->email);
            $user = new User($id, $firstName, $lastName, $email);
            $testFirstName = $faker->firstName;
            $user->setFirstName($testFirstName);
            expect($user->getFirstName())->equal($testFirstName);
        });
    });
    describe('-->setLastName()', function () {
        it('should change the userLastName to the given value.', function () {
            $faker = \Faker\Factory::create();
            $id = new Uuid();
            $firstName = new StringLiteral($faker->firstName);
            $lastName = new StringLiteral($faker->lastName);
            $email = new StringLiteral($faker->email);
            $user = new User($id, $firstName, $lastName, $email);
            $testLastName = $faker->lastName;
            $user->setLastName($testLastName);
            expect($user->getLastName())->equal($testLastName);
        });
    });
});
コード例 #12
0
 describe('->updateUser(swagzilla)', function () {
     it('should update a user in an owner user group', function () {
         $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;
コード例 #13
0
     });*/
 // also tests contains
 describe('->removeUser()', function () {
     it('Should remove a user object from the group', function () {
         $username = "******";
         $password = "******";
         $email = "*****@*****.**";
         $firstName = "Gary";
         $lastName = "Grice";
         $user1 = new User(new Uuid(), $username, $password, $email, $firstName, $lastName);
         $username1 = "TheWorldsGreatest";
         $password2 = "Imadeit12@";
         $email3 = "*****@*****.**";
         $firstName4 = "Robert";
         $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 Admin(new Uuid(), $groupName, $initialUsers);
         // create new Admin group with name cs3620 and add an array with 2 users as initial users
         expect($actual->getUser($user1Key))->equal($user1);
         $actual->removeUser($user1Key);
         expect($actual->containsUser($user1Key))->to->be->false;
     });
 });
 //todo figure out update
 describe('->updateUser(swagzilla)', function () {
     it('should update a user in an admin user group', function () {
         $actual = new Admin();
コード例 #14
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;
        });
    });
});
コード例 #15
0
            }
            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');
        });
    });
    // don't need to test set and get name info. that is already tested with the stringliteral tests
});
コード例 #16
0
 /**
  * @param User $user
  * @return bool
  */
 public function addUser(User $user)
 {
     $this->ownerRepository = array($user->getUserID() => $user);
     return $this;
 }
コード例 #17
0
         expect($actual)->to->be->instanceof('Notes\\Domain\\Entity\\User');
     });
 });
 describe('->getById()', function () {
     it('should return the user with the specified id', function () {
         $actual = $this->repo->getById("4840f14b-6ead-4c14-9519-20cafadaa9d1");
         expect($actual)->to->be->instanceof('Notes\\Domain\\Entity\\User');
     });
 });
 describe('->modifyById()', function () {
     it('should modify the user with the specified id', function () {
         $id = "50090c61-f944-4950-96f6-950c6d1370e9";
         $username = $this->faker->userName;
         $firstName = $this->faker->firstName;
         $lastName = $this->faker->lastName;
         $newUser = new User($id);
         $newUser->setUsername($username);
         $newUser->setFirstName($firstName);
         $newUser->setLastName($lastName);
         expect($this->repo->modifyById($id, $newUser))->equal(true);
         $actual = $this->repo->getById($id);
         expect($actual->getUsername())->equal($username);
         expect($actual->getFirstName())->equal($firstName);
         expect($actual->getLastName())->equal($lastName);
     });
 });
 describe('->removeById()', function () {
     it('should remove the user with the specified id', function () {
         $newUser = $this->userFactory->create();
         $this->repo->add($newUser);
         expect($this->repo->getById($newUser->getId()))->instanceof('Notes\\Domain\\Entity\\User');
コード例 #18
0
 /**
  * @param User $user
  * @return bool
  */
 public function addUser(User $user)
 {
     $userID = $user->getUserID();
     $this->adminRepository["{$userID}"] = $user;
     return $this;
 }
コード例 #19
0
ファイル: user.spec.php プロジェクト: twallgren/project-final
            $uuid = new StringLiteral($faker->uuid);
            $lastName = new StringLiteral($faker->lastName);
            $actual = new User($uuid);
            $actual->setLastName($lastName);
            expect($actual)->to->be->instanceof('Notes\\Domain\\Entity\\User');
            expect($actual->getLastName())->equal($lastName);
        });
    });
    describe('->setFirstName()', function () {
        it('should set the User\'s first name', function () {
            $faker = \Faker\Factory::create();
            $uuid = new StringLiteral($faker->uuid);
            $firstName = new StringLiteral($faker->firstName);
            $actual = new User($uuid);
            $actual->setFirstName($firstName);
            expect($actual)->to->be->instanceof('Notes\\Domain\\Entity\\User');
            expect($actual->getFirstName())->equal($firstName);
        });
    });
    describe('->setLastName()', function () {
        it('should set the User\'s last name', function () {
            $faker = \Faker\Factory::create();
            $uuid = new StringLiteral($faker->uuid);
            $lastName = new StringLiteral($faker->lastName);
            $actual = new User($uuid);
            $actual->setLastName($lastName);
            expect($actual)->to->be->instanceof('Notes\\Domain\\Entity\\User');
            expect($actual->getLastName())->equal($lastName);
        });
    });
});
コード例 #20
0
 /**
  * @param $row
  * @return User
  */
 private function generateUserFromRow($row)
 {
     $id = new Uuid($row[0]);
     $user = new User($id);
     $user->setUsername(new StringLiteral($row[1]));
     $user->setIsAdmin(intval($row[2]));
     $user->setIsOwner(intval($row[3]));
     return $user;
 }
コード例 #21
0
 /**
  * @param \Notes\Domain\Entity\User $userUser $user
  * @return bool
  */
 public function remove(User $user)
 {
     foreach ($this->users as $i => $user) {
         /** @var \Notes\Domain\Entity\User $user */
         if ($user->getId()->__toString() === $user->getId()->__toString()) {
             unset($this->users[$i]);
             return true;
         }
     }
     return false;
 }
コード例 #22
0
         $actual->setUsers($value);
         $before = $actual->getUsers();
         $user = '******';
         $actual->addUser($user);
         $after = $actual->getUsers();
         expect(!in_array($user, $before));
         expect(in_array($user, $after));
     });
 });
 describe('->removeById($uuid)', function () {
     it('should delete a user that the admin is responsible for', function () {
         $uuid = new Uuid();
         $user = new User($uuid);
         $user->setUsername(new StringLiteral('mbrow234'));
         $value[] = $user;
         $user = new User($uuid);
         $user->setUsername(new StringLiteral('randomUser1'));
         $value[] = $user;
         $removeUuid = new Uuid();
         $checkUser = new User($removeUuid);
         $checkUser->setUsername(new StringLiteral('coolUser85'));
         $value[] = $checkUser;
         $actual = new Group(new Uuid());
         $actual->setUsers($value);
         $before = $actual->getUsers();
         $actual->removeUserById($removeUuid);
         $after = $actual->getUsers();
         expect(in_array($checkUser, $before));
         expect(!in_array($checkUser, $after));
     });
 });
コード例 #23
0
ファイル: user.spec.php プロジェクト: basil100/project-final
 */
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');
        });
    });
});
コード例 #24
0
            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());
        });
    });
    describe('->get/setLastName()', function () {
        it('should get/set the user\' last name', function () {
            $faker = \Faker\Factory::create();
            $uuid = new Uuid();
            $userName = new StringLiteral($faker->userName);
            $user = new User($uuid, $userName);
            $lastName = new StringLiteral($faker->lastName);
            $user->setLastName($lastName);
            $actual = $user->getLastName();
            expect($actual)->to->be->instanceof('Notes\\Domain\\ValueObject\\StringLiteral');
            expect($actual->__toString())->equal($lastName->__toString());
        });
    });
});