Skip to:
Content

BuddyPress.org


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.

File:
1 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
Note: See TracChangeset for help on using the changeset viewer.