Bump WooCommerce minimum required PHP version to 7.3 and upgrade to PHPUnit 9 (#37366)
This commit is contained in:
commit
2d9b4bdd46
|
@ -27,7 +27,7 @@
|
||||||
|
|
||||||
<!-- Configs -->
|
<!-- Configs -->
|
||||||
<config name="minimum_supported_wp_version" value="5.2" />
|
<config name="minimum_supported_wp_version" value="5.2" />
|
||||||
<config name="testVersion" value="7.2-" />
|
<config name="testVersion" value="7.3-" />
|
||||||
|
|
||||||
<!-- Rules -->
|
<!-- Rules -->
|
||||||
<rule ref="WooCommerce-Core" />
|
<rule ref="WooCommerce-Core" />
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
Significance: patch
|
||||||
|
Type: dev
|
||||||
|
|
||||||
|
Bump required PHP version to 7.3 and PHPUnit version to 9
|
|
@ -14,7 +14,7 @@
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=7.2",
|
"php": ">=7.3",
|
||||||
"automattic/jetpack-autoloader": "2.10.1",
|
"automattic/jetpack-autoloader": "2.10.1",
|
||||||
"automattic/jetpack-constants": "1.5.1",
|
"automattic/jetpack-constants": "1.5.1",
|
||||||
"composer/installers": "^1.9",
|
"composer/installers": "^1.9",
|
||||||
|
@ -27,8 +27,8 @@
|
||||||
"automattic/jetpack-changelogger": "^3.3.0",
|
"automattic/jetpack-changelogger": "^3.3.0",
|
||||||
"bamarni/composer-bin-plugin": "^1.4",
|
"bamarni/composer-bin-plugin": "^1.4",
|
||||||
"dms/phpunit-arraysubset-asserts": "^0.4.0",
|
"dms/phpunit-arraysubset-asserts": "^0.4.0",
|
||||||
"phpunit/phpunit": "^8.0",
|
"phpunit/phpunit": "^9.0",
|
||||||
"sebastian/comparator": "3.0.3",
|
"sebastian/comparator": "^4.0",
|
||||||
"yoast/phpunit-polyfills": "^1.0"
|
"yoast/phpunit-polyfills": "^1.0"
|
||||||
},
|
},
|
||||||
"config": {
|
"config": {
|
||||||
|
@ -40,7 +40,7 @@
|
||||||
},
|
},
|
||||||
"sort-packages": true,
|
"sort-packages": true,
|
||||||
"platform": {
|
"platform": {
|
||||||
"php": "7.2"
|
"php": "7.3"
|
||||||
},
|
},
|
||||||
"allow-plugins": {
|
"allow-plugins": {
|
||||||
"automattic/jetpack-autoloader": true,
|
"automattic/jetpack-autoloader": true,
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -57,7 +57,6 @@ class WC_Admin_Notices {
|
||||||
add_action( 'woocommerce_installed', array( __CLASS__, 'reset_admin_notices' ) );
|
add_action( 'woocommerce_installed', array( __CLASS__, 'reset_admin_notices' ) );
|
||||||
add_action( 'wp_loaded', array( __CLASS__, 'add_redirect_download_method_notice' ) );
|
add_action( 'wp_loaded', array( __CLASS__, 'add_redirect_download_method_notice' ) );
|
||||||
add_action( 'admin_init', array( __CLASS__, 'hide_notices' ), 20 );
|
add_action( 'admin_init', array( __CLASS__, 'hide_notices' ), 20 );
|
||||||
self::add_action( 'admin_init', array( __CLASS__, 'maybe_remove_php73_required_notice' ) );
|
|
||||||
|
|
||||||
// @TODO: This prevents Action Scheduler async jobs from storing empty list of notices during WC installation.
|
// @TODO: This prevents Action Scheduler async jobs from storing empty list of notices during WC installation.
|
||||||
// That could lead to OBW not starting and 'Run setup wizard' notice not appearing in WP admin, which we want
|
// That could lead to OBW not starting and 'Run setup wizard' notice not appearing in WP admin, which we want
|
||||||
|
@ -120,53 +119,8 @@ class WC_Admin_Notices {
|
||||||
self::add_notice( 'template_files' );
|
self::add_notice( 'template_files' );
|
||||||
self::add_min_version_notice();
|
self::add_min_version_notice();
|
||||||
self::add_maxmind_missing_license_key_notice();
|
self::add_maxmind_missing_license_key_notice();
|
||||||
self::maybe_add_php73_required_notice();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// phpcs:disable Generic.Commenting.Todo.TaskFound
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add an admin notice about the bump of the required PHP version in WooCommerce 7.7
|
|
||||||
* if the current PHP version is too old.
|
|
||||||
*
|
|
||||||
* TODO: Remove this method in WooCommerce 7.7.
|
|
||||||
*/
|
|
||||||
private static function maybe_add_php73_required_notice() {
|
|
||||||
if ( version_compare( phpversion(), '7.3', '>=' ) ) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
self::add_custom_notice(
|
|
||||||
'php73_required_in_woo_77',
|
|
||||||
sprintf(
|
|
||||||
'%s%s',
|
|
||||||
sprintf(
|
|
||||||
'<h4>%s</h4>',
|
|
||||||
esc_html__( 'PHP version requirements will change soon', 'woocommerce' )
|
|
||||||
),
|
|
||||||
sprintf(
|
|
||||||
// translators: Placeholder is a URL.
|
|
||||||
wpautop( wp_kses_data( __( 'WooCommerce 7.7, scheduled for <b>May 2023</b>, will require PHP 7.3 or newer to work. Your server is currently running an older version of PHP, so this change will impact your store. Upgrading to at least PHP 8.0 is recommended. <b><a href="%s">Learn more about this change.</a></b>', 'woocommerce' ) ) ),
|
|
||||||
'https://developer.woocommerce.com/2023/01/10/new-requirement-for-woocommerce-7-7-php-7-3/'
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove the admin notice about the bump of the required PHP version in WooCommerce 7.7
|
|
||||||
* if the current PHP version is good.
|
|
||||||
*
|
|
||||||
* TODO: Remove this method in WooCommerce 7.7.
|
|
||||||
*/
|
|
||||||
private static function maybe_remove_php73_required_notice() {
|
|
||||||
if ( version_compare( phpversion(), '7.3', '>=' ) && self::has_notice( 'php73_required_in_woo_77' ) ) {
|
|
||||||
self::remove_notice( 'php73_required_in_woo_77' );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// phpcs:enable Generic.Commenting.Todo.TaskFound
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show a notice.
|
* Show a notice.
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<phpunit
|
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
bootstrap="tests/legacy/bootstrap.php"
|
bootstrap="tests/legacy/bootstrap.php"
|
||||||
backupGlobals="false"
|
backupGlobals="false"
|
||||||
colors="true"
|
colors="true"
|
||||||
|
@ -7,18 +7,19 @@
|
||||||
convertNoticesToExceptions="true"
|
convertNoticesToExceptions="true"
|
||||||
convertWarningsToExceptions="true"
|
convertWarningsToExceptions="true"
|
||||||
verbose="true"
|
verbose="true"
|
||||||
>
|
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
|
||||||
<testsuites>
|
<testsuites>
|
||||||
<testsuite name="WooCommerce Test Suite">
|
<testsuite name="WooCommerce Test Suite">
|
||||||
<directory suffix=".php">./tests/legacy/unit-tests</directory>
|
<directory suffix=".php">./tests/legacy/unit-tests</directory>
|
||||||
<directory suffix=".php">./tests/php</directory>
|
<directory suffix=".php">./tests/php</directory>
|
||||||
</testsuite>
|
</testsuite>
|
||||||
</testsuites>
|
</testsuites>
|
||||||
<filter>
|
<coverage includeUncoveredFiles="true">
|
||||||
<whitelist addUncoveredFilesFromWhitelist="true">
|
<include>
|
||||||
<directory suffix=".php">./includes</directory>
|
<directory suffix=".php">./includes</directory>
|
||||||
<file>woocommerce.php</file>
|
<file>woocommerce.php</file>
|
||||||
<file>uninstall.php</file>
|
<file>uninstall.php</file>
|
||||||
|
</include>
|
||||||
<exclude>
|
<exclude>
|
||||||
<directory suffix=".php">./includes/admin/helper/views</directory>
|
<directory suffix=".php">./includes/admin/helper/views</directory>
|
||||||
<directory suffix=".php">./includes/admin/importers/views</directory>
|
<directory suffix=".php">./includes/admin/importers/views</directory>
|
||||||
|
@ -44,6 +45,5 @@
|
||||||
<file>./includes/wc-template-hooks.php</file>
|
<file>./includes/wc-template-hooks.php</file>
|
||||||
<file>./includes/wc-widget-functions.php</file>
|
<file>./includes/wc-widget-functions.php</file>
|
||||||
</exclude>
|
</exclude>
|
||||||
</whitelist>
|
</coverage>
|
||||||
</filter>
|
|
||||||
</phpunit>
|
</phpunit>
|
||||||
|
|
|
@ -20,6 +20,8 @@ use PHPUnit\Framework\Constraint\IsType;
|
||||||
*/
|
*/
|
||||||
class WC_Unit_Test_Case extends WP_HTTP_TestCase {
|
class WC_Unit_Test_Case extends WP_HTTP_TestCase {
|
||||||
|
|
||||||
|
public const DEFAULT_FLOAT_COMPARISON_DELTA = 1e-10;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WC_Unit_Test_Factory instance.
|
* Holds the WC_Unit_Test_Factory instance.
|
||||||
*
|
*
|
||||||
|
@ -390,6 +392,18 @@ class WC_Unit_Test_Case extends WP_HTTP_TestCase {
|
||||||
$this->assertEmpty( $events );
|
$this->assertEmpty( $events );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Assert that the difference between two floats is smaller than a given delta.
|
||||||
|
*
|
||||||
|
* @param float $expected The expected value.
|
||||||
|
* @param float $actual The actual value.
|
||||||
|
* @param float|null $delta The maximum allowed difference, defaults to DEFAULT_FLOAT_COMPARISON_DELTA.
|
||||||
|
* @param string $message An optional error message to use if the assertion fails.
|
||||||
|
*/
|
||||||
|
public function assertFloatEquals( $expected, $actual, ?float $delta = null, string $message = '' ) {
|
||||||
|
$this->assertEqualsWithDelta( $expected, $actual, $delta ?? self::DEFAULT_FLOAT_COMPARISON_DELTA, $message );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mark test skipped when HPOS is enabled.
|
* Mark test skipped when HPOS is enabled.
|
||||||
*
|
*
|
||||||
|
|
|
@ -49,10 +49,10 @@ class WC_Tests_Admin_Dashboard extends WC_Unit_Test_Case {
|
||||||
|
|
||||||
$widget_output = $this->getActualOutput();
|
$widget_output = $this->getActualOutput();
|
||||||
|
|
||||||
$this->assertRegExp( '/page\=wc-admin\&\#038\;path\=\%2Fanalytics\%2Frevenue/', $widget_output );
|
$this->assertMatchesRegularExpression( '/page\=wc-admin\&\#038\;path\=\%2Fanalytics\%2Frevenue/', $widget_output );
|
||||||
$this->assertRegExp( '/page\=wc-admin\&\#038\;filter\=single_product/', $widget_output );
|
$this->assertMatchesRegularExpression( '/page\=wc-admin\&\#038\;filter\=single_product/', $widget_output );
|
||||||
$this->assertRegExp( '/page\=wc-admin\&\#038\;type\=lowstock/', $widget_output );
|
$this->assertMatchesRegularExpression( '/page\=wc-admin\&\#038\;type\=lowstock/', $widget_output );
|
||||||
$this->assertRegExp( '/page\=wc-admin\&\#038\;type\=outofstock/', $widget_output );
|
$this->assertMatchesRegularExpression( '/page\=wc-admin\&\#038\;type\=outofstock/', $widget_output );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -72,10 +72,10 @@ class WC_Tests_Admin_Dashboard extends WC_Unit_Test_Case {
|
||||||
( new WC_Admin_Dashboard() )->status_widget();
|
( new WC_Admin_Dashboard() )->status_widget();
|
||||||
|
|
||||||
$widget_output = $this->getActualOutput();
|
$widget_output = $this->getActualOutput();
|
||||||
$this->assertRegExp( '/page\=wc-reports\&\#038\;tab\=orders\&\#038\;range\=month/', $widget_output );
|
$this->assertMatchesRegularExpression( '/page\=wc-reports\&\#038\;tab\=orders\&\#038\;range\=month/', $widget_output );
|
||||||
$this->assertRegExp( '/page\=wc-reports\&\#038\;tab\=orders\&\#038\;report\=sales_by_product/', $widget_output );
|
$this->assertMatchesRegularExpression( '/page\=wc-reports\&\#038\;tab\=orders\&\#038\;report\=sales_by_product/', $widget_output );
|
||||||
$this->assertRegExp( '/page\=wc-reports\&\#038\;tab\=stock\&\#038\;report\=low_in_stock/', $widget_output );
|
$this->assertMatchesRegularExpression( '/page\=wc-reports\&\#038\;tab\=stock\&\#038\;report\=low_in_stock/', $widget_output );
|
||||||
$this->assertRegExp( '/page\=wc-reports\&\#038\;tab\=stock\&\#038\;report\=out_of_stock/', $widget_output );
|
$this->assertMatchesRegularExpression( '/page\=wc-reports\&\#038\;tab\=stock\&\#038\;report\=out_of_stock/', $widget_output );
|
||||||
|
|
||||||
remove_filter( 'woocommerce_admin_disabled', '__return_true' );
|
remove_filter( 'woocommerce_admin_disabled', '__return_true' );
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,7 @@ class WC_Test_WooCommerce extends WC_Unit_Test_Case {
|
||||||
* @since 2.2
|
* @since 2.2
|
||||||
*/
|
*/
|
||||||
public function test_wc_instance() {
|
public function test_wc_instance() {
|
||||||
$this->assertClassHasStaticAttribute( '_instance', 'WooCommerce' );
|
$this->assertTrue( property_exists( WooCommerce::class, '_instance' ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -219,13 +219,13 @@ class WC_Tests_Formatting_Functions extends WC_Unit_Test_Case {
|
||||||
$this->assertEquals( 4.53592, wc_get_weight( 10, 'kg' ) );
|
$this->assertEquals( 4.53592, wc_get_weight( 10, 'kg' ) );
|
||||||
$this->assertEquals( 4535.92, wc_get_weight( 10, 'g' ) );
|
$this->assertEquals( 4535.92, wc_get_weight( 10, 'g' ) );
|
||||||
$this->assertEquals( 10, wc_get_weight( 10, 'lbs' ) );
|
$this->assertEquals( 10, wc_get_weight( 10, 'lbs' ) );
|
||||||
$this->assertEquals( 160.00004208, wc_get_weight( 10, 'oz' ) );
|
$this->assertFloatEquals( 160.00004208, wc_get_weight( 10, 'oz' ) );
|
||||||
|
|
||||||
// oz.
|
// oz.
|
||||||
update_option( 'woocommerce_weight_unit', 'oz' );
|
update_option( 'woocommerce_weight_unit', 'oz' );
|
||||||
$this->assertEquals( 0.283495, wc_get_weight( 10, 'kg' ) );
|
$this->assertEquals( 0.283495, wc_get_weight( 10, 'kg' ) );
|
||||||
$this->assertEquals( 283.495, wc_get_weight( 10, 'g' ) );
|
$this->assertEquals( 283.495, wc_get_weight( 10, 'g' ) );
|
||||||
$this->assertEquals( 0.6249987469, wc_get_weight( 10, 'lbs' ) );
|
$this->assertFloatEquals( 0.6249987469, wc_get_weight( 10, 'lbs' ) );
|
||||||
$this->assertEquals( 10, wc_get_weight( 10, 'oz' ) );
|
$this->assertEquals( 10, wc_get_weight( 10, 'oz' ) );
|
||||||
|
|
||||||
// Custom from unit.
|
// Custom from unit.
|
||||||
|
|
|
@ -184,7 +184,8 @@ class WC_Tests_Log_Handler_Email extends WC_Unit_Test_Case {
|
||||||
|
|
||||||
$handler->handle( time(), 'notice', '', array() );
|
$handler->handle( time(), 'notice', '', array() );
|
||||||
$handler->send_log_email();
|
$handler->send_log_email();
|
||||||
$this->assertObjectHasAttribute( 'body', $mailer->get_sent( 0 ) );
|
|
||||||
|
$this->assertTrue( property_exists( $mailer->get_sent( 0 ), 'body' ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -206,7 +207,7 @@ class WC_Tests_Log_Handler_Email extends WC_Unit_Test_Case {
|
||||||
$handler->handle( time(), 'info', '', array() );
|
$handler->handle( time(), 'info', '', array() );
|
||||||
$handler->send_log_email();
|
$handler->send_log_email();
|
||||||
|
|
||||||
$this->assertObjectHasAttribute( 'body', $mailer->get_sent( 0 ) );
|
$this->assertTrue( property_exists( $mailer->get_sent( 0 ), 'body' ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,4 +1,9 @@
|
||||||
<?php
|
<?php
|
||||||
|
/**
|
||||||
|
* Class WC_Tests_Log_Handler_File file.
|
||||||
|
*
|
||||||
|
* @package WooCommerce\Tests
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class WC_Tests_Log_Handler_File
|
* Class WC_Tests_Log_Handler_File
|
||||||
|
@ -7,6 +12,11 @@
|
||||||
*/
|
*/
|
||||||
class WC_Tests_Log_Handler_File extends WC_Unit_Test_Case {
|
class WC_Tests_Log_Handler_File extends WC_Unit_Test_Case {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Runs after each test.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
public function tearDown(): void {
|
public function tearDown(): void {
|
||||||
$log_files = array(
|
$log_files = array(
|
||||||
'unit-tests',
|
'unit-tests',
|
||||||
|
@ -35,7 +45,14 @@ class WC_Tests_Log_Handler_File extends WC_Unit_Test_Case {
|
||||||
parent::tearDown();
|
parent::tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the entire contents of a file.
|
||||||
|
*
|
||||||
|
* @param string $handle File path.
|
||||||
|
* @return false|string Contents of the file, or false on error.
|
||||||
|
*/
|
||||||
public function read_content( $handle ) {
|
public function read_content( $handle ) {
|
||||||
|
// phpcs:ignore WordPress.WP.AlternativeFunctions
|
||||||
return file_get_contents( WC_Log_Handler_File::get_log_file_path( $handle ) );
|
return file_get_contents( WC_Log_Handler_File::get_log_file_path( $handle ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,7 +101,7 @@ class WC_Tests_Log_Handler_File extends WC_Unit_Test_Case {
|
||||||
$log_name = '_test_remove';
|
$log_name = '_test_remove';
|
||||||
$handler->handle( time(), 'debug', 'debug', array( 'source' => $log_name ) );
|
$handler->handle( time(), 'debug', 'debug', array( 'source' => $log_name ) );
|
||||||
$handler->remove( wc_get_log_file_name( $log_name ) );
|
$handler->remove( wc_get_log_file_name( $log_name ) );
|
||||||
$this->assertFileNotExists( WC_Log_Handler_File::get_log_file_path( $log_name ) );
|
$this->assertFileDoesNotExist( WC_Log_Handler_File::get_log_file_path( $log_name ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -165,20 +182,21 @@ class WC_Tests_Log_Handler_File extends WC_Unit_Test_Case {
|
||||||
* @since 3.0.0
|
* @since 3.0.0
|
||||||
*/
|
*/
|
||||||
public function test_log_rotate() {
|
public function test_log_rotate() {
|
||||||
|
// phpcs:disable WordPress.WP.AlternativeFunctions
|
||||||
|
|
||||||
// Handler with log size limit of 5mb
|
// Handler with log size limit of 5mb.
|
||||||
$handler = new WC_Log_Handler_File( 5 * 1024 * 1024 );
|
$handler = new WC_Log_Handler_File( 5 * 1024 * 1024 );
|
||||||
$time = time();
|
$time = time();
|
||||||
$log_name = '_test_log_rotate';
|
$log_name = '_test_log_rotate';
|
||||||
$base_log_file = WC_Log_Handler_File::get_log_file_path( $log_name );
|
$base_log_file = WC_Log_Handler_File::get_log_file_path( $log_name );
|
||||||
|
|
||||||
// Create log file larger than 5mb to ensure log is rotated
|
// Create log file larger than 5mb to ensure log is rotated.
|
||||||
$handle = fopen( $base_log_file, 'w' );
|
$handle = fopen( $base_log_file, 'w' );
|
||||||
fseek( $handle, 5 * 1024 * 1024 );
|
fseek( $handle, 5 * 1024 * 1024 );
|
||||||
fwrite( $handle, '_base_log_file_contents_' );
|
fwrite( $handle, '_base_log_file_contents_' );
|
||||||
fclose( $handle );
|
fclose( $handle );
|
||||||
|
|
||||||
// Write some files to ensure they've rotated correctly
|
// Write some files to ensure they've rotated correctly.
|
||||||
for ( $i = 0; $i < 10; $i++ ) {
|
for ( $i = 0; $i < 10; $i++ ) {
|
||||||
file_put_contents( WC_Log_Handler_File::get_log_file_path( $log_name . ".{$i}" ), $i ); // phpcs:ignore WordPress.VIP.FileSystemWritesDisallow.file_ops_file_put_contents
|
file_put_contents( WC_Log_Handler_File::get_log_file_path( $log_name . ".{$i}" ), $i ); // phpcs:ignore WordPress.VIP.FileSystemWritesDisallow.file_ops_file_put_contents
|
||||||
}
|
}
|
||||||
|
@ -188,14 +206,16 @@ class WC_Tests_Log_Handler_File extends WC_Unit_Test_Case {
|
||||||
|
|
||||||
$this->assertFileExists( WC_Log_Handler_File::get_log_file_path( $log_name ) );
|
$this->assertFileExists( WC_Log_Handler_File::get_log_file_path( $log_name ) );
|
||||||
|
|
||||||
// Ensure the handled log is correct
|
// Ensure the handled log is correct.
|
||||||
$this->assertStringEndsWith( 'EMERGENCY emergency' . PHP_EOL, $this->read_content( $log_name ) );
|
$this->assertStringEndsWith( 'EMERGENCY emergency' . PHP_EOL, $this->read_content( $log_name ) );
|
||||||
|
|
||||||
// Ensure other logs have rotated correctly
|
// Ensure other logs have rotated correctly.
|
||||||
$this->assertEquals( '_base_log_file_contents_', trim( $this->read_content( $log_name . '.0' ) ) );
|
$this->assertEquals( '_base_log_file_contents_', trim( $this->read_content( $log_name . '.0' ) ) );
|
||||||
for ( $i = 1; $i < 10; $i++ ) {
|
for ( $i = 1; $i < 10; $i++ ) {
|
||||||
$this->assertEquals( $i - 1, $this->read_content( $log_name . ".{$i}" ) );
|
$this->assertEquals( $i - 1, $this->read_content( $log_name . ".{$i}" ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// phpcs:enable WordPress.WP.AlternativeFunctions
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -205,7 +225,7 @@ class WC_Tests_Log_Handler_File extends WC_Unit_Test_Case {
|
||||||
*/
|
*/
|
||||||
public function test_get_log_file_path() {
|
public function test_get_log_file_path() {
|
||||||
$log_dir = trailingslashit( WC_LOG_DIR );
|
$log_dir = trailingslashit( WC_LOG_DIR );
|
||||||
$date_suffix = date( 'Y-m-d', time() );
|
$date_suffix = gmdate( 'Y-m-d', time() );
|
||||||
$hash_name = sanitize_file_name( wp_hash( 'unit-tests' ) );
|
$hash_name = sanitize_file_name( wp_hash( 'unit-tests' ) );
|
||||||
$this->assertEquals( $log_dir . 'unit-tests-' . $date_suffix . '-' . $hash_name . '.log', WC_Log_Handler_File::get_log_file_path( 'unit-tests' ) );
|
$this->assertEquals( $log_dir . 'unit-tests-' . $date_suffix . '-' . $hash_name . '.log', WC_Log_Handler_File::get_log_file_path( 'unit-tests' ) );
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,9 @@
|
||||||
<?php
|
<?php
|
||||||
|
/**
|
||||||
|
* Class WC_Tests_Logger file.
|
||||||
|
*
|
||||||
|
* @package WooCommerce\Tests
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class WC_Tests_Logger
|
* Class WC_Tests_Logger
|
||||||
|
@ -43,11 +48,13 @@ class WC_Tests_Logger extends WC_Unit_Test_Case {
|
||||||
* @since 2.4
|
* @since 2.4
|
||||||
*/
|
*/
|
||||||
public function test_clear() {
|
public function test_clear() {
|
||||||
|
// phpcs:disable WordPress.WP.AlternativeFunctions
|
||||||
$file = wc_get_log_file_path( 'unit-tests' );
|
$file = wc_get_log_file_path( 'unit-tests' );
|
||||||
file_put_contents( $file, 'Test file content.' ); // @codingStandardsIgnoreLine.
|
file_put_contents( $file, 'Test file content.' );
|
||||||
$log = new WC_Logger();
|
$log = new WC_Logger();
|
||||||
$log->clear( 'unit-tests' );
|
$log->clear( 'unit-tests' );
|
||||||
$this->assertEquals( '', file_get_contents( $file ) );
|
$this->assertEquals( '', file_get_contents( $file ) );
|
||||||
|
// phpcs:enable WordPress.WP.AlternativeFunctions
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -67,6 +74,8 @@ class WC_Tests_Logger extends WC_Unit_Test_Case {
|
||||||
* @since 3.0.0
|
* @since 3.0.0
|
||||||
*/
|
*/
|
||||||
public function test_log() {
|
public function test_log() {
|
||||||
|
$this->expectNotToPerformAssertions();
|
||||||
|
|
||||||
$handler = $this->create_mock_handler();
|
$handler = $this->create_mock_handler();
|
||||||
$log = new WC_Logger( array( $handler ), 'debug' );
|
$log = new WC_Logger( array( $handler ), 'debug' );
|
||||||
$log->log( 'debug', 'debug message' );
|
$log->log( 'debug', 'debug message' );
|
||||||
|
@ -121,6 +130,8 @@ class WC_Tests_Logger extends WC_Unit_Test_Case {
|
||||||
* @since 3.0.0
|
* @since 3.0.0
|
||||||
*/
|
*/
|
||||||
public function test_level_methods() {
|
public function test_level_methods() {
|
||||||
|
$this->expectNotToPerformAssertions();
|
||||||
|
|
||||||
$handler = $this->create_mock_handler();
|
$handler = $this->create_mock_handler();
|
||||||
$log = new WC_Logger( array( $handler ), 'debug' );
|
$log = new WC_Logger( array( $handler ), 'debug' );
|
||||||
$log->debug( 'debug message' );
|
$log->debug( 'debug message' );
|
||||||
|
@ -160,29 +171,27 @@ class WC_Tests_Logger extends WC_Unit_Test_Case {
|
||||||
public function test_threshold_defaults() {
|
public function test_threshold_defaults() {
|
||||||
$time = time();
|
$time = time();
|
||||||
|
|
||||||
// Test no filtering by default
|
// Test no filtering by default.
|
||||||
delete_option( 'woocommerce_log_threshold' );
|
delete_option( 'woocommerce_log_threshold' );
|
||||||
$handler = $this
|
$handler = $this
|
||||||
->getMockBuilder( 'WC_Log_Handler_Interface' )
|
->getMockBuilder( 'WC_Log_Handler_Interface' )
|
||||||
->setMethods( array( 'handle' ) )
|
->setMethods( array( 'handle' ) )
|
||||||
->getMock();
|
->getMock();
|
||||||
$handler
|
$handler
|
||||||
->expects( $this->at( 0 ) )
|
|
||||||
->method( 'handle' )
|
->method( 'handle' )
|
||||||
->with(
|
->withConsecutive(
|
||||||
|
array(
|
||||||
$this->greaterThanOrEqual( $time ),
|
$this->greaterThanOrEqual( $time ),
|
||||||
$this->equalTo( 'bad-level' ),
|
$this->equalTo( 'bad-level' ),
|
||||||
$this->equalTo( 'bad-level message' ),
|
$this->equalTo( 'bad-level message' ),
|
||||||
$this->equalTo( array() )
|
$this->equalTo( array() ),
|
||||||
);
|
),
|
||||||
$handler
|
array(
|
||||||
->expects( $this->at( 1 ) )
|
|
||||||
->method( 'handle' )
|
|
||||||
->with(
|
|
||||||
$this->greaterThanOrEqual( $time ),
|
$this->greaterThanOrEqual( $time ),
|
||||||
$this->equalTo( 'debug' ),
|
$this->equalTo( 'debug' ),
|
||||||
$this->equalTo( 'debug message' ),
|
$this->equalTo( 'debug message' ),
|
||||||
$this->equalTo( array() )
|
$this->equalTo( array() ),
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
$log = new WC_Logger( array( $handler ) );
|
$log = new WC_Logger( array( $handler ) );
|
||||||
|
@ -192,7 +201,7 @@ class WC_Tests_Logger extends WC_Unit_Test_Case {
|
||||||
// Bad level also complains.
|
// Bad level also complains.
|
||||||
$this->setExpectedIncorrectUsage( 'WC_Logger::log' );
|
$this->setExpectedIncorrectUsage( 'WC_Logger::log' );
|
||||||
|
|
||||||
// Debug is lowest recognized level
|
// Debug is lowest recognized level.
|
||||||
$log->debug( 'debug message' );
|
$log->debug( 'debug message' );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -251,76 +260,56 @@ class WC_Tests_Logger extends WC_Unit_Test_Case {
|
||||||
->getMock();
|
->getMock();
|
||||||
|
|
||||||
$handler
|
$handler
|
||||||
->expects( $this->at( 0 ) )
|
|
||||||
->method( 'handle' )
|
->method( 'handle' )
|
||||||
->with(
|
->withConsecutive(
|
||||||
|
array(
|
||||||
$this->greaterThanOrEqual( $time ),
|
$this->greaterThanOrEqual( $time ),
|
||||||
$this->equalTo( 'debug' ),
|
$this->equalTo( 'debug' ),
|
||||||
$this->equalTo( 'debug message' ),
|
$this->equalTo( 'debug message' ),
|
||||||
$this->equalTo( array() )
|
$this->equalTo( array() ),
|
||||||
);
|
),
|
||||||
$handler
|
array(
|
||||||
->expects( $this->at( 1 ) )
|
|
||||||
->method( 'handle' )
|
|
||||||
->with(
|
|
||||||
$this->greaterThanOrEqual( $time ),
|
$this->greaterThanOrEqual( $time ),
|
||||||
$this->equalTo( 'info' ),
|
$this->equalTo( 'info' ),
|
||||||
$this->equalTo( 'info message' ),
|
$this->equalTo( 'info message' ),
|
||||||
$this->equalTo( array() )
|
$this->equalTo( array() ),
|
||||||
);
|
),
|
||||||
$handler
|
array(
|
||||||
->expects( $this->at( 2 ) )
|
|
||||||
->method( 'handle' )
|
|
||||||
->with(
|
|
||||||
$this->greaterThanOrEqual( $time ),
|
$this->greaterThanOrEqual( $time ),
|
||||||
$this->equalTo( 'notice' ),
|
$this->equalTo( 'notice' ),
|
||||||
$this->equalTo( 'notice message' ),
|
$this->equalTo( 'notice message' ),
|
||||||
$this->equalTo( array() )
|
$this->equalTo( array() ),
|
||||||
);
|
),
|
||||||
$handler
|
array(
|
||||||
->expects( $this->at( 3 ) )
|
|
||||||
->method( 'handle' )
|
|
||||||
->with(
|
|
||||||
$this->greaterThanOrEqual( $time ),
|
$this->greaterThanOrEqual( $time ),
|
||||||
$this->equalTo( 'warning' ),
|
$this->equalTo( 'warning' ),
|
||||||
$this->equalTo( 'warning message' ),
|
$this->equalTo( 'warning message' ),
|
||||||
$this->equalTo( array() )
|
$this->equalTo( array() ),
|
||||||
);
|
),
|
||||||
$handler
|
array(
|
||||||
->expects( $this->at( 4 ) )
|
|
||||||
->method( 'handle' )
|
|
||||||
->with(
|
|
||||||
$this->greaterThanOrEqual( $time ),
|
$this->greaterThanOrEqual( $time ),
|
||||||
$this->equalTo( 'error' ),
|
$this->equalTo( 'error' ),
|
||||||
$this->equalTo( 'error message' ),
|
$this->equalTo( 'error message' ),
|
||||||
$this->equalTo( array() )
|
$this->equalTo( array() ),
|
||||||
);
|
),
|
||||||
$handler
|
array(
|
||||||
->expects( $this->at( 5 ) )
|
|
||||||
->method( 'handle' )
|
|
||||||
->with(
|
|
||||||
$this->greaterThanOrEqual( $time ),
|
$this->greaterThanOrEqual( $time ),
|
||||||
$this->equalTo( 'critical' ),
|
$this->equalTo( 'critical' ),
|
||||||
$this->equalTo( 'critical message' ),
|
$this->equalTo( 'critical message' ),
|
||||||
$this->equalTo( array() )
|
$this->equalTo( array() ),
|
||||||
);
|
),
|
||||||
$handler
|
array(
|
||||||
->expects( $this->at( 6 ) )
|
|
||||||
->method( 'handle' )
|
|
||||||
->with(
|
|
||||||
$this->greaterThanOrEqual( $time ),
|
$this->greaterThanOrEqual( $time ),
|
||||||
$this->equalTo( 'alert' ),
|
$this->equalTo( 'alert' ),
|
||||||
$this->equalTo( 'alert message' ),
|
$this->equalTo( 'alert message' ),
|
||||||
$this->equalTo( array() )
|
$this->equalTo( array() ),
|
||||||
);
|
),
|
||||||
$handler
|
array(
|
||||||
->expects( $this->at( 7 ) )
|
|
||||||
->method( 'handle' )
|
|
||||||
->with(
|
|
||||||
$this->greaterThanOrEqual( $time ),
|
$this->greaterThanOrEqual( $time ),
|
||||||
$this->equalTo( 'emergency' ),
|
$this->equalTo( 'emergency' ),
|
||||||
$this->equalTo( 'emergency message' ),
|
$this->equalTo( 'emergency message' ),
|
||||||
$this->equalTo( array() )
|
$this->equalTo( array() ),
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
return $handler;
|
return $handler;
|
||||||
|
|
|
@ -130,7 +130,7 @@ class WC_Tests_Order_Item_Product extends WC_Unit_Test_Case {
|
||||||
$product_item->set_order_id( $order->get_id() );
|
$product_item->set_order_id( $order->get_id() );
|
||||||
|
|
||||||
$expected_regex = '/download_file=.*&order=wc_order_.*&email=test%40woocommerce.com&key=100/';
|
$expected_regex = '/download_file=.*&order=wc_order_.*&email=test%40woocommerce.com&key=100/';
|
||||||
$this->assertRegexp( $expected_regex, $product_item->get_item_download_url( 100 ) );
|
$this->assertMatchesRegularExpression( $expected_regex, $product_item->get_item_download_url( 100 ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -253,7 +253,7 @@ class WC_Tests_Order_Coupons extends WC_Unit_Test_Case {
|
||||||
|
|
||||||
$order->apply_coupon( 'test-coupon-2' );
|
$order->apply_coupon( 'test-coupon-2' );
|
||||||
$this->assertEquals( 401, $order->get_discount_total(), $order->get_discount_total() );
|
$this->assertEquals( 401, $order->get_discount_total(), $order->get_discount_total() );
|
||||||
$this->assertEquals( ( 1000 - 401 ) * 1.1, $order->get_total(), $order->get_total() );
|
$this->assertFloatEquals( ( 1000 - 401 ) * 1.1, $order->get_total(), $order->get_total() );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -545,6 +545,7 @@ class WC_Tests_Product_Data_Store extends WC_Unit_Test_Case {
|
||||||
|
|
||||||
$sale_products = $product_store->get_on_sale_products();
|
$sale_products = $product_store->get_on_sale_products();
|
||||||
$sale_product_ids = wp_list_pluck( $sale_products, 'id' );
|
$sale_product_ids = wp_list_pluck( $sale_products, 'id' );
|
||||||
|
$sale_product_ids = array_map( 'absint', $sale_product_ids );
|
||||||
|
|
||||||
$this->assertContains( $sale_product->get_id(), $sale_product_ids );
|
$this->assertContains( $sale_product->get_id(), $sale_product_ids );
|
||||||
$this->assertNotContains( $not_sale_product->get_id(), $sale_product_ids );
|
$this->assertNotContains( $not_sale_product->get_id(), $sale_product_ids );
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
* @package WooCommerce\Tests\Product
|
* @package WooCommerce\Tests\Product
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Data Functions.
|
* Data Functions.
|
||||||
*
|
*
|
||||||
|
@ -13,6 +15,8 @@
|
||||||
*/
|
*/
|
||||||
class WC_Tests_Product_Data extends WC_Unit_Test_Case {
|
class WC_Tests_Product_Data extends WC_Unit_Test_Case {
|
||||||
|
|
||||||
|
use ArraySubsetAsserts;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test product setters and getters
|
* Test product setters and getters
|
||||||
*
|
*
|
||||||
|
@ -79,16 +83,15 @@ class WC_Tests_Product_Data extends WC_Unit_Test_Case {
|
||||||
$this->assertEquals( $value, $product->{"get_{$function}"}(), $function );
|
$this->assertEquals( $value, $product->{"get_{$function}"}(), $function );
|
||||||
}
|
}
|
||||||
$this->assertCount( 1, $product->get_attributes() );
|
$this->assertCount( 1, $product->get_attributes() );
|
||||||
$this->assertContains(
|
$this->assertArraySubset(
|
||||||
current( $product->get_attributes() )->get_data(),
|
|
||||||
array(
|
array(
|
||||||
'attribute_id' => 0,
|
|
||||||
'name' => 'Test Attribute',
|
'name' => 'Test Attribute',
|
||||||
'options' => array( 'Fish', 'Fingers' ),
|
'options' => array( 'Fish', 'Fingers' ),
|
||||||
'position' => 0,
|
'position' => 0,
|
||||||
'visible' => true,
|
'visible' => true,
|
||||||
'variation' => false,
|
'variation' => false,
|
||||||
)
|
),
|
||||||
|
current( $product->get_attributes() )->get_data()
|
||||||
);
|
);
|
||||||
$this->assertEquals( $product->get_date_on_sale_from()->getTimestamp(), 1475798400 );
|
$this->assertEquals( $product->get_date_on_sale_from()->getTimestamp(), 1475798400 );
|
||||||
$this->assertEquals( $product->get_date_on_sale_to()->getTimestamp(), 1477267200 );
|
$this->assertEquals( $product->get_date_on_sale_to()->getTimestamp(), 1477267200 );
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
* @package WooCommerce\Tests\Queue
|
* @package WooCommerce\Tests\Queue
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* WC_Tests_Discounts.
|
* WC_Tests_Discounts.
|
||||||
*/
|
*/
|
||||||
class WC_Tests_Queue extends WC_Unit_Test_Case {
|
class WC_Tests_Queue extends WC_Unit_Test_Case {
|
||||||
|
@ -41,7 +41,9 @@ class WC_Tests_Queue extends WC_Unit_Test_Case {
|
||||||
),
|
),
|
||||||
'ids'
|
'ids'
|
||||||
);
|
);
|
||||||
|
$action_ids = array_map( 'absint', $action_ids );
|
||||||
$this->assertContains( $single, $action_ids );
|
$this->assertContains( $single, $action_ids );
|
||||||
|
|
||||||
$action_ids = $queue->search(
|
$action_ids = $queue->search(
|
||||||
array(
|
array(
|
||||||
'hook' => $hook,
|
'hook' => $hook,
|
||||||
|
@ -50,6 +52,7 @@ class WC_Tests_Queue extends WC_Unit_Test_Case {
|
||||||
),
|
),
|
||||||
'ids'
|
'ids'
|
||||||
);
|
);
|
||||||
|
$action_ids = array_map( 'absint', $action_ids );
|
||||||
$this->assertContains( $single, $action_ids );
|
$this->assertContains( $single, $action_ids );
|
||||||
|
|
||||||
// Schedule a recurring action.
|
// Schedule a recurring action.
|
||||||
|
@ -69,7 +72,9 @@ class WC_Tests_Queue extends WC_Unit_Test_Case {
|
||||||
),
|
),
|
||||||
'ids'
|
'ids'
|
||||||
);
|
);
|
||||||
|
$action_ids = array_map( 'absint', $action_ids );
|
||||||
$this->assertContains( $recurring, $action_ids );
|
$this->assertContains( $recurring, $action_ids );
|
||||||
|
|
||||||
$action_ids = $queue->search(
|
$action_ids = $queue->search(
|
||||||
array(
|
array(
|
||||||
'hook' => $hook,
|
'hook' => $hook,
|
||||||
|
@ -78,6 +83,7 @@ class WC_Tests_Queue extends WC_Unit_Test_Case {
|
||||||
),
|
),
|
||||||
'ids'
|
'ids'
|
||||||
);
|
);
|
||||||
|
$action_ids = array_map( 'absint', $action_ids );
|
||||||
$this->assertContains( $recurring, $action_ids );
|
$this->assertContains( $recurring, $action_ids );
|
||||||
|
|
||||||
// Schedule a cron action on a daily midnight schedule starting at the next midnight.
|
// Schedule a cron action on a daily midnight schedule starting at the next midnight.
|
||||||
|
@ -99,7 +105,9 @@ class WC_Tests_Queue extends WC_Unit_Test_Case {
|
||||||
),
|
),
|
||||||
'ids'
|
'ids'
|
||||||
);
|
);
|
||||||
|
$action_ids = array_map( 'absint', $action_ids );
|
||||||
$this->assertContains( $cron_action, $action_ids );
|
$this->assertContains( $cron_action, $action_ids );
|
||||||
|
|
||||||
$action_ids = $queue->search(
|
$action_ids = $queue->search(
|
||||||
array(
|
array(
|
||||||
'hook' => $hook,
|
'hook' => $hook,
|
||||||
|
@ -108,6 +116,7 @@ class WC_Tests_Queue extends WC_Unit_Test_Case {
|
||||||
),
|
),
|
||||||
'ids'
|
'ids'
|
||||||
);
|
);
|
||||||
|
$action_ids = array_map( 'absint', $action_ids );
|
||||||
$this->assertContains( $cron_action, $action_ids );
|
$this->assertContains( $cron_action, $action_ids );
|
||||||
|
|
||||||
// Test wildcard search.
|
// Test wildcard search.
|
||||||
|
|
|
@ -1,11 +1,25 @@
|
||||||
<?php
|
<?php
|
||||||
|
/**
|
||||||
|
* Tests for the coupons REST API.
|
||||||
|
*
|
||||||
|
* @package WooCommerce\Tests\API
|
||||||
|
* @since 3.0.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Coupon API Tests
|
* Coupon API Tests
|
||||||
* @package WooCommerce\Tests\API
|
* @package WooCommerce\Tests\API
|
||||||
* @since 3.0.0
|
* @since 3.0.0
|
||||||
*/
|
*/
|
||||||
class WC_Tests_API_Coupons_V2 extends WC_REST_Unit_Test_Case {
|
class WC_Tests_API_Coupons_V2 extends WC_REST_Unit_Test_Case {
|
||||||
|
use ArraySubsetAsserts;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Endpoint to use for the tests.
|
||||||
|
* @var WC_REST_Coupons_Controller
|
||||||
|
*/
|
||||||
protected $endpoint;
|
protected $endpoint;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -49,7 +63,18 @@ class WC_Tests_API_Coupons_V2 extends WC_REST_Unit_Test_Case {
|
||||||
|
|
||||||
$this->assertEquals( 200, $response->get_status() );
|
$this->assertEquals( 200, $response->get_status() );
|
||||||
$this->assertEquals( 2, count( $coupons ) );
|
$this->assertEquals( 2, count( $coupons ) );
|
||||||
$this->assertContains(
|
|
||||||
|
$matching_coupon_data = current(
|
||||||
|
array_filter(
|
||||||
|
$coupons,
|
||||||
|
function( $coupon ) use ( $coupon_1 ) {
|
||||||
|
return $coupon['id'] === $coupon_1->get_id();
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$this->assertIsArray( $matching_coupon_data );
|
||||||
|
|
||||||
|
$this->assertArraySubset(
|
||||||
array(
|
array(
|
||||||
'id' => $coupon_1->get_id(),
|
'id' => $coupon_1->get_id(),
|
||||||
'code' => 'dummycoupon-1',
|
'code' => 'dummycoupon-1',
|
||||||
|
@ -92,7 +117,7 @@ class WC_Tests_API_Coupons_V2 extends WC_REST_Unit_Test_Case {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
$coupons
|
$matching_coupon_data
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
* @since 3.0.0
|
* @since 3.0.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for the Customers REST API.
|
* Tests for the Customers REST API.
|
||||||
*
|
*
|
||||||
|
@ -13,6 +15,7 @@
|
||||||
* @extends WC_REST_Unit_Test_Case
|
* @extends WC_REST_Unit_Test_Case
|
||||||
*/
|
*/
|
||||||
class Customers_V2 extends WC_REST_Unit_Test_Case {
|
class Customers_V2 extends WC_REST_Unit_Test_Case {
|
||||||
|
use ArraySubsetAsserts;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setup our test server, endpoints, and user info.
|
* Setup our test server, endpoints, and user info.
|
||||||
|
@ -58,7 +61,17 @@ class Customers_V2 extends WC_REST_Unit_Test_Case {
|
||||||
$this->assertEquals( 200, $response->get_status() );
|
$this->assertEquals( 200, $response->get_status() );
|
||||||
$this->assertEquals( 2, count( $customers ) );
|
$this->assertEquals( 2, count( $customers ) );
|
||||||
|
|
||||||
$this->assertContains(
|
$matching_customer_data = current(
|
||||||
|
array_filter(
|
||||||
|
$customers,
|
||||||
|
function( $customer ) use ( $customer_1 ) {
|
||||||
|
return $customer['id'] === $customer_1->get_id();
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$this->assertIsArray( $matching_customer_data );
|
||||||
|
|
||||||
|
$this->assertArraySubset(
|
||||||
array(
|
array(
|
||||||
'id' => $customer_1->get_id(),
|
'id' => $customer_1->get_id(),
|
||||||
'date_created' => wc_rest_prepare_date_response( $customer_1->get_date_created(), false ),
|
'date_created' => wc_rest_prepare_date_response( $customer_1->get_date_created(), false ),
|
||||||
|
@ -113,7 +126,7 @@ class Customers_V2 extends WC_REST_Unit_Test_Case {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
$customers
|
$matching_customer_data
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,10 +6,13 @@
|
||||||
* @since 3.0.0
|
* @since 3.0.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Payment gateway test class.
|
* Payment gateway test class.
|
||||||
*/
|
*/
|
||||||
class Payment_Gateways_V2 extends WC_REST_Unit_Test_Case {
|
class Payment_Gateways_V2 extends WC_REST_Unit_Test_Case {
|
||||||
|
use ArraySubsetAsserts;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setup our test server, endpoints, and user info.
|
* Setup our test server, endpoints, and user info.
|
||||||
|
@ -47,7 +50,18 @@ class Payment_Gateways_V2 extends WC_REST_Unit_Test_Case {
|
||||||
$gateways = $response->get_data();
|
$gateways = $response->get_data();
|
||||||
|
|
||||||
$this->assertEquals( 200, $response->get_status() );
|
$this->assertEquals( 200, $response->get_status() );
|
||||||
$this->assertContains(
|
|
||||||
|
$matching_gateway_data = current(
|
||||||
|
array_filter(
|
||||||
|
$gateways,
|
||||||
|
function( $gateway ) {
|
||||||
|
return 'cheque' === $gateway['id'];
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$this->assertIsArray( $matching_gateway_data );
|
||||||
|
|
||||||
|
$this->assertArraySubset(
|
||||||
array(
|
array(
|
||||||
'id' => 'cheque',
|
'id' => 'cheque',
|
||||||
'title' => 'Check payments',
|
'title' => 'Check payments',
|
||||||
|
@ -82,7 +96,7 @@ class Payment_Gateways_V2 extends WC_REST_Unit_Test_Case {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
$gateways
|
$matching_gateway_data
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,10 +6,14 @@
|
||||||
* @since 3.0.0
|
* @since 3.0.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper;
|
||||||
|
use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Products_API_V2 class.
|
* Products_API_V2 class.
|
||||||
*/
|
*/
|
||||||
class Products_API_V2 extends WC_REST_Unit_Test_Case {
|
class Products_API_V2 extends WC_REST_Unit_Test_Case {
|
||||||
|
use ArraySubsetAsserts;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setup our test server, endpoints, and user info.
|
* Setup our test server, endpoints, and user info.
|
||||||
|
@ -77,19 +81,20 @@ class Products_API_V2 extends WC_REST_Unit_Test_Case {
|
||||||
*/
|
*/
|
||||||
public function test_get_product() {
|
public function test_get_product() {
|
||||||
wp_set_current_user( $this->user );
|
wp_set_current_user( $this->user );
|
||||||
$simple = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_external_product();
|
$simple = ProductHelper::create_external_product();
|
||||||
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/products/' . $simple->get_id() ) );
|
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/products/' . $simple->get_id() ) );
|
||||||
$product = $response->get_data();
|
$product = $response->get_data();
|
||||||
|
|
||||||
$this->assertEquals( 200, $response->get_status() );
|
$this->assertEquals( 200, $response->get_status() );
|
||||||
$this->assertContains(
|
|
||||||
|
$this->assertArraySubset(
|
||||||
array(
|
array(
|
||||||
'id' => $simple->get_id(),
|
'id' => $simple->get_id(),
|
||||||
'name' => 'Dummy External Product',
|
'name' => 'Dummy External Product',
|
||||||
'type' => 'simple',
|
'type' => 'external',
|
||||||
'status' => 'publish',
|
'status' => 'publish',
|
||||||
'sku' => 'DUMMY EXTERNAL SKU',
|
'sku' => 'DUMMY EXTERNAL SKU',
|
||||||
'regular_price' => 10,
|
'regular_price' => '10',
|
||||||
),
|
),
|
||||||
$product
|
$product
|
||||||
);
|
);
|
||||||
|
|
|
@ -6,10 +6,13 @@
|
||||||
* @since 3.0.0
|
* @since 3.0.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Settings_V2.
|
* Class Settings_V2.
|
||||||
*/
|
*/
|
||||||
class Settings_V2 extends WC_REST_Unit_Test_Case {
|
class Settings_V2 extends WC_REST_Unit_Test_Case {
|
||||||
|
use ArraySubsetAsserts;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setup our test server, endpoints, and user info.
|
* Setup our test server, endpoints, and user info.
|
||||||
|
@ -50,7 +53,18 @@ class Settings_V2 extends WC_REST_Unit_Test_Case {
|
||||||
|
|
||||||
$this->assertEquals( 200, $response->get_status() );
|
$this->assertEquals( 200, $response->get_status() );
|
||||||
|
|
||||||
$this->assertContains(
|
$this->assertEquals( 200, $response->get_status() );
|
||||||
|
$matching_settings_data = current(
|
||||||
|
array_filter(
|
||||||
|
$data,
|
||||||
|
function( $settings ) {
|
||||||
|
return 'test' === $settings['id'];
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$this->assertIsArray( $matching_settings_data );
|
||||||
|
|
||||||
|
$this->assertArraySubset(
|
||||||
array(
|
array(
|
||||||
'id' => 'test',
|
'id' => 'test',
|
||||||
'label' => 'Test extension',
|
'label' => 'Test extension',
|
||||||
|
@ -65,10 +79,20 @@ class Settings_V2 extends WC_REST_Unit_Test_Case {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
$data
|
$matching_settings_data
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertContains(
|
$matching_settings_data = current(
|
||||||
|
array_filter(
|
||||||
|
$data,
|
||||||
|
function( $settings ) {
|
||||||
|
return 'sub-test' === $settings['id'];
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$this->assertIsArray( $matching_settings_data );
|
||||||
|
|
||||||
|
$this->assertArraySubset(
|
||||||
array(
|
array(
|
||||||
'id' => 'sub-test',
|
'id' => 'sub-test',
|
||||||
'label' => 'Sub test',
|
'label' => 'Sub test',
|
||||||
|
@ -83,7 +107,7 @@ class Settings_V2 extends WC_REST_Unit_Test_Case {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
$data
|
$matching_settings_data
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
* @package Automattic/WooCommerce/Tests
|
* @package Automattic/WooCommerce/Tests
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* System Status REST Tests.
|
* System Status REST Tests.
|
||||||
*
|
*
|
||||||
|
@ -12,6 +14,7 @@
|
||||||
* @since 3.0
|
* @since 3.0
|
||||||
*/
|
*/
|
||||||
class WC_Tests_REST_System_Status_V2 extends WC_REST_Unit_Test_Case {
|
class WC_Tests_REST_System_Status_V2 extends WC_REST_Unit_Test_Case {
|
||||||
|
use ArraySubsetAsserts;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setup our test server.
|
* Setup our test server.
|
||||||
|
@ -251,7 +254,18 @@ class WC_Tests_REST_System_Status_V2 extends WC_REST_Unit_Test_Case {
|
||||||
|
|
||||||
$this->assertEquals( 200, $response->get_status() );
|
$this->assertEquals( 200, $response->get_status() );
|
||||||
$this->assertEquals( count( $raw_tools ), count( $data ) );
|
$this->assertEquals( count( $raw_tools ), count( $data ) );
|
||||||
$this->assertContains(
|
|
||||||
|
$matching_tool_data = current(
|
||||||
|
array_filter(
|
||||||
|
$data,
|
||||||
|
function( $tool ) {
|
||||||
|
return 'regenerate_thumbnails' === $tool['id'];
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$this->assertIsArray( $matching_tool_data );
|
||||||
|
|
||||||
|
$this->assertArraySubset(
|
||||||
array(
|
array(
|
||||||
'id' => 'regenerate_thumbnails',
|
'id' => 'regenerate_thumbnails',
|
||||||
'name' => 'Regenerate shop thumbnails',
|
'name' => 'Regenerate shop thumbnails',
|
||||||
|
@ -266,7 +280,7 @@ class WC_Tests_REST_System_Status_V2 extends WC_REST_Unit_Test_Case {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
$data
|
$matching_tool_data
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
* @package WooCommerce\Tests\API
|
* @package WooCommerce\Tests\API
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts;
|
||||||
|
|
||||||
// phpcs:ignore Squiz.Commenting.FileComment.Missing
|
// phpcs:ignore Squiz.Commenting.FileComment.Missing
|
||||||
require_once __DIR__ . '/date-filtering.php';
|
require_once __DIR__ . '/date-filtering.php';
|
||||||
|
|
||||||
|
@ -14,6 +16,7 @@ require_once __DIR__ . '/date-filtering.php';
|
||||||
* @since 3.5.0
|
* @since 3.5.0
|
||||||
*/
|
*/
|
||||||
class WC_Tests_API_Coupons extends WC_REST_Unit_Test_Case {
|
class WC_Tests_API_Coupons extends WC_REST_Unit_Test_Case {
|
||||||
|
use ArraySubsetAsserts;
|
||||||
use DateFilteringForCrudControllers;
|
use DateFilteringForCrudControllers;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -62,7 +65,18 @@ class WC_Tests_API_Coupons extends WC_REST_Unit_Test_Case {
|
||||||
|
|
||||||
$this->assertEquals( 200, $response->get_status() );
|
$this->assertEquals( 200, $response->get_status() );
|
||||||
$this->assertEquals( 2, count( $coupons ) );
|
$this->assertEquals( 2, count( $coupons ) );
|
||||||
$this->assertContains(
|
|
||||||
|
$matching_coupon_data = current(
|
||||||
|
array_filter(
|
||||||
|
$coupons,
|
||||||
|
function( $coupon ) use ( $coupon_1 ) {
|
||||||
|
return $coupon['id'] === $coupon_1->get_id();
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$this->assertIsArray( $matching_coupon_data );
|
||||||
|
|
||||||
|
$this->assertArraySubset(
|
||||||
array(
|
array(
|
||||||
'id' => $coupon_1->get_id(),
|
'id' => $coupon_1->get_id(),
|
||||||
'code' => 'dummycoupon-1',
|
'code' => 'dummycoupon-1',
|
||||||
|
@ -105,7 +119,7 @@ class WC_Tests_API_Coupons extends WC_REST_Unit_Test_Case {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
$coupons
|
$matching_coupon_data
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
* @since 3.5.0
|
* @since 3.5.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for the Customers REST API.
|
* Tests for the Customers REST API.
|
||||||
*
|
*
|
||||||
|
@ -13,6 +15,7 @@
|
||||||
* @extends WC_REST_Unit_Test_Case
|
* @extends WC_REST_Unit_Test_Case
|
||||||
*/
|
*/
|
||||||
class Customers extends WC_REST_Unit_Test_Case {
|
class Customers extends WC_REST_Unit_Test_Case {
|
||||||
|
use ArraySubsetAsserts;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setup our test server, endpoints, and user info.
|
* Setup our test server, endpoints, and user info.
|
||||||
|
@ -59,7 +62,17 @@ class Customers extends WC_REST_Unit_Test_Case {
|
||||||
$this->assertEquals( 200, $response->get_status() );
|
$this->assertEquals( 200, $response->get_status() );
|
||||||
$this->assertEquals( 2, count( $customers ) );
|
$this->assertEquals( 2, count( $customers ) );
|
||||||
|
|
||||||
$this->assertContains(
|
$matching_customer_data = current(
|
||||||
|
array_filter(
|
||||||
|
$customers,
|
||||||
|
function( $customer ) use ( $customer_1 ) {
|
||||||
|
return $customer['id'] === $customer_1->get_id();
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$this->assertIsArray( $matching_customer_data );
|
||||||
|
|
||||||
|
$this->assertArraySubset(
|
||||||
array(
|
array(
|
||||||
'id' => $customer_1->get_id(),
|
'id' => $customer_1->get_id(),
|
||||||
'date_created' => wc_rest_prepare_date_response( $date_created, false ),
|
'date_created' => wc_rest_prepare_date_response( $date_created, false ),
|
||||||
|
@ -112,7 +125,7 @@ class Customers extends WC_REST_Unit_Test_Case {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
$customers
|
$matching_customer_data
|
||||||
);
|
);
|
||||||
|
|
||||||
update_option( 'timezone_tring', 'America/New York' );
|
update_option( 'timezone_tring', 'America/New York' );
|
||||||
|
@ -130,7 +143,17 @@ class Customers extends WC_REST_Unit_Test_Case {
|
||||||
|
|
||||||
$this->assertEquals( 200, $response->get_status() );
|
$this->assertEquals( 200, $response->get_status() );
|
||||||
|
|
||||||
$this->assertContains(
|
$matching_customer_data = current(
|
||||||
|
array_filter(
|
||||||
|
$customers,
|
||||||
|
function( $customer ) use ( $customer_3 ) {
|
||||||
|
return $customer['id'] === $customer_3->get_id();
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$this->assertIsArray( $matching_customer_data );
|
||||||
|
|
||||||
|
$this->assertArraySubset(
|
||||||
array(
|
array(
|
||||||
'id' => $customer_3->get_id(),
|
'id' => $customer_3->get_id(),
|
||||||
'date_created' => wc_rest_prepare_date_response( $date_created, false ),
|
'date_created' => wc_rest_prepare_date_response( $date_created, false ),
|
||||||
|
@ -183,9 +206,8 @@ class Customers extends WC_REST_Unit_Test_Case {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
$customers
|
$matching_customer_data
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -6,10 +6,13 @@
|
||||||
* @since 3.5.0
|
* @since 3.5.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Payment gateway test class.
|
* Payment gateway test class.
|
||||||
*/
|
*/
|
||||||
class Payment_Gateways extends WC_REST_Unit_Test_Case {
|
class Payment_Gateways extends WC_REST_Unit_Test_Case {
|
||||||
|
use ArraySubsetAsserts;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setup our test server, endpoints, and user info.
|
* Setup our test server, endpoints, and user info.
|
||||||
|
@ -47,7 +50,18 @@ class Payment_Gateways extends WC_REST_Unit_Test_Case {
|
||||||
$gateways = $response->get_data();
|
$gateways = $response->get_data();
|
||||||
|
|
||||||
$this->assertEquals( 200, $response->get_status() );
|
$this->assertEquals( 200, $response->get_status() );
|
||||||
$this->assertContains(
|
|
||||||
|
$matching_gateway_data = current(
|
||||||
|
array_filter(
|
||||||
|
$gateways,
|
||||||
|
function( $gateway ) {
|
||||||
|
return 'cheque' === $gateway['id'];
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$this->assertIsArray( $matching_gateway_data );
|
||||||
|
|
||||||
|
$this->assertArraySubset(
|
||||||
array(
|
array(
|
||||||
'id' => 'cheque',
|
'id' => 'cheque',
|
||||||
'title' => 'Check payments',
|
'title' => 'Check payments',
|
||||||
|
@ -85,7 +99,7 @@ class Payment_Gateways extends WC_REST_Unit_Test_Case {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
$gateways
|
$matching_gateway_data
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
* @since 3.5.0
|
* @since 3.5.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts;
|
||||||
|
|
||||||
// phpcs:ignore Squiz.Commenting.FileComment.Missing
|
// phpcs:ignore Squiz.Commenting.FileComment.Missing
|
||||||
require_once __DIR__ . '/date-filtering.php';
|
require_once __DIR__ . '/date-filtering.php';
|
||||||
|
|
||||||
|
@ -13,8 +15,9 @@ require_once __DIR__ . '/date-filtering.php';
|
||||||
* WC_Tests_API_Product class.
|
* WC_Tests_API_Product class.
|
||||||
*/
|
*/
|
||||||
class WC_Tests_API_Product extends WC_REST_Unit_Test_Case {
|
class WC_Tests_API_Product extends WC_REST_Unit_Test_Case {
|
||||||
use WC_REST_API_Complex_Meta;
|
use ArraySubsetAsserts;
|
||||||
use DateFilteringForCrudControllers;
|
use DateFilteringForCrudControllers;
|
||||||
|
use WC_REST_API_Complex_Meta;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setup our test server, endpoints, and user info.
|
* Setup our test server, endpoints, and user info.
|
||||||
|
@ -140,14 +143,14 @@ class WC_Tests_API_Product extends WC_REST_Unit_Test_Case {
|
||||||
$product = $response->get_data();
|
$product = $response->get_data();
|
||||||
|
|
||||||
$this->assertEquals( 200, $response->get_status() );
|
$this->assertEquals( 200, $response->get_status() );
|
||||||
$this->assertContains(
|
$this->assertArraySubset(
|
||||||
array(
|
array(
|
||||||
'id' => $simple->get_id(),
|
'id' => $simple->get_id(),
|
||||||
'name' => 'Dummy External Product',
|
'name' => 'Dummy External Product',
|
||||||
'type' => 'simple',
|
'type' => 'external',
|
||||||
'status' => 'publish',
|
'status' => 'publish',
|
||||||
'sku' => 'DUMMY EXTERNAL SKU',
|
'sku' => 'DUMMY EXTERNAL SKU',
|
||||||
'regular_price' => 10,
|
'regular_price' => '10',
|
||||||
),
|
),
|
||||||
$product
|
$product
|
||||||
);
|
);
|
||||||
|
|
|
@ -6,10 +6,13 @@
|
||||||
* @since 3.5.0
|
* @since 3.5.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Settings.
|
* Class Settings.
|
||||||
*/
|
*/
|
||||||
class Settings extends WC_REST_Unit_Test_Case {
|
class Settings extends WC_REST_Unit_Test_Case {
|
||||||
|
use ArraySubsetAsserts;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setup our test server, endpoints, and user info.
|
* Setup our test server, endpoints, and user info.
|
||||||
|
@ -49,8 +52,17 @@ class Settings extends WC_REST_Unit_Test_Case {
|
||||||
$data = $response->get_data();
|
$data = $response->get_data();
|
||||||
|
|
||||||
$this->assertEquals( 200, $response->get_status() );
|
$this->assertEquals( 200, $response->get_status() );
|
||||||
|
$matching_settings_data = current(
|
||||||
|
array_filter(
|
||||||
|
$data,
|
||||||
|
function( $settings ) {
|
||||||
|
return 'test' === $settings['id'];
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$this->assertIsArray( $matching_settings_data );
|
||||||
|
|
||||||
$this->assertContains(
|
$this->assertArraySubset(
|
||||||
array(
|
array(
|
||||||
'id' => 'test',
|
'id' => 'test',
|
||||||
'label' => 'Test extension',
|
'label' => 'Test extension',
|
||||||
|
@ -65,10 +77,20 @@ class Settings extends WC_REST_Unit_Test_Case {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
$data
|
$matching_settings_data
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertContains(
|
$matching_settings_data = current(
|
||||||
|
array_filter(
|
||||||
|
$data,
|
||||||
|
function( $settings ) {
|
||||||
|
return 'sub-test' === $settings['id'];
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$this->assertIsArray( $matching_settings_data );
|
||||||
|
|
||||||
|
$this->assertArraySubset(
|
||||||
array(
|
array(
|
||||||
'id' => 'sub-test',
|
'id' => 'sub-test',
|
||||||
'label' => 'Sub test',
|
'label' => 'Sub test',
|
||||||
|
@ -83,7 +105,7 @@ class Settings extends WC_REST_Unit_Test_Case {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
$data
|
$matching_settings_data
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
* @package Automattic/WooCommerce/Tests
|
* @package Automattic/WooCommerce/Tests
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* System Status REST Tests.
|
* System Status REST Tests.
|
||||||
*
|
*
|
||||||
|
@ -12,6 +14,7 @@
|
||||||
* @since 3.5.0
|
* @since 3.5.0
|
||||||
*/
|
*/
|
||||||
class WC_Tests_REST_System_Status extends WC_REST_Unit_Test_Case {
|
class WC_Tests_REST_System_Status extends WC_REST_Unit_Test_Case {
|
||||||
|
use ArraySubsetAsserts;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User variable.
|
* User variable.
|
||||||
|
@ -117,8 +120,8 @@ class WC_Tests_REST_System_Status extends WC_REST_Unit_Test_Case {
|
||||||
}
|
}
|
||||||
$expected_data = array(
|
$expected_data = array(
|
||||||
'environment' => array(
|
'environment' => array(
|
||||||
'version' => WC()->version
|
'version' => WC()->version,
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
$request = new WP_REST_Request( 'GET', '/wc/v3/system_status' );
|
$request = new WP_REST_Request( 'GET', '/wc/v3/system_status' );
|
||||||
|
@ -178,7 +181,8 @@ class WC_Tests_REST_System_Status extends WC_REST_Unit_Test_Case {
|
||||||
$theme = (array) $data['theme'];
|
$theme = (array) $data['theme'];
|
||||||
|
|
||||||
$this->assertEquals( 13, count( $theme ) );
|
$this->assertEquals( 13, count( $theme ) );
|
||||||
$this->assertEquals( $active_theme->Name, $theme['name'] ); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.NotSnakeCaseMemberVar
|
// phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
|
||||||
|
$this->assertEquals( $active_theme->Name, $theme['name'] );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -264,7 +268,18 @@ class WC_Tests_REST_System_Status extends WC_REST_Unit_Test_Case {
|
||||||
|
|
||||||
$this->assertEquals( 200, $response->get_status() );
|
$this->assertEquals( 200, $response->get_status() );
|
||||||
$this->assertEquals( count( $raw_tools ), count( $data ) );
|
$this->assertEquals( count( $raw_tools ), count( $data ) );
|
||||||
$this->assertContains(
|
|
||||||
|
$matching_tool_data = current(
|
||||||
|
array_filter(
|
||||||
|
$data,
|
||||||
|
function( $tool ) {
|
||||||
|
return 'regenerate_thumbnails' === $tool['id'];
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$this->assertIsArray( $matching_tool_data );
|
||||||
|
|
||||||
|
$this->assertArraySubset(
|
||||||
array(
|
array(
|
||||||
'id' => 'regenerate_thumbnails',
|
'id' => 'regenerate_thumbnails',
|
||||||
'name' => 'Regenerate shop thumbnails',
|
'name' => 'Regenerate shop thumbnails',
|
||||||
|
@ -279,7 +294,7 @@ class WC_Tests_REST_System_Status extends WC_REST_Unit_Test_Case {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
$data
|
$matching_tool_data
|
||||||
);
|
);
|
||||||
|
|
||||||
$query_params = array(
|
$query_params = array(
|
||||||
|
@ -292,12 +307,23 @@ class WC_Tests_REST_System_Status extends WC_REST_Unit_Test_Case {
|
||||||
|
|
||||||
$this->assertEquals( 200, $response->get_status() );
|
$this->assertEquals( 200, $response->get_status() );
|
||||||
$this->assertEquals( count( $raw_tools ), count( $data ) );
|
$this->assertEquals( count( $raw_tools ), count( $data ) );
|
||||||
$this->assertContains(
|
|
||||||
|
$matching_tool_data = current(
|
||||||
|
array_filter(
|
||||||
|
$data,
|
||||||
|
function( $tool ) {
|
||||||
|
return 'regenerate_thumbnails' === $tool['id'];
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$this->assertIsArray( $matching_tool_data );
|
||||||
|
|
||||||
|
$this->assertArraySubset(
|
||||||
array(
|
array(
|
||||||
'id' => 'regenerate_thumbnails',
|
'id' => 'regenerate_thumbnails',
|
||||||
'name' => 'Regenerate shop thumbnails',
|
'name' => 'Regenerate shop thumbnails',
|
||||||
),
|
),
|
||||||
$data
|
$matching_tool_data
|
||||||
);
|
);
|
||||||
foreach ( $data as $item ) {
|
foreach ( $data as $item ) {
|
||||||
// Fields that are not requested are not returned in response.
|
// Fields that are not requested are not returned in response.
|
||||||
|
|
|
@ -6,10 +6,13 @@
|
||||||
* @since 3.3.0
|
* @since 3.3.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* WC_Query tests.
|
* WC_Query tests.
|
||||||
*/
|
*/
|
||||||
class WC_Tests_WC_Query extends WC_Unit_Test_Case {
|
class WC_Tests_WC_Query extends WC_Unit_Test_Case {
|
||||||
|
use ArraySubsetAsserts;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test WC_Query gets initialized properly.
|
* Test WC_Query gets initialized properly.
|
||||||
|
@ -354,7 +357,16 @@ class WC_Tests_WC_Query extends WC_Unit_Test_Case {
|
||||||
|
|
||||||
WC()->query->product_query( new WP_Query( $query_args ) );
|
WC()->query->product_query( new WP_Query( $query_args ) );
|
||||||
$tax_queries = WC_Query::get_main_tax_query();
|
$tax_queries = WC_Query::get_main_tax_query();
|
||||||
$this->assertContains( $tax_query, $tax_queries );
|
$matching_tax_data = current(
|
||||||
|
array_filter(
|
||||||
|
$tax_queries,
|
||||||
|
function( $tax ) {
|
||||||
|
return 'product_tag' === $tax['taxonomy'];
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$this->assertIsArray( $matching_tax_data );
|
||||||
|
$this->assertArraySubset( $tax_query, $matching_tax_data );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -260,13 +260,13 @@ class WC_Admin_Tests_OnboardingTasks_TaskList extends WC_Unit_Test_Case {
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$json = $this->list->get_json();
|
$json = $this->list->get_json();
|
||||||
$this->assertContains( 'id', $json );
|
$this->assertArrayHasKey( 'id', $json );
|
||||||
$this->assertContains( 'title', $json );
|
$this->assertArrayHasKey( 'title', $json );
|
||||||
$this->assertContains( 'isHidden', $json );
|
$this->assertArrayHasKey( 'isHidden', $json );
|
||||||
$this->assertContains( 'isVisible', $json );
|
$this->assertArrayHasKey( 'isVisible', $json );
|
||||||
$this->assertContains( 'isComplete', $json );
|
$this->assertArrayHasKey( 'isComplete', $json );
|
||||||
$this->assertContains( 'tasks', $json );
|
$this->assertArrayHasKey( 'tasks', $json );
|
||||||
$this->assertContains( 'isComplete', $json['tasks'][0] );
|
$this->assertArrayHasKey( 'isComplete', $json['tasks'][0] );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -18,7 +18,7 @@ class WC_Admin_Tests_ProductForm_Form_Factory extends WC_Unit_Test_Case {
|
||||||
$field = Form::add_field( 'id', 'woocommerce', array() );
|
$field = Form::add_field( 'id', 'woocommerce', array() );
|
||||||
|
|
||||||
$this->assertInstanceOf( 'WP_Error', $field );
|
$this->assertInstanceOf( 'WP_Error', $field );
|
||||||
$this->assertContains( 'You are missing required arguments of WooCommerce ProductForm Field: type, section, properties.name, properties.label', $field->get_error_message() );
|
$this->assertStringContainsString( 'You are missing required arguments of WooCommerce ProductForm Field: type, section, properties.name, properties.label', $field->get_error_message() );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -51,7 +51,7 @@ class WC_Admin_Tests_ProductForm_Form_Factory extends WC_Unit_Test_Case {
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$this->assertInstanceOf( 'WP_Error', $field_duplicate );
|
$this->assertInstanceOf( 'WP_Error', $field_duplicate );
|
||||||
$this->assertContains( 'You have attempted to register a duplicate form field with WooCommerce Form: `id`', $field_duplicate->get_error_message() );
|
$this->assertStringContainsString( 'You have attempted to register a duplicate form field with WooCommerce Form: `id`', $field_duplicate->get_error_message() );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -165,7 +165,7 @@ class WC_Admin_Dashboard_Setup_Test extends WC_Unit_Test_Case {
|
||||||
);
|
);
|
||||||
|
|
||||||
foreach ( $required_strings as $required_string ) {
|
foreach ( $required_strings as $required_string ) {
|
||||||
$this->assertRegexp( "/{$required_string}/", $html );
|
$this->assertMatchesRegularExpression( "/{$required_string}/", $html );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -191,7 +191,7 @@ class WC_Admin_Dashboard_Setup_Test extends WC_Unit_Test_Case {
|
||||||
if ( $completed_tasks_count === $tasks_count ) {
|
if ( $completed_tasks_count === $tasks_count ) {
|
||||||
$this->assertEmpty( $this->get_widget_output() );
|
$this->assertEmpty( $this->get_widget_output() );
|
||||||
} else {
|
} else {
|
||||||
$this->assertRegexp( "/Step {$step_number} of 6/", $this->get_widget_output() );
|
$this->assertMatchesRegularExpression( "/Step {$step_number} of 6/", $this->get_widget_output() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -187,6 +187,6 @@ class WC_Cart_Test extends \WC_Unit_Test_Case {
|
||||||
|
|
||||||
$this->assertArrayHasKey( 'error', $notices );
|
$this->assertArrayHasKey( 'error', $notices );
|
||||||
$this->assertCount( 1, $notices['error'] );
|
$this->assertCount( 1, $notices['error'] );
|
||||||
$this->assertRegExp( '/Please choose product options by visiting/', $notices['error'][0]['notice'] );
|
$this->assertMatchesRegularExpression( '/Please choose product options by visiting/', $notices['error'][0]['notice'] );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,7 +97,7 @@ class WC_Core_Functions_Test extends \WC_Unit_Test_Case {
|
||||||
);
|
);
|
||||||
|
|
||||||
$actual = wc_add_number_precision( $value, $round );
|
$actual = wc_add_number_precision( $value, $round );
|
||||||
$this->assertEquals( $expected, $actual );
|
$this->assertFloatEquals( $expected, $actual );
|
||||||
|
|
||||||
remove_all_filters( 'wc_get_price_decimals' );
|
remove_all_filters( 'wc_get_price_decimals' );
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
* Text Domain: woocommerce
|
* Text Domain: woocommerce
|
||||||
* Domain Path: /i18n/languages/
|
* Domain Path: /i18n/languages/
|
||||||
* Requires at least: 5.9
|
* Requires at least: 5.9
|
||||||
* Requires PHP: 7.2
|
* Requires PHP: 7.3
|
||||||
*
|
*
|
||||||
* @package WooCommerce
|
* @package WooCommerce
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue