Skip to:
Content

BuddyPress.org

Changeset 11739


Ignore:
Timestamp:
11/03/2017 09:11:52 PM (9 years ago)
Author:
boonebgorges
Message:

Ensure that shared user fixtures are fully cleaned up.

It's not possible to inherit WP 4.4's user cleanup between tests, because
the the deletion routine runs after the core test suite has unhooked
certain actions (such as BP's that are hooked to delete_user). So
we are forced to run necessary cleanup tasks in our own delete_user()
method, and ensure that it's this method that is called in every case
where we're cleaning up after statically generated shared fixtures.
Otherwise leftover content in the activity table can leak to other
tests.

See #7620.

Location:
trunk/tests/phpunit
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/includes/testcase.php

    r11736 r11739  
    2626        protected $deactivated_components = array();
    2727
     28        /**
     29         * Cribbed from WP so that the self::factory() call comes from this class.
     30         *
     31         * @since 3.0.0
     32         */
    2833        public static function setUpBeforeClass() {
     34                global $wpdb;
    2935
    3036                // Fake WP mail globals, to avoid errors
     
    3238                add_filter( 'wp_mail_from', array( 'BP_UnitTestCase', 'tearDown_wp_mail' ) );
    3339
    34                 parent::setUpBeforeClass();
     40                $c = self::get_called_class();
     41                if ( ! method_exists( $c, 'wpSetUpBeforeClass' ) ) {
     42                        self::commit_transaction();
     43                        return;
     44                }
     45
     46                call_user_func( array( $c, 'wpSetUpBeforeClass' ), self::factory() );
     47
     48                self::commit_transaction();
    3549        }
    3650
     
    92106                }
    93107                $this->deactivated_components = array();
     108        }
     109
     110        /**
     111         * Multisite-agnostic way to delete a user from the database.
     112         *
     113         * @since 3.0.0
     114         */
     115        public static function delete_user( $user_id ) {
     116                $deleted = parent::delete_user( $user_id );
     117
     118                // When called in tearDownAfterClass(), BP's cleanup functions may no longer be hooked.
     119                if ( bp_is_active( 'activity' ) ) {
     120                        bp_activity_remove_all_user_data( $user_id );
     121                }
     122
     123                return $deleted;
    94124        }
    95125
  • trunk/tests/phpunit/testcases/core/class-bp-media-extractor.php

    r11737 r11739  
    88        public static $richtext        = '';
    99
    10 
    11         public static function setUpBeforeClass() {
    12                 parent::setUpBeforeClass();
    13 
     10        public static function wpSetUpBeforeClass( $f ) {
    1411                self::$media_extractor = new BP_Media_Extractor();
    1512                self::$richtext        = "Hello world.
  • trunk/tests/phpunit/testcases/core/suggestions-nonauth.php

    r9819 r11739  
    1111        protected static $user_ids     = array();
    1212
    13         public static function setUpBeforeClass() {
    14                 parent::setUpBeforeClass();
    15 
     13        public static function wpSetUpBeforeClass( $factory ) {
    1614                $users = array(
    1715                        // user_login, display_name
     
    2826                        array( 'zoom',        'Lisa Smithy' ),
    2927                );
    30 
    31                 $factory = new BP_UnitTest_Factory();
    3228
    3329                // Create some dummy users.
  • trunk/tests/phpunit/testcases/core/suggestions.php

    r11256 r11739  
    1313        protected static $user_ids     = array();
    1414
    15         public static function setUpBeforeClass() {
    16                 parent::setUpBeforeClass();
    17 
    18                 $factory = new BP_UnitTest_Factory();
    19 
     15        public static function wpSetUpBeforeClass( $factory ) {
    2016                self::$old_user_id  = get_current_user_id();
    2117                self::$current_user = $factory->user->create( array(
  • trunk/tests/phpunit/testcases/groups/functions/bpGetUserGroups.php

    r10794 r11739  
    1414        }
    1515
    16         public static function setUpBeforeClass() {
     16        public static function wpSetUpBeforeClass( $f ) {
    1717                $f = new BP_UnitTest_Factory();
    1818
  • trunk/tests/phpunit/testcases/groups/functions/groupsCreateGroup.php

    r11737 r11739  
    1111        public static function wpSetUpBeforeClass( $factory ) {
    1212                self::$user_id = $factory->user->create();
     13        }
     14
     15        public static function wpTearDownAfterClass() {
     16                self::delete_user( self::$user_id );
    1317        }
    1418
  • trunk/tests/phpunit/testcases/groups/functions/groupsIsUser.php

    r10794 r11739  
    1111        static $groups;
    1212
    13         public static function setUpBeforeClass() {
    14                 $f = new BP_UnitTest_Factory();
    15 
     13        public static function wpSetUpBeforeClass( $f ) {
    1614                self::$user = $f->user->create( array(
    1715                        'user_login' => 'groups_is_user',
  • trunk/tests/phpunit/testcases/groups/types.php

    r11737 r11739  
    1414        }
    1515
    16         public static function setUpBeforeClass() {
    17                 $f = new BP_UnitTest_Factory();
    18 
     16        public static function wpSetUpBeforeClass( $f ) {
    1917                self::$u1 = $f->user->create( array(
    2018                        'user_email' => 'group-types-tests@example.com',
     
    2321        }
    2422
    25         public static function tearDownAfterClass() {
    26                 if ( is_multisite() ) {
    27                         wpmu_delete_user( self::$u1 );
    28                 } else {
    29                         wp_delete_user( self::$u1 );
    30                 }
     23        public static function wpTearDownAfterClass() {
     24                self::delete_user( self::$u1 );
    3125        }
    3226
Note: See TracChangeset for help on using the changeset viewer.