[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

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

   1  <?php
   2  
   3  /**
   4   * @group members
   5   * @group activity
   6   */
   7  class BP_Tests_Members_Activity extends BP_UnitTestCase {
   8  
   9      /**
  10       * @group activity_action
  11       * @group bp_core_format_activity_action_new_member
  12       */
  13      public function test_bp_members_format_activity_action_new_member() {
  14          $u = self::factory()->user->create();
  15          $a = self::factory()->activity->create( array(
  16              'component' => buddypress()->members->id,
  17              'type' => 'new_member',
  18              'user_id' => $u,
  19          ) );
  20  
  21          $expected = sprintf( __( '%s became a registered member', 'buddypress' ), bp_core_get_userlink( $u ) );
  22  
  23          $a_obj = new BP_Activity_Activity( $a );
  24  
  25          $this->assertSame( $expected, $a_obj->action );
  26      }
  27  
  28      /**
  29       * @group activity_action
  30       * @group bp_members_format_activity_action_new_avatar
  31       */
  32      public function test_bp_members_format_activity_action_new_avatar() {
  33          $u = self::factory()->user->create();
  34          $a = self::factory()->activity->create( array(
  35              'component' => 'members',
  36              'type' => 'new_avatar',
  37              'user_id' => $u,
  38          ) );
  39  
  40          $expected = sprintf( __( '%s changed their profile picture', 'buddypress' ), bp_core_get_userlink( $u ) );
  41  
  42          $a_obj = new BP_Activity_Activity( $a );
  43  
  44          $this->assertSame( $expected, $a_obj->action );
  45      }
  46  
  47      /**
  48       * @group bp_migrate_new_member_activity_component
  49       */
  50  	public function test_bp_migrate_new_member_activity_component() {
  51          global $wpdb;
  52          $bp = buddypress();
  53  
  54          $u1 = self::factory()->user->create();
  55          $u2 = self::factory()->user->create();
  56          $u3 = self::factory()->user->create();
  57  
  58          $au1 = self::factory()->activity->create( array(
  59              'component' => 'xprofile',
  60              'type' => 'new_member',
  61              'user_id' => $u1,
  62          ) );
  63  
  64          $au2 = self::factory()->activity->create( array(
  65              'component' => 'xprofile',
  66              'type' => 'new_member',
  67              'user_id' => $u2,
  68          ) );
  69  
  70          $au3 = self::factory()->activity->create( array(
  71              'component' => 'xprofile',
  72              'type' => 'new_member',
  73              'user_id' => $u3,
  74          ) );
  75  
  76          bp_migrate_new_member_activity_component();
  77  
  78          $expected = array(
  79              $u1 => $au1,
  80              $u2 => $au2,
  81              $u3 => $au3,
  82          );
  83  
  84          $in = "'" . implode( "', '", array_keys( $expected ) ) . "'";
  85          $found = $wpdb->get_results(
  86              $wpdb->prepare(
  87                  "SELECT user_id, id FROM {$bp->members->table_name_last_activity} WHERE component = %s AND type = %s AND user_id IN ({$in}) ORDER BY user_id ASC",
  88                  $bp->members->id,
  89                  'new_member'
  90          ), OBJECT_K );
  91  
  92          $found = array_map( 'intval', wp_list_pluck( $found, 'id' ) );
  93  
  94          $this->assertSame( $expected, $found );
  95      }
  96  
  97      /**
  98       * @group bp_members_new_avatar_activity
  99       */
 100  	public function test_bp_members_new_avatar_activity_throttled() {
 101          $u = self::factory()->user->create();
 102          $a = self::factory()->activity->create( array(
 103              'component' => buddypress()->members->id,
 104              'type'      => 'new_avatar',
 105              'user_id'   => $u,
 106          ) );
 107  
 108          bp_members_new_avatar_activity( $u );
 109  
 110          $new_avatar_activities = bp_activity_get( array(
 111              'filter'    => array(
 112                  'object'  => buddypress()->members->id,
 113                  'user_id' => $u,
 114                  'action'  => 'new_avatar',
 115              ),
 116              'count_total' => 'count_query',
 117          ) );
 118  
 119          $this->assertEquals( 1, $new_avatar_activities['total'] );
 120          $this->assertNotSame( $a, $new_avatar_activities['activities'][0]->id );
 121      }
 122  
 123      /**
 124       * @group bp_members_new_avatar_activity
 125       */
 126      public function test_bp_members_new_avatar_activity_outside_of_throttle_time() {
 127          $u = self::factory()->user->create();
 128  
 129          $time      = strtotime( bp_core_current_time() );
 130          $prev_time = date( 'Y-m-d H:i:s', $time - ( 121 * HOUR_IN_SECONDS ) );
 131  
 132          $a = self::factory()->activity->create( array(
 133              'component'     => buddypress()->members->id,
 134              'type'          => 'new_avatar',
 135              'user_id'       => $u,
 136              'recorded_time' => $prev_time,
 137          ) );
 138  
 139          bp_members_new_avatar_activity( $u );
 140  
 141          $new_avatar_activities = bp_activity_get( array(
 142              'filter'    => array(
 143                  'object'  => buddypress()->members->id,
 144                  'user_id' => $u,
 145                  'action'  => 'new_avatar',
 146              ),
 147              'count_total' => 'count_query',
 148          ) );
 149  
 150          $this->assertEquals( 2, $new_avatar_activities['total'] );
 151      }
 152  
 153      /**
 154       * @group bp_members_remove_previous_avatar_activity
 155       */
 156      public function test_bp_members_remove_previous_avatar_activity() {
 157          $u              = self::factory()->user->create();
 158          $timestamp      = strtotime( bp_core_current_time() );
 159          $prev_timestamp = $timestamp - ( 121 * HOUR_IN_SECONDS );
 160          $date_recorded  = date( 'Y-m-d H:i:s', $timestamp );
 161          $prev_time      = date( 'Y-m-d H:i:s', $prev_timestamp );
 162  
 163          $a1 = self::factory()->activity->create( array(
 164              'component'     => buddypress()->members->id,
 165              'type'          => 'new_avatar',
 166              'user_id'       => $u,
 167              'recorded_time' => $prev_time,
 168          ) );
 169  
 170          $a2 = self::factory()->activity->create(
 171              array(
 172                  'component'     => buddypress()->members->id,
 173                  'type'          => 'new_avatar',
 174                  'user_id'       => $u,
 175                  'recorded_time' => $date_recorded,
 176              )
 177          );
 178  
 179          $this->assertTrue( bp_members_remove_previous_avatar_activity( $u, $prev_timestamp ) );
 180  
 181          $new_avatar_activities = bp_activity_get( array(
 182              'filter'    => array(
 183                  'object'  => buddypress()->members->id,
 184                  'user_id' => $u,
 185                  'action'  => 'new_avatar',
 186              ),
 187              'count_total' => 'count_query',
 188          ) );
 189  
 190          $this->assertEquals( 1, $new_avatar_activities['total'] );
 191      }
 192  }


Generated: Thu Nov 21 01:00:57 2024 Cross-referenced by PHPXref 0.7.1