From 6f9dd9c61bf465dac5139c081f5023cdcfee948a Mon Sep 17 00:00:00 2001 From: Peter Fabian Date: Fri, 2 Nov 2018 11:31:41 +0100 Subject: [PATCH] Moved wc-admin installation to phpunit bootstrap. --- plugins/woocommerce-admin/bin/phpunit.sh | 3 -- plugins/woocommerce-admin/tests/bootstrap.php | 30 +++++++++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/plugins/woocommerce-admin/bin/phpunit.sh b/plugins/woocommerce-admin/bin/phpunit.sh index 1b183e06978..080409f8a88 100755 --- a/plugins/woocommerce-admin/bin/phpunit.sh +++ b/plugins/woocommerce-admin/bin/phpunit.sh @@ -1,5 +1,2 @@ #!/usr/bin/env bash -WORKING_DIR="$PWD" -cd "/tmp/wordpress/wp-content/plugins/wc-admin/" phpunit -c phpunit.xml.dist -cd "$WORKING_DIR" diff --git a/plugins/woocommerce-admin/tests/bootstrap.php b/plugins/woocommerce-admin/tests/bootstrap.php index 0abac9a914c..c12ea13e5c7 100755 --- a/plugins/woocommerce-admin/tests/bootstrap.php +++ b/plugins/woocommerce-admin/tests/bootstrap.php @@ -28,6 +28,34 @@ function wc_dir() { return dirname( dirname( dirname( __FILE__ ) ) ) . '/woocommerce'; } +/** + * 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. + require_once dirname( dirname( __FILE__ ) ) . '/includes/class-wc-admin-api-init.php'; + + WC_Admin_Api_Init::install(); + + if ( ! wp_next_scheduled( 'wc_admin_daily' ) ) { + wp_schedule_event( time(), 'daily', 'wc_admin_daily' ); + } + + // 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; // WPCS: override ok. + wp_roles(); + } + + echo esc_html( 'Installing wc-admin...' . PHP_EOL ); +} + /** * Adds WooCommerce testing framework classes. */ @@ -72,6 +100,8 @@ function _manually_load_plugin() { define( 'WC_USE_TRANSACTIONS', false ); require_once wc_dir() . '/woocommerce.php'; + wc_admin_install(); + require dirname( dirname( __FILE__ ) ) . '/wc-admin.php'; } tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' );