[ Index ] |
PHP Cross Reference of BuddyPress |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @group groups 4 * @group BP_Group_Member_Query 5 */ 6 class BP_Tests_BP_Group_Member_Query_TestCases extends BP_UnitTestCase { 7 8 /** 9 * Make sure that a manual 'include' param is parsed correctly with 10 * BP_Group_Member_Query's limiting of the query to group members 11 */ 12 public function test_with_include() { 13 $g = self::factory()->group->create(); 14 $u1 = self::factory()->user->create(); 15 $u2 = self::factory()->user->create(); 16 $u3 = self::factory()->user->create(); 17 $time = time(); 18 19 $this->add_user_to_group( $u1, $g, array( 'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 100 ) ) ); 20 $this->add_user_to_group( $u2, $g, array( 'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 200 ) ) ); 21 22 $query = new BP_Group_Member_Query( array( 23 'group_id' => $g, 24 'include' => array( $u2 ), 25 ) ); 26 27 $ids = wp_parse_id_list( array_keys( $query->results ) ); 28 $this->assertEquals( array( $u2, ), $ids ); 29 } 30 31 // Make sure we're falling back on 'member' 32 public function test_with_group_role_null() { 33 $g = self::factory()->group->create(); 34 $u1 = self::factory()->user->create(); 35 $u2 = self::factory()->user->create(); 36 $u3 = self::factory()->user->create(); 37 $time = time(); 38 39 $this->add_user_to_group( $u1, $g, array( 'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 100 ) ) ); 40 $this->add_user_to_group( $u2, $g, array( 'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 200 ) ) ); 41 $this->add_user_to_group( $u3, $g, array( 'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 300 ) ) ); 42 43 $m1 = new BP_Groups_Member( $u1, $g ); 44 $m1->promote( 'admin' ); 45 $m2 = new BP_Groups_Member( $u2, $g ); 46 $m2->promote( 'mod' ); 47 48 $query = new BP_Group_Member_Query( array( 49 'group_id' => $g, 50 ) ); 51 52 $expected = new BP_Group_Member_Query( array( 53 'group_id' => $g, 54 'group_role' => array( 'member' ), 55 ) ); 56 57 $this->assertEquals( $expected->results, $query->results ); 58 } 59 60 public function test_with_group_role_member() { 61 $g = self::factory()->group->create(); 62 $u1 = self::factory()->user->create(); 63 $u2 = self::factory()->user->create(); 64 $u3 = self::factory()->user->create(); 65 $time = time(); 66 67 $this->add_user_to_group( $u1, $g, array( 'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 100 ) ) ); 68 $this->add_user_to_group( $u2, $g, array( 'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 200 ) ) ); 69 $this->add_user_to_group( $u3, $g, array( 'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 300 ) ) ); 70 71 $m1 = new BP_Groups_Member( $u1, $g ); 72 $m1->promote( 'admin' ); 73 $m2 = new BP_Groups_Member( $u2, $g ); 74 $m2->promote( 'mod' ); 75 76 $query_members = new BP_Group_Member_Query( array( 77 'group_id' => $g, 78 'group_role' => array( 'member' ), 79 ) ); 80 81 $ids = wp_parse_id_list( array_keys( $query_members->results ) ); 82 $this->assertEquals( array( $u3, ), $ids ); 83 } 84 85 public function test_with_group_role_mod() { 86 $g = self::factory()->group->create(); 87 $u1 = self::factory()->user->create(); 88 $u2 = self::factory()->user->create(); 89 $u3 = self::factory()->user->create(); 90 $time = time(); 91 92 $this->add_user_to_group( $u1, $g, array( 'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 100 ) ) ); 93 $this->add_user_to_group( $u2, $g, array( 'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 200 ) ) ); 94 $this->add_user_to_group( $u3, $g, array( 'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 300 ) ) ); 95 96 $m1 = new BP_Groups_Member( $u1, $g ); 97 $m1->promote( 'admin' ); 98 $m2 = new BP_Groups_Member( $u2, $g ); 99 $m2->promote( 'mod' ); 100 101 $query_members = new BP_Group_Member_Query( array( 102 'group_id' => $g, 103 'group_role' => array( 'mod' ), 104 ) ); 105 106 $ids = wp_parse_id_list( array_keys( $query_members->results ) ); 107 $this->assertEquals( array( $u2, ), $ids ); 108 } 109 110 public function test_with_group_role_admin() { 111 $u1 = self::factory()->user->create(); 112 $u2 = self::factory()->user->create(); 113 $u3 = self::factory()->user->create(); 114 $g = self::factory()->group->create( array( 115 'creator_id' => $u1 116 ) ); 117 $time = time(); 118 119 $this->add_user_to_group( $u1, $g, array( 'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 100 ) ) ); 120 $this->add_user_to_group( $u2, $g, array( 'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 200 ) ) ); 121 $this->add_user_to_group( $u3, $g, array( 'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 300 ) ) ); 122 123 $m1 = new BP_Groups_Member( $u1, $g ); 124 $m1->promote( 'admin' ); 125 $m2 = new BP_Groups_Member( $u2, $g ); 126 $m2->promote( 'mod' ); 127 128 $query_members = new BP_Group_Member_Query( array( 129 'group_id' => $g, 130 'group_role' => array( 'admin' ), 131 ) ); 132 133 $ids = wp_parse_id_list( array_keys( $query_members->results ) ); 134 $this->assertEquals( array( $u1, ), $ids ); 135 } 136 137 public function test_with_group_role_member_mod() { 138 $g = self::factory()->group->create(); 139 $u1 = self::factory()->user->create(); 140 $u2 = self::factory()->user->create(); 141 $u3 = self::factory()->user->create(); 142 $time = time(); 143 144 $this->add_user_to_group( $u1, $g, array( 'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 100 ) ) ); 145 $this->add_user_to_group( $u2, $g, array( 'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 200 ) ) ); 146 $this->add_user_to_group( $u3, $g, array( 'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 300 ) ) ); 147 148 $m1 = new BP_Groups_Member( $u1, $g ); 149 $m1->promote( 'admin' ); 150 $m2 = new BP_Groups_Member( $u2, $g ); 151 $m2->promote( 'mod' ); 152 153 $query_members = new BP_Group_Member_Query( array( 154 'group_id' => $g, 155 'group_role' => array( 'member', 'mod' ), 156 ) ); 157 158 $ids = wp_parse_id_list( array_keys( $query_members->results ) ); 159 $this->assertEquals( array( $u2, $u3, ), $ids ); 160 } 161 162 public function test_with_group_role_member_admin() { 163 $u1 = self::factory()->user->create(); 164 $u2 = self::factory()->user->create(); 165 $u3 = self::factory()->user->create(); 166 $g = self::factory()->group->create( array( 167 'creator_id' => $u1, 168 ) ); 169 $time = time(); 170 171 $this->add_user_to_group( $u1, $g, array( 'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 100 ) ) ); 172 $this->add_user_to_group( $u2, $g, array( 'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 200 ) ) ); 173 $this->add_user_to_group( $u3, $g, array( 'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 300 ) ) ); 174 175 $m1 = new BP_Groups_Member( $u1, $g ); 176 $m1->promote( 'admin' ); 177 $m2 = new BP_Groups_Member( $u2, $g ); 178 $m2->promote( 'mod' ); 179 180 $query_members = new BP_Group_Member_Query( array( 181 'group_id' => $g, 182 'group_role' => array( 'member', 'admin' ), 183 ) ); 184 185 $ids = wp_parse_id_list( array_keys( $query_members->results ) ); 186 $this->assertEquals( array( $u1, $u3, ), $ids ); 187 } 188 189 public function test_with_group_role_mod_admin() { 190 $u1 = self::factory()->user->create(); 191 $u2 = self::factory()->user->create(); 192 $u3 = self::factory()->user->create(); 193 $g = self::factory()->group->create( array( 194 'creator_id' => $u1, 195 ) ); 196 $time = time(); 197 198 $this->add_user_to_group( $u1, $g, array( 'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 100 ) ) ); 199 $this->add_user_to_group( $u2, $g, array( 'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 200 ) ) ); 200 $this->add_user_to_group( $u3, $g, array( 'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 300 ) ) ); 201 202 $m1 = new BP_Groups_Member( $u1, $g ); 203 $m1->promote( 'admin' ); 204 $m2 = new BP_Groups_Member( $u2, $g ); 205 $m2->promote( 'mod' ); 206 207 $query_members = new BP_Group_Member_Query( array( 208 'group_id' => $g, 209 'group_role' => array( 'mod', 'admin' ), 210 ) ); 211 212 $ids = wp_parse_id_list( array_keys( $query_members->results ) ); 213 $this->assertEquals( array( $u1, $u2, ), $ids ); 214 } 215 216 public function test_with_group_role_member_mod_admin() { 217 $u1 = self::factory()->user->create(); 218 $u2 = self::factory()->user->create(); 219 $u3 = self::factory()->user->create(); 220 $g = self::factory()->group->create( array( 221 'creator_id' => $u1, 222 ) ); 223 $time = time(); 224 225 $this->add_user_to_group( $u1, $g, array( 'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 100 ) ) ); 226 $this->add_user_to_group( $u2, $g, array( 'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 200 ) ) ); 227 $this->add_user_to_group( $u3, $g, array( 'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 300 ) ) ); 228 229 $m1 = new BP_Groups_Member( $u1, $g ); 230 $m1->promote( 'admin' ); 231 $m2 = new BP_Groups_Member( $u2, $g ); 232 $m2->promote( 'mod' ); 233 234 $query_members = new BP_Group_Member_Query( array( 235 'group_id' => $g, 236 'group_role' => array( 'member', 'mod', 'admin' ), 237 ) ); 238 239 $ids = wp_parse_id_list( array_keys( $query_members->results ) ); 240 $this->assertEquals( array( $u1, $u2, $u3, ), $ids ); 241 } 242 243 public function test_with_group_role_member_mod_admin_banned() { 244 $u1 = self::factory()->user->create(); 245 $u2 = self::factory()->user->create(); 246 $u3 = self::factory()->user->create(); 247 $u4 = self::factory()->user->create(); 248 $g = self::factory()->group->create( array( 249 'creator_id' => $u1, 250 ) ); 251 $time = time(); 252 253 $this->add_user_to_group( $u1, $g, array( 'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 100 ) ) ); 254 $this->add_user_to_group( $u2, $g, array( 'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 200 ) ) ); 255 $this->add_user_to_group( $u3, $g, array( 'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 300 ) ) ); 256 $this->add_user_to_group( $u4, $g, array( 'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 300 ) ) ); 257 258 $m1 = new BP_Groups_Member( $u1, $g ); 259 $m1->promote( 'admin' ); 260 $m2 = new BP_Groups_Member( $u2, $g ); 261 $m2->promote( 'mod' ); 262 $m3 = new BP_Groups_Member( $u3, $g ); 263 $m3->ban(); 264 265 $query_members = new BP_Group_Member_Query( array( 266 'group_id' => $g, 267 'group_role' => array( 'member', 'mod', 'admin', 'banned' ), 268 ) ); 269 270 $ids = wp_parse_id_list( array_keys( $query_members->results ) ); 271 $this->assertEquals( array( $u1, $u2, $u3, $u4, ), $ids ); 272 } 273 274 /** 275 * @group role 276 */ 277 public function test_with_group_role_banned() { 278 $g = self::factory()->group->create(); 279 $u1 = self::factory()->user->create(); 280 $u2 = self::factory()->user->create(); 281 $time = time(); 282 283 $this->add_user_to_group( $u1, $g, array( 'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 100 ) ) ); 284 $this->add_user_to_group( $u2, $g, array( 'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 200 ) ) ); 285 286 $m1 = new BP_Groups_Member( $u1, $g ); 287 $m1->ban(); 288 289 $query_members = new BP_Group_Member_Query( array( 290 'group_id' => $g, 291 'group_role' => array( 'banned' ), 292 ) ); 293 294 $ids = wp_parse_id_list( array_keys( $query_members->results ) ); 295 $this->assertEquals( array( $u1, ), $ids ); 296 } 297 298 public function test_group_has_no_members_of_role_mod() { 299 $g = self::factory()->group->create(); 300 $u1 = self::factory()->user->create(); 301 $time = time(); 302 303 $this->add_user_to_group( $u1, $g, array( 'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 100 ) ) ); 304 305 $query_members = new BP_Group_Member_Query( array( 306 'group_id' => $g, 307 'group_role' => array( 'mod' ), 308 ) ); 309 310 $ids = wp_parse_id_list( array_keys( $query_members->results ) ); 311 $this->assertEquals( array(), $ids ); 312 } 313 314 public function test_confirmed_members() { 315 $u = self::factory()->user->create(); 316 $g = self::factory()->group->create( array( 'status' => 'private', 'creator_id' => $u ) ); 317 $u1 = self::factory()->user->create(); 318 $u2 = self::factory()->user->create(); 319 $u3 = self::factory()->user->create(); 320 $time = time(); 321 322 groups_send_membership_request( array( 323 'user_id' => $u1, 324 'group_id' => $g 325 ) ); 326 327 groups_invite_user( array( 328 'user_id' => $u2, 329 'group_id' => $g, 330 'inviter_id' => $u, 331 'send_invite' => 1 332 ) ); 333 334 $this->add_user_to_group( $u3, $g, array( 335 'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 100 ), 336 'is_confirmed' => 1, 337 ) ); 338 339 $query_members = new BP_Group_Member_Query( array( 340 'group_id' => $g, 341 ) ); 342 343 $ids = wp_parse_id_list( array_keys( $query_members->results ) ); 344 $this->assertEquals( array( $u3 ), $ids ); 345 } 346 347 /** 348 * @group type 349 */ 350 public function test_get_with_type_last_joined() { 351 $g = self::factory()->group->create(); 352 $u1 = self::factory()->user->create(); 353 $u2 = self::factory()->user->create(); 354 $time = time(); 355 356 $this->add_user_to_group( $u1, $g, array( 357 'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 500 ), 358 ) ); 359 360 $this->add_user_to_group( $u2, $g, array( 361 'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 100 ), 362 ) ); 363 364 $query_members = new BP_Group_Member_Query( array( 365 'group_id' => $g, 366 'type' => 'last_joined', 367 ) ); 368 369 $ids = wp_parse_id_list( array_keys( $query_members->results ) ); 370 $this->assertEquals( array( $u2, $u1 ), $ids ); 371 } 372 373 /** 374 * @group type 375 */ 376 public function test_get_with_type_first_joined() { 377 $g = self::factory()->group->create(); 378 $u1 = self::factory()->user->create(); 379 $u2 = self::factory()->user->create(); 380 $time = time(); 381 382 $this->add_user_to_group( $u1, $g, array( 383 'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 500 ), 384 ) ); 385 386 $this->add_user_to_group( $u2, $g, array( 387 'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 100 ), 388 ) ); 389 390 $query_members = new BP_Group_Member_Query( array( 391 'group_id' => $g, 392 'type' => 'first_joined', 393 ) ); 394 395 $ids = wp_parse_id_list( array_keys( $query_members->results ) ); 396 $this->assertEquals( array( $u1, $u2 ), $ids ); 397 } 398 399 /** 400 * @group type 401 * @group group_activity 402 */ 403 public function test_get_with_type_group_activity_with_activity_component_disabled() { 404 $g = self::factory()->group->create(); 405 $u1 = self::factory()->user->create(); 406 $u2 = self::factory()->user->create(); 407 $u3 = self::factory()->user->create(); 408 $c = buddypress()->groups->id; 409 $time = time(); 410 411 $this->add_user_to_group( $u1, $g, array( 412 'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 500 ), 413 ) ); 414 415 $this->add_user_to_group( $u2, $g, array( 416 'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 400 ), 417 ) ); 418 419 $this->add_user_to_group( $u3, $g, array( 420 'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 300 ), 421 ) ); 422 423 self::factory()->activity->create( array( 424 'component' => $c, 425 'type' => 'activity_update', 426 'user_id' => $u3, 427 'item_id' => $g, 428 'recorded_time' => gmdate( 'Y-m-d H:i:s', $time - 250 ), 429 ) ); 430 431 self::factory()->activity->create( array( 432 'component' => $c, 433 'type' => 'activity_update', 434 'user_id' => $u1, 435 'item_id' => $g, 436 'recorded_time' => gmdate( 'Y-m-d H:i:s', $time - 200 ), 437 ) ); 438 439 self::factory()->activity->create( array( 440 'component' => $c, 441 'type' => 'activity_update', 442 'user_id' => $u2, 443 'item_id' => $g, 444 'recorded_time' => gmdate( 'Y-m-d H:i:s', $time - 100 ), 445 ) ); 446 447 // Deactivate activity component 448 $activity_active = isset( buddypress()->active_components['activity'] ); 449 if ( $activity_active ) { 450 unset( buddypress()->active_components['activity'] ); 451 } 452 453 $query_members1 = new BP_Group_Member_Query( array( 454 'group_id' => $g, 455 'type' => 'group_activity', 456 ) ); 457 458 $query_members2 = new BP_Group_Member_Query( array( 459 'group_id' => $g, 460 'type' => 'last_joined', 461 ) ); 462 463 if ( $activity_active ) { 464 buddypress()->active_components['activity'] = '1'; 465 } 466 467 $this->assertSame( wp_list_pluck( $query_members2->results, 'ID' ), wp_list_pluck( $query_members1->results, 'ID' ) ); 468 } 469 470 /** 471 * @group type 472 * @group group_activity 473 */ 474 public function test_get_with_type_group_activity() { 475 $g = self::factory()->group->create(); 476 $u1 = self::factory()->user->create(); 477 $u2 = self::factory()->user->create(); 478 $u3 = self::factory()->user->create(); 479 $c = buddypress()->groups->id; 480 $time = time(); 481 482 $this->add_user_to_group( $u1, $g, array( 483 'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 500 ), 484 ) ); 485 486 $this->add_user_to_group( $u2, $g, array( 487 'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 400 ), 488 ) ); 489 490 $this->add_user_to_group( $u3, $g, array( 491 'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 300 ), 492 ) ); 493 494 self::factory()->activity->create( array( 495 'component' => $c, 496 'type' => 'activity_update', 497 'user_id' => $u3, 498 'item_id' => $g, 499 'recorded_time' => gmdate( 'Y-m-d H:i:s', $time - 250 ), 500 ) ); 501 502 self::factory()->activity->create( array( 503 'component' => $c, 504 'type' => 'activity_update', 505 'user_id' => $u1, 506 'item_id' => $g, 507 'recorded_time' => gmdate( 'Y-m-d H:i:s', $time - 200 ), 508 ) ); 509 510 self::factory()->activity->create( array( 511 'component' => $c, 512 'type' => 'activity_update', 513 'user_id' => $u2, 514 'item_id' => $g, 515 'recorded_time' => gmdate( 'Y-m-d H:i:s', $time - 100 ), 516 ) ); 517 518 $query_members = new BP_Group_Member_Query( array( 519 'group_id' => $g, 520 'type' => 'group_activity', 521 ) ); 522 523 $ids = wp_parse_id_list( array_keys( $query_members->results ) ); 524 $this->assertEquals( array( $u2, $u1, $u3 ), $ids ); 525 } 526 527 /** 528 * @group type 529 * @group group_activity 530 */ 531 public function test_get_with_type_group_activity_no_dupes() { 532 $g = self::factory()->group->create(); 533 $u1 = self::factory()->user->create(); 534 $c = buddypress()->groups->id; 535 $time = time(); 536 537 $this->add_user_to_group( $u1, $g, array( 538 'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 500 ), 539 ) ); 540 541 self::factory()->activity->create( array( 542 'component' => $c, 543 'type' => 'activity_update', 544 'user_id' => $u1, 545 'item_id' => $g, 546 'recorded_time' => gmdate( 'Y-m-d H:i:s', $time - 250 ), 547 ) ); 548 549 self::factory()->activity->create( array( 550 'component' => $c, 551 'type' => 'activity_update', 552 'user_id' => $u1, 553 'item_id' => $g, 554 'recorded_time' => gmdate( 'Y-m-d H:i:s', $time - 200 ), 555 ) ); 556 557 $query_members = new BP_Group_Member_Query( array( 558 'group_id' => $g, 559 'type' => 'group_activity', 560 ) ); 561 562 $ids = wp_parse_id_list( array_keys( $query_members->results ) ); 563 $this->assertEquals( array( $u1, ), $ids ); 564 } 565 /** 566 * @group type 567 */ 568 public function test_get_with_type_alphabetical() { 569 $g = self::factory()->group->create(); 570 $u1 = self::factory()->user->create( array( 571 'display_name' => 'AAA', 572 ) ); 573 $u2 = self::factory()->user->create( array( 574 'display_name' => 'CCC', 575 ) ); 576 $u3 = self::factory()->user->create( array( 577 'display_name' => 'BBB', 578 ) ); 579 $time = time(); 580 581 $this->add_user_to_group( $u1, $g, array( 582 'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 100 ), 583 ) ); 584 585 $this->add_user_to_group( $u2, $g, array( 586 'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 200 ), 587 ) ); 588 589 $this->add_user_to_group( $u3, $g, array( 590 'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 300 ), 591 ) ); 592 593 $query_members = new BP_Group_Member_Query( array( 594 'group_id' => $g, 595 'type' => 'alphabetical', 596 ) ); 597 598 $ids = wp_parse_id_list( array_keys( $query_members->results ) ); 599 $this->assertEquals( array( $u1, $u3, $u2 ), $ids ); 600 } 601 602 /** 603 * @group invite_sent 604 */ 605 public function test_with_invite_sent_true() { 606 $u = self::factory()->user->create(); 607 $g = self::factory()->group->create( array( 'status' => 'private', 'creator_id' => $u ) ); 608 $u1 = self::factory()->user->create(); 609 $u2 = self::factory()->user->create(); 610 611 groups_invite_user( array( 612 'user_id' => $u1, 613 'group_id' => $g, 614 'inviter_id' => $u, 615 'send_invite' => 0 616 ) ); 617 618 groups_invite_user( array( 619 'user_id' => $u2, 620 'group_id' => $g, 621 'inviter_id' => $u, 622 'send_invite' => 1 623 ) ); 624 625 $query_members = new BP_Group_Member_Query( array( 626 'group_id' => $g, 627 'is_confirmed' => false, 628 'invite_sent' => true, 629 ) ); 630 631 $ids = wp_parse_id_list( array_keys( $query_members->results ) ); 632 $this->assertEquals( array( $u2 ), $ids ); 633 } 634 635 /** 636 * @group invite_sent 637 */ 638 public function test_with_invite_sent_false() { 639 $u = self::factory()->user->create(); 640 $g = self::factory()->group->create( array( 'status' => 'private', 'creator_id' => $u ) ); 641 $u1 = self::factory()->user->create(); 642 $u2 = self::factory()->user->create(); 643 644 groups_invite_user( array( 645 'user_id' => $u1, 646 'group_id' => $g, 647 'inviter_id' => $u, 648 'send_invite' => 0 649 ) ); 650 651 groups_invite_user( array( 652 'user_id' => $u2, 653 'group_id' => $g, 654 'inviter_id' => $u, 655 'send_invite' => 1 656 ) ); 657 658 $query_members = new BP_Group_Member_Query( array( 659 'group_id' => $g, 660 'is_confirmed' => false, 661 'invite_sent' => false, 662 ) ); 663 664 $ids = wp_parse_id_list( array_keys( $query_members->results ) ); 665 $this->assertEquals( array( $u1 ), $ids ); 666 } 667 668 /** 669 * @group inviter_id 670 */ 671 public function test_with_inviter_id_false() { 672 $u = self::factory()->user->create(); 673 $g = self::factory()->group->create( array( 'status' => 'private', 'creator_id' => $u ) ); 674 $u1 = self::factory()->user->create(); 675 $u2 = self::factory()->user->create(); 676 677 groups_send_membership_request( array( 678 'user_id' => $u1, 679 'group_id' => $g 680 ) ); 681 682 groups_invite_user( array( 683 'user_id' => $u2, 684 'group_id' => $g, 685 'inviter_id' => $u, 686 'send_invite' => 1 687 ) ); 688 689 $query_members = new BP_Group_Member_Query( array( 690 'group_id' => $g, 691 'inviter_id' => false, 692 ) ); 693 694 $ids = wp_parse_id_list( array_keys( $query_members->results ) ); 695 $this->assertEquals( array( $u1 ), $ids ); 696 } 697 698 /** 699 * @group inviter_id 700 */ 701 public function test_with_inviter_id_specific() { 702 $a1 = self::factory()->user->create(); 703 $a2 = self::factory()->user->create(); 704 $a3 = self::factory()->user->create(); 705 $g = self::factory()->group->create( array( 'status' => 'private', 'creator_id' => $a1 ) ); 706 $this->add_user_to_group( $a2, $g, array( 'is_admin' => 1 ) ); 707 $this->add_user_to_group( $a3, $g, array( 'is_admin' => 1 ) ); 708 709 $u1 = self::factory()->user->create(); 710 $u2 = self::factory()->user->create(); 711 $u3 = self::factory()->user->create(); 712 $u4 = self::factory()->user->create(); 713 714 groups_send_membership_request( array( 715 'user_id' => $u1, 716 'group_id' => $g 717 ) ); 718 719 groups_invite_user( array( 720 'user_id' => $u2, 721 'group_id' => $g, 722 'inviter_id' => $a1, 723 'send_invite' => 1 724 ) ); 725 groups_invite_user( array( 726 'user_id' => $u3, 727 'group_id' => $g, 728 'inviter_id' => $a2, 729 'send_invite' => 1 730 ) ); 731 groups_invite_user( array( 732 'user_id' => $u4, 733 'group_id' => $g, 734 'inviter_id' => $a3, 735 'send_invite' => 1 736 ) ); 737 738 $query_members = new BP_Group_Member_Query( array( 739 'group_id' => $g, 740 'inviter_id' => array( $a1, $a3 ), 741 ) ); 742 743 $ids = wp_parse_id_list( array_keys( $query_members->results ) ); 744 $this->assertEquals( array( $u2, $u4 ), $ids ); 745 } 746 747 /** 748 * @group inviter_id 749 */ 750 public function test_with_inviter_id_any() { 751 $a1 = self::factory()->user->create(); 752 $a2 = self::factory()->user->create(); 753 $a3 = self::factory()->user->create(); 754 $g = self::factory()->group->create( array( 'status' => 'private', 'creator_id' => $a1 ) ); 755 $this->add_user_to_group( $a2, $g, array( 'is_admin' => 1 ) ); 756 $this->add_user_to_group( $a3, $g, array( 'is_admin' => 1 ) ); 757 758 $u1 = self::factory()->user->create(); 759 $u2 = self::factory()->user->create(); 760 $u3 = self::factory()->user->create(); 761 $u4 = self::factory()->user->create(); 762 763 groups_send_membership_request( array( 764 'user_id' => $u1, 765 'group_id' => $g 766 ) ); 767 768 groups_invite_user( array( 769 'user_id' => $u2, 770 'group_id' => $g, 771 'inviter_id' => $a1, 772 'send_invite' => 1 773 ) ); 774 groups_invite_user( array( 775 'user_id' => $u3, 776 'group_id' => $g, 777 'inviter_id' => $a2, 778 'send_invite' => 1 779 ) ); 780 groups_invite_user( array( 781 'user_id' => $u4, 782 'group_id' => $g, 783 'inviter_id' => $a3, 784 'send_invite' => 1 785 ) ); 786 787 $query_members = new BP_Group_Member_Query( array( 788 'group_id' => $g, 789 'inviter_id' => 'any', 790 ) ); 791 792 $ids = wp_parse_id_list( array_keys( $query_members->results ) ); 793 $this->assertEquals( array( $u2, $u3, $u4 ), $ids ); 794 } 795 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Tue Dec 3 01:00:55 2024 | Cross-referenced by PHPXref 0.7.1 |