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


Generated: Sun Dec 8 01:01:37 2019 Cross-referenced by PHPXref 0.7.1