[ 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 bp_migrate_new_member_activity_component
  30       */
  31  	public function test_bp_migrate_new_member_activity_component() {
  32          global $wpdb;
  33          $bp = buddypress();
  34  
  35          $u1 = self::factory()->user->create();
  36          $u2 = self::factory()->user->create();
  37          $u3 = self::factory()->user->create();
  38  
  39          $au1 = self::factory()->activity->create( array(
  40              'component' => 'xprofile',
  41              'type' => 'new_member',
  42              'user_id' => $u1,
  43          ) );
  44  
  45          $au2 = self::factory()->activity->create( array(
  46              'component' => 'xprofile',
  47              'type' => 'new_member',
  48              'user_id' => $u2,
  49          ) );
  50  
  51          $au3 = self::factory()->activity->create( array(
  52              'component' => 'xprofile',
  53              'type' => 'new_member',
  54              'user_id' => $u3,
  55          ) );
  56  
  57          bp_migrate_new_member_activity_component();
  58  
  59          $expected = array(
  60              $u1 => $au1,
  61              $u2 => $au2,
  62              $u3 => $au3,
  63          );
  64  
  65          $in = "'" . implode( "', '", array_keys( $expected ) ) . "'";
  66          $found = $wpdb->get_results(
  67              $wpdb->prepare(
  68                  "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",
  69                  $bp->members->id,
  70                  'new_member'
  71          ), OBJECT_K );
  72  
  73          $found = array_map( 'intval', wp_list_pluck( $found, 'id' ) );
  74  
  75          $this->assertSame( $expected, $found );
  76      }
  77  }


Generated: Tue Sep 17 01:01:39 2019 Cross-referenced by PHPXref 0.7.1