Skip to:
Content

BuddyPress.org

Changeset 12599


Ignore:
Timestamp:
03/28/2020 09:20:46 PM (7 years ago)
Author:
boonebgorges
Message:

Use shared fixtures in BP_Tests_XProfile_Activity.

Aside from improving speed, this allows us to skirt PHP 7.4 variable
access notices thrown when the fixtures were improperly created.

See #8264.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/testcases/xprofile/activity.php

    r12393 r12599  
    66 */
    77class BP_Tests_XProfile_Activity extends BP_UnitTestCase {
    8         protected $updated_profile_data = array();
     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        }
    928
    1029        /**
    … …  
    1231         */
    1332        public function test_bp_xprofile_updated_profile_activity_with_errors() {
    14                 $d = $this->setup_updated_profile_data();
     33                $d = self::$updated_profile_data;
    1534
    1635                // Fake new/old values to ensure a change
    1736                $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(
     37                        $d['f'] => array(
     38                                'value'      => 'foo',
     39                                'visibility' => 'public',
     40                        ),
     41                );
     42                $new_values = array(
     43                        $d['f'] => array(
    2544                                'value'      => 'foo2',
    2645                                'visibility' => 'public',
    … …  
    2847                );
    2948
    30                 $this->assertFalse( bp_xprofile_updated_profile_activity( $d['u'], array( $d['f'] ), true ) );
     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 ) );
    3153        }
    3254
    … …  
    3557         */
    3658        public function test_bp_xprofile_updated_profile_activity_throttled() {
    37                 $d = $this->setup_updated_profile_data();
     59                $d = self::$updated_profile_data;
    3860
    3961                $time = time();
    … …  
    5072                // Fake new/old values to ensure a change
    5173                $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(
     74                        $d['f'] => array(
     75                                'value'      => 'foo',
     76                                'visibility' => 'public',
     77                        ),
     78                );
     79                $new_values = array(
     80                        $d['f'] => array(
    5981                                'value'      => 'foo2',
    6082                                'visibility' => 'public',
    … …  
    6991         */
    7092        public function test_bp_xprofile_updated_profile_activity_outside_of_throttle() {
    71                 $d = $this->setup_updated_profile_data();
     93                $d = self::$updated_profile_data;
    7294
    7395                $time = strtotime( bp_core_current_time() );
    … …  
    84106                // Fake new/old values to ensure a change
    85107                $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(
     108                        $d['f'] => array(
     109                                'value'      => 'foo',
     110                                'visibility' => 'public',
     111                        ),
     112                );
     113                $new_values = array(
     114                        $d['f'] => array(
    93115                                'value'      => 'foo2',
    94116                                'visibility' => 'public',
    … …  
    115137         */
    116138        public function test_bp_xprofile_updated_profile_activity_no_existing_activity() {
    117                 $d = $this->setup_updated_profile_data();
     139                $d = self::$updated_profile_data;
    118140
    119141                // Fake new/old values to ensure a change
    120142                $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(
     143                        $d['f'] => array(
     144                                'value'      => 'foo',
     145                                'visibility' => 'public',
     146                        ),
     147                );
     148                $new_values = array(
     149                        $d['f'] => array(
    128150                                'value'      => 'foo2',
    129151                                'visibility' => 'public',
    … …  
    150172         */
    151173        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(
     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(
    162184                                'value'      => 'foo',
    163185                                'visibility' => 'public',
    … …  
    172194         */
    173195        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(
     196                $d = self::$updated_profile_data;
     197
     198                $old_values = array(
     199                        $d['f'] => array(
    178200                                'value'      => 'foo',
    179201                                'visibility' => 'loggedin',
    … …  
    181203                );
    182204                $new_values = array(
    183                         $this->updated_profile_data['f'] => array(
     205                        $d['f'] => array(
    184206                                'value'      => 'bar',
    185207                                'visibility' => 'loggedin',
    … …  
    194216         */
    195217        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(
     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(
    206228                                'value'      => 'bar',
    207229                                'visibility' => 'loggedin',
    … …  
    216238         */
    217239        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(
     240                $d = self::$updated_profile_data;
     241
     242                $old_values = array(
     243                        $d['f'] => array(
    222244                                'value'      => 'foo',
    223245                                'visibility' => 'loggedin',
    … …  
    225247                );
    226248                $new_values = array(
    227                         $this->updated_profile_data['f'] => array(
     249                        $d['f'] => array(
    228250                                'value'      => 'foo',
    229251                                'visibility' => 'public',
    … …  
    238260         */
    239261        public function test_bp_xprofile_updated_profile_activity_field_didnt_previously_exist() {
    240                 $d = $this->setup_updated_profile_data();
     262                $d = self::$updated_profile_data;
    241263
    242264                $old_values = array();
    243265                $new_values = array(
    244                         $this->updated_profile_data['f'] => array(
     266                        $d['f'] => array(
    245267                                'value'      => 'bar',
    246268                                'visibility' => 'public',
    … …  
    255277         */
    256278        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(
     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(
    267289                                'value'      => 'bar',
    268290                                'visibility' => 'public',
    … …  
    310332                $this->assertSame( $expected, $a_obj->action );
    311333        }
    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         }
    321334}
Note: See TracChangeset for help on using the changeset viewer.