Merge pull request #25011 from woocommerce/try/add-wc-admin

wc-admin: Include package
This commit is contained in:
Peter Fabian 2020-02-06 12:09:25 +01:00 committed by GitHub
commit 7233dc8a2e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 100 additions and 22 deletions

View File

@ -34,6 +34,7 @@ output 2 "Done!"
output 3 "Updating package JS textdomains..."
find ./packages/woocommerce-blocks -iname '*.js' -exec sed -i.bak -e "s/'woo-gutenberg-products-block'/'woocommerce'/g" -e "s/\"woo-gutenberg-products-block\"/'woocommerce'/g" {} \;
find ./packages/woocommerce-admin -iname '*.js' -exec sed -i.bak -e "s/, 'woocommerce-admin'/, 'woocommerce'/g" {} \;
# Cleanup backup files
find ./packages -name "*.bak" -type f -delete

View File

@ -15,7 +15,8 @@
"pelago/emogrifier": "^3.1",
"woocommerce/action-scheduler": "3.0.1",
"woocommerce/woocommerce-blocks": "2.5.11",
"woocommerce/woocommerce-rest-api": "1.0.7"
"woocommerce/woocommerce-rest-api": "1.0.7",
"woocommerce/woocommerce-admin": "0.25.0"
},
"require-dev": {
"phpunit/phpunit": "7.5.20",
@ -72,7 +73,8 @@
"installer-paths": {
"packages/action-scheduler": ["woocommerce/action-scheduler"],
"packages/woocommerce-rest-api": ["woocommerce/woocommerce-rest-api"],
"packages/woocommerce-blocks": ["woocommerce/woocommerce-blocks"]
"packages/woocommerce-blocks": ["woocommerce/woocommerce-blocks"],
"packages/woocommerce-admin": ["woocommerce/woocommerce-admin"]
},
"scripts-description": {
"test": "Run unit tests",

49
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "3f7510fcb2dbb7503513ffaf674c4200",
"content-hash": "ae3bf0d9840be88a437c9415ef00c8e2",
"packages": [
{
"name": "automattic/jetpack-autoloader",
@ -416,6 +416,53 @@
"homepage": "https://actionscheduler.org/",
"time": "2020-01-14T01:30:08+00:00"
},
{
"name": "woocommerce/woocommerce-admin",
"version": "v0.25.0",
"source": {
"type": "git",
"url": "https://github.com/woocommerce/woocommerce-admin.git",
"reference": "3543ad7073522da5bc0782c0728db6c956695fc3"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/woocommerce/woocommerce-admin/zipball/3543ad7073522da5bc0782c0728db6c956695fc3",
"reference": "3543ad7073522da5bc0782c0728db6c956695fc3",
"shasum": ""
},
"require": {
"automattic/jetpack-autoloader": "^1.2.0",
"composer/installers": "1.7.0",
"php": ">=5.6|>=7.0"
},
"require-dev": {
"phpunit/phpunit": "7.5.20",
"woocommerce/woocommerce-sniffs": "0.0.9"
},
"type": "wordpress-plugin",
"extra": {
"scripts-description": {
"test": "Run unit tests",
"phpcs": "Analyze code against the WordPress coding standards with PHP_CodeSniffer",
"phpcbf": "Fix coding standards warnings/errors automatically with PHP Code Beautifier"
}
},
"autoload": {
"classmap": [
"includes/"
],
"psr-4": {
"Automattic\\WooCommerce\\Admin\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"GPL-3.0-or-later"
],
"description": "A modern, javascript-driven WooCommerce Admin experience.",
"homepage": "https://github.com/woocommerce/woocommerce-admin",
"time": "2020-02-04T23:56:22+00:00"
},
{
"name": "woocommerce/woocommerce-blocks",
"version": "v2.5.11",

View File

@ -462,7 +462,11 @@ class WC_Install {
wp_schedule_single_event( time() + ( absint( $held_duration ) * 60 ), 'woocommerce_cancel_unpaid_orders' );
}
wp_schedule_event( time(), 'daily', 'woocommerce_cleanup_personal_data' );
// Delay the first run of `woocommerce_cleanup_personal_data` by 10 seconds
// so it doesn't occur in the same request. WooCommerce Admin also schedules
// a daily cron that gets lost due to a race condition. WC_Privacy's background
// processing instance updates the cron schedule from within a cron job.
wp_schedule_event( time() + 10, 'daily', 'woocommerce_cleanup_personal_data' );
wp_schedule_event( time() + ( 3 * HOUR_IN_SECONDS ), 'daily', 'woocommerce_cleanup_logs' );
wp_schedule_event( time() + ( 6 * HOUR_IN_SECONDS ), 'twicedaily', 'woocommerce_cleanup_sessions' );
wp_schedule_event( time() + MINUTE_IN_SECONDS, 'fifteendays', 'woocommerce_geoip_updater' );

View File

@ -29,6 +29,7 @@ class Packages {
protected static $packages = array(
'woocommerce-blocks' => '\\Automattic\\WooCommerce\\Blocks\\Package',
'woocommerce-rest-api' => '\\Automattic\\WooCommerce\\RestApi\\Package',
'woocommerce-admin' => '\\Automattic\\WooCommerce\\Admin\\Package',
);
/**

View File

@ -3,6 +3,11 @@
* WooCommerce Unit Tests Bootstrap
*
* @since 2.2
* @package WooCommerce Tests
*/
/**
* Class WC_Unit_Tests_Bootstrap
*/
class WC_Unit_Tests_Bootstrap {
@ -25,10 +30,8 @@ class WC_Unit_Tests_Bootstrap {
*/
public function __construct() {
// phpcs:disable WordPress.PHP.DiscouragedPHPFunctions, WordPress.PHP.DevelopmentFunctions
ini_set( 'display_errors', 'on' );
error_reporting( E_ALL );
// phpcs:enable WordPress.PHP.DiscouragedPHPFunctions, WordPress.PHP.DevelopmentFunctions
ini_set( 'display_errors', 'on' ); // phpcs:ignore WordPress.PHP.IniSet.display_errors_Blacklisted
error_reporting( E_ALL ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.prevent_path_disclosure_error_reporting, WordPress.PHP.DiscouragedPHPFunctions.runtime_configuration_error_reporting
// Ensure server variable is set for WP email functions.
// phpcs:disable WordPress.VIP.SuperGlobalInputUsage.AccessDetected
@ -41,19 +44,19 @@ class WC_Unit_Tests_Bootstrap {
$this->plugin_dir = dirname( $this->tests_dir );
$this->wp_tests_dir = getenv( 'WP_TESTS_DIR' ) ? getenv( 'WP_TESTS_DIR' ) : '/tmp/wordpress-tests-lib';
// load test function so tests_add_filter() is available
// load test function so tests_add_filter() is available.
require_once $this->wp_tests_dir . '/includes/functions.php';
// load WC
// load WC.
tests_add_filter( 'muplugins_loaded', array( $this, 'load_wc' ) );
// install WC
// install WC.
tests_add_filter( 'setup_theme', array( $this, 'install_wc' ) );
// load the WP testing environment
// load the WP testing environment.
require_once $this->wp_tests_dir . '/includes/bootstrap.php';
// load WC testing framework
// load WC testing framework.
$this->includes();
}
@ -82,11 +85,15 @@ class WC_Unit_Tests_Bootstrap {
WC_Install::install();
// Reload capabilities after install, see https://core.trac.wordpress.org/ticket/28374
// Initialize the WC API extensions.
\Automattic\WooCommerce\Admin\Install::create_tables();
\Automattic\WooCommerce\Admin\Install::create_events();
// 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.
$GLOBALS['wp_roles'] = null; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
wp_roles();
}
@ -100,7 +107,7 @@ class WC_Unit_Tests_Bootstrap {
*/
public function includes() {
// framework
// framework.
require_once $this->tests_dir . '/framework/class-wc-unit-test-factory.php';
require_once $this->tests_dir . '/framework/class-wc-mock-session-handler.php';
require_once $this->tests_dir . '/framework/class-wc-mock-wc-data.php';
@ -109,13 +116,13 @@ class WC_Unit_Tests_Bootstrap {
require_once $this->tests_dir . '/framework/class-wc-payment-token-stub.php';
require_once $this->tests_dir . '/framework/vendor/class-wp-test-spy-rest-server.php';
// test cases
// test cases.
require_once $this->tests_dir . '/includes/wp-http-testcase.php';
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';
require_once $this->tests_dir . '/framework/class-wc-rest-unit-test-case.php';
// Helpers
// Helpers.
require_once $this->tests_dir . '/framework/helpers/class-wc-helper-product.php';
require_once $this->tests_dir . '/framework/helpers/class-wc-helper-coupon.php';
require_once $this->tests_dir . '/framework/helpers/class-wc-helper-fee.php';

View File

@ -27,6 +27,7 @@ class WC_Tests_Packages extends WC_Unit_Test_Case {
public function test_packages_exist() {
$this->assertTrue( \Automattic\WooCommerce\Packages::package_exists( 'woocommerce-blocks' ) );
$this->assertTrue( \Automattic\WooCommerce\Packages::package_exists( 'woocommerce-rest-api' ) );
$this->assertTrue( \Automattic\WooCommerce\Packages::package_exists( 'woocommerce-admin' ) );
}
/**
@ -35,6 +36,7 @@ class WC_Tests_Packages extends WC_Unit_Test_Case {
public function test_autoload_packages() {
$this->assertTrue( class_exists( '\Automattic\WooCommerce\Blocks\Package' ) );
$this->assertTrue( class_exists( '\Automattic\WooCommerce\RestApi\Package' ) );
$this->assertTrue( class_exists( '\Automattic\WooCommerce\Admin\Package' ) );
}
/**

View File

@ -28,6 +28,20 @@ wp_clear_scheduled_hook( 'woocommerce_tracker_send_event' );
* and to ensure only the site owner can perform this action.
*/
if ( Constants::is_true( 'WC_REMOVE_ALL_DATA' ) ) {
/**
* Load core packages autoloader.
*/
if ( ! class_exists( 'Automattic\WooCommerce\Admin\Install' ) ) {
require __DIR__ . '/src/Autoloader.php';
if ( \Automattic\WooCommerce\Autoloader::init() ) {
// Hook in WooCommerce Admin installation code.
// @todo an alternate way to do this is allow FeaturePlugin::has_satisfied_dependencies()
// to work during uninstall - (no WooCommerce instance).
\Automattic\WooCommerce\Admin\Install::drop_tables();
}
}
include_once dirname( __FILE__ ) . '/includes/class-wc-install.php';
// Roles + caps.
@ -72,21 +86,21 @@ if ( Constants::is_true( 'WC_REMOVE_ALL_DATA' ) ) {
// Delete terms if > WP 4.2 (term splitting was added in 4.2).
if ( version_compare( $wp_version, '4.2', '>=' ) ) {
// Delete term taxonomies.
foreach ( array( 'product_cat', 'product_tag', 'product_shipping_class', 'product_type' ) as $taxonomy ) {
foreach ( array( 'product_cat', 'product_tag', 'product_shipping_class', 'product_type' ) as $_taxonomy ) {
$wpdb->delete(
$wpdb->term_taxonomy,
array(
'taxonomy' => $taxonomy,
'taxonomy' => $_taxonomy,
)
);
}
// Delete term attributes.
foreach ( $wc_attributes as $taxonomy ) {
foreach ( $wc_attributes as $_taxonomy ) {
$wpdb->delete(
$wpdb->term_taxonomy,
array(
'taxonomy' => 'pa_' . $taxonomy,
'taxonomy' => 'pa_' . $_taxonomy,
)
);
}