[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/tests/phpunit/testcases/friends/ -> class-bp-friends-friendship.php (source)

   1  <?php
   2  
   3  /**
   4   * @group friends
   5   */
   6  class BP_Tests_BP_Friends_Friendship_TestCases extends BP_UnitTestCase {
   7  	public function test_search_friends() {
   8          $u1 = self::factory()->user->create();
   9          $u2 = self::factory()->user->create();
  10          $u3 = self::factory()->user->create();
  11  
  12          xprofile_set_field_data( 1, $u2, 'Cool Dude' );
  13          xprofile_set_field_data( 1, $u3, 'Rock And Roll America Yeah' );
  14  
  15          friends_add_friend( $u1, $u2, true );
  16          friends_add_friend( $u1, $u3, true );
  17  
  18          $friends = BP_Friends_Friendship::search_friends( 'Coo', $u1 );
  19          $this->assertEquals( array( $u2 ), $friends['friends'] );
  20      }
  21  
  22      /**
  23       * @ticket BP6546
  24       */
  25  	public function test_search_friends_with_xprofile_inactive() {
  26          $this->deactivate_component( 'xprofile' );
  27  
  28          $u1 = self::factory()->user->create();
  29          $u2 = self::factory()->user->create();
  30          $u3 = self::factory()->user->create();
  31  
  32          add_user_meta( $u2, 'nickname', 'Cool Dude' );
  33          add_user_meta( $u3, 'nickname', 'Rock And Roll America Yeah' );
  34  
  35          friends_add_friend( $u1, $u2, true );
  36          friends_add_friend( $u1, $u3, true );
  37  
  38          $friends = BP_Friends_Friendship::search_friends( 'Coo', $u1 );
  39          $this->assertEquals( array( $u2 ), $friends['friends'] );
  40      }
  41  
  42  	public function test_get_bulk_last_active() {
  43          $u1 = self::factory()->user->create( array(
  44              'last_activity' => gmdate( 'Y-m-d H:i:s' ),
  45          ) );
  46          $u2 = self::factory()->user->create( array(
  47              'last_activity' => gmdate( 'Y-m-d H:i:s', time() - 1000 ),
  48          ) );
  49          $u3 = self::factory()->user->create( array(
  50              'last_activity' => gmdate( 'Y-m-d H:i:s', time() - 50 ),
  51          ) );
  52  
  53          $friends = BP_Friends_Friendship::get_bulk_last_active( array( $u1, $u2, $u3, 'junk' ) );
  54          $friend_ids = wp_list_pluck( $friends, 'user_id' );
  55          $this->assertEquals( array( $u1, $u3, $u2 ), $friend_ids );
  56      }
  57  
  58  	public function test_search_users() {
  59          $u1 = self::factory()->user->create();
  60          $u2 = self::factory()->user->create();
  61          $u3 = self::factory()->user->create();
  62  
  63          xprofile_set_field_data( 1, $u1, 'Freedom Isn\'t Free' );
  64          xprofile_set_field_data( 1, $u2, 'Cool Dude' );
  65          xprofile_set_field_data( 1, $u3, 'Rock And Roll America Yeah' );
  66  
  67          // Needs a user_id param though it does nothing
  68          $friends = BP_Friends_Friendship::search_users( 'Coo', 1 );
  69          $this->assertEquals( array( $u2 ), $friends );
  70      }
  71  
  72  	public function test_search_users_count() {
  73          $u1 = self::factory()->user->create();
  74          $u2 = self::factory()->user->create();
  75          $u3 = self::factory()->user->create();
  76  
  77          xprofile_set_field_data( 1, $u1, 'Freedom Isn\'t Free' );
  78          xprofile_set_field_data( 1, $u2, 'Cool Dude' );
  79          xprofile_set_field_data( 1, $u3, 'Rock And Roll America Yeah' );
  80  
  81          // Needs a user_id param though it does nothing
  82          $friends = BP_Friends_Friendship::search_users_count( 'Coo' );
  83          $this->assertEquals( 1, $friends );
  84      }
  85  
  86      /**
  87       * @group check_is_friend
  88       */
  89  	public function test_check_is_friend_not_friends() {
  90          $u1 = self::factory()->user->create();
  91          $u2 = self::factory()->user->create();
  92          $this->assertEquals( 'not_friends', BP_Friends_Friendship::check_is_friend( $u1, $u2 ) );
  93      }
  94  
  95      /**
  96       * @group check_is_friend
  97       */
  98  	public function test_check_is_friend_pending() {
  99          $u1 = self::factory()->user->create();
 100          $u2 = self::factory()->user->create();
 101          friends_add_friend( $u1, $u2, false );
 102          $this->assertEquals( 'pending', BP_Friends_Friendship::check_is_friend( $u1, $u2 ) );
 103      }
 104  
 105      /**
 106       * @group check_is_friend
 107       */
 108  	public function test_check_is_friend_awaiting_response() {
 109          $u1 = self::factory()->user->create();
 110          $u2 = self::factory()->user->create();
 111          friends_add_friend( $u1, $u2, false );
 112          $this->assertEquals( 'awaiting_response', BP_Friends_Friendship::check_is_friend( $u2, $u1 ) );
 113      }
 114  
 115      /**
 116       * @group check_is_friend
 117       */
 118  	public function test_check_is_friend_is_friend() {
 119          $u1 = self::factory()->user->create();
 120          $u2 = self::factory()->user->create();
 121          friends_add_friend( $u1, $u2, true );
 122          $this->assertEquals( 'is_friend', BP_Friends_Friendship::check_is_friend( $u1, $u2 ) );
 123      }
 124  
 125      /**
 126       * @group BP6247
 127       */
 128  	public function test_save_method_should_update_existing_row() {
 129          $u1 = self::factory()->user->create();
 130          $u2 = self::factory()->user->create();
 131  
 132          $friendship = new BP_Friends_Friendship();
 133          $friendship->initiator_user_id = $u1;
 134          $friendship->friend_user_id = $u2;
 135          $friendship->is_confirmed = 0;
 136          $friendship->is_limited = 0;
 137          $friendship->date_created = bp_core_current_time();
 138          $friendship->is_confirmed = 1;
 139          $friendship->save();
 140  
 141          $fid = $friendship->id;
 142  
 143          $f = new BP_Friends_Friendship( $fid );
 144          $f->is_confirmed = 1;
 145          $f->save();
 146  
 147          $f2 = new BP_Friends_Friendship( $fid );
 148          $this->assertEquals( 1, $f2->is_confirmed );
 149      }
 150  
 151      /**
 152       * @group friendship_caching
 153       */
 154      public function test_new_bp_friends_friendship_object_should_hit_friendship_object_cache() {
 155          global $wpdb;
 156          $now = time();
 157          $u1 = self::factory()->user->create( array(
 158              'last_activity' => date( 'Y-m-d H:i:s', $now ),
 159          ) );
 160          $u2 = self::factory()->user->create( array(
 161              'last_activity' => date( 'Y-m-d H:i:s', $now - 100 ),
 162          ) );
 163  
 164          friends_add_friend( $u1, $u2, true );
 165          $fid = friends_get_friendship_id( $u1, $u2 );
 166  
 167          $friendship_obj = new BP_Friends_Friendship( $fid, false, false );
 168          $first_query_count = $wpdb->num_queries;
 169          // Create it again.
 170          $friendship_obj = new BP_Friends_Friendship( $fid, false, false );
 171  
 172          $this->assertEquals( $first_query_count, $wpdb->num_queries );
 173      }
 174  }


Generated: Sun Jul 21 01:01:44 2019 Cross-referenced by PHPXref 0.7.1