示例#1
0
 public function testGetUsers()
 {
     $db = (require __DIR__ . "/config.php");
     $connection = new Mysqltcs($db['host'], $db['user'], $db['psw'], $db['db']);
     $usersManagement = new UsersManagement($connection, $db['tables']['users']);
     $user = User::newUser($usersManagement, "t", "*****@*****.**", "gggg");
     $user2 = User::newUser($usersManagement, "t", "*****@*****.**", "gggg");
     $users = $usersManagement->getUsers();
     $data1 = $users[0]->getUserInfo();
     if ($data1['id'] == $user->getId()) {
         $this->assertEquals($user->getUserInfo(), $users[0]->getUserInfo());
         $this->assertEquals($user2->getUserInfo(), $users[1]->getUserInfo());
     } else {
         $this->assertEquals($user->getUserInfo(), $users[1]->getUserInfo());
         $this->assertEquals($user2->getUserInfo(), $users[0]->getUserInfo());
     }
     $this->assertEquals(2, count($usersManagement->getUsers(false)));
     $user->updateEnabled(false);
     $this->assertEquals(2, count($usersManagement->getUsers(true)));
     $this->assertEquals(1, count($usersManagement->getUsers(false)));
     $users = $usersManagement->getUsers(false);
     $this->assertEquals($user2->getUserInfo(), $users[0]->getUserInfo());
     $this->assertEquals($user2, $users[0]);
     $this->assertTrue($user2->equals($users[0]));
     $user->removeUser();
     $user2->removeUser();
 }
 public function testClone()
 {
     $db = (require __DIR__ . "/config.php");
     $connection = new Mysqltcs($db['host'], $db['user'], $db['psw'], $db['db']);
     $connection2 = clone $connection;
     $usersManagement = new UsersManagement($connection, $db['tables']['users']);
     $usersManagement2 = clone $usersManagement;
     $usersManagement2->setConnection($connection2);
     $user = User::newUser($usersManagement, "t", "*****@*****.**", "gggg");
     $user2 = clone $user;
     $this->assertEquals($user, $user2);
     $user2->setUsersManagement($usersManagement2);
     $this->assertNotEquals($user, $user2);
     $this->assertEquals($user->getUserInfo(), $user2->getUserInfo());
     $user->removeUser();
 }
 /**
  * Get a list (array) of User instances, all users are taken. The list is not ordered.
  * For disabled users see the $disabled parameter
  * @param bool $disabled if true all users are get, Even user disabled
  * @return User[]
  */
 public function getUsers($disabled = true)
 {
     if ($disabled) {
         $condition = "1";
     } else {
         $condition = "enabled IS TRUE";
     }
     $usersDb = $this->operations->getList("id", $condition);
     /* @var $users User[] */
     $users = array();
     foreach ($usersDb as $value) {
         $users[] = User::getUserById($this, $value['id']);
     }
     return $users;
 }
示例#4
0
 /**
  * return true if two user have the same userInfo. CAUTION if two user are the same userInfo but different
  * usersMangement (so different connection or user table for example) the method return true, not false
  * @param User $user
  * @return bool
  * @throws UsersManagementException when user is not valid
  */
 public function equals(User $user)
 {
     $this->checkUser();
     return $this->getUserInfo() == $user->getUserInfo();
 }