GroupTest.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508
  1. <?php
  2. namespace tests;
  3. class GroupTest extends Base
  4. {
  5. public function __construct()
  6. {
  7. parent::__construct();
  8. }
  9. public function testGroupCreatePublic()
  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. $groupId = $this->group->createPublicGroup($randomOwnerUsername, "group", "group description", $members, 200, true);
  17. $this->assertIsString($groupId);
  18. $data = $this->group->listAllGroupMembers($groupId);
  19. $this->assertArrayNotHasKey('code', $data);
  20. $this->assertEquals(count($data) - 1, count($members));
  21. $this->assertTrue($this->group->destroyGroup($groupId));
  22. $this->assertTrue($this->user->delete($randomOwnerUsername));
  23. $this->assertTrue($this->user->delete($randomMemberUsername));
  24. }
  25. public function testGroupCreatePublicWithCustom()
  26. {
  27. $randomOwnerUsername = Utils::randomUserName();
  28. $randomPassword = Utils::randomPassword();
  29. $randomMemberUsername = Utils::randomUserName();
  30. $this->assertArrayNotHasKey('code', $this->user->create(array(array('username' => $randomOwnerUsername, 'password' => $randomPassword), array('username' => $randomMemberUsername, 'password' => $randomPassword))));
  31. $members = array($randomMemberUsername);
  32. $groupId = $this->group->createPublicGroup($randomOwnerUsername, "group", "group description", $members, 200, true, 'custom');
  33. $this->assertIsString($groupId);
  34. $data = $this->group->listAllGroupMembers($groupId);
  35. $this->assertArrayNotHasKey('code', $data);
  36. $this->assertEquals(count($data) - 1, count($members));
  37. $result = $this->group->getGroup($groupId);
  38. $this->assertArrayNotHasKey('code', $result);
  39. $this->assertEquals($result['custom'], 'custom');
  40. $this->assertTrue($this->group->destroyGroup($groupId));
  41. $this->assertTrue($this->user->delete($randomOwnerUsername));
  42. $this->assertTrue($this->user->delete($randomMemberUsername));
  43. }
  44. public function testGroupCreatePrivate()
  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. $groupId = $this->group->createPrivateGroup($randomOwnerUsername, "group", "group description", $members, 200, true);
  52. $this->assertIsString($groupId);
  53. $data = $this->group->listAllGroupMembers($groupId);
  54. $this->assertArrayNotHasKey('code', $data);
  55. $this->assertEquals(count($data) - 1, count($members));
  56. $this->assertTrue($this->group->destroyGroup($groupId));
  57. $this->assertTrue($this->user->delete($randomOwnerUsername));
  58. $this->assertTrue($this->user->delete($randomMemberUsername));
  59. }
  60. public function testGroupCreatePrivateWithCustom()
  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($randomMemberUsername);
  67. $groupId = $this->group->createPrivateGroup($randomOwnerUsername, "group", "group description", $members, 200, true, 'custom');
  68. $this->assertIsString($groupId);
  69. $data = $this->group->listAllGroupMembers($groupId);
  70. $this->assertArrayNotHasKey('code', $data);
  71. $this->assertEquals(count($data) - 1, count($members));
  72. $group = $this->group->getGroup($groupId);
  73. $this->assertArrayNotHasKey('code', $group);
  74. $this->assertEquals($group['custom'], 'custom');
  75. $this->assertTrue($this->group->destroyGroup($groupId));
  76. $this->assertTrue($this->user->delete($randomOwnerUsername));
  77. $this->assertTrue($this->user->delete($randomMemberUsername));
  78. }
  79. public function testGroupDestroy()
  80. {
  81. $randomOwnerUsername = Utils::randomUserName();
  82. $randomPassword = Utils::randomPassword();
  83. $randomMemberUsername = Utils::randomUserName();
  84. $this->assertArrayNotHasKey('code', $this->user->create(array(array('username' => $randomOwnerUsername, 'password' => $randomPassword), array('username' => $randomMemberUsername, 'password' => $randomPassword))));
  85. $members = array($randomMemberUsername);
  86. $groupId = $this->group->createPrivateGroup($randomOwnerUsername, "group", "group description", $members, 200, true);
  87. $this->assertIsString($groupId);
  88. $this->assertTrue($this->group->destroyGroup($groupId));
  89. $this->assertArrayHasKey('code', $this->group->getGroup($groupId));
  90. $this->assertTrue($this->user->delete($randomOwnerUsername));
  91. $this->assertTrue($this->user->delete($randomMemberUsername));
  92. }
  93. public function testGroupListAllGroups()
  94. {
  95. $randomOwnerUsername = Utils::randomUserName();
  96. $randomPassword = Utils::randomPassword();
  97. $randomMemberUsername = Utils::randomUserName();
  98. $this->assertArrayNotHasKey('code', $this->user->create(array(array('username' => $randomOwnerUsername, 'password' => $randomPassword), array('username' => $randomMemberUsername, 'password' => $randomPassword))));
  99. $members = array($randomMemberUsername);
  100. $groupId = $this->group->createPrivateGroup($randomOwnerUsername, "group", "group description", $members, 200, true);
  101. $this->assertIsString($groupId);
  102. $this->assertArrayNotHasKey('code', $this->group->listAllGroups());
  103. $this->assertTrue($this->group->destroyGroup($groupId));
  104. $this->assertTrue($this->user->delete($randomOwnerUsername));
  105. $this->assertTrue($this->user->delete($randomMemberUsername));
  106. }
  107. public function testGroupListGroups()
  108. {
  109. $randomOwnerUsername = Utils::randomUserName();
  110. $randomPassword = Utils::randomPassword();
  111. $randomMemberUsername = Utils::randomUserName();
  112. $this->assertArrayNotHasKey('code', $this->user->create(array(array('username' => $randomOwnerUsername, 'password' => $randomPassword), array('username' => $randomMemberUsername, 'password' => $randomPassword))));
  113. $members = array($randomMemberUsername);
  114. $groupId = $this->group->createPrivateGroup($randomOwnerUsername, "group", "group description", $members, 200, true);
  115. $this->assertIsString($groupId);
  116. $this->assertArrayNotHasKey('code', $this->group->listGroups(1));
  117. $this->assertTrue($this->group->destroyGroup($groupId));
  118. $this->assertTrue($this->user->delete($randomOwnerUsername));
  119. $this->assertTrue($this->user->delete($randomMemberUsername));
  120. }
  121. public function testGroupGet()
  122. {
  123. $randomOwnerUsername = Utils::randomUserName();
  124. $randomPassword = Utils::randomPassword();
  125. $randomMemberUsername = Utils::randomUserName();
  126. $randomAdminUsername = Utils::randomUserName();
  127. $this->assertArrayNotHasKey('code', $this->user->create(array(array('username' => $randomOwnerUsername, 'password' => $randomPassword), array('username' => $randomMemberUsername, 'password' => $randomPassword), array('username' => $randomAdminUsername, 'password' => $randomPassword))));
  128. $members = array($randomMemberUsername, $randomAdminUsername);
  129. $groupId = $this->group->createPrivateGroup($randomOwnerUsername, "group", "group description", $members, 200, true);
  130. $this->assertIsString($groupId);
  131. $this->assertTrue($this->group->addGroupAdmin($groupId, $randomAdminUsername));
  132. $group = $this->group->getGroup($groupId);
  133. $this->assertArrayNotHasKey('code', $group);
  134. $this->assertEquals($group['affiliations_count'], 3);
  135. $this->assertNotNull($group['affiliations']);
  136. $this->assertTrue($this->group->destroyGroup($groupId));
  137. $this->assertTrue($this->user->delete($randomOwnerUsername));
  138. $this->assertTrue($this->user->delete($randomMemberUsername));
  139. $this->assertTrue($this->user->delete($randomAdminUsername));
  140. }
  141. public function testGroupUpdate()
  142. {
  143. $randomOwnerUsername = Utils::randomUserName();
  144. $randomPassword = Utils::randomPassword();
  145. $randomMemberUsername = Utils::randomUserName();
  146. $this->assertArrayNotHasKey('code', $this->user->create(array(array('username' => $randomOwnerUsername, 'password' => $randomPassword), array('username' => $randomMemberUsername, 'password' => $randomPassword))));
  147. $members = array($randomMemberUsername);
  148. $groupId = $this->group->createPrivateGroup($randomOwnerUsername, "group", "group description", $members, 200, true);
  149. $this->assertIsString($groupId);
  150. $maxUsers = 400;
  151. $this->assertTrue($this->group->updateGroup(array('group_id' => $groupId, 'maxusers' => $maxUsers)));
  152. $group = $this->group->getGroup($groupId);
  153. $this->assertArrayNotHasKey('code', $group);
  154. $this->assertEquals($group['maxusers'], $maxUsers);
  155. $this->assertTrue($this->group->destroyGroup($groupId));
  156. $this->assertTrue($this->user->delete($randomOwnerUsername));
  157. $this->assertTrue($this->user->delete($randomMemberUsername));
  158. }
  159. public function testGroupUpdateOwner()
  160. {
  161. $randomOwnerUsername = Utils::randomUserName();
  162. $randomPassword = Utils::randomPassword();
  163. $randomMemberUsername = Utils::randomUserName();
  164. $this->assertArrayNotHasKey('code', $this->user->create(array(array('username' => $randomOwnerUsername, 'password' => $randomPassword), array('username' => $randomMemberUsername, 'password' => $randomPassword))));
  165. $members = array($randomMemberUsername);
  166. $groupId = $this->group->createPrivateGroup($randomOwnerUsername, "group", "group description", $members, 200, true);
  167. $this->assertIsString($groupId);
  168. $this->assertTrue($this->group->updateGroupOwner($groupId, $randomMemberUsername));
  169. $group = $this->group->getGroup($groupId);
  170. $this->assertArrayNotHasKey('code', $group);
  171. $this->assertEquals($group['owner'], $randomMemberUsername);
  172. $this->assertTrue($this->group->destroyGroup($groupId));
  173. $this->assertTrue($this->user->delete($randomOwnerUsername));
  174. $this->assertTrue($this->user->delete($randomMemberUsername));
  175. }
  176. public function testGroupGetAnnouncement()
  177. {
  178. $randomOwnerUsername = Utils::randomUserName();
  179. $randomPassword = Utils::randomPassword();
  180. $randomMemberUsername = Utils::randomUserName();
  181. $this->assertArrayNotHasKey('code', $this->user->create(array(array('username' => $randomOwnerUsername, 'password' => $randomPassword), array('username' => $randomMemberUsername, 'password' => $randomPassword))));
  182. $members = array($randomMemberUsername);
  183. $groupId = $this->group->createPrivateGroup($randomOwnerUsername, "group", "group description", $members, 200, true);
  184. $this->assertIsString($groupId);
  185. $this->assertArrayNotHasKey('code', $this->group->getGroupAnnouncement($groupId));
  186. $this->assertTrue($this->group->destroyGroup($groupId));
  187. $this->assertTrue($this->user->delete($randomOwnerUsername));
  188. $this->assertTrue($this->user->delete($randomMemberUsername));
  189. }
  190. public function testGroupUpdateAnnouncement()
  191. {
  192. $randomOwnerUsername = Utils::randomUserName();
  193. $randomPassword = Utils::randomPassword();
  194. $randomMemberUsername = Utils::randomUserName();
  195. $this->assertArrayNotHasKey('code', $this->user->create(array(array('username' => $randomOwnerUsername, 'password' => $randomPassword), array('username' => $randomMemberUsername, 'password' => $randomPassword))));
  196. $members = array($randomMemberUsername);
  197. $groupId = $this->group->createPrivateGroup($randomOwnerUsername, "group", "group description", $members, 200, true);
  198. $this->assertIsString($groupId);
  199. $announcement = "update announcement";
  200. $this->assertTrue($this->group->updateGroupAnnouncement($groupId, $announcement));
  201. $group = $this->group->getGroupAnnouncement($groupId);
  202. $this->assertArrayNotHasKey('code', $group);
  203. $this->assertEquals($announcement, $group['announcement']);
  204. $this->assertTrue($this->group->destroyGroup($groupId));
  205. $this->assertTrue($this->user->delete($randomOwnerUsername));
  206. $this->assertTrue($this->user->delete($randomMemberUsername));
  207. }
  208. public function testGroupListAllGroupMembers()
  209. {
  210. $randomOwnerUsername = Utils::randomUserName();
  211. $randomPassword = Utils::randomPassword();
  212. $randomMemberUsername = Utils::randomUserName();
  213. $this->assertArrayNotHasKey('code', $this->user->create(array(array('username' => $randomOwnerUsername, 'password' => $randomPassword), array('username' => $randomMemberUsername, 'password' => $randomPassword))));
  214. $members = array($randomMemberUsername);
  215. $groupId = $this->group->createPrivateGroup($randomOwnerUsername, "group", "group description", $members, 200, true);
  216. $this->assertIsString($groupId);
  217. $this->assertArrayNotHasKey('code', $this->group->listAllGroupMembers($groupId));
  218. $this->assertTrue($this->group->destroyGroup($groupId));
  219. $this->assertTrue($this->user->delete($randomOwnerUsername));
  220. $this->assertTrue($this->user->delete($randomMemberUsername));
  221. }
  222. public function testGroupListMembers()
  223. {
  224. $randomOwnerUsername = Utils::randomUserName();
  225. $randomPassword = Utils::randomPassword();
  226. $randomMemberUsername = Utils::randomUserName();
  227. $this->assertArrayNotHasKey('code', $this->user->create(array(array('username' => $randomOwnerUsername, 'password' => $randomPassword), array('username' => $randomMemberUsername, 'password' => $randomPassword))));
  228. $members = array($randomMemberUsername);
  229. $groupId = $this->group->createPrivateGroup($randomOwnerUsername, "group", "group description", $members, 200, true);
  230. $this->assertIsString($groupId);
  231. $this->assertArrayNotHasKey('code', $this->group->listGroupMembers($groupId, 2));
  232. $this->assertTrue($this->group->destroyGroup($groupId));
  233. $this->assertTrue($this->user->delete($randomOwnerUsername));
  234. $this->assertTrue($this->user->delete($randomMemberUsername));
  235. }
  236. public function testGroupAddMemberSingle()
  237. {
  238. $randomOwnerUsername = Utils::randomUserName();
  239. $randomPassword = Utils::randomPassword();
  240. $randomMemberUsername = Utils::randomUserName();
  241. $randomMemberUsername1 = Utils::randomUserName();
  242. $this->assertArrayNotHasKey('code', $this->user->create(array(array('username' => $randomOwnerUsername, 'password' => $randomPassword), array('username' => $randomMemberUsername, 'password' => $randomPassword), array('username' => $randomMemberUsername1, 'password' => $randomPassword))));
  243. $members = array($randomMemberUsername);
  244. $groupId = $this->group->createPrivateGroup($randomOwnerUsername, "group", "group description", $members, 200, true);
  245. $this->assertIsString($groupId);
  246. $this->assertTrue($this->group->addGroupMember($groupId, $randomMemberUsername1));
  247. $this->assertTrue($this->group->destroyGroup($groupId));
  248. $this->assertTrue($this->user->delete($randomOwnerUsername));
  249. $this->assertTrue($this->user->delete($randomMemberUsername));
  250. $this->assertTrue($this->user->delete($randomMemberUsername1));
  251. }
  252. public function testGroupAddMemberBatch()
  253. {
  254. $randomOwnerUsername = Utils::randomUserName();
  255. $randomPassword = Utils::randomPassword();
  256. $randomMemberUsername = Utils::randomUserName();
  257. $randomMemberUsername1 = Utils::randomUserName();
  258. $randomMemberUsername2 = Utils::randomUserName();
  259. $this->assertArrayNotHasKey('code', $this->user->create(array(array('username' => $randomOwnerUsername, 'password' => $randomPassword), array('username' => $randomMemberUsername, 'password' => $randomPassword), array('username' => $randomMemberUsername1, 'password' => $randomPassword), array('username' => $randomMemberUsername2, 'password' => $randomPassword))));
  260. $members = array($randomMemberUsername);
  261. $groupId = $this->group->createPrivateGroup($randomOwnerUsername, "group", "group description", $members, 200, true);
  262. $this->assertIsString($groupId);
  263. $addMembers = array($randomMemberUsername1, $randomMemberUsername2);
  264. $this->assertTrue($this->group->addGroupMembers($groupId, $addMembers));
  265. $members = $this->group->listAllGroupMembers($groupId);
  266. $this->assertArrayNotHasKey('code', $members);
  267. $this->assertEquals(4, count($members));
  268. $this->assertTrue($this->group->destroyGroup($groupId));
  269. $this->assertTrue($this->user->delete($randomOwnerUsername));
  270. $this->assertTrue($this->user->delete($randomMemberUsername));
  271. $this->assertTrue($this->user->delete($randomMemberUsername1));
  272. $this->assertTrue($this->user->delete($randomMemberUsername2));
  273. }
  274. public function testGroupRemoveMemberSingle()
  275. {
  276. $randomOwnerUsername = Utils::randomUserName();
  277. $randomPassword = Utils::randomPassword();
  278. $randomMemberUsername = Utils::randomUserName();
  279. $this->assertArrayNotHasKey('code', $this->user->create(array(array('username' => $randomOwnerUsername, 'password' => $randomPassword), array('username' => $randomMemberUsername, 'password' => $randomPassword))));
  280. $members = array($randomMemberUsername);
  281. $groupId = $this->group->createPrivateGroup($randomOwnerUsername, "group", "group description", $members, 200, true);
  282. $this->assertIsString($groupId);
  283. $this->assertTrue($this->group->removeGroupMember($groupId, $randomMemberUsername));
  284. $members = $this->group->listAllGroupMembers($groupId);
  285. $this->assertArrayNotHasKey('code', $members);
  286. $this->assertEquals(1, count($members));
  287. $this->assertTrue($this->group->destroyGroup($groupId));
  288. $this->assertTrue($this->user->delete($randomOwnerUsername));
  289. $this->assertTrue($this->user->delete($randomMemberUsername));
  290. }
  291. public function testGroupRemoveMemberBatch()
  292. {
  293. $randomOwnerUsername = Utils::randomUserName();
  294. $randomPassword = Utils::randomPassword();
  295. $randomMemberUsername = Utils::randomUserName();
  296. $randomMemberUsername1 = Utils::randomUserName();
  297. $randomMemberUsername2 = Utils::randomUserName();
  298. $this->assertArrayNotHasKey('code', $this->user->create(array(array('username' => $randomOwnerUsername, 'password' => $randomPassword), array('username' => $randomMemberUsername, 'password' => $randomPassword), array('username' => $randomMemberUsername1, 'password' => $randomPassword), array('username' => $randomMemberUsername2, 'password' => $randomPassword))));
  299. $members = array($randomMemberUsername, $randomMemberUsername1, $randomMemberUsername2);
  300. $groupId = $this->group->createPrivateGroup($randomOwnerUsername, "group", "group description", $members, 200, true);
  301. $this->assertIsString($groupId);
  302. $this->assertTrue($this->group->removeGroupMembers($groupId, $members));
  303. $members = $this->group->listAllGroupMembers($groupId);
  304. $this->assertArrayNotHasKey('code', $members);
  305. $this->assertEquals(1, count($members));
  306. $this->assertTrue($this->group->destroyGroup($groupId));
  307. $this->assertTrue($this->user->delete($randomOwnerUsername));
  308. $this->assertTrue($this->user->delete($randomMemberUsername));
  309. $this->assertTrue($this->user->delete($randomMemberUsername1));
  310. $this->assertTrue($this->user->delete($randomMemberUsername2));
  311. }
  312. public function testGroupAdmin()
  313. {
  314. $randomOwnerUsername = Utils::randomUserName();
  315. $randomPassword = Utils::randomPassword();
  316. $randomMemberUsername = Utils::randomUserName();
  317. $randomAdminUsername = Utils::randomUserName();
  318. $this->assertArrayNotHasKey('code', $this->user->create(array(array('username' => $randomOwnerUsername, 'password' => $randomPassword), array('username' => $randomMemberUsername, 'password' => $randomPassword), array('username' => $randomAdminUsername, 'password' => $randomPassword))));
  319. $members = array($randomMemberUsername, $randomAdminUsername);
  320. $groupId = $this->group->createPrivateGroup($randomOwnerUsername, "group", "group description", $members, 200, true);
  321. $this->assertIsString($groupId);
  322. $this->assertTrue($this->group->addGroupAdmin($groupId, $randomAdminUsername));
  323. $admins = $this->group->listGroupAdmins($groupId);
  324. $this->assertArrayNotHasKey('code', $admins);
  325. $this->assertEquals(1, count($admins));
  326. $this->assertIsBool($this->group->removeGroupAdmin($groupId, $randomAdminUsername));
  327. $admins = $this->group->listGroupAdmins($groupId);
  328. $this->assertArrayNotHasKey('code', $admins);
  329. $this->assertEquals(0, count($admins));
  330. $this->assertTrue($this->group->destroyGroup($groupId));
  331. $this->assertTrue($this->user->delete($randomOwnerUsername));
  332. $this->assertTrue($this->user->delete($randomMemberUsername));
  333. $this->assertTrue($this->user->delete($randomAdminUsername));
  334. }
  335. public function testGroupUsersBlockedJoin()
  336. {
  337. $randomOwnerUsername = Utils::randomUserName();
  338. $randomPassword = Utils::randomPassword();
  339. $randomMemberUsername = Utils::randomUserName();
  340. $this->assertArrayNotHasKey('code', $this->user->create(array(array('username' => $randomOwnerUsername, 'password' => $randomPassword), array('username' => $randomMemberUsername, 'password' => $randomPassword))));
  341. $members = array($randomMemberUsername);
  342. $groupId = $this->group->createPrivateGroup($randomOwnerUsername, "group", "group description", $members, 200, true);
  343. $this->assertIsString($groupId);
  344. $this->assertTrue($this->block->blockUserJoinGroup($groupId, $randomMemberUsername));
  345. $data = $this->block->getUsersBlockedJoinGroup($groupId);
  346. $this->assertArrayNotHasKey('code', $data);
  347. $this->assertEquals($data[0], $randomMemberUsername);
  348. $this->assertTrue($this->block->unblockUserJoinGroup($groupId, $randomMemberUsername));
  349. $data = $this->block->getUsersBlockedJoinGroup($groupId);
  350. $this->assertArrayNotHasKey('code', $data);
  351. $this->assertEquals(count($data), 0);
  352. $this->assertTrue($this->group->destroyGroup($groupId));
  353. $this->assertTrue($this->user->delete($randomOwnerUsername));
  354. $this->assertTrue($this->user->delete($randomMemberUsername));
  355. }
  356. public function testGroupBlockUserSendMsg()
  357. {
  358. $randomOwnerUsername = Utils::randomUserName();
  359. $randomPassword = Utils::randomPassword();
  360. $randomMemberUsername = Utils::randomUserName();
  361. $this->assertArrayNotHasKey('code', $this->user->create(array(array('username' => $randomOwnerUsername, 'password' => $randomPassword), array('username' => $randomMemberUsername, 'password' => $randomPassword))));
  362. $members = array($randomMemberUsername);
  363. $groupId = $this->group->createPrivateGroup($randomOwnerUsername, "group", "group description", $members, 200, true);
  364. $this->assertIsString($groupId);
  365. $this->assertTrue($this->block->blockUserSendMsgToGroup($groupId, $members, 30000));
  366. $data = $this->block->getUsersBlockedSendMsgToGroup($groupId);
  367. $this->assertArrayNotHasKey('code', $data);
  368. $this->assertEquals(1, count($data));
  369. $this->assertTrue($this->block->unblockUserSendMsgToGroup($groupId, $members));
  370. $data = $this->block->getUsersBlockedSendMsgToGroup($groupId);
  371. $this->assertArrayNotHasKey('code', $data);
  372. $this->assertEquals(0, count($data));
  373. $this->assertTrue($this->group->destroyGroup($groupId));
  374. $this->assertTrue($this->user->delete($randomOwnerUsername));
  375. $this->assertTrue($this->user->delete($randomMemberUsername));
  376. }
  377. }