[#3176] Refactor bootstrap

* Adjust load and install order
* Fix issue with stale capabilities after install
This commit is contained in:
Max Rice 2014-09-01 16:04:09 -04:00
parent 50253bc8b6
commit 0bd7d8990c
1 changed files with 29 additions and 17 deletions

View File

@ -10,14 +10,13 @@ class WC_Unit_Tests_Bootstrap {
protected static $instance = null; protected static $instance = null;
/** @var string directory where wordpress-tests-lib is installed */ /** @var string directory where wordpress-tests-lib is installed */
protected $wp_tests_dir; public $wp_tests_dir;
/** @var string testing directory */ /** @var string testing directory */
protected $tests_dir; public $tests_dir;
/** @var string plugin directory */ /** @var string plugin directory */
protected $plugin_dir; public $plugin_dir;
/** /**
* Setup the unit testing environment * Setup the unit testing environment
@ -33,36 +32,50 @@ class WC_Unit_Tests_Bootstrap {
$this->plugin_dir = dirname( $this->tests_dir ); $this->plugin_dir = dirname( $this->tests_dir );
$this->wp_tests_dir = getenv( 'WP_TESTS_DIR' ) ? getenv( 'WP_TESTS_DIR' ) : $this->plugin_dir . '/tmp/wordpress-tests-lib'; $this->wp_tests_dir = getenv( 'WP_TESTS_DIR' ) ? getenv( 'WP_TESTS_DIR' ) : $this->plugin_dir . '/tmp/wordpress-tests-lib';
// load test function so tests_add_filter() is available
require_once( $this->wp_tests_dir . '/includes/functions.php' );
// load WC
tests_add_filter( 'muplugins_loaded', array( $this, 'load_wc' ) );
// install WC
tests_add_filter( 'setup_theme', array( $this, 'install_wc' ) );
// load the WP testing environment // load the WP testing environment
require_once( $this->wp_tests_dir . '/includes/bootstrap.php' ); require_once( $this->wp_tests_dir . '/includes/bootstrap.php' );
$this->install_wc(); // load WC testing framework
activate_plugin( 'woocommerce/woocommerce.php' );
$this->includes(); $this->includes();
} }
/**
* Load WooCommerce
*
* @since 2.2
*/
public function load_wc() {
require_once( $this->plugin_dir . '/woocommerce.php' );
}
/** /**
* Install WooCommerce after the test environment has loaded, but prior * Install WooCommerce after the test environment and WC have been loaded
* to activating the plugin
* *
* @since 2.2 * @since 2.2
*/ */
public function install_wc() { public function install_wc() {
echo 'Installing WooCommerce...' . PHP_EOL; // clean existing install first
define( 'WP_UNINSTALL_PLUGIN', true );
require_once( $this->plugin_dir . '/woocommerce.php' ); include( $this->plugin_dir . '/uninstall.php' );
$installer = include( $this->plugin_dir . '/includes/class-wc-install.php' ); $installer = include( $this->plugin_dir . '/includes/class-wc-install.php' );
$installer->install(); $installer->install();
$GLOBALS['current_user'] = new WP_User(1); // reload capabilities after install, see https://core.trac.wordpress.org/ticket/28374
$GLOBALS['current_user']->set_role('administrator'); $GLOBALS['wp_roles']->reinit();
}
echo "Installing WooCommerce..." . PHP_EOL;
}
/** /**
* Load WC-specific test cases and factories * Load WC-specific test cases and factories
@ -76,7 +89,6 @@ class WC_Unit_Tests_Bootstrap {
require_once( $this->tests_dir . '/framework/class-wc-api-unit-test-case.php' ); require_once( $this->tests_dir . '/framework/class-wc-api-unit-test-case.php' );
} }
/** /**
* Get the single class instance * Get the single class instance
* *