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


Generated: Sun Dec 22 01:00:54 2024 Cross-referenced by PHPXref 0.7.1