2019-06-10 11:36:11 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* PHPUnit bootstrap file
|
|
|
|
*
|
2019-06-21 09:40:39 +00:00
|
|
|
* @package Automattic/WooCommerce/RestApi
|
2019-06-10 11:36:11 +00:00
|
|
|
*/
|
2019-06-21 09:40:39 +00:00
|
|
|
namespace Automattic\WooCommerce\RestApi\UnitTests;
|
2019-06-10 11:36:11 +00:00
|
|
|
|
2019-06-10 15:32:12 +00:00
|
|
|
require __DIR__ . '/../src/Utilities/SingletonTrait.php';
|
|
|
|
|
2019-06-21 09:40:39 +00:00
|
|
|
use Automattic\WooCommerce\RestApi\Utilities\SingletonTrait;
|
2019-06-10 15:32:12 +00:00
|
|
|
|
2019-06-10 11:36:11 +00:00
|
|
|
class Bootstrap {
|
2019-06-10 15:32:12 +00:00
|
|
|
use SingletonTrait;
|
2019-06-10 11:36:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Directory path to WP core tests.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2019-06-10 15:32:12 +00:00
|
|
|
protected $wp_tests_dir;
|
2019-06-10 11:36:11 +00:00
|
|
|
|
|
|
|
/**
|
2019-06-24 15:17:02 +00:00
|
|
|
* Tests directory.
|
2019-06-11 10:57:20 +00:00
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $tests_dir;
|
|
|
|
|
|
|
|
/**
|
2019-06-24 15:17:02 +00:00
|
|
|
* WC Core unit tests directory.
|
2019-06-10 11:36:11 +00:00
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2019-06-10 15:32:12 +00:00
|
|
|
protected $wc_tests_dir;
|
2019-06-12 12:09:20 +00:00
|
|
|
|
2019-06-11 10:57:20 +00:00
|
|
|
/**
|
|
|
|
* This plugin directory.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $plugin_dir;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Plugins directory.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $plugins_dir;
|
|
|
|
|
2019-06-10 11:36:11 +00:00
|
|
|
/**
|
|
|
|
* Init unit testing library.
|
|
|
|
*/
|
2019-06-10 15:32:12 +00:00
|
|
|
public function init() {
|
2019-06-11 11:08:56 +00:00
|
|
|
$this->wp_tests_dir = getenv( 'WP_TESTS_DIR' ) ? getenv( 'WP_TESTS_DIR' ) : rtrim( sys_get_temp_dir(), '/\\' ) . '/wordpress-tests-lib';
|
2019-06-11 10:57:20 +00:00
|
|
|
$this->tests_dir = dirname( __FILE__ );
|
|
|
|
$this->plugin_dir = dirname( $this->tests_dir );
|
2019-06-11 11:10:53 +00:00
|
|
|
|
2019-06-11 11:08:56 +00:00
|
|
|
if ( file_exists( dirname( $this->plugin_dir ) . '/woocommerce/woocommerce.php' ) ) {
|
|
|
|
// From plugin directory.
|
|
|
|
$this->plugins_dir = dirname( $this->plugin_dir );
|
|
|
|
} else {
|
|
|
|
// Travis.
|
2019-06-11 11:10:53 +00:00
|
|
|
$this->plugins_dir = getenv( 'WP_CORE_DIR' ) . '/wp-content/plugins';
|
2019-06-11 11:08:56 +00:00
|
|
|
}
|
|
|
|
|
2019-06-11 10:57:20 +00:00
|
|
|
$this->wc_tests_dir = $this->plugins_dir . '/woocommerce/tests';
|
2019-06-10 11:36:11 +00:00
|
|
|
|
2019-06-10 15:32:12 +00:00
|
|
|
$this->setup_hooks();
|
|
|
|
$this->load_framework();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get tests dir.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function get_dir() {
|
2019-06-11 09:44:54 +00:00
|
|
|
return dirname( __FILE__ );
|
2019-06-10 11:36:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Setup hooks.
|
|
|
|
*/
|
2019-06-10 15:32:12 +00:00
|
|
|
protected function setup_hooks() {
|
2019-06-10 11:36:11 +00:00
|
|
|
// Give access to tests_add_filter() function.
|
2019-06-10 15:32:12 +00:00
|
|
|
require_once $this->wp_tests_dir . '/includes/functions.php';
|
2019-06-10 11:36:11 +00:00
|
|
|
|
|
|
|
\tests_add_filter( 'muplugins_loaded', function() {
|
2019-06-11 10:57:20 +00:00
|
|
|
require_once $this->plugins_dir . '/woocommerce/woocommerce.php';
|
|
|
|
require_once $this->plugin_dir . '/woocommerce-rest-api.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 );
|
2019-06-11 10:57:20 +00:00
|
|
|
include $this->plugins_dir . '/woocommerce/uninstall.php';
|
2019-06-10 11:36:11 +00:00
|
|
|
|
|
|
|
\WC_Install::install();
|
|
|
|
|
|
|
|
$GLOBALS['wp_roles'] = null; // WPCS: override ok.
|
|
|
|
\wp_roles();
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Load the testing framework.
|
|
|
|
*/
|
2019-06-10 15:32:12 +00:00
|
|
|
protected function load_framework() {
|
2019-06-10 11:36:11 +00:00
|
|
|
// Start up the WP testing environment.
|
2019-06-10 15:32:12 +00:00
|
|
|
require_once $this->wp_tests_dir . '/includes/bootstrap.php';
|
2019-06-10 11:36:11 +00:00
|
|
|
|
|
|
|
// WooCommerce Core Testing Framework.
|
2020-05-07 17:37:35 +00:00
|
|
|
require_once $this->wc_tests_dir . '/legacy/framework/class-wc-unit-test-factory.php';
|
|
|
|
require_once $this->wc_tests_dir . '/legacy/framework/vendor/class-wp-test-spy-rest-server.php';
|
|
|
|
require_once $this->wc_tests_dir . '/legacy/includes/wp-http-testcase.php';
|
|
|
|
require_once $this->wc_tests_dir . '/legacy/framework/class-wc-unit-test-case.php';
|
|
|
|
require_once $this->wc_tests_dir . '/legacy/framework/class-wc-rest-unit-test-case.php';
|
2019-06-10 11:36:11 +00:00
|
|
|
|
2019-06-11 10:57:20 +00:00
|
|
|
require_once $this->tests_dir . '/Helpers/AdminNotesHelper.php';
|
|
|
|
require_once $this->tests_dir . '/Helpers/CouponHelper.php';
|
|
|
|
require_once $this->tests_dir . '/Helpers/CustomerHelper.php';
|
|
|
|
require_once $this->tests_dir . '/Helpers/OrderHelper.php';
|
|
|
|
require_once $this->tests_dir . '/Helpers/ProductHelper.php';
|
|
|
|
require_once $this->tests_dir . '/Helpers/ShippingHelper.php';
|
|
|
|
require_once $this->tests_dir . '/Helpers/SettingsHelper.php';
|
|
|
|
require_once $this->tests_dir . '/Helpers/QueueHelper.php';
|
|
|
|
require_once $this->tests_dir . '/AbstractRestApiTest.php';
|
2019-06-10 11:36:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-10 15:32:12 +00:00
|
|
|
Bootstrap::instance()->init();
|