[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/tests/phpunit/testcases/members/ -> template.php (source)

   1  <?php
   2  /**
   3   * @group members
   4   */
   5  class BP_Tests_Members_Template extends BP_UnitTestCase {
   6  	public function test_bp_has_members_include_on_user_page() {
   7          $u1 = self::factory()->user->create();
   8          $u2 = self::factory()->user->create();
   9  
  10          $this->go_to( bp_core_get_user_domain( $u1 ) );
  11  
  12          global $members_template;
  13          bp_has_members( array(
  14              'include' => array( $u1, $u2 ),
  15          ) );
  16  
  17          $users = is_array( $members_template->members ) ? array_values( $members_template->members ) : array();
  18          $user_ids = wp_list_pluck( $users, 'ID' );
  19          sort( $user_ids );
  20  
  21          $shouldbe = array( $u1, $u2 );
  22          sort( $shouldbe );
  23  
  24          $this->assertEquals( $user_ids, $shouldbe );
  25      }
  26  
  27      /**
  28       * @ticket BP5898
  29       * @group bp_has_members
  30       */
  31      public function test_bp_has_members_search_pagination_with_spaces() {
  32          $u1 = self::factory()->user->create( array( 'display_name' => '~ tilde u1' ) );
  33          $u2 = self::factory()->user->create( array( 'display_name' => '~ tilde u2' ) );
  34  
  35          $template_args = array(
  36              'search_terms' => '~ tilde',
  37              'per_page'     => 1,
  38          );
  39  
  40          global $members_template;
  41          $reset_members_template = $members_template;
  42  
  43          bp_has_members( $template_args );
  44  
  45          preg_match( '/&#038;members_search=(.*)(\'|\")/', $members_template->pag_links, $matches );
  46  
  47          $this->assertEquals( urldecode( $matches[1] ), urldecode( $template_args['search_terms'] ) );
  48  
  49          // reset the members template global
  50          $members_template = $reset_members_template;
  51      }
  52  
  53  	public function test_bp_has_members_friendship_requests() {
  54          $u1 = self::factory()->user->create();
  55          $u2 = self::factory()->user->create();
  56  
  57          friends_add_friend( $u1, $u2 );
  58  
  59          $old_user = get_current_user_id();
  60          $this->set_current_user( $u2 );
  61  
  62          $this->go_to( bp_core_get_user_domain( $u2 ) . bp_get_friends_slug() . '/requests/' );
  63          $this->restore_admins();
  64  
  65          global $members_template;
  66          bp_has_members( array(
  67              'include' => bp_get_friendship_requests( $u2 ),
  68          ) );
  69  
  70          $requests = is_array( $members_template->members ) ? array_values( $members_template->members ) : array();
  71          $request_ids = wp_list_pluck( $requests, 'ID' );
  72          $this->assertEquals( $request_ids, array( $u1 ) );
  73  
  74          $this->set_current_user( $old_user );
  75      }
  76  
  77      /**
  78       * @group bp_has_members
  79       * @group friends
  80       * @ticket BP5071
  81       */
  82      public function test_bp_has_members_friendship_requests_with_no_requests() {
  83          $u1 = self::factory()->user->create();
  84          $u2 = self::factory()->user->create();
  85  
  86          $old_user = get_current_user_id();
  87          $this->set_current_user( $u2 );
  88  
  89          // For some reason, in all the user switching, the cache gets
  90          // confused. Never comes up when BP runs normally, because the
  91          // loggedin_user doesn't change on a pageload. @todo Fix for
  92          // real in BP
  93          wp_cache_delete( 'bp_user_domain_' . $u2, 'bp' );
  94  
  95          $this->go_to( bp_core_get_user_domain( $u2 ) . bp_get_friends_slug() . '/requests/' );
  96          $this->restore_admins();
  97  
  98          global $members_template;
  99          bp_has_members( array(
 100              'include' => bp_get_friendship_requests( $u2 ),
 101          ) );
 102  
 103          $requests = is_array( $members_template->members ) ? array_values( $members_template->members ) : array();
 104          $request_ids = wp_list_pluck( $requests, 'ID' );
 105          $this->assertEquals( array(), $request_ids );
 106  
 107          $this->set_current_user( $old_user );
 108      }
 109  
 110      /**
 111       * @group bp_has_members
 112       */
 113      public function test_bp_has_members_should_pass_member_type_param_to_query() {
 114          bp_register_member_type( 'foo' );
 115          bp_register_member_type( 'bar' );
 116          $users = self::factory()->user->create_many( 3 );
 117          bp_set_member_type( $users[0], 'foo' );
 118          bp_set_member_type( $users[1], 'bar' );
 119  
 120          global $members_template;
 121          $old_members_template = $members_template;
 122  
 123          bp_has_members( array(
 124              'member_type' => 'bar',
 125          ) );
 126  
 127          $members = is_array( $members_template->members ) ? array_values( $members_template->members ) : array();
 128          $member_ids = wp_list_pluck( $members, 'ID' );
 129          $this->assertEquals( array( $users[1]), $member_ids );
 130  
 131          $GLOBALS['members_template'] = $old_members_template;
 132      }
 133  
 134      /**
 135       * @group bp_has_members
 136       * @ticket BP6286
 137       */
 138      public function test_bp_has_members_should_infer_member_type_from_get_param() {
 139          bp_register_member_type( 'foo' );
 140          bp_register_member_type( 'bar' );
 141          $users = self::factory()->user->create_many( 3 );
 142          bp_set_member_type( $users[0], 'foo' );
 143          bp_set_member_type( $users[1], 'bar' );
 144  
 145          global $members_template;
 146          $old_members_template = $members_template;
 147  
 148          $old_get = $_GET;
 149          $_GET['member_type'] = 'bar';
 150  
 151          bp_has_members();
 152  
 153          $members = is_array( $members_template->members ) ? array_values( $members_template->members ) : array();
 154          $member_ids = wp_list_pluck( $members, 'ID' );
 155          $this->assertEquals( array( $users[1] ), $member_ids );
 156  
 157          $GLOBALS['members_template'] = $old_members_template;
 158      }
 159  
 160      /**
 161       * @group bp_has_members
 162       * @ticket BP6286
 163       */
 164      public function test_bp_has_members_should_infer_member_type_from_get_param_comma_sep() {
 165          bp_register_member_type( 'foo' );
 166          bp_register_member_type( 'bar' );
 167          bp_register_member_type( 'baz' );
 168          $users = self::factory()->user->create_many( 4 );
 169          bp_set_member_type( $users[0], 'foo' );
 170          bp_set_member_type( $users[1], 'bar' );
 171          bp_set_member_type( $users[2], 'baz' );
 172  
 173          global $members_template;
 174          $old_members_template = $members_template;
 175  
 176          $old_get = $_GET;
 177          $_GET['member_type'] = 'foo,bar';
 178  
 179          bp_has_members();
 180  
 181          $members = is_array( $members_template->members ) ? array_values( $members_template->members ) : array();
 182          $member_ids = wp_list_pluck( $members, 'ID' );
 183          $this->assertEqualSets( array( $users[0], $users[1] ), $member_ids );
 184  
 185          $GLOBALS['members_template'] = $old_members_template;
 186      }
 187  
 188      /**
 189       * @group bp_get_member_last_active
 190       */
 191  	public function test_bp_get_member_last_active_default_params() {
 192          // Fake the global
 193          global $members_template;
 194  
 195          $time = date( 'Y-m-d H:i:s', time() - 24*60*60 );
 196          $members_template = new stdClass;
 197          $members_template->member = new stdClass;
 198          $members_template->member->last_activity = $time;
 199  
 200          $this->assertEquals( bp_core_get_last_activity( $time, __( 'active %s', 'buddypress' ) ), bp_get_member_last_active() );
 201      }
 202  
 203      /**
 204       * @group bp_get_member_last_active
 205       */
 206      public function test_bp_get_member_last_active_active_format_true() {
 207          // Fake the global
 208          global $members_template;
 209  
 210          $time = date( 'Y-m-d H:i:s', time() - 24*60*60 );
 211          $members_template = new stdClass;
 212          $members_template->member = new stdClass;
 213          $members_template->member->last_activity = $time;
 214  
 215          $this->assertEquals( bp_core_get_last_activity( $time, __( 'active %s', 'buddypress' ) ), bp_get_member_last_active( array( 'active_format' => true, ) ) );
 216      }
 217  
 218      /**
 219       * @group bp_get_member_last_active
 220       */
 221      public function test_bp_get_member_last_active_active_format_false() {
 222          // Fake the global
 223          global $members_template;
 224  
 225          $time = date( 'Y-m-d H:i:s', time() - 24*60*60 );
 226          $members_template = new stdClass;
 227          $members_template->member = new stdClass;
 228          $members_template->member->last_activity = $time;
 229  
 230          $this->assertEquals( bp_core_time_since( $time ), bp_get_member_last_active( array( 'active_format' => false, ) ) );
 231      }
 232  
 233      /**
 234       * @group pagination
 235       * @group BP_Core_Members_Template
 236       */
 237      public function test_bp_groups_template_should_give_precedence_to_upage_URL_param() {
 238          $request = $_REQUEST;
 239          $_REQUEST['upage'] = '5';
 240  
 241          $r = array(
 242              'type'            => 'active',
 243              'page'            => 8,
 244              'per_page'        => 20,
 245              'max'             => false,
 246              'page_arg'        => 'upage',
 247              'include'         => false,
 248              'exclude'         => false,
 249              'user_id'         => 0,
 250              'member_type'     => '',
 251              'search_terms'    => null,
 252              'meta_key'        => false,
 253              'meta_value'      => false,
 254              'populate_extras' => true,
 255              'search_terms'    => ''
 256          );
 257  
 258          $at = new BP_Core_Members_Template(
 259              $r['type'],
 260              $r['page'],
 261              $r['per_page'],
 262              $r['max'],
 263              $r['user_id'],
 264              $r['search_terms'],
 265              $r['include'],
 266              $r['populate_extras'],
 267              $r['exclude'],
 268              $r['meta_key'],
 269              $r['meta_value'],
 270              $r['page_arg'],
 271              $r['member_type']
 272          );
 273  
 274          $this->assertEquals( 5, $at->pag_page );
 275  
 276          $_REQUEST = $request;
 277      }
 278  
 279      /**
 280       * @group pagination
 281       * @group BP_Core_Members_Template
 282       */
 283      public function test_bp_members_template_should_reset_0_pag_page_URL_param_to_default_pag_page_value() {
 284          $request = $_REQUEST;
 285          $_REQUEST['upage'] = '0';
 286  
 287          $r = array(
 288              'type'            => 'active',
 289              'page'            => 8,
 290              'per_page'        => 20,
 291              'max'             => false,
 292              'page_arg'        => 'upage',
 293              'include'         => false,
 294              'exclude'         => false,
 295              'user_id'         => 0,
 296              'member_type'     => '',
 297              'search_terms'    => null,
 298              'meta_key'        => false,
 299              'meta_value'      => false,
 300              'populate_extras' => true,
 301              'search_terms'    => ''
 302          );
 303  
 304          $at = new BP_Core_Members_Template(
 305              $r['type'],
 306              $r['page'],
 307              $r['per_page'],
 308              $r['max'],
 309              $r['user_id'],
 310              $r['search_terms'],
 311              $r['include'],
 312              $r['populate_extras'],
 313              $r['exclude'],
 314              $r['meta_key'],
 315              $r['meta_value'],
 316              $r['page_arg'],
 317              $r['member_type']
 318          );
 319  
 320          $this->assertEquals( 8, $at->pag_page );
 321  
 322          $_REQUEST = $request;
 323      }
 324  
 325      /**
 326       * @group pagination
 327       * @group BP_Core_Members_Template
 328       */
 329      public function test_bp_members_template_should_give_precedence_to_num_URL_param() {
 330          $request = $_REQUEST;
 331          $_REQUEST['num'] = '14';
 332  
 333          $r = array(
 334              'type'            => 'active',
 335              'page'            => 1,
 336              'per_page'        => 13,
 337              'max'             => false,
 338              'page_arg'        => 'upage',
 339              'include'         => false,
 340              'exclude'         => false,
 341              'user_id'         => 0,
 342              'member_type'     => '',
 343              'search_terms'    => null,
 344              'meta_key'        => false,
 345              'meta_value'      => false,
 346              'populate_extras' => true,
 347              'search_terms'    => ''
 348          );
 349  
 350          $at = new BP_Core_Members_Template(
 351              $r['type'],
 352              $r['page'],
 353              $r['per_page'],
 354              $r['max'],
 355              $r['user_id'],
 356              $r['search_terms'],
 357              $r['include'],
 358              $r['populate_extras'],
 359              $r['exclude'],
 360              $r['meta_key'],
 361              $r['meta_value'],
 362              $r['page_arg'],
 363              $r['member_type']
 364          );
 365  
 366          $this->assertEquals( 14, $at->pag_num );
 367  
 368          $_REQUEST = $request;
 369      }
 370  
 371      /**
 372       * @group pagination
 373       * @group BP_Core_Members_Template
 374       */
 375      public function test_bp_members_template_should_reset_0_pag_num_URL_param_to_default_pag_num_value() {
 376          $request = $_REQUEST;
 377          $_REQUEST['num'] = '0';
 378  
 379          $r = array(
 380              'type'            => 'active',
 381              'page'            => 1,
 382              'per_page'        => 13,
 383              'max'             => false,
 384              'page_arg'        => 'upage',
 385              'include'         => false,
 386              'exclude'         => false,
 387              'user_id'         => 0,
 388              'member_type'     => '',
 389              'search_terms'    => null,
 390              'meta_key'        => false,
 391              'meta_value'      => false,
 392              'populate_extras' => true,
 393              'search_terms'    => ''
 394          );
 395  
 396          $at = new BP_Core_Members_Template(
 397              $r['type'],
 398              $r['page'],
 399              $r['per_page'],
 400              $r['max'],
 401              $r['user_id'],
 402              $r['search_terms'],
 403              $r['include'],
 404              $r['populate_extras'],
 405              $r['exclude'],
 406              $r['meta_key'],
 407              $r['meta_value'],
 408              $r['page_arg'],
 409              $r['member_type']
 410          );
 411  
 412          $this->assertEquals( 13, $at->pag_num );
 413  
 414          $_REQUEST = $request;
 415      }
 416  }


Generated: Fri Oct 18 01:01:36 2019 Cross-referenced by PHPXref 0.7.1