Commit 9117dfb5a2b for woocommerce
commit 9117dfb5a2baec095ab21c92c3851f6c7df19ce3
Author: Vlad Olaru <vlad.olaru@automattic.com>
Date: Mon Nov 16 11:40:49 2026 +0200
[tests] Drop hook removals and option restores at the end of tests (#70968)
test: Drop hook removals and option restores at the end of tests
WordPress's test case restores its hook snapshot and rolls back the
database after every test, and the object cache is flushed before the
next one. A remove_filter(), remove_action(), remove_all_*(),
delete_option() or update_option() that ends a test method, or ends a
finally block that ends it, is undone by that teardown. It only matters
if something between the end of the test and the restore uses it.
A probe recorded every hook fired between each test's end and the hook
restore, in full suites with HPOS on and off. A removal is deleted only
when its hook never fires in that window for that test. An option write
is deleted only when the teardown does not read the option, the test
runs no DDL, and the option's own update or delete hooks have no
callback that changes state outside the database and object cache.
Deletes 510 hook removals and 179 option writes in 190 test files,
unwraps the 111 try statements left with an empty finally block, and
removes the variables that only held values for the restores. Keeps 16
statements: hooks that fire during teardown, options it reads, a DDL
test, a listener that changes WC_Admin_Notices' in-memory list, and
statements in tests that are always skipped.
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
diff --git a/plugins/woocommerce/changelog/test-drop-noop-in-test-hook-removals b/plugins/woocommerce/changelog/test-drop-noop-in-test-hook-removals
new file mode 100644
index 00000000000..268158d9332
--- /dev/null
+++ b/plugins/woocommerce/changelog/test-drop-noop-in-test-hook-removals
@@ -0,0 +1,3 @@
+Significance: patch
+Type: dev
+Comment: Remove hook removals and option restores at the end of tests that the base test case already undoes; no production change.
diff --git a/plugins/woocommerce/tests/legacy/unit-tests/admin/class-wc-tests-admin-dashboard.php b/plugins/woocommerce/tests/legacy/unit-tests/admin/class-wc-tests-admin-dashboard.php
index 037eff57ff2..7c77466e7e6 100644
--- a/plugins/woocommerce/tests/legacy/unit-tests/admin/class-wc-tests-admin-dashboard.php
+++ b/plugins/woocommerce/tests/legacy/unit-tests/admin/class-wc-tests-admin-dashboard.php
@@ -97,7 +97,7 @@ class WC_Tests_Admin_Dashboard extends WC_Unit_Test_Case {
* Test: recent reviews widget content (legacy).
*/
public function test_recent_reviews_widget_content_legacy_version() {
- add_filter( 'woocommerce_report_recent_reviews_query_from', $legacy_filter = fn( string $sql ) => $sql );
+ add_filter( 'woocommerce_report_recent_reviews_query_from', fn( string $sql ) => $sql );
$this->expected_deprecated = array_merge( $this->expected_deprecated, array( 'woocommerce_report_recent_reviews_query_from' ) );
$product = WC_Helper_Product::create_simple_product();
@@ -115,7 +115,6 @@ class WC_Tests_Admin_Dashboard extends WC_Unit_Test_Case {
$this->expectOutputRegex( '/reviewed by/' );
$product->delete();
- remove_filter( 'woocommerce_report_recent_reviews_query_from', $legacy_filter );
}
/**
diff --git a/plugins/woocommerce/tests/legacy/unit-tests/admin/settings.php b/plugins/woocommerce/tests/legacy/unit-tests/admin/settings.php
index aa45c24a6cf..6a1a17b5b6c 100644
--- a/plugins/woocommerce/tests/legacy/unit-tests/admin/settings.php
+++ b/plugins/woocommerce/tests/legacy/unit-tests/admin/settings.php
@@ -16,7 +16,6 @@ class WC_Tests_Admin_Settings extends WC_Unit_Test_Case {
* Test WC_Admin_Settings::check_download_folder_protection().
*/
public function test_check_download_folder_protection() {
- $default = get_option( 'woocommerce_file_download_method' );
$upload_dir = wp_get_upload_dir();
$file_path = $upload_dir['basedir'] . '/woocommerce_uploads/.htaccess';
@@ -33,8 +32,6 @@ class WC_Tests_Admin_Settings extends WC_Unit_Test_Case {
// phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
$file_content = file_exists( $file_path ) ? file_get_contents( $file_path ) : '';
$this->assertEquals( 'Options -Indexes', $file_content );
-
- update_option( 'woocommerce_file_download_method', $default );
}
/**
diff --git a/plugins/woocommerce/tests/legacy/unit-tests/cart/cart.php b/plugins/woocommerce/tests/legacy/unit-tests/cart/cart.php
index ffa3cdffb30..689001b1241 100644
--- a/plugins/woocommerce/tests/legacy/unit-tests/cart/cart.php
+++ b/plugins/woocommerce/tests/legacy/unit-tests/cart/cart.php
@@ -2093,9 +2093,6 @@ class WC_Tests_Cart extends WC_Unit_Test_Case {
// Reduced-rate class (20%) applied via filter: ex-tax subtotal is unchanged, total rises to reflect higher rate.
$this->assertEquals( '5.71', WC()->cart->get_subtotal() );
$this->assertEquals( '6.85', WC()->cart->get_total( 'edit' ) );
-
- remove_filter( 'woocommerce_product_get_tax_class', array( $this, 'change_tax_class_filter' ) );
- remove_filter( 'woocommerce_product_variation_get_tax_class', array( $this, 'change_tax_class_filter' ) );
}
/**
diff --git a/plugins/woocommerce/tests/legacy/unit-tests/cart/functions.php b/plugins/woocommerce/tests/legacy/unit-tests/cart/functions.php
index ff1ffd96973..9fee45a8eeb 100644
--- a/plugins/woocommerce/tests/legacy/unit-tests/cart/functions.php
+++ b/plugins/woocommerce/tests/legacy/unit-tests/cart/functions.php
@@ -213,8 +213,6 @@ class WC_Tests_Cart_Functions extends WC_Unit_Test_Case {
$message = wc_add_to_cart_message( $product->get_id(), true, true );
$this->assertEquals( '“Dummy Product” has been added to your cart. <a href="' . $cart_page_url . '" class="button wc-forward' . $wp_button_class . '">View cart</a>', $message );
-
- delete_option( 'woocommerce_cart_page_id' );
}
/**
diff --git a/plugins/woocommerce/tests/legacy/unit-tests/customer/functions.php b/plugins/woocommerce/tests/legacy/unit-tests/customer/functions.php
index 361d3a53d6c..dc1cc6e7ec3 100644
--- a/plugins/woocommerce/tests/legacy/unit-tests/customer/functions.php
+++ b/plugins/woocommerce/tests/legacy/unit-tests/customer/functions.php
@@ -137,8 +137,6 @@ class WC_Tests_Customer_Functions extends WC_Unit_Test_Case {
'woo_user_',
wc_create_new_customer_username( 'test@test.com' )
);
-
- remove_filter( 'illegal_user_logins', array( $this, 'setup_illegal_user_logins' ) );
}
/**
diff --git a/plugins/woocommerce/tests/legacy/unit-tests/discounts/discounts.php b/plugins/woocommerce/tests/legacy/unit-tests/discounts/discounts.php
index 2d1fe8b062e..8819485adf9 100644
--- a/plugins/woocommerce/tests/legacy/unit-tests/discounts/discounts.php
+++ b/plugins/woocommerce/tests/legacy/unit-tests/discounts/discounts.php
@@ -1509,8 +1509,6 @@ class WC_Tests_Discounts extends WC_Unit_Test_Case {
}
$this->assertEquals( 20, $discount_total );
-
- remove_filter( 'woocommerce_coupon_get_discount_amount', array( $this, 'filter_woocommerce_coupon_get_discount_amount' ) );
}
/**
diff --git a/plugins/woocommerce/tests/legacy/unit-tests/email/emails.php b/plugins/woocommerce/tests/legacy/unit-tests/email/emails.php
index ef57093a287..adcdfbd747a 100644
--- a/plugins/woocommerce/tests/legacy/unit-tests/email/emails.php
+++ b/plugins/woocommerce/tests/legacy/unit-tests/email/emails.php
@@ -182,10 +182,6 @@ class WC_Tests_WC_Emails extends WC_Unit_Test_Case {
$result = $email->format_string( 'Hello {customer_name}' );
$this->assertEquals( 'Hello Jane Smith', $result );
-
- // Clean up filters.
- remove_all_filters( 'woocommerce_email_format_string_replace' );
- remove_all_filters( 'woocommerce_email_format_string_find' );
}
/**
@@ -218,10 +214,6 @@ class WC_Tests_WC_Emails extends WC_Unit_Test_Case {
$email->format_string( 'Welcome to {blogname}!' ),
'Legacy filters should be able to override the default blogname replacement but cannot due to a bug'
);
-
- // Clean up filters.
- remove_all_filters( 'woocommerce_email_format_string_replace' );
- remove_all_filters( 'woocommerce_email_format_string_find' );
}
/**
@@ -242,9 +234,6 @@ class WC_Tests_WC_Emails extends WC_Unit_Test_Case {
'Completely overridden',
$email->format_string( 'Original text with {customer_name}' )
);
-
- // Clean up.
- remove_all_filters( 'woocommerce_email_format_string' );
}
/**
@@ -315,11 +304,6 @@ class WC_Tests_WC_Emails extends WC_Unit_Test_Case {
$this->assertTrue( $email->get_reply_to_enabled() );
$this->assertEquals( 'Support Team', $email->get_reply_to_name() );
$this->assertEquals( 'support@example.com', $email->get_reply_to_address() );
-
- // Clean up.
- delete_option( 'woocommerce_email_reply_to_enabled' );
- delete_option( 'woocommerce_email_reply_to_name' );
- delete_option( 'woocommerce_email_reply_to_address' );
}
/**
@@ -331,9 +315,6 @@ class WC_Tests_WC_Emails extends WC_Unit_Test_Case {
$email = new WC_Email();
$this->assertFalse( $email->get_reply_to_enabled() );
-
- // Clean up.
- delete_option( 'woocommerce_email_reply_to_enabled' );
}
/**
@@ -347,10 +328,6 @@ class WC_Tests_WC_Emails extends WC_Unit_Test_Case {
$this->assertEquals( 'Support', $email->get_reply_to_name() );
$this->assertEquals( 'support@example.com', $email->get_reply_to_address() );
-
- // Clean up.
- delete_option( 'woocommerce_email_reply_to_name' );
- delete_option( 'woocommerce_email_reply_to_address' );
}
/**
@@ -368,11 +345,6 @@ class WC_Tests_WC_Emails extends WC_Unit_Test_Case {
$result = $email->get_headers();
$this->assertStringContainsString( 'Reply-to: Support Team <support@example.com>', $result );
-
- // Clean up.
- delete_option( 'woocommerce_email_reply_to_enabled' );
- delete_option( 'woocommerce_email_reply_to_name' );
- delete_option( 'woocommerce_email_reply_to_address' );
}
/**
@@ -391,12 +363,6 @@ class WC_Tests_WC_Emails extends WC_Unit_Test_Case {
$result = $email->get_headers();
$this->assertStringContainsString( 'Reply-to: My Store <support@example.com>', $result );
-
- // Clean up.
- delete_option( 'woocommerce_email_reply_to_enabled' );
- delete_option( 'woocommerce_email_reply_to_name' );
- delete_option( 'woocommerce_email_reply_to_address' );
- delete_option( 'woocommerce_email_from_name' );
}
/**
@@ -423,11 +389,6 @@ class WC_Tests_WC_Emails extends WC_Unit_Test_Case {
// Should use customer email, not custom reply-to.
$this->assertStringContainsString( 'Reply-to: John Doe <customer@example.com>', $result );
$this->assertStringNotContainsString( 'support@example.com', $result );
-
- // Clean up.
- delete_option( 'woocommerce_email_reply_to_enabled' );
- delete_option( 'woocommerce_email_reply_to_name' );
- delete_option( 'woocommerce_email_reply_to_address' );
}
/**
@@ -446,11 +407,6 @@ class WC_Tests_WC_Emails extends WC_Unit_Test_Case {
// Should use from address as reply-to.
$this->assertStringContainsString( 'Reply-to: My Store <store@example.com>', $result );
-
- // Clean up.
- delete_option( 'woocommerce_email_reply_to_enabled' );
- delete_option( 'woocommerce_email_from_name' );
- delete_option( 'woocommerce_email_from_address' );
}
/**
@@ -487,14 +443,6 @@ class WC_Tests_WC_Emails extends WC_Unit_Test_Case {
$this->assertFalse( $email->get_reply_to_enabled() );
$this->assertEquals( 'Filtered Name', $email->get_reply_to_name() );
$this->assertEquals( 'filtered@example.com', $email->get_reply_to_address() );
-
- // Clean up.
- remove_all_filters( 'woocommerce_email_reply_to_enabled' );
- remove_all_filters( 'woocommerce_email_reply_to_name' );
- remove_all_filters( 'woocommerce_email_reply_to_address' );
- delete_option( 'woocommerce_email_reply_to_enabled' );
- delete_option( 'woocommerce_email_reply_to_name' );
- delete_option( 'woocommerce_email_reply_to_address' );
}
/**
@@ -516,12 +464,5 @@ class WC_Tests_WC_Emails extends WC_Unit_Test_Case {
// Should fallback to from address since reply-to address is invalid.
$this->assertStringContainsString( 'Reply-to: My Store <store@example.com>', $result );
$this->assertStringNotContainsString( 'invalid-email', $result );
-
- // Clean up.
- delete_option( 'woocommerce_email_reply_to_enabled' );
- delete_option( 'woocommerce_email_reply_to_name' );
- delete_option( 'woocommerce_email_reply_to_address' );
- delete_option( 'woocommerce_email_from_name' );
- delete_option( 'woocommerce_email_from_address' );
}
}
diff --git a/plugins/woocommerce/tests/legacy/unit-tests/formatting/functions.php b/plugins/woocommerce/tests/legacy/unit-tests/formatting/functions.php
index 75fde2d01af..d9e1b2520a9 100644
--- a/plugins/woocommerce/tests/legacy/unit-tests/formatting/functions.php
+++ b/plugins/woocommerce/tests/legacy/unit-tests/formatting/functions.php
@@ -107,9 +107,6 @@ class WC_Tests_Formatting_Functions extends WC_Unit_Test_Case {
* @since 2.2
*/
public function test_wc_get_dimension() {
- // Save default.
- $default_unit = get_option( 'woocommerce_dimension_unit' );
-
// in (default unit).
$this->assertEquals(
array( 25.4, 10, 0.2777777782, 254, 0.254 ),
@@ -187,9 +184,6 @@ class WC_Tests_Formatting_Functions extends WC_Unit_Test_Case {
wc_get_dimension( 10, 'yd', 'mm' ),
)
);
-
- // Restore default.
- update_option( 'woocommerce_dimension_unit', $default_unit );
}
/**
@@ -198,9 +192,6 @@ class WC_Tests_Formatting_Functions extends WC_Unit_Test_Case {
* @since 2.2
*/
public function test_wc_get_weight() {
- // Save default.
- $default_unit = get_option( 'woocommerce_weight_unit' );
-
// lbs (default unit).
$this->assertEquals( 4.53592, wc_get_weight( 10, 'kg' ) );
$this->assertEquals( 4535.92, wc_get_weight( 10, 'g' ) );
@@ -236,9 +227,6 @@ class WC_Tests_Formatting_Functions extends WC_Unit_Test_Case {
// Negative.
$this->assertEquals( 0, wc_get_weight( -10, 'g' ) );
-
- // Restore default.
- update_option( 'woocommerce_weight_unit', $default_unit );
}
/**
@@ -274,9 +262,6 @@ class WC_Tests_Formatting_Functions extends WC_Unit_Test_Case {
$this->assertEquals( 82, wc_round_tax_total( 82.5, 0 ) );
$this->assertEquals( 83, wc_round_tax_total( 82.54, 0 ) );
$this->assertEquals( 83, wc_round_tax_total( 82.546, 0 ) );
-
- // Default.
- update_option( 'woocommerce_prices_include_tax', 'no' );
}
/**
@@ -388,10 +373,6 @@ class WC_Tests_Formatting_Functions extends WC_Unit_Test_Case {
// Floats.
$this->assertEquals( '0.00001', wc_format_decimal( 0.00001 ) );
$this->assertEquals( '0.22222222', wc_format_decimal( 0.22222222 ) );
-
- update_option( 'woocommerce_price_num_decimals', '2' );
- update_option( 'woocommerce_price_decimal_sep', '.' );
- update_option( 'woocommerce_price_thousand_sep', ',' );
}
/**
@@ -411,14 +392,9 @@ class WC_Tests_Formatting_Functions extends WC_Unit_Test_Case {
* @since 2.2
*/
public function test_wc_format_localized_price() {
- // Save default.
- $decimal_sep = get_option( 'woocommerce_price_decimal_sep' );
update_option( 'woocommerce_price_decimal_sep', ',' );
$this->assertEquals( '1,17', wc_format_localized_price( '1.17' ) );
-
- // Restore default.
- update_option( 'woocommerce_price_decimal_sep', $decimal_sep );
}
/**
@@ -526,9 +502,6 @@ class WC_Tests_Formatting_Functions extends WC_Unit_Test_Case {
* @since 2.2
*/
public function test_get_woocommerce_price_format() {
- // Save default.
- $currency_pos = get_option( 'woocommerce_currency_pos' );
-
// Default format (left).
$this->assertEquals( '%1$s%2$s', get_woocommerce_price_format() );
@@ -543,9 +516,6 @@ class WC_Tests_Formatting_Functions extends WC_Unit_Test_Case {
// Right space.
update_option( 'woocommerce_currency_pos', 'right_space' );
$this->assertEquals( '%2$s %1$s', get_woocommerce_price_format() );
-
- // Restore default.
- update_option( 'woocommerce_currency_pos', $currency_pos );
}
/**
@@ -554,8 +524,6 @@ class WC_Tests_Formatting_Functions extends WC_Unit_Test_Case {
* @since 2.4
*/
public function test_wc_get_price_thousand_separator() {
- $separator = get_option( 'woocommerce_price_thousand_sep' );
-
// Default value.
$this->assertEquals( ',', wc_get_price_thousand_separator() );
@@ -564,8 +532,6 @@ class WC_Tests_Formatting_Functions extends WC_Unit_Test_Case {
update_option( 'woocommerce_price_thousand_sep', '<.>' );
$this->assertEquals( '<.>', wc_get_price_thousand_separator() );
-
- update_option( 'woocommerce_price_thousand_sep', $separator );
}
/**
@@ -574,8 +540,6 @@ class WC_Tests_Formatting_Functions extends WC_Unit_Test_Case {
* @since 2.4
*/
public function test_wc_get_price_decimal_separator() {
- $separator = get_option( 'woocommerce_price_decimal_sep' );
-
// Default value.
$this->assertEquals( '.', wc_get_price_decimal_separator() );
@@ -584,8 +548,6 @@ class WC_Tests_Formatting_Functions extends WC_Unit_Test_Case {
update_option( 'woocommerce_price_decimal_sep', '<.>' );
$this->assertEquals( '<.>', wc_get_price_decimal_separator() );
-
- update_option( 'woocommerce_price_decimal_sep', $separator );
}
/**
@@ -594,8 +556,6 @@ class WC_Tests_Formatting_Functions extends WC_Unit_Test_Case {
* @since 2.4
*/
public function test_wc_get_price_decimals() {
- $decimals = get_option( 'woocommerce_price_num_decimals' );
-
// Default value.
$this->assertEquals( 2, wc_get_price_decimals() );
@@ -607,8 +567,6 @@ class WC_Tests_Formatting_Functions extends WC_Unit_Test_Case {
update_option( 'woocommerce_price_num_decimals', '2.50' );
$this->assertEquals( 2, wc_get_price_decimals() );
-
- update_option( 'woocommerce_price_num_decimals', $decimals );
}
/**
@@ -644,10 +602,8 @@ class WC_Tests_Formatting_Functions extends WC_Unit_Test_Case {
remove_filter( 'woocommerce_price_trim_zeros', '__return_true' );
// Ex tax label.
- $calc_taxes = get_option( 'woocommerce_calc_taxes' );
update_option( 'woocommerce_calc_taxes', 'yes' );
$this->assertEquals( '<span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol" translate="no" dir="auto">$</span>1,111.17</bdi></span> <small class="woocommerce-Price-taxLabel tax_label">(ex. tax)</small>', wc_price( '1111.17', array( 'ex_tax_label' => true ) ) );
- update_option( 'woocommerce_calc_taxes', $calc_taxes );
}
/**
@@ -659,8 +615,7 @@ class WC_Tests_Formatting_Functions extends WC_Unit_Test_Case {
* @since 11.1.0
*/
public function test_wc_price_currency_symbol_is_direction_isolated() {
- $original_position = get_option( 'woocommerce_currency_pos' );
- $symbol = '<span class="woocommerce-Price-currencySymbol" translate="no" dir="auto">ل.ل</span>';
+ $symbol = '<span class="woocommerce-Price-currencySymbol" translate="no" dir="auto">ل.ل</span>';
$expected_by_position = array(
'left' => $symbol . '15.00',
@@ -677,8 +632,6 @@ class WC_Tests_Formatting_Functions extends WC_Unit_Test_Case {
"Currency position '{$position}' should render the direction-isolated symbol on the configured side"
);
}
-
- update_option( 'woocommerce_currency_pos', $original_position );
}
/**
@@ -767,9 +720,6 @@ class WC_Tests_Formatting_Functions extends WC_Unit_Test_Case {
// Test with invalid offset.
update_option( 'gmt_offset', 'invalid' );
$this->assertContains( wc_timezone_string(), array( '+00:00', 'UTC' ) );
-
- // Restore default.
- update_option( 'gmt_offset', '0' );
}
/**
@@ -902,11 +852,7 @@ class WC_Tests_Formatting_Functions extends WC_Unit_Test_Case {
public function test_wc_format_phone_number_is_not_affected_by_validate_phone_filter() {
add_filter( 'woocommerce_validate_phone', '__return_false' );
- try {
- $this->assertEquals( '1-610-385-0000', wc_format_phone_number( '1.610.385.0000' ) );
- } finally {
- remove_filter( 'woocommerce_validate_phone', '__return_false' );
- }
+ $this->assertEquals( '1-610-385-0000', wc_format_phone_number( '1.610.385.0000' ) );
}
/**
@@ -926,14 +872,10 @@ class WC_Tests_Formatting_Functions extends WC_Unit_Test_Case {
add_filter( 'woocommerce_format_phone_number', $callback, 10, 3 );
- try {
- $this->assertEquals( 'filtered', wc_format_phone_number( '1.610.385.0000' ) );
- $this->assertEquals( '1-610-385-0000', $received['formatted'] );
- $this->assertEquals( '1.610.385.0000', $received['original'] );
- $this->assertTrue( $received['is_valid'] );
- } finally {
- remove_filter( 'woocommerce_format_phone_number', $callback, 10 );
- }
+ $this->assertEquals( 'filtered', wc_format_phone_number( '1.610.385.0000' ) );
+ $this->assertEquals( '1-610-385-0000', $received['formatted'] );
+ $this->assertEquals( '1.610.385.0000', $received['original'] );
+ $this->assertTrue( $received['is_valid'] );
}
/**
diff --git a/plugins/woocommerce/tests/legacy/unit-tests/integrations/class-wc-tests-integrations.php b/plugins/woocommerce/tests/legacy/unit-tests/integrations/class-wc-tests-integrations.php
index 1adc9aff493..2187523b261 100644
--- a/plugins/woocommerce/tests/legacy/unit-tests/integrations/class-wc-tests-integrations.php
+++ b/plugins/woocommerce/tests/legacy/unit-tests/integrations/class-wc-tests-integrations.php
@@ -39,8 +39,6 @@ class WC_Tests_Integrations extends WC_Unit_Test_Case {
$integrations = new WC_Integrations();
$this->assertArrayHasKey( 'dummy-integration', $integrations->integrations );
$this->assertArrayHasKey( 'dummy-integration', $integrations->get_integrations() );
-
- remove_filter( 'woocommerce_integrations', array( $this, 'add_dummy_integration' ) );
}
/**
diff --git a/plugins/woocommerce/tests/legacy/unit-tests/log/logger.php b/plugins/woocommerce/tests/legacy/unit-tests/log/logger.php
index 88dcd33b346..45284e87fa7 100644
--- a/plugins/woocommerce/tests/legacy/unit-tests/log/logger.php
+++ b/plugins/woocommerce/tests/legacy/unit-tests/log/logger.php
@@ -194,7 +194,6 @@ class WC_Tests_Logger extends WC_Unit_Test_Case {
$log->critical( 'critical' );
$log->alert( 'alert' );
$log->emergency( 'emergency' );
- remove_filter( 'woocommerce_register_log_handlers', array( $this, 'return_assertion_handlers' ) );
}
/**
diff --git a/plugins/woocommerce/tests/legacy/unit-tests/order/class-wc-tests-crud-orders.php b/plugins/woocommerce/tests/legacy/unit-tests/order/class-wc-tests-crud-orders.php
index 514ad0b92ee..5658c14d6cb 100644
--- a/plugins/woocommerce/tests/legacy/unit-tests/order/class-wc-tests-crud-orders.php
+++ b/plugins/woocommerce/tests/legacy/unit-tests/order/class-wc-tests-crud-orders.php
@@ -1017,8 +1017,6 @@ class WC_Tests_CRUD_Orders extends WC_Unit_Test_Case {
)
);
$this->assertStringContainsString( 'Payment complete event failed', $note->content );
-
- remove_action( 'woocommerce_payment_complete', array( $this, 'throwAnException' ) );
}
/**
@@ -2320,8 +2318,6 @@ class WC_Tests_CRUD_Orders extends WC_Unit_Test_Case {
)
);
$this->assertStringContainsString( 'Update status event failed', $note->content );
-
- remove_filter( 'woocommerce_payment_complete_order_status', array( $this, 'throwAnException' ) );
}
/**
@@ -3313,8 +3309,6 @@ class WC_Tests_CRUD_Orders extends WC_Unit_Test_Case {
)
);
$this->assertStringContainsString( 'Error saving order', $note->content );
-
- remove_action( 'woocommerce_before_order_object_save', array( $this, 'throwAnException' ) );
}
/**
diff --git a/plugins/woocommerce/tests/legacy/unit-tests/order/class-wc-tests-order-functions.php b/plugins/woocommerce/tests/legacy/unit-tests/order/class-wc-tests-order-functions.php
index 07f68d61ed7..f0da7a44e1b 100644
--- a/plugins/woocommerce/tests/legacy/unit-tests/order/class-wc-tests-order-functions.php
+++ b/plugins/woocommerce/tests/legacy/unit-tests/order/class-wc-tests-order-functions.php
@@ -176,15 +176,11 @@ class WC_Tests_Order_Functions extends WC_Unit_Test_Case {
*/
public function test_wc_ship_to_billing_address_only() {
- $default = get_option( 'woocommerce_ship_to_destination' );
-
update_option( 'woocommerce_ship_to_destination', 'shipping' );
$this->assertFalse( wc_ship_to_billing_address_only() );
update_option( 'woocommerce_ship_to_destination', 'billing_only' );
$this->assertTrue( wc_ship_to_billing_address_only() );
-
- update_option( 'woocommerce_ship_to_destination', $default );
}
/**
@@ -1635,7 +1631,6 @@ class WC_Tests_Order_Functions extends WC_Unit_Test_Case {
);
WC_Tax::_delete_tax_rate( $rate_id );
- update_option( 'woocommerce_calc_taxes', 'no' );
}
/**
@@ -2111,13 +2106,6 @@ class WC_Tests_Order_Functions extends WC_Unit_Test_Case {
$this->assertEquals( 0, $coupon_data_store->get_tentative_usage_count( $coupon->get_id() ) );
$this->assertEquals( 1, $coupon_data_store->get_usage_by_email( $coupon, 'a@b.com' ) );
$this->assertEquals( 0, $coupon_data_store->get_tentative_usages_for_user( $coupon->get_id(), array( 'a@b.com' ) ) );
-
- remove_filter(
- 'woocommerce_coupon_hold_minutes',
- function () {
- return 0;
- }
- );
}
/**
diff --git a/plugins/woocommerce/tests/legacy/unit-tests/product/data-store.php b/plugins/woocommerce/tests/legacy/unit-tests/product/data-store.php
index 85ada028e34..6ad093c48c1 100644
--- a/plugins/woocommerce/tests/legacy/unit-tests/product/data-store.php
+++ b/plugins/woocommerce/tests/legacy/unit-tests/product/data-store.php
@@ -86,11 +86,6 @@ class WC_Tests_Product_Data_Store extends WC_Unit_Test_Case {
$product->save();
$this->assertEquals( ProductStatus::DRAFT, $product->get_status() );
-
- remove_filter(
- 'woocommerce_new_product_data',
- $force_draft_status_fn
- );
}
/**
@@ -797,8 +792,6 @@ class WC_Tests_Product_Data_Store extends WC_Unit_Test_Case {
$this->assertEquals( 'world', $test2 ); // this would be 'default' without the force meta refresh in WC_Product_Data_Store::update().
$this->assertEquals( 'world', $product->get_meta( '_test2' ) );
$this->assertEquals( 'Test Product_', $product->get_name() );
-
- remove_action( 'save_post', array( 'WC_Helper_Product', 'save_post_test_update_meta_data_direct' ) );
}
/**
diff --git a/plugins/woocommerce/tests/legacy/unit-tests/rest-api/Tests/Version2/shipping-zones.php b/plugins/woocommerce/tests/legacy/unit-tests/rest-api/Tests/Version2/shipping-zones.php
index d58f8aa560e..37e246bf6a3 100644
--- a/plugins/woocommerce/tests/legacy/unit-tests/rest-api/Tests/Version2/shipping-zones.php
+++ b/plugins/woocommerce/tests/legacy/unit-tests/rest-api/Tests/Version2/shipping-zones.php
@@ -164,8 +164,6 @@ class WC_Tests_API_Shipping_Zones_V2 extends WC_REST_Unit_Test_Case {
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/shipping/zones' ) );
$this->assertEquals( 404, $response->get_status() );
-
- remove_filter( 'wc_shipping_enabled', '__return_false' );
}
/**
diff --git a/plugins/woocommerce/tests/legacy/unit-tests/rest-api/Tests/Version3/shipping-zones.php b/plugins/woocommerce/tests/legacy/unit-tests/rest-api/Tests/Version3/shipping-zones.php
index bdcc6f9c5db..88810a13ce9 100644
--- a/plugins/woocommerce/tests/legacy/unit-tests/rest-api/Tests/Version3/shipping-zones.php
+++ b/plugins/woocommerce/tests/legacy/unit-tests/rest-api/Tests/Version3/shipping-zones.php
@@ -205,8 +205,6 @@ class WC_Tests_API_Shipping_Zones extends WC_REST_Unit_Test_Case {
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/shipping/zones' ) );
$this->assertEquals( 404, $response->get_status() );
-
- remove_filter( 'wc_shipping_enabled', '__return_false' );
}
/**
diff --git a/plugins/woocommerce/tests/legacy/unit-tests/shipping/shipping-zone.php b/plugins/woocommerce/tests/legacy/unit-tests/shipping/shipping-zone.php
index 78052c0302c..9245e9880cc 100644
--- a/plugins/woocommerce/tests/legacy/unit-tests/shipping/shipping-zone.php
+++ b/plugins/woocommerce/tests/legacy/unit-tests/shipping/shipping-zone.php
@@ -166,7 +166,6 @@ class WC_Tests_Shipping_Zone extends WC_Unit_Test_Case {
$this->assertFalse( $zone->is_valid_location_type( 'poop' ) );
add_filter( 'woocommerce_valid_location_types', array( $this, 'add_valid_zone_location' ) );
$this->assertTrue( $zone->is_valid_location_type( 'poop' ) );
- remove_filter( 'woocommerce_valid_location_types', array( $this, 'add_valid_zone_location' ), 10 );
}
/**
diff --git a/plugins/woocommerce/tests/legacy/unit-tests/util/class-wc-tests-core-functions.php b/plugins/woocommerce/tests/legacy/unit-tests/util/class-wc-tests-core-functions.php
index 3e8bbeb91fe..d2b2a68958e 100644
--- a/plugins/woocommerce/tests/legacy/unit-tests/util/class-wc-tests-core-functions.php
+++ b/plugins/woocommerce/tests/legacy/unit-tests/util/class-wc-tests-core-functions.php
@@ -460,8 +460,6 @@ class WC_Tests_Core_Functions extends WC_Unit_Test_Case {
$this->assertEquals( wp_json_encode( $arr ), wc_print_r( $arr, true ) );
$this->assertEquals( serialize( $arr ), wc_print_r( $arr, true ) );
$this->assertFalse( wc_print_r( $arr, true ) );
-
- remove_filter( 'woocommerce_print_r_alternatives', array( $this, 'filter_wc_print_r_alternatives' ) );
}
/**
diff --git a/plugins/woocommerce/tests/legacy/unit-tests/util/validation.php b/plugins/woocommerce/tests/legacy/unit-tests/util/validation.php
index 2e066528b97..2cb84fa6dbf 100644
--- a/plugins/woocommerce/tests/legacy/unit-tests/util/validation.php
+++ b/plugins/woocommerce/tests/legacy/unit-tests/util/validation.php
@@ -246,11 +246,7 @@ class WC_Tests_Validation extends WC_Unit_Test_Case {
public function test_is_phone_format_ignores_validate_phone_filter() {
add_filter( 'woocommerce_validate_phone', '__return_false' );
- try {
- $this->assertTrue( WC_Validation::is_phone_format( '+00 000 00 00 000' ) );
- $this->assertFalse( WC_Validation::is_phone( '+00 000 00 00 000' ) );
- } finally {
- remove_filter( 'woocommerce_validate_phone', '__return_false' );
- }
+ $this->assertTrue( WC_Validation::is_phone_format( '+00 000 00 00 000' ) );
+ $this->assertFalse( WC_Validation::is_phone( '+00 000 00 00 000' ) );
}
}
diff --git a/plugins/woocommerce/tests/legacy/unit-tests/webhooks/functions.php b/plugins/woocommerce/tests/legacy/unit-tests/webhooks/functions.php
index 01f32e0f47d..344659305c6 100644
--- a/plugins/woocommerce/tests/legacy/unit-tests/webhooks/functions.php
+++ b/plugins/woocommerce/tests/legacy/unit-tests/webhooks/functions.php
@@ -171,13 +171,8 @@ class WC_Tests_Webhook_Functions extends WC_Unit_Test_Case {
add_filter( 'woocommerce_valid_webhook_events', $add_event );
add_filter( 'woocommerce_valid_webhook_resources', $add_resource );
- try {
- $this->assertTrue( wc_is_webhook_valid_topic( 'order.refunded' ) );
- $this->assertTrue( wc_is_webhook_valid_topic( 'subscription.created' ) );
- } finally {
- remove_filter( 'woocommerce_valid_webhook_events', $add_event );
- remove_filter( 'woocommerce_valid_webhook_resources', $add_resource );
- }
+ $this->assertTrue( wc_is_webhook_valid_topic( 'order.refunded' ) );
+ $this->assertTrue( wc_is_webhook_valid_topic( 'subscription.created' ) );
}
/**
@@ -537,7 +532,6 @@ class WC_Tests_Webhook_Functions extends WC_Unit_Test_Case {
$webhook2->delete( true );
$customer1->delete( true );
$customer2->delete( true );
- remove_action( 'woocommerce_webhook_process_delivery', array( $this, 'woocommerce_webhook_process_delivery' ), 1, 2 );
}
/**
diff --git a/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/api/onboarding-tasks.php b/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/api/onboarding-tasks.php
index cb85370fecd..dc1f838a564 100644
--- a/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/api/onboarding-tasks.php
+++ b/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/api/onboarding-tasks.php
@@ -150,9 +150,6 @@ class WC_Admin_Tests_API_Onboarding_Tasks extends WC_REST_Unit_Test_Case {
$this->assertCount( 0, $data['skipped'] );
$this->assertArrayHasKey( 'updated', $data );
$this->assertEquals( 0, count( $data['updated'] ) );
-
- remove_all_filters( 'pre_http_request' );
- remove_all_filters( 'woocommerce_product_csv_importer_args' );
}
/**
diff --git a/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/api/orders.php b/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/api/orders.php
index d6eb54a8265..620e3414428 100644
--- a/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/api/orders.php
+++ b/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/api/orders.php
@@ -38,7 +38,6 @@ class WC_Admin_Tests_API_Orders extends WC_REST_Unit_Test_Case {
*/
public function test_order_status() {
// Add a status to the actionable list.
- $actionable_statuses = get_option( 'woocommerce_actionable_order_statuses', array() );
update_option( 'woocommerce_actionable_order_statuses', array( 'test-status' ) );
// Ideally this would be a test using an endpoint, but the option value is used
@@ -46,9 +45,6 @@ class WC_Admin_Tests_API_Orders extends WC_REST_Unit_Test_Case {
// here to test with the actual endpoint code. Instantiating a new WP_REST_Server
// didn't seem to work either.
$this->assertContains( 'test-status', ReportsController::get_order_statuses() );
-
- // Restore the actionable statuses.
- update_option( 'woocommerce_actionable_order_statuses', $actionable_statuses );
}
/**
diff --git a/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/api/reports-export.php b/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/api/reports-export.php
index 1ef1c26df58..2ada0414f72 100644
--- a/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/api/reports-export.php
+++ b/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/api/reports-export.php
@@ -157,7 +157,6 @@ class WC_Admin_Tests_API_Reports_Export extends WC_REST_Unit_Test_Case {
$this->assertEquals( 100, $status['percent_complete'] );
$this->assertStringMatchesFormat( '%s/wp-admin/?action=woocommerce_admin_download_report_csv&filename=wc-taxes-report-export-%d', $status['download_url'] );
$this->assertStringMatchesFormat( '%s/wc-analytics/reports/taxes/export/%d/status', $status['_links']['self'][0]['href'] );
- remove_filter( 'wc_tax_enabled', '__return_true' );
}
/**
diff --git a/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/features/onboarding-tasks/task-list.php b/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/features/onboarding-tasks/task-list.php
index a7c8e931ae5..0aa491ec34d 100644
--- a/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/features/onboarding-tasks/task-list.php
+++ b/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/features/onboarding-tasks/task-list.php
@@ -433,7 +433,6 @@ class WC_Admin_Tests_OnboardingTasks_TaskList extends WC_Unit_Test_Case {
);
$list->hide();
$this->assertEquals( get_option( 'woocommerce_default_homepage_layout', null ), 'two_columns' );
- delete_option( 'woocommerce_default_homepage_layout' );
}
/**
@@ -447,6 +446,5 @@ class WC_Admin_Tests_OnboardingTasks_TaskList extends WC_Unit_Test_Case {
);
$list->possibly_track_completion();
$this->assertEquals( get_option( 'woocommerce_default_homepage_layout', null ), 'two_columns' );
- delete_option( 'woocommerce_default_homepage_layout' );
}
}
diff --git a/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/features/payment-gateway-suggestions/evaluate-suggestion.php b/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/features/payment-gateway-suggestions/evaluate-suggestion.php
index 14d5768cbeb..0be6b2efb63 100644
--- a/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/features/payment-gateway-suggestions/evaluate-suggestion.php
+++ b/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/features/payment-gateway-suggestions/evaluate-suggestion.php
@@ -148,8 +148,6 @@ class WC_Admin_Tests_PaymentGatewaySuggestions_EvaluateSuggestion extends WC_Uni
);
EvaluateSuggestion::evaluate( (object) $suggestion, array( 'source' => 'unit-tests' ) );
-
- remove_filter( 'woocommerce_admin_remote_specs_evaluator_should_log', '__return_true' );
}
/**
@@ -183,8 +181,6 @@ class WC_Admin_Tests_PaymentGatewaySuggestions_EvaluateSuggestion extends WC_Uni
$this->mock_logger_debug_calls();
EvaluateSuggestion::evaluate( (object) $suggestion, array( 'source' => 'unit-tests' ) );
-
- remove_filter( 'woocommerce_admin_remote_specs_evaluator_should_log', '__return_false' );
}
/**
@@ -228,8 +224,6 @@ class WC_Admin_Tests_PaymentGatewaySuggestions_EvaluateSuggestion extends WC_Uni
);
EvaluateSuggestion::evaluate( (object) $suggestion, array( 'source' => 'unit-tests' ) );
-
- remove_filter( 'woocommerce_admin_remote_specs_evaluator_should_log', '__return_true' );
}
/**
@@ -273,8 +267,6 @@ class WC_Admin_Tests_PaymentGatewaySuggestions_EvaluateSuggestion extends WC_Uni
);
EvaluateSuggestion::evaluate( (object) $suggestion, array( 'source' => 'unit-tests' ) );
-
- remove_filter( 'woocommerce_admin_remote_specs_evaluator_should_log', '__return_true' );
}
/**
@@ -318,8 +310,6 @@ class WC_Admin_Tests_PaymentGatewaySuggestions_EvaluateSuggestion extends WC_Uni
);
EvaluateSuggestion::evaluate( (object) $suggestion );
-
- remove_filter( 'woocommerce_admin_remote_specs_evaluator_should_log', '__return_true' );
}
/**
diff --git a/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/features/payment-gateway-suggestions/payment-gateway-suggestions.php b/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/features/payment-gateway-suggestions/payment-gateway-suggestions.php
index d088b227e82..37956240048 100644
--- a/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/features/payment-gateway-suggestions/payment-gateway-suggestions.php
+++ b/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/features/payment-gateway-suggestions/payment-gateway-suggestions.php
@@ -69,9 +69,6 @@ class WC_Admin_Tests_PaymentGatewaySuggestions_Init extends WC_Unit_Test_Case {
// Assert.
$defaults = DefaultPaymentGateways::get_all();
$this->assertEquals( $defaults, $specs );
-
- // Clean up.
- remove_all_filters( DataSourcePoller::FILTER_NAME );
}
/**
@@ -326,11 +323,6 @@ class WC_Admin_Tests_PaymentGatewaySuggestions_Init extends WC_Unit_Test_Case {
$this->assertEquals( $stored_specs_in_transient['en_US'], $default_specs );
$expires = (int) get_transient( '_transient_timeout_woocommerce_admin_' . PaymentGatewaySuggestionsDataSourcePoller::ID . '_specs' );
$this->assertTrue( ( $expires - time() ) <= 3 * HOUR_IN_SECONDS );
-
- // Clean up.
- remove_all_filters( PaymentGatewaySuggestionsDataSourcePoller::FILTER_NAME );
- remove_all_filters( 'pre_http_request' );
- remove_all_filters( 'woocommerce_admin_payment_gateway_suggestion_specs' );
}
/**
@@ -361,8 +353,5 @@ class WC_Admin_Tests_PaymentGatewaySuggestions_Init extends WC_Unit_Test_Case {
// Assert.
$this->assertEquals( 'yes', get_option( PaymentGatewaySuggestions::RECOMMENDED_PAYMENT_PLUGINS_DISMISS_OPTION ) );
-
- // Clean up.
- delete_option( PaymentGatewaySuggestions::RECOMMENDED_PAYMENT_PLUGINS_DISMISS_OPTION );
}
}
diff --git a/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/notes/class-wc-tests-note-traits.php b/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/notes/class-wc-tests-note-traits.php
index 7c747fb7cba..f7f11ca6c2d 100644
--- a/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/notes/class-wc-tests-note-traits.php
+++ b/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/notes/class-wc-tests-note-traits.php
@@ -42,7 +42,6 @@ class WC_Admin_Tests_NoteTraits extends WC_Unit_Test_Case {
add_filter( 'woocommerce_data_stores', '__return_empty_array' );
$this->expectException( NotesUnavailableException::class );
$callback();
- remove_filter( 'woocommerce_data_stores', '__return_empty_array' );
}
/**
@@ -54,7 +53,6 @@ class WC_Admin_Tests_NoteTraits extends WC_Unit_Test_Case {
public function test_no_exception_is_thrown_even_if_data_store_cannot_be_loaded( $callback ) {
add_filter( 'woocommerce_data_stores', '__return_empty_array' );
$callback();
- remove_filter( 'woocommerce_data_stores', '__return_empty_array' );
}
/**
diff --git a/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/notes/class-wc-tests-notes.php b/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/notes/class-wc-tests-notes.php
index d7f8e4f659c..8e3eea01e3d 100644
--- a/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/notes/class-wc-tests-notes.php
+++ b/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/notes/class-wc-tests-notes.php
@@ -29,7 +29,6 @@ class WC_Admin_Tests_Notes extends WC_Unit_Test_Case {
add_filter( 'woocommerce_data_stores', '__return_empty_array' );
$this->expectException( NotesUnavailableException::class );
Notes::load_data_store();
- remove_filter( 'woocommerce_data_stores', '__return_empty_array' );
}
}
diff --git a/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/remote-specs/rule-processors/option-rule-processor.php b/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/remote-specs/rule-processors/option-rule-processor.php
index 20f5dccad84..151de8e6006 100644
--- a/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/remote-specs/rule-processors/option-rule-processor.php
+++ b/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/remote-specs/rule-processors/option-rule-processor.php
@@ -86,7 +86,6 @@ class WC_Admin_Tests_RemoteSpecs_RuleProcessors_OptionRuleProcessor extends WC_U
$rule->value = 'not_included';
$result = $processor->process( $rule, null );
$this->assertEquals( false, $result );
- delete_option( 'array_contain_item' );
}
/**
@@ -115,7 +114,6 @@ class WC_Admin_Tests_RemoteSpecs_RuleProcessors_OptionRuleProcessor extends WC_U
$rule->value = 'not_included';
$result = $processor->process( $rule, null );
$this->assertEquals( false, $result );
- delete_option( 'string_contain_substring' );
}
/**
@@ -153,6 +151,5 @@ class WC_Admin_Tests_RemoteSpecs_RuleProcessors_OptionRuleProcessor extends WC_U
$rule->operation = '!contains';
$result = $processor->process( $rule, null );
$this->assertEquals( true, $result );
- delete_option( 'contain_item' );
}
}
diff --git a/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/wc-admin-helper.php b/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/wc-admin-helper.php
index 74b9b9e0341..162ee992a43 100644
--- a/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/wc-admin-helper.php
+++ b/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/wc-admin-helper.php
@@ -429,8 +429,6 @@ class WC_Admin_Tests_Admin_Helper extends WC_Unit_Test_Case {
$this->go_to( home_url( '/?post_type=product' ) );
$this->assertTrue( WCAdminHelper::is_current_page_store_page(), 'Failed to identify product archive as store page' );
-
- remove_filter( 'woocommerce_get_shop_page_id', '__return_false' );
}
/**
diff --git a/plugins/woocommerce/tests/php/includes/abstracts/class-wc-abstract-order-test.php b/plugins/woocommerce/tests/php/includes/abstracts/class-wc-abstract-order-test.php
index f32410fd931..f053293a9d3 100644
--- a/plugins/woocommerce/tests/php/includes/abstracts/class-wc-abstract-order-test.php
+++ b/plugins/woocommerce/tests/php/includes/abstracts/class-wc-abstract-order-test.php
@@ -264,21 +264,15 @@ class WC_Abstract_Order_Test extends WC_Unit_Test_Case {
* @phpstan-param class-string<WC_Abstract_Order> $order_class
*/
public function test_constructor_initializes_prices_include_tax( string $order_class, string $tax_mode, bool $expected ): void {
- $previous_tax_mode = get_option( 'woocommerce_prices_include_tax' );
-
- try {
- update_option( 'woocommerce_calc_taxes', 'yes' );
- update_option( 'woocommerce_prices_include_tax', $tax_mode );
- $sut = new $order_class();
+ update_option( 'woocommerce_calc_taxes', 'yes' );
+ update_option( 'woocommerce_prices_include_tax', $tax_mode );
+ $sut = new $order_class();
- $this->assertSame( $expected, $sut->get_prices_include_tax( 'edit' ) );
- $this->assertArrayNotHasKey( 'prices_include_tax', $sut->get_changes(), 'Initialization must not be a pending edit.' );
+ $this->assertSame( $expected, $sut->get_prices_include_tax( 'edit' ) );
+ $this->assertArrayNotHasKey( 'prices_include_tax', $sut->get_changes(), 'Initialization must not be a pending edit.' );
- update_option( 'woocommerce_prices_include_tax', 'yes' === $tax_mode ? 'no' : 'yes' );
- $this->assertSame( $expected, $sut->get_prices_include_tax( 'edit' ), 'The default must be captured at construction, not at read time.' );
- } finally {
- update_option( 'woocommerce_prices_include_tax', $previous_tax_mode );
- }
+ update_option( 'woocommerce_prices_include_tax', 'yes' === $tax_mode ? 'no' : 'yes' );
+ $this->assertSame( $expected, $sut->get_prices_include_tax( 'edit' ), 'The default must be captured at construction, not at read time.' );
}
/**
@@ -304,8 +298,7 @@ class WC_Abstract_Order_Test extends WC_Unit_Test_Case {
* @param bool $expected Expected persisted tax mode.
*/
public function test_prices_include_tax_persists_initial_value( string $tax_mode, ?bool $override, bool $expected ): void {
- $previous_tax_mode = get_option( 'woocommerce_prices_include_tax' );
- $sut = null;
+ $sut = null;
try {
update_option( 'woocommerce_calc_taxes', 'yes' );
@@ -324,7 +317,6 @@ class WC_Abstract_Order_Test extends WC_Unit_Test_Case {
if ( $sut ) {
$sut->delete( true );
}
- update_option( 'woocommerce_prices_include_tax', $previous_tax_mode );
}
}
@@ -351,9 +343,8 @@ class WC_Abstract_Order_Test extends WC_Unit_Test_Case {
* @param bool $expected Expected refund tax mode.
*/
public function test_refund_inherits_parent_prices_include_tax( string $tax_mode, ?bool $override, bool $expected ): void {
- $previous_tax_mode = get_option( 'woocommerce_prices_include_tax' );
- $order = null;
- $sut = null;
+ $order = null;
+ $sut = null;
// This persistence test must not leave email logs for subsequent logging tests.
add_filter( 'woocommerce_email_log_enabled', '__return_false' );
@@ -386,8 +377,6 @@ class WC_Abstract_Order_Test extends WC_Unit_Test_Case {
if ( $order ) {
$order->delete( true );
}
- remove_filter( 'woocommerce_email_log_enabled', '__return_false' );
- update_option( 'woocommerce_prices_include_tax', $previous_tax_mode );
}
}
@@ -882,18 +871,14 @@ class WC_Abstract_Order_Test extends WC_Unit_Test_Case {
2
);
- try {
- $result = $order->remove_coupon( $coupon_code );
-
- $this->assertTrue( $result );
- $this->assertTrue( $hook_fired, 'woocommerce_order_removed_coupon hook did not fire.' );
- $this->assertInstanceOf( WC_Coupon::class, $hook_coupon, 'First parameter should be a WC_Coupon instance.' );
- $this->assertEquals( $coupon->get_code(), $hook_coupon->get_code(), 'Hook coupon code should match.' );
- $this->assertSame( $order, $hook_order, 'Second parameter should be the same WC_Order instance.' );
- $this->assertCount( 0, $order->get_items( 'coupon' ) );
- } finally {
- remove_all_actions( 'woocommerce_order_removed_coupon' );
- }
+ $result = $order->remove_coupon( $coupon_code );
+
+ $this->assertTrue( $result );
+ $this->assertTrue( $hook_fired, 'woocommerce_order_removed_coupon hook did not fire.' );
+ $this->assertInstanceOf( WC_Coupon::class, $hook_coupon, 'First parameter should be a WC_Coupon instance.' );
+ $this->assertEquals( $coupon->get_code(), $hook_coupon->get_code(), 'Hook coupon code should match.' );
+ $this->assertSame( $order, $hook_order, 'Second parameter should be the same WC_Order instance.' );
+ $this->assertCount( 0, $order->get_items( 'coupon' ) );
}
/**
@@ -2590,30 +2575,25 @@ class WC_Abstract_Order_Test extends WC_Unit_Test_Case {
add_filter( 'woocommerce_order_data_store', $data_store_filter, PHP_INT_MAX );
add_action( 'woocommerce_removed_order_items', $removed_hook, 10, 2 );
- try {
- $reflection = new ReflectionProperty( WC_Data::class, 'data_store' );
- $reflection->setAccessible( true );
- $reflection->setValue( $order, new WC_Data_Store( 'order' ) );
+ $reflection = new ReflectionProperty( WC_Data::class, 'data_store' );
+ $reflection->setAccessible( true );
+ $reflection->setValue( $order, new WC_Data_Store( 'order' ) );
- $order->remove_order_items( $type );
+ $order->remove_order_items( $type );
- $this->assertSame( array( $type ), $custom_data_store->deleted_item_types, 'The custom delete_items() implementation should run synchronously with the requested type.' );
- $this->assertSame( array( $type ), $removed_item_types, 'The post-removal hook should run synchronously with the requested type.' );
- foreach ( $expected_deleted_ids as $item_id ) {
- $this->assertFalse( WC_Order_Factory::get_order_item( $item_id ), 'Items selected for removal should be deleted synchronously.' );
- }
- foreach ( $expected_retained_ids as $item_id ) {
- $this->assertInstanceOf( WC_Order_Item::class, WC_Order_Factory::get_order_item( $item_id ), 'Items of other types should be retained.' );
- }
+ $this->assertSame( array( $type ), $custom_data_store->deleted_item_types, 'The custom delete_items() implementation should run synchronously with the requested type.' );
+ $this->assertSame( array( $type ), $removed_item_types, 'The post-removal hook should run synchronously with the requested type.' );
+ foreach ( $expected_deleted_ids as $item_id ) {
+ $this->assertFalse( WC_Order_Factory::get_order_item( $item_id ), 'Items selected for removal should be deleted synchronously.' );
+ }
+ foreach ( $expected_retained_ids as $item_id ) {
+ $this->assertInstanceOf( WC_Order_Item::class, WC_Order_Factory::get_order_item( $item_id ), 'Items of other types should be retained.' );
+ }
- $order->save();
+ $order->save();
- $this->assertSame( array( $type ), $custom_data_store->deleted_item_types, 'Saving should not invoke the custom delete_items() implementation again.' );
- $this->assertSame( array( $type ), $removed_item_types, 'Saving should not fire the post-removal hook again.' );
- } finally {
- remove_filter( 'woocommerce_order_data_store', $data_store_filter, PHP_INT_MAX );
- remove_action( 'woocommerce_removed_order_items', $removed_hook, 10 );
- }
+ $this->assertSame( array( $type ), $custom_data_store->deleted_item_types, 'Saving should not invoke the custom delete_items() implementation again.' );
+ $this->assertSame( array( $type ), $removed_item_types, 'Saving should not fire the post-removal hook again.' );
}
/**
@@ -2840,31 +2820,26 @@ class WC_Abstract_Order_Test extends WC_Unit_Test_Case {
add_action( 'woocommerce_remove_order_items', $pre_callback, 10, 2 );
add_action( 'woocommerce_removed_order_items', $post_callback, 10, 2 );
- try {
- $order->remove_order_items( 'line_item' );
+ $order->remove_order_items( 'line_item' );
- $this->assertSame(
- $expected_log,
- $pre_calls,
- 'woocommerce_remove_order_items should fire once when removal is requested.'
- );
- $this->assertSame(
- array(),
- $post_calls,
- 'woocommerce_removed_order_items should not fire until the deferred DB delete runs in save().'
- );
+ $this->assertSame(
+ $expected_log,
+ $pre_calls,
+ 'woocommerce_remove_order_items should fire once when removal is requested.'
+ );
+ $this->assertSame(
+ array(),
+ $post_calls,
+ 'woocommerce_removed_order_items should not fire until the deferred DB delete runs in save().'
+ );
- $order->save();
+ $order->save();
- $this->assertSame(
- $expected_log,
- $post_calls,
- 'woocommerce_removed_order_items should fire once with the requested type after save() commits the delete.'
- );
- } finally {
- remove_action( 'woocommerce_remove_order_items', $pre_callback, 10 );
- remove_action( 'woocommerce_removed_order_items', $post_callback, 10 );
- }//end try
+ $this->assertSame(
+ $expected_log,
+ $post_calls,
+ 'woocommerce_removed_order_items should fire once with the requested type after save() commits the delete.'
+ );
}
/**
@@ -2992,30 +2967,26 @@ class WC_Abstract_Order_Test extends WC_Unit_Test_Case {
add_filter( 'woocommerce_order_type_to_group', $adjust );
- try {
- $items_prop = $reflect->getProperty( 'items' );
- $items_prop->setAccessible( true );
- $items = $items_prop->getValue( $order );
+ $items_prop = $reflect->getProperty( 'items' );
+ $items_prop->setAccessible( true );
+ $items = $items_prop->getValue( $order );
- $items['custom_unit_test_lines'] = array( 'sentinel' );
- $items_prop->setValue( $order, $items );
+ $items['custom_unit_test_lines'] = array( 'sentinel' );
+ $items_prop->setValue( $order, $items );
- $order->remove_order_items();
+ $order->remove_order_items();
- $items_after = $items_prop->getValue( $order );
- $this->assertArrayHasKey(
- 'custom_unit_test_lines',
- $items_after,
- 'Filter-registered groups should be present as keys after the in-memory clear.'
- );
- $this->assertSame(
- array(),
- $items_after['custom_unit_test_lines'],
- 'Filter-registered group should be cleared to an empty array — not left with stale entries.'
- );
- } finally {
- remove_filter( 'woocommerce_order_type_to_group', $adjust );
- }
+ $items_after = $items_prop->getValue( $order );
+ $this->assertArrayHasKey(
+ 'custom_unit_test_lines',
+ $items_after,
+ 'Filter-registered groups should be present as keys after the in-memory clear.'
+ );
+ $this->assertSame(
+ array(),
+ $items_after['custom_unit_test_lines'],
+ 'Filter-registered group should be cleared to an empty array — not left with stale entries.'
+ );
}
/**
diff --git a/plugins/woocommerce/tests/php/includes/abstracts/class-wc-abstract-product-test.php b/plugins/woocommerce/tests/php/includes/abstracts/class-wc-abstract-product-test.php
index 70056844033..9727c0fec9a 100644
--- a/plugins/woocommerce/tests/php/includes/abstracts/class-wc-abstract-product-test.php
+++ b/plugins/woocommerce/tests/php/includes/abstracts/class-wc-abstract-product-test.php
@@ -423,7 +423,6 @@ class WC_Abstract_Product_Test extends WC_Unit_Test_Case {
* See https://github.com/woocommerce/woocommerce/issues/41676 for more details.
*/
public function test_validate_props_respects_non_default_no_stock_threshold_for_float_stock_quantity() {
- $previous_threshold = get_option( 'woocommerce_notify_no_stock_amount' );
update_option( 'woocommerce_notify_no_stock_amount', 5 );
remove_filter( 'woocommerce_stock_amount', 'intval' );
add_filter( 'woocommerce_stock_amount', 'floatval' );
@@ -450,7 +449,6 @@ class WC_Abstract_Product_Test extends WC_Unit_Test_Case {
remove_filter( 'woocommerce_stock_amount', 'floatval' );
add_filter( 'woocommerce_stock_amount', 'intval' );
- update_option( 'woocommerce_notify_no_stock_amount', $previous_threshold );
}
/**
@@ -460,7 +458,6 @@ class WC_Abstract_Product_Test extends WC_Unit_Test_Case {
* and stay in stock. With abs(), the threshold is compared by magnitude, so -5 behaves like 5.
*/
public function test_validate_props_treats_negative_no_stock_threshold_by_magnitude() {
- $previous_threshold = get_option( 'woocommerce_notify_no_stock_amount' );
update_option( 'woocommerce_notify_no_stock_amount', -5 );
remove_filter( 'woocommerce_stock_amount', 'intval' );
add_filter( 'woocommerce_stock_amount', 'floatval' );
@@ -487,7 +484,6 @@ class WC_Abstract_Product_Test extends WC_Unit_Test_Case {
remove_filter( 'woocommerce_stock_amount', 'floatval' );
add_filter( 'woocommerce_stock_amount', 'intval' );
- update_option( 'woocommerce_notify_no_stock_amount', $previous_threshold );
}
/**
diff --git a/plugins/woocommerce/tests/php/includes/admin/class-wc-admin-dashboard-setup-test.php b/plugins/woocommerce/tests/php/includes/admin/class-wc-admin-dashboard-setup-test.php
index 902bcfd78b7..f49843338a2 100644
--- a/plugins/woocommerce/tests/php/includes/admin/class-wc-admin-dashboard-setup-test.php
+++ b/plugins/woocommerce/tests/php/includes/admin/class-wc-admin-dashboard-setup-test.php
@@ -436,8 +436,6 @@ class WC_Admin_Dashboard_Setup_Test extends WC_Unit_Test_Case {
// Should redirect to setup wizard when profiler is not completed.
$this->assertStringContainsString( 'path=/setup-wizard', $button_link );
}
-
- delete_option( 'woocommerce_onboarding_profile' );
}
/**
@@ -458,8 +456,6 @@ class WC_Admin_Dashboard_Setup_Test extends WC_Unit_Test_Case {
// Should redirect to setup wizard when profiler is not completed.
$this->assertStringContainsString( 'path=/setup-wizard', $button_link );
}
-
- delete_option( 'woocommerce_onboarding_profile' );
}
/**
@@ -482,8 +478,6 @@ class WC_Admin_Dashboard_Setup_Test extends WC_Unit_Test_Case {
// Should contain the task ID or actionUrl.
$this->assertMatchesRegularExpression( '/(task=|path=)/', $button_link );
}
-
- delete_option( 'woocommerce_onboarding_profile' );
}
/**
@@ -506,8 +500,6 @@ class WC_Admin_Dashboard_Setup_Test extends WC_Unit_Test_Case {
// Should contain the task ID or actionUrl.
$this->assertMatchesRegularExpression( '/(task=|path=)/', $button_link );
}
-
- delete_option( 'woocommerce_onboarding_profile' );
}
/**
diff --git a/plugins/woocommerce/tests/php/includes/admin/class-wc-admin-dashboard-test.php b/plugins/woocommerce/tests/php/includes/admin/class-wc-admin-dashboard-test.php
index 40f51829556..d620dac40b7 100644
--- a/plugins/woocommerce/tests/php/includes/admin/class-wc-admin-dashboard-test.php
+++ b/plugins/woocommerce/tests/php/includes/admin/class-wc-admin-dashboard-test.php
@@ -455,7 +455,6 @@ class WC_Admin_Dashboard_Test extends WC_Unit_Test_Case {
}
add_filter( 'query', array( $this, '_create_temporary_tables' ) );
add_filter( 'query', array( $this, '_drop_temporary_tables' ) );
- remove_filter( 'wc_allow_changing_orders_storage_while_sync_is_pending', '__return_true' );
}
}
diff --git a/plugins/woocommerce/tests/php/includes/admin/class-wc-admin-duplicate-product-test.php b/plugins/woocommerce/tests/php/includes/admin/class-wc-admin-duplicate-product-test.php
index c0eae335222..1990b213d12 100644
--- a/plugins/woocommerce/tests/php/includes/admin/class-wc-admin-duplicate-product-test.php
+++ b/plugins/woocommerce/tests/php/includes/admin/class-wc-admin-duplicate-product-test.php
@@ -107,8 +107,6 @@ class WC_Admin_Duplicate_Product_Test extends WC_Unit_Test_Case {
$fourth_duplicate = ( new WC_Admin_Duplicate_Product() )->product_duplicate( $product );
$this->assertEquals( 'woo-cap-8', $fourth_duplicate->get_sku() );
$this->assertNotEquals( $product->get_id(), $fourth_duplicate->get_id() );
-
- remove_filter( 'wc_product_has_unique_sku', array( $this, 'dont_allow_skus_with_numbers_lower_than_8' ) );
}
/**
diff --git a/plugins/woocommerce/tests/php/includes/admin/class-wc-admin-settings-test.php b/plugins/woocommerce/tests/php/includes/admin/class-wc-admin-settings-test.php
index 04aefe1840e..5230a8b9e06 100644
--- a/plugins/woocommerce/tests/php/includes/admin/class-wc-admin-settings-test.php
+++ b/plugins/woocommerce/tests/php/includes/admin/class-wc-admin-settings-test.php
@@ -262,14 +262,10 @@ class WC_Admin_Settings_Test extends WC_Unit_Test_Case {
};
add_filter( 'wp_redirect', $intercept_redirect );
- try {
- $this->expectException( RuntimeException::class );
- $this->expectExceptionMessage( 'wp_redirect intercepted.' );
+ $this->expectException( RuntimeException::class );
+ $this->expectExceptionMessage( 'wp_redirect intercepted.' );
- WC_Admin_Settings::save();
- } finally {
- remove_filter( 'wp_redirect', $intercept_redirect );
- }
+ WC_Admin_Settings::save();
}
/**
diff --git a/plugins/woocommerce/tests/php/includes/admin/class-wc-admin-test.php b/plugins/woocommerce/tests/php/includes/admin/class-wc-admin-test.php
index de7e73ae38c..f4f72f3e7e7 100644
--- a/plugins/woocommerce/tests/php/includes/admin/class-wc-admin-test.php
+++ b/plugins/woocommerce/tests/php/includes/admin/class-wc-admin-test.php
@@ -213,12 +213,8 @@ class WC_Admin_Test extends WC_Unit_Test_Case {
};
add_filter( 'woocommerce_disable_admin_bar', $callback );
- try {
- $this->assertSame( null, $this->invoke_prevent_admin_access( $customer_id, '/var/www/html/wp-admin/index.php' ), 'The disable-admin-bar filter should suppress the customer redirect.' );
- $this->assertSame( true, $received, 'The disable-admin-bar filter should receive its default true value.' );
- } finally {
- remove_filter( 'woocommerce_disable_admin_bar', $callback );
- }
+ $this->assertSame( null, $this->invoke_prevent_admin_access( $customer_id, '/var/www/html/wp-admin/index.php' ), 'The disable-admin-bar filter should suppress the customer redirect.' );
+ $this->assertSame( true, $received, 'The disable-admin-bar filter should receive its default true value.' );
}
/**
@@ -233,12 +229,8 @@ class WC_Admin_Test extends WC_Unit_Test_Case {
};
add_filter( 'woocommerce_prevent_admin_access', $callback );
- try {
- $this->assertSame( null, $this->invoke_prevent_admin_access( $customer_id, '/var/www/html/wp-admin/index.php' ), 'The prevent-admin-access filter should suppress the computed customer denial.' );
- $this->assertSame( true, $received, 'The prevent-admin-access filter should receive the computed customer denial.' );
- } finally {
- remove_filter( 'woocommerce_prevent_admin_access', $callback );
- }
+ $this->assertSame( null, $this->invoke_prevent_admin_access( $customer_id, '/var/www/html/wp-admin/index.php' ), 'The prevent-admin-access filter should suppress the computed customer denial.' );
+ $this->assertSame( true, $received, 'The prevent-admin-access filter should receive the computed customer denial.' );
}
/**
@@ -253,12 +245,8 @@ class WC_Admin_Test extends WC_Unit_Test_Case {
};
add_filter( 'woocommerce_prevent_admin_access', $callback );
- try {
- $this->assertSame( get_permalink( $this->myaccount_page_id ), $this->invoke_prevent_admin_access( $customer_id, '/var/www/html/wp-admin/admin-ajax.php' ), 'The prevent-admin-access filter should force an exact My Account redirect from an exempt request.' );
- $this->assertSame( false, $received, 'The prevent-admin-access filter should receive false for an exempt request.' );
- } finally {
- remove_filter( 'woocommerce_prevent_admin_access', $callback );
- }
+ $this->assertSame( get_permalink( $this->myaccount_page_id ), $this->invoke_prevent_admin_access( $customer_id, '/var/www/html/wp-admin/admin-ajax.php' ), 'The prevent-admin-access filter should force an exact My Account redirect from an exempt request.' );
+ $this->assertSame( false, $received, 'The prevent-admin-access filter should receive false for an exempt request.' );
}
/**
diff --git a/plugins/woocommerce/tests/php/includes/admin/helper/class-wc-helper-test.php b/plugins/woocommerce/tests/php/includes/admin/helper/class-wc-helper-test.php
index 5f1e95a5113..97efc663322 100644
--- a/plugins/woocommerce/tests/php/includes/admin/helper/class-wc-helper-test.php
+++ b/plugins/woocommerce/tests/php/includes/admin/helper/class-wc-helper-test.php
@@ -1531,8 +1531,6 @@ class WC_Helper_Test extends \WC_Unit_Test_Case {
} catch ( WPDieException $e ) {
$this->assertIsArray( $access_token_body, 'The access token request should have been sent' );
$this->assertSame( $expected, $access_token_body['funnel_id'] ?? null );
- } finally {
- remove_filter( 'pre_http_request', $http_mock, 10 );
}
}
}
diff --git a/plugins/woocommerce/tests/php/includes/admin/helper/class-wc-helper-updater-test.php b/plugins/woocommerce/tests/php/includes/admin/helper/class-wc-helper-updater-test.php
index 731710c0666..3616505faeb 100644
--- a/plugins/woocommerce/tests/php/includes/admin/helper/class-wc-helper-updater-test.php
+++ b/plugins/woocommerce/tests/php/includes/admin/helper/class-wc-helper-updater-test.php
@@ -2674,11 +2674,7 @@ class WC_Helper_Updater_Test extends WC_Unit_Test_Case {
};
add_filter( 'pre_http_request', $fail );
- try {
- $this->assertNull( WC_Helper_Updater::get_plugins_without_subscription( false ), 'Without the list the answer is unknown.' );
- } finally {
- remove_filter( 'pre_http_request', $fail );
- }
+ $this->assertNull( WC_Helper_Updater::get_plugins_without_subscription( false ), 'Without the list the answer is unknown.' );
}
/**
diff --git a/plugins/woocommerce/tests/php/includes/admin/importers/class-wc-product-csv-importer-controller-test.php b/plugins/woocommerce/tests/php/includes/admin/importers/class-wc-product-csv-importer-controller-test.php
index 1d46d85cd0e..ad903ba6428 100644
--- a/plugins/woocommerce/tests/php/includes/admin/importers/class-wc-product-csv-importer-controller-test.php
+++ b/plugins/woocommerce/tests/php/includes/admin/importers/class-wc-product-csv-importer-controller-test.php
@@ -544,24 +544,20 @@ class WC_Product_CSV_Importer_Controller_Test extends WC_Unit_Test_Case {
public function test_resumed_request_keeps_the_markers_of_the_run_in_progress(): void {
add_filter( 'woocommerce_product_import_batch_size', array( $this, 'return_one' ) );
- try {
- $response = $this->dispatch_import_request( '0' );
+ $response = $this->dispatch_import_request( '0' );
- // A batch size of one leaves the second row for a resumed request.
- $this->assertIsNumeric( $response['data']['position'] );
+ // A batch size of one leaves the second row for a resumed request.
+ $this->assertIsNumeric( $response['data']['position'] );
- $parent_id = wc_get_product_id_by_sku( 'marker-parent' );
- $this->assertSame( 1, $response['data']['imported'] );
- $this->assertSame( '4242', get_post_meta( $parent_id, '_original_id', true ) );
+ $parent_id = wc_get_product_id_by_sku( 'marker-parent' );
+ $this->assertSame( 1, $response['data']['imported'] );
+ $this->assertSame( '4242', get_post_meta( $parent_id, '_original_id', true ) );
- $response = $this->dispatch_import_request( (string) $response['data']['position'] );
- $variation_id = wc_get_product_id_by_sku( 'marker-variation' );
+ $response = $this->dispatch_import_request( (string) $response['data']['position'] );
+ $variation_id = wc_get_product_id_by_sku( 'marker-variation' );
- $this->assertSame( 1, $response['data']['imported_variations'] );
- $this->assertSame( $parent_id, wp_get_post_parent_id( $variation_id ) );
- } finally {
- remove_filter( 'woocommerce_product_import_batch_size', array( $this, 'return_one' ) );
- }
+ $this->assertSame( 1, $response['data']['imported_variations'] );
+ $this->assertSame( $parent_id, wp_get_post_parent_id( $variation_id ) );
}
/**
diff --git a/plugins/woocommerce/tests/php/includes/admin/list-tables/class-wc-admin-list-table-products-test.php b/plugins/woocommerce/tests/php/includes/admin/list-tables/class-wc-admin-list-table-products-test.php
index f6378f88e96..94c67aeb568 100644
--- a/plugins/woocommerce/tests/php/includes/admin/list-tables/class-wc-admin-list-table-products-test.php
+++ b/plugins/woocommerce/tests/php/includes/admin/list-tables/class-wc-admin-list-table-products-test.php
@@ -218,30 +218,26 @@ class WC_Admin_List_Table_Products_Test extends WC_Unit_Test_Case {
};
add_filter( 'posts_clauses', $capture_orderby, PHP_INT_MAX );
- try {
- $this->get_search_results( $search_phrase );
- $this->assertStringContainsString( 'CASE WHEN', (string) $captured_orderby, 'A default-ordered search should rank title matches first.' );
- $this->assertStringContainsString( 'post_title LIKE', (string) $captured_orderby, 'The relevance clause should match against product titles.' );
+ $this->get_search_results( $search_phrase );
+ $this->assertStringContainsString( 'CASE WHEN', (string) $captured_orderby, 'A default-ordered search should rank title matches first.' );
+ $this->assertStringContainsString( 'post_title LIKE', (string) $captured_orderby, 'The relevance clause should match against product titles.' );
- $captured_orderby = null;
- $this->get_search_results(
- $search_phrase,
- array(
- 'orderby' => 'title',
- 'order' => 'ASC',
- )
- );
- $this->assertStringNotContainsString( 'CASE WHEN', (string) $captured_orderby, 'An explicitly sorted search should keep the requested ordering untouched.' );
-
- // A stopword-only term falls back to ranking by the whole group, mirroring search_products().
- // \S* absorbs the LIKE wildcards around the term: at the posts_clauses stage they are still
- // dynamic wpdb placeholder-escape hashes, not %.
- $captured_orderby = null;
- $this->get_search_results( 'the' );
- $this->assertMatchesRegularExpression( "/CASE WHEN.+post_title LIKE '\\S*the\\S*'/", (string) $captured_orderby, 'A stopword-only search should rank by the raw search group.' );
- } finally {
- remove_filter( 'posts_clauses', $capture_orderby, PHP_INT_MAX );
- }
+ $captured_orderby = null;
+ $this->get_search_results(
+ $search_phrase,
+ array(
+ 'orderby' => 'title',
+ 'order' => 'ASC',
+ )
+ );
+ $this->assertStringNotContainsString( 'CASE WHEN', (string) $captured_orderby, 'An explicitly sorted search should keep the requested ordering untouched.' );
+
+ // A stopword-only term falls back to ranking by the whole group, mirroring search_products().
+ // \S* absorbs the LIKE wildcards around the term: at the posts_clauses stage they are still
+ // dynamic wpdb placeholder-escape hashes, not %.
+ $captured_orderby = null;
+ $this->get_search_results( 'the' );
+ $this->assertMatchesRegularExpression( "/CASE WHEN.+post_title LIKE '\\S*the\\S*'/", (string) $captured_orderby, 'A stopword-only search should rank by the raw search group.' );
}
/**
diff --git a/plugins/woocommerce/tests/php/includes/class-wc-ajax-test.php b/plugins/woocommerce/tests/php/includes/class-wc-ajax-test.php
index f7dbc8d971d..e9d1ae02b1c 100644
--- a/plugins/woocommerce/tests/php/includes/class-wc-ajax-test.php
+++ b/plugins/woocommerce/tests/php/includes/class-wc-ajax-test.php
@@ -2807,7 +2807,6 @@ class WC_AJAX_Test extends \WP_Ajax_UnitTestCase {
unset( $_POST['security'], $_POST['order_id'], $_POST['refund_amount'], $_POST['refunded_amount'], $_POST['refund_reason'], $_POST['line_item_qtys'], $_POST['line_item_totals'], $_POST['line_item_tax_totals'], $_POST['api_refund'] );
WC_Tax::_delete_tax_rate( $rate_id );
- update_option( 'woocommerce_calc_taxes', 'no' );
}
/**
diff --git a/plugins/woocommerce/tests/php/includes/class-wc-brands-test.php b/plugins/woocommerce/tests/php/includes/class-wc-brands-test.php
index 691cd095271..49cad31dba4 100644
--- a/plugins/woocommerce/tests/php/includes/class-wc-brands-test.php
+++ b/plugins/woocommerce/tests/php/includes/class-wc-brands-test.php
@@ -249,9 +249,6 @@ class WC_Brands_Test extends WC_Unit_Test_Case {
// Test that the count is cached correctly.
$cached_count = get_term_meta( $brand_term->term_id, 'product_count_product_brand', true );
$this->assertEquals( '0', $cached_count, 'Brand count should be cached as 0 when product is out of stock' );
-
- // Reset the setting.
- update_option( 'woocommerce_hide_out_of_stock_items', 'no' );
}
/**
@@ -302,9 +299,6 @@ class WC_Brands_Test extends WC_Unit_Test_Case {
// Test that the count is 1 (ignores out of stock setting in admin context).
$this->assertEquals( 1, $brand_term->count, 'Brand count should be 1 in admin context, ignoring out of stock setting' );
-
- // Reset the setting.
- update_option( 'woocommerce_hide_out_of_stock_items', 'no' );
}
/**
diff --git a/plugins/woocommerce/tests/php/includes/class-wc-breadcrumb-test.php b/plugins/woocommerce/tests/php/includes/class-wc-breadcrumb-test.php
index 5d06c12c45f..894d53c21d7 100644
--- a/plugins/woocommerce/tests/php/includes/class-wc-breadcrumb-test.php
+++ b/plugins/woocommerce/tests/php/includes/class-wc-breadcrumb-test.php
@@ -101,7 +101,6 @@ class WC_Breadcrumb_Test extends \WC_Unit_Test_Case {
$this->assertNotEquals( $breadcrumbs[1][0], $breadcrumbs[2][0] );
wp_delete_post( $my_account_page_id, true );
- delete_option( 'woocommerce_myaccount_page_id' );
}
/**
@@ -167,7 +166,6 @@ class WC_Breadcrumb_Test extends \WC_Unit_Test_Case {
$this->assertNotEquals( $breadcrumbs[1][0], $breadcrumbs[2][0] );
wp_delete_post( $my_account_page_id, true );
- delete_option( 'woocommerce_myaccount_page_id' );
}
/**
diff --git a/plugins/woocommerce/tests/php/includes/class-wc-cart-test.php b/plugins/woocommerce/tests/php/includes/class-wc-cart-test.php
index 9429152a211..8a225387eeb 100644
--- a/plugins/woocommerce/tests/php/includes/class-wc-cart-test.php
+++ b/plugins/woocommerce/tests/php/includes/class-wc-cart-test.php
@@ -1129,14 +1129,10 @@ class WC_Cart_Test extends \WC_Unit_Test_Case {
WC()->cart->add_to_cart( $product->get_id(), 1 );
WC()->customer->set_shipping_location( 'US', 'NY', '', '' );
- try {
- $this->assertSame( $expected, WC()->cart->show_shipping(), 'Shipping should only stay hidden while the shopper has a postcode field to fill in.' );
+ $this->assertSame( $expected, WC()->cart->show_shipping(), 'Shipping should only stay hidden while the shopper has a postcode field to fill in.' );
- WC()->customer->set_shipping_location( 'US', '', '', '' );
- $this->assertFalse( WC()->cart->show_shipping(), 'A removed postcode must not stop the state from being required.' );
- } finally {
- remove_filter( 'woocommerce_checkout_fields', $remove_billing_address );
- }
+ WC()->customer->set_shipping_location( 'US', '', '', '' );
+ $this->assertFalse( WC()->cart->show_shipping(), 'A removed postcode must not stop the state from being required.' );
}
/**
@@ -2231,8 +2227,6 @@ class WC_Cart_Test extends \WC_Unit_Test_Case {
$this->assertNull( WC()->session->get( 'shipping_for_package_0' ) );
$this->assertNull( WC()->session->get( 'shipping_for_package_1' ) );
$this->assertNull( WC()->session->get( 'chosen_shipping_methods' ) );
-
- remove_all_filters( 'woocommerce_cart_shipping_packages' );
}
/**
@@ -2272,8 +2266,6 @@ class WC_Cart_Test extends \WC_Unit_Test_Case {
$this->assertNull( WC()->session->get( 'shipping_for_package_0' ) );
$this->assertNull( WC()->session->get( 'shipping_for_package_1' ) );
$this->assertNull( WC()->session->get( 'chosen_shipping_methods' ) );
-
- remove_all_filters( 'woocommerce_cart_shipping_packages' );
}
/**
@@ -2311,8 +2303,6 @@ class WC_Cart_Test extends \WC_Unit_Test_Case {
$this->assertNotEmpty( WC()->session->get( 'shipping_for_package_0' ) );
$this->assertNotEmpty( WC()->session->get( 'shipping_for_package_1' ) );
$this->assertNotEmpty( WC()->session->get( 'chosen_shipping_methods' ) );
-
- remove_all_filters( 'woocommerce_cart_shipping_packages' );
}
/**
@@ -2348,8 +2338,6 @@ class WC_Cart_Test extends \WC_Unit_Test_Case {
$this->assertNull( WC()->session->get( 'shipping_for_package_0' ) );
$this->assertNull( WC()->session->get( 'shipping_for_package_1' ) );
$this->assertNull( WC()->session->get( 'chosen_shipping_methods' ) );
-
- remove_all_filters( 'woocommerce_cart_shipping_packages' );
}
/**
diff --git a/plugins/woocommerce/tests/php/includes/class-wc-checkout-test.php b/plugins/woocommerce/tests/php/includes/class-wc-checkout-test.php
index b2acc95753f..13415aba4bb 100644
--- a/plugins/woocommerce/tests/php/includes/class-wc-checkout-test.php
+++ b/plugins/woocommerce/tests/php/includes/class-wc-checkout-test.php
@@ -744,7 +744,6 @@ class WC_Checkout_Test extends \WC_Unit_Test_Case {
$expect_we_dont_ship_error ? 'Unfortunately, <strong>we do not ship to Japan</strong>. Please enter an alternative shipping address.' : '',
$errors->get_error_message( 'shipping' )
);
- remove_all_filters( 'woocommerce_countries_allowed_countries' );
}
/**
diff --git a/plugins/woocommerce/tests/php/includes/class-wc-coupon-test.php b/plugins/woocommerce/tests/php/includes/class-wc-coupon-test.php
index 34e2b309ce1..14381793061 100644
--- a/plugins/woocommerce/tests/php/includes/class-wc-coupon-test.php
+++ b/plugins/woocommerce/tests/php/includes/class-wc-coupon-test.php
@@ -542,21 +542,16 @@ class WC_Coupon_Tests extends WC_Unit_Test_Case {
* @testdox set_minimum_amount throws exception when a comma-decimal minimum exceeds existing maximum.
*/
public function test_set_minimum_amount_throws_when_comma_decimal_exceeds_maximum(): void {
- $original_decimal_separator = get_option( 'woocommerce_price_decimal_sep' );
update_option( 'woocommerce_price_decimal_sep', ',' );
+ $coupon = new WC_Coupon();
+ $coupon->set_maximum_amount( '100,00' );
+
try {
- $coupon = new WC_Coupon();
- $coupon->set_maximum_amount( '100,00' );
-
- try {
- $coupon->set_minimum_amount( '100,50' );
- $this->fail( 'Expected WC_Data_Exception was not thrown.' );
- } catch ( \WC_Data_Exception $e ) {
- $this->assertSame( 'coupon_invalid_minimum_amount', $e->getErrorCode() );
- }
- } finally {
- update_option( 'woocommerce_price_decimal_sep', $original_decimal_separator );
+ $coupon->set_minimum_amount( '100,50' );
+ $this->fail( 'Expected WC_Data_Exception was not thrown.' );
+ } catch ( \WC_Data_Exception $e ) {
+ $this->assertSame( 'coupon_invalid_minimum_amount', $e->getErrorCode() );
}
}
@@ -564,19 +559,14 @@ class WC_Coupon_Tests extends WC_Unit_Test_Case {
* @testdox set_maximum_amount succeeds and stores the normalized value when a comma-decimal maximum satisfies the existing minimum.
*/
public function test_set_maximum_amount_succeeds_when_comma_decimal_satisfies_minimum(): void {
- $original_decimal_separator = get_option( 'woocommerce_price_decimal_sep' );
update_option( 'woocommerce_price_decimal_sep', ',' );
- try {
- $coupon = new WC_Coupon();
- $coupon->set_minimum_amount( '100.50' );
+ $coupon = new WC_Coupon();
+ $coupon->set_minimum_amount( '100.50' );
- $coupon->set_maximum_amount( '100,75' );
+ $coupon->set_maximum_amount( '100,75' );
- $this->assertSame( '100.75', $coupon->get_maximum_amount() );
- } finally {
- update_option( 'woocommerce_price_decimal_sep', $original_decimal_separator );
- }
+ $this->assertSame( '100.75', $coupon->get_maximum_amount() );
}
// -------------------------------------------------------------------------
diff --git a/plugins/woocommerce/tests/php/includes/class-wc-discounts-tests.php b/plugins/woocommerce/tests/php/includes/class-wc-discounts-tests.php
index 1260763ca35..036fa923d43 100644
--- a/plugins/woocommerce/tests/php/includes/class-wc-discounts-tests.php
+++ b/plugins/woocommerce/tests/php/includes/class-wc-discounts-tests.php
@@ -283,7 +283,6 @@ class WC_Discounts_Tests extends WC_Unit_Test_Case {
$result = $discounts->is_coupon_valid( $valid_coupon );
$this->assertWPError( $result, 'Returning false from the filter should force rejection.' );
$this->assertStringContainsString( 'is not applicable to selected products', $result->get_error_message(), 'Forced rejection should surface the product_ids error.' );
- remove_filter( 'woocommerce_coupon_is_valid_for_product_ids', '__return_false' );
}
/**
@@ -336,7 +335,6 @@ class WC_Discounts_Tests extends WC_Unit_Test_Case {
$result = $discounts->is_coupon_valid( $valid_coupon );
$this->assertWPError( $result, 'Returning false from the filter should force rejection.' );
$this->assertStringContainsString( 'is not applicable to selected products', $result->get_error_message(), 'Forced rejection should surface the product_categories error.' );
- remove_filter( 'woocommerce_coupon_is_valid_for_product_categories', '__return_false' );
}
/**
@@ -381,7 +379,6 @@ class WC_Discounts_Tests extends WC_Unit_Test_Case {
$result = $discounts->is_coupon_valid( $valid_coupon );
$this->assertWPError( $result, 'Returning false from the filter should force rejection.' );
$this->assertStringContainsString( 'is not applicable to selected products', $result->get_error_message(), 'Forced rejection should surface the excluded_items error.' );
- remove_filter( 'woocommerce_coupon_is_valid_for_excluded_items', '__return_false' );
}
/**
@@ -437,7 +434,6 @@ class WC_Discounts_Tests extends WC_Unit_Test_Case {
$result = $discounts->is_coupon_valid( $valid_coupon );
$this->assertWPError( $result, 'Returning false from the filter should force rejection.' );
$this->assertStringContainsString( 'is not valid for sale items', $result->get_error_message(), 'Forced rejection should surface the sale_items error.' );
- remove_filter( 'woocommerce_coupon_is_valid_for_sale_items', '__return_false' );
}
/**
@@ -484,7 +480,6 @@ class WC_Discounts_Tests extends WC_Unit_Test_Case {
$this->assertWPError( $result, 'Returning false should reject even when no excluded product is in the cart.' );
$this->assertStringContainsString( 'is not applicable to selected products', $result->get_error_message(), 'With no matched products the generic message is used.' );
$this->assertStringNotContainsString( 'products: .', $result->get_error_message(), 'The rejection message should not contain an empty product list.' );
- remove_filter( 'woocommerce_coupon_is_valid_for_excluded_product_ids', '__return_false' );
}
/**
@@ -534,6 +529,5 @@ class WC_Discounts_Tests extends WC_Unit_Test_Case {
$result = $discounts->is_coupon_valid( $unmatched_coupon );
$this->assertWPError( $result, 'Returning false should reject even when no excluded category is in the cart.' );
$this->assertStringContainsString( 'is not applicable to selected products', $result->get_error_message(), 'With no matched categories the generic message is used.' );
- remove_filter( 'woocommerce_coupon_is_valid_for_excluded_product_categories', '__return_false' );
}
}
diff --git a/plugins/woocommerce/tests/php/includes/class-wc-emails-tests.php b/plugins/woocommerce/tests/php/includes/class-wc-emails-tests.php
index fa205784fb0..1a25941b8e2 100644
--- a/plugins/woocommerce/tests/php/includes/class-wc-emails-tests.php
+++ b/plugins/woocommerce/tests/php/includes/class-wc-emails-tests.php
@@ -82,8 +82,6 @@ class WC_Emails_Tests extends \WC_Unit_Test_Case {
$this->assertContains( $hook, $captured_actions, 'Pending to cancelled status changes should be part of the default transactional email action list.' );
$this->assertSame( 10, has_action( $hook, array( 'WC_Emails', 'send_transactional_email' ) ), 'Pending to cancelled status changes should dispatch transactional emails.' );
-
- remove_action( $hook, array( 'WC_Emails', 'send_transactional_email' ), 10 );
}
/**
@@ -233,8 +231,6 @@ class WC_Emails_Tests extends \WC_Unit_Test_Case {
$after = count( $mailer->mock_sent );
$this->assertSame( $before, $after, 'Backorder notification must not be sent when the setting is disabled.' );
-
- update_option( 'woocommerce_notify_backorder', 'yes' );
}
/**
diff --git a/plugins/woocommerce/tests/php/includes/class-wc-install-test.php b/plugins/woocommerce/tests/php/includes/class-wc-install-test.php
index ae302238a5e..fb589f58ba4 100644
--- a/plugins/woocommerce/tests/php/includes/class-wc-install-test.php
+++ b/plugins/woocommerce/tests/php/includes/class-wc-install-test.php
@@ -292,8 +292,6 @@ class WC_Install_Test extends \WC_Unit_Test_Case {
\WC_Install::maybe_set_store_id();
$existing_store_id = get_option( \WC_Install::STORE_ID_OPTION );
$this->assertSame( $store_id, $existing_store_id );
- // cleanup.
- delete_option( \WC_Install::STORE_ID_OPTION );
}
/**
@@ -370,13 +368,6 @@ class WC_Install_Test extends \WC_Unit_Test_Case {
$shop_id = 10;
WC_Install::is_new_install();
$this->assertFalse( $counted_posts, 'For established stores (version and shop ID both set), we do not need to count the number of existing products.' );
-
- // Cleanup.
- remove_filter( 'option_woocommerce_version', $supply_version );
- remove_filter( 'woocommerce_get_shop_page_id', $supply_shop_id );
- remove_filter( 'wp_count_posts', $supply_post_count );
- remove_filter( 'pre_option_woocommerce_coming_soon', $supply_coming_soon );
- remove_filter( 'pre_option_woocommerce_task_list_completed_lists', $supply_completed_lists );
}
/**
@@ -519,11 +510,6 @@ class WC_Install_Test extends \WC_Unit_Test_Case {
// Assert that the schema includes fulfillment_status index.
$this->assertStringContainsString( 'KEY fulfillment_status (fulfillment_status),', $schema, 'Schema should include fulfillment_status index for new installations.' );
-
- // Cleanup.
- remove_filter( 'option_woocommerce_version', $supply_version );
- remove_filter( 'woocommerce_get_shop_page_id', $supply_shop_id );
- remove_filter( 'pre_option_woocommerce_feature_fulfillments_enabled', $supply_feature_enabled );
}
/**
@@ -564,10 +550,6 @@ class WC_Install_Test extends \WC_Unit_Test_Case {
// Assert that the schema does NOT include fulfillment_status index.
$this->assertStringNotContainsString( 'KEY fulfillment_status (fulfillment_status),', $schema, 'Schema should NOT include fulfillment_status index for new installations without fulfillments feature enabled.' );
-
- // Cleanup.
- remove_filter( 'option_woocommerce_version', $supply_version );
- remove_filter( 'woocommerce_get_shop_page_id', $supply_shop_id );
}
/**
@@ -609,11 +591,6 @@ class WC_Install_Test extends \WC_Unit_Test_Case {
// Assert that the schema does NOT include fulfillment_status column.
$this->assertStringNotContainsString( 'fulfillment_status', $schema, 'Schema should NOT include fulfillment_status column for existing installations without the column.' );
-
- // Cleanup.
- remove_filter( 'option_woocommerce_version', $supply_version );
- remove_filter( 'woocommerce_get_shop_page_id', $supply_shop_id );
- remove_filter( 'pre_option_' . \Automattic\WooCommerce\Admin\API\Reports\Orders\Stats\DataStore::OPTION_ORDER_STATS_TABLE_HAS_COLUMN_ORDER_FULFILLMENT_STATUS, $supply_column_status );
}
/**
@@ -655,11 +632,6 @@ class WC_Install_Test extends \WC_Unit_Test_Case {
// Assert that the schema DOES include fulfillment_status column for consistency.
$this->assertStringContainsString( 'fulfillment_status', $schema, 'Schema should include fulfillment_status column for existing installations that already have the column.' );
-
- // Cleanup.
- remove_filter( 'option_woocommerce_version', $supply_version );
- remove_filter( 'woocommerce_get_shop_page_id', $supply_shop_id );
- remove_filter( 'pre_option_' . \Automattic\WooCommerce\Admin\API\Reports\Orders\Stats\DataStore::OPTION_ORDER_STATS_TABLE_HAS_COLUMN_ORDER_FULFILLMENT_STATUS, $supply_column_status );
}
/**
diff --git a/plugins/woocommerce/tests/php/includes/class-wc-post-data-test.php b/plugins/woocommerce/tests/php/includes/class-wc-post-data-test.php
index 00651c81def..7d4e500d0b7 100644
--- a/plugins/woocommerce/tests/php/includes/class-wc-post-data-test.php
+++ b/plugins/woocommerce/tests/php/includes/class-wc-post-data-test.php
@@ -305,7 +305,6 @@ class WC_Post_Data_Test extends \WC_Unit_Test_Case {
}
add_filter( 'query', array( $this, '_create_temporary_tables' ) );
add_filter( 'query', array( $this, '_drop_temporary_tables' ) );
- remove_filter( 'wc_allow_changing_orders_storage_while_sync_is_pending', '__return_true' );
}
}
diff --git a/plugins/woocommerce/tests/php/includes/class-wc-product-factory-test.php b/plugins/woocommerce/tests/php/includes/class-wc-product-factory-test.php
index c0be3427ce9..e0d363f89bd 100644
--- a/plugins/woocommerce/tests/php/includes/class-wc-product-factory-test.php
+++ b/plugins/woocommerce/tests/php/includes/class-wc-product-factory-test.php
@@ -48,14 +48,10 @@ class WC_Product_Factory_Test extends WC_Unit_Test_Case {
$variation_id = $parent->get_children()[0];
update_option( 'woocommerce_attribute_lookup_direct_updates', 'yes' );
- try {
- $this->assertInstanceOf( WC_Product_Variation::class, wc_get_product( $variation_id ) );
+ $this->assertInstanceOf( WC_Product_Variation::class, wc_get_product( $variation_id ) );
- $parent->delete( true );
+ $parent->delete( true );
- $this->assertFalse( wc_get_product( $variation_id ) );
- } finally {
- delete_option( 'woocommerce_attribute_lookup_direct_updates' );
- }
+ $this->assertFalse( wc_get_product( $variation_id ) );
}
}
diff --git a/plugins/woocommerce/tests/php/includes/class-wc-session-concurrency-test.php b/plugins/woocommerce/tests/php/includes/class-wc-session-concurrency-test.php
index f14e2db00cf..0ead557e513 100644
--- a/plugins/woocommerce/tests/php/includes/class-wc-session-concurrency-test.php
+++ b/plugins/woocommerce/tests/php/includes/class-wc-session-concurrency-test.php
@@ -163,7 +163,6 @@ class WC_Session_Concurrency_Test extends WC_Unit_Test_Case {
$this->assertArrayNotHasKey( $cookie_name, $_COOKIE, 'The unverifiable cookie should be removed from the request' );
$this->assertFalse( $handler->has_session(), 'An unverifiable cookie should not count as a session' );
} finally {
- remove_filter( 'woocommerce_set_cookie_enabled', '__return_false' );
unset( $_COOKIE[ $cookie_name ] );
}
}
@@ -191,7 +190,6 @@ class WC_Session_Concurrency_Test extends WC_Unit_Test_Case {
$this->assertArrayHasKey( $cookie_name, $_COOKIE, 'A verifiable cookie should stay in the request' );
$this->assertTrue( $handler->has_session(), 'A verifiable cookie should count as a session' );
} finally {
- remove_filter( 'woocommerce_set_cookie_enabled', '__return_false' );
unset( $_COOKIE[ $cookie_name ] );
}
}
@@ -213,7 +211,6 @@ class WC_Session_Concurrency_Test extends WC_Unit_Test_Case {
$this->assertArrayNotHasKey( $cookie_name, $_COOKIE, 'The malformed cookie should be removed from the request' );
$this->assertFalse( $handler->has_session(), 'A malformed cookie should not count as a session' );
} finally {
- remove_filter( 'woocommerce_set_cookie_enabled', '__return_false' );
unset( $_COOKIE[ $cookie_name ] );
}
}
diff --git a/plugins/woocommerce/tests/php/includes/class-wc-shipping-test.php b/plugins/woocommerce/tests/php/includes/class-wc-shipping-test.php
index 0648515a02d..fcd99aae0bb 100644
--- a/plugins/woocommerce/tests/php/includes/class-wc-shipping-test.php
+++ b/plugins/woocommerce/tests/php/includes/class-wc-shipping-test.php
@@ -74,8 +74,6 @@ class WC_Shipping_Test extends WC_Unit_Test_Case {
foreach ( $expected_rates as $rate ) {
$this->assertArrayHasKey( $rate, $result['rates'] );
}
-
- remove_action( 'woocommerce_shipping_methods', $shipping_methods_hook );
}
/**
@@ -210,9 +208,6 @@ class WC_Shipping_Test extends WC_Unit_Test_Case {
// Verify that rates are still returned.
$this->assertIsArray( $result );
$this->assertArrayHasKey( 'rates', $result );
-
- remove_filter( 'woocommerce_package_rates', $filter_callback, 10 );
- remove_action( 'woocommerce_shipping_methods', $shipping_methods_hook );
}
/**
@@ -240,8 +235,6 @@ class WC_Shipping_Test extends WC_Unit_Test_Case {
$this->sut->calculate_shipping_for_package( $package );
$this->assertSame( 1, $filter_calls );
-
- remove_filter( 'woocommerce_package_rates', $filter, 10 );
}
/**
@@ -268,8 +261,6 @@ class WC_Shipping_Test extends WC_Unit_Test_Case {
$this->sut->calculate_shipping_for_package( $package );
$this->assertSame( 2, $filter_calls );
-
- remove_filter( 'woocommerce_package_rates', $filter, 10 );
}
/**
@@ -292,8 +283,6 @@ class WC_Shipping_Test extends WC_Unit_Test_Case {
$this->sut->calculate_shipping_for_package( $package );
$this->assertSame( 2, $filter_calls );
-
- remove_filter( 'woocommerce_package_rates', $filter, 10 );
}
/**
@@ -321,9 +310,6 @@ class WC_Shipping_Test extends WC_Unit_Test_Case {
$this->sut->calculate_shipping_for_package( $package );
$this->assertSame( 1, $filter_calls );
-
- remove_filter( 'woocommerce_shipping_package_hash_ignored_fields', $ignored_fields_filter );
- remove_filter( 'woocommerce_package_rates', $filter, 10 );
}
/**
@@ -353,8 +339,6 @@ class WC_Shipping_Test extends WC_Unit_Test_Case {
$this->sut->calculate_shipping_for_package( $package );
$this->assertSame( $expected_calculations, $filter_calls );
-
- remove_filter( 'woocommerce_package_rates', $filter, 10 );
}
/**
@@ -383,9 +367,6 @@ class WC_Shipping_Test extends WC_Unit_Test_Case {
$this->sut->calculate_shipping_for_package( $package );
$this->assertSame( 1, $filter_calls );
-
- remove_filter( 'woocommerce_shipping_package_hash_ignored_fields', $ignored_fields_filter );
- remove_filter( 'woocommerce_package_rates', $filter, 10 );
}
/**
diff --git a/plugins/woocommerce/tests/php/includes/class-wc-shortcodes-test.php b/plugins/woocommerce/tests/php/includes/class-wc-shortcodes-test.php
index 92a37619d22..ed4d25b3134 100644
--- a/plugins/woocommerce/tests/php/includes/class-wc-shortcodes-test.php
+++ b/plugins/woocommerce/tests/php/includes/class-wc-shortcodes-test.php
@@ -220,8 +220,6 @@ class WC_Shortcodes_Test extends WC_Unit_Test_Case {
$this->enable_deprecation_notice();
$this->assertNotEmpty( $product_page );
-
- remove_filter( 'woocommerce_shortcode_product_page_invalid_statuses', '__return_empty_array' );
}
/**
@@ -374,8 +372,6 @@ class WC_Shortcodes_Test extends WC_Unit_Test_Case {
);
$this->assertEmpty( $product_page );
-
- remove_filter( 'woocommerce_shortcode_product_page_force_rendering', '__return_null' );
}
/**
@@ -408,8 +404,6 @@ class WC_Shortcodes_Test extends WC_Unit_Test_Case {
);
$this->assertEmpty( $product_page );
-
- remove_filter( 'woocommerce_shortcode_product_page_force_rendering', '__return_false' );
}
/**
diff --git a/plugins/woocommerce/tests/php/includes/class-wc-tax-test.php b/plugins/woocommerce/tests/php/includes/class-wc-tax-test.php
index 6a451b0f40b..ecb785c3974 100644
--- a/plugins/woocommerce/tests/php/includes/class-wc-tax-test.php
+++ b/plugins/woocommerce/tests/php/includes/class-wc-tax-test.php
@@ -735,8 +735,6 @@ class WC_Tax_Test extends WC_Unit_Test_Case {
$expected_net = 10.00 / 1.20;
$net = 10.00 - array_sum( $taxes_inclusive );
$this->assertEqualsWithDelta( $expected_net, $net, 0.01, 'Net cost should equal gross divided by (1 + rate)' );
-
- remove_filter( 'woocommerce_shipping_prices_include_tax', '__return_true' );
}
/**
@@ -774,7 +772,6 @@ class WC_Tax_Test extends WC_Unit_Test_Case {
add_filter( 'woocommerce_shipping_prices_include_tax', '__return_true' );
$taxes_inclusive = WC_Tax::calc_shipping_tax( 10.00, $tax_rates );
$this->assertEquals( 0.00, array_sum( $taxes_inclusive ), 'Zero tax: inclusive should be 0' );
- remove_filter( 'woocommerce_shipping_prices_include_tax', '__return_true' );
}
/**
@@ -787,7 +784,6 @@ class WC_Tax_Test extends WC_Unit_Test_Case {
add_filter( 'woocommerce_shipping_prices_include_tax', '__return_true' );
$taxes = WC_Tax::calc_shipping_tax( 10.00, array() );
$this->assertEmpty( $taxes, 'No tax rates with filter should return empty array' );
- remove_filter( 'woocommerce_shipping_prices_include_tax', '__return_true' );
}
/**
@@ -838,8 +834,6 @@ class WC_Tax_Test extends WC_Unit_Test_Case {
$expected_tax = 15.00 - ( 15.00 / 1.10 );
$this->assertEqualsWithDelta( $expected_tax, array_sum( $taxes_with_filter ), 0.01, 'Filter return value should be used for inclusive calculation' );
-
- remove_all_filters( 'woocommerce_shipping_prices_include_tax' );
}
/**
@@ -925,7 +919,5 @@ class WC_Tax_Test extends WC_Unit_Test_Case {
$this->assertEqualsWithDelta( 2.00, $total_tax, 0.02, 'Tax taken from 12.00 should be about 2.00' );
$this->assertEqualsWithDelta( 10.00, $net_cost, 0.02, 'Net cost should be 10.00' );
-
- remove_filter( 'woocommerce_shipping_prices_include_tax', '__return_true' );
}
}
diff --git a/plugins/woocommerce/tests/php/includes/class-wc-tracker-test.php b/plugins/woocommerce/tests/php/includes/class-wc-tracker-test.php
index 92d2796cd13..02f9dc6441e 100644
--- a/plugins/woocommerce/tests/php/includes/class-wc-tracker-test.php
+++ b/plugins/woocommerce/tests/php/includes/class-wc-tracker-test.php
@@ -780,7 +780,6 @@ class WC_Tracker_Test extends \WC_Unit_Test_Case {
$tracking_data = WC_Tracker::get_tracking_data();
$this->assertArrayHasKey( 'store_id', $tracking_data );
$this->assertEquals( '12345', $tracking_data['store_id'] );
- delete_option( \WC_Install::STORE_ID_OPTION );
}
/**
@@ -792,7 +791,6 @@ class WC_Tracker_Test extends \WC_Unit_Test_Case {
$tracking_data = WC_Tracker::get_tracking_data();
$this->assertArrayHasKey( 'admin_install_timestamp', $tracking_data['settings'] );
$this->assertEquals( $tracking_data['settings']['admin_install_timestamp'], $time );
- delete_option( 'woocommerce_admin_install_timestamp' );
}
/**
@@ -806,8 +804,6 @@ class WC_Tracker_Test extends \WC_Unit_Test_Case {
* @testDox Test woocommerce_allow_tracking related data is included in tracking snapshot.
*/
public function test_tracking_data_woocommerce_allow_tracking() {
- $current_woocommerce_allow_tracking = get_option( 'woocommerce_allow_tracking', 'no' );
-
// Clear everything.
update_option( 'woocommerce_allow_tracking', 'no' );
delete_option( 'woocommerce_allow_tracking_last_modified' );
@@ -848,11 +844,6 @@ class WC_Tracker_Test extends \WC_Unit_Test_Case {
$this->assertEquals( $tracking_data['woocommerce_allow_tracking'], 'yes' );
$this->assertGreaterThanOrEqual( $before, (int) $tracking_data['woocommerce_allow_tracking_last_modified'] );
$this->assertEquals( $first_optin, (int) $tracking_data['woocommerce_allow_tracking_first_optin'] );
-
- // Restore everything as it was.
- update_option( 'woocommerce_allow_tracking', $current_woocommerce_allow_tracking );
- delete_option( 'woocommerce_allow_tracking_last_modified' );
- delete_option( 'woocommerce_allow_tracking_first_optin' );
}
/**
diff --git a/plugins/woocommerce/tests/php/includes/class-wc-tracks-test.php b/plugins/woocommerce/tests/php/includes/class-wc-tracks-test.php
index 0277a7c6547..bab0bab3bbc 100644
--- a/plugins/woocommerce/tests/php/includes/class-wc-tracks-test.php
+++ b/plugins/woocommerce/tests/php/includes/class-wc-tracks-test.php
@@ -224,7 +224,6 @@ class WC_Tracks_Test extends \WC_Unit_Test_Case {
);
$this->assertContains( 'store_id', array_keys( $properties ) );
$this->assertEquals( $store_id, $properties['store_id'] );
- delete_option( \WC_Install::STORE_ID_OPTION );
}
/**
@@ -278,9 +277,6 @@ class WC_Tracks_Test extends \WC_Unit_Test_Case {
// Third call should get fresh data with the new store ID.
$third_call = \WC_Tracks::get_blog_details( get_current_user_id() );
$this->assertEquals( $new_store_id, $third_call['store_id'] );
-
- // Clean up.
- delete_option( \WC_Install::STORE_ID_OPTION );
}
/**
diff --git a/plugins/woocommerce/tests/php/includes/class-wc-validation-test.php b/plugins/woocommerce/tests/php/includes/class-wc-validation-test.php
index 998aa2531c0..d3d8753769a 100644
--- a/plugins/woocommerce/tests/php/includes/class-wc-validation-test.php
+++ b/plugins/woocommerce/tests/php/includes/class-wc-validation-test.php
@@ -54,13 +54,9 @@ class WC_Validation_Test extends \WC_Unit_Test_Case {
};
add_filter( 'woocommerce_validate_phone', $callback, 10, 3 );
- try {
- $this->assertTrue( WC_Validation::is_phone( '+Û¹Û¸Û¹Û±ÛµÛ±Û±Û±Û²Û²Û³Û³', 'IR' ) );
- $this->assertTrue( WC_Validation::is_phone( 'Û°Û°Û¹Û¸Û¹Û±ÛµÛ±Û±Û±Û²Û²Û³Û³', 'IR' ) );
- $this->assertTrue( WC_Validation::is_phone( 'Û°Û¹Û±ÛµÛ±Û±Û±Û²Û²Û³Û³', 'IR' ) );
- } finally {
- remove_filter( 'woocommerce_validate_phone', $callback, 10 );
- }
+ $this->assertTrue( WC_Validation::is_phone( '+Û¹Û¸Û¹Û±ÛµÛ±Û±Û±Û²Û²Û³Û³', 'IR' ) );
+ $this->assertTrue( WC_Validation::is_phone( 'Û°Û°Û¹Û¸Û¹Û±ÛµÛ±Û±Û±Û²Û²Û³Û³', 'IR' ) );
+ $this->assertTrue( WC_Validation::is_phone( 'Û°Û¹Û±ÛµÛ±Û±Û±Û²Û²Û³Û³', 'IR' ) );
}
/**
@@ -143,11 +139,7 @@ class WC_Validation_Test extends \WC_Unit_Test_Case {
};
add_filter( 'woocommerce_validate_postcode', $callback, 10, 3 );
- try {
- $this->assertTrue( WC_Validation::is_postcode( 'ABCDE', 'US' ) );
- } finally {
- remove_filter( 'woocommerce_validate_postcode', $callback, 10 );
- }
+ $this->assertTrue( WC_Validation::is_postcode( 'ABCDE', 'US' ) );
}
/**
diff --git a/plugins/woocommerce/tests/php/includes/class-wc-webhook-tests.php b/plugins/woocommerce/tests/php/includes/class-wc-webhook-tests.php
index cc678657134..67c7a42306c 100644
--- a/plugins/woocommerce/tests/php/includes/class-wc-webhook-tests.php
+++ b/plugins/woocommerce/tests/php/includes/class-wc-webhook-tests.php
@@ -847,8 +847,6 @@ class WC_Webhook_Test extends WC_Unit_Test_Case {
wc_get_webhook( $webhook->get_id() )->get_failure_count(),
'Failure tracking must still run when delivery logging is disabled.'
);
-
- remove_filter( 'woocommerce_logger_log_message', $log_spy, 10 );
}
/**
diff --git a/plugins/woocommerce/tests/php/includes/data-stores/class-wc-order-data-store-cpt-test.php b/plugins/woocommerce/tests/php/includes/data-stores/class-wc-order-data-store-cpt-test.php
index 722cf958c45..f24edba1405 100644
--- a/plugins/woocommerce/tests/php/includes/data-stores/class-wc-order-data-store-cpt-test.php
+++ b/plugins/woocommerce/tests/php/includes/data-stores/class-wc-order-data-store-cpt-test.php
@@ -690,8 +690,6 @@ class WC_Order_Data_Store_CPT_Test extends WC_Unit_Test_Case {
}
$this->assertEquals( 0, $new_count );
-
- remove_action( 'woocommerce_new_order', $callback );
}
/**
@@ -733,8 +731,6 @@ class WC_Order_Data_Store_CPT_Test extends WC_Unit_Test_Case {
'Failed to trigger new order hook changing status: ' . $current_status . ' -> ' . $status
);
}
-
- remove_action( 'woocommerce_new_order', $callback );
}
/**
@@ -760,8 +756,6 @@ class WC_Order_Data_Store_CPT_Test extends WC_Unit_Test_Case {
$order_data_store_cpt->update( $order );
$this->assertEquals( 1, $new_count );
-
- remove_action( 'woocommerce_new_order', $callback );
}
/**
@@ -865,9 +859,7 @@ class WC_Order_Data_Store_CPT_Test extends WC_Unit_Test_Case {
* @testdox An order with missing tax-mode metadata uses the filtered setting without writing during the read.
*/
public function test_reading_order_without_prices_include_tax_metadata_uses_effective_setting(): void {
- $previous_tax_mode = get_option( 'woocommerce_prices_include_tax' );
- $previous_tax_enabled = get_option( 'woocommerce_calc_taxes' );
- $order = null;
+ $order = null;
try {
update_option( 'woocommerce_calc_taxes', 'yes' );
@@ -890,8 +882,6 @@ class WC_Order_Data_Store_CPT_Test extends WC_Unit_Test_Case {
if ( $order ) {
$order->delete( true );
}
- update_option( 'woocommerce_prices_include_tax', $previous_tax_mode );
- update_option( 'woocommerce_calc_taxes', $previous_tax_enabled );
}
}
@@ -904,9 +894,7 @@ class WC_Order_Data_Store_CPT_Test extends WC_Unit_Test_Case {
* @param string $post_status Post status when WooCommerce first loads the order.
*/
public function test_native_draft_loads_and_persists_store_defaults( string $tax_mode, bool $expected, string $post_status ): void {
- $previous_tax_mode = get_option( 'woocommerce_prices_include_tax' );
- $previous_currency = get_option( 'woocommerce_currency' );
- $order_id = 0;
+ $order_id = 0;
try {
update_option( 'woocommerce_calc_taxes', 'yes' );
@@ -949,8 +937,6 @@ class WC_Order_Data_Store_CPT_Test extends WC_Unit_Test_Case {
if ( $order_id ) {
wp_delete_post( $order_id, true );
}
- update_option( 'woocommerce_prices_include_tax', $previous_tax_mode );
- update_option( 'woocommerce_currency', $previous_currency );
}
}
@@ -977,8 +963,7 @@ class WC_Order_Data_Store_CPT_Test extends WC_Unit_Test_Case {
* @param string $status Order status.
*/
public function test_reading_order_preserves_persisted_tax_mode( string $tax_mode, bool $saved_value, string $status ): void {
- $previous_tax_mode = get_option( 'woocommerce_prices_include_tax' );
- $order = new WC_Order();
+ $order = new WC_Order();
try {
update_option( 'woocommerce_prices_include_tax', $tax_mode );
@@ -994,7 +979,6 @@ class WC_Order_Data_Store_CPT_Test extends WC_Unit_Test_Case {
if ( $order->get_id() ) {
$order->delete( true );
}
- update_option( 'woocommerce_prices_include_tax', $previous_tax_mode );
}
}
diff --git a/plugins/woocommerce/tests/php/includes/data-stores/class-wc-product-variable-data-store-cpt-test.php b/plugins/woocommerce/tests/php/includes/data-stores/class-wc-product-variable-data-store-cpt-test.php
index de488d89b2f..cc6ec683936 100644
--- a/plugins/woocommerce/tests/php/includes/data-stores/class-wc-product-variable-data-store-cpt-test.php
+++ b/plugins/woocommerce/tests/php/includes/data-stores/class-wc-product-variable-data-store-cpt-test.php
@@ -492,11 +492,6 @@ class WC_Product_Variable_Data_Store_CPT_Test extends WC_Unit_Test_Case {
// Clean up.
WC_Tax::_delete_tax_rate( $tax_id );
-
- remove_filter( 'wc_tax_enabled', '__return_true' );
- remove_filter( 'woocommerce_prices_include_tax', '__return_true' );
- remove_filter( 'pre_option_woocommerce_tax_display_shop', array( $this, '__return_incl' ) );
- remove_filter( 'pre_option_woocommerce_tax_display_cart', array( $this, '__return_incl' ) );
}
/**
@@ -618,10 +613,6 @@ class WC_Product_Variable_Data_Store_CPT_Test extends WC_Unit_Test_Case {
// Restore default state to avoid leaking into subsequent tests.
WC()->customer->set_is_vat_exempt( false );
-
- remove_filter( 'wc_tax_enabled', $tax_enabled ? '__return_true' : '__return_false' );
- remove_filter( 'woocommerce_product_is_taxable', $taxable_product ? '__return_true' : '__return_false' );
- remove_filter( 'woocommerce_matched_rates', $tax_has_rates ? array( $this, '__return_rates' ) : '__return_empty_array' );
}
/**
@@ -649,10 +640,6 @@ class WC_Product_Variable_Data_Store_CPT_Test extends WC_Unit_Test_Case {
// Restore default state to avoid leaking into other tests.
WC()->customer->set_is_vat_exempt( false );
-
- remove_filter( 'wc_tax_enabled', '__return_true' );
- remove_filter( 'woocommerce_product_is_taxable', '__return_true' );
- remove_filter( 'woocommerce_matched_rates', array( $this, '__return_rates' ) );
}
/**
@@ -694,11 +681,6 @@ class WC_Product_Variable_Data_Store_CPT_Test extends WC_Unit_Test_Case {
$this->assertSame( $expected, $extended_data_store->taxes_influence_price( $product ) );
$this->assertSame( $expected_default, $received_default, 'Filter callback should receive the default decision.' );
$this->assertSame( $product->get_id(), $received_product->get_id(), 'Filter callback should receive the product being evaluated.' );
-
- remove_filter( 'woocommerce_variable_product_taxes_influence_price', $filter_callback, 10 );
- remove_filter( 'wc_tax_enabled', '__return_true' );
- remove_filter( 'woocommerce_product_is_taxable', $taxable_product ? '__return_true' : '__return_false' );
- remove_filter( 'woocommerce_matched_rates', $tax_has_rates ? array( $this, '__return_rates' ) : '__return_empty_array' );
}
/**
@@ -728,10 +710,6 @@ class WC_Product_Variable_Data_Store_CPT_Test extends WC_Unit_Test_Case {
$expected_hashes = array( $extended_data_store->get_price_hash( $product, true ), $extended_data_store->get_price_hash( $product, false ) );
$actual_hashes = array_unique( $this->get_keys_for_json_encoded_transient( $transient_name ) );
$this->assertSame( $expected_hashes, $actual_hashes );
-
- remove_filter( 'wc_tax_enabled', '__return_true' );
- remove_filter( 'woocommerce_product_is_taxable', '__return_true' );
- remove_filter( 'woocommerce_matched_rates', array( $this, '__return_rates' ) );
}
/**
@@ -773,11 +751,6 @@ class WC_Product_Variable_Data_Store_CPT_Test extends WC_Unit_Test_Case {
$expected_hashes = array( $extended_data_store->get_price_hash( $product, true ), $extended_data_store->get_price_hash( $product, false ) );
$actual_hashes = array_unique( $this->get_keys_for_json_encoded_transient( $transient_name ) );
$this->assertSame( $expected_hashes, $actual_hashes );
-
- remove_all_filters( 'woocommerce_variation_prices_array' );
- remove_filter( 'wc_tax_enabled', '__return_true' );
- remove_filter( 'woocommerce_product_is_taxable', '__return_false' );
- remove_filter( 'woocommerce_matched_rates', array( $this, '__return_rates' ) );
}
/**
@@ -2119,12 +2092,6 @@ class WC_Product_Variable_Data_Store_CPT_Test extends WC_Unit_Test_Case {
$this->assertSame( $hashes_after_first_call, $hashes_after_second_call, 'Hashes must not change after the second call.' );
$this->assertSame( $aggregation_after_first, $aggregation_count, 'Second call must not trigger re-aggregation.' );
-
- remove_filter( 'woocommerce_variation_prices_price', $count_aggregation );
-
- remove_filter( 'wc_tax_enabled', '__return_true' );
- remove_filter( 'woocommerce_product_is_taxable', '__return_true' );
- remove_filter( 'woocommerce_matched_rates', array( $this, '__return_rates' ) );
}
/**
diff --git a/plugins/woocommerce/tests/php/includes/emails/class-wc-email-admin-payment-gateway-enabled-test.php b/plugins/woocommerce/tests/php/includes/emails/class-wc-email-admin-payment-gateway-enabled-test.php
index 929242576ba..507b27c7cd2 100644
--- a/plugins/woocommerce/tests/php/includes/emails/class-wc-email-admin-payment-gateway-enabled-test.php
+++ b/plugins/woocommerce/tests/php/includes/emails/class-wc-email-admin-payment-gateway-enabled-test.php
@@ -121,8 +121,6 @@ class WC_Email_Admin_Payment_Gateway_Enabled_Test extends WC_Unit_Test_Case {
$this->sut->trigger( $gateway );
$this->assertTrue( $email_sent, 'Email should be sent when trigger is called with a valid gateway' );
-
- remove_filter( 'wp_mail', $watcher );
}
/**
@@ -136,8 +134,6 @@ class WC_Email_Admin_Payment_Gateway_Enabled_Test extends WC_Unit_Test_Case {
$this->assertEquals( $gateway->get_method_title(), $this->sut->gateway_title );
$this->assertEquals( $gateway->get_method_title(), $this->sut->placeholders['{gateway_title}'] );
-
- remove_filter( 'wp_mail', '__return_empty_array' );
}
/**
@@ -150,8 +146,6 @@ class WC_Email_Admin_Payment_Gateway_Enabled_Test extends WC_Unit_Test_Case {
$this->sut->trigger( $gateway );
$this->assertStringContainsString( 'page=wc-settings&tab=checkout§ion=bacs', $this->sut->gateway_settings_url );
-
- remove_filter( 'wp_mail', '__return_empty_array' );
}
/**
@@ -192,8 +186,6 @@ class WC_Email_Admin_Payment_Gateway_Enabled_Test extends WC_Unit_Test_Case {
$this->assertStringContainsString( $gateway->get_method_title(), $subject );
$this->assertStringNotContainsString( '{gateway_title}', $subject );
-
- remove_filter( 'wp_mail', '__return_empty_array' );
}
/**
@@ -212,8 +204,6 @@ class WC_Email_Admin_Payment_Gateway_Enabled_Test extends WC_Unit_Test_Case {
$this->assertStringContainsString( 'extra@example.com', $recipient );
$this->assertStringContainsString( get_option( 'admin_email' ), $recipient );
-
- remove_filter( 'wc_payment_gateway_enabled_notification_email_addresses', $extra_watcher );
}
/**
diff --git a/plugins/woocommerce/tests/php/includes/emails/class-wc-email-customer-review-request-test.php b/plugins/woocommerce/tests/php/includes/emails/class-wc-email-customer-review-request-test.php
index 44b91f9896a..da17bcab0a5 100644
--- a/plugins/woocommerce/tests/php/includes/emails/class-wc-email-customer-review-request-test.php
+++ b/plugins/woocommerce/tests/php/includes/emails/class-wc-email-customer-review-request-test.php
@@ -126,8 +126,6 @@ class WC_Email_Customer_Review_Request_Test extends \WC_Unit_Test_Case {
add_filter( 'woocommerce_review_request_delay_seconds', $override );
$this->assertSame( 90, $this->sut->get_delay_seconds() );
-
- remove_filter( 'woocommerce_review_request_delay_seconds', $override );
}
/**
@@ -168,8 +166,6 @@ class WC_Email_Customer_Review_Request_Test extends \WC_Unit_Test_Case {
add_filter( 'woocommerce_review_order_url', $override );
$this->assertSame( 'https://example.test/custom', $this->sut->get_review_order_url() );
-
- remove_filter( 'woocommerce_review_order_url', $override );
}
/**
diff --git a/plugins/woocommerce/tests/php/includes/exporter/class-wc-product-csv-exporter-test.php b/plugins/woocommerce/tests/php/includes/exporter/class-wc-product-csv-exporter-test.php
index 5029849640e..1ba7e3eca8d 100644
--- a/plugins/woocommerce/tests/php/includes/exporter/class-wc-product-csv-exporter-test.php
+++ b/plugins/woocommerce/tests/php/includes/exporter/class-wc-product-csv-exporter-test.php
@@ -165,16 +165,12 @@ class WC_Product_CSV_Exporter_Test extends \WC_Unit_Test_Case {
add_filter( 'woocommerce_product_export_product_query_args', array( $this, 'set_export_product_query_args' ) );
- try {
- $exporter = new WC_Product_CSV_Exporter();
- $exporter->prepare_data_to_export();
- $data = $this->get_exported_data( $exporter );
+ $exporter = new WC_Product_CSV_Exporter();
+ $exporter->prepare_data_to_export();
+ $data = $this->get_exported_data( $exporter );
- foreach ( $data as $row ) {
- $this->assertEquals( -1, $row['published'] );
- }
- } finally {
- remove_filter( 'woocommerce_product_export_product_query_args', array( $this, 'set_export_product_query_args' ) );
+ foreach ( $data as $row ) {
+ $this->assertEquals( -1, $row['published'] );
}
}
@@ -190,17 +186,13 @@ class WC_Product_CSV_Exporter_Test extends \WC_Unit_Test_Case {
add_filter( 'woocommerce_product_export_product_query_args', array( $this, 'set_export_product_query_args' ) );
- try {
- $exporter = new WC_Product_CSV_Exporter();
- $exporter->prepare_data_to_export();
- $data = $this->get_exported_data( $exporter );
+ $exporter = new WC_Product_CSV_Exporter();
+ $exporter->prepare_data_to_export();
+ $data = $this->get_exported_data( $exporter );
- $this->assertNotEmpty( $data, 'Pending review product should be included in the export.' );
- foreach ( $data as $row ) {
- $this->assertEquals( 2, $row['published'], 'Pending review products should not export as draft (-1).' );
- }
- } finally {
- remove_filter( 'woocommerce_product_export_product_query_args', array( $this, 'set_export_product_query_args' ) );
+ $this->assertNotEmpty( $data, 'Pending review product should be included in the export.' );
+ foreach ( $data as $row ) {
+ $this->assertEquals( 2, $row['published'], 'Pending review products should not export as draft (-1).' );
}
}
diff --git a/plugins/woocommerce/tests/php/includes/importer/class-wc-product-csv-importer-test.php b/plugins/woocommerce/tests/php/includes/importer/class-wc-product-csv-importer-test.php
index 2b17d17fe2b..95dad044f4b 100644
--- a/plugins/woocommerce/tests/php/includes/importer/class-wc-product-csv-importer-test.php
+++ b/plugins/woocommerce/tests/php/includes/importer/class-wc-product-csv-importer-test.php
@@ -1836,8 +1836,6 @@ class WC_Product_CSV_Importer_Test extends \WC_Unit_Test_Case {
? (int) $inserted->get_error_data( 'term_exists' )
: $inserted['term_id'];
- // Preserve the previous option value so other tests reading it are unaffected.
- $previous_default_cat = get_option( 'default_product_cat' );
update_option( 'default_product_cat', $default_cat );
$imported_ids = array();
@@ -1879,7 +1877,6 @@ class WC_Product_CSV_Importer_Test extends \WC_Unit_Test_Case {
foreach ( $imported_ids as $id ) {
WC_Helper_Product::delete_product( $id );
}
- update_option( 'default_product_cat', $previous_default_cat );
}
}
diff --git a/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version3/class-wc-rest-order-refunds-computed-totals-test.php b/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version3/class-wc-rest-order-refunds-computed-totals-test.php
index 83d893edb51..5f089a34ceb 100644
--- a/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version3/class-wc-rest-order-refunds-computed-totals-test.php
+++ b/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version3/class-wc-rest-order-refunds-computed-totals-test.php
@@ -678,28 +678,24 @@ class WC_REST_Order_Refunds_Computed_Totals_Test extends WC_REST_Unit_Test_Case
public function test_zero_decimal_currency(): void {
add_filter( 'wc_get_price_decimals', '__return_zero' );
- try {
- $order = $this->create_order_with_product( 100.00, 1 );
- $item_id = $this->get_first_line_item_id( $order );
+ $order = $this->create_order_with_product( 100.00, 1 );
+ $item_id = $this->get_first_line_item_id( $order );
- $response = $this->do_create_request(
- $order->get_id(),
- array(
- 'compute_totals' => true,
- 'line_items' => array(
- array(
- 'id' => $item_id,
- 'quantity' => 1,
- ),
+ $response = $this->do_create_request(
+ $order->get_id(),
+ array(
+ 'compute_totals' => true,
+ 'line_items' => array(
+ array(
+ 'id' => $item_id,
+ 'quantity' => 1,
),
- )
- );
+ ),
+ )
+ );
- $this->assertEquals( 201, $response->get_status() );
- $this->assertEquals( '100', $response->get_data()['amount'] );
- } finally {
- remove_filter( 'wc_get_price_decimals', '__return_zero' );
- }
+ $this->assertEquals( 201, $response->get_status() );
+ $this->assertEquals( '100', $response->get_data()['amount'] );
}
/**
@@ -1232,72 +1228,67 @@ class WC_REST_Order_Refunds_Computed_Totals_Test extends WC_REST_Unit_Test_Case
* @testdox A full-line refund with higher-precision tax is accepted at currency precision.
*/
public function test_unflagged_high_precision_tax_full_refund(): void {
- $previous = get_option( 'woocommerce_tax_round_at_subtotal' );
update_option( 'woocommerce_tax_round_at_subtotal', 'yes' );
- try {
- $rate_id = $this->create_tax_rate( 8.333 );
- $order = $this->create_order_with_product_and_tax( 10.00, 1, $rate_id, 0.8333 );
- $item_id = $this->get_first_line_item_id( $order );
- $response = $this->do_create_request(
- $order->get_id(),
- array(
- 'amount' => '10.83',
- 'line_items' => array(
- array(
- 'id' => $item_id,
- 'refund_total' => 10,
- 'refund_tax' => array(
- array(
- 'id' => $rate_id,
- 'refund_total' => 0.8333,
- ),
+ $rate_id = $this->create_tax_rate( 8.333 );
+ $order = $this->create_order_with_product_and_tax( 10.00, 1, $rate_id, 0.8333 );
+ $item_id = $this->get_first_line_item_id( $order );
+ $response = $this->do_create_request(
+ $order->get_id(),
+ array(
+ 'amount' => '10.83',
+ 'line_items' => array(
+ array(
+ 'id' => $item_id,
+ 'refund_total' => 10,
+ 'refund_tax' => array(
+ array(
+ 'id' => $rate_id,
+ 'refund_total' => 0.8333,
),
),
),
- )
- );
- $this->assertSame( 201, $response->get_status() );
- $this->assertSame( '10.83', $response->get_data()['amount'] );
+ ),
+ )
+ );
+ $this->assertSame( 201, $response->get_status() );
+ $this->assertSame( '10.83', $response->get_data()['amount'] );
- $partial_order = $this->create_order_with_product_and_tax( 10.00, 1, $rate_id, 0.8333 );
- $partial_id = $this->get_first_line_item_id( $partial_order );
- $first = $this->do_create_request(
- $partial_order->get_id(),
- array(
- 'amount' => '5',
- 'line_items' => array(
- array(
- 'id' => $partial_id,
- 'refund_total' => 5,
- ),
+ $partial_order = $this->create_order_with_product_and_tax( 10.00, 1, $rate_id, 0.8333 );
+ $partial_id = $this->get_first_line_item_id( $partial_order );
+ $first = $this->do_create_request(
+ $partial_order->get_id(),
+ array(
+ 'amount' => '5',
+ 'line_items' => array(
+ array(
+ 'id' => $partial_id,
+ 'refund_total' => 5,
),
- )
- );
- $this->assertSame( 201, $first->get_status() );
+ ),
+ )
+ );
+ $this->assertSame( 201, $first->get_status() );
- $remaining = $this->do_create_request(
- $partial_order->get_id(),
- array(
- 'amount' => '5.83',
- 'line_items' => array(
- array(
- 'id' => $partial_id,
- 'refund_total' => 5,
- 'refund_tax' => array(
- array(
- 'id' => $rate_id,
- 'refund_total' => 0.8333,
- ),
+ $remaining = $this->do_create_request(
+ $partial_order->get_id(),
+ array(
+ 'amount' => '5.83',
+ 'line_items' => array(
+ array(
+ 'id' => $partial_id,
+ 'refund_total' => 5,
+ 'refund_tax' => array(
+ array(
+ 'id' => $rate_id,
+ 'refund_total' => 0.8333,
),
),
),
- )
- );
- $this->assertSame( 201, $remaining->get_status() );
- $this->assertCount( 2, wc_get_order( $partial_order->get_id() )->get_refunds() );
- } finally {
- update_option( 'woocommerce_tax_round_at_subtotal', $previous );
- }
+ ),
+ )
+ );
+ $this->assertSame( 201, $remaining->get_status() );
+ $this->assertCount( 2, wc_get_order( $partial_order->get_id() )->get_refunds() );
}
/**
diff --git a/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version3/class-wc-rest-order-refunds-preview-test.php b/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version3/class-wc-rest-order-refunds-preview-test.php
index 1af30d928f5..80ddba3547d 100644
--- a/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version3/class-wc-rest-order-refunds-preview-test.php
+++ b/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version3/class-wc-rest-order-refunds-preview-test.php
@@ -728,27 +728,23 @@ class WC_REST_Order_Refunds_Preview_Test extends WC_REST_Unit_Test_Case {
add_filter( 'wc_get_price_decimals', '__return_zero' );
- try {
- $response = $this->do_preview_request(
- $order->get_id(),
+ $response = $this->do_preview_request(
+ $order->get_id(),
+ array(
array(
- array(
- 'line_item_id' => $item_id,
- 'refund_total' => 55.4,
- ),
- )
- );
+ 'line_item_id' => $item_id,
+ 'refund_total' => 55.4,
+ ),
+ )
+ );
- $this->assertEquals( 200, $response->get_status() );
- $item = $response->get_data()['breakdown']['products']['items'][0];
+ $this->assertEquals( 200, $response->get_status() );
+ $item = $response->get_data()['breakdown']['products']['items'][0];
- // 55.4 rounds to 55 at 0dp; the 10% split gives whole-unit 50 net / 5 tax.
- $this->assertEquals( '55', $item['total'], 'Total should round to a whole unit.' );
- $this->assertEquals( '5', $item['tax'] );
- $this->assertEquals( '50', $item['subtotal'] );
- } finally {
- remove_filter( 'wc_get_price_decimals', '__return_zero' );
- }
+ // 55.4 rounds to 55 at 0dp; the 10% split gives whole-unit 50 net / 5 tax.
+ $this->assertEquals( '55', $item['total'], 'Total should round to a whole unit.' );
+ $this->assertEquals( '5', $item['tax'] );
+ $this->assertEquals( '50', $item['subtotal'] );
}
/**
@@ -760,25 +756,21 @@ class WC_REST_Order_Refunds_Preview_Test extends WC_REST_Unit_Test_Case {
};
add_filter( 'wc_get_price_decimals', $three_decimals );
- try {
- $order = $this->create_order_with_product( 10.555, 1 );
- $item_id = $this->get_first_line_item_id( $order );
+ $order = $this->create_order_with_product( 10.555, 1 );
+ $item_id = $this->get_first_line_item_id( $order );
- $response = $this->do_preview_request(
- $order->get_id(),
+ $response = $this->do_preview_request(
+ $order->get_id(),
+ array(
array(
- array(
- 'line_item_id' => $item_id,
- 'quantity' => 1,
- ),
- )
- );
+ 'line_item_id' => $item_id,
+ 'quantity' => 1,
+ ),
+ )
+ );
- $this->assertEquals( 200, $response->get_status() );
- $this->assertEquals( '10.555', $response->get_data()['total'], 'Three-decimal precision should be preserved.' );
- } finally {
- remove_filter( 'wc_get_price_decimals', $three_decimals );
- }
+ $this->assertEquals( 200, $response->get_status() );
+ $this->assertEquals( '10.555', $response->get_data()['total'], 'Three-decimal precision should be preserved.' );
}
/**
diff --git a/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version3/class-wc-rest-products-controller-tests.php b/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version3/class-wc-rest-products-controller-tests.php
index df2b9b2409b..a2ed1922d2e 100644
--- a/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version3/class-wc-rest-products-controller-tests.php
+++ b/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version3/class-wc-rest-products-controller-tests.php
@@ -499,8 +499,6 @@ class WC_REST_Products_Controller_Tests extends WC_Unit_Test_Case {
$this->assertEquals( $response_products[0]['sku'], 'pancake-2' );
$this->assertEquals( $response_products[1]['name'], 'Waffle 3' );
$this->assertEquals( $response_products[1]['sku'], 'waffle-3' );
-
- remove_filter( 'wc_product_sku_enabled', '__return_false' );
}
/**
diff --git a/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version3/class-wc-rest-report-sales-controller-tests.php b/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version3/class-wc-rest-report-sales-controller-tests.php
index bd3a359afcd..e25b162e348 100644
--- a/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version3/class-wc-rest-report-sales-controller-tests.php
+++ b/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version3/class-wc-rest-report-sales-controller-tests.php
@@ -164,53 +164,47 @@ class WC_REST_Report_Sales_Controller_Tests extends WC_REST_Unit_Test_Case {
* per-row net sales (sales - refunds) wrong.
*/
public function test_refunds_bucketed_by_local_time_in_non_utc_site(): void {
- $previous_wp_tz = get_option( 'timezone_string' );
-
// Pacific/Auckland is UTC+12 (or +13 in DST). Configure the non-UTC site the
// way WordPress actually does (via the timezone_string option, leaving PHP's
// default timezone at UTC) so the legacy report range math (which assumes the
// WordPress UTC invariant) is exercised as it runs in production.
update_option( 'timezone_string', 'Pacific/Auckland' );
- try {
- $order = WC_Helper_Order::create_order();
- $order->set_status( OrderStatus::COMPLETED );
- $order->save();
+ $order = WC_Helper_Order::create_order();
+ $order->set_status( OrderStatus::COMPLETED );
+ $order->save();
- $refund = wc_create_refund(
- array(
- 'amount' => 3,
- 'order_id' => $order->get_id(),
- )
- );
+ $refund = wc_create_refund(
+ array(
+ 'amount' => 3,
+ 'order_id' => $order->get_id(),
+ )
+ );
- // Local time of 02:00 is still the previous calendar day in UTC, so the
- // refund's post_date (local) and post_date_gmt (UTC) land on different days.
- // Bucketing by UTC instead of local time would put the refund in the wrong row.
- $local_today = current_datetime()->format( 'Y-m-d' );
- $local_post_date = $local_today . ' 02:00:00';
- wp_update_post(
- array(
- 'ID' => $refund->get_id(),
- 'post_date' => $local_post_date,
- )
- );
+ // Local time of 02:00 is still the previous calendar day in UTC, so the
+ // refund's post_date (local) and post_date_gmt (UTC) land on different days.
+ // Bucketing by UTC instead of local time would put the refund in the wrong row.
+ $local_today = current_datetime()->format( 'Y-m-d' );
+ $local_post_date = $local_today . ' 02:00:00';
+ wp_update_post(
+ array(
+ 'ID' => $refund->get_id(),
+ 'post_date' => $local_post_date,
+ )
+ );
- $data = $this->get_report( 'month' );
+ $data = $this->get_report( 'month' );
- $this->assertArrayHasKey(
- $local_today,
- $data['totals'],
- 'Local-time today should exist as a bucket key.'
- );
- $this->assertSame(
- '3.00',
- $data['totals'][ $local_today ]['refunds'],
- 'Refund must bucket by local time so it lines up with sales/orders in the same row.'
- );
- } finally {
- update_option( 'timezone_string', $previous_wp_tz );
- }
+ $this->assertArrayHasKey(
+ $local_today,
+ $data['totals'],
+ 'Local-time today should exist as a bucket key.'
+ );
+ $this->assertSame(
+ '3.00',
+ $data['totals'][ $local_today ]['refunds'],
+ 'Refund must bucket by local time so it lines up with sales/orders in the same row.'
+ );
}
/**
diff --git a/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version4/Customers/class-wc-rest-customers-v4-controller-tests.php b/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version4/Customers/class-wc-rest-customers-v4-controller-tests.php
index 9280437fa69..0eb6f94b575 100644
--- a/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version4/Customers/class-wc-rest-customers-v4-controller-tests.php
+++ b/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version4/Customers/class-wc-rest-customers-v4-controller-tests.php
@@ -789,9 +789,6 @@ class WC_REST_Customers_V4_Controller_Tests extends WC_REST_Unit_Test_Case {
// Should return default per_page (10), not 0.
$this->assertEquals( 10, count( $response_data ), 'number=-5 should fall back to default (10)' );
-
- // Clean up filter.
- remove_all_filters( 'woocommerce_customer_query_args' );
}
/**
diff --git a/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version4/Orders/class-wc-rest-orders-v4-controller-tests.php b/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version4/Orders/class-wc-rest-orders-v4-controller-tests.php
index 25b79f97d73..c13cc9e3d37 100644
--- a/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version4/Orders/class-wc-rest-orders-v4-controller-tests.php
+++ b/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version4/Orders/class-wc-rest-orders-v4-controller-tests.php
@@ -847,8 +847,6 @@ class WC_REST_Orders_V4_Controller_Tests extends WC_REST_Unit_Test_Case {
* Test edge case: created_via filtering when COT is enabled.
*/
public function test_created_via_filtering_with_cot_enabled(): void {
- $original_cot_setting = get_option( CustomOrdersTableController::CUSTOM_ORDERS_TABLE_USAGE_ENABLED_OPTION );
-
// Skip test if COT cannot be safely enabled/disabled.
try {
update_option( CustomOrdersTableController::CUSTOM_ORDERS_TABLE_USAGE_ENABLED_OPTION, 'yes' );
@@ -875,10 +873,9 @@ class WC_REST_Orders_V4_Controller_Tests extends WC_REST_Unit_Test_Case {
$this->assertCount( 1, $response_data );
$this->assertEquals( 'checkout', $response_data[0]['created_via'] );
- // Clean up orders first, then restore setting.
+ // Clean up orders.
$order1->delete( true );
$order2->delete( true );
- update_option( CustomOrdersTableController::CUSTOM_ORDERS_TABLE_USAGE_ENABLED_OPTION, $original_cot_setting );
}
/**
diff --git a/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version4/Refunds/class-wc-rest-refunds-v4-controller-tests.php b/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version4/Refunds/class-wc-rest-refunds-v4-controller-tests.php
index 1a1a12ab787..dac3200c29f 100644
--- a/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version4/Refunds/class-wc-rest-refunds-v4-controller-tests.php
+++ b/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version4/Refunds/class-wc-rest-refunds-v4-controller-tests.php
@@ -1993,86 +1993,76 @@ class WC_REST_Refunds_V4_Controller_Tests extends WC_REST_Unit_Test_Case {
)
);
- // Capture original option values so we can restore them in finally —
- // tearDown doesn't reset these globally and leakage breaks subsequent
- // tests that assume the default tax config.
- $original_calc_taxes = get_option( 'woocommerce_calc_taxes', 'no' );
- $original_prices_include_tax = get_option( 'woocommerce_prices_include_tax', 'no' );
update_option( 'woocommerce_calc_taxes', 'yes' );
update_option( 'woocommerce_prices_include_tax', 'no' );
- try {
- $product = WC_Helper_Product::create_simple_product();
- $product->set_regular_price( 100.00 );
- $product->set_tax_status( 'taxable' );
- $product->save();
+ $product = WC_Helper_Product::create_simple_product();
+ $product->set_regular_price( 100.00 );
+ $product->set_tax_status( 'taxable' );
+ $product->save();
- $order = wc_create_order();
- $item = new WC_Order_Item_Product();
- $item->set_props(
- array(
- 'product' => $product,
- 'quantity' => 1,
- 'subtotal' => 100.00,
- 'total' => 100.00,
- )
- );
- $item->set_taxes(
- array(
- 'total' => array( $tax_rate_id => 10.00 ),
- 'subtotal' => array( $tax_rate_id => 10.00 ),
- )
- );
- $item->save();
- $order->add_item( $item );
+ $order = wc_create_order();
+ $item = new WC_Order_Item_Product();
+ $item->set_props(
+ array(
+ 'product' => $product,
+ 'quantity' => 1,
+ 'subtotal' => 100.00,
+ 'total' => 100.00,
+ )
+ );
+ $item->set_taxes(
+ array(
+ 'total' => array( $tax_rate_id => 10.00 ),
+ 'subtotal' => array( $tax_rate_id => 10.00 ),
+ )
+ );
+ $item->save();
+ $order->add_item( $item );
- $tax_item = new \WC_Order_Item_Tax();
- $tax_item->set_rate( $tax_rate_id );
- $tax_item->set_tax_total( 10.00 );
- $tax_item->save();
- $order->add_item( $tax_item );
+ $tax_item = new \WC_Order_Item_Tax();
+ $tax_item->set_rate( $tax_rate_id );
+ $tax_item->set_tax_total( 10.00 );
+ $tax_item->save();
+ $order->add_item( $tax_item );
- $order->set_billing_country( 'US' );
- // calculate_totals( false ) is not reliable in the test environment when
- // taxes are involved — set_total() explicitly so get_remaining_refund_amount()
- // matches the line + tax sum.
- $order->set_total( 110.00 );
- $order->set_status( OrderStatus::COMPLETED );
- $order->save();
- $this->created_orders[] = $order->get_id();
+ $order->set_billing_country( 'US' );
+ // calculate_totals( false ) is not reliable in the test environment when
+ // taxes are involved — set_total() explicitly so get_remaining_refund_amount()
+ // matches the line + tax sum.
+ $order->set_total( 110.00 );
+ $order->set_status( OrderStatus::COMPLETED );
+ $order->save();
+ $this->created_orders[] = $order->get_id();
- // Refund the line — refund_total OMITTED.
- $request = new WP_REST_Request( 'POST', '/wc/v4/refunds' );
- $request->set_body_params(
- array(
- 'order_id' => $order->get_id(),
- 'line_items' => array(
- array(
- 'line_item_id' => $item->get_id(),
- 'quantity' => 1,
- ),
+ // Refund the line — refund_total OMITTED.
+ $request = new WP_REST_Request( 'POST', '/wc/v4/refunds' );
+ $request->set_body_params(
+ array(
+ 'order_id' => $order->get_id(),
+ 'line_items' => array(
+ array(
+ 'line_item_id' => $item->get_id(),
+ 'quantity' => 1,
),
- )
- );
- $response = $this->server->dispatch( $request );
+ ),
+ )
+ );
+ $response = $this->server->dispatch( $request );
- $this->assertEquals( 201, $response->get_status() );
- $data = $response->get_data();
- $this->assertEquals( '110.00', $data['total'], 'Auto-computed amount should include tax ($100 + 10% = $110)' );
+ $this->assertEquals( 201, $response->get_status() );
+ $data = $response->get_data();
+ $this->assertEquals( '110.00', $data['total'], 'Auto-computed amount should include tax ($100 + 10% = $110)' );
- // Verify the per-line refund_tax was extracted (not 0).
- $this->assertNotEmpty( $data['line_items'] );
- $line_item_response = $data['line_items'][0];
- $this->assertEquals( '100.00', $line_item_response['refund_total'], 'Per-line refund_total should be tax-exclusive after extraction' );
- $this->assertNotEmpty( $line_item_response['refund_tax'], 'refund_tax should be populated from extraction' );
- $this->assertEquals( '10.00', $line_item_response['refund_tax'][0]['refund_total'] );
+ // Verify the per-line refund_tax was extracted (not 0).
+ $this->assertNotEmpty( $data['line_items'] );
+ $line_item_response = $data['line_items'][0];
+ $this->assertEquals( '100.00', $line_item_response['refund_total'], 'Per-line refund_total should be tax-exclusive after extraction' );
+ $this->assertNotEmpty( $line_item_response['refund_tax'], 'refund_tax should be populated from extraction' );
+ $this->assertEquals( '10.00', $line_item_response['refund_tax'][0]['refund_total'] );
- $this->created_refunds[] = $data['id'];
- $product->delete( true );
- } finally {
- update_option( 'woocommerce_calc_taxes', $original_calc_taxes );
- update_option( 'woocommerce_prices_include_tax', $original_prices_include_tax );
- }
+ $this->created_refunds[] = $data['id'];
+ $product->delete( true );
}
/**
@@ -2177,106 +2167,99 @@ class WC_REST_Refunds_V4_Controller_Tests extends WC_REST_Unit_Test_Case {
)
);
- $original_calc_taxes = get_option( 'woocommerce_calc_taxes', 'no' );
- $original_prices_include_tax = get_option( 'woocommerce_prices_include_tax', 'no' );
update_option( 'woocommerce_calc_taxes', 'yes' );
// Actually exercise a tax-inclusive store (the test name now matches reality).
update_option( 'woocommerce_prices_include_tax', 'yes' );
- try {
- $dispatch_refund = function ( array $line_item_overrides ) use ( $tax_rate_id ): array {
- $product = WC_Helper_Product::create_simple_product();
- // Tax-inclusive store: regular_price entered with tax baked in.
- $product->set_regular_price( 110.00 );
- $product->set_tax_status( 'taxable' );
- $product->save();
-
- $order = wc_create_order();
- $item = new WC_Order_Item_Product();
- $item->set_props(
- array(
- 'product' => $product,
- 'quantity' => 1,
- 'subtotal' => 100.00,
- 'total' => 100.00,
- )
- );
- $item->set_taxes(
- array(
- 'total' => array( $tax_rate_id => 10.00 ),
- 'subtotal' => array( $tax_rate_id => 10.00 ),
- )
- );
- $item->save();
- $order->add_item( $item );
-
- $tax_item = new \WC_Order_Item_Tax();
- $tax_item->set_rate( $tax_rate_id );
- $tax_item->set_tax_total( 10.00 );
- $tax_item->save();
- $order->add_item( $tax_item );
-
- $order->set_billing_country( 'US' );
- $order->set_total( 110.00 );
- $order->set_status( OrderStatus::COMPLETED );
- $order->save();
- $this->created_orders[] = $order->get_id();
-
- $request = new WP_REST_Request( 'POST', '/wc/v4/refunds' );
- $request->set_body_params(
- array(
- 'order_id' => $order->get_id(),
- 'line_items' => array(
- array_merge( array( 'line_item_id' => $item->get_id() ), $line_item_overrides ),
- ),
- )
- );
- $response = $this->server->dispatch( $request );
+ $dispatch_refund = function ( array $line_item_overrides ) use ( $tax_rate_id ): array {
+ $product = WC_Helper_Product::create_simple_product();
+ // Tax-inclusive store: regular_price entered with tax baked in.
+ $product->set_regular_price( 110.00 );
+ $product->set_tax_status( 'taxable' );
+ $product->save();
- $this->assertEquals( 201, $response->get_status() );
- $data = $response->get_data();
- $this->created_refunds[] = $data['id'];
- $product->delete( true );
+ $order = wc_create_order();
+ $item = new WC_Order_Item_Product();
+ $item->set_props(
+ array(
+ 'product' => $product,
+ 'quantity' => 1,
+ 'subtotal' => 100.00,
+ 'total' => 100.00,
+ )
+ );
+ $item->set_taxes(
+ array(
+ 'total' => array( $tax_rate_id => 10.00 ),
+ 'subtotal' => array( $tax_rate_id => 10.00 ),
+ )
+ );
+ $item->save();
+ $order->add_item( $item );
+
+ $tax_item = new \WC_Order_Item_Tax();
+ $tax_item->set_rate( $tax_rate_id );
+ $tax_item->set_tax_total( 10.00 );
+ $tax_item->save();
+ $order->add_item( $tax_item );
- return $data;
- };
+ $order->set_billing_country( 'US' );
+ $order->set_total( 110.00 );
+ $order->set_status( OrderStatus::COMPLETED );
+ $order->save();
+ $this->created_orders[] = $order->get_id();
- // Path A: simplified form — no refund_total, backend auto-computes via compute_line_item_refund_total.
- $data_simplified = $dispatch_refund( array( 'quantity' => 1 ) );
- // Path B: explicit form — client supplies the tax-inclusive refund_total.
- $data_explicit = $dispatch_refund(
+ $request = new WP_REST_Request( 'POST', '/wc/v4/refunds' );
+ $request->set_body_params(
array(
- 'quantity' => 1,
- 'refund_total' => 110.00,
+ 'order_id' => $order->get_id(),
+ 'line_items' => array(
+ array_merge( array( 'line_item_id' => $item->get_id() ), $line_item_overrides ),
+ ),
)
);
+ $response = $this->server->dispatch( $request );
- $this->assertEquals(
- $data_explicit['total'],
- $data_simplified['total'],
- 'Tax-inclusive store: simplified and explicit forms must produce the same amount.'
- );
- $this->assertEquals( '110.00', $data_simplified['total'] );
+ $this->assertEquals( 201, $response->get_status() );
+ $data = $response->get_data();
+ $this->created_refunds[] = $data['id'];
+ $product->delete( true );
- // The per-line refund_total / refund_tax must round-trip identically too.
- $this->assertEquals(
- $data_explicit['line_items'][0]['refund_total'],
- $data_simplified['line_items'][0]['refund_total'],
- 'Per-line refund_total must match (tax-exclusive after extraction).'
- );
- $this->assertEquals( '100.00', $data_simplified['line_items'][0]['refund_total'] );
+ return $data;
+ };
- $this->assertNotEmpty( $data_simplified['line_items'][0]['refund_tax'] );
- $this->assertEquals(
- $data_explicit['line_items'][0]['refund_tax'][0]['refund_total'],
- $data_simplified['line_items'][0]['refund_tax'][0]['refund_total'],
- 'Extracted refund_tax must match between paths.'
- );
- $this->assertEquals( '10.00', $data_simplified['line_items'][0]['refund_tax'][0]['refund_total'] );
- } finally {
- update_option( 'woocommerce_calc_taxes', $original_calc_taxes );
- update_option( 'woocommerce_prices_include_tax', $original_prices_include_tax );
- }
+ // Path A: simplified form — no refund_total, backend auto-computes via compute_line_item_refund_total.
+ $data_simplified = $dispatch_refund( array( 'quantity' => 1 ) );
+ // Path B: explicit form — client supplies the tax-inclusive refund_total.
+ $data_explicit = $dispatch_refund(
+ array(
+ 'quantity' => 1,
+ 'refund_total' => 110.00,
+ )
+ );
+
+ $this->assertEquals(
+ $data_explicit['total'],
+ $data_simplified['total'],
+ 'Tax-inclusive store: simplified and explicit forms must produce the same amount.'
+ );
+ $this->assertEquals( '110.00', $data_simplified['total'] );
+
+ // The per-line refund_total / refund_tax must round-trip identically too.
+ $this->assertEquals(
+ $data_explicit['line_items'][0]['refund_total'],
+ $data_simplified['line_items'][0]['refund_total'],
+ 'Per-line refund_total must match (tax-exclusive after extraction).'
+ );
+ $this->assertEquals( '100.00', $data_simplified['line_items'][0]['refund_total'] );
+
+ $this->assertNotEmpty( $data_simplified['line_items'][0]['refund_tax'] );
+ $this->assertEquals(
+ $data_explicit['line_items'][0]['refund_tax'][0]['refund_total'],
+ $data_simplified['line_items'][0]['refund_tax'][0]['refund_total'],
+ 'Extracted refund_tax must match between paths.'
+ );
+ $this->assertEquals( '10.00', $data_simplified['line_items'][0]['refund_tax'][0]['refund_total'] );
}
/**
@@ -2651,81 +2634,75 @@ class WC_REST_Refunds_V4_Controller_Tests extends WC_REST_Unit_Test_Case {
)
);
- $original_prices_include_tax = get_option( 'woocommerce_prices_include_tax', 'no' );
update_option( 'woocommerce_calc_taxes', 'yes' );
update_option( 'woocommerce_prices_include_tax', 'yes' );
- try {
- // Product price $110 entered tax-inclusive; tax-exclusive total is $100, tax is $10.
- $product = WC_Helper_Product::create_simple_product();
- $product->set_regular_price( 110.00 );
- $product->set_tax_status( 'taxable' );
- $product->save();
+ // Product price $110 entered tax-inclusive; tax-exclusive total is $100, tax is $10.
+ $product = WC_Helper_Product::create_simple_product();
+ $product->set_regular_price( 110.00 );
+ $product->set_tax_status( 'taxable' );
+ $product->save();
- $order = wc_create_order();
- $item = new WC_Order_Item_Product();
- $item->set_props(
- array(
- 'product' => $product,
- 'quantity' => 1,
- 'subtotal' => 100.00,
- 'total' => 100.00,
- )
- );
- $item->set_taxes(
- array(
- 'total' => array( $tax_rate_id => 10.00 ),
- 'subtotal' => array( $tax_rate_id => 10.00 ),
- )
- );
- $item->save();
- $order->add_item( $item );
+ $order = wc_create_order();
+ $item = new WC_Order_Item_Product();
+ $item->set_props(
+ array(
+ 'product' => $product,
+ 'quantity' => 1,
+ 'subtotal' => 100.00,
+ 'total' => 100.00,
+ )
+ );
+ $item->set_taxes(
+ array(
+ 'total' => array( $tax_rate_id => 10.00 ),
+ 'subtotal' => array( $tax_rate_id => 10.00 ),
+ )
+ );
+ $item->save();
+ $order->add_item( $item );
- $tax_item = new \WC_Order_Item_Tax();
- $tax_item->set_rate( $tax_rate_id );
- $tax_item->set_tax_total( 10.00 );
- $tax_item->save();
- $order->add_item( $tax_item );
+ $tax_item = new \WC_Order_Item_Tax();
+ $tax_item->set_rate( $tax_rate_id );
+ $tax_item->set_tax_total( 10.00 );
+ $tax_item->save();
+ $order->add_item( $tax_item );
- $order->set_billing_country( 'US' );
- $order->set_total( 110.00 );
- $order->set_status( OrderStatus::COMPLETED );
- $order->save();
- $this->created_orders[] = $order->get_id();
+ $order->set_billing_country( 'US' );
+ $order->set_total( 110.00 );
+ $order->set_status( OrderStatus::COMPLETED );
+ $order->save();
+ $this->created_orders[] = $order->get_id();
- // Refund via the simplified form (no refund_total).
- $request = new WP_REST_Request( 'POST', '/wc/v4/refunds' );
- $request->set_body_params(
- array(
- 'order_id' => $order->get_id(),
- 'line_items' => array(
- array(
- 'line_item_id' => $item->get_id(),
- 'quantity' => 1,
- ),
+ // Refund via the simplified form (no refund_total).
+ $request = new WP_REST_Request( 'POST', '/wc/v4/refunds' );
+ $request->set_body_params(
+ array(
+ 'order_id' => $order->get_id(),
+ 'line_items' => array(
+ array(
+ 'line_item_id' => $item->get_id(),
+ 'quantity' => 1,
),
- )
- );
- $response = $this->server->dispatch( $request );
+ ),
+ )
+ );
+ $response = $this->server->dispatch( $request );
- $this->assertEquals( 201, $response->get_status() );
- $data = $response->get_data();
- // Tax-inclusive store: refund amount must still be $110 ($100 + $10 tax),
- // confirming the auto-compute round-trip works under prices_include_tax=yes.
- $this->assertEquals( '110.00', $data['total'], 'Tax-inclusive store: auto-computed amount must equal the tax-inclusive line total.' );
+ $this->assertEquals( 201, $response->get_status() );
+ $data = $response->get_data();
+ // Tax-inclusive store: refund amount must still be $110 ($100 + $10 tax),
+ // confirming the auto-compute round-trip works under prices_include_tax=yes.
+ $this->assertEquals( '110.00', $data['total'], 'Tax-inclusive store: auto-computed amount must equal the tax-inclusive line total.' );
- $this->assertNotEmpty( $data['line_items'] );
- $line_item_response = $data['line_items'][0];
- $this->assertEquals( '100.00', $line_item_response['refund_total'], 'Per-line refund_total should be tax-exclusive after extraction.' );
- $this->assertNotEmpty( $line_item_response['refund_tax'] );
- $this->assertEquals( '10.00', $line_item_response['refund_tax'][0]['refund_total'] );
+ $this->assertNotEmpty( $data['line_items'] );
+ $line_item_response = $data['line_items'][0];
+ $this->assertEquals( '100.00', $line_item_response['refund_total'], 'Per-line refund_total should be tax-exclusive after extraction.' );
+ $this->assertNotEmpty( $line_item_response['refund_tax'] );
+ $this->assertEquals( '10.00', $line_item_response['refund_tax'][0]['refund_total'] );
- $this->created_refunds[] = $data['id'];
- $product->delete( true );
- } finally {
- // Restore the option so a failing assertion above can't leak state into other tests.
- update_option( 'woocommerce_prices_include_tax', $original_prices_include_tax );
- }
+ $this->created_refunds[] = $data['id'];
+ $product->delete( true );
}
/**
@@ -2931,80 +2908,73 @@ class WC_REST_Refunds_V4_Controller_Tests extends WC_REST_Unit_Test_Case {
)
);
- $original_calc_taxes = get_option( 'woocommerce_calc_taxes', 'no' );
- $original_prices_include_tax = get_option( 'woocommerce_prices_include_tax', 'no' );
update_option( 'woocommerce_calc_taxes', 'yes' );
update_option( 'woocommerce_prices_include_tax', 'yes' );
- try {
- $product = WC_Helper_Product::create_simple_product();
- $product->set_regular_price( 110.00 );
- $product->set_tax_status( 'taxable' );
- $product->save();
-
- $order = wc_create_order();
- $item = new WC_Order_Item_Product();
- $item->set_props(
- array(
- 'product' => $product,
- 'quantity' => 1,
- 'subtotal' => 100.00,
- 'total' => 100.00,
- )
- );
- $item->set_taxes(
- array(
- 'total' => array( $tax_rate_id => 10.00 ),
- 'subtotal' => array( $tax_rate_id => 10.00 ),
- )
- );
- $item->save();
- $order->add_item( $item );
+ $product = WC_Helper_Product::create_simple_product();
+ $product->set_regular_price( 110.00 );
+ $product->set_tax_status( 'taxable' );
+ $product->save();
- $tax_item = new \WC_Order_Item_Tax();
- $tax_item->set_rate( $tax_rate_id );
- $tax_item->set_tax_total( 10.00 );
- $tax_item->save();
- $order->add_item( $tax_item );
+ $order = wc_create_order();
+ $item = new WC_Order_Item_Product();
+ $item->set_props(
+ array(
+ 'product' => $product,
+ 'quantity' => 1,
+ 'subtotal' => 100.00,
+ 'total' => 100.00,
+ )
+ );
+ $item->set_taxes(
+ array(
+ 'total' => array( $tax_rate_id => 10.00 ),
+ 'subtotal' => array( $tax_rate_id => 10.00 ),
+ )
+ );
+ $item->save();
+ $order->add_item( $item );
- $order->set_billing_country( 'US' );
- $order->set_total( 110.00 );
- $order->set_status( OrderStatus::COMPLETED );
- $order->save();
- $this->created_orders[] = $order->get_id();
+ $tax_item = new \WC_Order_Item_Tax();
+ $tax_item->set_rate( $tax_rate_id );
+ $tax_item->set_tax_total( 10.00 );
+ $tax_item->save();
+ $order->add_item( $tax_item );
- // Legacy form: client supplies the tax-inclusive refund_total ($110)
- // and omits quantity. Converter must extract the $10 tax portion the
- // same way it does for the simplified/explicit-with-quantity paths.
- $request = new WP_REST_Request( 'POST', '/wc/v4/refunds' );
- $request->set_body_params(
- array(
- 'order_id' => $order->get_id(),
- 'line_items' => array(
- array(
- 'line_item_id' => $item->get_id(),
- 'refund_total' => 110.00,
- ),
+ $order->set_billing_country( 'US' );
+ $order->set_total( 110.00 );
+ $order->set_status( OrderStatus::COMPLETED );
+ $order->save();
+ $this->created_orders[] = $order->get_id();
+
+ // Legacy form: client supplies the tax-inclusive refund_total ($110)
+ // and omits quantity. Converter must extract the $10 tax portion the
+ // same way it does for the simplified/explicit-with-quantity paths.
+ $request = new WP_REST_Request( 'POST', '/wc/v4/refunds' );
+ $request->set_body_params(
+ array(
+ 'order_id' => $order->get_id(),
+ 'line_items' => array(
+ array(
+ 'line_item_id' => $item->get_id(),
+ 'refund_total' => 110.00,
),
- )
- );
- $response = $this->server->dispatch( $request );
+ ),
+ )
+ );
+ $response = $this->server->dispatch( $request );
- $this->assertEquals( 201, $response->get_status() );
- $data = $response->get_data();
- $this->created_refunds[] = $data['id'];
+ $this->assertEquals( 201, $response->get_status() );
+ $data = $response->get_data();
+ $this->created_refunds[] = $data['id'];
- $this->assertEquals( '110.00', $data['total'] );
- $this->assertNotEmpty( $data['line_items'] );
- $this->assertEquals( '100.00', $data['line_items'][0]['refund_total'], 'Per-line refund_total should be tax-exclusive after extraction.' );
- $this->assertNotEmpty( $data['line_items'][0]['refund_tax'], 'refund_tax must be extracted on the tax-inclusive legacy path.' );
- $this->assertEquals( '10.00', $data['line_items'][0]['refund_tax'][0]['refund_total'] );
+ $this->assertEquals( '110.00', $data['total'] );
+ $this->assertNotEmpty( $data['line_items'] );
+ $this->assertEquals( '100.00', $data['line_items'][0]['refund_total'], 'Per-line refund_total should be tax-exclusive after extraction.' );
+ $this->assertNotEmpty( $data['line_items'][0]['refund_tax'], 'refund_tax must be extracted on the tax-inclusive legacy path.' );
+ $this->assertEquals( '10.00', $data['line_items'][0]['refund_tax'][0]['refund_total'] );
- $product->delete( true );
- } finally {
- update_option( 'woocommerce_calc_taxes', $original_calc_taxes );
- update_option( 'woocommerce_prices_include_tax', $original_prices_include_tax );
- }
+ $product->delete( true );
}
/**
@@ -3225,79 +3195,72 @@ class WC_REST_Refunds_V4_Controller_Tests extends WC_REST_Unit_Test_Case {
)
);
- $original_calc_taxes = get_option( 'woocommerce_calc_taxes', 'no' );
- $original_prices_include_tax = get_option( 'woocommerce_prices_include_tax', 'no' );
update_option( 'woocommerce_calc_taxes', 'yes' );
update_option( 'woocommerce_prices_include_tax', 'no' );
- try {
- $product = WC_Helper_Product::create_simple_product();
- $product->set_regular_price( 100.00 );
- $product->set_tax_status( 'taxable' );
- $product->save();
+ $product = WC_Helper_Product::create_simple_product();
+ $product->set_regular_price( 100.00 );
+ $product->set_tax_status( 'taxable' );
+ $product->save();
- $order = wc_create_order();
- $item = new WC_Order_Item_Product();
- $item->set_props(
- array(
- 'product' => $product,
- 'quantity' => 1,
- 'subtotal' => 100.00,
- 'total' => 100.00,
- )
- );
- $item->set_taxes(
- array(
- 'total' => array( $tax_rate_id => 10.00 ),
- 'subtotal' => array( $tax_rate_id => 10.00 ),
- )
- );
- $item->save();
- $order->add_item( $item );
+ $order = wc_create_order();
+ $item = new WC_Order_Item_Product();
+ $item->set_props(
+ array(
+ 'product' => $product,
+ 'quantity' => 1,
+ 'subtotal' => 100.00,
+ 'total' => 100.00,
+ )
+ );
+ $item->set_taxes(
+ array(
+ 'total' => array( $tax_rate_id => 10.00 ),
+ 'subtotal' => array( $tax_rate_id => 10.00 ),
+ )
+ );
+ $item->save();
+ $order->add_item( $item );
- $tax_item = new \WC_Order_Item_Tax();
- $tax_item->set_rate( $tax_rate_id );
- $tax_item->set_tax_total( 10.00 );
- $tax_item->save();
- $order->add_item( $tax_item );
+ $tax_item = new \WC_Order_Item_Tax();
+ $tax_item->set_rate( $tax_rate_id );
+ $tax_item->set_tax_total( 10.00 );
+ $tax_item->save();
+ $order->add_item( $tax_item );
- $order->set_billing_country( 'US' );
- $order->set_total( 110.00 );
- $order->set_status( OrderStatus::COMPLETED );
- $order->save();
- $this->created_orders[] = $order->get_id();
+ $order->set_billing_country( 'US' );
+ $order->set_total( 110.00 );
+ $order->set_status( OrderStatus::COMPLETED );
+ $order->save();
+ $this->created_orders[] = $order->get_id();
- // Auto-compute (no refund_total) + explicit refund_tax.
- $request = new WP_REST_Request( 'POST', '/wc/v4/refunds' );
- $request->set_body_params(
- array(
- 'order_id' => $order->get_id(),
- 'line_items' => array(
- array(
- 'line_item_id' => $item->get_id(),
- 'quantity' => 1,
- 'refund_tax' => array(
- array(
- 'id' => $tax_rate_id,
- 'refund_total' => 10.00,
- ),
+ // Auto-compute (no refund_total) + explicit refund_tax.
+ $request = new WP_REST_Request( 'POST', '/wc/v4/refunds' );
+ $request->set_body_params(
+ array(
+ 'order_id' => $order->get_id(),
+ 'line_items' => array(
+ array(
+ 'line_item_id' => $item->get_id(),
+ 'quantity' => 1,
+ 'refund_tax' => array(
+ array(
+ 'id' => $tax_rate_id,
+ 'refund_total' => 10.00,
),
),
),
- )
- );
- $response = $this->server->dispatch( $request );
+ ),
+ )
+ );
+ $response = $this->server->dispatch( $request );
- $this->assertEquals( 400, $response->get_status() );
- $data = $response->get_data();
- $this->assertEquals( 'invalid_line_item', $data['code'] );
- $this->assertStringContainsString( 'refund_tax cannot be combined', $data['message'] );
+ $this->assertEquals( 400, $response->get_status() );
+ $data = $response->get_data();
+ $this->assertEquals( 'invalid_line_item', $data['code'] );
+ $this->assertStringContainsString( 'refund_tax cannot be combined', $data['message'] );
- $product->delete( true );
- } finally {
- update_option( 'woocommerce_calc_taxes', $original_calc_taxes );
- update_option( 'woocommerce_prices_include_tax', $original_prices_include_tax );
- }
+ $product->delete( true );
}
/**
@@ -3989,58 +3952,53 @@ class WC_REST_Refunds_V4_Controller_Tests extends WC_REST_Unit_Test_Case {
* @testdox Auto-compute follows the store's zero-decimal price setting and the final unit refund absorbs the rounding remainder.
*/
public function test_refunds_create_auto_compute_zero_decimal_currency(): void {
- $original_decimals = get_option( 'woocommerce_price_num_decimals', '2' );
update_option( 'woocommerce_price_num_decimals', '0' );
- try {
- list( $order, $item ) = $this->create_order_with_exact_line( 3, 1000.00, 1000.00, 1000.00 );
-
- $response = $this->dispatch_refund_request(
- $order->get_id(),
- array(
- array(
- 'line_item_id' => $item->get_id(),
- 'quantity' => 2,
- ),
- )
- );
- $this->assertEquals( 201, $response->get_status() );
- $this->assertEqualsWithDelta( 667.0, (float) $response->get_data()['total'], 0.001, 'Qty-2 refund of a 1000/3 line rounds to 667 at zero decimals' );
- $this->created_refunds[] = $response->get_data()['id'];
+ list( $order, $item ) = $this->create_order_with_exact_line( 3, 1000.00, 1000.00, 1000.00 );
- $response = $this->dispatch_refund_request(
- $order->get_id(),
+ $response = $this->dispatch_refund_request(
+ $order->get_id(),
+ array(
array(
- array(
- 'line_item_id' => $item->get_id(),
- 'quantity' => 1,
- ),
- )
- );
- $this->assertEquals( 201, $response->get_status() );
- $this->assertEqualsWithDelta( 333.0, (float) $response->get_data()['total'], 0.001, '667 + 333 consumes the 1000 line exactly' );
- $this->created_refunds[] = $response->get_data()['id'];
-
- list( $order_b, $item_b ) = $this->create_order_with_exact_line( 3, 1000.00, 1000.00, 1000.00 );
+ 'line_item_id' => $item->get_id(),
+ 'quantity' => 2,
+ ),
+ )
+ );
+ $this->assertEquals( 201, $response->get_status() );
+ $this->assertEqualsWithDelta( 667.0, (float) $response->get_data()['total'], 0.001, 'Qty-2 refund of a 1000/3 line rounds to 667 at zero decimals' );
+ $this->created_refunds[] = $response->get_data()['id'];
- $unit_refund = array(
+ $response = $this->dispatch_refund_request(
+ $order->get_id(),
+ array(
array(
- 'line_item_id' => $item_b->get_id(),
+ 'line_item_id' => $item->get_id(),
'quantity' => 1,
),
- );
- foreach ( array( 333.0, 333.0, 334.0 ) as $refund_number => $expected_total ) {
- $response = $this->dispatch_refund_request( $order_b->get_id(), $unit_refund );
- $this->assertEquals( 201, $response->get_status() );
- $this->assertEqualsWithDelta( $expected_total, (float) $response->get_data()['total'], 0.001, "Unit refund {$refund_number} of the 1000/3 line: the final unit absorbs the rounding remainder" );
- $this->created_refunds[] = $response->get_data()['id'];
- }
+ )
+ );
+ $this->assertEquals( 201, $response->get_status() );
+ $this->assertEqualsWithDelta( 333.0, (float) $response->get_data()['total'], 0.001, '667 + 333 consumes the 1000 line exactly' );
+ $this->created_refunds[] = $response->get_data()['id'];
- $order_b = wc_get_order( $order_b->get_id() );
- $this->assertEqualsWithDelta( 0.0, (float) $order_b->get_remaining_refund_amount(), 0.001, 'The final 334 refund consumes the 1000 line exactly — no stranded currency unit' );
- } finally {
- update_option( 'woocommerce_price_num_decimals', $original_decimals );
+ list( $order_b, $item_b ) = $this->create_order_with_exact_line( 3, 1000.00, 1000.00, 1000.00 );
+
+ $unit_refund = array(
+ array(
+ 'line_item_id' => $item_b->get_id(),
+ 'quantity' => 1,
+ ),
+ );
+ foreach ( array( 333.0, 333.0, 334.0 ) as $refund_number => $expected_total ) {
+ $response = $this->dispatch_refund_request( $order_b->get_id(), $unit_refund );
+ $this->assertEquals( 201, $response->get_status() );
+ $this->assertEqualsWithDelta( $expected_total, (float) $response->get_data()['total'], 0.001, "Unit refund {$refund_number} of the 1000/3 line: the final unit absorbs the rounding remainder" );
+ $this->created_refunds[] = $response->get_data()['id'];
}
+
+ $order_b = wc_get_order( $order_b->get_id() );
+ $this->assertEqualsWithDelta( 0.0, (float) $order_b->get_remaining_refund_amount(), 0.001, 'The final 334 refund consumes the 1000 line exactly — no stranded currency unit' );
}
/**
@@ -4061,70 +4019,63 @@ class WC_REST_Refunds_V4_Controller_Tests extends WC_REST_Unit_Test_Case {
)
);
- $original_calc_taxes = get_option( 'woocommerce_calc_taxes', 'no' );
- $original_prices_include_tax = get_option( 'woocommerce_prices_include_tax', 'no' );
update_option( 'woocommerce_calc_taxes', 'yes' );
update_option( 'woocommerce_prices_include_tax', 'no' );
- try {
- // 3 × 9.99 = 29.97, tax at 8.875% = 2.66, grand total 32.63.
- list( $one_shot_order, $one_shot_item ) = $this->create_order_with_exact_line( 3, 29.97, 29.97, 32.63, array( $tax_rate_id => 2.66 ) );
+ // 3 × 9.99 = 29.97, tax at 8.875% = 2.66, grand total 32.63.
+ list( $one_shot_order, $one_shot_item ) = $this->create_order_with_exact_line( 3, 29.97, 29.97, 32.63, array( $tax_rate_id => 2.66 ) );
- $response = $this->dispatch_refund_request(
- $one_shot_order->get_id(),
+ $response = $this->dispatch_refund_request(
+ $one_shot_order->get_id(),
+ array(
array(
- array(
- 'line_item_id' => $one_shot_item->get_id(),
- 'quantity' => 3,
- ),
- )
- );
- $this->assertEquals( 201, $response->get_status() );
- $this->assertEqualsWithDelta( 32.63, (float) $response->get_data()['total'], 0.001, 'Full-quantity refund must equal line total + line tax exactly' );
- $this->created_refunds[] = $response->get_data()['id'];
+ 'line_item_id' => $one_shot_item->get_id(),
+ 'quantity' => 3,
+ ),
+ )
+ );
+ $this->assertEquals( 201, $response->get_status() );
+ $this->assertEqualsWithDelta( 32.63, (float) $response->get_data()['total'], 0.001, 'Full-quantity refund must equal line total + line tax exactly' );
+ $this->created_refunds[] = $response->get_data()['id'];
- list( $order, $item ) = $this->create_order_with_exact_line( 3, 29.97, 29.97, 32.63, array( $tax_rate_id => 2.66 ) );
+ list( $order, $item ) = $this->create_order_with_exact_line( 3, 29.97, 29.97, 32.63, array( $tax_rate_id => 2.66 ) );
- $response = $this->dispatch_refund_request(
- $order->get_id(),
+ $response = $this->dispatch_refund_request(
+ $order->get_id(),
+ array(
array(
- array(
- 'line_item_id' => $item->get_id(),
- 'quantity' => 2,
- ),
- )
- );
- $this->assertEquals( 201, $response->get_status() );
- $data = $response->get_data();
- $this->assertEqualsWithDelta( 21.75, (float) $data['total'], 0.001, 'Qty-2 refund of the 32.63 line rounds 21.7533 to 21.75' );
- $this->created_refunds[] = $data['id'];
+ 'line_item_id' => $item->get_id(),
+ 'quantity' => 2,
+ ),
+ )
+ );
+ $this->assertEquals( 201, $response->get_status() );
+ $data = $response->get_data();
+ $this->assertEqualsWithDelta( 21.75, (float) $data['total'], 0.001, 'Qty-2 refund of the 32.63 line rounds 21.7533 to 21.75' );
+ $this->created_refunds[] = $data['id'];
- $line = $data['line_items'][0];
- $tax_sum = 0.0;
- foreach ( $line['refund_tax'] as $tax ) {
- $tax_sum += (float) $tax['refund_total'];
- }
- $this->assertEqualsWithDelta( 21.75, (float) $line['refund_total'] + $tax_sum, 0.001, 'Extracted net + tax must reassemble the tax-inclusive amount' );
+ $line = $data['line_items'][0];
+ $tax_sum = 0.0;
+ foreach ( $line['refund_tax'] as $tax ) {
+ $tax_sum += (float) $tax['refund_total'];
+ }
+ $this->assertEqualsWithDelta( 21.75, (float) $line['refund_total'] + $tax_sum, 0.001, 'Extracted net + tax must reassemble the tax-inclusive amount' );
- $response = $this->dispatch_refund_request(
- $order->get_id(),
+ $response = $this->dispatch_refund_request(
+ $order->get_id(),
+ array(
array(
- array(
- 'line_item_id' => $item->get_id(),
- 'quantity' => 1,
- ),
- )
- );
- $this->assertEquals( 201, $response->get_status() );
- $this->assertEqualsWithDelta( 10.88, (float) $response->get_data()['total'], 0.001, '21.75 + 10.88 consumes the 32.63 line exactly' );
- $this->created_refunds[] = $response->get_data()['id'];
+ 'line_item_id' => $item->get_id(),
+ 'quantity' => 1,
+ ),
+ )
+ );
+ $this->assertEquals( 201, $response->get_status() );
+ $this->assertEqualsWithDelta( 10.88, (float) $response->get_data()['total'], 0.001, '21.75 + 10.88 consumes the 32.63 line exactly' );
+ $this->created_refunds[] = $response->get_data()['id'];
- $order = wc_get_order( $order->get_id() );
- $this->assertEqualsWithDelta( 0.0, (float) $order->get_remaining_refund_amount(), 0.001, 'Qty-2 then qty-1 must leave nothing unrefunded' );
- } finally {
- update_option( 'woocommerce_calc_taxes', $original_calc_taxes );
- update_option( 'woocommerce_prices_include_tax', $original_prices_include_tax );
- }
+ $order = wc_get_order( $order->get_id() );
+ $this->assertEqualsWithDelta( 0.0, (float) $order->get_remaining_refund_amount(), 0.001, 'Qty-2 then qty-1 must leave nothing unrefunded' );
}
/**
@@ -4145,46 +4096,39 @@ class WC_REST_Refunds_V4_Controller_Tests extends WC_REST_Unit_Test_Case {
)
);
- $original_calc_taxes = get_option( 'woocommerce_calc_taxes', 'no' );
- $original_prices_include_tax = get_option( 'woocommerce_prices_include_tax', 'no' );
update_option( 'woocommerce_calc_taxes', 'yes' );
update_option( 'woocommerce_prices_include_tax', 'yes' );
- try {
- // 5 × 9.99 displayed (tax-inclusive) = 49.95; stored net 40.61 + 9.34 tax.
- list( $order, $item ) = $this->create_order_with_exact_line( 5, 40.61, 40.61, 49.95, array( $tax_rate_id => 9.34 ) );
+ // 5 × 9.99 displayed (tax-inclusive) = 49.95; stored net 40.61 + 9.34 tax.
+ list( $order, $item ) = $this->create_order_with_exact_line( 5, 40.61, 40.61, 49.95, array( $tax_rate_id => 9.34 ) );
- $response = $this->dispatch_refund_request(
- $order->get_id(),
+ $response = $this->dispatch_refund_request(
+ $order->get_id(),
+ array(
array(
- array(
- 'line_item_id' => $item->get_id(),
- 'quantity' => 5,
- ),
- )
- );
- $this->assertEquals( 201, $response->get_status() );
- $this->assertEqualsWithDelta( 49.95, (float) $response->get_data()['total'], 0.001, 'Full-quantity refund must equal 5 × the displayed 9.99 price' );
- $this->created_refunds[] = $response->get_data()['id'];
+ 'line_item_id' => $item->get_id(),
+ 'quantity' => 5,
+ ),
+ )
+ );
+ $this->assertEquals( 201, $response->get_status() );
+ $this->assertEqualsWithDelta( 49.95, (float) $response->get_data()['total'], 0.001, 'Full-quantity refund must equal 5 × the displayed 9.99 price' );
+ $this->created_refunds[] = $response->get_data()['id'];
- list( $order_b, $item_b ) = $this->create_order_with_exact_line( 5, 40.61, 40.61, 49.95, array( $tax_rate_id => 9.34 ) );
+ list( $order_b, $item_b ) = $this->create_order_with_exact_line( 5, 40.61, 40.61, 49.95, array( $tax_rate_id => 9.34 ) );
- $response = $this->dispatch_refund_request(
- $order_b->get_id(),
+ $response = $this->dispatch_refund_request(
+ $order_b->get_id(),
+ array(
array(
- array(
- 'line_item_id' => $item_b->get_id(),
- 'quantity' => 2,
- ),
- )
- );
- $this->assertEquals( 201, $response->get_status() );
- $this->assertEqualsWithDelta( 19.98, (float) $response->get_data()['total'], 0.001, 'Qty-2 refund must equal 2 × the displayed 9.99 price' );
- $this->created_refunds[] = $response->get_data()['id'];
- } finally {
- update_option( 'woocommerce_calc_taxes', $original_calc_taxes );
- update_option( 'woocommerce_prices_include_tax', $original_prices_include_tax );
- }
+ 'line_item_id' => $item_b->get_id(),
+ 'quantity' => 2,
+ ),
+ )
+ );
+ $this->assertEquals( 201, $response->get_status() );
+ $this->assertEqualsWithDelta( 19.98, (float) $response->get_data()['total'], 0.001, 'Qty-2 refund must equal 2 × the displayed 9.99 price' );
+ $this->created_refunds[] = $response->get_data()['id'];
}
/**
@@ -4218,51 +4162,44 @@ class WC_REST_Refunds_V4_Controller_Tests extends WC_REST_Unit_Test_Case {
)
);
- $original_calc_taxes = get_option( 'woocommerce_calc_taxes', 'no' );
- $original_prices_include_tax = get_option( 'woocommerce_prices_include_tax', 'no' );
update_option( 'woocommerce_calc_taxes', 'yes' );
update_option( 'woocommerce_prices_include_tax', 'no' );
- try {
- // 3 × 50 = 150; GST 5% = 7.50; compound PST 7% of 157.50 = 11.03; grand total 168.53.
- list( $order, $item ) = $this->create_order_with_exact_line(
- 3,
- 150.00,
- 150.00,
- 168.53,
- array(
- $gst_rate_id => 7.50,
- $pst_rate_id => 11.03,
- )
- );
+ // 3 × 50 = 150; GST 5% = 7.50; compound PST 7% of 157.50 = 11.03; grand total 168.53.
+ list( $order, $item ) = $this->create_order_with_exact_line(
+ 3,
+ 150.00,
+ 150.00,
+ 168.53,
+ array(
+ $gst_rate_id => 7.50,
+ $pst_rate_id => 11.03,
+ )
+ );
- $line_items = array(
- array(
- 'line_item_id' => $item->get_id(),
- 'quantity' => 2,
- ),
- );
+ $line_items = array(
+ array(
+ 'line_item_id' => $item->get_id(),
+ 'quantity' => 2,
+ ),
+ );
- $data_utils = wc_get_container()->get( DataUtils::class );
- $preview = $data_utils->build_refund_preview( $order, $line_items );
+ $data_utils = wc_get_container()->get( DataUtils::class );
+ $preview = $data_utils->build_refund_preview( $order, $line_items );
- $response = $this->dispatch_refund_request( $order->get_id(), $line_items );
- $this->assertEquals( 201, $response->get_status() );
- $data = $response->get_data();
- $this->assertEqualsWithDelta( 112.35, (float) $data['total'], 0.001, 'Qty-2 refund of the 168.53 line rounds 112.3533 to 112.35' );
- $this->assertEquals( $preview['total'], $data['total'], 'Create amount must match build_refund_preview total exactly' );
- $this->created_refunds[] = $data['id'];
+ $response = $this->dispatch_refund_request( $order->get_id(), $line_items );
+ $this->assertEquals( 201, $response->get_status() );
+ $data = $response->get_data();
+ $this->assertEqualsWithDelta( 112.35, (float) $data['total'], 0.001, 'Qty-2 refund of the 168.53 line rounds 112.3533 to 112.35' );
+ $this->assertEquals( $preview['total'], $data['total'], 'Create amount must match build_refund_preview total exactly' );
+ $this->created_refunds[] = $data['id'];
- $line = $data['line_items'][0];
- $tax_sum = 0.0;
- foreach ( $line['refund_tax'] as $tax ) {
- $tax_sum += (float) $tax['refund_total'];
- }
- $this->assertEqualsWithDelta( 112.35, (float) $line['refund_total'] + $tax_sum, 0.001, 'Net + per-rate taxes must reassemble the tax-inclusive amount' );
- } finally {
- update_option( 'woocommerce_calc_taxes', $original_calc_taxes );
- update_option( 'woocommerce_prices_include_tax', $original_prices_include_tax );
+ $line = $data['line_items'][0];
+ $tax_sum = 0.0;
+ foreach ( $line['refund_tax'] as $tax ) {
+ $tax_sum += (float) $tax['refund_total'];
}
+ $this->assertEqualsWithDelta( 112.35, (float) $line['refund_total'] + $tax_sum, 0.001, 'Net + per-rate taxes must reassemble the tax-inclusive amount' );
}
/**
@@ -4581,78 +4518,74 @@ class WC_REST_Refunds_V4_Controller_Tests extends WC_REST_Unit_Test_Case {
};
add_filter( 'wc_get_price_decimals', $zero_decimals );
- try {
- $product = WC_Helper_Product::create_simple_product();
- $product->set_regular_price( 1000.00 );
- $product->set_tax_status( 'taxable' );
- $product->save();
+ $product = WC_Helper_Product::create_simple_product();
+ $product->set_regular_price( 1000.00 );
+ $product->set_tax_status( 'taxable' );
+ $product->save();
- $order = wc_create_order();
- $item = new WC_Order_Item_Product();
- $item->set_props(
- array(
- 'product' => $product,
- 'quantity' => 1,
- 'subtotal' => 1000.00,
- 'total' => 1000.00,
- )
- );
- $item->set_taxes(
- array(
- 'total' => array( $tax_rate_id => 100.00 ),
- 'subtotal' => array( $tax_rate_id => 100.00 ),
- )
- );
- $item->save();
- $order->add_item( $item );
+ $order = wc_create_order();
+ $item = new WC_Order_Item_Product();
+ $item->set_props(
+ array(
+ 'product' => $product,
+ 'quantity' => 1,
+ 'subtotal' => 1000.00,
+ 'total' => 1000.00,
+ )
+ );
+ $item->set_taxes(
+ array(
+ 'total' => array( $tax_rate_id => 100.00 ),
+ 'subtotal' => array( $tax_rate_id => 100.00 ),
+ )
+ );
+ $item->save();
+ $order->add_item( $item );
- $tax_item = new WC_Order_Item_Tax();
- $tax_item->set_rate( $tax_rate_id );
- $tax_item->set_tax_total( 100.00 );
- $tax_item->save();
- $order->add_item( $tax_item );
+ $tax_item = new WC_Order_Item_Tax();
+ $tax_item->set_rate( $tax_rate_id );
+ $tax_item->set_tax_total( 100.00 );
+ $tax_item->save();
+ $order->add_item( $tax_item );
- $order->set_billing_country( 'US' );
- $order->set_total( 1100.00 );
- $order->set_status( OrderStatus::COMPLETED );
- $order->save();
- $this->created_orders[] = $order->get_id();
+ $order->set_billing_country( 'US' );
+ $order->set_total( 1100.00 );
+ $order->set_status( OrderStatus::COMPLETED );
+ $order->save();
+ $this->created_orders[] = $order->get_id();
- // Refund 549 of the 1100 tax-inclusive line. The stored ratio gives
- // 549 * 100/1100 = 49.909..., which rounds to 50 at zero decimals (it would
- // be 49.91 at two), and the net subtotal becomes 549 - 50 = 499. Asserting
- // these whole numbers proves the split honours the currency precision.
- $request = new WP_REST_Request( 'POST', '/wc/v4/refunds' );
- $request->set_body_params(
- array(
- 'order_id' => $order->get_id(),
- 'line_items' => array(
- array(
- 'line_item_id' => $item->get_id(),
- 'refund_total' => 549,
- ),
+ // Refund 549 of the 1100 tax-inclusive line. The stored ratio gives
+ // 549 * 100/1100 = 49.909..., which rounds to 50 at zero decimals (it would
+ // be 49.91 at two), and the net subtotal becomes 549 - 50 = 499. Asserting
+ // these whole numbers proves the split honours the currency precision.
+ $request = new WP_REST_Request( 'POST', '/wc/v4/refunds' );
+ $request->set_body_params(
+ array(
+ 'order_id' => $order->get_id(),
+ 'line_items' => array(
+ array(
+ 'line_item_id' => $item->get_id(),
+ 'refund_total' => 549,
),
- )
- );
- $response = $this->server->dispatch( $request );
+ ),
+ )
+ );
+ $response = $this->server->dispatch( $request );
- $this->assertEquals( 201, $response->get_status() );
- $data = $response->get_data();
- $this->created_refunds[] = $data['id'];
+ $this->assertEquals( 201, $response->get_status() );
+ $data = $response->get_data();
+ $this->created_refunds[] = $data['id'];
- $refund = wc_get_order( $data['id'] );
- $refund_items = $refund->get_items( 'line_item' );
- $refund_line_item = reset( $refund_items );
- $refund_taxes = $refund_line_item->get_taxes();
+ $refund = wc_get_order( $data['id'] );
+ $refund_items = $refund->get_items( 'line_item' );
+ $refund_line_item = reset( $refund_items );
+ $refund_taxes = $refund_line_item->get_taxes();
- $this->assertEquals( -499.0, (float) $refund_line_item->get_total(), 'Net subtotal rounds to a whole number at zero decimals.' );
- $this->assertEquals( -50.0, (float) $refund_taxes['total'][ $tax_rate_id ], 'Tax rounds to a whole number at zero decimals.' );
- $this->assertEquals( 549.0, (float) $data['total'], 'Net + tax must reconstitute the requested amount.' );
+ $this->assertEquals( -499.0, (float) $refund_line_item->get_total(), 'Net subtotal rounds to a whole number at zero decimals.' );
+ $this->assertEquals( -50.0, (float) $refund_taxes['total'][ $tax_rate_id ], 'Tax rounds to a whole number at zero decimals.' );
+ $this->assertEquals( 549.0, (float) $data['total'], 'Net + tax must reconstitute the requested amount.' );
- $product->delete( true );
- } finally {
- remove_filter( 'wc_get_price_decimals', $zero_decimals );
- }
+ $product->delete( true );
}
/**
@@ -4807,80 +4740,75 @@ class WC_REST_Refunds_V4_Controller_Tests extends WC_REST_Unit_Test_Case {
)
);
- $original_prices_include_tax = get_option( 'woocommerce_prices_include_tax', 'no' );
update_option( 'woocommerce_calc_taxes', 'yes' );
update_option( 'woocommerce_prices_include_tax', 'yes' );
- try {
- $product = WC_Helper_Product::create_simple_product();
- $product->set_regular_price( 110.00 );
- $product->set_tax_status( 'taxable' );
- $product->save();
+ $product = WC_Helper_Product::create_simple_product();
+ $product->set_regular_price( 110.00 );
+ $product->set_tax_status( 'taxable' );
+ $product->save();
- $order = wc_create_order();
- $item = new WC_Order_Item_Product();
- $item->set_props(
- array(
- 'product' => $product,
- 'quantity' => 1,
- 'subtotal' => 100.00,
- 'total' => 100.00,
- )
- );
- $item->set_taxes(
- array(
- 'total' => array( $tax_rate_id => 10.00 ),
- 'subtotal' => array( $tax_rate_id => 10.00 ),
- )
- );
- $item->save();
- $order->add_item( $item );
+ $order = wc_create_order();
+ $item = new WC_Order_Item_Product();
+ $item->set_props(
+ array(
+ 'product' => $product,
+ 'quantity' => 1,
+ 'subtotal' => 100.00,
+ 'total' => 100.00,
+ )
+ );
+ $item->set_taxes(
+ array(
+ 'total' => array( $tax_rate_id => 10.00 ),
+ 'subtotal' => array( $tax_rate_id => 10.00 ),
+ )
+ );
+ $item->save();
+ $order->add_item( $item );
- $tax_item = new WC_Order_Item_Tax();
- $tax_item->set_rate( $tax_rate_id );
- $tax_item->set_tax_total( 10.00 );
- $tax_item->save();
- $order->add_item( $tax_item );
+ $tax_item = new WC_Order_Item_Tax();
+ $tax_item->set_rate( $tax_rate_id );
+ $tax_item->set_tax_total( 10.00 );
+ $tax_item->save();
+ $order->add_item( $tax_item );
- $order->set_billing_country( 'US' );
- $order->set_total( 110.00 );
- $order->set_status( OrderStatus::COMPLETED );
- $order->save();
- $this->created_orders[] = $order->get_id();
+ $order->set_billing_country( 'US' );
+ $order->set_total( 110.00 );
+ $order->set_status( OrderStatus::COMPLETED );
+ $order->save();
+ $this->created_orders[] = $order->get_id();
- // Refund $55 of the $110 tax-inclusive line → $50 net, $5 tax, same split as a tax-exclusive store.
- $request = new WP_REST_Request( 'POST', '/wc/v4/refunds' );
- $request->set_body_params(
- array(
- 'order_id' => $order->get_id(),
- 'line_items' => array(
- array(
- 'line_item_id' => $item->get_id(),
- 'refund_total' => 55.00,
- ),
+ // Refund $55 of the $110 tax-inclusive line → $50 net, $5 tax, same split as a tax-exclusive store.
+ $request = new WP_REST_Request( 'POST', '/wc/v4/refunds' );
+ $request->set_body_params(
+ array(
+ 'order_id' => $order->get_id(),
+ 'line_items' => array(
+ array(
+ 'line_item_id' => $item->get_id(),
+ 'refund_total' => 55.00,
),
- )
- );
- $response = $this->server->dispatch( $request );
+ ),
+ )
+ );
+ $response = $this->server->dispatch( $request );
- $this->assertEquals( 201, $response->get_status() );
- $data = $response->get_data();
- $this->created_refunds[] = $data['id'];
+ $this->assertEquals( 201, $response->get_status() );
+ $data = $response->get_data();
+ $this->created_refunds[] = $data['id'];
- $this->assertEquals( '55.00', $data['total'], 'Tax-inclusive store: amount equals the requested tax-inclusive partial.' );
+ $this->assertEquals( '55.00', $data['total'], 'Tax-inclusive store: amount equals the requested tax-inclusive partial.' );
- $refund = wc_get_order( $data['id'] );
- $refund_items = $refund->get_items( 'line_item' );
- $refund_line_item = reset( $refund_items );
- $refund_taxes = $refund_line_item->get_taxes();
+ $refund = wc_get_order( $data['id'] );
+ $refund_items = $refund->get_items( 'line_item' );
+ $refund_line_item = reset( $refund_items );
+ $refund_taxes = $refund_line_item->get_taxes();
- $this->assertEquals( -50.00, (float) $refund_line_item->get_total(), 'Stored net total should be half of $100.' );
- $this->assertEquals( -5.00, (float) $refund_taxes['total'][ $tax_rate_id ], 'Stored tax should be half of $10, not re-extracted.' );
+ $this->assertEquals( -50.00, (float) $refund_line_item->get_total(), 'Stored net total should be half of $100.' );
+ $this->assertEquals( -5.00, (float) $refund_taxes['total'][ $tax_rate_id ], 'Stored tax should be half of $10, not re-extracted.' );
- $product->delete( true );
- } finally {
- update_option( 'woocommerce_prices_include_tax', $original_prices_include_tax );
- }
+ $product->delete( true );
}
/**
diff --git a/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version4/Refunds/class-wc-rest-refunds-v4-preview-tests.php b/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version4/Refunds/class-wc-rest-refunds-v4-preview-tests.php
index 60bbea6d39f..0d4398587f6 100644
--- a/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version4/Refunds/class-wc-rest-refunds-v4-preview-tests.php
+++ b/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version4/Refunds/class-wc-rest-refunds-v4-preview-tests.php
@@ -1604,27 +1604,23 @@ class WC_REST_Refunds_V4_Preview_Tests extends WC_REST_Unit_Test_Case {
// Switch to a zero-decimal currency for the request only.
add_filter( 'wc_get_price_decimals', '__return_zero' );
- try {
- $response = $this->do_preview_request(
- $order->get_id(),
+ $response = $this->do_preview_request(
+ $order->get_id(),
+ array(
array(
- array(
- 'line_item_id' => $item_id,
- 'refund_total' => 55.4,
- ),
- )
- );
+ 'line_item_id' => $item_id,
+ 'refund_total' => 55.4,
+ ),
+ )
+ );
- $this->assertEquals( 200, $response->get_status() );
- $item = $response->get_data()['breakdown']['products']['items'][0];
+ $this->assertEquals( 200, $response->get_status() );
+ $item = $response->get_data()['breakdown']['products']['items'][0];
- // 55.4 rounds to 55 at 0dp; the 10% split gives whole-unit 50 net / 5 tax.
- $this->assertEquals( '55', $item['total'], 'Total should round to a whole unit.' );
- $this->assertEquals( '5', $item['tax'] );
- $this->assertEquals( '50', $item['subtotal'] );
- } finally {
- remove_filter( 'wc_get_price_decimals', '__return_zero' );
- }
+ // 55.4 rounds to 55 at 0dp; the 10% split gives whole-unit 50 net / 5 tax.
+ $this->assertEquals( '55', $item['total'], 'Total should round to a whole unit.' );
+ $this->assertEquals( '5', $item['tax'] );
+ $this->assertEquals( '50', $item['subtotal'] );
}
/**
diff --git a/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version4/ShippingZoneMethod/class-wc-rest-shipping-zone-method-v4-controller-tests.php b/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version4/ShippingZoneMethod/class-wc-rest-shipping-zone-method-v4-controller-tests.php
index 5fd31d9aad8..17912657578 100644
--- a/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version4/ShippingZoneMethod/class-wc-rest-shipping-zone-method-v4-controller-tests.php
+++ b/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version4/ShippingZoneMethod/class-wc-rest-shipping-zone-method-v4-controller-tests.php
@@ -152,9 +152,6 @@ class WC_REST_Shipping_Zone_Method_V4_Controller_Tests extends WC_REST_Unit_Test
$this->assertInstanceOf( WP_Error::class, $result );
$this->assertEquals( 'rest_shipping_disabled', $result->get_error_code() );
$this->assertEquals( WP_Http::SERVICE_UNAVAILABLE, $result->get_error_data()['status'] );
-
- // Re-enable shipping.
- remove_filter( 'wc_shipping_enabled', '__return_false' );
}
/**
diff --git a/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version4/ShippingZones/class-wc-rest-shipping-zones-v4-controller-tests.php b/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version4/ShippingZones/class-wc-rest-shipping-zones-v4-controller-tests.php
index f8a066ef047..8aa501afc85 100644
--- a/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version4/ShippingZones/class-wc-rest-shipping-zones-v4-controller-tests.php
+++ b/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version4/ShippingZones/class-wc-rest-shipping-zones-v4-controller-tests.php
@@ -400,8 +400,6 @@ class WC_REST_Shipping_Zones_V4_Controller_Tests extends WC_Unit_Test_Case {
// Should be denied because delete permission is blocked.
$this->assertInstanceOf( WP_Error::class, $result );
-
- remove_filter( 'woocommerce_rest_check_permissions', $filter_callback, 10 );
}
/**
@@ -422,8 +420,6 @@ class WC_REST_Shipping_Zones_V4_Controller_Tests extends WC_Unit_Test_Case {
// Should be denied because read permission is blocked.
$this->assertInstanceOf( WP_Error::class, $result );
-
- remove_filter( 'woocommerce_rest_check_permissions', $filter_callback, 10 );
}
/**
@@ -626,9 +622,6 @@ class WC_REST_Shipping_Zones_V4_Controller_Tests extends WC_Unit_Test_Case {
$this->assertEquals( 'woocommerce_rest_api_v4_shipping_zones_disabled', $data['code'] );
$this->assertArrayHasKey( 'message', $data );
$this->assertEquals( 'Shipping is disabled.', $data['message'] );
-
- // Re-enable shipping.
- remove_filter( 'wc_shipping_enabled', '__return_false' );
}
/**
@@ -743,9 +736,6 @@ class WC_REST_Shipping_Zones_V4_Controller_Tests extends WC_Unit_Test_Case {
$this->assertEquals( 'woocommerce_rest_api_v4_shipping_zones_disabled', $data['code'] );
$this->assertArrayHasKey( 'message', $data );
$this->assertEquals( 'Shipping is disabled.', $data['message'] );
-
- // Re-enable shipping.
- remove_filter( 'wc_shipping_enabled', '__return_false' );
}
/**
@@ -1081,9 +1071,6 @@ class WC_REST_Shipping_Zones_V4_Controller_Tests extends WC_Unit_Test_Case {
$this->assertEquals( 503, $response->get_status() );
$this->assertArrayHasKey( 'code', $data );
$this->assertEquals( 'woocommerce_rest_api_v4_shipping_zones_disabled', $data['code'] );
-
- // Re-enable shipping.
- remove_filter( 'wc_shipping_enabled', '__return_false' );
}
/**
@@ -1683,9 +1670,6 @@ class WC_REST_Shipping_Zones_V4_Controller_Tests extends WC_Unit_Test_Case {
$this->assertEquals( 503, $response->get_status() );
$this->assertArrayHasKey( 'code', $data );
$this->assertEquals( 'woocommerce_rest_api_v4_shipping_zones_disabled', $data['code'] );
-
- // Re-enable shipping.
- remove_filter( 'wc_shipping_enabled', '__return_false' );
}
/**
diff --git a/plugins/woocommerce/tests/php/includes/rest-api/class-wc-rest-authentication-tests.php b/plugins/woocommerce/tests/php/includes/rest-api/class-wc-rest-authentication-tests.php
index fa36c3d130f..ef1d30ed337 100644
--- a/plugins/woocommerce/tests/php/includes/rest-api/class-wc-rest-authentication-tests.php
+++ b/plugins/woocommerce/tests/php/includes/rest-api/class-wc-rest-authentication-tests.php
@@ -385,11 +385,7 @@ class WC_REST_Authentication_Tests extends WC_REST_Unit_Test_Case {
$this->simulate_rest_dispatching( true );
$_SERVER['REQUEST_URI'] = $request_uri;
- try {
- $this->assertSame( $expected, $this->is_request_to_rest_api() );
- } finally {
- remove_filter( 'option_home', $home_filter );
- }
+ $this->assertSame( $expected, $this->is_request_to_rest_api() );
}
/**
@@ -532,20 +528,16 @@ class WC_REST_Authentication_Tests extends WC_REST_Unit_Test_Case {
add_filter( 'woocommerce_rest_is_request_to_rest_api', '__return_true' );
- try {
- $this->assertTrue(
- $this->is_request_to_rest_api(),
- 'A namespace opted in through the filter must be treated as a WooCommerce request.'
- );
+ $this->assertTrue(
+ $this->is_request_to_rest_api(),
+ 'A namespace opted in through the filter must be treated as a WooCommerce request.'
+ );
- $this->simulate_rest_dispatching( false );
- $this->assertFalse(
- $this->is_request_to_rest_api(),
- 'The filter must not opt in a request WordPress is not dispatching as REST.'
- );
- } finally {
- remove_filter( 'woocommerce_rest_is_request_to_rest_api', '__return_true' );
- }
+ $this->simulate_rest_dispatching( false );
+ $this->assertFalse(
+ $this->is_request_to_rest_api(),
+ 'The filter must not opt in a request WordPress is not dispatching as REST.'
+ );
}
/**
diff --git a/plugins/woocommerce/tests/php/includes/shortcodes/class-wc-shortcode-my-account-password-reset-test.php b/plugins/woocommerce/tests/php/includes/shortcodes/class-wc-shortcode-my-account-password-reset-test.php
index 38dd820fc5d..cb8c2305a61 100644
--- a/plugins/woocommerce/tests/php/includes/shortcodes/class-wc-shortcode-my-account-password-reset-test.php
+++ b/plugins/woocommerce/tests/php/includes/shortcodes/class-wc-shortcode-my-account-password-reset-test.php
@@ -199,11 +199,7 @@ class WC_Shortcode_My_Account_Password_Reset_Test extends WC_Unit_Test_Case {
$token = $this->create_exchanged_form_token();
add_filter( 'password_reset_expiration', '__return_zero' );
- try {
- $this->assertFalse( WC_Shortcode_My_Account::check_password_reset_key( $token, $this->user->user_login ) );
- } finally {
- remove_filter( 'password_reset_expiration', '__return_zero' );
- }
+ $this->assertFalse( WC_Shortcode_My_Account::check_password_reset_key( $token, $this->user->user_login ) );
}
/**
diff --git a/plugins/woocommerce/tests/php/includes/tracks/class-wc-site-tracking-tests.php b/plugins/woocommerce/tests/php/includes/tracks/class-wc-site-tracking-tests.php
index 4521e2669d3..295d22b6728 100644
--- a/plugins/woocommerce/tests/php/includes/tracks/class-wc-site-tracking-tests.php
+++ b/plugins/woocommerce/tests/php/includes/tracks/class-wc-site-tracking-tests.php
@@ -37,7 +37,5 @@ class WC_Site_Tracking_Tests extends WC_Unit_Test_Case {
update_option( 'woocommerce_allow_tracking', 'no' );
WC_Site_Tracking::set_tracking_cookie( 'bar', 'baz' );
$this->assertNotEquals( 'bar', $last_cookie_key, 'When tracking is disabled, a tracking cookie cannot be set.' );
-
- remove_filter( 'woocommerce_set_cookie_enabled', $watch_wc_cookie );
}
}
diff --git a/plugins/woocommerce/tests/php/includes/tracks/class-wc-tracks-client-test.php b/plugins/woocommerce/tests/php/includes/tracks/class-wc-tracks-client-test.php
index 580f1be63d5..8de493f56fd 100644
--- a/plugins/woocommerce/tests/php/includes/tracks/class-wc-tracks-client-test.php
+++ b/plugins/woocommerce/tests/php/includes/tracks/class-wc-tracks-client-test.php
@@ -303,9 +303,6 @@ class WC_Tracks_Client_Test extends \WC_Unit_Test_Case {
// Queue should be empty since batching is disabled.
$queue = $this->get_batch_queue();
$this->assertEmpty( $queue, 'Queue should be empty when batching is disabled via filter.' );
-
- // Clean up filter.
- remove_filter( 'wc_tracks_use_batch_requests', '__return_false' );
}
/**
@@ -328,9 +325,6 @@ class WC_Tracks_Client_Test extends \WC_Unit_Test_Case {
// Queue should have the pixel.
$queue = $this->get_batch_queue();
$this->assertCount( 1, $queue );
-
- // Clean up filter.
- remove_filter( 'wc_tracks_use_batch_requests', '__return_true' );
}
/**
@@ -513,8 +507,5 @@ class WC_Tracks_Client_Test extends \WC_Unit_Test_Case {
// Verify that HTTP request was intercepted.
$this->assertCount( 1, $this->intercepted_requests, 'Should have intercepted 1 HTTP request.' );
$this->assertStringContainsString( '_en=fallback_event', $this->intercepted_requests[0]['url'] );
-
- // Clean up filter.
- remove_filter( 'wc_tracks_use_batch_requests', '__return_false' );
}
}
diff --git a/plugins/woocommerce/tests/php/includes/wc-core-functions-test.php b/plugins/woocommerce/tests/php/includes/wc-core-functions-test.php
index 3583aab858f..d6a6fbf3e44 100644
--- a/plugins/woocommerce/tests/php/includes/wc-core-functions-test.php
+++ b/plugins/woocommerce/tests/php/includes/wc-core-functions-test.php
@@ -570,8 +570,6 @@ class WC_Core_Functions_Test extends \WC_Unit_Test_Case {
$actual = wc_get_rounding_precision();
$this->assertEquals( $expected, $actual );
-
- remove_all_filters( 'wc_get_price_decimals' );
}
/**
@@ -603,8 +601,6 @@ class WC_Core_Functions_Test extends \WC_Unit_Test_Case {
$actual = wc_add_number_precision( $value, $round );
$this->assertFloatEquals( $expected, $actual );
-
- remove_all_filters( 'wc_get_price_decimals' );
}
/**
@@ -627,8 +623,6 @@ class WC_Core_Functions_Test extends \WC_Unit_Test_Case {
$actual = wc_remove_number_precision( $value );
$this->assertEquals( $expected, $actual );
-
- remove_all_filters( 'wc_get_price_decimals' );
}
/**
@@ -728,7 +722,6 @@ class WC_Core_Functions_Test extends \WC_Unit_Test_Case {
$result = wc_get_customer_default_location();
$this->assertEquals( 'GB', $result['country'] );
$this->assertEquals( '', $result['state'] );
- remove_all_filters( 'woocommerce_geolocate_ip' );
}
/**
diff --git a/plugins/woocommerce/tests/php/includes/wc-product-functions-test.php b/plugins/woocommerce/tests/php/includes/wc-product-functions-test.php
index d07cc23681d..ced562a0d4e 100644
--- a/plugins/woocommerce/tests/php/includes/wc-product-functions-test.php
+++ b/plugins/woocommerce/tests/php/includes/wc-product-functions-test.php
@@ -775,8 +775,6 @@ class WC_Product_Functions_Tests extends \WC_Unit_Test_Case {
add_filter( 'woocommerce_product_get_price', $callback, 50, 2 );
$this->assertEquals( 50, wc_get_product( $product_id )->get_price(), 'A deliberate third-party price is respected, not reverted to the sale price.' );
-
- remove_filter( 'woocommerce_product_get_price', $callback, 50 );
}
/**
@@ -808,8 +806,6 @@ class WC_Product_Functions_Tests extends \WC_Unit_Test_Case {
wc_get_product( $product_id )->get_price(),
'The third-party price wins over the scheduled-sale heal (which would otherwise return 20).'
);
-
- remove_filter( 'woocommerce_product_get_price', $callback, 50 );
}
/**
@@ -1575,8 +1571,6 @@ class WC_Product_Functions_Tests extends \WC_Unit_Test_Case {
* @testdox Assigned-customer orders apply matched rates for the editor tax location and pass the order customer to the filter.
*/
public function test_wc_get_price_excluding_tax_editor_location_filters_customer_rates(): void {
- $original_calc_taxes = get_option( 'woocommerce_calc_taxes' );
- $original_prices_include_tax = get_option( 'woocommerce_prices_include_tax' );
update_option( 'woocommerce_calc_taxes', 'yes' );
update_option( 'woocommerce_prices_include_tax', 'yes' );
@@ -1640,8 +1634,6 @@ class WC_Product_Functions_Tests extends \WC_Unit_Test_Case {
WC_Tax::_delete_tax_rate( $french_tax_rate_id );
$order->delete( true );
wp_delete_user( $customer->get_id() );
- update_option( 'woocommerce_calc_taxes', $original_calc_taxes );
- update_option( 'woocommerce_prices_include_tax', $original_prices_include_tax );
}
}
@@ -3059,7 +3051,6 @@ class WC_Product_Functions_Tests extends \WC_Unit_Test_Case {
wp_delete_attachment( $attachment_id, true );
WC_Helper_Product::delete_product( $product->get_id() );
wp_delete_user( $subscriber_id );
- delete_option( 'woocommerce_product_match_featured_image_by_sku' );
}
}
diff --git a/plugins/woocommerce/tests/php/includes/wc-rest-functions-test.php b/plugins/woocommerce/tests/php/includes/wc-rest-functions-test.php
index f509a944689..53b0e9ee6a7 100644
--- a/plugins/woocommerce/tests/php/includes/wc-rest-functions-test.php
+++ b/plugins/woocommerce/tests/php/includes/wc-rest-functions-test.php
@@ -62,6 +62,5 @@ class WCRestFunctionsTest extends WC_REST_Unit_Test_Case {
$this->assertFalse( wc_rest_should_load_namespace( 'wc/v1', 'wc/v2' ) );
add_filter( 'wc_rest_should_load_namespace', '__return_true' );
$this->assertTrue( wc_rest_should_load_namespace( 'wc/v1', 'wc/v2' ) );
- remove_filter( 'wc_rest_should_load_namespace', '__return_true' );
}
}
diff --git a/plugins/woocommerce/tests/php/includes/wc-template-functions-test.php b/plugins/woocommerce/tests/php/includes/wc-template-functions-test.php
index bb1d069c4ca..323a1bfee0f 100644
--- a/plugins/woocommerce/tests/php/includes/wc-template-functions-test.php
+++ b/plugins/woocommerce/tests/php/includes/wc-template-functions-test.php
@@ -201,8 +201,6 @@ class WC_Template_Functions_Tests extends \WC_Unit_Test_Case {
$this->assertFalse( wp_cache_get( $cache_key, 'product_cat' ) );
// Result should be empty too (query with empty taxonomy returns nothing).
$this->assertEmpty( $result );
-
- remove_filter( 'woocommerce_product_subcategories_args', $filter );
}
/**
@@ -222,8 +220,6 @@ class WC_Template_Functions_Tests extends \WC_Unit_Test_Case {
// Cache should remain empty because taxonomy was removed.
$this->assertFalse( wp_cache_get( $cache_key, 'product_cat' ) );
-
- remove_filter( 'woocommerce_product_subcategories_args', $filter );
}
/**
diff --git a/plugins/woocommerce/tests/php/includes/wc-update-functions-test.php b/plugins/woocommerce/tests/php/includes/wc-update-functions-test.php
index 70ef3be6906..7d68fc7efe8 100644
--- a/plugins/woocommerce/tests/php/includes/wc-update-functions-test.php
+++ b/plugins/woocommerce/tests/php/includes/wc-update-functions-test.php
@@ -135,8 +135,6 @@ class WC_Update_Functions_Test extends \WC_Unit_Test_Case {
wc_update_920_add_wc_hooked_blocks_version_option();
$this->assertEquals( 'no', get_option( 'woocommerce_hooked_blocks_version' ) );
-
- remove_filter( 'woocommerce_hooked_blocks_theme_include_list', '__return_empty_array', 999, 1 );
}
/**
@@ -1221,8 +1219,6 @@ class WC_Update_Functions_Test extends \WC_Unit_Test_Case {
update_option( 'woocommerce_use_legacy_get_variations_price_hash', 'no' );
wc_update_1130_set_legacy_variation_price_hash_option();
$this->assertSame( 'no', get_option( 'woocommerce_use_legacy_get_variations_price_hash' ), 'Migration must not overwrite an existing option.' );
-
- delete_option( 'woocommerce_use_legacy_get_variations_price_hash' );
}
/**
diff --git a/plugins/woocommerce/tests/php/includes/widgets/class-wc-widget-top-rated-products-test.php b/plugins/woocommerce/tests/php/includes/widgets/class-wc-widget-top-rated-products-test.php
index 4664c821b62..b4a1727ddb6 100644
--- a/plugins/woocommerce/tests/php/includes/widgets/class-wc-widget-top-rated-products-test.php
+++ b/plugins/woocommerce/tests/php/includes/widgets/class-wc-widget-top-rated-products-test.php
@@ -130,14 +130,10 @@ class WC_Widget_Top_Rated_Products_Test extends \WC_Unit_Test_Case {
add_filter( 'woocommerce_top_rated_products_widget_args', $order_by_id );
- try {
- $this->assertSame(
- array( $ids[2], $ids[1], $ids[0] ),
- $this->rating_ordered_ids(),
- 'A filter that changes orderby should decide the ordering.'
- );
- } finally {
- remove_filter( 'woocommerce_top_rated_products_widget_args', $order_by_id );
- }
+ $this->assertSame(
+ array( $ids[2], $ids[1], $ids[0] ),
+ $this->rating_ordered_ids(),
+ 'A filter that changes orderby should decide the ordering.'
+ );
}
}
diff --git a/plugins/woocommerce/tests/php/src/Admin/API/MobileAppQRLoginTest.php b/plugins/woocommerce/tests/php/src/Admin/API/MobileAppQRLoginTest.php
index acb9a1e8761..83a8403c4e2 100644
--- a/plugins/woocommerce/tests/php/src/Admin/API/MobileAppQRLoginTest.php
+++ b/plugins/woocommerce/tests/php/src/Admin/API/MobileAppQRLoginTest.php
@@ -749,14 +749,10 @@ class MobileAppQRLoginTest extends WC_Unit_Test_Case {
};
add_filter( 'site_url', $downgrade_site_url );
- try {
- $response = $this->dispatch_generate();
+ $response = $this->dispatch_generate();
- $this->assertSame( 500, $response->get_status() );
- $this->assertSame( 'insecure_site_url', $response->get_data()['code'] );
- } finally {
- remove_filter( 'site_url', $downgrade_site_url );
- }
+ $this->assertSame( 500, $response->get_status() );
+ $this->assertSame( 'insecure_site_url', $response->get_data()['code'] );
}
/**
@@ -801,14 +797,10 @@ class MobileAppQRLoginTest extends WC_Unit_Test_Case {
add_filter( 'wp_is_application_passwords_available', '__return_false' );
- try {
- $response = $this->dispatch_generate();
+ $response = $this->dispatch_generate();
- $this->assertSame( 501, $response->get_status() );
- $this->assertSame( 'application_passwords_unavailable', $response->get_data()['code'] );
- } finally {
- remove_filter( 'wp_is_application_passwords_available', '__return_false' );
- }
+ $this->assertSame( 501, $response->get_status() );
+ $this->assertSame( 'application_passwords_unavailable', $response->get_data()['code'] );
}
/**
@@ -821,20 +813,16 @@ class MobileAppQRLoginTest extends WC_Unit_Test_Case {
// Disable APs only for the exchange itself.
add_filter( 'wp_is_application_passwords_available', '__return_false' );
- try {
- $response = $this->dispatch_exchange( $prep['plaintext'], $prep['exchange_grant'] );
+ $response = $this->dispatch_exchange( $prep['plaintext'], $prep['exchange_grant'] );
- $this->assertSame( 501, $response->get_status() );
- $this->assertSame( 'application_passwords_unavailable', $response->get_data()['code'] );
- $this->assertCount( 0, WP_Application_Passwords::get_user_application_passwords( $this->admin_id ) );
- $this->assertSame(
- MobileAppQRLogin::STATE_APPROVED,
- get_transient( $this->token_transient_key( $prep['plaintext'] ) )['state']
- );
- $this->assertFalse( get_option( $this->token_claim_key( $prep['plaintext'] ), false ) );
- } finally {
- remove_filter( 'wp_is_application_passwords_available', '__return_false' );
- }
+ $this->assertSame( 501, $response->get_status() );
+ $this->assertSame( 'application_passwords_unavailable', $response->get_data()['code'] );
+ $this->assertCount( 0, WP_Application_Passwords::get_user_application_passwords( $this->admin_id ) );
+ $this->assertSame(
+ MobileAppQRLogin::STATE_APPROVED,
+ get_transient( $this->token_transient_key( $prep['plaintext'] ) )['state']
+ );
+ $this->assertFalse( get_option( $this->token_claim_key( $prep['plaintext'] ), false ) );
}
/**
@@ -851,18 +839,14 @@ class MobileAppQRLoginTest extends WC_Unit_Test_Case {
};
add_filter( 'map_meta_cap', $deny_create_app_password, 10, 2 );
- try {
- wp_set_current_user( 0 );
- $response = $this->dispatch_exchange( $prep['plaintext'], $prep['exchange_grant'] );
+ wp_set_current_user( 0 );
+ $response = $this->dispatch_exchange( $prep['plaintext'], $prep['exchange_grant'] );
- $this->assertSame( rest_authorization_required_code(), $response->get_status() );
- $this->assertSame( 'rest_cannot_create_application_passwords', $response->get_data()['code'] );
- $this->assertCount( 0, WP_Application_Passwords::get_user_application_passwords( $this->admin_id ) );
- $this->assertIsArray( get_transient( $this->token_transient_key( $prep['plaintext'] ) ) );
- $this->assertFalse( get_option( $this->token_claim_key( $prep['plaintext'] ), false ) );
- } finally {
- remove_filter( 'map_meta_cap', $deny_create_app_password, 10 );
- }
+ $this->assertSame( rest_authorization_required_code(), $response->get_status() );
+ $this->assertSame( 'rest_cannot_create_application_passwords', $response->get_data()['code'] );
+ $this->assertCount( 0, WP_Application_Passwords::get_user_application_passwords( $this->admin_id ) );
+ $this->assertIsArray( get_transient( $this->token_transient_key( $prep['plaintext'] ) ) );
+ $this->assertFalse( get_option( $this->token_claim_key( $prep['plaintext'] ), false ) );
}
/**
@@ -1220,28 +1204,24 @@ class MobileAppQRLoginTest extends WC_Unit_Test_Case {
add_filter( 'wp_is_application_passwords_available', '__return_false' );
- try {
- for ( $i = 1; $i <= MobileAppQRLogin::MAX_EXCHANGE_ATTEMPTS; $i++ ) {
- $response = $this->dispatch_exchange( $prep['plaintext'], $prep['exchange_grant'] );
- $this->assertSame(
- 501,
- $response->get_status(),
- sprintf( 'Application Passwords unavailable response expected before the valid-token cap, got %d on attempt %d.', $response->get_status(), $i )
- );
- }
-
+ for ( $i = 1; $i <= MobileAppQRLogin::MAX_EXCHANGE_ATTEMPTS; $i++ ) {
$response = $this->dispatch_exchange( $prep['plaintext'], $prep['exchange_grant'] );
-
- $this->assertSame( 429, $response->get_status() );
- $this->assertSame( 'rate_limit_exceeded', $response->get_data()['code'] );
$this->assertSame(
- MobileAppQRLogin::STATE_APPROVED,
- get_transient( $this->token_transient_key( $prep['plaintext'] ) )['state']
+ 501,
+ $response->get_status(),
+ sprintf( 'Application Passwords unavailable response expected before the valid-token cap, got %d on attempt %d.', $response->get_status(), $i )
);
- $this->assertFalse( get_option( $this->token_claim_key( $prep['plaintext'] ), false ) );
- } finally {
- remove_filter( 'wp_is_application_passwords_available', '__return_false' );
- }//end try
+ }
+
+ $response = $this->dispatch_exchange( $prep['plaintext'], $prep['exchange_grant'] );
+
+ $this->assertSame( 429, $response->get_status() );
+ $this->assertSame( 'rate_limit_exceeded', $response->get_data()['code'] );
+ $this->assertSame(
+ MobileAppQRLogin::STATE_APPROVED,
+ get_transient( $this->token_transient_key( $prep['plaintext'] ) )['state']
+ );
+ $this->assertFalse( get_option( $this->token_claim_key( $prep['plaintext'] ), false ) );
}
// -----------------------------------------------------------------------
@@ -2291,8 +2271,6 @@ class MobileAppQRLoginTest extends WC_Unit_Test_Case {
get_option( $claim_key ),
'A rejected second scan must not release another request\'s claim.'
);
-
- delete_option( $claim_key );
}
/**
@@ -2313,8 +2291,6 @@ class MobileAppQRLoginTest extends WC_Unit_Test_Case {
$this->assertFalse( $method->invoke( $controller, $claim_key, $stale_claim_value ) );
$this->assertSame( $fresh_claim_value, get_option( $claim_key ) );
-
- delete_option( $claim_key );
}
/**
@@ -2350,8 +2326,6 @@ class MobileAppQRLoginTest extends WC_Unit_Test_Case {
get_option( $claim_key ),
'A rejected concurrent approval must not release another request\'s claim.'
);
-
- delete_option( $claim_key );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Admin/API/OptionsPermissionsTest.php b/plugins/woocommerce/tests/php/src/Admin/API/OptionsPermissionsTest.php
index 3283a44d906..c8d409e0add 100644
--- a/plugins/woocommerce/tests/php/src/Admin/API/OptionsPermissionsTest.php
+++ b/plugins/woocommerce/tests/php/src/Admin/API/OptionsPermissionsTest.php
@@ -99,17 +99,13 @@ class OptionsPermissionsTest extends WC_REST_Unit_Test_Case {
add_filter( 'woocommerce_rest_api_option_permissions', $grant_permission );
$this->setExpectedDeprecated( 'woocommerce_rest_api_option_permissions' );
- try {
- $read_response = $this->get_options( array( self::UNLISTED_OPTION ) );
- $this->assertSame( 200, $read_response->get_status(), 'A filtered option should be readable.' );
- $this->assertSame( 'original', $read_response->get_data()[ self::UNLISTED_OPTION ], 'The filtered option should return its stored value.' );
-
- $write_response = $this->post_options( array( self::UNLISTED_OPTION => 'changed' ) );
- $this->assertSame( 200, $write_response->get_status(), 'A filtered option should be writable.' );
- $this->assertSame( 'changed', get_option( self::UNLISTED_OPTION ), 'The filtered option should be updated.' );
- } finally {
- remove_filter( 'woocommerce_rest_api_option_permissions', $grant_permission );
- }
+ $read_response = $this->get_options( array( self::UNLISTED_OPTION ) );
+ $this->assertSame( 200, $read_response->get_status(), 'A filtered option should be readable.' );
+ $this->assertSame( 'original', $read_response->get_data()[ self::UNLISTED_OPTION ], 'The filtered option should return its stored value.' );
+
+ $write_response = $this->post_options( array( self::UNLISTED_OPTION => 'changed' ) );
+ $this->assertSame( 200, $write_response->get_status(), 'A filtered option should be writable.' );
+ $this->assertSame( 'changed', get_option( self::UNLISTED_OPTION ), 'The filtered option should be updated.' );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Admin/API/PaymentGatewaySuggestionsTest.php b/plugins/woocommerce/tests/php/src/Admin/API/PaymentGatewaySuggestionsTest.php
index 822fa0ea6b6..28da72bbbf5 100644
--- a/plugins/woocommerce/tests/php/src/Admin/API/PaymentGatewaySuggestionsTest.php
+++ b/plugins/woocommerce/tests/php/src/Admin/API/PaymentGatewaySuggestionsTest.php
@@ -48,7 +48,6 @@ class PaymentGatewaySuggestionsTest extends WC_REST_Unit_Test_Case {
// Clear any existing cache first.
Init::delete_specs_transient();
- $existing_base_country = wc_get_base_location();
// update the base country to the U.S for testing purposes.
update_option( 'woocommerce_default_country', 'US:CA' );
@@ -90,11 +89,5 @@ class PaymentGatewaySuggestionsTest extends WC_REST_Unit_Test_Case {
// Make a new request -- this should populate the cache with the updated country.
$response = rest_get_server()->dispatch( $request )->get_data();
$this->assertEquals( 'CA', $response[0]->id );
-
- // Clean up.
- remove_filter( 'pre_http_request', $response_mock_ref );
-
- // restore the base country.
- update_option( 'woocommerce_default_country', $existing_base_country['country'] . ':' . $existing_base_country['state'] );
}
}
diff --git a/plugins/woocommerce/tests/php/src/Admin/API/Reports/Orders/Stats/DataStoreBasicsTest.php b/plugins/woocommerce/tests/php/src/Admin/API/Reports/Orders/Stats/DataStoreBasicsTest.php
index fe6b050111c..6d3efc581b2 100644
--- a/plugins/woocommerce/tests/php/src/Admin/API/Reports/Orders/Stats/DataStoreBasicsTest.php
+++ b/plugins/woocommerce/tests/php/src/Admin/API/Reports/Orders/Stats/DataStoreBasicsTest.php
@@ -390,9 +390,7 @@ class DataStoreBasicsTest extends OrdersStatsTestCase {
);
// Enable taxes.
- $default_calc_taxes = get_option( 'woocommerce_calc_taxes', 'no' );
$default_customer_address = get_option( 'woocommerce_default_customer_address', 'geolocation' );
- $default_tax_based_on = get_option( 'woocommerce_tax_based_on', 'shipping' );
update_option( 'woocommerce_calc_taxes', 'yes' );
update_option( 'woocommerce_default_customer_address', 'base' );
update_option( 'woocommerce_tax_based_on', 'base' );
@@ -461,9 +459,6 @@ class DataStoreBasicsTest extends OrdersStatsTestCase {
$this->assertEmpty( $results );
}
- // Reset taxes settings.
- update_option( 'woocommerce_calc_taxes', $default_calc_taxes );
update_option( 'woocommerce_default_customer_address', $default_customer_address );
- update_option( 'woocommerce_tax_based_on', $default_tax_based_on );
}
}
diff --git a/plugins/woocommerce/tests/php/src/Admin/API/Reports/TimeIntervalTest.php b/plugins/woocommerce/tests/php/src/Admin/API/Reports/TimeIntervalTest.php
index d1cc1e27dfb..d1b49d2ba69 100644
--- a/plugins/woocommerce/tests/php/src/Admin/API/Reports/TimeIntervalTest.php
+++ b/plugins/woocommerce/tests/php/src/Admin/API/Reports/TimeIntervalTest.php
@@ -45,29 +45,24 @@ class TimeIntervalTest extends WC_Unit_Test_Case {
* production-path guarantee lives in TotalPaymentsVolumeProcessorTest.
*/
public function test_timeframes_default_to_site_timezone_now(): void {
- $timeframes = array( 'last_week', 'last_month', 'last_quarter', 'last_6_months', 'last_year' );
- $original_timezone = get_option( 'timezone_string' );
+ $timeframes = array( 'last_week', 'last_month', 'last_quarter', 'last_6_months', 'last_year' );
- try {
- // Extreme offsets on both sides of UTC maximize the window where the site-local date differs from the UTC date.
- foreach ( array( 'Pacific/Kiritimati', 'Pacific/Midway' ) as $timezone ) {
- update_option( 'timezone_string', $timezone );
+ // Extreme offsets on both sides of UTC maximize the window where the site-local date differs from the UTC date.
+ foreach ( array( 'Pacific/Kiritimati', 'Pacific/Midway' ) as $timezone ) {
+ update_option( 'timezone_string', $timezone );
- foreach ( $timeframes as $timeframe ) {
- // Compute the expectation before and after the call so the assertion also holds if midnight passes mid-test.
- $expected_before = TimeInterval::get_timeframe_dates( $timeframe, new DateTime( 'now', wp_timezone() ) );
- $actual = TimeInterval::get_timeframe_dates( $timeframe );
- $expected_after = TimeInterval::get_timeframe_dates( $timeframe, new DateTime( 'now', wp_timezone() ) );
+ foreach ( $timeframes as $timeframe ) {
+ // Compute the expectation before and after the call so the assertion also holds if midnight passes mid-test.
+ $expected_before = TimeInterval::get_timeframe_dates( $timeframe, new DateTime( 'now', wp_timezone() ) );
+ $actual = TimeInterval::get_timeframe_dates( $timeframe );
+ $expected_after = TimeInterval::get_timeframe_dates( $timeframe, new DateTime( 'now', wp_timezone() ) );
- $this->assertContains(
- $actual,
- array( $expected_before, $expected_after ),
- "Default \"$timeframe\" dates should be based on the current date in the $timezone site timezone"
- );
- }
+ $this->assertContains(
+ $actual,
+ array( $expected_before, $expected_after ),
+ "Default \"$timeframe\" dates should be based on the current date in the $timezone site timezone"
+ );
}
- } finally {
- update_option( 'timezone_string', $original_timezone );
}
}
}
diff --git a/plugins/woocommerce/tests/php/src/Admin/Features/Analytics/FeatureEnabledTest.php b/plugins/woocommerce/tests/php/src/Admin/Features/Analytics/FeatureEnabledTest.php
index 263527e7e75..4ab6210f269 100644
--- a/plugins/woocommerce/tests/php/src/Admin/Features/Analytics/FeatureEnabledTest.php
+++ b/plugins/woocommerce/tests/php/src/Admin/Features/Analytics/FeatureEnabledTest.php
@@ -40,14 +40,10 @@ class FeatureEnabledTest extends WC_Unit_Test_Case {
public function test_should_be_disabled_when_removed_from_legacy_admin_features(): void {
add_filter( 'woocommerce_admin_features', array( $this, 'disable_analytics_feature' ), PHP_INT_MAX );
- try {
- $this->assertFalse(
- FeaturesUtil::feature_is_enabled( 'analytics' ),
- 'Analytics should be disabled when removed from the legacy admin feature list.'
- );
- } finally {
- remove_filter( 'woocommerce_admin_features', array( $this, 'disable_analytics_feature' ), PHP_INT_MAX );
- }
+ $this->assertFalse(
+ FeaturesUtil::feature_is_enabled( 'analytics' ),
+ 'Analytics should be disabled when removed from the legacy admin feature list.'
+ );
}
/**
@@ -56,14 +52,10 @@ class FeatureEnabledTest extends WC_Unit_Test_Case {
public function test_should_be_disabled_when_woocommerce_admin_is_disabled(): void {
add_filter( 'woocommerce_admin_disabled', '__return_true', PHP_INT_MAX );
- try {
- $this->assertFalse(
- FeaturesUtil::feature_is_enabled( 'analytics' ),
- 'Analytics should be disabled when WooCommerce Admin is disabled.'
- );
- } finally {
- remove_filter( 'woocommerce_admin_disabled', '__return_true', PHP_INT_MAX );
- }
+ $this->assertFalse(
+ FeaturesUtil::feature_is_enabled( 'analytics' ),
+ 'Analytics should be disabled when WooCommerce Admin is disabled.'
+ );
}
/**
@@ -74,14 +66,10 @@ class FeatureEnabledTest extends WC_Unit_Test_Case {
update_option( 'woocommerce_analytics_enabled', 'no' );
$this->setExpectedDeprecated( "Automattic\WooCommerce\Admin\Features\Features::is_enabled( 'analytics' )" );
- try {
- $this->assertFalse(
- Features::is_enabled( 'analytics' ),
- 'Analytics should be unavailable in legacy admin features when the feature option is disabled.'
- );
- } finally {
- remove_filter( 'woocommerce_admin_features', array( $this, 'enable_analytics_feature' ) );
- }
+ $this->assertFalse(
+ Features::is_enabled( 'analytics' ),
+ 'Analytics should be unavailable in legacy admin features when the feature option is disabled.'
+ );
}
/**
@@ -115,14 +103,10 @@ class FeatureEnabledTest extends WC_Unit_Test_Case {
add_filter( 'woocommerce_admin_features', array( $this, 'disable_launch_your_store_feature' ) );
$this->setExpectedDeprecated( "Automattic\WooCommerce\Admin\Features\Features::is_enabled( 'launch-your-store' )" );
- try {
- $this->assertFalse(
- Features::is_enabled( 'launch-your-store' ),
- 'Retired feature flags should respect the filtered feature list through the compatibility shim.'
- );
- } finally {
- remove_filter( 'woocommerce_admin_features', array( $this, 'disable_launch_your_store_feature' ) );
- }
+ $this->assertFalse(
+ Features::is_enabled( 'launch-your-store' ),
+ 'Retired feature flags should respect the filtered feature list through the compatibility shim.'
+ );
}
/**
@@ -132,14 +116,10 @@ class FeatureEnabledTest extends WC_Unit_Test_Case {
add_filter( 'woocommerce_admin_features', array( $this, 'disable_customize_store_feature' ) );
$this->setExpectedDeprecated( "Automattic\WooCommerce\Admin\Features\Features::exists( 'customize-store' )" );
- try {
- $this->assertFalse(
- Features::exists( 'customize-store' ),
- 'Retired feature flags should respect the filtered feature list through the compatibility shim.'
- );
- } finally {
- remove_filter( 'woocommerce_admin_features', array( $this, 'disable_customize_store_feature' ) );
- }
+ $this->assertFalse(
+ Features::exists( 'customize-store' ),
+ 'Retired feature flags should respect the filtered feature list through the compatibility shim.'
+ );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Admin/Features/Fulfillments/DataStore/FulfillmentsDataStoreHookTest.php b/plugins/woocommerce/tests/php/src/Admin/Features/Fulfillments/DataStore/FulfillmentsDataStoreHookTest.php
index 426aeb53f98..a2ad171442e 100644
--- a/plugins/woocommerce/tests/php/src/Admin/Features/Fulfillments/DataStore/FulfillmentsDataStoreHookTest.php
+++ b/plugins/woocommerce/tests/php/src/Admin/Features/Fulfillments/DataStore/FulfillmentsDataStoreHookTest.php
@@ -285,7 +285,6 @@ class FulfillmentsDataStoreHookTest extends WC_Unit_Test_Case {
$db_fulfillment = new Fulfillment( $fulfillment->get_id() );
$this->assertFalse( $db_fulfillment->get_is_fulfilled() );
- remove_all_filters( 'woocommerce_fulfillment_before_fulfill' );
}
/**
@@ -328,7 +327,6 @@ class FulfillmentsDataStoreHookTest extends WC_Unit_Test_Case {
$db_fulfillment = new Fulfillment( $fulfillment->get_id() );
$this->assertTrue( $db_fulfillment->get_is_fulfilled() );
- remove_all_filters( 'woocommerce_fulfillment_before_fulfill' );
}
/**
@@ -380,7 +378,6 @@ class FulfillmentsDataStoreHookTest extends WC_Unit_Test_Case {
$this->expectExceptionMessage( 'Fulfillment not found.' );
new Fulfillment( $fulfillment->get_id() );
}
- remove_all_filters( 'woocommerce_fulfillment_before_fulfill' );
}
/**
@@ -432,7 +429,6 @@ class FulfillmentsDataStoreHookTest extends WC_Unit_Test_Case {
$this->assertEquals( $received_fulfillment->get_meta( 'test_meta_key_2' ), $fulfillment->get_meta( 'test_meta_key_2' ) );
$this->assertEquals( $received_fulfillment->get_meta( 'test_meta_update' ), $fulfillment->get_meta( 'test_meta_update' ) );
$this->assertEquals( $received_fulfillment->get_items(), $fulfillment->get_items() );
- remove_all_actions( 'woocommerce_fulfillment_after_fulfill' );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Admin/Features/Fulfillments/DataStore/FulfillmentsDataStoreTest.php b/plugins/woocommerce/tests/php/src/Admin/Features/Fulfillments/DataStore/FulfillmentsDataStoreTest.php
index d494f29a75c..4ea1b0d1b7d 100644
--- a/plugins/woocommerce/tests/php/src/Admin/Features/Fulfillments/DataStore/FulfillmentsDataStoreTest.php
+++ b/plugins/woocommerce/tests/php/src/Admin/Features/Fulfillments/DataStore/FulfillmentsDataStoreTest.php
@@ -149,33 +149,25 @@ class FulfillmentsDataStoreTest extends \WC_Unit_Test_Case {
* Tests that setters normalize datetime inputs to UTC regardless of the site timezone.
*/
public function test_setters_normalize_to_utc_under_non_utc_site_timezone() {
- $original_timezone = get_option( 'timezone_string' );
- $original_offset = get_option( 'gmt_offset' );
-
update_option( 'timezone_string', 'America/Los_Angeles' );
update_option( 'gmt_offset', '' );
- try {
- $fulfillment = new Fulfillment();
+ $fulfillment = new Fulfillment();
- // A bare MySQL string is interpreted as site-local (LA, UTC-8 in January).
- $fulfillment->set_date_fulfilled( '2025-01-15 10:30:00' );
- $this->assertSame( '2025-01-15 18:30:00', $fulfillment->get_date_fulfilled() );
+ // A bare MySQL string is interpreted as site-local (LA, UTC-8 in January).
+ $fulfillment->set_date_fulfilled( '2025-01-15 10:30:00' );
+ $this->assertSame( '2025-01-15 18:30:00', $fulfillment->get_date_fulfilled() );
- // An ISO string with explicit Z is respected as UTC.
- $fulfillment->set_date_fulfilled( '2025-01-15T10:30:00Z' );
- $this->assertSame( '2025-01-15 10:30:00', $fulfillment->get_date_fulfilled() );
+ // An ISO string with explicit Z is respected as UTC.
+ $fulfillment->set_date_fulfilled( '2025-01-15T10:30:00Z' );
+ $this->assertSame( '2025-01-15 10:30:00', $fulfillment->get_date_fulfilled() );
- // The same normalization applies to date_updated and date_deleted setters.
- $fulfillment->set_date_updated( '2025-01-15 10:30:00' );
- $this->assertSame( '2025-01-15 18:30:00', $fulfillment->get_date_updated() );
+ // The same normalization applies to date_updated and date_deleted setters.
+ $fulfillment->set_date_updated( '2025-01-15 10:30:00' );
+ $this->assertSame( '2025-01-15 18:30:00', $fulfillment->get_date_updated() );
- $fulfillment->set_date_deleted( '2025-01-15T10:30:00+00:00' );
- $this->assertSame( '2025-01-15 10:30:00', $fulfillment->get_date_deleted() );
- } finally {
- update_option( 'timezone_string', $original_timezone );
- update_option( 'gmt_offset', $original_offset );
- }//end try
+ $fulfillment->set_date_deleted( '2025-01-15T10:30:00+00:00' );
+ $this->assertSame( '2025-01-15 10:30:00', $fulfillment->get_date_deleted() );
}
/**
@@ -202,50 +194,42 @@ class FulfillmentsDataStoreTest extends \WC_Unit_Test_Case {
* timezone is not UTC, and that the value survives a DB round-trip unchanged.
*/
public function test_data_store_persists_dates_in_utc_under_non_utc_site_timezone() {
- $original_timezone = get_option( 'timezone_string' );
- $original_offset = get_option( 'gmt_offset' );
-
update_option( 'timezone_string', 'America/Los_Angeles' );
update_option( 'gmt_offset', '' );
- try {
- $fulfillment = new Fulfillment();
- $fulfillment->set_entity_type( 'order-fulfillment' );
- $fulfillment->set_entity_id( '789' );
- $fulfillment->set_status( 'fulfilled' );
- $fulfillment->set_items(
+ $fulfillment = new Fulfillment();
+ $fulfillment->set_entity_type( 'order-fulfillment' );
+ $fulfillment->set_entity_id( '789' );
+ $fulfillment->set_status( 'fulfilled' );
+ $fulfillment->set_items(
+ array(
array(
- array(
- 'item_id' => 1,
- 'qty' => 1,
- ),
- )
- );
+ 'item_id' => 1,
+ 'qty' => 1,
+ ),
+ )
+ );
- $before_utc = gmdate( 'Y-m-d H:i:s' );
- $this->data_store->create( $fulfillment );
- $after_utc = gmdate( 'Y-m-d H:i:s' );
-
- // Persisted date_updated should be a UTC value within the create window.
- $stored_date_updated = $fulfillment->get_date_updated();
- $this->assertNotNull( $stored_date_updated );
- $this->assertGreaterThanOrEqual( $before_utc, $stored_date_updated );
- $this->assertLessThanOrEqual( $after_utc, $stored_date_updated );
-
- // Same for date_fulfilled (set automatically on create when is_fulfilled=true).
- $stored_date_fulfilled = $fulfillment->get_date_fulfilled();
- $this->assertNotNull( $stored_date_fulfilled );
- $this->assertGreaterThanOrEqual( $before_utc, $stored_date_fulfilled );
- $this->assertLessThanOrEqual( $after_utc, $stored_date_fulfilled );
-
- // Values must survive a DB round-trip unchanged (no re-normalization on read).
- $read_fulfillment = new Fulfillment( $fulfillment->get_id() );
- $this->assertSame( $stored_date_updated, $read_fulfillment->get_date_updated() );
- $this->assertSame( $stored_date_fulfilled, $read_fulfillment->get_date_fulfilled() );
- } finally {
- update_option( 'timezone_string', $original_timezone );
- update_option( 'gmt_offset', $original_offset );
- }//end try
+ $before_utc = gmdate( 'Y-m-d H:i:s' );
+ $this->data_store->create( $fulfillment );
+ $after_utc = gmdate( 'Y-m-d H:i:s' );
+
+ // Persisted date_updated should be a UTC value within the create window.
+ $stored_date_updated = $fulfillment->get_date_updated();
+ $this->assertNotNull( $stored_date_updated );
+ $this->assertGreaterThanOrEqual( $before_utc, $stored_date_updated );
+ $this->assertLessThanOrEqual( $after_utc, $stored_date_updated );
+
+ // Same for date_fulfilled (set automatically on create when is_fulfilled=true).
+ $stored_date_fulfilled = $fulfillment->get_date_fulfilled();
+ $this->assertNotNull( $stored_date_fulfilled );
+ $this->assertGreaterThanOrEqual( $before_utc, $stored_date_fulfilled );
+ $this->assertLessThanOrEqual( $after_utc, $stored_date_fulfilled );
+
+ // Values must survive a DB round-trip unchanged (no re-normalization on read).
+ $read_fulfillment = new Fulfillment( $fulfillment->get_id() );
+ $this->assertSame( $stored_date_updated, $read_fulfillment->get_date_updated() );
+ $this->assertSame( $stored_date_fulfilled, $read_fulfillment->get_date_fulfilled() );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Admin/Features/Fulfillments/FulfillmentOrderNotesTest.php b/plugins/woocommerce/tests/php/src/Admin/Features/Fulfillments/FulfillmentOrderNotesTest.php
index f4d574dc427..84115a56dc1 100644
--- a/plugins/woocommerce/tests/php/src/Admin/Features/Fulfillments/FulfillmentOrderNotesTest.php
+++ b/plugins/woocommerce/tests/php/src/Admin/Features/Fulfillments/FulfillmentOrderNotesTest.php
@@ -523,8 +523,6 @@ class FulfillmentOrderNotesTest extends \WC_Unit_Test_Case {
}
}
$this->assertTrue( $found, 'Expected a sanitized fulfillment note.' );
-
- remove_filter( 'woocommerce_fulfillment_created_order_note', $malicious_filter );
}
/**
@@ -571,8 +569,6 @@ class FulfillmentOrderNotesTest extends \WC_Unit_Test_Case {
}
}
$this->assertTrue( $found, 'Expected allowed HTML to be preserved in note.' );
-
- remove_filter( 'woocommerce_fulfillment_created_order_note', $filter_with_html );
}
/**
@@ -617,8 +613,6 @@ class FulfillmentOrderNotesTest extends \WC_Unit_Test_Case {
}
}
$this->assertFalse( $found_created_note, 'Expected no fulfillment note when filter returns a non-string value.' );
-
- remove_filter( 'woocommerce_fulfillment_created_order_note', $non_string_filter );
}
/**
@@ -663,8 +657,6 @@ class FulfillmentOrderNotesTest extends \WC_Unit_Test_Case {
}
}
$this->assertFalse( $found_created_note, 'Expected no fulfillment note when filter returns empty string.' );
-
- remove_filter( 'woocommerce_fulfillment_created_order_note', $empty_filter );
}
/**
@@ -709,8 +701,6 @@ class FulfillmentOrderNotesTest extends \WC_Unit_Test_Case {
}
}
$this->assertFalse( $found_created_note, 'Expected no fulfillment note when filter returns whitespace-only string.' );
-
- remove_filter( 'woocommerce_fulfillment_created_order_note', $whitespace_filter );
}
/**
@@ -752,8 +742,6 @@ class FulfillmentOrderNotesTest extends \WC_Unit_Test_Case {
}
}
$this->assertFalse( $found_created_note, 'Expected no fulfillment created note when filter returns null.' );
-
- remove_filter( 'woocommerce_fulfillment_created_order_note', '__return_null' );
}
/**
@@ -798,8 +786,6 @@ class FulfillmentOrderNotesTest extends \WC_Unit_Test_Case {
}
}
$this->assertTrue( $found, 'Expected the note to contain the custom filter message.' );
-
- remove_filter( 'woocommerce_fulfillment_created_order_note', $custom_filter );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Admin/Features/Fulfillments/FulfillmentsRendererTest.php b/plugins/woocommerce/tests/php/src/Admin/Features/Fulfillments/FulfillmentsRendererTest.php
index f2d088c1047..2a4d3aa671a 100644
--- a/plugins/woocommerce/tests/php/src/Admin/Features/Fulfillments/FulfillmentsRendererTest.php
+++ b/plugins/woocommerce/tests/php/src/Admin/Features/Fulfillments/FulfillmentsRendererTest.php
@@ -524,14 +524,10 @@ class FulfillmentsRendererTest extends \WC_Unit_Test_Case {
};
add_filter( 'woocommerce_fulfillment_shipping_providers', $register_known );
- try {
- $this->seed_fulfillment( 201, 'amazon-logistics' );
- $this->seed_fulfillment( 202, 'ghost-provider' );
+ $this->seed_fulfillment( 201, 'amazon-logistics' );
+ $this->seed_fulfillment( 202, 'ghost-provider' );
- $this->assertSame( array( 202 ), $this->get_order_ids( '__other__' ) );
- } finally {
- remove_filter( 'woocommerce_fulfillment_shipping_providers', $register_known );
- }
+ $this->assertSame( array( 202 ), $this->get_order_ids( '__other__' ) );
}
/**
@@ -721,19 +717,15 @@ class FulfillmentsRendererTest extends \WC_Unit_Test_Case {
$this->seed_fulfillment( 972, 'acme-couriers' );
add_filter( 'woocommerce_hpos_pre_query', '__return_null' );
- try {
- $this->with_provider_param(
- 'acme-couriers',
- function () {
- // The query remaps p onto id, so a single-order query must not widen to the whole set.
- $args = $this->renderer->filter_orders_by_shipping_provider( array( 'p' => 972 ) );
+ $this->with_provider_param(
+ 'acme-couriers',
+ function () {
+ // The query remaps p onto id, so a single-order query must not widen to the whole set.
+ $args = $this->renderer->filter_orders_by_shipping_provider( array( 'p' => 972 ) );
- $this->assertSame( array( 972 ), $args['post__in'] );
- }
- );
- } finally {
- remove_filter( 'woocommerce_hpos_pre_query', '__return_null' );
- }
+ $this->assertSame( array( 972 ), $args['post__in'] );
+ }
+ );
}
/**
@@ -781,24 +773,20 @@ class FulfillmentsRendererTest extends \WC_Unit_Test_Case {
// Only the callback's presence matters here, not what it returns.
add_filter( 'woocommerce_hpos_pre_query', '__return_null' );
- try {
- $this->with_provider_param(
- 'acme-couriers',
- function () {
- $args = $this->renderer->filter_orders_by_shipping_provider( array() );
-
- $this->assertArrayHasKey( 'post__in', $args );
- $this->assertEqualsCanonicalizing( array( 901, 902 ), $args['post__in'] );
- $this->assertArrayNotHasKey(
- 'fulfillment_shipping_provider',
- $args,
- 'The marker would be ignored by a callback that discards the built SQL.'
- );
- }
- );
- } finally {
- remove_filter( 'woocommerce_hpos_pre_query', '__return_null' );
- }
+ $this->with_provider_param(
+ 'acme-couriers',
+ function () {
+ $args = $this->renderer->filter_orders_by_shipping_provider( array() );
+
+ $this->assertArrayHasKey( 'post__in', $args );
+ $this->assertEqualsCanonicalizing( array( 901, 902 ), $args['post__in'] );
+ $this->assertArrayNotHasKey(
+ 'fulfillment_shipping_provider',
+ $args,
+ 'The marker would be ignored by a callback that discards the built SQL.'
+ );
+ }
+ );
}
/**
@@ -809,18 +797,14 @@ class FulfillmentsRendererTest extends \WC_Unit_Test_Case {
$this->seed_fulfillment( 912, 'acme-couriers' );
add_filter( 'woocommerce_hpos_pre_query', '__return_null' );
- try {
- $this->with_provider_param(
- 'acme-couriers',
- function () {
- $args = $this->renderer->filter_orders_by_shipping_provider( array( 'post__in' => array( 911, 999 ) ) );
+ $this->with_provider_param(
+ 'acme-couriers',
+ function () {
+ $args = $this->renderer->filter_orders_by_shipping_provider( array( 'post__in' => array( 911, 999 ) ) );
- $this->assertSame( array( 911 ), $args['post__in'] );
- }
- );
- } finally {
- remove_filter( 'woocommerce_hpos_pre_query', '__return_null' );
- }
+ $this->assertSame( array( 911 ), $args['post__in'] );
+ }
+ );
}
/**
@@ -831,19 +815,15 @@ class FulfillmentsRendererTest extends \WC_Unit_Test_Case {
$this->seed_fulfillment( 962, 'acme-couriers' );
add_filter( 'woocommerce_hpos_pre_query', '__return_null' );
- try {
- $this->with_provider_param(
- 'acme-couriers',
- function () {
- // The query remaps post__in onto id, so an existing id must survive the fallback.
- $args = $this->renderer->filter_orders_by_shipping_provider( array( 'id' => array( 962, 999 ) ) );
+ $this->with_provider_param(
+ 'acme-couriers',
+ function () {
+ // The query remaps post__in onto id, so an existing id must survive the fallback.
+ $args = $this->renderer->filter_orders_by_shipping_provider( array( 'id' => array( 962, 999 ) ) );
- $this->assertSame( array( 962 ), $args['post__in'] );
- }
- );
- } finally {
- remove_filter( 'woocommerce_hpos_pre_query', '__return_null' );
- }
+ $this->assertSame( array( 962 ), $args['post__in'] );
+ }
+ );
}
/**
@@ -853,18 +833,14 @@ class FulfillmentsRendererTest extends \WC_Unit_Test_Case {
$this->seed_fulfillment( 921, 'acme-couriers' );
add_filter( 'woocommerce_hpos_pre_query', '__return_null' );
- try {
- $this->with_provider_param(
- 'nobody-ships-with-this',
- function () {
- $args = $this->renderer->filter_orders_by_shipping_provider( array() );
+ $this->with_provider_param(
+ 'nobody-ships-with-this',
+ function () {
+ $args = $this->renderer->filter_orders_by_shipping_provider( array() );
- $this->assertSame( array( 0 ), $args['post__in'], 'An empty post__in would drop the filter instead of applying it.' );
- }
- );
- } finally {
- remove_filter( 'woocommerce_hpos_pre_query', '__return_null' );
- }
+ $this->assertSame( array( 0 ), $args['post__in'], 'An empty post__in would drop the filter instead of applying it.' );
+ }
+ );
}
/**
@@ -879,27 +855,23 @@ class FulfillmentsRendererTest extends \WC_Unit_Test_Case {
// Only the callback's presence matters here, not what it returns.
add_filter( 'posts_pre_query', '__return_null' );
- try {
- $this->with_main_query(
- $query,
- function () use ( $query ) {
- $this->with_provider_param(
- 'acme-couriers',
- function () use ( $query ) {
- $this->renderer->filter_legacy_orders_by_shipping_provider( $query );
-
- $this->assertSame( array( 931 ), $query->get( 'post__in' ) );
- $this->assertEmpty(
- $query->get( 'fulfillment_shipping_provider' ),
- 'The marker would be ignored by a callback that discards the built SQL.'
- );
- }
- );
- }
- );
- } finally {
- remove_filter( 'posts_pre_query', '__return_null' );
- }
+ $this->with_main_query(
+ $query,
+ function () use ( $query ) {
+ $this->with_provider_param(
+ 'acme-couriers',
+ function () use ( $query ) {
+ $this->renderer->filter_legacy_orders_by_shipping_provider( $query );
+
+ $this->assertSame( array( 931 ), $query->get( 'post__in' ) );
+ $this->assertEmpty(
+ $query->get( 'fulfillment_shipping_provider' ),
+ 'The marker would be ignored by a callback that discards the built SQL.'
+ );
+ }
+ );
+ }
+ );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Admin/RemoteSpecs/RuleProcessors/TotalPaymentsVolumeProcessorTest.php b/plugins/woocommerce/tests/php/src/Admin/RemoteSpecs/RuleProcessors/TotalPaymentsVolumeProcessorTest.php
index 27b7e9eec9e..6a9286c4e90 100644
--- a/plugins/woocommerce/tests/php/src/Admin/RemoteSpecs/RuleProcessors/TotalPaymentsVolumeProcessorTest.php
+++ b/plugins/woocommerce/tests/php/src/Admin/RemoteSpecs/RuleProcessors/TotalPaymentsVolumeProcessorTest.php
@@ -82,34 +82,29 @@ class TotalPaymentsVolumeProcessorTest extends WC_Unit_Test_Case {
* @testdox Should evaluate the timeframe against the site's calendar date, not the UTC date.
*/
public function test_process_resolves_timeframe_in_site_timezone(): void {
- $original_timezone = get_option( 'timezone_string' );
update_option( 'timezone_string', 'Pacific/Kiritimati' );
- try {
- $processor = $this->get_processor_with_frozen_clock();
- $rule = (object) array(
- 'timeframe' => 'last_month',
- 'value' => 50,
- 'operation' => '>',
- );
-
- $result = $processor->process( $rule, (object) array() );
-
- $this->assertTrue( $result, 'total_sales of 100 should satisfy "> 50"' );
- // On the frozen instant the site-local date is 2020-09-01 while the UTC date is still
- // 2020-08-31, so last_month must resolve to August 2020, not July 2020.
- $this->assertSame( '2020-08-01 00:00:00', $processor->captured_args['after'] );
- $this->assertSame( '2020-08-31 23:59:59', $processor->captured_args['before'] );
-
- // A second evaluation must produce the same window: the date calculations mutate the
- // reference date in place, and that must not leak into the provider's cached instance.
- $processor->process( $rule, (object) array() );
-
- $this->assertSame( '2020-08-01 00:00:00', $processor->captured_args['after'], 'Repeated process() calls should not drift the timeframe' );
- $this->assertSame( '2020-08-31 23:59:59', $processor->captured_args['before'], 'Repeated process() calls should not drift the timeframe' );
- } finally {
- update_option( 'timezone_string', $original_timezone );
- }
+ $processor = $this->get_processor_with_frozen_clock();
+ $rule = (object) array(
+ 'timeframe' => 'last_month',
+ 'value' => 50,
+ 'operation' => '>',
+ );
+
+ $result = $processor->process( $rule, (object) array() );
+
+ $this->assertTrue( $result, 'total_sales of 100 should satisfy "> 50"' );
+ // On the frozen instant the site-local date is 2020-09-01 while the UTC date is still
+ // 2020-08-31, so last_month must resolve to August 2020, not July 2020.
+ $this->assertSame( '2020-08-01 00:00:00', $processor->captured_args['after'] );
+ $this->assertSame( '2020-08-31 23:59:59', $processor->captured_args['before'] );
+
+ // A second evaluation must produce the same window: the date calculations mutate the
+ // reference date in place, and that must not leak into the provider's cached instance.
+ $processor->process( $rule, (object) array() );
+
+ $this->assertSame( '2020-08-01 00:00:00', $processor->captured_args['after'], 'Repeated process() calls should not drift the timeframe' );
+ $this->assertSame( '2020-08-31 23:59:59', $processor->captured_args['before'], 'Repeated process() calls should not drift the timeframe' );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Blocks/Assets/AssetDataRegistry.php b/plugins/woocommerce/tests/php/src/Blocks/Assets/AssetDataRegistry.php
index 4398fa42fdd..ea4b3bd0c7a 100644
--- a/plugins/woocommerce/tests/php/src/Blocks/Assets/AssetDataRegistry.php
+++ b/plugins/woocommerce/tests/php/src/Blocks/Assets/AssetDataRegistry.php
@@ -147,7 +147,6 @@ class AssetDataRegistry extends \WP_UnitTestCase {
$data = $this->registry->get();
$this->registry->initialize_core_data();
$this->assertEquals( $original_data, $data );
- remove_filter( 'woocommerce_shared_settings', [ self::class, 'pdatcallback' ] );
}
public static function pdatcallback( $existing_data ) {
@@ -168,7 +167,6 @@ class AssetDataRegistry extends \WP_UnitTestCase {
$data = $this->registry->get();
$original_data['cheeseburger'] = 'fries';
$this->assertEquals( $original_data, $data );
- remove_filter( 'woocommerce_shared_settings', [ self::class, 'ndcallback' ] );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Blocks/BlockTypes/AddToCartWithOptions.php b/plugins/woocommerce/tests/php/src/Blocks/BlockTypes/AddToCartWithOptions.php
index 8d52599c4fc..a67859b7dbc 100644
--- a/plugins/woocommerce/tests/php/src/Blocks/BlockTypes/AddToCartWithOptions.php
+++ b/plugins/woocommerce/tests/php/src/Blocks/BlockTypes/AddToCartWithOptions.php
@@ -110,8 +110,6 @@ class AddToCartWithOptions extends \WC_Unit_Test_Case {
// Third-party product types use their own template.
$this->assertStringContainsString( 'Custom Product Type Add to Cart Form', $markup, 'The Custom Product Type Add to Cart + Options contains the custom product type add to cart form.' );
-
- remove_action( 'woocommerce_custom_add_to_cart', array( $this, 'print_custom_product_type_add_to_cart_markup' ) );
}
/**
@@ -168,9 +166,6 @@ class AddToCartWithOptions extends \WC_Unit_Test_Case {
$this->assertStringContainsString( 'Hook into add to cart action', $markup, 'The Add to Cart + Options correctly renders the contents from the wrapper hook if the product is out of stock.' );
$this->assertStringNotContainsString( 'Hook into add to cart button action', $markup, 'The Add to Cart + Options doesn\'t render the contents from the inner hooks if the product is out of stock.' );
-
- remove_action( 'woocommerce_simple_add_to_cart', array( $this, 'hook_into_add_to_cart_action' ) );
- remove_action( 'woocommerce_before_add_to_cart_button', array( $this, 'hook_into_add_to_cart_button_action' ) );
}
/**
@@ -268,10 +263,6 @@ class AddToCartWithOptions extends \WC_Unit_Test_Case {
$this->assertStringNotContainsString( 'action="https://example.com"', $markup, 'The form doesn\'t have an action that redirects to the page defined by the woocommerce_add_to_cart_form_action filter when an extension hooks into the form but not adding a form element.' );
$this->assertStringContainsString( 'data-wp-on--submit', $markup, 'The form has an on submit event when an extension hooks into the form but not adding a form element.' );
-
- remove_action( 'woocommerce_before_add_to_cart_button', array( $this, 'hook_into_add_to_cart_button_action_text' ) );
-
- remove_filter( 'woocommerce_add_to_cart_form_action', array( $this, 'hook_into_woocommerce_add_to_cart_form_action_filter' ) );
}
/**
@@ -606,18 +597,14 @@ class AddToCartWithOptions extends \WC_Unit_Test_Case {
add_filter( 'woocommerce_quantity_input_args', $filter, 10, 2 );
- try {
- $markup = do_blocks( '<!-- wp:woocommerce/single-product {"productId":' . $product_id . '} --><!-- wp:woocommerce/add-to-cart-with-options /--><!-- /wp:woocommerce/single-product -->' );
+ $markup = do_blocks( '<!-- wp:woocommerce/single-product {"productId":' . $product_id . '} --><!-- wp:woocommerce/add-to-cart-with-options /--><!-- /wp:woocommerce/single-product -->' );
- // Quantity selector block should not render at all.
- $this->assertStringContainsString( 'wc-block-add-to-cart-with-options__quantity-selector--hidden', $markup, 'The Quantity Selector block is hidden when min equals max.' );
+ // Quantity selector block should not render at all.
+ $this->assertStringContainsString( 'wc-block-add-to-cart-with-options__quantity-selector--hidden', $markup, 'The Quantity Selector block is hidden when min equals max.' );
- // Plus and minus stepper buttons should not be present.
- $this->assertStringNotContainsString( 'wc-block-components-quantity-selector__button--plus', $markup, 'The plus stepper is not rendered when min equals max.' );
- $this->assertStringNotContainsString( 'wc-block-components-quantity-selector__button--minus', $markup, 'The minus stepper is not rendered when min equals max.' );
- } finally {
- remove_filter( 'woocommerce_quantity_input_args', $filter, 10 );
- }
+ // Plus and minus stepper buttons should not be present.
+ $this->assertStringNotContainsString( 'wc-block-components-quantity-selector__button--plus', $markup, 'The plus stepper is not rendered when min equals max.' );
+ $this->assertStringNotContainsString( 'wc-block-components-quantity-selector__button--minus', $markup, 'The minus stepper is not rendered when min equals max.' );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Blocks/BlockTypes/BlockHooksTests.php b/plugins/woocommerce/tests/php/src/Blocks/BlockTypes/BlockHooksTests.php
index 19bc9dcd0b6..26fcecf1c13 100644
--- a/plugins/woocommerce/tests/php/src/Blocks/BlockTypes/BlockHooksTests.php
+++ b/plugins/woocommerce/tests/php/src/Blocks/BlockTypes/BlockHooksTests.php
@@ -31,7 +31,6 @@ class BlockHooksTests extends WC_Unit_Test_Case {
$hooked_block_types,
'Test block should be included in hooked blocks with correct version'
);
- delete_option( self::$option_name );
}
/**
@@ -60,6 +59,5 @@ class BlockHooksTests extends WC_Unit_Test_Case {
$hooked_block_types,
'Test block should not be included in hooked blocks with lower version'
);
- delete_option( self::$option_name );
}
}
diff --git a/plugins/woocommerce/tests/php/src/Blocks/BlockTypes/MiniCart.php b/plugins/woocommerce/tests/php/src/Blocks/BlockTypes/MiniCart.php
index a8918df5b7c..8b7e8058c75 100644
--- a/plugins/woocommerce/tests/php/src/Blocks/BlockTypes/MiniCart.php
+++ b/plugins/woocommerce/tests/php/src/Blocks/BlockTypes/MiniCart.php
@@ -360,10 +360,6 @@ class MiniCart extends \WC_Unit_Test_Case {
// Mini-cart should not render (empty output).
$this->assertEmpty( $output, 'Mini-cart should not render for logged-out users when store is in coming soon mode.' );
-
- // Clean up.
- update_option( 'woocommerce_coming_soon', 'no' );
- update_option( 'woocommerce_store_pages_only', 'no' );
}
/**
@@ -388,8 +384,6 @@ class MiniCart extends \WC_Unit_Test_Case {
// Clean up.
wp_set_current_user( 0 );
- update_option( 'woocommerce_coming_soon', 'no' );
- update_option( 'woocommerce_store_pages_only', 'no' );
}
/**
@@ -484,10 +478,6 @@ class MiniCart extends \WC_Unit_Test_Case {
// Mini-cart should render (non-empty output) because the logic only checks for store pages coming soon.
$this->assertNotEmpty( $output, 'Mini-cart should render when site-wide coming soon is enabled but not store pages only.' );
-
- // Clean up.
- update_option( 'woocommerce_coming_soon', 'no' );
- update_option( 'woocommerce_store_pages_only', 'no' );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Blocks/BlockTypes/ProductCollection/QueryBuilder.php b/plugins/woocommerce/tests/php/src/Blocks/BlockTypes/ProductCollection/QueryBuilder.php
index e76e390e82a..9504a16b96e 100644
--- a/plugins/woocommerce/tests/php/src/Blocks/BlockTypes/ProductCollection/QueryBuilder.php
+++ b/plugins/woocommerce/tests/php/src/Blocks/BlockTypes/ProductCollection/QueryBuilder.php
@@ -881,19 +881,15 @@ class QueryBuilder extends \WC_Unit_Test_Case {
add_filter( 'wp_date', $wp_date_mock, 10, 2 );
- try {
- $first_seed = ProductCollectionUtils::get_random_order_seed( 53919, $query_context );
- $rotation_key = '2026-06-04';
- $second_seed = ProductCollectionUtils::get_random_order_seed( 53919, $query_context );
-
- $this->assertNotSame(
- $first_seed,
- $second_seed,
- 'Random sorting should use a different seed when the daily rotation key changes.'
- );
- } finally {
- remove_filter( 'wp_date', $wp_date_mock, 10 );
- }
+ $first_seed = ProductCollectionUtils::get_random_order_seed( 53919, $query_context );
+ $rotation_key = '2026-06-04';
+ $second_seed = ProductCollectionUtils::get_random_order_seed( 53919, $query_context );
+
+ $this->assertNotSame(
+ $first_seed,
+ $second_seed,
+ 'Random sorting should use a different seed when the daily rotation key changes.'
+ );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Blocks/BlockTypes/ProductQuery.php b/plugins/woocommerce/tests/php/src/Blocks/BlockTypes/ProductQuery.php
index 7db4a68d8b5..3c38ee35d2a 100644
--- a/plugins/woocommerce/tests/php/src/Blocks/BlockTypes/ProductQuery.php
+++ b/plugins/woocommerce/tests/php/src/Blocks/BlockTypes/ProductQuery.php
@@ -372,10 +372,6 @@ class ProductQuery extends \WP_UnitTestCase {
),
$merged_query['tax_query']
);
- remove_filter(
- 'pre_option_woocommerce_hide_out_of_stock_items',
- $fn
- );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Blocks/BlockTypes/ProductSaleBadge.php b/plugins/woocommerce/tests/php/src/Blocks/BlockTypes/ProductSaleBadge.php
index 7b7af2d5ea8..e2e6d930bdb 100644
--- a/plugins/woocommerce/tests/php/src/Blocks/BlockTypes/ProductSaleBadge.php
+++ b/plugins/woocommerce/tests/php/src/Blocks/BlockTypes/ProductSaleBadge.php
@@ -344,7 +344,6 @@ class ProductSaleBadge extends \WP_UnitTestCase {
}
} finally {
\WC_Tax::_delete_tax_rate( $tax_id );
- remove_filter( 'wc_tax_enabled', '__return_true' );
}
}
diff --git a/plugins/woocommerce/tests/php/src/Blocks/CoreBreadcrumbsCompatibilityTest.php b/plugins/woocommerce/tests/php/src/Blocks/CoreBreadcrumbsCompatibilityTest.php
index 58832232a4c..8d35b82e35a 100644
--- a/plugins/woocommerce/tests/php/src/Blocks/CoreBreadcrumbsCompatibilityTest.php
+++ b/plugins/woocommerce/tests/php/src/Blocks/CoreBreadcrumbsCompatibilityTest.php
@@ -171,16 +171,11 @@ class CoreBreadcrumbsCompatibilityTest extends WC_Unit_Test_Case {
new Bootstrap( $container );
$controller = $container->get( BlockTypesController::class );
- try {
- $this->assertSame( 10, has_filter( 'block_core_breadcrumbs_post_type_settings', array( $controller, 'set_product_breadcrumbs_preferred_taxonomy' ) ), 'Bootstrap should register the product breadcrumb settings filter.' );
- $this->assertSame( 10, has_filter( 'block_core_breadcrumbs_items', array( $controller, 'apply_woocommerce_breadcrumb_filters' ) ), 'Bootstrap should register the breadcrumb items filter.' );
- $this->assertSame( array( 'taxonomy' => 'product_cat' ), $controller->set_product_breadcrumbs_preferred_taxonomy( array(), 'product' ), 'BlockTypesController should set the product breadcrumb settings.' );
- $this->assertSame( array(), $controller->apply_woocommerce_breadcrumb_filters( array() ), 'BlockTypesController should filter the breadcrumb items.' );
- $this->assertTrue( remove_filter( 'block_core_breadcrumbs_items', array( $controller, 'apply_woocommerce_breadcrumb_filters' ), 10 ), 'The breadcrumb items filter should be removable.' );
- } finally {
- remove_filter( 'block_core_breadcrumbs_post_type_settings', array( $controller, 'set_product_breadcrumbs_preferred_taxonomy' ), 10 );
- remove_filter( 'block_core_breadcrumbs_items', array( $controller, 'apply_woocommerce_breadcrumb_filters' ), 10 );
- }
+ $this->assertSame( 10, has_filter( 'block_core_breadcrumbs_post_type_settings', array( $controller, 'set_product_breadcrumbs_preferred_taxonomy' ) ), 'Bootstrap should register the product breadcrumb settings filter.' );
+ $this->assertSame( 10, has_filter( 'block_core_breadcrumbs_items', array( $controller, 'apply_woocommerce_breadcrumb_filters' ) ), 'Bootstrap should register the breadcrumb items filter.' );
+ $this->assertSame( array( 'taxonomy' => 'product_cat' ), $controller->set_product_breadcrumbs_preferred_taxonomy( array(), 'product' ), 'BlockTypesController should set the product breadcrumb settings.' );
+ $this->assertSame( array(), $controller->apply_woocommerce_breadcrumb_filters( array() ), 'BlockTypesController should filter the breadcrumb items.' );
+ $this->assertTrue( remove_filter( 'block_core_breadcrumbs_items', array( $controller, 'apply_woocommerce_breadcrumb_filters' ), 10 ), 'The breadcrumb items filter should be removable.' );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Blocks/Domain/Services/CheckoutFieldsFrontendTest.php b/plugins/woocommerce/tests/php/src/Blocks/Domain/Services/CheckoutFieldsFrontendTest.php
index 50a02117573..6f44cc6fc36 100644
--- a/plugins/woocommerce/tests/php/src/Blocks/Domain/Services/CheckoutFieldsFrontendTest.php
+++ b/plugins/woocommerce/tests/php/src/Blocks/Domain/Services/CheckoutFieldsFrontendTest.php
@@ -213,8 +213,6 @@ class CheckoutFieldsFrontendTest extends \WC_Unit_Test_Case {
$this->assertEquals( 'error', $mocked_messages[0]['type'] );
$value = $this->controller->get_field_from_object( 'mynamespace/required_field', new WC_Customer( 1 ) );
$this->assertEquals( '', $value );
-
- remove_action( 'woocommerce_blocks_validate_location_contact_fields', $e_thrower );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Blocks/Domain/Services/DeleteDraftOrders.php b/plugins/woocommerce/tests/php/src/Blocks/Domain/Services/DeleteDraftOrders.php
index 7e4a95c0c4e..936ca3845ef 100644
--- a/plugins/woocommerce/tests/php/src/Blocks/Domain/Services/DeleteDraftOrders.php
+++ b/plugins/woocommerce/tests/php/src/Blocks/Domain/Services/DeleteDraftOrders.php
@@ -185,8 +185,6 @@ class DeleteDraftOrders extends \WC_Unit_Test_Case {
$this->draft_orders_instance->delete_expired_draft_orders();
$this->assertNull( $this->caught_exception, 'No exception should be thrown when batch size filter allows more results.' );
$this->unset_mock_results_for_wc_query( $sample_results );
-
- remove_all_filters( 'woocommerce_delete_expired_draft_orders_batch_size' );
}
public function test_greater_than_batch_results_error() {
diff --git a/plugins/woocommerce/tests/php/src/Blocks/Patterns/PTKClientTest.php b/plugins/woocommerce/tests/php/src/Blocks/Patterns/PTKClientTest.php
index c685701e36f..5a696c25aa5 100644
--- a/plugins/woocommerce/tests/php/src/Blocks/Patterns/PTKClientTest.php
+++ b/plugins/woocommerce/tests/php/src/Blocks/Patterns/PTKClientTest.php
@@ -39,8 +39,6 @@ class PTKClientTest extends \WP_UnitTestCase {
$response = $this->client->fetch_patterns();
$this->assertErrorResponse( $response, 'Failed to connect with the Patterns Toolkit API: try again later.' );
-
- remove_filter( 'pre_http_request', array( $this, 'return_wp_error' ) );
}
/**
@@ -61,8 +59,6 @@ class PTKClientTest extends \WP_UnitTestCase {
$response = $this->client->fetch_patterns();
$this->assertErrorResponse( $response, 'Failed to connect with the Patterns Toolkit API: try again later.' );
-
- remove_filter( 'pre_http_request', array( $this, 'return_request_failed' ) );
}
/**
@@ -83,8 +79,6 @@ class PTKClientTest extends \WP_UnitTestCase {
$response = $this->client->fetch_patterns();
$this->assertErrorResponse( $response, 'Empty response received from the Patterns Toolkit API.' );
-
- remove_filter( 'pre_http_request', array( $this, 'return_request_failed' ) );
}
/**
@@ -105,8 +99,6 @@ class PTKClientTest extends \WP_UnitTestCase {
$response = $this->client->fetch_patterns();
$this->assertErrorResponse( $response, 'Wrong response received from the Patterns Toolkit API: try again later.' );
-
- remove_filter( 'pre_http_request', array( $this, 'return_request_failed' ) );
}
/**
@@ -143,8 +135,6 @@ class PTKClientTest extends \WP_UnitTestCase {
$response = $this->client->fetch_patterns();
$this->assertIsArray( $response );
$this->assertCount( 1, $response );
-
- remove_filter( 'pre_http_request', array( $this, 'return_request_failed' ) );
}
/**
@@ -194,8 +184,6 @@ class PTKClientTest extends \WP_UnitTestCase {
$response = $this->client->fetch_patterns();
$this->assertErrorResponse( $response, 'Wrong response received from the Patterns Toolkit API: try again later.' );
-
- remove_filter( 'pre_http_request', array( $this, 'return_request_failed' ) );
}
/**
@@ -239,8 +227,6 @@ class PTKClientTest extends \WP_UnitTestCase {
$response = $this->client->fetch_patterns();
$this->assertErrorResponse( $response, 'Wrong response received from the Patterns Toolkit API: try again later.' );
-
- remove_filter( 'pre_http_request', array( $this, 'return_request_failed' ) );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Blocks/Shipping/PickupIdentityTest.php b/plugins/woocommerce/tests/php/src/Blocks/Shipping/PickupIdentityTest.php
index 78f7bb32649..e627e6eb3fd 100644
--- a/plugins/woocommerce/tests/php/src/Blocks/Shipping/PickupIdentityTest.php
+++ b/plugins/woocommerce/tests/php/src/Blocks/Shipping/PickupIdentityTest.php
@@ -158,7 +158,6 @@ class PickupIdentityTest extends WC_Unit_Test_Case {
$order->needs_shipping_address(),
'Running after the controller, the same filter does have the last word.'
);
- remove_filter( 'woocommerce_order_hide_shipping_address', $empty_it, 20 );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Blocks/Shipping/ShippingControllerTest.php b/plugins/woocommerce/tests/php/src/Blocks/Shipping/ShippingControllerTest.php
index e463e3801ec..5e072ef7d55 100644
--- a/plugins/woocommerce/tests/php/src/Blocks/Shipping/ShippingControllerTest.php
+++ b/plugins/woocommerce/tests/php/src/Blocks/Shipping/ShippingControllerTest.php
@@ -143,9 +143,6 @@ class ShippingControllerTest extends \WC_Unit_Test_Case {
// Finally test that it passes when an ordinarily optional prop filtered to be required is provided.
WC()->customer->set_shipping_state( 'Lancashire' );
$this->assertTrue( WC()->customer->has_full_shipping_address() );
-
- // Remove filter.
- remove_all_filters( 'woocommerce_get_country_locale' );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Blocks/StoreApi/Routes/AdditionalFields.php b/plugins/woocommerce/tests/php/src/Blocks/StoreApi/Routes/AdditionalFields.php
index 504c2060d73..1fbdc6bf8de 100644
--- a/plugins/woocommerce/tests/php/src/Blocks/StoreApi/Routes/AdditionalFields.php
+++ b/plugins/woocommerce/tests/php/src/Blocks/StoreApi/Routes/AdditionalFields.php
@@ -296,14 +296,6 @@ class AdditionalFields extends \WP_Test_REST_TestCase {
);
// register fields.
$this->register_fields();
- // remove our callbacks.
- \remove_action(
- 'doing_it_wrong_run',
- array(
- $doing_it_wrong_mocker,
- 'doing_it_wrong_run',
- )
- );
}
/**
@@ -676,14 +668,6 @@ class AdditionalFields extends \WP_Test_REST_TestCase {
'required' => true,
)
);
-
- \remove_action(
- 'doing_it_wrong_run',
- array(
- $doing_it_wrong_mocker,
- 'doing_it_wrong_run',
- )
- );
}
/**
@@ -2556,8 +2540,6 @@ class AdditionalFields extends \WP_Test_REST_TestCase {
$this->assertEquals( 'external-value', ( (array) $data['additional_fields'] )[ $id ], print_r( $data, true ) );
\__internal_woocommerce_blocks_deregister_checkout_field( $id );
-
- \remove_all_filters( "woocommerce_get_default_value_for_{$id}" );
}
/**
@@ -2629,7 +2611,6 @@ class AdditionalFields extends \WP_Test_REST_TestCase {
$this->assertEquals( 'value', ( (array) $data['additional_fields'] )[ $id ], print_r( $data, true ) );
\__internal_woocommerce_blocks_deregister_checkout_field( $id );
- \remove_all_filters( "woocommerce_get_default_value_for_{$id}" );
}
@@ -2710,14 +2691,6 @@ class AdditionalFields extends \WP_Test_REST_TestCase {
$data = $response->get_data();
$this->assertEquals( 200, $response->get_status(), print_r( $data, true ) );
-
- \remove_action(
- 'woocommerce_set_additional_field_value',
- array(
- $set_value_mocker,
- 'woocommerce_set_additional_field_value',
- )
- );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Blocks/StoreApi/Routes/Cart.php b/plugins/woocommerce/tests/php/src/Blocks/StoreApi/Routes/Cart.php
index 8dc9b93b2aa..198e88b939b 100644
--- a/plugins/woocommerce/tests/php/src/Blocks/StoreApi/Routes/Cart.php
+++ b/plugins/woocommerce/tests/php/src/Blocks/StoreApi/Routes/Cart.php
@@ -257,32 +257,28 @@ class Cart extends ControllerTestCase {
};
add_filter( 'woocommerce_store_api_cart_item_parent_item_key', $parent_item_key_filter, 10, 3 );
- try {
- $cart_response = rest_get_server()->dispatch( new \WP_REST_Request( 'GET', '/wc/store/v1/cart' ) );
- $this->assertSame( 200, $cart_response->get_status() );
- $cart_items = array_column( $cart_response->get_data()['items'], null, 'key' );
- $this->assertSame( $this->keys[0], $cart_items[ $this->keys[1] ]['parent_item_key'] );
- $this->assertNull( $cart_items[ $this->keys[0] ]['parent_item_key'] );
-
- $remove_request = new \WP_REST_Request( 'POST', '/wc/store/v1/cart/remove-item' );
- $remove_request->set_header( 'Nonce', wp_create_nonce( 'wc_store_api' ) );
- $remove_request->set_body_params( array( 'key' => $this->keys[0] ) );
- $remove_response = rest_get_server()->dispatch( $remove_request );
-
- $this->assertSame( 200, $remove_response->get_status() );
- $remaining_items = array_column( $remove_response->get_data()['items'], null, 'key' );
- $this->assertArrayNotHasKey( $this->keys[0], $remaining_items );
- $this->assertArrayHasKey( $this->keys[1], $remaining_items );
- $this->assertNull( $remaining_items[ $this->keys[1] ]['parent_item_key'] );
- $this->assertSame( 1, $remaining_items[ $this->keys[1] ]['quantity'] );
-
- $this->assertSame( $this->keys[0], wc()->cart->add_to_cart( $this->products[0]->get_id(), 2 ) );
- $restored_response = rest_get_server()->dispatch( new \WP_REST_Request( 'GET', '/wc/store/v1/cart' ) );
- $restored_items = array_column( $restored_response->get_data()['items'], null, 'key' );
- $this->assertSame( $this->keys[0], $restored_items[ $this->keys[1] ]['parent_item_key'] );
- } finally {
- remove_filter( 'woocommerce_store_api_cart_item_parent_item_key', $parent_item_key_filter, 10 );
- }
+ $cart_response = rest_get_server()->dispatch( new \WP_REST_Request( 'GET', '/wc/store/v1/cart' ) );
+ $this->assertSame( 200, $cart_response->get_status() );
+ $cart_items = array_column( $cart_response->get_data()['items'], null, 'key' );
+ $this->assertSame( $this->keys[0], $cart_items[ $this->keys[1] ]['parent_item_key'] );
+ $this->assertNull( $cart_items[ $this->keys[0] ]['parent_item_key'] );
+
+ $remove_request = new \WP_REST_Request( 'POST', '/wc/store/v1/cart/remove-item' );
+ $remove_request->set_header( 'Nonce', wp_create_nonce( 'wc_store_api' ) );
+ $remove_request->set_body_params( array( 'key' => $this->keys[0] ) );
+ $remove_response = rest_get_server()->dispatch( $remove_request );
+
+ $this->assertSame( 200, $remove_response->get_status() );
+ $remaining_items = array_column( $remove_response->get_data()['items'], null, 'key' );
+ $this->assertArrayNotHasKey( $this->keys[0], $remaining_items );
+ $this->assertArrayHasKey( $this->keys[1], $remaining_items );
+ $this->assertNull( $remaining_items[ $this->keys[1] ]['parent_item_key'] );
+ $this->assertSame( 1, $remaining_items[ $this->keys[1] ]['quantity'] );
+
+ $this->assertSame( $this->keys[0], wc()->cart->add_to_cart( $this->products[0]->get_id(), 2 ) );
+ $restored_response = rest_get_server()->dispatch( new \WP_REST_Request( 'GET', '/wc/store/v1/cart' ) );
+ $restored_items = array_column( $restored_response->get_data()['items'], null, 'key' );
+ $this->assertSame( $this->keys[0], $restored_items[ $this->keys[1] ]['parent_item_key'] );
}
/**
@@ -357,14 +353,6 @@ class Cart extends ControllerTestCase {
),
)
);
-
- remove_action(
- 'woocommerce_store_api_cart_update_customer_from_request',
- array(
- $action_callback,
- 'do_customer_callback',
- )
- );
}
/**
@@ -1300,8 +1288,6 @@ class Cart extends ControllerTestCase {
$this->assertNotEmpty( $captured_args, 'The add action should have been fired' );
$this->assertSame( $this->products[0]->get_id(), $captured_args['product_id'] );
$this->assertEquals( 2, $captured_args['quantity'] );
-
- remove_action( 'internal_woocommerce_cart_item_added_from_user_request', $callback );
}
/**
@@ -1333,8 +1319,6 @@ class Cart extends ControllerTestCase {
$this->assertNotEmpty( $captured_args, 'The add action should have been fired' );
$this->assertSame( $this->products[0]->get_id(), $captured_args['product_id'] );
$this->assertEquals( 1, $captured_args['quantity'] );
-
- remove_action( 'internal_woocommerce_cart_item_added_from_user_request', $callback );
}
/**
@@ -1365,8 +1349,6 @@ class Cart extends ControllerTestCase {
$this->assertEquals( 5, $captured_args['quantity'] );
$this->assertEquals( 2, $captured_args['old_quantity'] );
$this->assertInstanceOf( \WC_Cart::class, $captured_args['cart'] );
-
- remove_action( 'internal_woocommerce_cart_item_updated_from_user_request', $callback );
}
/**
@@ -1394,8 +1376,6 @@ class Cart extends ControllerTestCase {
$this->assertNotEmpty( $captured_args, 'The remove action should have been fired' );
$this->assertSame( $this->keys[0], $captured_args['cart_item_key'] );
$this->assertInstanceOf( \WC_Cart::class, $captured_args['cart'] );
-
- remove_action( 'internal_woocommerce_cart_item_removed_from_user_request', $callback );
}
/**
@@ -1421,8 +1401,6 @@ class Cart extends ControllerTestCase {
$this->assertAPIResponse( $request, 200 );
$this->assertFalse( $action_fired, 'The update action should not fire when quantity is unchanged' );
-
- remove_action( 'internal_woocommerce_cart_item_updated_from_user_request', $callback );
}
/**
@@ -1470,8 +1448,6 @@ class Cart extends ControllerTestCase {
$this->assertNotEmpty( $captured_args, 'The add action should have been fired' );
$this->assertSame( $variation->get_id(), $captured_args['product_id'], 'The product_id should be the variation ID, not the parent product ID' );
$this->assertEquals( 1, $captured_args['quantity'] );
-
- remove_action( 'internal_woocommerce_cart_item_added_from_user_request', $callback );
}
/**
@@ -1496,8 +1472,6 @@ class Cart extends ControllerTestCase {
$this->assertAPIResponse( $request, 200 );
$this->assertFalse( $action_fired, 'The update action should not fire when quantity is not set' );
-
- remove_action( 'internal_woocommerce_cart_item_updated_from_user_request', $callback );
}
/**
@@ -1612,8 +1586,6 @@ class Cart extends ControllerTestCase {
$this->assertNotEmpty( $captured_args, 'The update action should have been fired' );
$this->assertSame( 3, $captured_args['quantity'], 'The new quantity should be a numeric value' );
$this->assertSame( 2, $captured_args['old_quantity'], 'The old quantity should be normalized to a numeric value' );
-
- remove_action( 'internal_woocommerce_cart_item_updated_from_user_request', $callback );
}
/**
@@ -1651,9 +1623,6 @@ class Cart extends ControllerTestCase {
$this->assertNotEmpty( $captured_args, 'The add action should have been fired' );
$this->assertSame( 2, $captured_args['quantity'], 'The quantity should be normalized to a numeric value' );
-
- remove_action( 'internal_woocommerce_cart_item_added_from_user_request', $callback );
- remove_filter( 'woocommerce_store_api_add_to_cart_data', $add_to_cart_data_callback );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Blocks/StoreApi/Routes/CartApplyCoupon.php b/plugins/woocommerce/tests/php/src/Blocks/StoreApi/Routes/CartApplyCoupon.php
index 96a2d0feacc..d7d94308ff7 100644
--- a/plugins/woocommerce/tests/php/src/Blocks/StoreApi/Routes/CartApplyCoupon.php
+++ b/plugins/woocommerce/tests/php/src/Blocks/StoreApi/Routes/CartApplyCoupon.php
@@ -272,9 +272,6 @@ class CartApplyCoupon extends ControllerTestCase {
$this->assertEquals( 404, $response->get_status() );
$this->assertEquals( 'woocommerce_rest_cart_coupon_disabled', $data['code'] );
-
- // Re-enable coupons for other tests.
- update_option( 'woocommerce_enable_coupons', 'yes' );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Blocks/StoreApi/Routes/CartItems.php b/plugins/woocommerce/tests/php/src/Blocks/StoreApi/Routes/CartItems.php
index d0f21f7d903..07ce7cd7932 100644
--- a/plugins/woocommerce/tests/php/src/Blocks/StoreApi/Routes/CartItems.php
+++ b/plugins/woocommerce/tests/php/src/Blocks/StoreApi/Routes/CartItems.php
@@ -458,26 +458,22 @@ class CartItems extends ControllerTestCase {
};
add_filter( 'woocommerce_store_api_cart_item_parent_item_key', $parent_item_key_filter );
- try {
- $cart_response = rest_get_server()->dispatch( new \WP_REST_Request( 'GET', '/wc/store/v1/cart' ) );
- $this->assertSame( 200, $cart_response->get_status() );
- $cart_items = array_column( $cart_response->get_data()['items'], null, 'key' );
- $this->assertArrayHasKey( $this->keys[0], $cart_items );
- $this->assertNull( $cart_items[ $this->keys[0] ]['parent_item_key'] );
-
- $items_response = rest_get_server()->dispatch( new \WP_REST_Request( 'GET', '/wc/store/v1/cart/items' ) );
- $this->assertSame( 200, $items_response->get_status() );
- $items = array_column( $items_response->get_data(), null, 'key' );
- $this->assertArrayHasKey( $this->keys[0], $items );
- $this->assertNull( $items[ $this->keys[0] ]['parent_item_key'] );
-
- $item_response = rest_get_server()->dispatch( new \WP_REST_Request( 'GET', '/wc/store/v1/cart/items/' . $this->keys[0] ) );
- $this->assertSame( 200, $item_response->get_status() );
- $this->assertArrayHasKey( 'parent_item_key', $item_response->get_data() );
- $this->assertNull( $item_response->get_data()['parent_item_key'] );
- } finally {
- remove_filter( 'woocommerce_store_api_cart_item_parent_item_key', $parent_item_key_filter );
- }
+ $cart_response = rest_get_server()->dispatch( new \WP_REST_Request( 'GET', '/wc/store/v1/cart' ) );
+ $this->assertSame( 200, $cart_response->get_status() );
+ $cart_items = array_column( $cart_response->get_data()['items'], null, 'key' );
+ $this->assertArrayHasKey( $this->keys[0], $cart_items );
+ $this->assertNull( $cart_items[ $this->keys[0] ]['parent_item_key'] );
+
+ $items_response = rest_get_server()->dispatch( new \WP_REST_Request( 'GET', '/wc/store/v1/cart/items' ) );
+ $this->assertSame( 200, $items_response->get_status() );
+ $items = array_column( $items_response->get_data(), null, 'key' );
+ $this->assertArrayHasKey( $this->keys[0], $items );
+ $this->assertNull( $items[ $this->keys[0] ]['parent_item_key'] );
+
+ $item_response = rest_get_server()->dispatch( new \WP_REST_Request( 'GET', '/wc/store/v1/cart/items/' . $this->keys[0] ) );
+ $this->assertSame( 200, $item_response->get_status() );
+ $this->assertArrayHasKey( 'parent_item_key', $item_response->get_data() );
+ $this->assertNull( $item_response->get_data()['parent_item_key'] );
}
/**
@@ -500,7 +496,6 @@ class CartItems extends ControllerTestCase {
$this->assertNull( $response->get_data()['parent_item_key'] );
} finally {
WC()->cart = $cart;
- remove_filter( 'woocommerce_store_api_cart_item_parent_item_key', $filter );
}
}
@@ -569,23 +564,19 @@ class CartItems extends ControllerTestCase {
};
add_filter( 'woocommerce_get_item_data', $filter );
- try {
- $routes = new \Automattic\WooCommerce\StoreApi\RoutesController( new \Automattic\WooCommerce\StoreApi\SchemaController( $this->mock_extend ) );
- $controller = $routes->get( 'cart-items', 'v1' );
- $cart = WC()->cart->get_cart();
- $response = $controller->prepare_item_for_response( current( $cart ), new \WP_REST_Request() );
-
- $entry = $response->get_data()['item_data'][0];
- $this->assertSame( 'gift_message', $entry['raw_key'] );
- $this->assertSame( 'Gift message', $entry['name'], 'The display label must be left alone.' );
-
- $validate = new ValidateSchema( $controller->get_item_schema() );
- $diff = $validate->get_diff_from_object( $response->get_data() );
- // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_print_r
- $this->assertEmpty( $diff, print_r( $diff, true ) );
- } finally {
- remove_filter( 'woocommerce_get_item_data', $filter );
- }
+ $routes = new \Automattic\WooCommerce\StoreApi\RoutesController( new \Automattic\WooCommerce\StoreApi\SchemaController( $this->mock_extend ) );
+ $controller = $routes->get( 'cart-items', 'v1' );
+ $cart = WC()->cart->get_cart();
+ $response = $controller->prepare_item_for_response( current( $cart ), new \WP_REST_Request() );
+
+ $entry = $response->get_data()['item_data'][0];
+ $this->assertSame( 'gift_message', $entry['raw_key'] );
+ $this->assertSame( 'Gift message', $entry['name'], 'The display label must be left alone.' );
+
+ $validate = new ValidateSchema( $controller->get_item_schema() );
+ $diff = $validate->get_diff_from_object( $response->get_data() );
+ // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_print_r
+ $this->assertEmpty( $diff, print_r( $diff, true ) );
}
/**
@@ -607,16 +598,12 @@ class CartItems extends ControllerTestCase {
};
add_filter( 'woocommerce_get_item_data', $filter );
- try {
- $routes = new \Automattic\WooCommerce\StoreApi\RoutesController( new \Automattic\WooCommerce\StoreApi\SchemaController( $this->mock_extend ) );
- $controller = $routes->get( 'cart-items', 'v1' );
- $cart = WC()->cart->get_cart();
- $response = $controller->prepare_item_for_response( current( $cart ), new \WP_REST_Request() );
+ $routes = new \Automattic\WooCommerce\StoreApi\RoutesController( new \Automattic\WooCommerce\StoreApi\SchemaController( $this->mock_extend ) );
+ $controller = $routes->get( 'cart-items', 'v1' );
+ $cart = WC()->cart->get_cart();
+ $response = $controller->prepare_item_for_response( current( $cart ), new \WP_REST_Request() );
- $this->assertSame( 'acme&co_gift', $response->get_data()['item_data'][0]['raw_key'] );
- } finally {
- remove_filter( 'woocommerce_get_item_data', $filter );
- }
+ $this->assertSame( 'acme&co_gift', $response->get_data()['item_data'][0]['raw_key'] );
}
/**
@@ -637,20 +624,16 @@ class CartItems extends ControllerTestCase {
};
add_filter( 'woocommerce_get_item_data', $filter );
- try {
- $routes = new \Automattic\WooCommerce\StoreApi\RoutesController( new \Automattic\WooCommerce\StoreApi\SchemaController( $this->mock_extend ) );
- $controller = $routes->get( 'cart-items', 'v1' );
- $cart = WC()->cart->get_cart();
- $response = $controller->prepare_item_for_response( current( $cart ), new \WP_REST_Request() );
-
- $entry = $response->get_data()['item_data'][0];
- $this->assertArrayNotHasKey( 'raw_key', $entry, 'raw_key must not be invented.' );
- $this->assertSame( 'gifting_to_hidden', $entry['name'] );
- $this->assertSame( 'recipient@example.com', $entry['value'] );
- $this->assertSame( '1', $entry['hidden'], 'hidden is string-coerced by wp_kses_post().' );
- } finally {
- remove_filter( 'woocommerce_get_item_data', $filter );
- }
+ $routes = new \Automattic\WooCommerce\StoreApi\RoutesController( new \Automattic\WooCommerce\StoreApi\SchemaController( $this->mock_extend ) );
+ $controller = $routes->get( 'cart-items', 'v1' );
+ $cart = WC()->cart->get_cart();
+ $response = $controller->prepare_item_for_response( current( $cart ), new \WP_REST_Request() );
+
+ $entry = $response->get_data()['item_data'][0];
+ $this->assertArrayNotHasKey( 'raw_key', $entry, 'raw_key must not be invented.' );
+ $this->assertSame( 'gifting_to_hidden', $entry['name'] );
+ $this->assertSame( 'recipient@example.com', $entry['value'] );
+ $this->assertSame( '1', $entry['hidden'], 'hidden is string-coerced by wp_kses_post().' );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Blocks/StoreApi/Routes/Checkout.php b/plugins/woocommerce/tests/php/src/Blocks/StoreApi/Routes/Checkout.php
index 37373e1eba9..cd37da39d1f 100644
--- a/plugins/woocommerce/tests/php/src/Blocks/StoreApi/Routes/Checkout.php
+++ b/plugins/woocommerce/tests/php/src/Blocks/StoreApi/Routes/Checkout.php
@@ -1884,7 +1884,6 @@ class Checkout extends \WP_Test_REST_TestCase {
add_action( 'woocommerce_store_api_checkout_update_order_from_request', array( $action_callback, 'do_callback' ), 10, 2 );
$response = rest_get_server()->dispatch( $request );
$this->assertEquals( 200, $response->get_status() );
- remove_action( 'woocommerce_store_api_checkout_update_order_from_request', array( $action_callback, 'do_callback' ), 10, 2 );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Blocks/StoreApi/Routes/UcpCart.php b/plugins/woocommerce/tests/php/src/Blocks/StoreApi/Routes/UcpCart.php
index 6a420baf6ca..685c4936c35 100644
--- a/plugins/woocommerce/tests/php/src/Blocks/StoreApi/Routes/UcpCart.php
+++ b/plugins/woocommerce/tests/php/src/Blocks/StoreApi/Routes/UcpCart.php
@@ -273,14 +273,10 @@ class UcpCart extends UcpCartTestCase {
$bind->setAccessible( true );
$bind->invoke( $route, new \WP_REST_Request( 'POST', '/wc/ucp/v1/carts' ) );
- try {
- $this->assertSame(
- SessionHandler::class,
- apply_filters( 'woocommerce_session_handler', \WC_Session_Handler::class )
- );
- } finally {
- remove_filter( 'woocommerce_session_handler', array( AbstractCartRoute::class, 'session_handler_class' ) );
- }
+ $this->assertSame(
+ SessionHandler::class,
+ apply_filters( 'woocommerce_session_handler', \WC_Session_Handler::class )
+ );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Blocks/StoreApi/Utilities/CartControllerTests.php b/plugins/woocommerce/tests/php/src/Blocks/StoreApi/Utilities/CartControllerTests.php
index 3d23b45ae1a..ad8d18194b0 100644
--- a/plugins/woocommerce/tests/php/src/Blocks/StoreApi/Utilities/CartControllerTests.php
+++ b/plugins/woocommerce/tests/php/src/Blocks/StoreApi/Utilities/CartControllerTests.php
@@ -263,8 +263,6 @@ class CartControllerTests extends \WC_Unit_Test_Case {
$this->assertArrayHasKey( 'package_name', $packages[1], 'Second package should have package_name.' );
$this->assertEquals( 1, $packages[1]['package_id'], 'Second package should have package_id of 1.' );
$this->assertStringContainsString( 'Shipment 2', $packages[1]['package_name'], 'Second package should have package_name containing "Shipment 2".' );
-
- remove_all_filters( 'woocommerce_cart_shipping_packages' );
}
/**
@@ -304,8 +302,6 @@ class CartControllerTests extends \WC_Unit_Test_Case {
$this->assertNotEmpty( $packages, 'Should have at least one shipping package.' );
$this->assertEquals( 'custom-package-123', $packages[0]['package_id'], 'Package should use custom package_id from filter.' );
$this->assertArrayHasKey( 'package_name', $packages[0], 'Package should still have package_name.' );
-
- remove_all_filters( 'woocommerce_cart_shipping_packages' );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Blocks/StoreApi/Utilities/LocalPickupUtilsTest.php b/plugins/woocommerce/tests/php/src/Blocks/StoreApi/Utilities/LocalPickupUtilsTest.php
index bb0df2dd301..58050bf1453 100644
--- a/plugins/woocommerce/tests/php/src/Blocks/StoreApi/Utilities/LocalPickupUtilsTest.php
+++ b/plugins/woocommerce/tests/php/src/Blocks/StoreApi/Utilities/LocalPickupUtilsTest.php
@@ -252,8 +252,6 @@ class LocalPickupUtilsTest extends \WC_Unit_Test_Case {
$this->assertCount( 1, $result );
$this->assertSame( 'GB', $result[0]['address']['country'] );
$this->assertSame( 'LND', $result[0]['address']['state'] );
-
- remove_all_filters( 'pre_option_woocommerce_default_country' );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Blocks/StoreApi/Utilities/OrderControllerTests.php b/plugins/woocommerce/tests/php/src/Blocks/StoreApi/Utilities/OrderControllerTests.php
index b4706476434..8e946dbc702 100644
--- a/plugins/woocommerce/tests/php/src/Blocks/StoreApi/Utilities/OrderControllerTests.php
+++ b/plugins/woocommerce/tests/php/src/Blocks/StoreApi/Utilities/OrderControllerTests.php
@@ -446,7 +446,6 @@ class OrderControllerTests extends \WC_Unit_Test_Case {
$errors = new \WP_Error();
$this->sut->validate_address_fields( $order, 'shipping', $errors );
$this->assertEmpty( $errors->get_error_messages() );
- remove_filter( 'woocommerce_get_country_locale', $hide_postcode );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Blocks/StoreApi/Utilities/QuantityLimitsTests.php b/plugins/woocommerce/tests/php/src/Blocks/StoreApi/Utilities/QuantityLimitsTests.php
index 3925280c7f1..b8367b5c5d4 100644
--- a/plugins/woocommerce/tests/php/src/Blocks/StoreApi/Utilities/QuantityLimitsTests.php
+++ b/plugins/woocommerce/tests/php/src/Blocks/StoreApi/Utilities/QuantityLimitsTests.php
@@ -79,7 +79,6 @@ class QuantityLimitsTests extends \WC_Unit_Test_Case {
$this->assertEquals( 2, $limits['minimum'], 'Minimum quantity should be 2' );
$this->assertEquals( 10, $limits['maximum'], 'Maximum quantity should be 10 to match stock quantity' );
$this->assertEquals( 2, $limits['multiple_of'], 'Multiple of should be 2' );
- remove_all_filters( 'woocommerce_quantity_input_args' );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Blocks/Utils/BlockTemplateUtilsTest.php b/plugins/woocommerce/tests/php/src/Blocks/Utils/BlockTemplateUtilsTest.php
index 27a7b4e0b91..cecba57b504 100644
--- a/plugins/woocommerce/tests/php/src/Blocks/Utils/BlockTemplateUtilsTest.php
+++ b/plugins/woocommerce/tests/php/src/Blocks/Utils/BlockTemplateUtilsTest.php
@@ -314,8 +314,6 @@ class BlockTemplateUtilsTest extends WP_UnitTestCase {
switch_theme( 'twentytwentytwo' );
check_theme_switched();
$this->assertFalse( BlockTemplateUtils::should_use_blockified_product_grid_templates() );
-
- delete_option( Options::WC_BLOCK_USE_BLOCKIFIED_PRODUCT_GRID_BLOCK_AS_TEMPLATE );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Gateways/PayPal/NoticesTest.php b/plugins/woocommerce/tests/php/src/Gateways/PayPal/NoticesTest.php
index 34e48984afd..b8c99dd6b1a 100644
--- a/plugins/woocommerce/tests/php/src/Gateways/PayPal/NoticesTest.php
+++ b/plugins/woocommerce/tests/php/src/Gateways/PayPal/NoticesTest.php
@@ -283,7 +283,6 @@ class NoticesTest extends \WC_Unit_Test_Case {
* @param bool $should_display Whether the notice should display.
*/
public function test_unsupported_currency_notice_respects_currency( $currency, $should_display ) {
- $store_currency = get_option( 'woocommerce_currency' );
// Set the currency.
update_option( 'woocommerce_currency', $currency );
@@ -299,16 +298,12 @@ class NoticesTest extends \WC_Unit_Test_Case {
} else {
$this->assertStringNotContainsString( 'PayPal Standard does not support your store currency', $output );
}
-
- // Reset currency.
- update_option( 'woocommerce_currency', $store_currency );
}
/**
* Test that unsupported currency notice is not displayed when dismissed.
*/
public function test_unsupported_currency_notice_not_displayed_when_dismissed() {
- $store_currency = get_option( 'woocommerce_currency' );
// Set the currency.
update_option( 'woocommerce_currency', 'TRY' );
update_user_meta( $this->admin_user_id, 'dismissed_paypal_unsupported_currency_notice', true );
@@ -320,9 +315,6 @@ class NoticesTest extends \WC_Unit_Test_Case {
$output = ob_get_clean();
$this->assertStringNotContainsString( 'PayPal Standard does not support your store currency', $output );
-
- // Reset currency.
- update_option( 'woocommerce_currency', $store_currency );
}
/**
@@ -363,9 +355,6 @@ class NoticesTest extends \WC_Unit_Test_Case {
// Verify the flag is still 'yes'.
$this->assertEquals( 'yes', get_option( 'woocommerce_paypal_account_restricted_status', 'no' ) );
-
- // Clean up.
- remove_filter( 'pre_update_option_woocommerce_paypal_account_restricted_status', $track_updates );
}
/**
@@ -406,9 +395,6 @@ class NoticesTest extends \WC_Unit_Test_Case {
// Verify the flag is still 'no'.
$this->assertEquals( 'no', get_option( 'woocommerce_paypal_account_restricted_status', 'no' ) );
-
- // Clean up.
- remove_filter( 'pre_update_option_woocommerce_paypal_account_restricted_status', $track_updates );
}
/**
@@ -495,7 +481,6 @@ class NoticesTest extends \WC_Unit_Test_Case {
update_option( 'woocommerce_paypal_account_restricted_status', 'yes' );
$this->mock_gateway_available();
- $store_currency = get_option( 'woocommerce_currency' );
update_option( 'woocommerce_currency', 'TRY' );
$notices = new Notices();
@@ -510,9 +495,6 @@ class NoticesTest extends \WC_Unit_Test_Case {
$this->assertStringContainsString( 'PayPal Account Restricted', $output );
// Should contain unsupported currency notice.
$this->assertStringContainsString( 'PayPal Standard does not support your store currency', $output );
-
- // Reset currency.
- update_option( 'woocommerce_currency', $store_currency );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Gateways/PayPal/RequestTest.php b/plugins/woocommerce/tests/php/src/Gateways/PayPal/RequestTest.php
index 836fe97e79d..1380d2b8c62 100644
--- a/plugins/woocommerce/tests/php/src/Gateways/PayPal/RequestTest.php
+++ b/plugins/woocommerce/tests/php/src/Gateways/PayPal/RequestTest.php
@@ -552,8 +552,6 @@ class RequestTest extends \WC_Unit_Test_Case {
// Second call: should not hit order details again because flag is set.
$request->capture_authorized_payment( $order );
$this->assertEquals( 1, $order_details_call_count, 'Expected no additional order details request after 404 (flag prevents retry)' );
-
- remove_all_filters( 'pre_http_request' );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Internal/AbilitiesApi/ExtensibleAbilitiesTest.php b/plugins/woocommerce/tests/php/src/Internal/AbilitiesApi/ExtensibleAbilitiesTest.php
index c885dd7d848..1a27f92373b 100644
--- a/plugins/woocommerce/tests/php/src/Internal/AbilitiesApi/ExtensibleAbilitiesTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/AbilitiesApi/ExtensibleAbilitiesTest.php
@@ -496,7 +496,6 @@ class ExtensibleAbilitiesTest extends \WC_REST_Unit_Test_Case {
} finally {
remove_all_filters( 'pre_option_' . DataSynchronizer::ORDERS_DATA_SYNC_ENABLED_OPTION );
$this->toggle_cot_feature_and_usage( $original );
- remove_filter( 'wc_allow_changing_orders_storage_while_sync_is_pending', '__return_true' );
}
}
@@ -565,7 +564,6 @@ class ExtensibleAbilitiesTest extends \WC_REST_Unit_Test_Case {
remove_action( 'woocommerce_extensible_abilities_init', array( $this, 'register_contains_product_filter' ) );
remove_all_filters( 'pre_option_' . DataSynchronizer::ORDERS_DATA_SYNC_ENABLED_OPTION );
$this->toggle_cot_feature_and_usage( $original );
- remove_filter( 'wc_allow_changing_orders_storage_while_sync_is_pending', '__return_true' );
}
}
@@ -608,7 +606,6 @@ class ExtensibleAbilitiesTest extends \WC_REST_Unit_Test_Case {
} finally {
remove_action( 'woocommerce_extensible_abilities_init', array( $this, 'register_contains_product_filter' ) );
$this->toggle_cot_feature_and_usage( $original );
- remove_filter( 'wc_allow_changing_orders_storage_while_sync_is_pending', '__return_true' );
}
}
@@ -3528,8 +3525,6 @@ class ExtensibleAbilitiesTest extends \WC_REST_Unit_Test_Case {
$this->assertSame( 'completed', wc_get_order( $order->get_id() )->get_status() );
}
}
-
- remove_filter( 'woocommerce_order_class', $filter_class, 100 );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Internal/AddressProvider/AbstractAutomatticAddressProviderTest.php b/plugins/woocommerce/tests/php/src/Internal/AddressProvider/AbstractAutomatticAddressProviderTest.php
index 70aa1f70cba..107d43d7367 100644
--- a/plugins/woocommerce/tests/php/src/Internal/AddressProvider/AbstractAutomatticAddressProviderTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/AddressProvider/AbstractAutomatticAddressProviderTest.php
@@ -518,9 +518,6 @@ class AbstractAutomatticAddressProviderTest extends \WC_Unit_Test_Case {
// Check if script is registered and enqueued.
$this->assertTrue( wp_script_is( 'a8c-address-autocomplete-service', 'registered' ) );
$this->assertTrue( wp_script_is( 'a8c-address-autocomplete-service', 'enqueued' ) );
-
- // Clean up filter.
- remove_all_filters( 'woocommerce_is_checkout' );
}
/**
@@ -579,9 +576,6 @@ class AbstractAutomatticAddressProviderTest extends \WC_Unit_Test_Case {
// If no inline script was added, that's also acceptable for this test.
$this->assertTrue( true );
}
-
- // Clean up filter.
- remove_all_filters( 'woocommerce_is_checkout' );
}
/**
@@ -631,9 +625,6 @@ class AbstractAutomatticAddressProviderTest extends \WC_Unit_Test_Case {
// If no inline script was added, that's also acceptable for this test.
$this->assertTrue( true );
}
-
- // Clean up filter.
- remove_all_filters( 'woocommerce_is_checkout' );
}
/**
@@ -684,9 +675,6 @@ class AbstractAutomatticAddressProviderTest extends \WC_Unit_Test_Case {
// Script should still be registered and enqueued only once.
$this->assertTrue( wp_script_is( 'a8c-address-autocomplete-service', 'registered' ) );
$this->assertTrue( wp_script_is( 'a8c-address-autocomplete-service', 'enqueued' ) );
-
- // Clean up filter.
- remove_all_filters( 'woocommerce_is_checkout' );
}
/**
@@ -995,8 +983,5 @@ class AbstractAutomatticAddressProviderTest extends \WC_Unit_Test_Case {
// Check that script was not enqueued.
$this->assertFalse( wp_script_is( 'a8c-address-autocomplete-service', 'enqueued' ) );
-
- // Clean up filter.
- remove_all_filters( 'woocommerce_is_checkout' );
}
}
diff --git a/plugins/woocommerce/tests/php/src/Internal/Admin/AnalyticsTest.php b/plugins/woocommerce/tests/php/src/Internal/Admin/AnalyticsTest.php
index 04f064958c7..4baed2b2641 100644
--- a/plugins/woocommerce/tests/php/src/Internal/Admin/AnalyticsTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/Admin/AnalyticsTest.php
@@ -906,42 +906,30 @@ class AnalyticsTest extends WC_Unit_Test_Case {
$analytics = new Analytics();
- try {
- $this->assertNotFalse(
- has_filter( 'woocommerce_component_settings_preload_endpoints', array( $analytics, 'add_preload_endpoints' ) ),
- 'Preload endpoints filter should be registered in the admin area.'
- );
- $this->assertNotFalse(
- has_filter( 'woocommerce_admin_get_user_data_fields', array( $analytics, 'add_user_data_fields' ) ),
- 'User data fields filter should be registered in the admin area.'
- );
- $this->assertNotFalse(
- has_action( 'admin_menu', array( $analytics, 'register_pages' ) ),
- 'Admin menu action should be registered in the admin area.'
- );
- $this->assertNotFalse(
- has_filter( 'woocommerce_debug_tools', array( $analytics, 'register_cache_clear_tool' ) ),
- 'Cache clear tool filter should be registered in the admin area.'
- );
- $this->assertNotFalse(
- has_filter( 'woocommerce_debug_tools', array( $analytics, 'register_regenerate_order_fulfillment_status_tool' ) ),
- 'Regenerate fulfillment status tool filter should be registered in the admin area.'
- );
- $this->assertNotFalse(
- has_filter( 'woocommerce_debug_tools', array( $analytics, 'register_refund_double_count_tool' ) ),
- 'Refund double-count tool filter should be registered in the admin area.'
- );
- } finally {
- remove_filter( 'woocommerce_component_settings_preload_endpoints', array( $analytics, 'add_preload_endpoints' ) );
- remove_filter( 'woocommerce_admin_get_user_data_fields', array( $analytics, 'add_user_data_fields' ) );
- remove_action( 'admin_menu', array( $analytics, 'register_pages' ) );
- remove_filter( 'woocommerce_debug_tools', array( $analytics, 'register_cache_clear_tool' ) );
- remove_filter( 'woocommerce_debug_tools', array( $analytics, 'register_regenerate_order_fulfillment_status_tool' ), 12 );
- remove_filter( 'woocommerce_debug_tools', array( $analytics, 'register_refund_double_count_tool' ) );
- remove_action( 'woocommerce_analytics_refund_fix_batch', array( $analytics, 'process_refund_fix_batch' ) );
- remove_action( Analytics::REFUND_DOUBLE_COUNT_FIX_HOOK, array( $analytics, 'process_refund_double_count_fix_batch' ) );
- remove_action( 'woocommerce_analytics_regenerate_init', array( $analytics, 'maybe_cancel_refund_double_count_fix_on_regenerate' ) );
- }
+ $this->assertNotFalse(
+ has_filter( 'woocommerce_component_settings_preload_endpoints', array( $analytics, 'add_preload_endpoints' ) ),
+ 'Preload endpoints filter should be registered in the admin area.'
+ );
+ $this->assertNotFalse(
+ has_filter( 'woocommerce_admin_get_user_data_fields', array( $analytics, 'add_user_data_fields' ) ),
+ 'User data fields filter should be registered in the admin area.'
+ );
+ $this->assertNotFalse(
+ has_action( 'admin_menu', array( $analytics, 'register_pages' ) ),
+ 'Admin menu action should be registered in the admin area.'
+ );
+ $this->assertNotFalse(
+ has_filter( 'woocommerce_debug_tools', array( $analytics, 'register_cache_clear_tool' ) ),
+ 'Cache clear tool filter should be registered in the admin area.'
+ );
+ $this->assertNotFalse(
+ has_filter( 'woocommerce_debug_tools', array( $analytics, 'register_regenerate_order_fulfillment_status_tool' ) ),
+ 'Regenerate fulfillment status tool filter should be registered in the admin area.'
+ );
+ $this->assertNotFalse(
+ has_filter( 'woocommerce_debug_tools', array( $analytics, 'register_refund_double_count_tool' ) ),
+ 'Refund double-count tool filter should be registered in the admin area.'
+ );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Internal/Admin/EmailPreview/EmailPreviewRestControllerTest.php b/plugins/woocommerce/tests/php/src/Internal/Admin/EmailPreview/EmailPreviewRestControllerTest.php
index c6f415bbaed..dbeb573643c 100644
--- a/plugins/woocommerce/tests/php/src/Internal/Admin/EmailPreview/EmailPreviewRestControllerTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/Admin/EmailPreview/EmailPreviewRestControllerTest.php
@@ -116,8 +116,6 @@ class EmailPreviewRestControllerTest extends WC_REST_Unit_Test_Case {
$response = $this->server->dispatch( $request );
$this->assertEquals( rest_authorization_required_code(), $response->get_status() );
-
- remove_filter( 'user_has_cap', $filter_callback );
}
/**
@@ -142,8 +140,6 @@ class EmailPreviewRestControllerTest extends WC_REST_Unit_Test_Case {
$this->assertEquals( 500, $response->get_status() );
$this->assertEquals( 'Error sending test email. Please try again.', $response->get_data()['message'] );
-
- remove_filter( 'woocommerce_mail_callback', array( $this, 'simulate_failed_sending' ), 10 );
}
/**
@@ -165,20 +161,16 @@ class EmailPreviewRestControllerTest extends WC_REST_Unit_Test_Case {
};
add_action( 'woocommerce_email_sent', $capture, 10, 3 );
- try {
- $request = $this->get_email_preview_request( EmailPreview::DEFAULT_EMAIL_TYPE, self::EMAIL );
- $response = $this->server->dispatch( $request );
+ $request = $this->get_email_preview_request( EmailPreview::DEFAULT_EMAIL_TYPE, self::EMAIL );
+ $response = $this->server->dispatch( $request );
- $this->assertEquals( 200, $response->get_status() );
- $this->assertNotEmpty( $captured, 'woocommerce_email_sent should fire for the preview send path.' );
-
- $last = end( $captured );
- $this->assertSame( EmailPreview::DEFAULT_EMAIL_TYPE, $last['class'], 'Send path should use the resolved WC_Email subclass, not a generic WC_Emails instance.' );
- $this->assertNotEmpty( $last['email_id'], 'Email id should be set so listeners can identify the email type.' );
- $this->assertSame( self::EMAIL, $last['recipient'], 'Recipient should be set on the resolved instance before send.' );
- } finally {
- remove_action( 'woocommerce_email_sent', $capture, 10 );
- }
+ $this->assertEquals( 200, $response->get_status() );
+ $this->assertNotEmpty( $captured, 'woocommerce_email_sent should fire for the preview send path.' );
+
+ $last = end( $captured );
+ $this->assertSame( EmailPreview::DEFAULT_EMAIL_TYPE, $last['class'], 'Send path should use the resolved WC_Email subclass, not a generic WC_Emails instance.' );
+ $this->assertNotEmpty( $last['email_id'], 'Email id should be set so listeners can identify the email type.' );
+ $this->assertSame( self::EMAIL, $last['recipient'], 'Recipient should be set on the resolved instance before send.' );
}
/**
@@ -264,8 +256,6 @@ class EmailPreviewRestControllerTest extends WC_REST_Unit_Test_Case {
$response = $this->server->dispatch( $request );
$this->assertEquals( rest_authorization_required_code(), $response->get_status() );
-
- remove_filter( 'user_has_cap', $filter_callback );
}
/**
@@ -368,8 +358,6 @@ class EmailPreviewRestControllerTest extends WC_REST_Unit_Test_Case {
$response = $this->server->dispatch( $request );
$this->assertEquals( rest_authorization_required_code(), $response->get_status() );
-
- remove_filter( 'user_has_cap', $filter_callback );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Internal/Admin/EmailPreview/EmailPreviewTest.php b/plugins/woocommerce/tests/php/src/Internal/Admin/EmailPreview/EmailPreviewTest.php
index 08d8f5944d0..9e95ebf371a 100644
--- a/plugins/woocommerce/tests/php/src/Internal/Admin/EmailPreview/EmailPreviewTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/Admin/EmailPreview/EmailPreviewTest.php
@@ -158,7 +158,6 @@ class EmailPreviewTest extends WC_Unit_Test_Case {
$product = $this->sut->get_dummy_product_when_not_set( null );
$this->assertEquals( 'Filtered Product', $product->get_name() );
$this->assertEquals( '99', $product->get_price() );
- remove_filter( 'woocommerce_email_preview_dummy_product', $product_filter, 10 );
}
/**
@@ -174,8 +173,6 @@ class EmailPreviewTest extends WC_Unit_Test_Case {
$content = $this->sut->render();
$this->assertStringContainsString( '500.00', $content );
$this->assertStringNotContainsString( '100.00', $content );
-
- remove_filter( 'woocommerce_email_preview_dummy_order', $order_filter, 10 );
}
/**
@@ -223,8 +220,6 @@ class EmailPreviewTest extends WC_Unit_Test_Case {
$content = $this->sut->render();
$this->assertStringContainsString( 'Jane Smith', $content );
$this->assertStringNotContainsString( 'John Doe', $content );
-
- remove_filter( 'woocommerce_email_preview_dummy_address', $address_filter, 10 );
}
/**
@@ -241,8 +236,6 @@ class EmailPreviewTest extends WC_Unit_Test_Case {
$subject = $this->sut->get_subject();
$this->assertStringContainsString( '98765', $subject );
$this->assertStringNotContainsString( '12345', $subject );
-
- remove_filter( 'woocommerce_email_preview_placeholders', $placeholders_filter, 10 );
}
/**
@@ -260,8 +253,6 @@ class EmailPreviewTest extends WC_Unit_Test_Case {
$subject = $this->sut->get_subject();
$this->assertStringContainsString( 'Filtered Subject 12345', $subject );
$this->assertStringNotContainsString( 'Your ' . self::SITE_TITLE . ' order has been received!', $subject );
-
- remove_filter( 'woocommerce_prepare_email_for_preview', $email_filter, 10 );
}
/**
@@ -343,8 +334,6 @@ class EmailPreviewTest extends WC_Unit_Test_Case {
$this->sut->set_email_type( 'WC_Email_Customer_Completed_Order' );
$content = $this->sut->render();
$this->assertStringContainsString( 'Filtered Downloadable Product', $content );
-
- remove_filter( 'woocommerce_email_preview_dummy_downloadable_product', $downloadable_product_filter, 10 );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Internal/Admin/Logging/FileV2/FileControllerTest.php b/plugins/woocommerce/tests/php/src/Internal/Admin/Logging/FileV2/FileControllerTest.php
index f799a800910..79f29cb6b0b 100644
--- a/plugins/woocommerce/tests/php/src/Internal/Admin/Logging/FileV2/FileControllerTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/Admin/Logging/FileV2/FileControllerTest.php
@@ -180,8 +180,6 @@ class FileControllerTest extends WC_Unit_Test_Case {
break;
}
}
-
- remove_filter( 'woocommerce_log_file_size_limit', $filter_callback );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Internal/Admin/Logging/SettingsTest.php b/plugins/woocommerce/tests/php/src/Internal/Admin/Logging/SettingsTest.php
index 72ccbec918f..13bb2e84217 100644
--- a/plugins/woocommerce/tests/php/src/Internal/Admin/Logging/SettingsTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/Admin/Logging/SettingsTest.php
@@ -179,8 +179,6 @@ class SettingsTest extends WC_Unit_Test_Case {
$files = $this->file_controller->get_files();
$this->assertCount( 0, $files );
-
- delete_option( 'woocommerce_logs_logging_enabled' );
}
/**
@@ -225,8 +223,6 @@ class SettingsTest extends WC_Unit_Test_Case {
update_option( 'woocommerce_logs_default_handler', 'Smorgasbord' );
$handler = $this->sut->get_default_handler();
$this->assertEquals( LogHandlerFileV2::class, $handler );
-
- delete_option( 'woocommerce_logs_default_handler' );
}
/**
@@ -251,7 +247,6 @@ class SettingsTest extends WC_Unit_Test_Case {
add_filter( 'woocommerce_logger_days_to_retain_logs', '__return_zero' );
$retention = $this->sut->get_retention_period();
$this->assertEquals( 30, $retention );
- remove_all_filters( 'woocommerce_logger_days_to_retain_logs' );
}
/**
@@ -273,8 +268,6 @@ class SettingsTest extends WC_Unit_Test_Case {
update_option( 'woocommerce_logs_retention_period_days', 'french toast' );
$handler = $this->sut->get_retention_period();
$this->assertEquals( 30, $handler );
-
- delete_option( 'woocommerce_logs_retention_period_days' );
}
/**
@@ -319,8 +312,6 @@ class SettingsTest extends WC_Unit_Test_Case {
update_option( 'woocommerce_logs_level_threshold', 123 );
$level = $this->sut->get_level_threshold();
$this->assertEquals( 'none', $level );
-
- delete_option( 'woocommerce_logs_level_threshold' );
}
/**
@@ -336,8 +327,6 @@ class SettingsTest extends WC_Unit_Test_Case {
$this->assertStringNotContainsString( 'Log storage', $content );
$this->assertStringNotContainsString( 'Retention period', $content );
$this->assertStringNotContainsString( 'Level threshold', $content );
-
- delete_option( 'woocommerce_logs_logging_enabled' );
}
/**
@@ -379,8 +368,6 @@ class SettingsTest extends WC_Unit_Test_Case {
'This setting cannot be changed here because it is being set by a filter on the <code>woocommerce_logger_days_to_retain_logs</code> hook',
$content
);
-
- remove_all_filters( 'woocommerce_logger_days_to_retain_logs' );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Internal/Admin/Orders/ListTableTest.php b/plugins/woocommerce/tests/php/src/Internal/Admin/Orders/ListTableTest.php
index 4316c4f2191..4c8519c7fad 100644
--- a/plugins/woocommerce/tests/php/src/Internal/Admin/Orders/ListTableTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/Admin/Orders/ListTableTest.php
@@ -162,8 +162,6 @@ class ListTableTest extends \WC_Unit_Test_Case {
$this->assertEquals( 2024, end( $year_months )->year );
$this->assertEquals( 12, end( $year_months )->month );
-
- delete_option( 'gmt_offset' );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Internal/Admin/ProductReviews/ReviewsListTableTest.php b/plugins/woocommerce/tests/php/src/Internal/Admin/ProductReviews/ReviewsListTableTest.php
index 90addee2f11..776b4734022 100644
--- a/plugins/woocommerce/tests/php/src/Internal/Admin/ProductReviews/ReviewsListTableTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/Admin/ProductReviews/ReviewsListTableTest.php
@@ -367,8 +367,6 @@ class ReviewsListTableTest extends WC_Unit_Test_Case {
),
$this->get_reviews_list_table()->get_columns()
);
-
- remove_filter( 'woocommerce_product_reviews_table_columns', $filter_callback );
}
/**
@@ -1661,8 +1659,6 @@ class ReviewsListTableTest extends WC_Unit_Test_Case {
$method->invokeArgs( $list_table, array( $review, 'custom_column' ) );
$this->assertSame( 'Custom content for "custom_column" for ID ' . $review->comment_ID, ob_get_clean() );
-
- remove_action( 'woocommerce_product_reviews_table_column_custom_column', $callback );
}
/**
@@ -1688,8 +1684,6 @@ class ReviewsListTableTest extends WC_Unit_Test_Case {
$output = $method->invokeArgs( $list_table, array( 'test', 'test content', $review ) );
$this->assertSame( 'Additional content to "test content" for test column belonging to review with ID: ' . (string) $review->comment_ID, $output );
-
- remove_filter( 'woocommerce_product_reviews_table_column_test_content', $callback );
}
/**
@@ -2097,15 +2091,11 @@ class ReviewsListTableTest extends WC_Unit_Test_Case {
};
add_filter( 'edit_comments_per_page', $legacy );
- try {
- $this->assertSame( 45, $method->invoke( $list_table ) );
+ $this->assertSame( 45, $method->invoke( $list_table ) );
- // phpcs:ignore WooCommerce.Commenting.CommentHooks -- Mirrors WordPress's Screen Options filter.
- $input_per_page = (int) apply_filters( Reviews::PER_PAGE_USER_OPTION_KEY, 20 );
- $this->assertSame( 45, $input_per_page );
- } finally {
- remove_filter( 'edit_comments_per_page', $legacy );
- }
+ // phpcs:ignore WooCommerce.Commenting.CommentHooks -- Mirrors WordPress's Screen Options filter.
+ $input_per_page = (int) apply_filters( Reviews::PER_PAGE_USER_OPTION_KEY, 20 );
+ $this->assertSame( 45, $input_per_page );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Internal/Admin/ProductReviews/ReviewsTest.php b/plugins/woocommerce/tests/php/src/Internal/Admin/ProductReviews/ReviewsTest.php
index 087b02c156d..48fa0938b83 100644
--- a/plugins/woocommerce/tests/php/src/Internal/Admin/ProductReviews/ReviewsTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/Admin/ProductReviews/ReviewsTest.php
@@ -63,8 +63,6 @@ class ReviewsTest extends WC_Unit_Test_Case {
add_filter( 'woocommerce_product_reviews_page_capability', $callback );
$this->assertEquals( 'manage_woocommerce', Reviews::get_capability() );
-
- remove_filter( 'woocommerce_product_reviews_page_capability', $callback );
}
/**
@@ -803,8 +801,6 @@ test2</p></div>',
add_filter( 'woocommerce_product_reviews_is_product_review_or_reply', $callback );
$this->assertTrue( $method->invoke( $reviews, new stdClass() ) );
-
- remove_filter( 'woocommerce_product_reviews_is_product_review_or_reply', $callback );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Internal/Admin/ProductReviews/ReviewsUtilTest.php b/plugins/woocommerce/tests/php/src/Internal/Admin/ProductReviews/ReviewsUtilTest.php
index 6d336217a7b..97fa159f86b 100644
--- a/plugins/woocommerce/tests/php/src/Internal/Admin/ProductReviews/ReviewsUtilTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/Admin/ProductReviews/ReviewsUtilTest.php
@@ -159,9 +159,6 @@ class ReviewsUtilTest extends WC_Unit_Test_Case {
if ( $post_id ) {
wp_delete_post( $post_id, true );
}
-
- // Remove the filter.
- remove_all_filters( 'admin_url' );
}
/** @see test_modify_product_review_moderation_urls */
@@ -205,8 +202,5 @@ class ReviewsUtilTest extends WC_Unit_Test_Case {
$result = ReviewsUtil::modify_product_review_moderation_urls( $original_message, 999999 ); // Non-existent comment ID.
$this->assertEquals( $original_message, $result );
-
- // Remove the filter.
- remove_all_filters( 'admin_url' );
}
}
diff --git a/plugins/woocommerce/tests/php/src/Internal/Admin/RemoteFreeExtensions/EvaluateOverridesTest.php b/plugins/woocommerce/tests/php/src/Internal/Admin/RemoteFreeExtensions/EvaluateOverridesTest.php
index 5fb285743a9..468ef6a56b0 100644
--- a/plugins/woocommerce/tests/php/src/Internal/Admin/RemoteFreeExtensions/EvaluateOverridesTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/Admin/RemoteFreeExtensions/EvaluateOverridesTest.php
@@ -51,8 +51,7 @@ class EvaluateOverridesTest extends WC_Unit_Test_Case {
* @return void
*/
public function test_overrides_can_use_existing_rules() {
- $current_wc_country = get_option( 'woocommerce_default_country' );
- $evaluator = new EvaluateOverrides();
+ $evaluator = new EvaluateOverrides();
$extensions = $this->get_extensions();
// Set default country to "CA".
@@ -71,9 +70,6 @@ class EvaluateOverridesTest extends WC_Unit_Test_Case {
// Evaluation should pass and return the overridden value.
$this->assertEquals( 2, $result[0]->order );
-
- // Reset the default country.
- update_option( 'woocommerce_default_country', $current_wc_country );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Internal/Admin/RemoteFreeExtensions/InitTest.php b/plugins/woocommerce/tests/php/src/Internal/Admin/RemoteFreeExtensions/InitTest.php
index 783c05825bf..50e28680a69 100644
--- a/plugins/woocommerce/tests/php/src/Internal/Admin/RemoteFreeExtensions/InitTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/Admin/RemoteFreeExtensions/InitTest.php
@@ -155,13 +155,9 @@ class InitTest extends WC_Unit_Test_Case {
return array();
};
add_filter( DataSourcePoller::FILTER_NAME, $data_sources_filter );
- try {
- $specs = RemoteFreeExtensions::get_specs();
- $defaults = DefaultFreeExtensions::get_all();
- $this->assertEquals( $defaults, $specs );
- } finally {
- remove_filter( DataSourcePoller::FILTER_NAME, $data_sources_filter );
- }
+ $specs = RemoteFreeExtensions::get_specs();
+ $defaults = DefaultFreeExtensions::get_all();
+ $this->assertEquals( $defaults, $specs );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Internal/Admin/Schedulers/OrdersSchedulerTest.php b/plugins/woocommerce/tests/php/src/Internal/Admin/Schedulers/OrdersSchedulerTest.php
index 1320ddd7adc..09b2e9e4e82 100644
--- a/plugins/woocommerce/tests/php/src/Internal/Admin/Schedulers/OrdersSchedulerTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/Admin/Schedulers/OrdersSchedulerTest.php
@@ -744,8 +744,6 @@ class OrdersSchedulerTest extends WC_Unit_Test_Case {
add_filter( 'woocommerce_analytics_is_test_order', '__return_true' );
$this->assertTrue( OrdersScheduler::is_test_order( $order ) );
-
- remove_filter( 'woocommerce_analytics_is_test_order', '__return_true' );
}
/**
@@ -763,8 +761,6 @@ class OrdersSchedulerTest extends WC_Unit_Test_Case {
add_filter( 'woocommerce_analytics_is_test_order', '__return_false' );
$this->assertFalse( OrdersScheduler::is_test_order( $order ) );
-
- remove_filter( 'woocommerce_analytics_is_test_order', '__return_false' );
}
/**
@@ -815,8 +811,6 @@ class OrdersSchedulerTest extends WC_Unit_Test_Case {
$this->assertNotNull( $received_order );
$this->assertEquals( $order->get_id(), $received_order->get_id() );
-
- remove_filter( 'woocommerce_analytics_is_test_order', $filter_callback );
}
/**
@@ -1096,32 +1090,28 @@ class OrdersSchedulerTest extends WC_Unit_Test_Case {
);
};
- try {
- $order = \WC_Helper_Order::create_order();
- $order->set_status( 'completed' );
- $order->save();
- $order_id = $order->get_id();
- OrdersScheduler::import( $order_id );
+ $order = \WC_Helper_Order::create_order();
+ $order->set_status( 'completed' );
+ $order->save();
+ $order_id = $order->get_id();
+ OrdersScheduler::import( $order_id );
- // Trash. woocommerce_trash_order fires after the status is persisted, so the
- // synchronous import records it correctly without any queue run.
- $order->delete( false );
- $this->assertSame( 'wc-trash', $read_status( $order_id ), 'Trashing should sync wc-trash synchronously.' );
+ // Trash. woocommerce_trash_order fires after the status is persisted, so the
+ // synchronous import records it correctly without any queue run.
+ $order->delete( false );
+ $this->assertSame( 'wc-trash', $read_status( $order_id ), 'Trashing should sync wc-trash synchronously.' );
- // Restore. Note delete() cleared the in-memory ID, so reload first.
- $order = wc_get_order( $order_id );
- $order->get_data_store()->untrash_order( $order );
+ // Restore. Note delete() cleared the in-memory ID, so reload first.
+ $order = wc_get_order( $order_id );
+ $order->get_data_store()->untrash_order( $order );
- // Deliberately no queue run: the import already ran inline, and it must have
- // seen the restored status rather than the trashed one.
- $this->assertSame(
- 'wc-completed',
- $read_status( $order_id ),
- 'Untrashing should sync the restored status, not wc-trash, on the synchronous path.'
- );
- } finally {
- remove_filter( 'woocommerce_analytics_disable_action_scheduling', '__return_true' );
- }
+ // Deliberately no queue run: the import already ran inline, and it must have
+ // seen the restored status rather than the trashed one.
+ $this->assertSame(
+ 'wc-completed',
+ $read_status( $order_id ),
+ 'Untrashing should sync the restored status, not wc-trash, on the synchronous path.'
+ );
}
/**
@@ -1188,17 +1178,12 @@ class OrdersSchedulerTest extends WC_Unit_Test_Case {
};
add_action( 'woocommerce_order_scheduler_after_import_order', $callback );
- try {
- $order->delete( false );
- $this->assertSame( 1, $imports, 'Trashing a CPT order should schedule exactly one import.' );
+ $order->delete( false );
+ $this->assertSame( 1, $imports, 'Trashing a CPT order should schedule exactly one import.' );
- $imports = 0;
- wp_untrash_post( $order_id );
- $this->assertSame( 1, $imports, 'Restoring a CPT order should schedule exactly one import.' );
- } finally {
- remove_filter( 'woocommerce_analytics_disable_action_scheduling', '__return_true' );
- remove_action( 'woocommerce_order_scheduler_after_import_order', $callback );
- }
+ $imports = 0;
+ wp_untrash_post( $order_id );
+ $this->assertSame( 1, $imports, 'Restoring a CPT order should schedule exactly one import.' );
}
/**
@@ -1224,25 +1209,21 @@ class OrdersSchedulerTest extends WC_Unit_Test_Case {
);
};
- try {
- $order = \WC_Helper_Order::create_order();
- $order->set_status( 'completed' );
- $order->save();
- $order_id = $order->get_id();
- OrdersScheduler::import( $order_id );
+ $order = \WC_Helper_Order::create_order();
+ $order->set_status( 'completed' );
+ $order->save();
+ $order_id = $order->get_id();
+ OrdersScheduler::import( $order_id );
- $order->delete( false );
- $this->assertSame( 'wc-trash', $read_status( $order_id ), 'Trashing should sync wc-trash synchronously under CPT.' );
+ $order->delete( false );
+ $this->assertSame( 'wc-trash', $read_status( $order_id ), 'Trashing should sync wc-trash synchronously under CPT.' );
- wp_untrash_post( $order_id );
- $this->assertSame(
- 'wc-completed',
- $read_status( $order_id ),
- 'Restoring should sync the restored status under CPT on the synchronous path.'
- );
- } finally {
- remove_filter( 'woocommerce_analytics_disable_action_scheduling', '__return_true' );
- }
+ wp_untrash_post( $order_id );
+ $this->assertSame(
+ 'wc-completed',
+ $read_status( $order_id ),
+ 'Restoring should sync the restored status under CPT on the synchronous path.'
+ );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Internal/Admin/Settings/PaymentsProviders/PaymentGatewayTest.php b/plugins/woocommerce/tests/php/src/Internal/Admin/Settings/PaymentsProviders/PaymentGatewayTest.php
index 3604c688fc8..e00b2bb1332 100644
--- a/plugins/woocommerce/tests/php/src/Internal/Admin/Settings/PaymentsProviders/PaymentGatewayTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/Admin/Settings/PaymentsProviders/PaymentGatewayTest.php
@@ -2542,9 +2542,6 @@ class PaymentGatewayTest extends WC_Unit_Test_Case {
$this->assertEmpty( $fake_logger->warning_calls, 'Warning logging should NOT be triggered for empty country code' );
$this->assertEmpty( $fake_logger->error_calls, 'Error logging should NOT be triggered for empty country code' );
$this->assertFalse( $fake_logger->has_any_logs(), 'No logging should occur for empty country code' );
-
- // Clean up - Remove filter.
- remove_all_filters( 'woocommerce_logging_class' );
}
/**
@@ -2590,9 +2587,6 @@ class PaymentGatewayTest extends WC_Unit_Test_Case {
$this->assertEmpty( $fake_logger->warning_calls, "Warning logging should NOT be triggered for valid country code: {$country_code}" );
$this->assertEmpty( $fake_logger->error_calls, "Error logging should NOT be triggered for valid country code: {$country_code}" );
$this->assertFalse( $fake_logger->has_any_logs(), "No logging should occur for valid country code: {$country_code}" );
-
- // Clean up - Remove filter.
- remove_all_filters( 'woocommerce_logging_class' );
}
/**
@@ -2661,9 +2655,6 @@ class PaymentGatewayTest extends WC_Unit_Test_Case {
$this->assertArrayHasKey( 'gateway', $debug_call['context'] );
$this->assertEquals( 'gateway1', $debug_call['context']['gateway'] );
$this->assertArrayHasKey( 'country', $debug_call['context'] );
-
- // Clean up - Remove filter.
- remove_all_filters( 'woocommerce_logging_class' );
}
/**
@@ -2800,9 +2791,6 @@ class PaymentGatewayTest extends WC_Unit_Test_Case {
$this->assertArrayHasKey( 'gateway', $debug_call['context'] );
$this->assertEquals( 'throwing_gateway', $debug_call['context']['gateway'] );
$this->assertArrayHasKey( 'exception', $debug_call['context'] );
-
- // Clean up.
- remove_all_filters( 'woocommerce_logging_class' );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Internal/Admin/Settings/PaymentsProviders/WooPayments/WooPaymentsRestControllerIntegrationTest.php b/plugins/woocommerce/tests/php/src/Internal/Admin/Settings/PaymentsProviders/WooPayments/WooPaymentsRestControllerIntegrationTest.php
index cc3a75589e0..e09e006b4a8 100644
--- a/plugins/woocommerce/tests/php/src/Internal/Admin/Settings/PaymentsProviders/WooPayments/WooPaymentsRestControllerIntegrationTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/Admin/Settings/PaymentsProviders/WooPayments/WooPaymentsRestControllerIntegrationTest.php
@@ -492,9 +492,6 @@ class WooPaymentsRestControllerIntegrationTest extends WC_Unit_Test_Case {
// Assert.
$this->assertSame( rest_authorization_required_code(), $response->get_status() );
-
- // Clean up.
- remove_filter( 'user_has_cap', $filter_callback );
}
/**
@@ -545,9 +542,6 @@ class WooPaymentsRestControllerIntegrationTest extends WC_Unit_Test_Case {
$this->assertArrayHasKey( 'check', $step['actions'] );
$this->assertArrayHasKey( 'finish', $step['actions'] );
$this->assertArrayHasKey( 'clean', $step['actions'] );
-
- // Clean up.
- remove_filter( 'user_has_cap', $filter_callback );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Internal/Admin/Settings/PaymentsProviders/WooPayments/WooPaymentsRestControllerTest.php b/plugins/woocommerce/tests/php/src/Internal/Admin/Settings/PaymentsProviders/WooPayments/WooPaymentsRestControllerTest.php
index ec34256bec1..b5059188413 100644
--- a/plugins/woocommerce/tests/php/src/Internal/Admin/Settings/PaymentsProviders/WooPayments/WooPaymentsRestControllerTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/Admin/Settings/PaymentsProviders/WooPayments/WooPaymentsRestControllerTest.php
@@ -103,9 +103,6 @@ class WooPaymentsRestControllerTest extends WC_Unit_Test_Case {
// Assert.
$this->assertSame( rest_authorization_required_code(), $response->get_status() );
-
- // Clean up.
- remove_filter( 'user_has_cap', $filter_callback );
}
/**
@@ -158,9 +155,6 @@ class WooPaymentsRestControllerTest extends WC_Unit_Test_Case {
$this->assertArrayHasKey( 'kyc_session_finish', $step['actions'] );
$this->assertArrayHasKey( 'kyc_fallback', $step['actions'] );
$this->assertArrayHasKey( 'clean', $step['actions'] );
-
- // Clean up.
- remove_filter( 'user_has_cap', $filter_callback );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Internal/Admin/Settings/PaymentsProviders/WooPaymentsTest.php b/plugins/woocommerce/tests/php/src/Internal/Admin/Settings/PaymentsProviders/WooPaymentsTest.php
index 6af03bfce9f..f168eb31c0a 100644
--- a/plugins/woocommerce/tests/php/src/Internal/Admin/Settings/PaymentsProviders/WooPaymentsTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/Admin/Settings/PaymentsProviders/WooPaymentsTest.php
@@ -1184,19 +1184,13 @@ class WooPaymentsTest extends WC_Unit_Test_Case {
)
);
- try {
- // Act.
- $onboarding_url = $this->sut->get_onboarding_url( $fake_gateway );
+ // Act.
+ $onboarding_url = $this->sut->get_onboarding_url( $fake_gateway );
- // Assert - Should do LIVE onboarding (no test_drive params).
- $this->assertStringContainsString( 'https://example.com/wp-admin/woopayments/connect-url', $onboarding_url );
- $this->assertStringNotContainsString( 'test_drive=true', $onboarding_url );
- $this->assertStringNotContainsString( 'auto_start_test_drive_onboarding=true', $onboarding_url );
- } finally {
- // Clean up.
- delete_option( 'woocommerce_coming_soon' );
- delete_option( 'woocommerce_onboarding_profile' );
- }
+ // Assert - Should do LIVE onboarding (no test_drive params).
+ $this->assertStringContainsString( 'https://example.com/wp-admin/woopayments/connect-url', $onboarding_url );
+ $this->assertStringNotContainsString( 'test_drive=true', $onboarding_url );
+ $this->assertStringNotContainsString( 'auto_start_test_drive_onboarding=true', $onboarding_url );
}
/**
@@ -1224,19 +1218,13 @@ class WooPaymentsTest extends WC_Unit_Test_Case {
)
);
- try {
- // Act.
- $onboarding_url = $this->sut->get_onboarding_url( $fake_gateway );
+ // Act.
+ $onboarding_url = $this->sut->get_onboarding_url( $fake_gateway );
- // Assert - Should do LIVE onboarding (no test_drive params).
- $this->assertStringContainsString( 'https://example.com/wp-admin/woopayments/connect-url', $onboarding_url );
- $this->assertStringNotContainsString( 'test_drive=true', $onboarding_url );
- $this->assertStringNotContainsString( 'auto_start_test_drive_onboarding=true', $onboarding_url );
- } finally {
- // Clean up.
- delete_option( 'woocommerce_coming_soon' );
- delete_option( 'woocommerce_onboarding_profile' );
- }
+ // Assert - Should do LIVE onboarding (no test_drive params).
+ $this->assertStringContainsString( 'https://example.com/wp-admin/woopayments/connect-url', $onboarding_url );
+ $this->assertStringNotContainsString( 'test_drive=true', $onboarding_url );
+ $this->assertStringNotContainsString( 'auto_start_test_drive_onboarding=true', $onboarding_url );
}
/**
@@ -1263,19 +1251,13 @@ class WooPaymentsTest extends WC_Unit_Test_Case {
)
);
- try {
- // Act.
- $onboarding_url = $this->sut->get_onboarding_url( $fake_gateway );
+ // Act.
+ $onboarding_url = $this->sut->get_onboarding_url( $fake_gateway );
- // Assert - Should do TEST-DRIVE onboarding (includes test_drive params).
- $this->assertStringContainsString( 'https://example.com/wp-admin/woopayments/connect-url', $onboarding_url );
- $this->assertStringContainsString( 'test_drive=true', $onboarding_url );
- $this->assertStringContainsString( 'auto_start_test_drive_onboarding=true', $onboarding_url );
- } finally {
- // Clean up.
- delete_option( 'woocommerce_coming_soon' );
- delete_option( 'woocommerce_onboarding_profile' );
- }
+ // Assert - Should do TEST-DRIVE onboarding (includes test_drive params).
+ $this->assertStringContainsString( 'https://example.com/wp-admin/woopayments/connect-url', $onboarding_url );
+ $this->assertStringContainsString( 'test_drive=true', $onboarding_url );
+ $this->assertStringContainsString( 'auto_start_test_drive_onboarding=true', $onboarding_url );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Internal/Admin/Settings/PaymentsProvidersTest.php b/plugins/woocommerce/tests/php/src/Internal/Admin/Settings/PaymentsProvidersTest.php
index 65211b0e60c..c630f13a67c 100644
--- a/plugins/woocommerce/tests/php/src/Internal/Admin/Settings/PaymentsProvidersTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/Admin/Settings/PaymentsProvidersTest.php
@@ -878,10 +878,6 @@ class PaymentsProvidersTest extends WC_Unit_Test_Case {
$gateway_details['management']['_links']['settings']['href']
);
$this->assertTrue( $gateway_details['state']['test_mode'] ); // It should be in test mode because of the DB options. The custom provider logic handles this.
-
- // Clean up.
- delete_option( 'mollie-payments-for-woocommerce_test_mode_enabled' );
- delete_option( 'mollie-payments-for-woocommerce_test_api_key' );
}
/**
@@ -2414,9 +2410,6 @@ class PaymentsProvidersTest extends WC_Unit_Test_Case {
$this->assertArrayHasKey( 'timestamp', $nox_profile['suggestions'][ $suggestion_id ]['attached'] );
// The other profile entries should be kept.
$this->assertSame( 'value', $nox_profile['something_other'] );
-
- // Clean up.
- delete_option( Payments::PAYMENTS_NOX_PROFILE_KEY );
}
/**
@@ -2467,10 +2460,6 @@ class PaymentsProvidersTest extends WC_Unit_Test_Case {
$nox_profile = get_option( Payments::PAYMENTS_NOX_PROFILE_KEY );
$this->assertIsArray( $nox_profile['suggestions'][ $suggestion_id ]['attached'] );
$this->assertArrayHasKey( 'timestamp', $nox_profile['suggestions'][ $suggestion_id ]['attached'] );
-
- // Clean up.
- delete_option( 'woocommerce_paypal_branded' );
- delete_option( Payments::PAYMENTS_NOX_PROFILE_KEY );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Internal/Admin/Settings/PaymentsRestControllerIntegrationTest.php b/plugins/woocommerce/tests/php/src/Internal/Admin/Settings/PaymentsRestControllerIntegrationTest.php
index a2c914661a3..5eb92598179 100644
--- a/plugins/woocommerce/tests/php/src/Internal/Admin/Settings/PaymentsRestControllerIntegrationTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/Admin/Settings/PaymentsRestControllerIntegrationTest.php
@@ -359,9 +359,6 @@ class PaymentsRestControllerIntegrationTest extends WC_Unit_Test_Case {
// Assert.
$this->assertSame( rest_authorization_required_code(), $response->get_status() );
-
- // Clean up.
- remove_filter( 'user_has_cap', $filter_callback );
}
/**
@@ -407,9 +404,6 @@ class PaymentsRestControllerIntegrationTest extends WC_Unit_Test_Case {
$this->assertCount( 0, $data['suggestions'] );
// But we do get the suggestion categories.
$this->assertCount( 4, $data['suggestion_categories'] );
-
- // Clean up.
- remove_filter( 'user_has_cap', $filter_callback );
}
/**
@@ -458,9 +452,6 @@ class PaymentsRestControllerIntegrationTest extends WC_Unit_Test_Case {
// Assert that the other suggestions are all PSPs.
$other_suggestions = $data['suggestions'];
$this->assertSame( array( PaymentsExtensionSuggestions::TYPE_PSP ), array_unique( array_column( $other_suggestions, '_type' ) ) );
-
- // Clean up.
- remove_filter( 'user_has_cap', $filter_callback );
}
/**
@@ -811,9 +802,6 @@ class PaymentsRestControllerIntegrationTest extends WC_Unit_Test_Case {
$this->assertArrayHasKey( '_priority', $suggestion_category, 'Suggestion category `_order` entry is missing' );
$this->assertArrayHasKey( 'title', $suggestion_category, 'Suggestion category `title` entry is missing' );
$this->assertArrayHasKey( 'description', $suggestion_category, 'Suggestion category `description` entry is missing' );
-
- // Clean up.
- remove_filter( 'user_has_cap', $filter_callback );
}
/**
@@ -1002,9 +990,6 @@ class PaymentsRestControllerIntegrationTest extends WC_Unit_Test_Case {
// Assert that the PayPal gateway is returned as enabled.
$provider = $data['providers'][1];
$this->assertTrue( $provider['state']['enabled'] );
-
- // Clean up.
- remove_filter( 'user_has_cap', $filter_callback );
}
/**
@@ -1194,9 +1179,6 @@ class PaymentsRestControllerIntegrationTest extends WC_Unit_Test_Case {
// Assert that the PayPal gateway is returned as enabled.
$provider = $data['providers'][1];
$this->assertTrue( $provider['state']['enabled'] );
-
- // Clean up.
- remove_filter( 'user_has_cap', $filter_callback );
}
/**
@@ -1328,9 +1310,6 @@ class PaymentsRestControllerIntegrationTest extends WC_Unit_Test_Case {
// Assert that the PayPal gateway is returned as enabled.
$provider = $data['providers'][3];
$this->assertTrue( $provider['state']['enabled'] );
-
- // Clean up.
- remove_filter( 'user_has_cap', $filter_callback );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Internal/Admin/Settings/PaymentsRestControllerTest.php b/plugins/woocommerce/tests/php/src/Internal/Admin/Settings/PaymentsRestControllerTest.php
index 0018fc23354..e13da9d075c 100644
--- a/plugins/woocommerce/tests/php/src/Internal/Admin/Settings/PaymentsRestControllerTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/Admin/Settings/PaymentsRestControllerTest.php
@@ -100,9 +100,6 @@ class PaymentsRestControllerTest extends WC_Unit_Test_Case {
// Assert.
$this->assertSame( rest_authorization_required_code(), $response->get_status() );
-
- // Clean up.
- remove_filter( 'user_has_cap', $filter_callback );
}
/**
@@ -188,9 +185,6 @@ class PaymentsRestControllerTest extends WC_Unit_Test_Case {
$this->assertArrayHasKey( '_priority', $suggestion_category, 'Suggestion category `_order` entry is missing' );
$this->assertArrayHasKey( 'title', $suggestion_category, 'Suggestion category `title` entry is missing' );
$this->assertArrayHasKey( 'description', $suggestion_category, 'Suggestion category `description` entry is missing' );
-
- // Clean up.
- remove_filter( 'user_has_cap', $filter_callback );
}
/**
@@ -269,9 +263,6 @@ class PaymentsRestControllerTest extends WC_Unit_Test_Case {
$this->assertIsArray( $suggestion['tags'] );
$this->assertArrayHasKey( 'category', $suggestion, 'Suggestion `category` entry is missing' );
}
-
- // Clean up.
- remove_filter( 'user_has_cap', $filter_callback );
}
/**
@@ -500,9 +491,6 @@ class PaymentsRestControllerTest extends WC_Unit_Test_Case {
$this->assertCount( 2, $data['suggestions'] );
// Assert we get the suggestion categories.
$this->assertCount( 3, $data['suggestion_categories'] );
-
- // Clean up.
- delete_option( 'woocommerce_default_country' );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Internal/Admin/Settings/PaymentsTest.php b/plugins/woocommerce/tests/php/src/Internal/Admin/Settings/PaymentsTest.php
index b4e6c1af8ae..061d563a2bb 100644
--- a/plugins/woocommerce/tests/php/src/Internal/Admin/Settings/PaymentsTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/Admin/Settings/PaymentsTest.php
@@ -506,7 +506,6 @@ class PaymentsTest extends WC_Unit_Test_Case {
)
);
- $initial_country = WC()->countries->get_base_country();
update_option( 'woocommerce_default_country', $country );
// Act.
@@ -517,7 +516,6 @@ class PaymentsTest extends WC_Unit_Test_Case {
// Clean up.
delete_user_meta( $this->store_admin_id, Payments::PAYMENTS_NOX_PROFILE_KEY );
- update_option( 'woocommerce_default_country', $initial_country );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Internal/Admin/Settings/SettingsUIFeatureFlagTest.php b/plugins/woocommerce/tests/php/src/Internal/Admin/Settings/SettingsUIFeatureFlagTest.php
index b046a9433b6..f09e0520c5f 100644
--- a/plugins/woocommerce/tests/php/src/Internal/Admin/Settings/SettingsUIFeatureFlagTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/Admin/Settings/SettingsUIFeatureFlagTest.php
@@ -525,13 +525,9 @@ class SettingsUIFeatureFlagTest extends WC_Unit_Test_Case {
add_filter( 'woocommerce_get_settings_settings_ui_flag_test', $filter );
- try {
- $this->assertNull( $context->get_schema() );
- $this->assertTrue( $context->has_schema_failed() );
- $this->assertStringContainsString( 'Unable to build the Settings UI schema.', $context->get_schema_failure_reason() );
- } finally {
- remove_filter( 'woocommerce_get_settings_settings_ui_flag_test', $filter );
- }
+ $this->assertNull( $context->get_schema() );
+ $this->assertTrue( $context->has_schema_failed() );
+ $this->assertStringContainsString( 'Unable to build the Settings UI schema.', $context->get_schema_failure_reason() );
}
/**
@@ -778,17 +774,13 @@ class SettingsUIFeatureFlagTest extends WC_Unit_Test_Case {
};
add_filter( 'woocommerce_get_settings_settings_ui_flag_test', $schema_filter );
- try {
- $dependencies = $this->invoke_private_method( new WCAdminAssets(), 'get_settings_ui_script_dependencies' );
+ $dependencies = $this->invoke_private_method( new WCAdminAssets(), 'get_settings_ui_script_dependencies' );
- $this->assertContains( 'wc-settings-ui', $dependencies );
- $this->assertSame( 0, $schema_filter_calls, 'Asset dependency resolution should not move public settings filters earlier in the request.' );
+ $this->assertContains( 'wc-settings-ui', $dependencies );
+ $this->assertSame( 0, $schema_filter_calls, 'Asset dependency resolution should not move public settings filters earlier in the request.' );
- SettingsUIRequestContext::for_settings_page( $page, '' )->get_schema();
- $this->assertSame( 1, $schema_filter_calls, 'The settings filter should still run when the schema is requested.' );
- } finally {
- remove_filter( 'woocommerce_get_settings_settings_ui_flag_test', $schema_filter );
- }
+ SettingsUIRequestContext::for_settings_page( $page, '' )->get_schema();
+ $this->assertSame( 1, $schema_filter_calls, 'The settings filter should still run when the schema is requested.' );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Internal/Admin/ShippingPartnerSuggestions/ShippingPartnerSuggestionsTest.php b/plugins/woocommerce/tests/php/src/Internal/Admin/ShippingPartnerSuggestions/ShippingPartnerSuggestionsTest.php
index 0ae3d95b84d..a87020bb3e4 100644
--- a/plugins/woocommerce/tests/php/src/Internal/Admin/ShippingPartnerSuggestions/ShippingPartnerSuggestionsTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/Admin/ShippingPartnerSuggestions/ShippingPartnerSuggestionsTest.php
@@ -169,8 +169,6 @@ class ShippingPartnerSuggestionsTest extends WC_Unit_Test_Case {
update_option( 'woocommerce_default_country', 'ZA' );
ShippingPartnerSuggestions::get_suggestions();
-
- remove_filter( 'woocommerce_admin_remote_specs_evaluator_should_log', '__return_true' );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Internal/Admin/SiteHealthTest.php b/plugins/woocommerce/tests/php/src/Internal/Admin/SiteHealthTest.php
index 1dd39d4cfb0..80837dbd3d3 100644
--- a/plugins/woocommerce/tests/php/src/Internal/Admin/SiteHealthTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/Admin/SiteHealthTest.php
@@ -263,18 +263,14 @@ class SiteHealthTest extends WC_Unit_Test_Case {
add_filter( 'pre_http_request', $filter_callback, 10, 3 );
- try {
- $result = $this->sut->run_test( 'woocommerce_uploads_directory_protection' );
+ $result = $this->sut->run_test( 'woocommerce_uploads_directory_protection' );
- $this->assertSame( 'recommended', $result['status'], 'Request failures should not be reported as a confirmed security failure.' );
- $this->assertSame( 'WooCommerce could not verify uploads directory protection', $result['label'], 'Request failures should report that the result could not be verified.' );
+ $this->assertSame( 'recommended', $result['status'], 'Request failures should not be reported as a confirmed security failure.' );
+ $this->assertSame( 'WooCommerce could not verify uploads directory protection', $result['label'], 'Request failures should report that the result could not be verified.' );
- $this->sut->run_test( 'woocommerce_uploads_directory_protection' );
+ $this->sut->run_test( 'woocommerce_uploads_directory_protection' );
- $this->assertSame( 2, $request_count, 'Each run should check again instead of reusing an earlier result.' );
- } finally {
- remove_filter( 'pre_http_request', $filter_callback, 10 );
- }
+ $this->assertSame( 2, $request_count, 'Each run should check again instead of reusing an earlier result.' );
}
/**
@@ -298,14 +294,10 @@ class SiteHealthTest extends WC_Unit_Test_Case {
add_filter( 'pre_http_request', $filter_callback, 10, 3 );
- try {
- $result = $this->sut->run_test( 'woocommerce_uploads_directory_protection' );
+ $result = $this->sut->run_test( 'woocommerce_uploads_directory_protection' );
- $this->assertSame( 'recommended', $result['status'], 'Missing response codes should not be reported as a confirmed security failure.' );
- $this->assertSame( 'WooCommerce could not verify uploads directory protection', $result['label'], 'Missing response codes should report that the result could not be verified.' );
- } finally {
- remove_filter( 'pre_http_request', $filter_callback, 10 );
- }
+ $this->assertSame( 'recommended', $result['status'], 'Missing response codes should not be reported as a confirmed security failure.' );
+ $this->assertSame( 'WooCommerce could not verify uploads directory protection', $result['label'], 'Missing response codes should report that the result could not be verified.' );
}
/**
@@ -331,14 +323,10 @@ class SiteHealthTest extends WC_Unit_Test_Case {
add_filter( 'pre_http_request', $filter_callback, 10, 3 );
- try {
- $result = $this->sut->run_test( 'woocommerce_uploads_directory_protection' );
+ $result = $this->sut->run_test( 'woocommerce_uploads_directory_protection' );
- $this->assertSame( 'critical', $result['status'], 'Browsable uploads directories should remain critical.' );
- $this->assertSame( 'WooCommerce uploads directory is browsable from the web', $result['label'], 'Browsable uploads directories should keep the confirmed security failure label.' );
- } finally {
- remove_filter( 'pre_http_request', $filter_callback, 10 );
- }
+ $this->assertSame( 'critical', $result['status'], 'Browsable uploads directories should remain critical.' );
+ $this->assertSame( 'WooCommerce uploads directory is browsable from the web', $result['label'], 'Browsable uploads directories should keep the confirmed security failure label.' );
}
/**
@@ -367,16 +355,12 @@ class SiteHealthTest extends WC_Unit_Test_Case {
add_filter( 'pre_http_request', $filter_callback, 10, 3 );
- try {
- $result = $this->sut->run_test( 'woocommerce_uploads_directory_protection' );
+ $result = $this->sut->run_test( 'woocommerce_uploads_directory_protection' );
- $this->assertSame( 'critical', $result['status'], 'Directly downloadable files should be a confirmed security failure.' );
- $this->assertSame( 'Downloadable product files can be accessed directly from the web', $result['label'], 'Directly downloadable files should report that files are exposed.' );
- $this->assertStringStartsWith( $uploads['basedir'] . '/woocommerce_uploads/', $requested_paths[0], 'The check should request a file in the WooCommerce uploads directory.' );
- $this->assertFileDoesNotExist( $requested_paths[0], 'The temporary file should be deleted after the request.' );
- } finally {
- remove_filter( 'pre_http_request', $filter_callback, 10 );
- }
+ $this->assertSame( 'critical', $result['status'], 'Directly downloadable files should be a confirmed security failure.' );
+ $this->assertSame( 'Downloadable product files can be accessed directly from the web', $result['label'], 'Directly downloadable files should report that files are exposed.' );
+ $this->assertStringStartsWith( $uploads['basedir'] . '/woocommerce_uploads/', $requested_paths[0], 'The check should request a file in the WooCommerce uploads directory.' );
+ $this->assertFileDoesNotExist( $requested_paths[0], 'The temporary file should be deleted after the request.' );
}
/**
@@ -408,14 +392,10 @@ class SiteHealthTest extends WC_Unit_Test_Case {
add_filter( 'pre_http_request', $filter_callback, 10, 3 );
- try {
- $result = $this->sut->run_test( 'woocommerce_uploads_directory_protection' );
+ $result = $this->sut->run_test( 'woocommerce_uploads_directory_protection' );
- $this->assertSame( 'good', $result['status'], 'Files that are not served should be reported as protected.' );
- $this->assertStringContainsString( 'Downloadable product files cannot be accessed directly from the web.', $result['description'], 'The protected description should refer to file access.' );
- } finally {
- remove_filter( 'pre_http_request', $filter_callback, 10 );
- }
+ $this->assertSame( 'good', $result['status'], 'Files that are not served should be reported as protected.' );
+ $this->assertStringContainsString( 'Downloadable product files cannot be accessed directly from the web.', $result['description'], 'The protected description should refer to file access.' );
}
/**
@@ -443,15 +423,11 @@ class SiteHealthTest extends WC_Unit_Test_Case {
add_filter( 'pre_http_request', $filter_callback, 10, 3 );
- try {
- $result = $this->sut->run_test( 'woocommerce_uploads_directory_protection' );
+ $result = $this->sut->run_test( 'woocommerce_uploads_directory_protection' );
- $this->assertSame( 'recommended', $result['status'], 'A site that blocks every upload should not be reported as protected.' );
- foreach ( $requested_urls as $url ) {
- $this->assertFileDoesNotExist( str_replace( $uploads['baseurl'], $uploads['basedir'], $url ), 'Each temporary file should be deleted after its request.' );
- }
- } finally {
- remove_filter( 'pre_http_request', $filter_callback, 10 );
+ $this->assertSame( 'recommended', $result['status'], 'A site that blocks every upload should not be reported as protected.' );
+ foreach ( $requested_urls as $url ) {
+ $this->assertFileDoesNotExist( str_replace( $uploads['baseurl'], $uploads['basedir'], $url ), 'Each temporary file should be deleted after its request.' );
}
}
@@ -521,16 +497,11 @@ class SiteHealthTest extends WC_Unit_Test_Case {
add_filter( 'pre_http_request', $http_callback );
add_filter( 'upload_dir', $upload_dir_callback );
- try {
- $result = $this->sut->run_test( 'woocommerce_uploads_directory_protection' );
+ $result = $this->sut->run_test( 'woocommerce_uploads_directory_protection' );
- $this->assertSame( 'recommended', $result['status'], 'A file that cannot be written should not be reported as a confirmed security failure.' );
- $this->assertSame( 'WooCommerce could not verify uploads directory protection', $result['label'], 'A file that cannot be written should report that the result could not be verified.' );
- $this->assertSame( 0, $request_count, 'No request should be made without a temporary file.' );
- } finally {
- remove_filter( 'pre_http_request', $http_callback );
- remove_filter( 'upload_dir', $upload_dir_callback );
- }
+ $this->assertSame( 'recommended', $result['status'], 'A file that cannot be written should not be reported as a confirmed security failure.' );
+ $this->assertSame( 'WooCommerce could not verify uploads directory protection', $result['label'], 'A file that cannot be written should report that the result could not be verified.' );
+ $this->assertSame( 0, $request_count, 'No request should be made without a temporary file.' );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Internal/Admin/Suggestions/Incentives/IncentiveTest.php b/plugins/woocommerce/tests/php/src/Internal/Admin/Suggestions/Incentives/IncentiveTest.php
index cd579cca4b5..8b53b643f66 100644
--- a/plugins/woocommerce/tests/php/src/Internal/Admin/Suggestions/Incentives/IncentiveTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/Admin/Suggestions/Incentives/IncentiveTest.php
@@ -514,9 +514,6 @@ class IncentiveTest extends WC_Unit_Test_Case {
// Assert.
$this->assertTrue( $result );
-
- // Clean up.
- remove_filter( 'user_has_cap', $filter_callback );
}
/**
@@ -552,9 +549,6 @@ class IncentiveTest extends WC_Unit_Test_Case {
// Assert.
$this->assertFalse( $result );
-
- // Clean up.
- remove_filter( 'user_has_cap', $filter_callback );
}
/**
@@ -590,9 +584,6 @@ class IncentiveTest extends WC_Unit_Test_Case {
// Assert.
$this->assertFalse( $result );
-
- // Clean up.
- remove_filter( 'user_has_cap', $filter_callback );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Internal/Admin/Suggestions/Incentives/WooPaymentsTest.php b/plugins/woocommerce/tests/php/src/Internal/Admin/Suggestions/Incentives/WooPaymentsTest.php
index bf6d0c271cd..a7e83480888 100644
--- a/plugins/woocommerce/tests/php/src/Internal/Admin/Suggestions/Incentives/WooPaymentsTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/Admin/Suggestions/Incentives/WooPaymentsTest.php
@@ -242,9 +242,6 @@ class WooPaymentsTest extends WC_Unit_Test_Case {
// Assert.
$this->assertTrue( $result );
-
- // Clean up.
- remove_filter( 'user_has_cap', $filter_callback );
}
/**
@@ -285,9 +282,6 @@ class WooPaymentsTest extends WC_Unit_Test_Case {
// Assert.
$this->assertFalse( $result );
-
- // Clean up.
- delete_option( 'wcpay_account_data' );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Internal/Admin/Suggestions/PaymentsExtensionSuggestionsTest.php b/plugins/woocommerce/tests/php/src/Internal/Admin/Suggestions/PaymentsExtensionSuggestionsTest.php
index 5ac45a0547e..2f0938dc601 100644
--- a/plugins/woocommerce/tests/php/src/Internal/Admin/Suggestions/PaymentsExtensionSuggestionsTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/Admin/Suggestions/PaymentsExtensionSuggestionsTest.php
@@ -178,8 +178,6 @@ class PaymentsExtensionSuggestionsTest extends WC_Unit_Test_Case {
$this->assertNotContains( PaymentsExtensionSuggestions::TAG_PREFERRED, $square['tags'] );
$this->assertNotContains( PaymentsExtensionSuggestions::TAG_PREFERRED_OFFLINE, $square['tags'] );
}
-
- delete_option( OnboardingProfile::DATA_OPTION );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Internal/Admin/WCPayPromotion/InitTest.php b/plugins/woocommerce/tests/php/src/Internal/Admin/WCPayPromotion/InitTest.php
index 275c2401fff..ec10a57fefb 100644
--- a/plugins/woocommerce/tests/php/src/Internal/Admin/WCPayPromotion/InitTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/Admin/WCPayPromotion/InitTest.php
@@ -71,9 +71,6 @@ class InitTest extends WC_Unit_Test_Case {
// Assert.
$defaults = DefaultPromotions::get_all();
$this->assertEquals( $defaults, $specs );
-
- // Clean up.
- remove_all_filters( DataSourcePoller::FILTER_NAME );
}
/**
@@ -307,11 +304,5 @@ class InitTest extends WC_Unit_Test_Case {
$expires = (int) get_transient( '_transient_timeout_woocommerce_admin_' . WCPayPromotionDataSourcePoller::ID . '_specs' );
$this->assertTrue( ( $expires - time() ) <= 3 * HOUR_IN_SECONDS );
-
- // Clean up.
- remove_all_filters( WCPayPromotionDataSourcePoller::FILTER_NAME );
- remove_all_filters( WCPayPromotionDataSourcePoller::FILTER_NAME_SPECS );
- remove_all_filters( 'pre_http_request' );
- remove_all_filters( 'woocommerce_admin_payment_gateway_suggestion_specs' );
}
}
diff --git a/plugins/woocommerce/tests/php/src/Internal/CLI/Migrator/Platforms/Shopify/ShopifyClientTest.php b/plugins/woocommerce/tests/php/src/Internal/CLI/Migrator/Platforms/Shopify/ShopifyClientTest.php
index 6399bde937d..a88fb2029fc 100644
--- a/plugins/woocommerce/tests/php/src/Internal/CLI/Migrator/Platforms/Shopify/ShopifyClientTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/CLI/Migrator/Platforms/Shopify/ShopifyClientTest.php
@@ -74,9 +74,6 @@ class ShopifyClientTest extends WC_Unit_Test_Case {
$this->assertNotInstanceOf( WP_Error::class, $result );
$this->assertEquals( 42, $result->count );
-
- // Clean up filter.
- remove_all_filters( 'pre_http_request' );
}
/**
@@ -109,8 +106,6 @@ class ShopifyClientTest extends WC_Unit_Test_Case {
$this->assertNotInstanceOf( WP_Error::class, $result );
$this->assertEquals( 15, $result->count );
-
- remove_all_filters( 'pre_http_request' );
}
/**
@@ -160,8 +155,6 @@ class ShopifyClientTest extends WC_Unit_Test_Case {
$this->assertInstanceOf( WP_Error::class, $result );
$this->assertEquals( 'api_error', $result->get_error_code() );
$this->assertStringContainsString( 'Connection timeout', $result->get_error_message() );
-
- remove_all_filters( 'pre_http_request' );
}
/**
@@ -189,8 +182,6 @@ class ShopifyClientTest extends WC_Unit_Test_Case {
$this->assertEquals( 'api_error', $result->get_error_code() );
$this->assertStringContainsString( '401', $result->get_error_message() );
$this->assertStringContainsString( 'Unauthorized', $result->get_error_message() );
-
- remove_all_filters( 'pre_http_request' );
}
/**
@@ -213,8 +204,6 @@ class ShopifyClientTest extends WC_Unit_Test_Case {
$this->assertInstanceOf( WP_Error::class, $result );
$this->assertEquals( 'api_error', $result->get_error_code() );
$this->assertStringContainsString( 'Failed to decode', $result->get_error_message() );
-
- remove_all_filters( 'pre_http_request' );
}
/**
@@ -243,8 +232,6 @@ class ShopifyClientTest extends WC_Unit_Test_Case {
);
$client_no_protocol->rest_request( '/products/count.json' );
-
- remove_all_filters( 'pre_http_request' );
}
/**
@@ -273,8 +260,6 @@ class ShopifyClientTest extends WC_Unit_Test_Case {
$this->assertNotInstanceOf( WP_Error::class, $result );
$this->assertEquals( 123, $result->product->id );
-
- remove_all_filters( 'pre_http_request' );
}
/**
@@ -332,9 +317,6 @@ class ShopifyClientTest extends WC_Unit_Test_Case {
$this->assertIsObject( $result );
$this->assertEquals( 1, count( $result->products->edges ) );
$this->assertEquals( 'Test Product', $result->products->edges[0]->node->title );
-
- // Clean up filter.
- remove_all_filters( 'pre_http_request' );
}
/**
@@ -369,8 +351,6 @@ class ShopifyClientTest extends WC_Unit_Test_Case {
$result = $this->client->graphql_request( $query, $variables );
$this->assertNotInstanceOf( WP_Error::class, $result );
-
- remove_all_filters( 'pre_http_request' );
}
/**
@@ -397,8 +377,6 @@ class ShopifyClientTest extends WC_Unit_Test_Case {
$this->assertInstanceOf( WP_Error::class, $result );
$this->assertEquals( 'api_error', $result->get_error_code() );
$this->assertStringContainsString( '500', $result->get_error_message() );
-
- remove_all_filters( 'pre_http_request' );
}
/**
@@ -434,8 +412,6 @@ class ShopifyClientTest extends WC_Unit_Test_Case {
$this->assertInstanceOf( WP_Error::class, $result );
$this->assertEquals( 'graphql_error', $result->get_error_code() );
$this->assertStringContainsString( 'Field \\"invalidField\\"', $result->get_error_message() );
-
- remove_all_filters( 'pre_http_request' );
}
/**
@@ -461,8 +437,6 @@ class ShopifyClientTest extends WC_Unit_Test_Case {
$this->assertInstanceOf( WP_Error::class, $result );
$this->assertEquals( 'api_error', $result->get_error_code() );
-
- remove_all_filters( 'pre_http_request' );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Internal/CLI/Migrator/Platforms/Webflow/WebflowMapperTest.php b/plugins/woocommerce/tests/php/src/Internal/CLI/Migrator/Platforms/Webflow/WebflowMapperTest.php
index 121efef641d..76c2cbdae79 100644
--- a/plugins/woocommerce/tests/php/src/Internal/CLI/Migrator/Platforms/Webflow/WebflowMapperTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/CLI/Migrator/Platforms/Webflow/WebflowMapperTest.php
@@ -162,20 +162,15 @@ class WebflowMapperTest extends \WC_Unit_Test_Case {
* Test SKU passes through and weight is converted to the store unit.
*/
public function test_simple_product_sku_and_weight(): void {
- $original_unit = get_option( 'woocommerce_weight_unit' );
update_option( 'woocommerce_weight_unit', 'kg' );
- try {
- $result = $this->mapper->map_product_data( MockWebflowData::simple_product_item() );
+ $result = $this->mapper->map_product_data( MockWebflowData::simple_product_item() );
- $this->assertSame( 'PLAIN-001', $result['sku'] );
+ $this->assertSame( 'PLAIN-001', $result['sku'] );
- // Fixture weight is 0.5 lb; converting to the store's kg unit pins the conversion
- // (0.5 lb ≈ 0.2268 kg) rather than accepting any positive float.
- $this->assertEqualsWithDelta( 0.2268, $result['weight'], 0.0005 );
- } finally {
- update_option( 'woocommerce_weight_unit', $original_unit );
- }
+ // Fixture weight is 0.5 lb; converting to the store's kg unit pins the conversion
+ // (0.5 lb ≈ 0.2268 kg) rather than accepting any positive float.
+ $this->assertEqualsWithDelta( 0.2268, $result['weight'], 0.0005 );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Internal/Caches/ProductVersionStringInvalidatorTest.php b/plugins/woocommerce/tests/php/src/Internal/Caches/ProductVersionStringInvalidatorTest.php
index 2b4250fc07e..502f8573aff 100644
--- a/plugins/woocommerce/tests/php/src/Internal/Caches/ProductVersionStringInvalidatorTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/Caches/ProductVersionStringInvalidatorTest.php
@@ -558,8 +558,6 @@ class ProductVersionStringInvalidatorTest extends \WC_Unit_Test_Case {
$this->assertNotEmpty( $filter_calls, 'Filter should have been called' );
$this->assertSame( ProductVersionStringInvalidator::DEFAULT_TAXONOMY_LOOKUP_CACHE_TTL, $filter_calls[0]['ttl'] );
$this->assertSame( 'product', $filter_calls[0]['entity_type'] );
-
- remove_all_filters( 'woocommerce_version_string_invalidator_taxonomy_lookup_ttl' );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Internal/Checkout/PaymentRecoveryTest.php b/plugins/woocommerce/tests/php/src/Internal/Checkout/PaymentRecoveryTest.php
index 57dda1f5f1a..a08298c1ecf 100644
--- a/plugins/woocommerce/tests/php/src/Internal/Checkout/PaymentRecoveryTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/Checkout/PaymentRecoveryTest.php
@@ -59,14 +59,10 @@ class PaymentRecoveryTest extends WC_Unit_Test_Case {
add_filter( 'woocommerce_valid_order_statuses_for_payment', $declare_on_hold_payable );
- try {
- $this->assertFalse(
- PaymentRecovery::order_moved_past_payment( $order ),
- 'A status the site declares payable is still awaiting payment.'
- );
- } finally {
- remove_filter( 'woocommerce_valid_order_statuses_for_payment', $declare_on_hold_payable );
- }
+ $this->assertFalse(
+ PaymentRecovery::order_moved_past_payment( $order ),
+ 'A status the site declares payable is still awaiting payment.'
+ );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Internal/CustomerEmailVerification/EmailVerificationServiceTest.php b/plugins/woocommerce/tests/php/src/Internal/CustomerEmailVerification/EmailVerificationServiceTest.php
index 95d8fd8e000..450406d4c73 100644
--- a/plugins/woocommerce/tests/php/src/Internal/CustomerEmailVerification/EmailVerificationServiceTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/CustomerEmailVerification/EmailVerificationServiceTest.php
@@ -57,8 +57,6 @@ class EmailVerificationServiceTest extends WC_Unit_Test_Case {
$this->assertTrue( $this->sut->is_verified( $user_id ), 'User should be verified after mark_verified()' );
$this->assertSame( 1, $hook_calls, 'Hook should fire exactly once' );
$this->assertSame( $user_id, $hook_arg, 'Hook should receive the correct user ID' );
-
- remove_action( 'woocommerce_customer_email_verified', $listener );
}
/**
@@ -196,8 +194,6 @@ class EmailVerificationServiceTest extends WC_Unit_Test_Case {
$this->assertSame( 0, $hook_calls, 'A mismatched email must not fire the verification hook' );
$this->assertTrue( $this->sut->has_pending_key( $user_id ), 'A mismatched email must not consume the pending key' );
$this->assertFalse( $this->sut->check_verification_key( $user_id, $key ), 'The key must remain bound to the original email' );
-
- remove_action( 'woocommerce_customer_email_verified', $listener );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Internal/DataStores/Orders/DataSynchronizerTests.php b/plugins/woocommerce/tests/php/src/Internal/DataStores/Orders/DataSynchronizerTests.php
index 3651b0e238b..df420af4216 100644
--- a/plugins/woocommerce/tests/php/src/Internal/DataStores/Orders/DataSynchronizerTests.php
+++ b/plugins/woocommerce/tests/php/src/Internal/DataStores/Orders/DataSynchronizerTests.php
@@ -823,7 +823,6 @@ class DataSynchronizerTests extends \HposTestCase {
'',
'Meta data deleted from the CPT datastore should also be deleted from the HPOS datastore.'
);
- remove_all_filters( 'woocommerce_hpos_enable_sync_on_read' );
}
/**
@@ -869,8 +868,6 @@ class DataSynchronizerTests extends \HposTestCase {
$hpos_order = $legacy_handler->get_order_from_datastore( $legacy_order->get_id(), 'hpos' );
$this->assertEquals( $hpos_order->get_meta( 'quux' ), '' );
-
- remove_all_filters( 'woocommerce_hpos_enable_sync_on_read' );
}
/**
@@ -905,9 +902,6 @@ class DataSynchronizerTests extends \HposTestCase {
// Confirm placeholder has been updated.
$this->assertNotEquals( $this->sut::PLACEHOLDER_ORDER_POST_TYPE, get_post_type( $order->get_id() ) );
-
- remove_all_filters( 'pre_option_' . $this->sut::ORDERS_DATA_SYNC_ENABLED_OPTION );
- remove_all_filters( 'woocommerce_hpos_enable_sync_on_read' );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Internal/DataStores/Orders/OrdersTableDataStoreCacheCrossBleedTest.php b/plugins/woocommerce/tests/php/src/Internal/DataStores/Orders/OrdersTableDataStoreCacheCrossBleedTest.php
index 4bc245901a6..6449d4abbdc 100644
--- a/plugins/woocommerce/tests/php/src/Internal/DataStores/Orders/OrdersTableDataStoreCacheCrossBleedTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/DataStores/Orders/OrdersTableDataStoreCacheCrossBleedTest.php
@@ -303,8 +303,6 @@ class OrdersTableDataStoreCacheCrossBleedTest extends \HposTestCase {
}
}
$this->assertTrue( $found_hpos_source, 'Debug log entries should have source "hpos-data-cache"' );
-
- remove_all_filters( 'woocommerce_logging_class' );
}
/**
@@ -350,8 +348,6 @@ class OrdersTableDataStoreCacheCrossBleedTest extends \HposTestCase {
$this->assertInstanceOf( \stdClass::class, $recached[ $order_id ], 'The corrupt entry should be replaced in cache by a valid object.' );
$this->assert_hpos_cache_warning_logged( $fake_logger, 'corrupt HPOS order cache entry' );
-
- remove_all_filters( 'woocommerce_logging_class' );
}
/**
@@ -393,8 +389,6 @@ class OrdersTableDataStoreCacheCrossBleedTest extends \HposTestCase {
$this->assertSame( $order_id, (int) $order_data[ $order_id ]->id );
$this->assert_hpos_cache_warning_logged( $fake_logger, 'corrupt HPOS order cache entry' );
-
- remove_all_filters( 'woocommerce_logging_class' );
}
/**
@@ -432,8 +426,6 @@ class OrdersTableDataStoreCacheCrossBleedTest extends \HposTestCase {
$this->assertSame( 'custom_value', $reloaded_order->get_meta( 'custom_meta_key' ), 'Meta should be re-read from the database after the corrupt cache entry is discarded.' );
$this->assert_hpos_cache_warning_logged( $fake_logger, 'corrupt HPOS meta cache entry' );
-
- remove_all_filters( 'woocommerce_logging_class' );
}
/**
@@ -474,8 +466,6 @@ class OrdersTableDataStoreCacheCrossBleedTest extends \HposTestCase {
$this->assertInstanceOf( WC_Order::class, $reloaded_order, 'The order should load instead of fataling on the corrupt meta elements.' );
$this->assertSame( 'custom_value', $reloaded_order->get_meta( 'custom_meta_key' ), 'Meta should be re-read correctly from the database, not the corrupt scalar elements.' );
$this->assert_hpos_cache_warning_logged( $fake_logger, 'corrupt HPOS meta cache entry' );
-
- remove_all_filters( 'woocommerce_logging_class' );
}
/**
@@ -511,8 +501,6 @@ class OrdersTableDataStoreCacheCrossBleedTest extends \HposTestCase {
$this->assertInstanceOf( WC_Order::class, $reloaded_order, 'The order should load instead of using the incomplete cached row.' );
$this->assertSame( 'custom_value', $reloaded_order->get_meta( 'custom_meta_key' ), 'The incomplete row should be discarded and the real value re-read from the database.' );
$this->assert_hpos_cache_warning_logged( $fake_logger, 'corrupt HPOS meta cache entry' );
-
- remove_all_filters( 'woocommerce_logging_class' );
}
/**
@@ -553,8 +541,6 @@ class OrdersTableDataStoreCacheCrossBleedTest extends \HposTestCase {
$this->assertArrayHasKey( $order_id, $order_data, 'Order data should still be returned after the cross-bled entry is discarded.' );
$this->assertSame( $order_id, (int) $order_data[ $order_id ]->id, 'The mismatched-id entry should be replaced by the correct order read from the database.' );
$this->assert_hpos_cache_warning_logged( $fake_logger, 'corrupt HPOS order cache entry' );
-
- remove_all_filters( 'woocommerce_logging_class' );
}
/**
@@ -604,8 +590,6 @@ class OrdersTableDataStoreCacheCrossBleedTest extends \HposTestCase {
$this->assertTrue( property_exists( $order_data[ $order_id ], 'status' ), 'The truncated entry should be replaced by a complete record read from the database.' );
$this->assertSame( $order_id, (int) $order_data[ $order_id ]->id );
$this->assert_hpos_cache_warning_logged( $fake_logger, 'corrupt HPOS order cache entry' );
-
- remove_all_filters( 'woocommerce_logging_class' );
}
/**
@@ -635,8 +619,6 @@ class OrdersTableDataStoreCacheCrossBleedTest extends \HposTestCase {
$this->assertSame( array(), $result, 'A non-array meta argument should be treated as empty meta.' );
$this->assert_hpos_cache_warning_logged( $fake_logger, 'Discarded malformed meta data' );
-
- remove_all_filters( 'woocommerce_logging_class' );
}
/**
@@ -703,8 +685,6 @@ class OrdersTableDataStoreCacheCrossBleedTest extends \HposTestCase {
$this->count_hpos_cache_warnings( $fake_logger, 'Discarded malformed meta data' ),
'The corruption warning should fire once and stop once the cache self-heals.'
);
-
- remove_all_filters( 'woocommerce_logging_class' );
}
/**
@@ -755,8 +735,6 @@ class OrdersTableDataStoreCacheCrossBleedTest extends \HposTestCase {
$order->get_meta( 'custom_meta_key' ),
'The incomplete row should be discarded and the real value re-read from the database, not loaded as null.'
);
-
- remove_all_filters( 'woocommerce_logging_class' );
}
/**
@@ -823,9 +801,6 @@ class OrdersTableDataStoreCacheCrossBleedTest extends \HposTestCase {
);
$this->assertSame( 'virtual_value', $order->get_meta( '_virtual_meta' ), 'The injected virtual meta should still resolve after a cache hit.' );
$this->assertSame( 'custom_value', $order->get_meta( 'custom_meta_key' ), 'The real database meta should be unaffected.' );
-
- remove_filter( 'woocommerce_data_store_wp_post_read_meta', $read_meta_filter );
- remove_all_filters( 'woocommerce_logging_class' );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Internal/DataStores/Orders/OrdersTableDataStoreTests.php b/plugins/woocommerce/tests/php/src/Internal/DataStores/Orders/OrdersTableDataStoreTests.php
index 86fb1ff5c2a..8320fd787e7 100644
--- a/plugins/woocommerce/tests/php/src/Internal/DataStores/Orders/OrdersTableDataStoreTests.php
+++ b/plugins/woocommerce/tests/php/src/Internal/DataStores/Orders/OrdersTableDataStoreTests.php
@@ -1651,7 +1651,6 @@ class OrdersTableDataStoreTests extends \HposTestCase {
$this->sut->read( $refreshed_order );
$this->assertEquals( array( 'key' => 'value' ), $refreshed_order->get_meta( 'my_custom_meta' ) );
- remove_all_filters( 'woocommerce_hpos_enable_sync_on_read' );
}
/**
@@ -1692,7 +1691,6 @@ class OrdersTableDataStoreTests extends \HposTestCase {
$this->assertEquals( 'custom_value_4', $refreshed_order->get_meta( 'custom_meta_4' ) );
$this->assertEquals( 'custom_value_1_updated', $refreshed_order->get_meta( 'custom_meta_1' ) );
$this->assertEquals( '', $refreshed_order->get_meta( 'custom_meta_2' ) );
- remove_all_filters( 'woocommerce_hpos_enable_sync_on_read' );
}
/**
@@ -1726,7 +1724,6 @@ class OrdersTableDataStoreTests extends \HposTestCase {
$this->assertEquals( array( 'new_value' ), get_post_meta( $order->get_id(), 'new_meta', false ) );
$this->assertEquals( array( 'after' ), get_post_meta( $order->get_id(), 'changed_meta', false ) );
$this->assertEquals( array( 'y', 'z' ), get_post_meta( $order->get_id(), 'multi_meta', false ) );
- remove_all_filters( 'woocommerce_hpos_enable_sync_on_read' );
}
/**
@@ -1760,7 +1757,6 @@ class OrdersTableDataStoreTests extends \HposTestCase {
$this->sut->read( $r_order );
$this->assertFalse( $post_order_comparison_closure->call( $this->sut, $r_order ) );
$this->assertEquals( array( 'key' => 'value' ), $r_order->get_meta( 'my_custom_meta' ) );
- remove_all_filters( 'woocommerce_hpos_enable_sync_on_read' );
}
/**
@@ -1926,9 +1922,6 @@ class OrdersTableDataStoreTests extends \HposTestCase {
$this->reset_order_data_store_state( $this->sut );
wc_get_order( $order->get_id() );
$this->assertFalse( $sync_on_read_triggered, 'Sync on read should not trigger when post is older.' );
-
- remove_all_actions( 'woocommerce_hpos_post_record_migrated_on_read' );
- remove_all_filters( 'woocommerce_hpos_enable_sync_on_read' );
}
/**
@@ -2659,9 +2652,7 @@ class OrdersTableDataStoreTests extends \HposTestCase {
* @testdox Generic order persistence saves the store tax-mode default captured at construction.
*/
public function test_create_without_explicit_prices_include_tax_keeps_default(): void {
- $previous_tax_mode = get_option( 'woocommerce_prices_include_tax' );
- $previous_calc_tax = get_option( 'woocommerce_calc_taxes' );
- $order = null;
+ $order = null;
try {
update_option( 'woocommerce_calc_taxes', 'yes' );
@@ -2687,8 +2678,6 @@ class OrdersTableDataStoreTests extends \HposTestCase {
if ( $order ) {
$order->delete( true );
}
- update_option( 'woocommerce_prices_include_tax', $previous_tax_mode );
- update_option( 'woocommerce_calc_taxes', $previous_calc_tax );
}
}
@@ -2696,8 +2685,7 @@ class OrdersTableDataStoreTests extends \HposTestCase {
* @testDox An explicitly set prices_include_tax value is persisted as given, not replaced by the store setting.
*/
public function test_create_keeps_explicit_prices_include_tax_value(): void {
- $previous_tax_mode = get_option( 'woocommerce_prices_include_tax' );
- $order = null;
+ $order = null;
try {
update_option( 'woocommerce_prices_include_tax', 'yes' );
@@ -2721,7 +2709,6 @@ class OrdersTableDataStoreTests extends \HposTestCase {
if ( $order ) {
$order->delete( true );
}
- update_option( 'woocommerce_prices_include_tax', $previous_tax_mode );
}
}
@@ -2731,9 +2718,7 @@ class OrdersTableDataStoreTests extends \HposTestCase {
public function test_read_with_null_prices_include_tax_uses_store_default(): void {
global $wpdb;
- $previous_tax_mode = get_option( 'woocommerce_prices_include_tax' );
- $previous_calc_tax = get_option( 'woocommerce_calc_taxes' );
- $order = new WC_Order();
+ $order = new WC_Order();
try {
update_option( 'woocommerce_calc_taxes', 'yes' );
@@ -2762,8 +2747,6 @@ class OrdersTableDataStoreTests extends \HposTestCase {
$this->assertArrayNotHasKey( 'prices_include_tax', $read_order->get_changes() );
} finally {
$order->delete( true );
- update_option( 'woocommerce_prices_include_tax', $previous_tax_mode );
- update_option( 'woocommerce_calc_taxes', $previous_calc_tax );
}
}
@@ -3377,7 +3360,6 @@ class OrdersTableDataStoreTests extends \HposTestCase {
$this->assertEquals( 'test_value', $r_order->get_meta( 'test_key', true ) );
$this->assertEquals( 'test_value_2', $r_order->get_meta( 'test_key_2', true ) );
$this->assertEquals( 'test_value_3', $r_order->get_meta( 'test_key_3', true ) );
- remove_filter( 'added_post_meta', array( $this, 'add_meta_when_meta_added' ) );
}
/**
@@ -3415,7 +3397,6 @@ class OrdersTableDataStoreTests extends \HposTestCase {
$this->assertEquals( 'test_value_2', $r_order->get_meta( 'test_key_2', true ) );
$this->assertEquals( 'test_value_3', $r_order->get_meta( 'test_key_3', true ) );
$this->assertEquals( 1, $r_order->get_customer_id() );
- remove_filter( 'added_post_meta', array( $this, 'add_meta_when_meta_added' ) );
}
/**
@@ -3517,9 +3498,6 @@ class OrdersTableDataStoreTests extends \HposTestCase {
$this->assertEquals( 2, $new_count );
$this->assertEquals( 2, $update_count );
}
-
- remove_action( 'woocommerce_new_order', $callback );
- remove_action( 'woocommerce_update_order', $callback );
}
/**
@@ -4007,8 +3985,6 @@ class OrdersTableDataStoreTests extends \HposTestCase {
$r_order = wc_get_order( $order->get_id() );
$this->assertEquals( 2, $r_order->get_customer_id() );
-
- remove_all_actions( 'woocommerce_delete_shop_order_transients' );
}
/**
@@ -4094,7 +4070,6 @@ class OrdersTableDataStoreTests extends \HposTestCase {
$this->assertTrue( $current_time_called, 'current_time mock was not called' );
remove_filter( 'woocommerce_order_data_store', $orders_table_data_store, 1000 );
- remove_all_actions( 'woocommerce_before_order_object_save' );
}
/**
@@ -4362,8 +4337,6 @@ class OrdersTableDataStoreTests extends \HposTestCase {
}
$this->assertEquals( 0, $new_count );
-
- remove_action( 'woocommerce_new_order', $callback );
}
/**
@@ -4399,8 +4372,6 @@ class OrdersTableDataStoreTests extends \HposTestCase {
}
$this->assertEquals( 4, $new_count );
-
- remove_action( 'woocommerce_new_order', $callback );
}
/**
@@ -4427,8 +4398,6 @@ class OrdersTableDataStoreTests extends \HposTestCase {
$order->save();
$this->assertEquals( 1, $new_count );
-
- remove_action( 'woocommerce_new_order', $callback );
}
diff --git a/plugins/woocommerce/tests/php/src/Internal/DataStores/Orders/OrdersTableQueryTests.php b/plugins/woocommerce/tests/php/src/Internal/DataStores/Orders/OrdersTableQueryTests.php
index c308face491..7294d2b5a43 100644
--- a/plugins/woocommerce/tests/php/src/Internal/DataStores/Orders/OrdersTableQueryTests.php
+++ b/plugins/woocommerce/tests/php/src/Internal/DataStores/Orders/OrdersTableQueryTests.php
@@ -293,7 +293,6 @@ class OrdersTableQueryTests extends \WC_Unit_Test_Case {
$order1->get_id(),
)
);
- remove_all_filters( 'woocommerce_orders_table_query_clauses' );
}
/**
@@ -333,8 +332,6 @@ class OrdersTableQueryTests extends \WC_Unit_Test_Case {
$orders = wc_get_orders( array() );
$this->assertCount( 1, $orders );
$this->assertEquals( $order1->get_id(), $orders[0]->get_id() );
-
- remove_all_filters( 'woocommerce_hpos_pre_query' );
}
/**
@@ -376,8 +373,6 @@ class OrdersTableQueryTests extends \WC_Unit_Test_Case {
$orders = wc_get_orders( array() );
$this->assertCount( 1, $orders );
$this->assertEquals( $order1->get_id(), $orders[0]->get_id() );
-
- remove_all_filters( 'woocommerce_hpos_pre_query' );
}
/**
@@ -403,8 +398,6 @@ class OrdersTableQueryTests extends \WC_Unit_Test_Case {
$this->assertCount( 1, $query->orders );
$this->assertEquals( 10, $query->found_orders );
$this->assertEquals( 2, $query->max_num_pages );
-
- remove_all_filters( 'woocommerce_hpos_pre_query' );
}
/**
@@ -431,8 +424,6 @@ class OrdersTableQueryTests extends \WC_Unit_Test_Case {
$this->assertCount( 1, $query->orders );
$this->assertEquals( 1, $query->found_orders );
$this->assertEquals( null, $query->max_num_pages );
-
- remove_all_filters( 'woocommerce_hpos_pre_query' );
}
/**
@@ -457,8 +448,6 @@ class OrdersTableQueryTests extends \WC_Unit_Test_Case {
$this->assertCount( 1, $query->orders );
$this->assertEquals( 1, $query->found_orders );
$this->assertEquals( 1, $query->max_num_pages );
-
- remove_all_filters( 'woocommerce_hpos_pre_query' );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Internal/Email/EmailLoggerTest.php b/plugins/woocommerce/tests/php/src/Internal/Email/EmailLoggerTest.php
index 8403e42b9f5..d0492ae9fb4 100644
--- a/plugins/woocommerce/tests/php/src/Internal/Email/EmailLoggerTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/Email/EmailLoggerTest.php
@@ -1053,7 +1053,5 @@ class EmailLoggerTest extends WC_Unit_Test_Case {
$this->assertIsBool( $received_return, 'woocommerce_email_sent should receive a bool even when the mail callback returns a non-bool' );
$this->assertFalse( $received_return );
-
- remove_all_actions( 'woocommerce_email_sent' );
}
}
diff --git a/plugins/woocommerce/tests/php/src/Internal/EmailEditor/BlockEmailRendererTest.php b/plugins/woocommerce/tests/php/src/Internal/EmailEditor/BlockEmailRendererTest.php
index 58f421d5042..3006322a457 100644
--- a/plugins/woocommerce/tests/php/src/Internal/EmailEditor/BlockEmailRendererTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/EmailEditor/BlockEmailRendererTest.php
@@ -204,14 +204,10 @@ class BlockEmailRendererTest extends \WC_Unit_Test_Case {
// sending must hand back null so the classic pipeline takes over.
add_filter( 'woocommerce_email_block_template_html', '__return_empty_string' );
- try {
- $this->assertNull(
- $this->block_email_renderer->maybe_render_block_email( $wc_mail_mock ),
- 'An empty file template must yield null, not an empty-bodied email'
- );
- } finally {
- remove_filter( 'woocommerce_email_block_template_html', '__return_empty_string' );
- }
+ $this->assertNull(
+ $this->block_email_renderer->maybe_render_block_email( $wc_mail_mock ),
+ 'An empty file template must yield null, not an empty-bodied email'
+ );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Internal/EmailEditor/WCTransactionalEmails/WCEmailPostsCleanupTest.php b/plugins/woocommerce/tests/php/src/Internal/EmailEditor/WCTransactionalEmails/WCEmailPostsCleanupTest.php
index 27f1d9e81a5..72ef3ea7ea4 100644
--- a/plugins/woocommerce/tests/php/src/Internal/EmailEditor/WCTransactionalEmails/WCEmailPostsCleanupTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/EmailEditor/WCTransactionalEmails/WCEmailPostsCleanupTest.php
@@ -396,8 +396,6 @@ class WCEmailPostsCleanupTest extends \WC_Unit_Test_Case {
(int) get_option( $lookalike_option ),
'Options merely matching the LIKE pattern must never be deleted'
);
-
- delete_option( $lookalike_option );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Internal/EmailEditor/WCTransactionalEmails/WCEmailTemplateSelectiveApplierTest.php b/plugins/woocommerce/tests/php/src/Internal/EmailEditor/WCTransactionalEmails/WCEmailTemplateSelectiveApplierTest.php
index d9328e57bd4..62d7b10a9c4 100644
--- a/plugins/woocommerce/tests/php/src/Internal/EmailEditor/WCTransactionalEmails/WCEmailTemplateSelectiveApplierTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/EmailEditor/WCTransactionalEmails/WCEmailTemplateSelectiveApplierTest.php
@@ -800,31 +800,27 @@ class WCEmailTemplateSelectiveApplierTest extends \WC_Unit_Test_Case {
};
add_filter( 'content_save_pre', $mutator, 99 );
- try {
- $result = WCEmailTemplateSelectiveApplier::apply_selectively(
- $post_id,
+ $result = WCEmailTemplateSelectiveApplier::apply_selectively(
+ $post_id,
+ array(
array(
- array(
- 'path' => array( 0 ),
- 'decision' => 'use_core',
- ),
- )
- );
- $this->assertIsArray( $result );
-
- $persisted = get_post( $post_id );
- $stored_hash = (string) get_post_meta( $post_id, WCEmailTemplateDivergenceDetector::SOURCE_HASH_META_KEY, true );
-
- $this->assertInstanceOf( \WP_Post::class, $persisted );
- $this->assertStringContainsString( '<!-- filter mutated -->', (string) $persisted->post_content );
- $this->assertSame(
- sha1( (string) $persisted->post_content ),
- $stored_hash,
- 'use_core apply must stamp sha1(persisted post_content), not sha1(in-memory merged).'
- );
- } finally {
- remove_filter( 'content_save_pre', $mutator, 99 );
- }//end try
+ 'path' => array( 0 ),
+ 'decision' => 'use_core',
+ ),
+ )
+ );
+ $this->assertIsArray( $result );
+
+ $persisted = get_post( $post_id );
+ $stored_hash = (string) get_post_meta( $post_id, WCEmailTemplateDivergenceDetector::SOURCE_HASH_META_KEY, true );
+
+ $this->assertInstanceOf( \WP_Post::class, $persisted );
+ $this->assertStringContainsString( '<!-- filter mutated -->', (string) $persisted->post_content );
+ $this->assertSame(
+ sha1( (string) $persisted->post_content ),
+ $stored_hash,
+ 'use_core apply must stamp sha1(persisted post_content), not sha1(in-memory merged).'
+ );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Internal/LegacyAssets/LegacySelect2UsageTrackerTest.php b/plugins/woocommerce/tests/php/src/Internal/LegacyAssets/LegacySelect2UsageTrackerTest.php
index d378755bb58..d8bfed2d31e 100644
--- a/plugins/woocommerce/tests/php/src/Internal/LegacyAssets/LegacySelect2UsageTrackerTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/LegacyAssets/LegacySelect2UsageTrackerTest.php
@@ -260,9 +260,6 @@ class LegacySelect2UsageTrackerTest extends WC_Unit_Test_Case {
has_action( 'admin_print_footer_scripts', array( $this->sut, 'handle_admin_print_footer_scripts' ) ),
'Admin tracking should remain disabled when core Tracks is disabled.'
);
-
- remove_action( 'wp_print_footer_scripts', array( $this->sut, 'handle_wp_print_footer_scripts' ), PHP_INT_MAX );
- remove_filter( 'woocommerce_apply_user_tracking', '__return_false' );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Internal/McStatsTest.php b/plugins/woocommerce/tests/php/src/Internal/McStatsTest.php
index 055976746c0..baa3e38dfd7 100644
--- a/plugins/woocommerce/tests/php/src/Internal/McStatsTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/McStatsTest.php
@@ -122,7 +122,5 @@ class McStatsTest extends \WC_Unit_Test_Case {
$result = $this->sut->do_server_side_stat( 'http://example.com' );
$this->assertTrue( $result );
-
- remove_all_filters( 'pre_http_request' );
}
}
diff --git a/plugins/woocommerce/tests/php/src/Internal/OrderReviews/EndpointTest.php b/plugins/woocommerce/tests/php/src/Internal/OrderReviews/EndpointTest.php
index db3eb342026..5b51cce1dd9 100644
--- a/plugins/woocommerce/tests/php/src/Internal/OrderReviews/EndpointTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/OrderReviews/EndpointTest.php
@@ -194,8 +194,6 @@ class EndpointTest extends WC_Unit_Test_Case {
add_filter( 'woocommerce_review_order_url', $override );
$this->assertSame( 'https://example.test/custom', wc_get_review_order_url( $order ) );
-
- remove_filter( 'woocommerce_review_order_url', $override );
}
/**
@@ -445,9 +443,6 @@ class EndpointTest extends WC_Unit_Test_Case {
$this->assertNotFalse(
has_filter( 'render_block_core/post-title', array( $this->endpoint, 'maybe_hide_post_title_block' ) )
);
-
- remove_filter( 'the_title', array( $this->endpoint, 'maybe_hide_page_title' ), 10 );
- remove_filter( 'render_block_core/post-title', array( $this->endpoint, 'maybe_hide_post_title_block' ), 10 );
}
/**
@@ -1538,9 +1533,6 @@ class EndpointTest extends WC_Unit_Test_Case {
$this->assertNotFalse( has_filter( 'the_title', array( $this->endpoint, 'maybe_hide_page_title' ) ) );
$this->assertNotFalse( has_filter( 'render_block_core/post-title', array( $this->endpoint, 'maybe_hide_post_title_block' ) ) );
-
- remove_filter( 'the_title', array( $this->endpoint, 'maybe_hide_page_title' ), 10 );
- remove_filter( 'render_block_core/post-title', array( $this->endpoint, 'maybe_hide_post_title_block' ), 10 );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Internal/OrderReviews/SchedulerTest.php b/plugins/woocommerce/tests/php/src/Internal/OrderReviews/SchedulerTest.php
index f740703613d..9f2d1f2da63 100644
--- a/plugins/woocommerce/tests/php/src/Internal/OrderReviews/SchedulerTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/OrderReviews/SchedulerTest.php
@@ -307,21 +307,17 @@ class SchedulerTest extends WC_Unit_Test_Case {
};
add_filter( 'woocommerce_review_order_eligible_statuses', $widen );
- try {
- $order = $this->create_pending_order();
- $order->update_status( 'completed' );
- $this->assertTrue( (bool) as_next_scheduled_action( Scheduler::ACTION_HOOK, array( $order->get_id() ) ) );
+ $order = $this->create_pending_order();
+ $order->update_status( 'completed' );
+ $this->assertTrue( (bool) as_next_scheduled_action( Scheduler::ACTION_HOOK, array( $order->get_id() ) ) );
- // `processing` is eligible per the filter, so the pending action stays.
- $order->update_status( 'processing' );
- $this->assertTrue( (bool) as_next_scheduled_action( Scheduler::ACTION_HOOK, array( $order->get_id() ) ) );
+ // `processing` is eligible per the filter, so the pending action stays.
+ $order->update_status( 'processing' );
+ $this->assertTrue( (bool) as_next_scheduled_action( Scheduler::ACTION_HOOK, array( $order->get_id() ) ) );
- // `on-hold` is NOT in the filter's eligible set, so the action is now unscheduled.
- $order->update_status( 'on-hold' );
- $this->assertFalse( (bool) as_next_scheduled_action( Scheduler::ACTION_HOOK, array( $order->get_id() ) ) );
- } finally {
- remove_filter( 'woocommerce_review_order_eligible_statuses', $widen );
- }
+ // `on-hold` is NOT in the filter's eligible set, so the action is now unscheduled.
+ $order->update_status( 'on-hold' );
+ $this->assertFalse( (bool) as_next_scheduled_action( Scheduler::ACTION_HOOK, array( $order->get_id() ) ) );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Internal/OrderWithdrawal/OrderWithdrawalTest.php b/plugins/woocommerce/tests/php/src/Internal/OrderWithdrawal/OrderWithdrawalTest.php
index cbfac24ec16..f1087db1e32 100644
--- a/plugins/woocommerce/tests/php/src/Internal/OrderWithdrawal/OrderWithdrawalTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/OrderWithdrawal/OrderWithdrawalTest.php
@@ -641,27 +641,13 @@ class OrderWithdrawalTest extends WC_Unit_Test_Case {
$notification->init( $endpoint );
$controller->init( $this->sut, new OrderWithdrawalFormView(), $notification, $email_preview, $endpoint );
- try {
- $controller->register();
- $controller->register_feature_hooks();
+ $controller->register();
+ $controller->register_feature_hooks();
- $this->assertNotFalse( has_action( 'woocommerce_before_delete_order', array( $this->sut, 'delete_order_withdrawal_inbox_note_for_order' ) ) );
- $this->assertNotFalse( has_action( 'before_delete_post', array( $this->sut, 'delete_order_withdrawal_inbox_note_for_order' ) ) );
- $this->assertNotFalse( has_action( FeaturesController::FEATURE_ENABLED_CHANGED_ACTION, array( $notification, 'possibly_add_enabled_note' ) ) );
- $this->assertFalse( has_filter( 'woocommerce_prepare_email_for_preview', array( $email_preview, 'prepare_email_for_preview' ) ) );
- } finally {
- remove_action( 'init', array( $controller, 'register_feature_hooks' ), 0 );
- remove_action( FeaturesController::FEATURE_ENABLED_CHANGED_ACTION, array( $controller, 'maybe_flush_rewrite_rules' ), 10 );
- remove_action( FeaturesController::FEATURE_ENABLED_CHANGED_ACTION, array( $notification, 'possibly_add_enabled_note' ), 10 );
- remove_filter( 'woocommerce_prepare_email_for_preview', array( $email_preview, 'prepare_email_for_preview' ), 10 );
- remove_filter( 'woocommerce_get_query_vars', array( $controller, 'add_query_var' ), 10 );
- remove_filter( 'woocommerce_endpoint_order-withdrawal_title', array( $controller, 'get_endpoint_title' ), 10 );
- remove_filter( 'woocommerce_settings_pages', array( $controller, 'add_endpoint_setting' ), 10 );
- remove_action( 'woocommerce_account_order-withdrawal_endpoint', array( $controller, 'render_view' ), 10 );
- remove_action( 'woocommerce_before_delete_order', array( $this->sut, 'delete_order_withdrawal_inbox_note_for_order' ), 10 );
- remove_action( 'before_delete_post', array( $this->sut, 'delete_order_withdrawal_inbox_note_for_order' ), 10 );
- remove_action( 'woocommerce_privacy_remove_order_personal_data', array( $this->sut, 'delete_order_withdrawal_inbox_note_for_order' ), 10 );
- }
+ $this->assertNotFalse( has_action( 'woocommerce_before_delete_order', array( $this->sut, 'delete_order_withdrawal_inbox_note_for_order' ) ) );
+ $this->assertNotFalse( has_action( 'before_delete_post', array( $this->sut, 'delete_order_withdrawal_inbox_note_for_order' ) ) );
+ $this->assertNotFalse( has_action( FeaturesController::FEATURE_ENABLED_CHANGED_ACTION, array( $notification, 'possibly_add_enabled_note' ) ) );
+ $this->assertFalse( has_filter( 'woocommerce_prepare_email_for_preview', array( $email_preview, 'prepare_email_for_preview' ) ) );
}
/**
@@ -724,17 +710,8 @@ class OrderWithdrawalTest extends WC_Unit_Test_Case {
$this->assertFalse( has_action( 'update_option_woocommerce_coming_soon', array( $notification, 'maybe_add_note_when_store_goes_live' ) ), 'The feature highlight notification should not listen for coming-soon changes when the feature is enabled.' );
$this->assertFalse( has_action( 'wc_admin_daily', array( $notification, 'possibly_add_note' ) ), 'The feature highlight notification should not run daily when the feature is enabled.' );
} finally {
- remove_action( 'init', array( $controller, 'register_feature_hooks' ), 0 );
remove_action( FeaturesController::FEATURE_ENABLED_CHANGED_ACTION, array( $controller, 'maybe_flush_rewrite_rules' ), 10 );
remove_action( FeaturesController::FEATURE_ENABLED_CHANGED_ACTION, array( $notification, 'possibly_add_enabled_note' ), 10 );
- remove_filter( 'woocommerce_prepare_email_for_preview', array( $email_preview, 'prepare_email_for_preview' ), 10 );
- remove_filter( 'woocommerce_get_query_vars', array( $controller, 'add_query_var' ), 10 );
- remove_filter( 'woocommerce_endpoint_order-withdrawal_title', array( $controller, 'get_endpoint_title' ), 10 );
- remove_filter( 'woocommerce_settings_pages', array( $controller, 'add_endpoint_setting' ), 10 );
- remove_action( 'woocommerce_account_order-withdrawal_endpoint', array( $controller, 'render_view' ), 10 );
- remove_action( 'woocommerce_before_delete_order', array( $this->sut, 'delete_order_withdrawal_inbox_note_for_order' ), 10 );
- remove_action( 'before_delete_post', array( $this->sut, 'delete_order_withdrawal_inbox_note_for_order' ), 10 );
- remove_action( 'woocommerce_privacy_remove_order_personal_data', array( $this->sut, 'delete_order_withdrawal_inbox_note_for_order' ), 10 );
}
}
@@ -759,28 +736,17 @@ class OrderWithdrawalTest extends WC_Unit_Test_Case {
$endpoint
);
- try {
- $controller->register();
- $controller->register_feature_hooks();
-
- $this->assertFalse( has_filter( 'woocommerce_get_query_vars', array( $controller, 'add_query_var' ) ), 'The endpoint query var should not be registered while the feature is disabled.' );
- $this->assertFalse( has_filter( 'woocommerce_endpoint_order-withdrawal_title', array( $controller, 'get_endpoint_title' ) ), 'The endpoint title should not be registered while the feature is disabled.' );
- $this->assertFalse( has_filter( 'woocommerce_settings_pages', array( $controller, 'add_endpoint_setting' ) ), 'The endpoint setting should not be registered while the feature is disabled.' );
- $this->assertFalse( has_action( 'woocommerce_account_order-withdrawal_endpoint', array( $controller, 'render_view' ) ), 'The endpoint renderer should not be registered while the feature is disabled.' );
- $this->assertNotFalse( has_action( 'woocommerce_before_delete_order', array( $this->sut, 'delete_order_withdrawal_inbox_note_for_order' ) ), 'HPOS order cleanup should stay registered while the feature is disabled.' );
- $this->assertNotFalse( has_action( 'before_delete_post', array( $this->sut, 'delete_order_withdrawal_inbox_note_for_order' ) ), 'Legacy order cleanup should stay registered while the feature is disabled.' );
- $this->assertNotFalse( has_action( 'woocommerce_privacy_remove_order_personal_data', array( $this->sut, 'delete_order_withdrawal_inbox_note_for_order' ) ), 'Privacy erasure cleanup should stay registered while the feature is disabled.' );
- $this->assertNotFalse( has_action( 'wc_admin_daily', array( $notification, 'possibly_add_note' ) ), 'The feature highlight notification should run while the feature is disabled.' );
- } finally {
- remove_action( 'init', array( $controller, 'register_feature_hooks' ), 0 );
- remove_action( FeaturesController::FEATURE_ENABLED_CHANGED_ACTION, array( $controller, 'maybe_flush_rewrite_rules' ), 10 );
- remove_action( FeaturesController::FEATURE_ENABLED_CHANGED_ACTION, array( $notification, 'possibly_add_enabled_note' ), 10 );
- remove_action( 'update_option_woocommerce_coming_soon', array( $notification, 'maybe_add_note_when_store_goes_live' ), 10 );
- remove_action( 'wc_admin_daily', array( $notification, 'possibly_add_note' ), 10 );
- remove_action( 'woocommerce_before_delete_order', array( $this->sut, 'delete_order_withdrawal_inbox_note_for_order' ), 10 );
- remove_action( 'before_delete_post', array( $this->sut, 'delete_order_withdrawal_inbox_note_for_order' ), 10 );
- remove_action( 'woocommerce_privacy_remove_order_personal_data', array( $this->sut, 'delete_order_withdrawal_inbox_note_for_order' ), 10 );
- }
+ $controller->register();
+ $controller->register_feature_hooks();
+
+ $this->assertFalse( has_filter( 'woocommerce_get_query_vars', array( $controller, 'add_query_var' ) ), 'The endpoint query var should not be registered while the feature is disabled.' );
+ $this->assertFalse( has_filter( 'woocommerce_endpoint_order-withdrawal_title', array( $controller, 'get_endpoint_title' ) ), 'The endpoint title should not be registered while the feature is disabled.' );
+ $this->assertFalse( has_filter( 'woocommerce_settings_pages', array( $controller, 'add_endpoint_setting' ) ), 'The endpoint setting should not be registered while the feature is disabled.' );
+ $this->assertFalse( has_action( 'woocommerce_account_order-withdrawal_endpoint', array( $controller, 'render_view' ) ), 'The endpoint renderer should not be registered while the feature is disabled.' );
+ $this->assertNotFalse( has_action( 'woocommerce_before_delete_order', array( $this->sut, 'delete_order_withdrawal_inbox_note_for_order' ) ), 'HPOS order cleanup should stay registered while the feature is disabled.' );
+ $this->assertNotFalse( has_action( 'before_delete_post', array( $this->sut, 'delete_order_withdrawal_inbox_note_for_order' ) ), 'Legacy order cleanup should stay registered while the feature is disabled.' );
+ $this->assertNotFalse( has_action( 'woocommerce_privacy_remove_order_personal_data', array( $this->sut, 'delete_order_withdrawal_inbox_note_for_order' ) ), 'Privacy erasure cleanup should stay registered while the feature is disabled.' );
+ $this->assertNotFalse( has_action( 'wc_admin_daily', array( $notification, 'possibly_add_note' ) ), 'The feature highlight notification should run while the feature is disabled.' );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Internal/Orders/OrderActionsRestControllerTest.php b/plugins/woocommerce/tests/php/src/Internal/Orders/OrderActionsRestControllerTest.php
index 752a8cd2368..02959b51809 100644
--- a/plugins/woocommerce/tests/php/src/Internal/Orders/OrderActionsRestControllerTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/Orders/OrderActionsRestControllerTest.php
@@ -728,8 +728,6 @@ class OrderActionsRestControllerTest extends WC_Unit_Test_Case {
$data = $response->get_data();
$this->assertStringContainsString( 'Order details sent to', $data['message'] );
-
- remove_filter( 'woocommerce_rest_order_actions_email_preferred_template_ids', $override_preferred_ids );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Internal/Orders/OrderAttributionControllerTest.php b/plugins/woocommerce/tests/php/src/Internal/Orders/OrderAttributionControllerTest.php
index df9a63864c9..d503c10beef 100644
--- a/plugins/woocommerce/tests/php/src/Internal/Orders/OrderAttributionControllerTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/Orders/OrderAttributionControllerTest.php
@@ -246,8 +246,6 @@ class OrderAttributionControllerTest extends WP_UnitTestCase {
// Should only contain one instance.
$this->assertEquals( 1, substr_count( $output, '<wc-order-attribution-inputs>' ) );
-
- remove_filter( 'wc_order_attribution_allow_multiple_elements', '__return_false' );
}
/**
@@ -303,8 +301,6 @@ class OrderAttributionControllerTest extends WP_UnitTestCase {
$this->attribution_class->stamp_html_element();
$output2 = ob_get_clean();
$this->assertEmpty( $output2 );
-
- remove_filter( 'wc_order_attribution_allow_multiple_elements', '__return_false' );
}
/**
@@ -337,8 +333,6 @@ class OrderAttributionControllerTest extends WP_UnitTestCase {
$this->attribution_class->stamp_html_element();
$output3 = ob_get_clean();
$this->assertEmpty( $output3, 'Second call within same request should be suppressed' );
-
- remove_filter( 'wc_order_attribution_allow_multiple_elements', '__return_false' );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Internal/Orders/PaymentInfoTest.php b/plugins/woocommerce/tests/php/src/Internal/Orders/PaymentInfoTest.php
index c51be1389de..aa96e7b5878 100644
--- a/plugins/woocommerce/tests/php/src/Internal/Orders/PaymentInfoTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/Orders/PaymentInfoTest.php
@@ -65,7 +65,5 @@ class PaymentInfoTest extends WC_Unit_Test_Case {
$this->assertArrayHasKey( 'payment_method', $result );
$this->assertEquals( 'foo', $result['payment_method'] );
-
- remove_filter( 'wc_order_payment_card_info', $filter_callback );
}
}
diff --git a/plugins/woocommerce/tests/php/src/Internal/Orders/PointOfSaleEmailHandlerTest.php b/plugins/woocommerce/tests/php/src/Internal/Orders/PointOfSaleEmailHandlerTest.php
index 852a073fbe1..c5061580f9f 100644
--- a/plugins/woocommerce/tests/php/src/Internal/Orders/PointOfSaleEmailHandlerTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/Orders/PointOfSaleEmailHandlerTest.php
@@ -137,12 +137,5 @@ class PointOfSaleEmailHandlerTest extends WC_Unit_Test_Case {
$this->assertNotFalse(
has_filter( 'woocommerce_email_enabled_customer_partially_refunded_order', array( $handler, 'maybe_suppress_email' ) )
);
-
- remove_all_filters( 'woocommerce_email_enabled_customer_completed_order' );
- remove_all_filters( 'woocommerce_email_enabled_customer_processing_order' );
- remove_all_filters( 'woocommerce_email_enabled_customer_on_hold_order' );
- remove_all_filters( 'woocommerce_email_enabled_customer_refunded_order' );
- remove_all_filters( 'woocommerce_email_enabled_customer_partially_refunded_order' );
- remove_all_filters( 'woocommerce_email_enabled_new_order' );
}
}
diff --git a/plugins/woocommerce/tests/php/src/Internal/ProductFeed/Integrations/POSCatalog/AsyncGeneratorTest.php b/plugins/woocommerce/tests/php/src/Internal/ProductFeed/Integrations/POSCatalog/AsyncGeneratorTest.php
index c9d923ab9b9..8193a32dec9 100644
--- a/plugins/woocommerce/tests/php/src/Internal/ProductFeed/Integrations/POSCatalog/AsyncGeneratorTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/ProductFeed/Integrations/POSCatalog/AsyncGeneratorTest.php
@@ -209,7 +209,6 @@ class AsyncGeneratorTest extends \WC_Unit_Test_Case {
$this->assertSame( AsyncGenerator::STATE_SCHEDULED, $status['state'] );
as_unschedule_all_actions( AsyncGenerator::FEED_GENERATION_ACTION, array(), 'woo-product-feed' );
- delete_option( $option_key );
}
/**
@@ -280,7 +279,6 @@ class AsyncGeneratorTest extends \WC_Unit_Test_Case {
$callback = fn() => 10;
add_filter( 'woocommerce_product_feed_in_progress_timeout', $callback );
$this->assertFalse( $method->invoke( $this->sut, $status ) );
- remove_filter( 'woocommerce_product_feed_in_progress_timeout', $callback );
}
/**
@@ -325,7 +323,6 @@ class AsyncGeneratorTest extends \WC_Unit_Test_Case {
$callback = fn() => 20 * MINUTE_IN_SECONDS;
add_filter( 'woocommerce_product_feed_batch_time_limit', $callback );
$this->assertTrue( $method->invoke( $this->sut, $status ) );
- remove_filter( 'woocommerce_product_feed_batch_time_limit', $callback );
}
/**
@@ -697,8 +694,6 @@ class AsyncGeneratorTest extends \WC_Unit_Test_Case {
$this->assertSame( 2500, (int) get_option( $option_key . '_chunk_size' ) );
as_unschedule_all_actions( AsyncGenerator::FEED_GENERATION_ACTION, array(), 'woo-product-feed' );
- delete_option( $option_key );
- delete_option( $option_key . '_chunk_size' );
}
/**
@@ -716,8 +711,6 @@ class AsyncGeneratorTest extends \WC_Unit_Test_Case {
$this->assertSame( 1000, $reduce->invoke( $this->sut, $option_key ) );
// Already at the smallest configured size: it stays there.
$this->assertSame( 1000, $reduce->invoke( $this->sut, $option_key ) );
-
- delete_option( $option_key . '_chunk_size' );
}
/**
@@ -766,8 +759,6 @@ class AsyncGeneratorTest extends \WC_Unit_Test_Case {
$this->assertSame( 2500, (int) get_option( $option_key . '_chunk_size' ) );
as_unschedule_all_actions( AsyncGenerator::FEED_GENERATION_ACTION, array(), 'woo-product-feed' );
- delete_option( $option_key );
- delete_option( $option_key . '_chunk_size' );
}
/**
@@ -817,7 +808,6 @@ class AsyncGeneratorTest extends \WC_Unit_Test_Case {
$this->assertArrayNotHasKey( 'file_name', $status );
as_unschedule_all_actions( AsyncGenerator::FEED_GENERATION_ACTION, array(), 'woo-product-feed' );
- delete_option( $option_key );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Internal/ProductFeed/Integrations/POSCatalog/POSProductVisibilitySyncTest.php b/plugins/woocommerce/tests/php/src/Internal/ProductFeed/Integrations/POSCatalog/POSProductVisibilitySyncTest.php
index 355256faaa4..8d10499d59b 100644
--- a/plugins/woocommerce/tests/php/src/Internal/ProductFeed/Integrations/POSCatalog/POSProductVisibilitySyncTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/ProductFeed/Integrations/POSCatalog/POSProductVisibilitySyncTest.php
@@ -200,7 +200,6 @@ class POSProductVisibilitySyncTest extends \WC_Unit_Test_Case {
// Try to set hidden again (no change).
add_action( 'woocommerce_update_product_variation', array( $mock_callback, 'save' ) );
$this->sut->set_product_pos_visibility( $product->get_id(), false );
- remove_action( 'woocommerce_update_product_variation', array( $mock_callback, 'save' ) );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Internal/ProductFeed/Storage/JsonFileFeedTest.php b/plugins/woocommerce/tests/php/src/Internal/ProductFeed/Storage/JsonFileFeedTest.php
index 75b50ed8165..6310ab14248 100644
--- a/plugins/woocommerce/tests/php/src/Internal/ProductFeed/Storage/JsonFileFeedTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/ProductFeed/Storage/JsonFileFeedTest.php
@@ -311,14 +311,10 @@ class JsonFileFeedTest extends \WC_Unit_Test_Case {
};
add_filter( 'upload_dir', $upload_dir_filter );
- try {
- $this->assertSame(
- 'https://current.example/uploads/product-feeds/feed%20name.json',
- JsonFileFeed::get_file_url_for_identifier( 'feed name.json' )
- );
- } finally {
- remove_filter( 'upload_dir', $upload_dir_filter );
- }
+ $this->assertSame(
+ 'https://current.example/uploads/product-feeds/feed%20name.json',
+ JsonFileFeed::get_file_url_for_identifier( 'feed name.json' )
+ );
}
/**
@@ -353,14 +349,10 @@ class JsonFileFeedTest extends \WC_Unit_Test_Case {
};
add_filter( 'upload_dir', $response_upload_dir_filter );
- try {
- $this->assertStringStartsWith(
- 'https://generation.example/uploads/product-feeds/',
- (string) $feed->get_file_url()
- );
- } finally {
- remove_filter( 'upload_dir', $response_upload_dir_filter );
- }
+ $this->assertStringStartsWith(
+ 'https://generation.example/uploads/product-feeds/',
+ (string) $feed->get_file_url()
+ );
}
/**
@@ -449,20 +441,16 @@ class JsonFileFeedTest extends \WC_Unit_Test_Case {
$broken_method = fn() => 'this-method-does-not-exist';
add_filter( 'filesystem_method', $broken_method );
- try {
- $feed = new JsonFileFeed( 'test-feed' );
- $feed->start();
- $feed->end();
- $feed->get_file_url();
+ $feed = new JsonFileFeed( 'test-feed' );
+ $feed->start();
+ $feed->end();
+ $feed->get_file_url();
- $this->assertSame(
- 'Options -Indexes',
- trim( (string) file_get_contents( $directory . '/.htaccess' ) ),
- 'The .htaccess refresh must succeed without a usable WP_Filesystem.'
- );
- } finally {
- remove_filter( 'filesystem_method', $broken_method );
- }
+ $this->assertSame(
+ 'Options -Indexes',
+ trim( (string) file_get_contents( $directory . '/.htaccess' ) ),
+ 'The .htaccess refresh must succeed without a usable WP_Filesystem.'
+ );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Internal/ProductFilters/FilterDataTest.php b/plugins/woocommerce/tests/php/src/Internal/ProductFilters/FilterDataTest.php
index 8170f597281..2a7a1763dae 100644
--- a/plugins/woocommerce/tests/php/src/Internal/ProductFilters/FilterDataTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/ProductFilters/FilterDataTest.php
@@ -206,7 +206,6 @@ class FilterDataTest extends AbstractProductFiltersTest {
update_option( 'woocommerce_product_lookup_table_is_generating', '1' );
$this->test_get_stock_status_counts_with( new \WP_Query( array( 'post_type' => 'product' ) ) );
- delete_option( 'woocommerce_product_lookup_table_is_generating' );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Internal/PushNotifications/Controllers/PushTokenRestControllerTest.php b/plugins/woocommerce/tests/php/src/Internal/PushNotifications/Controllers/PushTokenRestControllerTest.php
index e0c12785c44..8c9b82069cf 100644
--- a/plugins/woocommerce/tests/php/src/Internal/PushNotifications/Controllers/PushTokenRestControllerTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/PushNotifications/Controllers/PushTokenRestControllerTest.php
@@ -1081,19 +1081,15 @@ class PushTokenRestControllerTest extends WC_Unit_Test_Case {
add_filter( 'pre_delete_post', '__return_false' );
- try {
- $request = new WP_REST_Request( 'DELETE', '/wc-push-notifications/push-tokens/' . $token_id );
- $response = $this->server->dispatch( $request );
+ $request = new WP_REST_Request( 'DELETE', '/wc-push-notifications/push-tokens/' . $token_id );
+ $response = $this->server->dispatch( $request );
- $this->assertEquals( WP_Http::INTERNAL_SERVER_ERROR, $response->get_status() );
+ $this->assertEquals( WP_Http::INTERNAL_SERVER_ERROR, $response->get_status() );
- $data = $response->get_data();
+ $data = $response->get_data();
- $this->assertEquals( 'woocommerce_internal_error', $data['code'] );
- $this->assertEquals( 'Internal server error', $data['message'] );
- } finally {
- remove_filter( 'pre_delete_post', '__return_false' );
- }
+ $this->assertEquals( 'woocommerce_internal_error', $data['code'] );
+ $this->assertEquals( 'Internal server error', $data['message'] );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Internal/PushNotifications/Controllers/StepLogRestControllerTest.php b/plugins/woocommerce/tests/php/src/Internal/PushNotifications/Controllers/StepLogRestControllerTest.php
index 3681f35e739..39ec11397eb 100644
--- a/plugins/woocommerce/tests/php/src/Internal/PushNotifications/Controllers/StepLogRestControllerTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/PushNotifications/Controllers/StepLogRestControllerTest.php
@@ -89,8 +89,6 @@ class StepLogRestControllerTest extends WC_Unit_Test_Case {
$server = $this->create_rest_server_with_routes( array( array( $this->sut, 'register_routes' ) ), true );
$this->assertContains( '/wc-push-notifications/step-logs/site', array_keys( $server->get_routes( 'wc-push-notifications' ) ) );
-
- remove_filter( 'pre_option_woocommerce_feature_push_notifications_enabled', fn() => 'no' );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Internal/PushNotifications/PushNotificationsTest.php b/plugins/woocommerce/tests/php/src/Internal/PushNotifications/PushNotificationsTest.php
index d1f6d57d43a..5f17aaf63fd 100644
--- a/plugins/woocommerce/tests/php/src/Internal/PushNotifications/PushNotificationsTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/PushNotifications/PushNotificationsTest.php
@@ -113,8 +113,6 @@ class PushNotificationsTest extends WC_Unit_Test_Case {
$push_notifications = new PushNotifications();
$this->assertFalse( $push_notifications->should_be_enabled() );
-
- remove_filter( 'woocommerce_enhanced_push_notifications_disabled', '__return_true' );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Internal/PushNotifications/Services/PendingNotificationStoreTest.php b/plugins/woocommerce/tests/php/src/Internal/PushNotifications/Services/PendingNotificationStoreTest.php
index 51861050e59..ba3c380b106 100644
--- a/plugins/woocommerce/tests/php/src/Internal/PushNotifications/Services/PendingNotificationStoreTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/PushNotifications/Services/PendingNotificationStoreTest.php
@@ -187,8 +187,6 @@ class PendingNotificationStoreTest extends WC_Unit_Test_Case {
$store->register();
$store->add( $this->create_order_mock( 42 ) );
-
- remove_filter( 'pre_as_schedule_single_action', '__return_zero' );
}
/**
@@ -358,8 +356,6 @@ class PendingNotificationStoreTest extends WC_Unit_Test_Case {
$store->add( $this->create_order_mock( 1 ) );
$store->dispatch_all();
-
- remove_action( 'shutdown', array( $store, 'dispatch_all' ) );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Internal/RestApi/Routes/V4/Products/ProductsControllerTest.php b/plugins/woocommerce/tests/php/src/Internal/RestApi/Routes/V4/Products/ProductsControllerTest.php
index ea0922ff8b6..74713d8fa2c 100644
--- a/plugins/woocommerce/tests/php/src/Internal/RestApi/Routes/V4/Products/ProductsControllerTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/RestApi/Routes/V4/Products/ProductsControllerTest.php
@@ -604,8 +604,6 @@ class ProductsControllerTest extends WC_Unit_Test_Case {
$this->assertEquals( $response_products[0]['sku'], 'pancake-2' );
$this->assertEquals( $response_products[1]['name'], 'Waffle 3' );
$this->assertEquals( $response_products[1]['sku'], 'waffle-3' );
-
- remove_filter( 'wc_product_sku_enabled', '__return_false' );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Internal/RestApi/Routes/V4/Settings/Tax/TaxControllerTest.php b/plugins/woocommerce/tests/php/src/Internal/RestApi/Routes/V4/Settings/Tax/TaxControllerTest.php
index 1d6ba7887b3..0c5e82dfb53 100644
--- a/plugins/woocommerce/tests/php/src/Internal/RestApi/Routes/V4/Settings/Tax/TaxControllerTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/RestApi/Routes/V4/Settings/Tax/TaxControllerTest.php
@@ -149,9 +149,6 @@ class TaxControllerTest extends WC_Unit_Test_Case {
* Test updating tax settings successfully.
*/
public function test_update_tax_settings_success() {
- // Arrange.
- $original_prices_include_tax = get_option( 'woocommerce_prices_include_tax', 'no' );
-
// Act.
$request = new WP_REST_Request( 'PUT', self::ENDPOINT );
$request->set_body(
@@ -187,19 +184,12 @@ class TaxControllerTest extends WC_Unit_Test_Case {
);
$this->assertSame( 'yes', $data['values']['woocommerce_prices_include_tax'] );
$this->assertSame( 'yes', get_option( 'woocommerce_prices_include_tax' ) );
-
- // Reset to original value.
- update_option( 'woocommerce_prices_include_tax', $original_prices_include_tax );
}
/**
* Test updating multiple tax settings at once.
*/
public function test_update_multiple_tax_settings() {
- // Arrange.
- $original_prices_include_tax = get_option( 'woocommerce_prices_include_tax', 'no' );
- $original_tax_based_on = get_option( 'woocommerce_tax_based_on', 'shipping' );
-
// Act.
$request = new WP_REST_Request( 'PUT', self::ENDPOINT );
$request->set_body(
@@ -245,19 +235,12 @@ class TaxControllerTest extends WC_Unit_Test_Case {
// Verify in the database.
$this->assertSame( 'yes', get_option( 'woocommerce_prices_include_tax' ) );
$this->assertSame( 'billing', get_option( 'woocommerce_tax_based_on' ) );
-
- // Reset to original values.
- update_option( 'woocommerce_prices_include_tax', $original_prices_include_tax );
- update_option( 'woocommerce_tax_based_on', $original_tax_based_on );
}
/**
* Test updating tax settings with the old format (backward compatibility).
*/
public function test_update_tax_settings_old_format() {
- // Arrange.
- $original_prices_include_tax = get_option( 'woocommerce_prices_include_tax', 'no' );
-
// Act - Use old format without 'values' wrapper.
$request = new WP_REST_Request( 'PUT', self::ENDPOINT );
$request->set_body(
@@ -291,9 +274,6 @@ class TaxControllerTest extends WC_Unit_Test_Case {
);
$this->assertSame( 'yes', $data['values']['woocommerce_prices_include_tax'] );
$this->assertSame( 'yes', get_option( 'woocommerce_prices_include_tax' ) );
-
- // Reset to original value.
- update_option( 'woocommerce_prices_include_tax', $original_prices_include_tax );
}
/**
@@ -392,9 +372,6 @@ class TaxControllerTest extends WC_Unit_Test_Case {
* Test that POST requests are accepted for updating tax settings (WP_REST_Server::EDITABLE).
*/
public function test_update_tax_settings_accepts_post() {
- // Arrange.
- $original_prices_include_tax = get_option( 'woocommerce_prices_include_tax', 'no' );
-
// Act.
$request = new WP_REST_Request( 'POST', self::ENDPOINT );
$request->set_body(
@@ -430,9 +407,6 @@ class TaxControllerTest extends WC_Unit_Test_Case {
);
$this->assertSame( 'yes', $data['values']['woocommerce_prices_include_tax'] );
$this->assertSame( 'yes', get_option( 'woocommerce_prices_include_tax' ) );
-
- // Reset to original value.
- update_option( 'woocommerce_prices_include_tax', $original_prices_include_tax );
}
/**
@@ -532,8 +506,6 @@ class TaxControllerTest extends WC_Unit_Test_Case {
*/
public function test_update_tax_settings_sanitizes_malicious_payloads() {
// Arrange.
- $original_suffix = get_option( 'woocommerce_price_display_suffix', '' );
-
// Test data with various malicious payloads using a text field that accepts any input.
$malicious_payloads = array(
'woocommerce_price_display_suffix' => '<script>alert("xss")</script> {price_including_tax} javascript:alert("xss") \' OR \'1\'=\'1 <img src=x onerror=alert("xss")>',
@@ -628,17 +600,13 @@ class TaxControllerTest extends WC_Unit_Test_Case {
);
}
}
-
- // Reset to original value.
- update_option( 'woocommerce_price_display_suffix', $original_suffix );
}
/**
* @testdox Should accept a valid value when a plugin filters options into the structured format.
*/
public function test_update_tax_settings_structured_options_accepts_valid_value() {
- $original = get_option( 'woocommerce_tax_based_on', 'shipping' );
- $callback = $this->filter_tax_based_on_options(
+ $this->filter_tax_based_on_options(
array(
array(
'value' => 'shipping',
@@ -670,9 +638,6 @@ class TaxControllerTest extends WC_Unit_Test_Case {
$this->assertSame( 200, $response->get_status(), 'Valid values should pass validation when options are in the structured format' );
$this->assertSame( 'base', get_option( 'woocommerce_tax_based_on' ) );
-
- remove_filter( 'woocommerce_tax_settings', $callback );
- update_option( 'woocommerce_tax_based_on', $original );
}
/**
@@ -680,7 +645,7 @@ class TaxControllerTest extends WC_Unit_Test_Case {
*/
public function test_update_tax_settings_structured_options_rejects_numeric_index() {
$original = get_option( 'woocommerce_tax_based_on', 'shipping' );
- $callback = $this->filter_tax_based_on_options(
+ $this->filter_tax_based_on_options(
array(
array(
'value' => 'shipping',
@@ -715,16 +680,13 @@ class TaxControllerTest extends WC_Unit_Test_Case {
$this->assertStringContainsString( 'invalid_param', $data['code'] );
$this->assertStringContainsString( 'shipping, billing, base', $data['message'], 'Error message should list the real option values, not numeric indexes' );
$this->assertSame( $original, get_option( 'woocommerce_tax_based_on', 'shipping' ) );
-
- remove_filter( 'woocommerce_tax_settings', $callback );
}
/**
* @testdox Should validate each option entry by its own format when formats are mixed.
*/
public function test_update_tax_settings_mixed_format_options() {
- $original = get_option( 'woocommerce_tax_based_on', 'shipping' );
- $callback = $this->filter_tax_based_on_options(
+ $this->filter_tax_based_on_options(
array(
array(
'value' => 'shipping',
@@ -751,9 +713,6 @@ class TaxControllerTest extends WC_Unit_Test_Case {
$this->assertSame( 200, $response->get_status(), "Value '$value' should pass validation with mixed format options" );
$this->assertSame( $value, get_option( 'woocommerce_tax_based_on' ) );
}
-
- remove_filter( 'woocommerce_tax_settings', $callback );
- update_option( 'woocommerce_tax_based_on', $original );
}
/**
@@ -761,7 +720,7 @@ class TaxControllerTest extends WC_Unit_Test_Case {
* filtering 'woocommerce_tax_settings' can do.
*
* @param array $options Replacement options for the setting.
- * @return callable The registered filter callback, so tests can remove it.
+ * @return callable The registered filter callback.
*/
private function filter_tax_based_on_options( array $options ): callable {
$callback = function ( $settings ) use ( $options ) {
diff --git a/plugins/woocommerce/tests/php/src/Internal/StockNotifications/Admin/SettingsControllerTests.php b/plugins/woocommerce/tests/php/src/Internal/StockNotifications/Admin/SettingsControllerTests.php
index f66062f9712..f579d75ac31 100644
--- a/plugins/woocommerce/tests/php/src/Internal/StockNotifications/Admin/SettingsControllerTests.php
+++ b/plugins/woocommerce/tests/php/src/Internal/StockNotifications/Admin/SettingsControllerTests.php
@@ -265,8 +265,6 @@ class SettingsControllerTests extends \WC_Settings_Unit_Test_Case {
$this->assertSame( 0, $field['value'] );
$this->assertSame( 0, $field['custom_attributes']['min'] );
-
- delete_option( $option_id );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Internal/Tax/ShopBaseTaxEstimateNoticeTest.php b/plugins/woocommerce/tests/php/src/Internal/Tax/ShopBaseTaxEstimateNoticeTest.php
index e407ce3522f..6a0e36d4c2e 100644
--- a/plugins/woocommerce/tests/php/src/Internal/Tax/ShopBaseTaxEstimateNoticeTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/Tax/ShopBaseTaxEstimateNoticeTest.php
@@ -293,14 +293,10 @@ class ShopBaseTaxEstimateNoticeTest extends WC_Unit_Test_Case {
};
add_filter( 'woocommerce_matched_rates', $break_rates );
- try {
- $notice = $this->sut->get_notice();
+ $notice = $this->sut->get_notice();
- $this->assertStringContainsString( 'your store base address', $notice['estimate'] );
- $this->assertStringContainsString( 'Standard rate: –', $notice['estimate'] );
- } finally {
- remove_filter( 'woocommerce_matched_rates', $break_rates );
- }
+ $this->assertStringContainsString( 'your store base address', $notice['estimate'] );
+ $this->assertStringContainsString( 'Standard rate: –', $notice['estimate'] );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Internal/Traits/RestApiCacheTest.php b/plugins/woocommerce/tests/php/src/Internal/Traits/RestApiCacheTest.php
index 7ec984d95b4..76ae6e0058e 100644
--- a/plugins/woocommerce/tests/php/src/Internal/Traits/RestApiCacheTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/Traits/RestApiCacheTest.php
@@ -166,8 +166,6 @@ class RestApiCacheTest extends WC_Unit_Test_Case {
$response3 = $this->query_endpoint( 'with_endpoint_hooks' );
$this->assertCacheHeader( $response3, 'MISS' );
-
- remove_filter( 'test_endpoint_hook_for_caching', '__return_true' );
}
/**
@@ -188,8 +186,6 @@ class RestApiCacheTest extends WC_Unit_Test_Case {
$response3 = $this->query_endpoint( 'with_controller_hooks' );
$this->assertCacheHeader( $response3, 'MISS' );
-
- remove_filter( 'test_controller_hook_for_caching', '__return_false' );
}
/**
@@ -293,8 +289,6 @@ class RestApiCacheTest extends WC_Unit_Test_Case {
$response = $this->query_endpoint( 'single_entity' );
$this->assertCacheHeader( $response, 'SKIP' );
$this->assertCount( 0, $this->get_all_cache_keys() );
-
- remove_all_filters( 'woocommerce_rest_api_enable_response_caching' );
}
/**
@@ -393,8 +387,6 @@ class RestApiCacheTest extends WC_Unit_Test_Case {
$this->assertTrue( $filter_called, 'Filter should have been called' );
$this->assertCacheHeader( $response2, 'MISS' );
$this->assertCount( 2, $this->get_all_cache_keys() );
-
- remove_all_filters( 'woocommerce_rest_api_cache_key_info' );
}
/**
@@ -688,8 +680,6 @@ class RestApiCacheTest extends WC_Unit_Test_Case {
$this->assertArrayHasKey( 'X-Header-One', $headers );
$this->assertArrayNotHasKey( 'X-Header-Two', $headers, 'Filtered header should not be restored' );
$this->assertArrayHasKey( 'X-Header-Three', $headers );
-
- remove_filter( 'woocommerce_rest_api_cached_headers', $filter_callback, 10 );
}
/**
@@ -783,8 +773,6 @@ class RestApiCacheTest extends WC_Unit_Test_Case {
$this->assertStringNotContainsString( 'no-cache', $headers['Cache-Control'], 'Original no-cache value should not be in Cache-Control' );
$this->assertStringContainsString( 'max-age', $headers['Cache-Control'], 'Our generated Cache-Control should contain max-age' );
$this->assertArrayHasKey( 'X-Custom-Header', $headers );
-
- remove_filter( 'woocommerce_rest_api_cached_headers', $filter_callback, 10 );
}
/**
@@ -802,8 +790,6 @@ class RestApiCacheTest extends WC_Unit_Test_Case {
$this->setExpectedIncorrectUsage( 'Automattic\WooCommerce\Internal\Traits\RestApiCache::get_headers_to_cache' );
$this->query_endpoint( 'standard' );
-
- remove_filter( 'woocommerce_rest_api_cached_headers', $filter_callback, 10 );
}
/**
@@ -1483,8 +1469,6 @@ class RestApiCacheTest extends WC_Unit_Test_Case {
$this->assertSame( 200, $response2->get_status() );
$this->assertNotNull( $response2->get_data() );
$this->assertCacheHeader( $response2, 'HEADERS' );
-
- remove_filter( 'woocommerce_rest_api_not_modified_response', $filter, 10 );
}
/**
@@ -1516,8 +1500,6 @@ class RestApiCacheTest extends WC_Unit_Test_Case {
$headers = $response2->get_headers();
$this->assertArrayHasKey( 'X-Custom-Header', $headers );
$this->assertSame( 'custom-value', $headers['X-Custom-Header'] );
-
- remove_filter( 'woocommerce_rest_api_not_modified_response', $filter, 10 );
}
/**
@@ -1554,8 +1536,6 @@ class RestApiCacheTest extends WC_Unit_Test_Case {
$this->assertSame( 200, $response3->get_status() );
$this->assertNotNull( $response3->get_data() );
$this->assertCacheHeader( $response3, 'HIT' );
-
- remove_filter( 'woocommerce_rest_api_not_modified_response', $filter, 10 );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Internal/TransientFiles/TransientFilesEngineTest.php b/plugins/woocommerce/tests/php/src/Internal/TransientFiles/TransientFilesEngineTest.php
index f23b3cd09a8..7c3aa1a8498 100644
--- a/plugins/woocommerce/tests/php/src/Internal/TransientFiles/TransientFilesEngineTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/TransientFiles/TransientFilesEngineTest.php
@@ -271,11 +271,7 @@ class TransientFilesEngineTest extends \WC_REST_Unit_Test_Case {
$this->expectException( \Exception::class );
$this->expectExceptionMessage( "The base transient files directory doesn't exist: foobar_dir" );
- try {
- $this->sut->get_transient_files_directory();
- } finally {
- remove_all_filters( 'woocommerce_transient_files_directory' );
- }
+ $this->sut->get_transient_files_directory();
}
/**
@@ -367,11 +363,7 @@ class TransientFilesEngineTest extends \WC_REST_Unit_Test_Case {
$this->expectException( \Exception::class );
$this->expectExceptionMessage( "The base transient files directory doesn't exist: $missing_dir" );
- try {
- $this->sut->get_transient_files_directory();
- } finally {
- remove_all_filters( 'woocommerce_transient_files_directory' );
- }
+ $this->sut->get_transient_files_directory();
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Internal/Utilities/FilesystemUtilTest.php b/plugins/woocommerce/tests/php/src/Internal/Utilities/FilesystemUtilTest.php
index 91cf596c9ba..e8ccf760e70 100644
--- a/plugins/woocommerce/tests/php/src/Internal/Utilities/FilesystemUtilTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/Utilities/FilesystemUtilTest.php
@@ -108,8 +108,6 @@ class FilesystemUtilTest extends WC_Unit_Test_Case {
add_filter( 'filesystem_method', $callback );
$this->assertInstanceOf( WP_Filesystem_Base::class, FilesystemUtil::get_wp_filesystem() );
-
- remove_filter( 'filesystem_method', $callback );
}
/**
@@ -122,8 +120,6 @@ class FilesystemUtilTest extends WC_Unit_Test_Case {
add_filter( 'filesystem_method', $callback );
FilesystemUtil::get_wp_filesystem();
-
- remove_filter( 'filesystem_method', $callback );
}
/**
@@ -598,7 +594,6 @@ class FilesystemUtilTest extends WC_Unit_Test_Case {
);
} finally {
$this->delete_test_dir( $dir );
- remove_filter( 'filesystem_method', $callback );
}
}
@@ -623,7 +618,6 @@ class FilesystemUtilTest extends WC_Unit_Test_Case {
);
} finally {
$this->delete_test_dir( $dir );
- remove_filter( 'filesystem_method', $callback );
}
}
@@ -652,7 +646,6 @@ class FilesystemUtilTest extends WC_Unit_Test_Case {
);
} finally {
$this->delete_test_dir( $dir );
- remove_filter( 'filesystem_method', $callback );
}
}
diff --git a/plugins/woocommerce/tests/php/src/Utilities/CallbackUtilTest.php b/plugins/woocommerce/tests/php/src/Utilities/CallbackUtilTest.php
index fd14792f9a7..66f74604b1c 100644
--- a/plugins/woocommerce/tests/php/src/Utilities/CallbackUtilTest.php
+++ b/plugins/woocommerce/tests/php/src/Utilities/CallbackUtilTest.php
@@ -293,8 +293,6 @@ class CallbackUtilTest extends \WC_Unit_Test_Case {
$this->assertCount( 1, $signatures[20] );
$this->assertContains( DummyCallbackClass::class . '::static_method', $signatures[20] );
-
- remove_all_actions( $hook_name );
}
/**
@@ -322,8 +320,6 @@ class CallbackUtilTest extends \WC_Unit_Test_Case {
foreach ( $signatures[10] as $signature ) {
$this->assertStringStartsWith( 'Closure@', $signature );
}
-
- remove_all_actions( $hook_name );
}
/**
@@ -345,8 +341,6 @@ class CallbackUtilTest extends \WC_Unit_Test_Case {
DummyInvokableClass::class . '::__invoke',
$signatures[10][0]
);
-
- remove_all_actions( $hook_name );
}
/**
@@ -373,8 +367,6 @@ class CallbackUtilTest extends \WC_Unit_Test_Case {
DummyCallbackClassWithDynamicProps::class . '::my_method',
$signatures1[10][0]
);
-
- remove_all_actions( $hook_name );
}
/**
@@ -406,8 +398,6 @@ class CallbackUtilTest extends \WC_Unit_Test_Case {
$this->assertSame( $first, $second );
$this->assertSame( '__return_true', $first[10][0] );
-
- remove_all_actions( $hook_name );
}
/**
@@ -425,8 +415,6 @@ class CallbackUtilTest extends \WC_Unit_Test_Case {
$this->assertArrayNotHasKey( 30, $before );
$this->assertArrayHasKey( 30, $after );
$this->assertSame( '__return_false', $after[30][0] );
-
- remove_all_actions( $hook_name );
}
/**
@@ -444,8 +432,6 @@ class CallbackUtilTest extends \WC_Unit_Test_Case {
$this->assertArrayHasKey( 10, $after );
$this->assertArrayNotHasKey( 30, $after );
-
- remove_all_actions( $hook_name );
}
/**
@@ -466,8 +452,6 @@ class CallbackUtilTest extends \WC_Unit_Test_Case {
$this->assertSame( DummyCallbackClass::class . '::my_method', $before[10][0] );
$this->assertSame( AnotherDummyCallbackClass::class . '::my_method', $after[10][0] );
-
- remove_all_actions( $hook_name );
}
/**
@@ -504,8 +488,6 @@ class CallbackUtilTest extends \WC_Unit_Test_Case {
$this->assertSame( CallbackUtil::get_callback_signature( $first ), $before[10][0] );
$this->assertSame( CallbackUtil::get_callback_signature( $second ), $after[10][0] );
$this->assertNotSame( $before[10][0], $after[10][0] );
-
- remove_all_actions( $hook_name );
}
/**
@@ -536,8 +518,6 @@ class CallbackUtilTest extends \WC_Unit_Test_Case {
$this->assertStringStartsWith( 'Closure@', $before[10][0] );
$this->assertStringStartsWith( 'Closure@', $after[10][0] );
$this->assertNotSame( $before[10][0], $after[10][0] );
-
- remove_all_actions( $hook_name );
}
/**
@@ -566,7 +546,5 @@ class CallbackUtilTest extends \WC_Unit_Test_Case {
$this->assertCount( 2, $signatures[10] );
$this->assertNotSame( $signatures[10][0], $signatures[10][1] );
$this->assertSame( $signatures, CallbackUtil::get_hook_callback_signatures( $hook_name ) );
-
- remove_all_actions( $hook_name );
}
}
diff --git a/plugins/woocommerce/tests/php/templates/single-product/SingleProductMetaTemplateTest.php b/plugins/woocommerce/tests/php/templates/single-product/SingleProductMetaTemplateTest.php
index a52e86e69d3..995493162fd 100644
--- a/plugins/woocommerce/tests/php/templates/single-product/SingleProductMetaTemplateTest.php
+++ b/plugins/woocommerce/tests/php/templates/single-product/SingleProductMetaTemplateTest.php
@@ -122,20 +122,16 @@ class SingleProductMetaTemplateTest extends WC_Unit_Test_Case {
};
add_filter( 'woocommerce_product_meta_category_orderby', $orderby_filter );
- try {
- $expected = implode(
- ', ',
- array( $this->category_names['leaf'], $this->category_names['mid'], $this->category_names['root'] )
- );
+ $expected = implode(
+ ', ',
+ array( $this->category_names['leaf'], $this->category_names['mid'], $this->category_names['root'] )
+ );
- $this->assertStringContainsString(
- 'Categories: ' . $expected,
- wp_strip_all_tags( wc_get_template_html( 'single-product/meta.php' ) ),
- 'Single product meta should honor the filtered product category ordering mode.'
- );
- } finally {
- remove_filter( 'woocommerce_product_meta_category_orderby', $orderby_filter );
- }
+ $this->assertStringContainsString(
+ 'Categories: ' . $expected,
+ wp_strip_all_tags( wc_get_template_html( 'single-product/meta.php' ) ),
+ 'Single product meta should honor the filtered product category ordering mode.'
+ );
}
/**