[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/tests/phpunit/testcases/core/ -> class-bp-core-user.php (source)

   1  <?php
   2  
   3  /**
   4   * @group core
   5   * @group BP_Core_User
   6   */
   7  class BP_Tests_BP_Core_User_TestCases extends BP_UnitTestCase {
   8      /**
   9       * @expectedDeprecated BP_Core_User::get_users
  10       */
  11  	public function test_get_users_with_exclude_querystring() {
  12          $u1 = self::factory()->user->create();
  13          $u2 = self::factory()->user->create();
  14          $u3 = self::factory()->user->create();
  15  
  16          $exclude_qs = $u1 . ',junkstring,' . $u3;
  17  
  18          $users = BP_Core_User::get_users( 'active', 0, 1, 0, false, false, true, $exclude_qs );
  19          $user_ids = wp_parse_id_list( wp_list_pluck( $users['users'], 'id' ) );
  20  
  21          $this->assertEquals( array( $u2 ), $user_ids );
  22      }
  23  
  24      /**
  25       * @expectedDeprecated BP_Core_User::get_users
  26       */
  27  	public function test_get_users_with_exclude_array() {
  28          $u1 = self::factory()->user->create();
  29          $u2 = self::factory()->user->create();
  30          $u3 = self::factory()->user->create();
  31  
  32          $exclude_array = array(
  33              $u1,
  34              'junkstring',
  35              $u3,
  36          );
  37  
  38          $users = BP_Core_User::get_users( 'active', 0, 1, 0, false, false, true, $exclude_array );
  39          $user_ids = wp_parse_id_list( wp_list_pluck( $users['users'], 'id' ) );
  40  
  41          $this->assertEquals( array( $u2 ), $user_ids );
  42      }
  43  
  44      /**
  45       * @expectedDeprecated BP_Core_User::get_users
  46       */
  47  	public function test_get_users_with_include_querystring() {
  48          $u1 = self::factory()->user->create( array(
  49              'last_activity' => gmdate( 'Y-m-d H:i:s' ),
  50          ) );
  51          $u2 = self::factory()->user->create( array(
  52              'last_activity' => gmdate( 'Y-m-d H:i:s', time() - 1000 ),
  53          ) );
  54          $u3 = self::factory()->user->create( array(
  55              'last_activity' => gmdate( 'Y-m-d H:i:s', time() - 50 ),
  56          ) );
  57  
  58          $include_qs = $u1 . ',junkstring,' . $u3;
  59  
  60          $users = BP_Core_User::get_users( 'active', 0, 1, 0, $include_qs );
  61          $user_ids = wp_parse_id_list( wp_list_pluck( $users['users'], 'id' ) );
  62  
  63          $this->assertEquals( array( $u1, $u3 ), $user_ids );
  64      }
  65  
  66      /**
  67       * @expectedDeprecated BP_Core_User::get_users
  68       */
  69  	public function test_get_users_with_include_array() {
  70          $u1 = self::factory()->user->create( array(
  71              'last_activity' => gmdate( 'Y-m-d H:i:s' ),
  72          ) );
  73          $u2 = self::factory()->user->create( array(
  74              'last_activity' => gmdate( 'Y-m-d H:i:s', time() - 1000 ),
  75          ) );
  76          $u3 = self::factory()->user->create( array(
  77              'last_activity' => gmdate( 'Y-m-d H:i:s', time() - 50 ),
  78          ) );
  79  
  80  
  81          $include_array = array(
  82              $u1,
  83              'junkstring',
  84              $u3,
  85          );
  86  
  87          $users = BP_Core_User::get_users( 'active', 0, 1, 0, $include_array );
  88          $user_ids = wp_list_pluck( $users['users'], 'id' );
  89  
  90          // typecast...ugh
  91          $user_ids = array_map( 'intval', $user_ids );
  92  
  93          $this->assertEquals( array( $u1, $u3 ), $user_ids );
  94      }
  95  
  96      /**
  97       * @expectedDeprecated BP_Core_User::get_users
  98       * @group get_users
  99       * @group type
 100       */
 101  	public function test_type_alphabetical() {
 102          $u1 = self::factory()->user->create( array(
 103              'display_name' => 'foo',
 104          ) );
 105          $u2 = self::factory()->user->create( array(
 106              'display_name' => 'bar',
 107          ) );
 108  
 109          global $wpdb;
 110  
 111          $q = BP_Core_User::get_users( 'alphabetical' );
 112          $found = array_map( 'intval', wp_list_pluck( $q['users'], 'id' ) );
 113  
 114          $this->assertEquals( array( $u2, $u1 ), $found );
 115      }
 116  
 117      /**
 118       * @group get_users_by_letter
 119       */
 120  	public function test_get_users_by_letter() {
 121          $u1 = self::factory()->user->create( array(
 122              'display_name' => 'foo',
 123          ) );
 124          $u2 = self::factory()->user->create( array(
 125              'display_name' => 'bar',
 126          ) );
 127  
 128          $q = BP_Core_User::get_users_by_letter( 'b' );
 129          $found = array_map( 'intval', wp_list_pluck( $q['users'], 'id' ) );
 130  
 131          $this->assertEquals( array( $u2 ), $found );
 132      }
 133  
 134      /**
 135       * @group search_users
 136       */
 137  	public function test_search_users() {
 138          $u1 = self::factory()->user->create( array(
 139              'display_name' => 'foo',
 140          ) );
 141          $u2 = self::factory()->user->create( array(
 142              'display_name' => 'bar',
 143          ) );
 144  
 145          $q = BP_Core_User::search_users( 'ar' );
 146          $found = array_map( 'intval', wp_list_pluck( $q['users'], 'id' ) );
 147  
 148          $this->assertEquals( array( $u2 ), $found );
 149      }
 150  
 151  	public function test_get_specific_users() {
 152          $u1 = self::factory()->user->create();
 153          $u2 = self::factory()->user->create();
 154          $u3 = self::factory()->user->create();
 155  
 156          $include_array = array(
 157              $u1,
 158              'junkstring',
 159              $u3,
 160          );
 161  
 162          $users = BP_Core_User::get_specific_users( $include_array );
 163          $user_ids = wp_parse_id_list( wp_list_pluck( $users['users'], 'id' ) );
 164  
 165          $this->assertEquals( array( $u1, $u3 ), $user_ids );
 166      }
 167  
 168      /**
 169       * @group last_activity
 170       */
 171  	public function test_get_last_activity() {
 172          $u = self::factory()->user->create();
 173          $time = bp_core_current_time();
 174  
 175          BP_Core_User::update_last_activity( $u, $time );
 176  
 177          $a = BP_Core_User::get_last_activity( $u );
 178          $found = isset( $a[ $u ]['date_recorded'] ) ? $a[ $u ]['date_recorded'] : '';
 179  
 180          $this->assertEquals( $time, $found );
 181      }
 182  
 183      /**
 184       * @group last_activity
 185       * @group cache
 186       */
 187  	public function test_get_last_activity_store_in_cache() {
 188          $u = self::factory()->user->create();
 189          $time = bp_core_current_time();
 190  
 191          // Cache is set during user creation. Clear to reflect actual
 192          // pageload
 193          wp_cache_delete( $u, 'bp_last_activity' );
 194  
 195          // prime cache
 196          $a = BP_Core_User::get_last_activity( $u );
 197  
 198          $this->assertSame( $a[ $u ], wp_cache_get( $u, 'bp_last_activity' ) );
 199      }
 200  
 201      /**
 202       * @group last_activity
 203       * @group cache
 204       */
 205      public function test_get_last_activity_store_in_cache_multiple_users() {
 206          $u1 = self::factory()->user->create();
 207          $u2 = self::factory()->user->create();
 208          $time = bp_core_current_time();
 209  
 210          // Cache is set during user creation. Clear to reflect actual
 211          // pageload
 212          wp_cache_delete( $u1, 'bp_last_activity' );
 213          wp_cache_delete( $u2, 'bp_last_activity' );
 214  
 215          // prime cache
 216          $a = BP_Core_User::get_last_activity( array( $u1, $u2 ) );
 217  
 218          $this->assertSame( $a[ $u1 ], wp_cache_get( $u1, 'bp_last_activity' ) );
 219          $this->assertSame( $a[ $u2 ], wp_cache_get( $u2, 'bp_last_activity' ) );
 220      }
 221  
 222      /**
 223       * @group last_activity
 224       * @group cache
 225       */
 226  	public function test_get_last_activity_from_cache_single_user() {
 227          $u    = self::factory()->user->create();
 228          $time = bp_core_current_time();
 229  
 230          BP_Core_User::update_last_activity( $u, $time );
 231  
 232          // Cache is set during user creation. Clear to reflect actual
 233          // pageload
 234          wp_cache_delete( $u, 'bp_last_activity' );
 235  
 236          // Prime cache
 237          $uncached = BP_Core_User::get_last_activity( $u );
 238  
 239          // Fetch again to get from the cache
 240          $cached = BP_Core_User::get_last_activity( $u );
 241  
 242          $this->assertSame( $uncached, $cached );
 243      }
 244  
 245      /**
 246       * @group last_activity
 247       * @group cache
 248       */
 249      public function test_get_last_activity_in_cache_multiple_users() {
 250          $u1 = self::factory()->user->create();
 251          $u2 = self::factory()->user->create();
 252          $time = bp_core_current_time();
 253  
 254          BP_Core_User::update_last_activity( $u1, $time );
 255          BP_Core_User::update_last_activity( $u2, $time );
 256  
 257          // Cache is set during user creation. Clear to reflect actual pageload
 258          wp_cache_delete( $u1, 'bp_last_activity' );
 259          wp_cache_delete( $u2, 'bp_last_activity' );
 260  
 261          // Prime cache
 262          $uncached = BP_Core_User::get_last_activity( array( $u1, $u2 ) );
 263  
 264          // Second grab will be from the cache
 265          $cached = BP_Core_User::get_last_activity( array( $u1, $u2 ) );
 266          $cached_u1 = wp_cache_get( $u1, 'bp_last_activity' );
 267  
 268          $this->assertSame( $cached, $uncached );
 269      }
 270  
 271      /**
 272       * @group last_activity
 273       */
 274  	public function test_update_last_activity() {
 275          $u = self::factory()->user->create();
 276          $time = bp_core_current_time();
 277          $time2 = '1968-12-25 01:23:45';
 278  
 279          BP_Core_User::update_last_activity( $u, $time );
 280          $a = BP_Core_User::get_last_activity( $u );
 281          $found = isset( $a[ $u ]['date_recorded'] ) ? $a[ $u ]['date_recorded'] : '';
 282          $this->assertEquals( $time, $found );
 283  
 284          BP_Core_User::update_last_activity( $u, $time2 );
 285          $a = BP_Core_User::get_last_activity( $u );
 286          $found = isset( $a[ $u ]['date_recorded'] ) ? $a[ $u ]['date_recorded'] : '';
 287          $this->assertEquals( $time2, $found );
 288      }
 289  
 290      /**
 291       * @group last_activity
 292       */
 293  	public function test_delete_last_activity() {
 294          $u = self::factory()->user->create();
 295          $time = bp_core_current_time();
 296  
 297          BP_Core_User::update_last_activity( $u, $time );
 298          $a = BP_Core_User::get_last_activity( $u );
 299          $found = isset( $a[ $u ]['date_recorded'] ) ? $a[ $u ]['date_recorded'] : '';
 300          $this->assertEquals( $time, $found );
 301  
 302          BP_Core_User::delete_last_activity( $u );
 303          $a = BP_Core_User::get_last_activity( $u );
 304          $found = isset( $a[ $u ]['date_recorded'] ) ? $a[ $u ]['date_recorded'] : '';
 305          $this->assertEquals( '', $found );
 306      }
 307  }


Generated: Wed Jul 24 01:01:43 2019 Cross-referenced by PHPXref 0.7.1