2014-09-01 06:03:52 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2015-11-03 13:53:50 +00:00
|
|
|
* WooCommerce Unit Tests Bootstrap
|
2014-09-01 06:03:52 +00:00
|
|
|
*
|
|
|
|
* @since 2.2
|
|
|
|
*/
|
|
|
|
class WC_Unit_Tests_Bootstrap {
|
|
|
|
|
2016-03-23 12:14:13 +00:00
|
|
|
/** @var WC_Unit_Tests_Bootstrap instance */
|
2014-09-01 06:03:52 +00:00
|
|
|
protected static $instance = null;
|
|
|
|
|
|
|
|
/** @var string directory where wordpress-tests-lib is installed */
|
2014-09-01 20:04:09 +00:00
|
|
|
public $wp_tests_dir;
|
2014-09-01 06:03:52 +00:00
|
|
|
|
|
|
|
/** @var string testing directory */
|
2014-09-01 20:04:09 +00:00
|
|
|
public $tests_dir;
|
2014-09-01 06:03:52 +00:00
|
|
|
|
|
|
|
/** @var string plugin directory */
|
2014-09-01 20:04:09 +00:00
|
|
|
public $plugin_dir;
|
2014-09-01 06:03:52 +00:00
|
|
|
|
|
|
|
/**
|
2015-11-03 13:31:20 +00:00
|
|
|
* Setup the unit testing environment.
|
2014-09-01 06:03:52 +00:00
|
|
|
*
|
|
|
|
* @since 2.2
|
|
|
|
*/
|
|
|
|
public function __construct() {
|
|
|
|
|
|
|
|
ini_set( 'display_errors','on' );
|
|
|
|
error_reporting( E_ALL );
|
|
|
|
|
2016-03-23 15:35:06 +00:00
|
|
|
// Ensure server variable is set for WP email functions.
|
|
|
|
if ( ! isset( $_SERVER['SERVER_NAME'] ) ) {
|
|
|
|
$_SERVER['SERVER_NAME'] = 'localhost';
|
|
|
|
}
|
|
|
|
|
2014-09-01 06:03:52 +00:00
|
|
|
$this->tests_dir = dirname( __FILE__ );
|
|
|
|
$this->plugin_dir = dirname( $this->tests_dir );
|
2015-10-20 16:24:46 +00:00
|
|
|
$this->wp_tests_dir = getenv( 'WP_TESTS_DIR' ) ? getenv( 'WP_TESTS_DIR' ) : '/tmp/wordpress-tests-lib';
|
2014-09-01 06:03:52 +00:00
|
|
|
|
2014-09-01 20:04:09 +00:00
|
|
|
// load test function so tests_add_filter() is available
|
|
|
|
require_once( $this->wp_tests_dir . '/includes/functions.php' );
|
2014-09-01 06:03:52 +00:00
|
|
|
|
2014-09-01 20:04:09 +00:00
|
|
|
// load WC
|
|
|
|
tests_add_filter( 'muplugins_loaded', array( $this, 'load_wc' ) );
|
2014-09-01 06:03:52 +00:00
|
|
|
|
2014-09-01 20:04:09 +00:00
|
|
|
// install WC
|
|
|
|
tests_add_filter( 'setup_theme', array( $this, 'install_wc' ) );
|
2014-09-01 06:03:52 +00:00
|
|
|
|
2014-09-01 20:04:09 +00:00
|
|
|
// load the WP testing environment
|
|
|
|
require_once( $this->wp_tests_dir . '/includes/bootstrap.php' );
|
|
|
|
|
|
|
|
// load WC testing framework
|
2014-09-01 06:03:52 +00:00
|
|
|
$this->includes();
|
|
|
|
}
|
|
|
|
|
2014-09-01 20:04:09 +00:00
|
|
|
/**
|
2015-11-03 13:31:20 +00:00
|
|
|
* Load WooCommerce.
|
2014-09-01 20:04:09 +00:00
|
|
|
*
|
|
|
|
* @since 2.2
|
|
|
|
*/
|
|
|
|
public function load_wc() {
|
2017-11-06 21:25:02 +00:00
|
|
|
define( 'WC_TAX_ROUNDING_MODE', 'auto' );
|
2014-09-01 20:04:09 +00:00
|
|
|
require_once( $this->plugin_dir . '/woocommerce.php' );
|
|
|
|
}
|
2014-09-01 06:03:52 +00:00
|
|
|
|
|
|
|
/**
|
2015-11-03 13:31:20 +00:00
|
|
|
* Install WooCommerce after the test environment and WC have been loaded.
|
2014-09-01 06:03:52 +00:00
|
|
|
*
|
|
|
|
* @since 2.2
|
|
|
|
*/
|
|
|
|
public function install_wc() {
|
|
|
|
|
2017-01-23 17:37:26 +00:00
|
|
|
// Clean existing install first.
|
2014-09-01 20:04:09 +00:00
|
|
|
define( 'WP_UNINSTALL_PLUGIN', true );
|
2016-08-24 16:34:13 +00:00
|
|
|
define( 'WC_REMOVE_ALL_DATA', true );
|
2014-09-01 20:04:09 +00:00
|
|
|
include( $this->plugin_dir . '/uninstall.php' );
|
2014-09-01 06:03:52 +00:00
|
|
|
|
2014-11-25 17:09:19 +00:00
|
|
|
WC_Install::install();
|
2014-09-01 06:03:52 +00:00
|
|
|
|
2017-01-23 17:37:26 +00:00
|
|
|
// Reload capabilities after install, see https://core.trac.wordpress.org/ticket/28374
|
|
|
|
if ( version_compare( $GLOBALS['wp_version'], '4.7', '<' ) ) {
|
|
|
|
$GLOBALS['wp_roles']->reinit();
|
|
|
|
} else {
|
|
|
|
$GLOBALS['wp_roles'] = null;
|
|
|
|
wp_roles();
|
|
|
|
}
|
2014-09-01 06:03:52 +00:00
|
|
|
|
2017-01-23 17:37:26 +00:00
|
|
|
echo 'Installing WooCommerce...' . PHP_EOL;
|
2014-09-01 20:04:09 +00:00
|
|
|
}
|
2014-09-01 06:03:52 +00:00
|
|
|
|
|
|
|
/**
|
2015-11-03 13:31:20 +00:00
|
|
|
* Load WC-specific test cases and factories.
|
2014-09-01 06:03:52 +00:00
|
|
|
*
|
|
|
|
* @since 2.2
|
|
|
|
*/
|
|
|
|
public function includes() {
|
|
|
|
|
2014-09-05 18:34:51 +00:00
|
|
|
// framework
|
|
|
|
require_once( $this->tests_dir . '/framework/class-wc-unit-test-factory.php' );
|
2014-09-05 06:35:53 +00:00
|
|
|
require_once( $this->tests_dir . '/framework/class-wc-mock-session-handler.php' );
|
2016-03-11 21:48:16 +00:00
|
|
|
require_once( $this->tests_dir . '/framework/class-wc-mock-wc-data.php' );
|
2017-04-24 18:33:17 +00:00
|
|
|
require_once( $this->tests_dir . '/framework/class-wc-mock-wc-object-query.php' );
|
2016-02-08 19:57:48 +00:00
|
|
|
require_once( $this->tests_dir . '/framework/class-wc-payment-token-stub.php' );
|
2016-07-25 18:19:44 +00:00
|
|
|
require_once( $this->tests_dir . '/framework/vendor/class-wp-test-spy-rest-server.php' );
|
2014-09-05 18:34:51 +00:00
|
|
|
|
|
|
|
// test cases
|
2014-09-01 06:03:52 +00:00
|
|
|
require_once( $this->tests_dir . '/framework/class-wc-unit-test-case.php' );
|
|
|
|
require_once( $this->tests_dir . '/framework/class-wc-api-unit-test-case.php' );
|
2016-07-25 18:19:44 +00:00
|
|
|
require_once( $this->tests_dir . '/framework/class-wc-rest-unit-test-case.php' );
|
2014-10-21 22:26:04 +00:00
|
|
|
|
|
|
|
// Helpers
|
|
|
|
require_once( $this->tests_dir . '/framework/helpers/class-wc-helper-product.php' );
|
2014-10-28 10:51:46 +00:00
|
|
|
require_once( $this->tests_dir . '/framework/helpers/class-wc-helper-coupon.php' );
|
2014-10-30 18:08:33 +00:00
|
|
|
require_once( $this->tests_dir . '/framework/helpers/class-wc-helper-fee.php' );
|
2014-10-30 19:58:19 +00:00
|
|
|
require_once( $this->tests_dir . '/framework/helpers/class-wc-helper-shipping.php' );
|
2014-12-10 23:02:43 +00:00
|
|
|
require_once( $this->tests_dir . '/framework/helpers/class-wc-helper-customer.php' );
|
2015-05-23 08:48:07 +00:00
|
|
|
require_once( $this->tests_dir . '/framework/helpers/class-wc-helper-order.php' );
|
2016-01-08 13:56:01 +00:00
|
|
|
require_once( $this->tests_dir . '/framework/helpers/class-wc-helper-shipping-zones.php' );
|
2016-02-08 19:57:48 +00:00
|
|
|
require_once( $this->tests_dir . '/framework/helpers/class-wc-helper-payment-token.php' );
|
2016-03-07 21:46:40 +00:00
|
|
|
require_once( $this->tests_dir . '/framework/helpers/class-wc-helper-settings.php' );
|
2014-09-01 06:03:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-11-03 13:31:20 +00:00
|
|
|
* Get the single class instance.
|
2014-09-01 06:03:52 +00:00
|
|
|
*
|
|
|
|
* @since 2.2
|
|
|
|
* @return WC_Unit_Tests_Bootstrap
|
|
|
|
*/
|
|
|
|
public static function instance() {
|
|
|
|
if ( is_null( self::$instance ) ) {
|
|
|
|
self::$instance = new self();
|
|
|
|
}
|
|
|
|
|
|
|
|
return self::$instance;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
WC_Unit_Tests_Bootstrap::instance();
|