2018-04-17 21:03:14 +00:00
< ? php
/**
* PHPUnit bootstrap file
*
2018-07-10 12:48:06 +00:00
* @ package WC_Admin
2018-04-17 21:03:14 +00:00
*/
$_tests_dir = getenv ( 'WP_TESTS_DIR' );
if ( ! $_tests_dir ) {
$_tests_dir = rtrim ( sys_get_temp_dir (), '/\\' ) . '/wordpress-tests-lib' ;
}
if ( ! file_exists ( $_tests_dir . '/includes/functions.php' ) ) {
2018-09-24 15:49:21 +00:00
echo " Could not find $_tests_dir /includes/functions.php, have you run bin/install-wp-tests.sh ? " . PHP_EOL ; // phpcs:ignore WordPress.XSS.EscapeOutput.OutputNotEscaped
2018-04-17 21:03:14 +00:00
exit ( 1 );
}
// Give access to tests_add_filter() function.
require_once $_tests_dir . '/includes/functions.php' ;
2018-09-24 15:49:21 +00:00
/**
* Returns WooCommerce main directory .
*
* @ return string
*/
2018-09-20 14:20:04 +00:00
function wc_dir () {
return dirname ( dirname ( dirname ( __FILE__ ) ) ) . '/woocommerce' ;
}
2018-11-02 10:31:41 +00:00
/**
* Install wc admin .
*/
function wc_admin_install () {
// Clean existing install first.
define ( 'WP_UNINSTALL_PLUGIN' , true );
define ( 'WC_REMOVE_ALL_DATA' , true );
// Initialize the WC API extensions.
2019-08-12 21:52:09 +00:00
\Automattic\WooCommerce\Admin\Install :: create_tables ();
\Automattic\WooCommerce\Admin\Install :: create_events ();
2018-11-02 10:31:41 +00:00
// Reload capabilities after install, see https://core.trac.wordpress.org/ticket/28374.
2019-02-12 20:22:16 +00:00
$GLOBALS [ 'wp_roles' ] = null ; // WPCS: override ok.
wp_roles ();
2018-11-02 10:31:41 +00:00
2019-03-13 17:14:02 +00:00
echo esc_html ( 'Installing woocommerce-admin...' . PHP_EOL );
2018-11-02 10:31:41 +00:00
}
2018-09-24 15:49:21 +00:00
/**
* Adds WooCommerce testing framework classes .
*/
2018-09-20 14:20:04 +00:00
function wc_test_includes () {
2018-12-12 21:13:49 +00:00
$wc_tests_framework_base_dir = wc_dir () . '/tests' ;
2018-09-20 14:20:04 +00:00
// WooCommerce test classes.
// Framework.
require_once $wc_tests_framework_base_dir . '/framework/class-wc-unit-test-factory.php' ;
require_once $wc_tests_framework_base_dir . '/framework/class-wc-mock-session-handler.php' ;
require_once $wc_tests_framework_base_dir . '/framework/class-wc-mock-wc-data.php' ;
require_once $wc_tests_framework_base_dir . '/framework/class-wc-mock-wc-object-query.php' ;
require_once $wc_tests_framework_base_dir . '/framework/class-wc-mock-payment-gateway.php' ;
require_once $wc_tests_framework_base_dir . '/framework/class-wc-payment-token-stub.php' ;
require_once $wc_tests_framework_base_dir . '/framework/vendor/class-wp-test-spy-rest-server.php' ;
// Test cases.
require_once $wc_tests_framework_base_dir . '/includes/wp-http-testcase.php' ;
require_once $wc_tests_framework_base_dir . '/framework/class-wc-unit-test-case.php' ;
require_once $wc_tests_framework_base_dir . '/framework/class-wc-api-unit-test-case.php' ;
require_once $wc_tests_framework_base_dir . '/framework/class-wc-rest-unit-test-case.php' ;
// Helpers.
require_once $wc_tests_framework_base_dir . '/framework/helpers/class-wc-helper-product.php' ;
require_once $wc_tests_framework_base_dir . '/framework/helpers/class-wc-helper-coupon.php' ;
require_once $wc_tests_framework_base_dir . '/framework/helpers/class-wc-helper-fee.php' ;
require_once $wc_tests_framework_base_dir . '/framework/helpers/class-wc-helper-shipping.php' ;
require_once $wc_tests_framework_base_dir . '/framework/helpers/class-wc-helper-customer.php' ;
require_once $wc_tests_framework_base_dir . '/framework/helpers/class-wc-helper-order.php' ;
require_once $wc_tests_framework_base_dir . '/framework/helpers/class-wc-helper-shipping-zones.php' ;
require_once $wc_tests_framework_base_dir . '/framework/helpers/class-wc-helper-payment-token.php' ;
require_once $wc_tests_framework_base_dir . '/framework/helpers/class-wc-helper-settings.php' ;
}
2018-04-17 21:03:14 +00:00
/**
* Manually load the plugin being tested .
*/
function _manually_load_plugin () {
2018-09-24 15:49:21 +00:00
define ( 'WC_TAX_ROUNDING_MODE' , 'auto' );
define ( 'WC_USE_TRANSACTIONS' , false );
2019-06-24 16:43:58 +00:00
update_option ( 'woocommerce_enable_coupons' , 'yes' );
2019-06-27 16:46:54 +00:00
update_option ( 'woocommerce_calc_taxes' , 'yes' );
2019-11-07 18:31:02 +00:00
define ( 'WOOCOMMERCE_ADMIN_ONBOARDING_ENABLED' , true );
2019-06-27 16:46:54 +00:00
2018-09-24 15:49:21 +00:00
require_once wc_dir () . '/woocommerce.php' ;
2019-08-12 17:54:04 +00:00
require dirname ( __DIR__ ) . '/vendor/autoload.php' ;
2018-09-24 15:49:21 +00:00
2018-11-02 10:31:41 +00:00
wc_admin_install ();
2019-03-13 17:14:02 +00:00
require dirname ( dirname ( __FILE__ ) ) . '/woocommerce-admin.php' ;
2018-04-17 21:03:14 +00:00
}
tests_add_filter ( 'muplugins_loaded' , '_manually_load_plugin' );
// Start up the WP testing environment.
require $_tests_dir . '/includes/bootstrap.php' ;
2018-09-20 14:20:04 +00:00
wc_test_includes ();
// Include wc-admin helpers.
require_once dirname ( __FILE__ ) . '/framework/helpers/class-wc-helper-reports.php' ;
2018-11-14 19:06:53 +00:00
require_once dirname ( __FILE__ ) . '/framework/helpers/class-wc-helper-admin-notes.php' ;
2019-01-12 01:13:12 +00:00
require_once dirname ( __FILE__ ) . '/framework/helpers/class-wc-test-action-queue.php' ;
2019-01-30 16:59:45 +00:00
require_once dirname ( __FILE__ ) . '/framework/helpers/class-wc-helper-queue.php' ;
2019-02-12 20:02:02 +00:00
/**
2019-09-25 18:20:15 +00:00
* Use the `development` features for testing .
2019-02-12 20:02:02 +00:00
*/
2019-09-25 18:20:15 +00:00
function wc_admin_add_development_features () {
2019-02-14 23:04:30 +00:00
$config = json_decode ( file_get_contents ( dirname ( dirname ( __FILE__ ) ) . '/config/development.json' ) ); // @codingStandardsIgnoreLine.
2019-02-12 20:02:02 +00:00
$flags = array ();
foreach ( $config -> features as $feature => $bool ) {
$flags [ $feature ] = $bool ;
}
return $flags ;
}
2019-09-25 18:20:15 +00:00
tests_add_filter ( 'wc_admin_get_feature_config' , 'wc_admin_add_development_features' );