2019-06-10 11:36:11 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* PHPUnit bootstrap file
|
|
|
|
*
|
|
|
|
* @package WooCommerce/RestApi
|
|
|
|
*/
|
|
|
|
namespace WooCommerce\RestApi\UnitTests;
|
|
|
|
|
|
|
|
class Bootstrap {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Directory path to WP core tests.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected static $wp_tests_dir;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Directory path to woocommerce core tests.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected static $wc_tests_dir;
|
|
|
|
/**
|
|
|
|
* Init unit testing library.
|
|
|
|
*/
|
|
|
|
public static function init() {
|
|
|
|
self::$wc_tests_dir = dirname( dirname( dirname( __FILE__ ) ) ) . '/woocommerce/tests';
|
2019-06-10 12:39:46 +00:00
|
|
|
self::$wp_tests_dir = getenv( 'WP_TESTS_DIR' );
|
2019-06-10 11:36:11 +00:00
|
|
|
|
|
|
|
if ( ! self::$wp_tests_dir ) {
|
|
|
|
self::$wp_tests_dir = rtrim( sys_get_temp_dir(), '/\\' ) . '/wordpress-tests-lib';
|
|
|
|
}
|
|
|
|
|
|
|
|
self::setup_hooks();
|
|
|
|
self::load_framework();
|
|
|
|
}
|
|
|
|
|
2019-06-10 12:39:46 +00:00
|
|
|
/**
|
|
|
|
* Should we skip WC Admin Reports tests?
|
|
|
|
*
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public static function skip_report_tests() {
|
|
|
|
return ! file_exists( dirname( dirname( __DIR__ ) ) . '/woocommerce-admin/woocommerce-admin.php' );
|
|
|
|
}
|
|
|
|
|
2019-06-10 11:36:11 +00:00
|
|
|
/**
|
|
|
|
* Setup hooks.
|
|
|
|
*/
|
|
|
|
protected static function setup_hooks() {
|
|
|
|
// Give access to tests_add_filter() function.
|
|
|
|
require_once self::$wp_tests_dir . '/includes/functions.php';
|
|
|
|
|
|
|
|
\tests_add_filter( 'muplugins_loaded', function() {
|
|
|
|
require_once dirname( dirname( __DIR__ ) ) . '/woocommerce/woocommerce.php';
|
|
|
|
require_once dirname( __DIR__ ) . '/woocommerce-rest-api.php';
|
2019-06-10 12:39:46 +00:00
|
|
|
|
|
|
|
if ( file_exists( dirname( dirname( __DIR__ ) ) . '/woocommerce-admin/woocommerce-admin.php' ) ) {
|
|
|
|
require_once dirname( dirname( __DIR__ ) ) . '/woocommerce-admin/woocommerce-admin.php';
|
|
|
|
}
|
2019-06-10 11:36:11 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
\tests_add_filter( 'setup_theme', function() {
|
|
|
|
echo \esc_html( 'Installing WooCommerce...' . PHP_EOL );
|
|
|
|
|
|
|
|
define( 'WP_UNINSTALL_PLUGIN', true );
|
|
|
|
define( 'WC_REMOVE_ALL_DATA', true );
|
|
|
|
include dirname( dirname( __DIR__ ) ) . '/woocommerce/uninstall.php';
|
|
|
|
|
|
|
|
\WC_Install::install();
|
|
|
|
|
2019-06-10 12:39:46 +00:00
|
|
|
if ( ! self::skip_report_tests() ) {
|
|
|
|
echo esc_html( 'Installing WooCommerce Admin...' . PHP_EOL );
|
|
|
|
require_once dirname( dirname( __DIR__ ) ) . '/woocommerce-admin/includes/class-wc-admin-install.php';
|
|
|
|
\WC_Admin_Install::create_tables();
|
|
|
|
\WC_Admin_Install::create_events();
|
|
|
|
}
|
|
|
|
|
2019-06-10 11:36:11 +00:00
|
|
|
$GLOBALS['wp_roles'] = null; // WPCS: override ok.
|
|
|
|
\wp_roles();
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Load the testing framework.
|
|
|
|
*/
|
|
|
|
protected static function load_framework() {
|
|
|
|
// Start up the WP testing environment.
|
|
|
|
require_once self::$wp_tests_dir . '/includes/bootstrap.php';
|
|
|
|
|
|
|
|
// WooCommerce Core Testing Framework.
|
|
|
|
require_once self::$wc_tests_dir . '/framework/class-wc-unit-test-factory.php';
|
|
|
|
require_once self::$wc_tests_dir . '/framework/vendor/class-wp-test-spy-rest-server.php';
|
|
|
|
require_once self::$wc_tests_dir . '/includes/wp-http-testcase.php';
|
|
|
|
require_once self::$wc_tests_dir . '/framework/class-wc-unit-test-case.php';
|
|
|
|
require_once self::$wc_tests_dir . '/framework/class-wc-rest-unit-test-case.php';
|
|
|
|
|
|
|
|
require_once __DIR__ . '/Helpers/AdminNotesHelper.php';
|
|
|
|
require_once __DIR__ . '/Helpers/CouponHelper.php';
|
|
|
|
require_once __DIR__ . '/Helpers/CustomerHelper.php';
|
|
|
|
require_once __DIR__ . '/Helpers/OrderHelper.php';
|
|
|
|
require_once __DIR__ . '/Helpers/ProductHelper.php';
|
|
|
|
require_once __DIR__ . '/Helpers/ShippingHelper.php';
|
|
|
|
require_once __DIR__ . '/Helpers/SettingsHelper.php';
|
|
|
|
require_once __DIR__ . '/Helpers/QueueHelper.php';
|
|
|
|
require_once __DIR__ . '/AbstractRestApiTest.php';
|
2019-06-10 12:39:46 +00:00
|
|
|
require_once __DIR__ . '/AbstractReportsTest.php';
|
2019-06-10 11:36:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Bootstrap::init();
|