RoomTest.php 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. <?php
  2. namespace tests;
  3. class RoomTest extends Base
  4. {
  5. public function __construct()
  6. {
  7. parent::__construct();
  8. }
  9. public function testRoomCycles()
  10. {
  11. $randomOwnerUsername = Utils::randomUserName();
  12. $randomPassword = Utils::randomPassword();
  13. $randomMemberUsername = Utils::randomUserName();
  14. $this->assertArrayNotHasKey('code', $this->user->create(array(array('username' => $randomOwnerUsername, 'password' => $randomPassword), array('username' => $randomMemberUsername, 'password' => $randomPassword))));
  15. $members = array($randomMemberUsername);
  16. $roomId = $this->room->createRoom("chat room", "room description", $randomOwnerUsername, $members, 200);
  17. $this->assertIsString($roomId);
  18. $data = $this->room->getRoom($roomId);
  19. $this->assertArrayNotHasKey('code', $data);
  20. $this->assertEquals($data['name'], "chat room");
  21. $this->assertTrue($this->room->updateRoom(array('room_id' => $roomId, 'name' => "room chat")));
  22. $data = $this->room->getRoom($roomId);
  23. $this->assertArrayNotHasKey('code', $data);
  24. $this->assertEquals($data['name'], "room chat");
  25. $this->assertTrue($this->room->destroyRoom($roomId));
  26. $this->assertTrue($this->user->delete($randomOwnerUsername));
  27. $this->assertTrue($this->user->delete($randomMemberUsername));
  28. }
  29. public function testRoomListAll()
  30. {
  31. $randomOwnerUsername = Utils::randomUserName();
  32. $randomPassword = Utils::randomPassword();
  33. $randomMemberUsername = Utils::randomUserName();
  34. $this->assertArrayNotHasKey('code', $this->user->create(array(array('username' => $randomOwnerUsername, 'password' => $randomPassword), array('username' => $randomMemberUsername, 'password' => $randomPassword))));
  35. $members = array($randomMemberUsername);
  36. $roomId = $this->room->createRoom("chat room", "room description", $randomOwnerUsername, $members, 200);
  37. $this->assertIsString($roomId);
  38. $this->assertArrayNotHasKey('code', $this->room->listAllRooms());
  39. $this->assertArrayNotHasKey('code', $this->room->listRooms(1));
  40. $this->assertTrue($this->room->destroyRoom($roomId));
  41. $this->assertTrue($this->user->delete($randomOwnerUsername));
  42. $this->assertTrue($this->user->delete($randomMemberUsername));
  43. }
  44. public function testRoomUserJoinedList()
  45. {
  46. $randomOwnerUsername = Utils::randomUserName();
  47. $randomPassword = Utils::randomPassword();
  48. $randomMemberUsername = Utils::randomUserName();
  49. $this->assertArrayNotHasKey('code', $this->user->create(array(array('username' => $randomOwnerUsername, 'password' => $randomPassword), array('username' => $randomMemberUsername, 'password' => $randomPassword))));
  50. $members = array($randomMemberUsername);
  51. $roomId = $this->room->createRoom("chat room", "room description", $randomOwnerUsername, $members, 200);
  52. $this->assertIsString($roomId);
  53. $data = $this->room->listAllRoomsUserJoined($randomOwnerUsername);
  54. $this->assertArrayNotHasKey('code', $data);
  55. $this->assertEquals(1, count($data));
  56. $this->assertTrue($this->room->destroyRoom($roomId));
  57. $this->assertTrue($this->user->delete($randomOwnerUsername));
  58. $this->assertTrue($this->user->delete($randomMemberUsername));
  59. }
  60. public function testRoomMembers()
  61. {
  62. $randomOwnerUsername = Utils::randomUserName();
  63. $randomPassword = Utils::randomPassword();
  64. $randomMemberUsername = Utils::randomUserName();
  65. $this->assertArrayNotHasKey('code', $this->user->create(array(array('username' => $randomOwnerUsername, 'password' => $randomPassword), array('username' => $randomMemberUsername, 'password' => $randomPassword))));
  66. $members = array();
  67. $roomId = $this->room->createRoom("chat room", "room description", $randomOwnerUsername, $members, 200);
  68. $this->assertIsString($roomId);
  69. $this->assertTrue($this->room->addRoomMember($roomId, $randomMemberUsername));
  70. $data = $this->room->listRoomMembersAll($roomId);
  71. $this->assertArrayNotHasKey('code', $data);
  72. $this->assertEquals(2, count($data));
  73. $this->assertTrue($this->room->removeRoomMember($roomId, $randomMemberUsername));
  74. $data = $this->room->listRoomMembersAll($roomId);
  75. $this->assertArrayNotHasKey('code', $data);
  76. $this->assertEquals(1, count($data));
  77. $this->assertArrayNotHasKey('code', $this->room->listRoomMembers($roomId, 2));
  78. $this->assertTrue($this->room->destroyRoom($roomId));
  79. $this->assertTrue($this->user->delete($randomOwnerUsername));
  80. $this->assertTrue($this->user->delete($randomMemberUsername));
  81. }
  82. public function testRoomAdmins()
  83. {
  84. $randomOwnerUsername = Utils::randomUserName();
  85. $randomPassword = Utils::randomPassword();
  86. $randomMemberUsername = Utils::randomUserName();
  87. $this->assertArrayNotHasKey('code', $this->user->create(array(array('username' => $randomOwnerUsername, 'password' => $randomPassword), array('username' => $randomMemberUsername, 'password' => $randomPassword))));
  88. $members = array($randomMemberUsername);
  89. $roomId = $this->room->createRoom("chat room", "room description", $randomOwnerUsername, $members, 200);
  90. $this->assertIsString($roomId);
  91. $this->assertTrue($this->room->promoteRoomAdmin($roomId, $randomMemberUsername));
  92. $data = $this->room->listRoomAdminsAll($roomId);
  93. $this->assertArrayNotHasKey('code', $data);
  94. $this->assertEquals(1, count($data));
  95. $this->assertTrue($this->room->demoteRoomAdmin($roomId, $randomMemberUsername));
  96. $data = $this->room->listRoomAdminsAll($roomId);
  97. $this->assertArrayNotHasKey('code', $data);
  98. $this->assertEquals(0, count($data));
  99. $this->assertTrue($this->room->destroyRoom($roomId));
  100. $this->assertTrue($this->user->delete($randomOwnerUsername));
  101. $this->assertTrue($this->user->delete($randomMemberUsername));
  102. }
  103. public function testRoomSuperAdmins()
  104. {
  105. $randomUsername = Utils::randomUserName();
  106. $randomPassword = Utils::randomPassword();
  107. $this->assertArrayNotHasKey('code', $this->user->create(array('username' => $randomUsername, 'password' => $randomPassword)));
  108. $this->assertTrue($this->room->promoteRoomSuperAdmin($randomUsername));
  109. $data = $this->room->listRoomSuperAdminsAll();
  110. $this->assertArrayNotHasKey('code', $data);
  111. $this->assertEquals(1, count($data));
  112. $this->assertTrue($this->room->demoteRoomSuperAdmin($randomUsername));
  113. $data = $this->room->listRoomSuperAdminsAll();
  114. $this->assertArrayNotHasKey('code', $data);
  115. $this->assertEquals(0, count($data));
  116. $this->assertTrue($this->user->delete($randomUsername));
  117. }
  118. public function testRoomUsersBlockedJoin()
  119. {
  120. $randomOwnerUsername = Utils::randomUserName();
  121. $randomPassword = Utils::randomPassword();
  122. $randomMemberUsername = Utils::randomUserName();
  123. $this->assertArrayNotHasKey('code', $this->user->create(array(array('username' => $randomOwnerUsername, 'password' => $randomPassword), array('username' => $randomMemberUsername, 'password' => $randomPassword))));
  124. $members = array($randomMemberUsername);
  125. $roomId = $this->room->createRoom("chat room", "room description", $randomOwnerUsername, $members, 200);
  126. $this->assertIsString($roomId);
  127. $this->assertTrue($this->block->blockUserJoinRoom($roomId, $randomMemberUsername));
  128. $data = $this->block->getUsersBlockedJoinRoom($roomId);
  129. $this->assertArrayNotHasKey('code', $data);
  130. $this->assertEquals($data[0], $randomMemberUsername);
  131. $this->assertTrue($this->block->unblockUserJoinRoom($roomId, $randomMemberUsername));
  132. $data = $this->block->getUsersBlockedJoinRoom($roomId);
  133. $this->assertArrayNotHasKey('code', $data);
  134. $this->assertEquals(count($data), 0);
  135. $this->assertTrue($this->room->destroyRoom($roomId));
  136. $this->assertTrue($this->user->delete($randomOwnerUsername));
  137. $this->assertTrue($this->user->delete($randomMemberUsername));
  138. }
  139. public function testRoomBlockUserSendMsg()
  140. {
  141. $randomOwnerUsername = Utils::randomUserName();
  142. $randomPassword = Utils::randomPassword();
  143. $randomMemberUsername = Utils::randomUserName();
  144. $this->assertArrayNotHasKey('code', $this->user->create(array(array('username' => $randomOwnerUsername, 'password' => $randomPassword), array('username' => $randomMemberUsername, 'password' => $randomPassword))));
  145. $members = array($randomMemberUsername);
  146. $roomId = $this->room->createRoom("chat room", "room description", $randomOwnerUsername, $members, 200);
  147. $this->assertIsString($roomId);
  148. $this->assertTrue($this->block->blockUserSendMsgToRoom($roomId, $members, 30000));
  149. $data = $this->block->getUsersBlockedSendMsgToRoom($roomId);
  150. $this->assertArrayNotHasKey('code', $data);
  151. $this->assertEquals(1, count($data));
  152. $this->assertTrue($this->block->unblockUserSendMsgToRoom($roomId, $members));
  153. $data = $this->block->getUsersBlockedSendMsgToRoom($roomId);
  154. $this->assertArrayNotHasKey('code', $data);
  155. $this->assertEquals(0, count($data));
  156. $this->assertTrue($this->room->destroyRoom($roomId));
  157. $this->assertTrue($this->user->delete($randomOwnerUsername));
  158. $this->assertTrue($this->user->delete($randomMemberUsername));
  159. }
  160. }