Skip to:
Content

BuddyPress.org

Changeset 9984


Ignore:
Timestamp:
07/02/2015 12:54:20 PM (5 years ago)
Author:
boonebgorges
Message:

Introduce BP_UnitTestCase::deactivate_component().

This allows for the easy deactivation of components during unit tests.

Components deactivated in this way will be reactivated during tearDown().

File:
1 edited

Legend:

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

    r9981 r9984  
    1616     */
    1717    protected $autocommitted = false;
     18
     19    /**
     20     * A list of components that have been deactivated during a test.
     21     *
     22     * @since BuddyPress (2.4.0)
     23     *
     24     * @var array
     25     */
     26    protected $deactivated_components = array();
    1827
    1928    public static function setUpBeforeClass() {
     
    6877
    6978        $this->commit_transaction();
     79
     80        // Reactivate any components that have been deactivated.
     81        foreach ( $this->deactivated_components as $component ) {
     82            buddypress()->active_components[ $component ] = 1;
     83        }
     84        $this->deactivated_components = array();
    7085    }
    7186
     
    465480        $this->autocommitted = true;
    466481    }
     482
     483    /**
     484     * Deactivate a component for the duration of a test.
     485     *
     486     * @since BuddyPress (2.4.0)
     487     *
     488     * @param string $component Component name.
     489     */
     490    public function deactivate_component( $component ) {
     491        $is_active = isset( buddypress()->active_components[ $component ] );
     492
     493        if ( ! isset( $component ) ) {
     494            return false;
     495        }
     496
     497        unset( buddypress()->active_components[ $component ] );
     498        $this->deactivated_components[] = $component;
     499    }
    467500}
Note: See TracChangeset for help on using the changeset viewer.