[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

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

   1  <?php
   2  
   3  /**
   4   * @group xprofile
   5   * @group activity
   6   */
   7  class BP_Tests_XProfile_Activity extends BP_UnitTestCase {
   8      protected static $updated_profile_data = array();
   9  
  10  	public static function wpSetUpBeforeClass( $factory ) {
  11          self::$updated_profile_data['u'] = $factory->user->create();
  12          self::$updated_profile_data['g'] = $factory->xprofile_group->create();
  13          self::$updated_profile_data['f'] = $factory->xprofile_field->create( array(
  14              'field_group_id' => self::$updated_profile_data['g'],
  15          ) );
  16      }
  17  
  18  	public static function tearDownAfterClass() {
  19          $d = self::$updated_profile_data;
  20  
  21          xprofile_delete_field_group( $d['g'] );
  22          xprofile_delete_field( $d['f'] );
  23  
  24          self::delete_user( $d['u'] );
  25  
  26          self::commit_transaction();
  27      }
  28  
  29      /**
  30       * @group bp_xprofile_updated_profile_activity
  31       */
  32      public function test_bp_xprofile_updated_profile_activity_with_errors() {
  33          $d = self::$updated_profile_data;
  34  
  35          // Fake new/old values to ensure a change
  36          $old_values = array(
  37              $d['f'] => array(
  38                  'value'      => 'foo',
  39                  'visibility' => 'public',
  40              ),
  41          );
  42          $new_values = array(
  43              $d['f'] => array(
  44                  'value'      => 'foo2',
  45                  'visibility' => 'public',
  46              ),
  47          );
  48  
  49          $du = isset( $d['u'] ) ? $d['u'] : '';
  50          $df = isset( $d['f'] ) ? $d['f'] : '';
  51  
  52          $this->assertFalse( bp_xprofile_updated_profile_activity( $du, array( $df ), true ) );
  53      }
  54  
  55      /**
  56       * @group bp_xprofile_updated_profile_activity
  57       */
  58      public function test_bp_xprofile_updated_profile_activity_throttled() {
  59          $d = self::$updated_profile_data;
  60  
  61          $time = time();
  62          $prev_time = date( 'Y-m-d H:i:s', $time - ( 119 * 60 ) );
  63          $now_time = date( 'Y-m-d H:i:s', $time );
  64  
  65          self::factory()->activity->create( array(
  66              'user_id' => $d['u'],
  67              'component' => buddypress()->profile->id,
  68              'type' => 'updated_profile',
  69              'date_recorded' => $prev_time,
  70          ) );
  71  
  72          // Fake new/old values to ensure a change
  73          $old_values = array(
  74              $d['f'] => array(
  75                  'value'      => 'foo',
  76                  'visibility' => 'public',
  77              ),
  78          );
  79          $new_values = array(
  80              $d['f'] => array(
  81                  'value'      => 'foo2',
  82                  'visibility' => 'public',
  83              ),
  84          );
  85  
  86          $this->assertFalse( bp_xprofile_updated_profile_activity( $d['u'], array( $d['f'] ), false ) );
  87      }
  88  
  89      /**
  90       * @group bp_xprofile_updated_profile_activity
  91       */
  92      public function test_bp_xprofile_updated_profile_activity_outside_of_throttle() {
  93          $d = self::$updated_profile_data;
  94  
  95          $time = strtotime( bp_core_current_time() );
  96          $prev_time = date( 'Y-m-d H:i:s', $time - ( 121 * 60 ) );
  97          $now_time = date( 'Y-m-d H:i:s', $time );
  98  
  99          self::factory()->activity->create( array(
 100              'user_id' => $d['u'],
 101              'component' => buddypress()->profile->id,
 102              'type' => 'updated_profile',
 103              'recorded_time' => $prev_time,
 104          ) );
 105  
 106          // Fake new/old values to ensure a change
 107          $old_values = array(
 108              $d['f'] => array(
 109                  'value'      => 'foo',
 110                  'visibility' => 'public',
 111              ),
 112          );
 113          $new_values = array(
 114              $d['f'] => array(
 115                  'value'      => 'foo2',
 116                  'visibility' => 'public',
 117              ),
 118          );
 119  
 120          $this->assertTrue( bp_xprofile_updated_profile_activity( $d['u'], array( $d['f'] ), false, $old_values, $new_values ) );
 121  
 122          $existing = bp_activity_get( array(
 123              'max' => 1,
 124              'filter' => array(
 125                  'user_id' => $d['u'],
 126                  'object' => buddypress()->profile->id,
 127                  'action' => 'updated_profile',
 128              ),
 129              'count_total' => 'count_query',
 130          ) );
 131  
 132          $this->assertEquals( 1, $existing['total'] );
 133      }
 134  
 135      /**
 136       * @group bp_xprofile_updated_profile_activity
 137       */
 138      public function test_bp_xprofile_updated_profile_activity_no_existing_activity() {
 139          $d = self::$updated_profile_data;
 140  
 141          // Fake new/old values to ensure a change
 142          $old_values = array(
 143              $d['f'] => array(
 144                  'value'      => 'foo',
 145                  'visibility' => 'public',
 146              ),
 147          );
 148          $new_values = array(
 149              $d['f'] => array(
 150                  'value'      => 'foo2',
 151                  'visibility' => 'public',
 152              ),
 153          );
 154  
 155          $this->assertTrue( bp_xprofile_updated_profile_activity( $d['u'], array( $d['f'] ), false, $old_values, $new_values ) );
 156  
 157          $existing = bp_activity_get( array(
 158              'max' => 1,
 159              'filter' => array(
 160                  'user_id' => $d['u'],
 161                  'object' => buddypress()->profile->id,
 162                  'action' => 'updated_profile',
 163              ),
 164              'count_total' => 'count_query',
 165          ) );
 166  
 167          $this->assertEquals( 1, $existing['total'] );
 168      }
 169  
 170      /**
 171       * @group bp_xprofile_updated_profile_activity
 172       */
 173      public function test_bp_xprofile_updated_profile_activity_no_changes() {
 174          $d = self::$updated_profile_data;
 175  
 176          $old_values = array(
 177              $d['f'] => array(
 178                  'value'      => 'foo',
 179                  'visibility' => 'public',
 180              ),
 181          );
 182          $new_values = array(
 183              $d['f'] => array(
 184                  'value'      => 'foo',
 185                  'visibility' => 'public',
 186              ),
 187          );
 188  
 189          $this->assertFalse( bp_xprofile_updated_profile_activity( $d['u'], array( $d['f'] ), false, $old_values, $new_values ) );
 190      }
 191  
 192      /**
 193       * @group bp_xprofile_updated_profile_activity
 194       */
 195      public function test_bp_xprofile_updated_profile_activity_no_public_changes() {
 196          $d = self::$updated_profile_data;
 197  
 198          $old_values = array(
 199              $d['f'] => array(
 200                  'value'      => 'foo',
 201                  'visibility' => 'loggedin',
 202              ),
 203          );
 204          $new_values = array(
 205              $d['f'] => array(
 206                  'value'      => 'bar',
 207                  'visibility' => 'loggedin',
 208              ),
 209          );
 210  
 211          $this->assertFalse( bp_xprofile_updated_profile_activity( $d['u'], array( $d['f'] ), false, $old_values, $new_values ) );
 212      }
 213  
 214      /**
 215       * @group bp_xprofile_updated_profile_activity
 216       */
 217      public function test_bp_xprofile_updated_profile_activity_public_changed_to_private() {
 218          $d = self::$updated_profile_data;
 219  
 220          $old_values = array(
 221              $d['f'] => array(
 222                  'value'      => 'foo',
 223                  'visibility' => 'public',
 224              ),
 225          );
 226          $new_values = array(
 227              $d['f'] => array(
 228                  'value'      => 'bar',
 229                  'visibility' => 'loggedin',
 230              ),
 231          );
 232  
 233          $this->assertFalse( bp_xprofile_updated_profile_activity( $d['u'], array( $d['f'] ), false, $old_values, $new_values ) );
 234      }
 235  
 236      /**
 237       * @group bp_xprofile_updated_profile_activity
 238       */
 239      public function test_bp_xprofile_updated_profile_activity_private_changed_to_public() {
 240          $d = self::$updated_profile_data;
 241  
 242          $old_values = array(
 243              $d['f'] => array(
 244                  'value'      => 'foo',
 245                  'visibility' => 'loggedin',
 246              ),
 247          );
 248          $new_values = array(
 249              $d['f'] => array(
 250                  'value'      => 'foo',
 251                  'visibility' => 'public',
 252              ),
 253          );
 254  
 255          $this->assertTrue( bp_xprofile_updated_profile_activity( $d['u'], array( $d['f'] ), false, $old_values, $new_values ) );
 256      }
 257  
 258      /**
 259       * @group bp_xprofile_updated_profile_activity
 260       */
 261      public function test_bp_xprofile_updated_profile_activity_field_didnt_previously_exist() {
 262          $d = self::$updated_profile_data;
 263  
 264          $old_values = array();
 265          $new_values = array(
 266              $d['f'] => array(
 267                  'value'      => 'bar',
 268                  'visibility' => 'public',
 269              ),
 270          );
 271  
 272          $this->assertTrue( bp_xprofile_updated_profile_activity( $d['u'], array( $d['f'] ), false, $old_values, $new_values ) );
 273      }
 274  
 275      /**
 276       * @group bp_xprofile_updated_profile_activity
 277       */
 278      public function test_bp_xprofile_updated_profile_activity_public_changes() {
 279          $d = self::$updated_profile_data;
 280  
 281          $old_values = array(
 282              $d['f'] => array(
 283                  'value'      => 'foo',
 284                  'visibility' => 'public',
 285              ),
 286          );
 287          $new_values = array(
 288              $d['f'] => array(
 289                  'value'      => 'bar',
 290                  'visibility' => 'public',
 291              ),
 292          );
 293  
 294          $this->assertTrue( bp_xprofile_updated_profile_activity( $d['u'], array( $d['f'] ), false, $old_values, $new_values ) );
 295      }
 296  
 297      /**
 298       * @group activity_action
 299       * @group bp_xprofile_format_activity_action_new_avatar
 300       */
 301      public function test_bp_xprofile_format_activity_action_new_avatar() {
 302          $u = self::factory()->user->create();
 303          $a = self::factory()->activity->create( array(
 304              'component' => 'profile',
 305              'type' => 'new_avatar',
 306              'user_id' => $u,
 307          ) );
 308  
 309          $expected = sprintf( __( '%s changed their profile picture', 'buddypress' ), bp_core_get_userlink( $u ) );
 310  
 311          $a_obj = new BP_Activity_Activity( $a );
 312  
 313          $this->assertSame( $expected, $a_obj->action );
 314      }
 315  
 316      /**
 317       * @group activity_action
 318       * @group bp_xprofile_format_activity_action_updated_profile
 319       */
 320      public function test_bp_xprofile_format_activity_action_updated_profile() {
 321          $u = self::factory()->user->create();
 322          $a = self::factory()->activity->create( array(
 323              'component' => buddypress()->profile->id,
 324              'type' => 'updated_profile',
 325              'user_id' => $u,
 326          ) );
 327  
 328          $expected = sprintf( esc_html__( "%s's profile was updated", 'buddypress' ), '<a href="' . bp_core_get_user_domain( $u ) . bp_get_profile_slug() . '/">' . bp_core_get_user_displayname( $u ) . '</a>' );
 329  
 330          $a_obj = new BP_Activity_Activity( $a );
 331  
 332          $this->assertSame( $expected, $a_obj->action );
 333      }
 334  }


Generated: Wed Aug 12 01:01:32 2020 Cross-referenced by PHPXref 0.7.1