[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/tests/phpunit/testcases/groups/ -> class-bp-group-member-query.php (source)

   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          $g = self::factory()->group->create();
 316          $u1 = self::factory()->user->create();
 317          $u2 = self::factory()->user->create();
 318          $time = time();
 319  
 320          $this->add_user_to_group( $u1, $g, array(
 321              'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 100 ),
 322              'is_confirmed' => 0,
 323          ) );
 324  
 325          $this->add_user_to_group( $u2, $g, array(
 326              'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 100 ),
 327              'is_confirmed' => 1,
 328          ) );
 329  
 330          $query_members = new BP_Group_Member_Query( array(
 331              'group_id' => $g,
 332          ) );
 333  
 334          $ids = wp_parse_id_list( array_keys( $query_members->results ) );
 335          $this->assertEquals( array( $u2 ), $ids );
 336      }
 337  
 338      /**
 339       * @group type
 340       */
 341  	public function test_get_with_type_last_joined() {
 342          $g = self::factory()->group->create();
 343          $u1 = self::factory()->user->create();
 344          $u2 = self::factory()->user->create();
 345          $time = time();
 346  
 347          $this->add_user_to_group( $u1, $g, array(
 348              'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 500 ),
 349          ) );
 350  
 351          $this->add_user_to_group( $u2, $g, array(
 352              'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 100 ),
 353          ) );
 354  
 355          $query_members = new BP_Group_Member_Query( array(
 356              'group_id' => $g,
 357              'type' => 'last_joined',
 358          ) );
 359  
 360          $ids = wp_parse_id_list( array_keys( $query_members->results ) );
 361          $this->assertEquals( array( $u2, $u1 ), $ids );
 362      }
 363  
 364      /**
 365       * @group type
 366       */
 367  	public function test_get_with_type_first_joined() {
 368          $g = self::factory()->group->create();
 369          $u1 = self::factory()->user->create();
 370          $u2 = self::factory()->user->create();
 371          $time = time();
 372  
 373          $this->add_user_to_group( $u1, $g, array(
 374              'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 500 ),
 375          ) );
 376  
 377          $this->add_user_to_group( $u2, $g, array(
 378              'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 100 ),
 379          ) );
 380  
 381          $query_members = new BP_Group_Member_Query( array(
 382              'group_id' => $g,
 383              'type' => 'first_joined',
 384          ) );
 385  
 386          $ids = wp_parse_id_list( array_keys( $query_members->results ) );
 387          $this->assertEquals( array( $u1, $u2 ), $ids );
 388      }
 389  
 390      /**
 391       * @group type
 392       * @group group_activity
 393       */
 394      public function test_get_with_type_group_activity_with_activity_component_disabled() {
 395          $g = self::factory()->group->create();
 396          $u1 = self::factory()->user->create();
 397          $u2 = self::factory()->user->create();
 398          $u3 = self::factory()->user->create();
 399          $c = buddypress()->groups->id;
 400          $time = time();
 401  
 402          $this->add_user_to_group( $u1, $g, array(
 403              'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 500 ),
 404          ) );
 405  
 406          $this->add_user_to_group( $u2, $g, array(
 407              'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 400 ),
 408          ) );
 409  
 410          $this->add_user_to_group( $u3, $g, array(
 411              'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 300 ),
 412          ) );
 413  
 414          self::factory()->activity->create( array(
 415              'component' => $c,
 416              'type' => 'activity_update',
 417              'user_id' => $u3,
 418              'item_id' => $g,
 419              'recorded_time' => gmdate( 'Y-m-d H:i:s', $time - 250 ),
 420          ) );
 421  
 422          self::factory()->activity->create( array(
 423              'component' => $c,
 424              'type' => 'activity_update',
 425              'user_id' => $u1,
 426              'item_id' => $g,
 427              'recorded_time' => gmdate( 'Y-m-d H:i:s', $time - 200 ),
 428          ) );
 429  
 430          self::factory()->activity->create( array(
 431              'component' => $c,
 432              'type' => 'activity_update',
 433              'user_id' => $u2,
 434              'item_id' => $g,
 435              'recorded_time' => gmdate( 'Y-m-d H:i:s', $time - 100 ),
 436          ) );
 437  
 438          // Deactivate activity component
 439          $activity_active = isset( buddypress()->active_components['activity'] );
 440          if ( $activity_active ) {
 441              unset( buddypress()->active_components['activity'] );
 442          }
 443  
 444          $query_members1 = new BP_Group_Member_Query( array(
 445              'group_id' => $g,
 446              'type' => 'group_activity',
 447          ) );
 448  
 449          $query_members2 = new BP_Group_Member_Query( array(
 450              'group_id' => $g,
 451              'type' => 'last_joined',
 452          ) );
 453  
 454          if ( $activity_active ) {
 455              buddypress()->active_components['activity'] = '1';
 456          }
 457  
 458          $this->assertSame( wp_list_pluck( $query_members2->results, 'ID' ), wp_list_pluck( $query_members1->results, 'ID' ) );
 459      }
 460  
 461      /**
 462       * @group type
 463       * @group group_activity
 464       */
 465  	public function test_get_with_type_group_activity() {
 466          $g = self::factory()->group->create();
 467          $u1 = self::factory()->user->create();
 468          $u2 = self::factory()->user->create();
 469          $u3 = self::factory()->user->create();
 470          $c = buddypress()->groups->id;
 471          $time = time();
 472  
 473          $this->add_user_to_group( $u1, $g, array(
 474              'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 500 ),
 475          ) );
 476  
 477          $this->add_user_to_group( $u2, $g, array(
 478              'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 400 ),
 479          ) );
 480  
 481          $this->add_user_to_group( $u3, $g, array(
 482              'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 300 ),
 483          ) );
 484  
 485          self::factory()->activity->create( array(
 486              'component' => $c,
 487              'type' => 'activity_update',
 488              'user_id' => $u3,
 489              'item_id' => $g,
 490              'recorded_time' => gmdate( 'Y-m-d H:i:s', $time - 250 ),
 491          ) );
 492  
 493          self::factory()->activity->create( array(
 494              'component' => $c,
 495              'type' => 'activity_update',
 496              'user_id' => $u1,
 497              'item_id' => $g,
 498              'recorded_time' => gmdate( 'Y-m-d H:i:s', $time - 200 ),
 499          ) );
 500  
 501          self::factory()->activity->create( array(
 502              'component' => $c,
 503              'type' => 'activity_update',
 504              'user_id' => $u2,
 505              'item_id' => $g,
 506              'recorded_time' => gmdate( 'Y-m-d H:i:s', $time - 100 ),
 507          ) );
 508  
 509          $query_members = new BP_Group_Member_Query( array(
 510              'group_id' => $g,
 511              'type' => 'group_activity',
 512          ) );
 513  
 514          $ids = wp_parse_id_list( array_keys( $query_members->results ) );
 515          $this->assertEquals( array( $u2, $u1, $u3 ), $ids );
 516      }
 517  
 518      /**
 519       * @group type
 520       * @group group_activity
 521       */
 522  	public function test_get_with_type_group_activity_no_dupes() {
 523          $g = self::factory()->group->create();
 524          $u1 = self::factory()->user->create();
 525          $c = buddypress()->groups->id;
 526          $time = time();
 527  
 528          $this->add_user_to_group( $u1, $g, array(
 529              'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 500 ),
 530          ) );
 531  
 532          self::factory()->activity->create( array(
 533              'component' => $c,
 534              'type' => 'activity_update',
 535              'user_id' => $u1,
 536              'item_id' => $g,
 537              'recorded_time' => gmdate( 'Y-m-d H:i:s', $time - 250 ),
 538          ) );
 539  
 540          self::factory()->activity->create( array(
 541              'component' => $c,
 542              'type' => 'activity_update',
 543              'user_id' => $u1,
 544              'item_id' => $g,
 545              'recorded_time' => gmdate( 'Y-m-d H:i:s', $time - 200 ),
 546          ) );
 547  
 548          $query_members = new BP_Group_Member_Query( array(
 549              'group_id' => $g,
 550              'type' => 'group_activity',
 551          ) );
 552  
 553          $ids = wp_parse_id_list( array_keys( $query_members->results ) );
 554          $this->assertEquals( array( $u1, ), $ids );
 555      }
 556      /**
 557       * @group type
 558       */
 559  	public function test_get_with_type_alphabetical() {
 560          $g = self::factory()->group->create();
 561          $u1 = self::factory()->user->create( array(
 562              'display_name' => 'AAA',
 563          ) );
 564          $u2 = self::factory()->user->create( array(
 565              'display_name' => 'CCC',
 566          ) );
 567          $u3 = self::factory()->user->create( array(
 568              'display_name' => 'BBB',
 569          ) );
 570          $time = time();
 571  
 572          $this->add_user_to_group( $u1, $g, array(
 573              'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 100 ),
 574          ) );
 575  
 576          $this->add_user_to_group( $u2, $g, array(
 577              'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 200 ),
 578          ) );
 579  
 580          $this->add_user_to_group( $u3, $g, array(
 581              'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 300 ),
 582          ) );
 583  
 584          $query_members = new BP_Group_Member_Query( array(
 585              'group_id' => $g,
 586              'type' => 'alphabetical',
 587          ) );
 588  
 589          $ids = wp_parse_id_list( array_keys( $query_members->results ) );
 590          $this->assertEquals( array( $u1, $u3, $u2 ), $ids );
 591      }
 592  
 593      /**
 594       * @group invite_sent
 595       */
 596  	public function test_with_invite_sent_true() {
 597          $g = self::factory()->group->create();
 598          $u1 = self::factory()->user->create();
 599          $u2 = self::factory()->user->create();
 600          $time = time();
 601  
 602          $this->add_user_to_group( $u1, $g, array(
 603              'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 100 ),
 604              'is_confirmed' => 0,
 605              'invite_sent' => 0,
 606          ) );
 607  
 608          $this->add_user_to_group( $u2, $g, array(
 609              'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 100 ),
 610              'is_confirmed' => 0,
 611              'invite_sent' => 1,
 612          ) );
 613  
 614          $query_members = new BP_Group_Member_Query( array(
 615              'group_id' => $g,
 616              'is_confirmed' => false,
 617              'invite_sent' => true,
 618          ) );
 619  
 620          $ids = wp_parse_id_list( array_keys( $query_members->results ) );
 621          $this->assertEquals( array( $u2 ), $ids );
 622      }
 623  
 624      /**
 625       * @group invite_sent
 626       */
 627  	public function test_with_invite_sent_false() {
 628          $g = self::factory()->group->create();
 629          $u1 = self::factory()->user->create();
 630          $u2 = self::factory()->user->create();
 631          $time = time();
 632  
 633          $this->add_user_to_group( $u1, $g, array(
 634              'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 100 ),
 635              'is_confirmed' => 0,
 636              'invite_sent' => 0,
 637          ) );
 638  
 639          $this->add_user_to_group( $u2, $g, array(
 640              'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 100 ),
 641              'is_confirmed' => 0,
 642              'invite_sent' => 1,
 643          ) );
 644  
 645          $query_members = new BP_Group_Member_Query( array(
 646              'group_id' => $g,
 647              'is_confirmed' => false,
 648              'invite_sent' => false,
 649          ) );
 650  
 651          $ids = wp_parse_id_list( array_keys( $query_members->results ) );
 652          $this->assertEquals( array( $u1 ), $ids );
 653      }
 654  
 655      /**
 656       * @group inviter_id
 657       */
 658  	public function test_with_inviter_id_false() {
 659          $g = self::factory()->group->create();
 660          $u1 = self::factory()->user->create();
 661          $u2 = self::factory()->user->create();
 662          $time = time();
 663  
 664          $this->add_user_to_group( $u1, $g, array(
 665              'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 100 ),
 666              'inviter_id' => 0,
 667          ) );
 668  
 669          $this->add_user_to_group( $u2, $g, array(
 670              'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 100 ),
 671              'inviter_id' => 1,
 672          ) );
 673  
 674          $query_members = new BP_Group_Member_Query( array(
 675              'group_id' => $g,
 676              'inviter_id' => false,
 677          ) );
 678  
 679          $ids = wp_parse_id_list( array_keys( $query_members->results ) );
 680          $this->assertEquals( array( $u1 ), $ids );
 681      }
 682  
 683      /**
 684       * @group inviter_id
 685       */
 686  	public function test_with_inviter_id_specific() {
 687          $g = self::factory()->group->create();
 688          $u1 = self::factory()->user->create();
 689          $u2 = self::factory()->user->create();
 690          $u3 = self::factory()->user->create();
 691          $u4 = self::factory()->user->create();
 692          $time = time();
 693  
 694          $this->add_user_to_group( $u1, $g, array(
 695              'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 100 ),
 696              'inviter_id' => 0,
 697          ) );
 698  
 699          $this->add_user_to_group( $u2, $g, array(
 700              'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 200 ),
 701              'inviter_id' => 1,
 702          ) );
 703  
 704          $this->add_user_to_group( $u3, $g, array(
 705              'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 300 ),
 706              'inviter_id' => 6,
 707          ) );
 708  
 709          $this->add_user_to_group( $u4, $g, array(
 710              'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 400 ),
 711              'inviter_id' => 2,
 712          ) );
 713  
 714          $query_members = new BP_Group_Member_Query( array(
 715              'group_id' => $g,
 716              'inviter_id' => array( 2, 6 ),
 717          ) );
 718  
 719          $ids = wp_parse_id_list( array_keys( $query_members->results ) );
 720          $this->assertEquals( array( $u3, $u4 ), $ids );
 721      }
 722  
 723      /**
 724       * @group inviter_id
 725       */
 726  	public function test_with_inviter_id_any() {
 727          $g = self::factory()->group->create();
 728          $u1 = self::factory()->user->create();
 729          $u2 = self::factory()->user->create();
 730          $u3 = self::factory()->user->create();
 731          $u4 = self::factory()->user->create();
 732          $time = time();
 733  
 734          $this->add_user_to_group( $u1, $g, array(
 735              'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 100 ),
 736              'inviter_id' => 0,
 737          ) );
 738  
 739          $this->add_user_to_group( $u2, $g, array(
 740              'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 200 ),
 741              'inviter_id' => 1,
 742          ) );
 743  
 744          $this->add_user_to_group( $u3, $g, array(
 745              'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 300 ),
 746              'inviter_id' => 6,
 747          ) );
 748  
 749          $this->add_user_to_group( $u4, $g, array(
 750              'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 400 ),
 751              'inviter_id' => 2,
 752          ) );
 753  
 754          $query_members = new BP_Group_Member_Query( array(
 755              'group_id' => $g,
 756              'inviter_id' => 'any',
 757          ) );
 758  
 759          $ids = wp_parse_id_list( array_keys( $query_members->results ) );
 760          $this->assertEquals( array( $u2, $u3, $u4 ), $ids );
 761      }
 762  }


Generated: Mon Jul 22 01:01:43 2019 Cross-referenced by PHPXref 0.7.1