[ 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  }


Generated: Mon May 10 01:01:38 2021 Cross-referenced by PHPXref 0.7.1