123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262 |
- <?php
- namespace tests;
- class UserTest extends Base
- {
- public function __construct()
- {
- parent::__construct();
- }
- public function testCreate()
- {
- $username = Utils::randomUserName();
- $password = Utils::randomPassword();
- $this->assertArrayNotHasKey('code', $this->user->create(array('username' => $username, 'password' => $password)));
- $this->assertArrayHasKey('uuid', $this->user->get($username));
- }
- public function testBatchCreate()
- {
- $randomUsername = Utils::randomUserName();
- $randomUsername1 = Utils::randomUserName();
- $randomPassword = Utils::randomPassword();
- $this->assertArrayNotHasKey('code', $this->user->create(array(array('username' => $randomUsername, 'password' => $randomPassword), array('username' => $randomUsername1, 'password' => $randomPassword))));
- $this->assertArrayHasKey('uuid', $this->user->get($randomUsername));
- $this->assertArrayHasKey('uuid', $this->user->get($randomUsername1));
- }
- public function testUserLifeCycles()
- {
- $username = Utils::randomUserName();
- $password = Utils::randomPassword();
- $this->assertArrayNotHasKey('code', $this->user->create(array('username' => $username, 'password' => $password)));
- $this->assertArrayHasKey('uuid', $this->user->get($username));
- $this->assertTrue($this->user->delete($username));
- $result = $this->user->get($username);
- $this->assertEquals(404, $result['code']);
- }
- public function testUserForceLogout()
- {
- $username = Utils::randomUserName();
- $password = Utils::randomPassword();
- $this->assertArrayNotHasKey('code', $this->user->create(array('username' => $username, 'password' => $password)));
- $this->assertIsBool($this->user->forceLogoutAllDevices($username));
- $this->assertTrue($this->user->delete($username));
- }
- public function testUserUpdatePassword()
- {
- $username = Utils::randomUserName();
- $password = Utils::randomPassword();
- $this->assertArrayNotHasKey('code', $this->user->create(array('username' => $username, 'password' => $password)));
- $this->assertIsBool($this->user->updateUserPassword($username, 'password'));
- $this->assertTrue($this->user->delete($username));
- }
- public function testUserListUsers()
- {
- $username = Utils::randomUserName();
- $password = Utils::randomPassword();
- $this->assertArrayNotHasKey('code', $this->user->create(array('username' => $username, 'password' => $password)));
- $data = $this->user->listUsers(1);
- $this->assertArrayHasKey('data', $data);
- $this->assertEquals(1, count($data['data']));
- $this->assertArrayHasKey('uuid', $data['data'][0]);
- $this->assertTrue($this->user->delete($username));
- }
- public function testUserContactLifeCycles()
- {
- $username = Utils::randomUserName();
- $password = Utils::randomPassword();
- $contactUsername = Utils::randomUserName();
- $contactPassword = Utils::randomPassword();
- $this->assertArrayNotHasKey('code', $this->user->create(array(array('username' => $username, 'password' => $password), array('username' => $contactUsername, 'password' => $contactPassword))));
- $this->assertIsBool($this->contact->add($username, $contactUsername));
- $data = $this->contact->get($username);
- $this->assertArrayNotHasKey('code', $data);
- $this->assertEquals(1, count($data));
- $this->assertEquals($data[0], $contactUsername);
- $this->assertIsBool($this->contact->remove($username, $contactUsername));
- $data = $this->contact->get($username);
- $this->assertArrayNotHasKey('code', $data);
- $this->assertEquals(0, count($data));
- $this->assertTrue($this->user->delete($username));
- $this->assertTrue($this->user->delete($contactUsername));
- }
- public function testUserGetUsersBlockedFromSendMsg()
- {
- $username = Utils::randomUserName();
- $password = Utils::randomPassword();
- $randomUsernameCodeJack = Utils::randomUserName();
- $this->assertArrayNotHasKey('code', $this->user->create(array(array('username' => $username, 'password' => $password), array('username' => $randomUsernameCodeJack, 'password' => $password))));
- $this->assertTrue($this->block->blockUserSendMsgToUser($username, array($randomUsernameCodeJack)));
- $data = $this->block->getUsersBlockedFromSendMsgToUser($username);
- $this->assertArrayNotHasKey('code', $data);
- $this->assertEquals(1, count($data));
- $this->assertEquals($data[0], $randomUsernameCodeJack);
- $this->assertTrue($this->user->delete($username));
- $this->assertTrue($this->user->delete($randomUsernameCodeJack));
- }
- public function testUserBlockUserSendMsg()
- {
- $username = Utils::randomUserName();
- $password = Utils::randomPassword();
- $randomUsernameCodeJack = Utils::randomUserName();
- $this->assertArrayNotHasKey('code', $this->user->create(array(array('username' => $username, 'password' => $password), array('username' => $randomUsernameCodeJack, 'password' => $password))));
- $this->assertIsBool($this->contact->add($username, $randomUsernameCodeJack));
- $data = $this->contact->get($username);
- $this->assertArrayNotHasKey('code', $data);
- $this->assertEquals(1, count($data));
- $this->assertEquals($data[0], $randomUsernameCodeJack);
- $this->assertTrue($this->block->blockUserSendMsgToUser($username, array($randomUsernameCodeJack)));
- $data = $this->block->getUsersBlockedFromSendMsgToUser($username);
- $this->assertArrayNotHasKey('code', $data);
- $this->assertEquals(1, count($data));
- $this->assertEquals($data[0], $randomUsernameCodeJack);
- $data = $this->contact->get($username);
- $this->assertArrayNotHasKey('code', $data);
- $this->assertEquals(1, count($data));
- $this->assertEquals($data[0], $randomUsernameCodeJack);
- $this->assertTrue($this->user->delete($username));
- $this->assertTrue($this->user->delete($randomUsernameCodeJack));
- }
- public function testUserUnblockUserSendMsg()
- {
- $username = Utils::randomUserName();
- $password = Utils::randomPassword();
- $randomUsernameCodeJack = Utils::randomUserName();
- $this->assertArrayNotHasKey('code', $this->user->create(array(array('username' => $username, 'password' => $password), array('username' => $randomUsernameCodeJack, 'password' => $password))));
- $this->assertIsBool($this->contact->add($username, $randomUsernameCodeJack));
- $data = $this->contact->get($username);
- $this->assertArrayNotHasKey('code', $data);
- $this->assertEquals(1, count($data));
- $this->assertEquals($data[0], $randomUsernameCodeJack);
- $this->assertTrue($this->block->blockUserSendMsgToUser($username, array($randomUsernameCodeJack)));
- $data = $this->block->getUsersBlockedFromSendMsgToUser($username);
- $this->assertArrayNotHasKey('code', $data);
- $this->assertEquals(1, count($data));
- $this->assertEquals($data[0], $randomUsernameCodeJack);
- $this->assertTrue($this->block->unblockUserSendMsgToUser($username, $randomUsernameCodeJack));
- $data = $this->block->getUsersBlockedFromSendMsgToUser($username);
- $this->assertArrayNotHasKey('code', $data);
- $this->assertEquals(0, count($data));
- $data = $this->contact->get($username);
- $this->assertArrayNotHasKey('code', $data);
- $this->assertEquals(1, count($data));
- $this->assertEquals($data[0], $randomUsernameCodeJack);
- $this->assertTrue($this->user->delete($username));
- $this->assertTrue($this->user->delete($randomUsernameCodeJack));
- }
- public function testUserCountMissedMessages()
- {
- $username = Utils::randomUserName();
- $password = Utils::randomPassword();
- $randomUsernameCodeJack = Utils::randomUserName();
- $this->assertArrayNotHasKey('code', $this->user->create(array(array('username' => $username, 'password' => $password), array('username' => $randomUsernameCodeJack, 'password' => $password))));
- $this->assertArrayNotHasKey('code', $this->message->text('users', array($randomUsernameCodeJack), array('msg' => 'CountMissedMessages'), $username));
- $data = $this->message->countMissedMessages($randomUsernameCodeJack);
- $this->assertIsInt($data);
- $this->assertEquals(1, $data);
- $this->assertTrue($this->user->delete($username));
- $this->assertTrue($this->user->delete($randomUsernameCodeJack));
- }
- public function testUserBlockLogin()
- {
- $username = Utils::randomUserName();
- $password = Utils::randomPassword();
- $this->assertArrayNotHasKey('code', $this->user->create(array('username' => $username, 'password' => $password)));
- $this->assertTrue($this->block->blockUserLogin($username));
- $result = $this->user->get($username);
- $this->assertFalse($result['activated']);
- $this->assertTrue($this->block->unblockUserLogin($username));
- $result = $this->user->get($username);
- $this->assertTrue($result['activated']);
- $this->assertTrue($this->user->delete($username));
- }
- public function testUserOnlineStatus()
- {
- $username = Utils::randomUserName();
- $password = Utils::randomPassword();
-
- $this->assertArrayNotHasKey('code', $this->user->create(array('username' => $username, 'password' => $password)));
- $this->assertIsBool($this->user->isUserOnline($username));
- $this->assertTrue($this->user->delete($username));
- }
- public function testUsersOnlineStatus()
- {
- $username = Utils::randomUserName();
- $password = Utils::randomPassword();
- $randomUsernameCodeJack = Utils::randomUserName();
- $this->assertArrayNotHasKey('code', $this->user->create(array(array('username' => $username, 'password' => $password), array('username' => $randomUsernameCodeJack, 'password' => $password))));
- $this->assertArrayNotHasKey('code', $this->user->isUsersOnline(array($username, $randomUsernameCodeJack)));
- $this->assertTrue($this->user->delete($username));
- $this->assertTrue($this->user->delete($randomUsernameCodeJack));
- }
- public function testGetUserToken()
- {
- $username = Utils::randomUserName();
- $password = Utils::randomPassword();
-
- $this->assertArrayNotHasKey('code', $this->user->create(array('username' => $username, 'password' => $password)));
- $this->assertArrayHasKey('access_token', $this->auth->getUserToken($username, $password));
- $this->assertTrue($this->user->delete($username));
- }
- }
|