Commit b21199c41b4 for woocommerce
commit b21199c41b4225eeb6ff632541b5a7391979bd76
Author: Vlad Olaru <vlad.olaru@automattic.com>
Date: Wed Nov 11 09:57:38 2026 +0200
[tests] Drop per-class $_SERVER, customer and Constants restores the base test case now covers (#70830)
* test: Drop per-class $_SERVER restores the base test case now covers
WC_Unit_Test_Case saves all of $_SERVER at the end of setUp() and puts
it back in tearDown() (#69738), so a class that saves a key itself and
restores it later repeats that work. #69639 removes the REQUEST_URI
copies; these are the other keys: HTTPS, SERVER_PORT, REMOTE_ADDR,
forwarding headers, REQUEST_METHOD, HTTP_CART_TOKEN, QUERY_STRING and
whole-array snapshots.
Each class changes $_SERVER after parent::setUp(), so the base saves
the clean value, and nothing later in the same test reads the restored
one. Drop the saved properties and locals, the restores in tearDown()
and in the finally blocks that end a test, and the tearDown()
overrides left with only the parent call (SessionHandlerTest,
WC_Admin_Test). Unsets that set up the next assertion stay.
WC_WCCOM_Site_Test is left for #69639, which edits the same key list.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* test: Drop per-class customer restores the base test case now covers
WC_Unit_Test_Case keeps the WC()->customer it saw at setUp() and that
customer's id, data, change set, meta, VAT exemption and
calculated-shipping flag, and puts all of it back in tearDown()
(#69738). Classes that still save the customer, or some of its
fields, and restore them afterwards repeat that work, and some do it
only in part: WC_Cart_Test's coupon test put back the billing country
but not the shipping one it also changed.
Drop those saves and restores: whole-customer swaps put back in
tearDown() or in a finally block that ends the test, billing and
shipping country restores, VAT exemption resets, and the fresh
customer WC_Checkout_Test rebuilt in tearDown() only for the base to
replace it. Setters that give a test the address it needs stay, and so
do WC()->session swaps and session data resets, which the base does
not restore.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* test: Drop notice, cart, locale and Constants resets the base covers
WC_Unit_Test_Case already clears notices, empties the cart, empties
the country locale cache and puts back Constants overrides after every
test. A few classes still did the same in tearDown(), or as the last
statement of a test, or in a finally block that ends one:
- notices: WC_Form_Handler_Test, OrderWithdrawalTest,
MyAccountEndpointTests, MyAccountPromptTest, the Hydration test
and WC_Cart_Test (through the wc_notices session key)
- cart: the linked products meta box test, which emptied the throwaway
cart it then replaced with the original
- locale: WC_Checkout_Test
- Constants: AnalyticsTest's REST and WP-CLI context tests
The clears in setUp() and in the middle of a test stay: they reset
state before the step that follows.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
diff --git a/plugins/woocommerce/changelog/test-drop-base-covered-restores b/plugins/woocommerce/changelog/test-drop-base-covered-restores
new file mode 100644
index 00000000000..8916b48ce45
--- /dev/null
+++ b/plugins/woocommerce/changelog/test-drop-base-covered-restores
@@ -0,0 +1,3 @@
+Significance: patch
+Type: dev
+Comment: Remove per-class test cleanup that WC_Unit_Test_Case now does; no production change.
diff --git a/plugins/woocommerce/tests/legacy/unit-tests/cart/cart.php b/plugins/woocommerce/tests/legacy/unit-tests/cart/cart.php
index 55890b2c09a..ffa3cdffb30 100644
--- a/plugins/woocommerce/tests/legacy/unit-tests/cart/cart.php
+++ b/plugins/woocommerce/tests/legacy/unit-tests/cart/cart.php
@@ -12,15 +12,6 @@ use Automattic\WooCommerce\Enums\ProductTaxStatus;
*/
class WC_Tests_Cart extends WC_Unit_Test_Case {
- /**
- * tearDown.
- */
- public function tearDown(): void {
- parent::tearDown();
-
- WC()->customer->set_is_vat_exempt( false );
- }
-
/**
* Test whether totals are correct when discount is applied.
*/
diff --git a/plugins/woocommerce/tests/legacy/unit-tests/geolocation/class-wc-test-gelocation.php b/plugins/woocommerce/tests/legacy/unit-tests/geolocation/class-wc-test-gelocation.php
index a0cf7815fdd..c740996e002 100644
--- a/plugins/woocommerce/tests/legacy/unit-tests/geolocation/class-wc-test-gelocation.php
+++ b/plugins/woocommerce/tests/legacy/unit-tests/geolocation/class-wc-test-gelocation.php
@@ -47,7 +47,6 @@ class WC_Tests_Geolocation extends WC_Unit_Test_Case {
$this->assertEquals( '2620:0:ccc::2', WC_Geolocation::get_ip_address() );
$_SERVER['REMOTE_ADDR'] = '2620:0:ccc::2, 2001:4860:4860::8888';
$this->assertEquals( '2620:0:ccc::2', WC_Geolocation::get_ip_address() );
- unset( $_SERVER['REMOTE_ADDR'] );
}
/**
diff --git a/plugins/woocommerce/tests/legacy/unit-tests/totals/totals.php b/plugins/woocommerce/tests/legacy/unit-tests/totals/totals.php
index 9599bab8a96..8114eb17d1f 100644
--- a/plugins/woocommerce/tests/legacy/unit-tests/totals/totals.php
+++ b/plugins/woocommerce/tests/legacy/unit-tests/totals/totals.php
@@ -120,8 +120,6 @@ class WC_Tests_Totals extends WC_Unit_Test_Case {
WC_Helper_Shipping::delete_simple_flat_rate();
remove_action( 'woocommerce_cart_calculate_fees', array( $this, 'add_cart_fees_callback' ) );
- WC()->customer->set_is_vat_exempt( false );
-
parent::tearDown();
}
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 74620178c8c..d5d4141ee6a 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
@@ -19,13 +19,6 @@ class WC_Admin_Test extends WC_Unit_Test_Case {
*/
private WC_Admin $sut;
- /**
- * Original $_SERVER, or null when setUp did not get as far as capturing it.
- *
- * @var array<string,mixed>|null
- */
- private ?array $original_server = null;
-
/**
* The My Account page this test creates, so the redirect target is a real page.
*
@@ -40,10 +33,6 @@ class WC_Admin_Test extends WC_Unit_Test_Case {
parent::setUp();
$this->sut = new WC_Admin();
- // $_SERVER is the one request global the base class leaves alone: it only resets
- // it for core's own suite, which never runs here.
- $this->original_server = $_SERVER;
-
// Without a real My Account page, wc_get_page_permalink() falls back to the home URL and
// the redirect assertions cannot tell My Account from the site root.
$this->myaccount_page_id = self::factory()->post->create(
@@ -59,21 +48,6 @@ class WC_Admin_Test extends WC_Unit_Test_Case {
add_filter( 'wp_redirect', array( $this, 'intercept_redirect' ) );
}
- /**
- * Tear down test fixtures.
- */
- public function tearDown(): void {
- // PHPUnit runs tearDown whenever checkRequirements() passed, whether or not
- // setUp finished, so an unconditional restore would blank $_SERVER for the
- // rest of the process if setUp threw before the capture below it. Nothing
- // puts it back: the base class only resets $_SERVER for core's own suite.
- if ( null !== $this->original_server ) {
- $_SERVER = $this->original_server;
- }
-
- parent::tearDown();
- }
-
/**
* Intercepts redirects so the tested handler's trailing exit does not run.
*
diff --git a/plugins/woocommerce/tests/php/includes/admin/meta-boxes/class-wc-meta-box-product-data-linked-products-test.php b/plugins/woocommerce/tests/php/includes/admin/meta-boxes/class-wc-meta-box-product-data-linked-products-test.php
index 6889f29003c..91e8d5ee2fe 100644
--- a/plugins/woocommerce/tests/php/includes/admin/meta-boxes/class-wc-meta-box-product-data-linked-products-test.php
+++ b/plugins/woocommerce/tests/php/includes/admin/meta-boxes/class-wc-meta-box-product-data-linked-products-test.php
@@ -66,10 +66,6 @@ class WC_Meta_Box_Product_Data_Linked_Products_Test extends WC_Unit_Test_Case {
*/
public function tearDown(): void {
try {
- if ( WC()->cart ) {
- WC()->cart->empty_cart();
- }
-
wp_reset_postdata();
wc_reset_loop();
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 3879cd5f148..f7408e24286 100644
--- a/plugins/woocommerce/tests/php/includes/class-wc-cart-test.php
+++ b/plugins/woocommerce/tests/php/includes/class-wc-cart-test.php
@@ -37,9 +37,6 @@ class WC_Cart_Test extends \WC_Unit_Test_Case {
public function tearDown(): void {
parent::tearDown();
- WC()->customer->set_is_vat_exempt( false );
- WC()->session->set( 'wc_notices', null );
-
// The checkout fields may have been built while a test's filters were attached.
$this->clear_checkout_fields();
@@ -1684,54 +1681,48 @@ class WC_Cart_Test extends \WC_Unit_Test_Case {
WC_Tax::_insert_tax_rate( $tax_rate );
- // Rates are only ever found for a customer with a country, and the customer object
- // carries whatever address the test before this one left on it.
- $previous_billing_country = WC()->customer->get_billing_country();
+ // Rates are only ever found for a customer with a country.
WC()->customer->set_shipping_country( 'GB' );
WC()->customer->set_billing_country( 'GB' );
- try {
- // Create a product to add to cart.
- $product = WC_Helper_Product::create_simple_product();
- $product->set_regular_price( 100 );
- $product->save();
+ // Create a product to add to cart.
+ $product = WC_Helper_Product::create_simple_product();
+ $product->set_regular_price( 100 );
+ $product->save();
- // Create a coupon with uppercase code.
- $coupon = WC_Helper_Coupon::create_coupon( 'TESTCOUPON123' );
- $coupon->set_discount_type( 'fixed_cart' );
- $coupon->set_amount( 10 );
- $coupon->save();
+ // Create a coupon with uppercase code.
+ $coupon = WC_Helper_Coupon::create_coupon( 'TESTCOUPON123' );
+ $coupon->set_discount_type( 'fixed_cart' );
+ $coupon->set_amount( 10 );
+ $coupon->save();
- // Add product to cart.
- WC()->cart->add_to_cart( $product->get_id(), 1 );
- WC()->cart->calculate_totals();
+ // Add product to cart.
+ WC()->cart->add_to_cart( $product->get_id(), 1 );
+ WC()->cart->calculate_totals();
- // Apply the coupon using lowercase code.
- $applied = WC()->cart->apply_coupon( 'testcoupon123' );
- $this->assertTrue( $applied, 'Coupon should be applied successfully with lowercase code' );
+ // Apply the coupon using lowercase code.
+ $applied = WC()->cart->apply_coupon( 'testcoupon123' );
+ $this->assertTrue( $applied, 'Coupon should be applied successfully with lowercase code' );
- // Verify the coupon is in applied coupons (should be stored in original case).
- $applied_coupons = WC()->cart->get_applied_coupons();
- $this->assertContains( 'testcoupon123', $applied_coupons, 'Coupon should be stored in provided case' );
+ // Verify the coupon is in applied coupons (should be stored in original case).
+ $applied_coupons = WC()->cart->get_applied_coupons();
+ $this->assertContains( 'testcoupon123', $applied_coupons, 'Coupon should be stored in provided case' );
- // Test get_coupon_discount_amount with lowercase code.
- $discount_amount = WC()->cart->get_coupon_discount_amount( 'testcoupon123' );
- $this->assertEquals( 10.00, $discount_amount, 'get_coupon_discount_amount should return correct value with lowercase code' );
+ // Test get_coupon_discount_amount with lowercase code.
+ $discount_amount = WC()->cart->get_coupon_discount_amount( 'testcoupon123' );
+ $this->assertEquals( 10.00, $discount_amount, 'get_coupon_discount_amount should return correct value with lowercase code' );
- // Test get_coupon_discount_amount with uppercase code.
- $discount_amount_upper = WC()->cart->get_coupon_discount_amount( 'TESTCOUPON123' );
- $this->assertEquals( 10.00, $discount_amount_upper, 'get_coupon_discount_amount should return correct value with uppercase code' );
+ // Test get_coupon_discount_amount with uppercase code.
+ $discount_amount_upper = WC()->cart->get_coupon_discount_amount( 'TESTCOUPON123' );
+ $this->assertEquals( 10.00, $discount_amount_upper, 'get_coupon_discount_amount should return correct value with uppercase code' );
- // Test get_coupon_discount_tax_amount with lowercase code.
- $tax_amount = WC()->cart->get_coupon_discount_tax_amount( 'testcoupon123' );
- $this->assertEquals( 2.00, $tax_amount, 'get_coupon_discount_tax_amount should return correct value with lowercase code' );
+ // Test get_coupon_discount_tax_amount with lowercase code.
+ $tax_amount = WC()->cart->get_coupon_discount_tax_amount( 'testcoupon123' );
+ $this->assertEquals( 2.00, $tax_amount, 'get_coupon_discount_tax_amount should return correct value with lowercase code' );
- // Test get_coupon_discount_tax_amount with uppercase code.
- $tax_amount_upper = WC()->cart->get_coupon_discount_tax_amount( 'TESTCOUPON123' );
- $this->assertEquals( 2.00, $tax_amount_upper, 'get_coupon_discount_tax_amount should return correct value with uppercase code' );
- } finally {
- WC()->customer->set_billing_country( $previous_billing_country );
- }
+ // Test get_coupon_discount_tax_amount with uppercase code.
+ $tax_amount_upper = WC()->cart->get_coupon_discount_tax_amount( 'TESTCOUPON123' );
+ $this->assertEquals( 2.00, $tax_amount_upper, 'get_coupon_discount_tax_amount should return correct value with uppercase code' );
}
/**
diff --git a/plugins/woocommerce/tests/php/includes/class-wc-cart-totals-test.php b/plugins/woocommerce/tests/php/includes/class-wc-cart-totals-test.php
index 6268109e80f..5b39baec208 100644
--- a/plugins/woocommerce/tests/php/includes/class-wc-cart-totals-test.php
+++ b/plugins/woocommerce/tests/php/includes/class-wc-cart-totals-test.php
@@ -13,20 +13,6 @@ class WC_Cart_Totals_Tests extends WC_Unit_Test_Case {
*/
private $shipping_was_enabled;
- /**
- * Customer billing country before the test.
- *
- * @var string
- */
- private $previous_billing_country;
-
- /**
- * Customer shipping country before the test.
- *
- * @var string
- */
- private $previous_shipping_country;
-
/**
* Set up non-shipping cart total tests.
*/
@@ -38,10 +24,7 @@ class WC_Cart_Totals_Tests extends WC_Unit_Test_Case {
// The tax rates these tests insert have no country of their own, and
// WC_Tax::find_rates() finds nothing for a customer whose taxable address has no
- // country. WC()->customer outlives a test, so set a country here instead of reading
- // whatever the test before left on it.
- $this->previous_billing_country = WC()->customer->get_billing_country();
- $this->previous_shipping_country = WC()->customer->get_shipping_country();
+ // country, so give the customer one.
WC()->customer->set_billing_country( 'US' );
WC()->customer->set_shipping_country( 'US' );
}
@@ -50,9 +33,6 @@ class WC_Cart_Totals_Tests extends WC_Unit_Test_Case {
* tearDown.
*/
public function tearDown(): void {
- WC()->customer->set_billing_country( $this->previous_billing_country );
- WC()->customer->set_shipping_country( $this->previous_shipping_country );
-
parent::tearDown();
WC()->shipping()->enabled = $this->shipping_was_enabled;
}
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 f226ef6984f..5afcab99a32 100644
--- a/plugins/woocommerce/tests/php/includes/class-wc-checkout-test.php
+++ b/plugins/woocommerce/tests/php/includes/class-wc-checkout-test.php
@@ -57,16 +57,6 @@ class WC_Checkout_Test extends \WC_Unit_Test_Case {
*/
private $original_session;
- /**
- * @var WC_Customer|null The customer the test base installed, put back after a test ran a full checkout into a fresh one.
- */
- private $original_session_customer;
-
- /**
- * @var array The customer's location and VAT exemption before each test, restored on tear down.
- */
- private $original_customer = array();
-
/**
* Runs before each test.
*/
@@ -106,9 +96,6 @@ class WC_Checkout_Test extends \WC_Unit_Test_Case {
WC()->cart->empty_cart();
- $customer = WC()->customer;
- $this->original_customer = array( $customer->get_billing_country(), $customer->get_billing_state(), $customer->get_shipping_country(), $customer->get_shipping_state(), $customer->get_is_vat_exempt() );
-
add_filter( 'woocommerce_checkout_registration_enabled', '__return_true' );
}
@@ -118,7 +105,6 @@ class WC_Checkout_Test extends \WC_Unit_Test_Case {
public function tearDown(): void {
remove_filter( 'woocommerce_checkout_registration_enabled', '__return_true' );
delete_option( 'woocommerce_calc_taxes' );
- WC()->countries->locale = array();
foreach ( $this->extra_field_filters as $extra_field_filter ) {
remove_filter( 'woocommerce_checkout_fields', $extra_field_filter );
@@ -127,20 +113,12 @@ class WC_Checkout_Test extends \WC_Unit_Test_Case {
$this->extra_field_filters = array();
if ( $this->original_session ) {
- WC()->session = $this->original_session;
- WC()->customer = $this->original_session_customer;
- $this->original_session = null;
- $this->original_session_customer = null;
+ WC()->session = $this->original_session;
+ $this->original_session = null;
}
wp_set_current_user( 0 );
WC()->session->set( 'customer', null );
- WC()->customer = new WC_Customer( 0, true );
-
- $customer = WC()->customer;
- $customer->set_billing_location( $this->original_customer[0], $this->original_customer[1] );
- $customer->set_shipping_location( $this->original_customer[2], $this->original_customer[3] );
- $customer->set_is_vat_exempt( $this->original_customer[4] );
WC_Helper_Shipping::delete_simple_flat_rate();
parent::tearDown();
@@ -287,30 +265,24 @@ class WC_Checkout_Test extends \WC_Unit_Test_Case {
wp_set_current_user( $customer_id );
WC()->session->init();
- $original_customer = WC()->customer;
- WC()->customer = new WC_Customer( $customer_id, true );
-
- try {
- WC()->customer->set_is_vat_exempt( true );
- WC()->customer->save();
+ WC()->customer = new WC_Customer( $customer_id, true );
+ WC()->customer->set_is_vat_exempt( true );
+ WC()->customer->save();
- $this->sut->process_customer(
- array(
- 'billing_first_name' => 'Classic',
- 'billing_address_1' => '456 Classic Road',
- 'billing_email' => 'classic-vat-exempt@example.com',
- )
- );
+ $this->sut->process_customer(
+ array(
+ 'billing_first_name' => 'Classic',
+ 'billing_address_1' => '456 Classic Road',
+ 'billing_email' => 'classic-vat-exempt@example.com',
+ )
+ );
- // The session customer is saved on shutdown in a real request.
- WC()->customer->save();
+ // The session customer is saved on shutdown in a real request.
+ WC()->customer->save();
- $reloaded_customer = new WC_Customer( $customer_id, true );
- $this->assertTrue( $reloaded_customer->get_is_vat_exempt(), 'VAT exemption should survive the account save so a retry is not charged tax.' );
- $this->assertSame( '456 Classic Road', $reloaded_customer->get_billing_address_1(), 'The address should come from the saved account.' );
- } finally {
- WC()->customer = $original_customer;
- }
+ $reloaded_customer = new WC_Customer( $customer_id, true );
+ $this->assertTrue( $reloaded_customer->get_is_vat_exempt(), 'VAT exemption should survive the account save so a retry is not charged tax.' );
+ $this->assertSame( '456 Classic Road', $reloaded_customer->get_billing_address_1(), 'The address should come from the saved account.' );
}
/**
@@ -594,8 +566,6 @@ class WC_Checkout_Test extends \WC_Unit_Test_Case {
* country rules, so this also pins that no country is assumed when the customer can't supply one.
*/
public function test_validate_posted_data_does_not_throw_without_a_customer_object() {
- $original_customer = WC()->customer;
-
WC()->customer = null;
$data = array(
@@ -605,11 +575,7 @@ class WC_Checkout_Test extends \WC_Unit_Test_Case {
$errors = new WP_Error();
- try {
- $this->sut->validate_posted_data( $data, $errors );
- } finally {
- WC()->customer = $original_customer;
- }
+ $this->sut->validate_posted_data( $data, $errors );
$this->assertEmpty(
$errors->get_error_message( 'billing_postcode_validation' ),
@@ -621,8 +587,6 @@ class WC_Checkout_Test extends \WC_Unit_Test_Case {
* @testdox 'validate_posted_data' prefers the posted country over the one stored on the customer.
*/
public function test_validate_posted_data_prefers_the_posted_country() {
- $original_billing_country = WC()->customer->get_billing_country();
-
WC()->customer->set_billing_country( 'GB' );
$data = array(
@@ -633,11 +597,7 @@ class WC_Checkout_Test extends \WC_Unit_Test_Case {
$errors = new WP_Error();
- try {
- $this->sut->validate_posted_data( $data, $errors );
- } finally {
- WC()->customer->set_billing_country( $original_billing_country );
- }
+ $this->sut->validate_posted_data( $data, $errors );
$this->assertEmpty(
$errors->get_error_message( 'billing_postcode_validation' ),
@@ -660,9 +620,6 @@ class WC_Checkout_Test extends \WC_Unit_Test_Case {
public function test_validate_posted_data_falls_back_to_the_customer_country( $fieldset_key, $customer_country, $expect_error ) {
add_filter( 'woocommerce_cart_needs_shipping_address', '__return_true' );
- $original_billing_country = WC()->customer->get_billing_country();
- $original_shipping_country = WC()->customer->get_shipping_country();
-
WC()->customer->set_billing_country( $customer_country );
WC()->customer->set_shipping_country( $customer_country );
@@ -677,8 +634,6 @@ class WC_Checkout_Test extends \WC_Unit_Test_Case {
try {
$this->sut->validate_posted_data( $data, $errors );
} finally {
- WC()->customer->set_billing_country( $original_billing_country );
- WC()->customer->set_shipping_country( $original_shipping_country );
remove_filter( 'woocommerce_cart_needs_shipping_address', '__return_true' );
}
@@ -1208,12 +1163,9 @@ class WC_Checkout_Test extends \WC_Unit_Test_Case {
public function test_get_value_no_error_on_null_customer() {
$sut = WC_Checkout::instance();
- $orig_customer = WC()->customer;
WC()->customer = null;
$this->assertNull( $sut->get_value( 'billing_country' ) );
-
- WC()->customer = $orig_customer;
}
/**
@@ -2997,11 +2949,10 @@ class WC_Checkout_Test extends \WC_Unit_Test_Case {
/**
* Swap the test base's in-memory session for a real handler, which is what process_order_payment() needs (it calls save_data()).
*
- * The customer is swapped too, because a full checkout writes the posted address into it and nothing else resets that singleton.
+ * The customer is swapped for a fresh one too, because a full checkout writes the posted address into it.
*/
private function use_real_session(): void {
- $this->original_session = WC()->session;
- $this->original_session_customer = WC()->customer;
+ $this->original_session = WC()->session;
WC()->session = new WC_Session_Handler();
WC()->session->init();
diff --git a/plugins/woocommerce/tests/php/includes/class-wc-form-handler-test.php b/plugins/woocommerce/tests/php/includes/class-wc-form-handler-test.php
index eb18b8ca0af..4cec4e95319 100644
--- a/plugins/woocommerce/tests/php/includes/class-wc-form-handler-test.php
+++ b/plugins/woocommerce/tests/php/includes/class-wc-form-handler-test.php
@@ -82,7 +82,6 @@ class WC_Form_Handler_Test extends WC_Unit_Test_Case {
$_REQUEST = $this->original_request;
wp_set_current_user( 0 );
- wc_clear_notices();
WC()->session = $this->original_session;
foreach ( $this->registered_checkout_fields as $field_id ) {
diff --git a/plugins/woocommerce/tests/php/includes/class-wc-no-default-location-test.php b/plugins/woocommerce/tests/php/includes/class-wc-no-default-location-test.php
index ee2c5b92b41..5092fc2c5b8 100644
--- a/plugins/woocommerce/tests/php/includes/class-wc-no-default-location-test.php
+++ b/plugins/woocommerce/tests/php/includes/class-wc-no-default-location-test.php
@@ -18,13 +18,6 @@ use Automattic\WooCommerce\Enums\DefaultCustomerAddress;
*/
class WC_No_Default_Location_Test extends WC_Unit_Test_Case {
- /**
- * The session customer to restore, since the tests replace it.
- *
- * @var WC_Customer
- */
- private $original_customer;
-
/**
* Turn taxes on, put a US rate in place, and a cart with a taxable product, so "no tax quoted"
* is a real outcome rather than the result of taxes being off or an empty cart.
@@ -55,9 +48,8 @@ class WC_No_Default_Location_Test extends WC_Unit_Test_Case {
WC()->cart->add_to_cart( $product->get_id(), 1 );
// new WC_Customer( 0, true ) in the tests reads the shared session, so an address a
- // previous test left there would decide the result. Save the customer to restore it, and
- // start from an empty session customer so the outcome is the setting's doing.
- $this->original_customer = WC()->customer;
+ // previous test left there would decide the result. Start from an empty session
+ // customer so the outcome is the setting's doing.
WC()->session->set( 'customer', null );
}
@@ -66,7 +58,6 @@ class WC_No_Default_Location_Test extends WC_Unit_Test_Case {
*/
public function tearDown(): void {
WC()->session->set( 'customer', null );
- WC()->customer = $this->original_customer;
parent::tearDown();
}
diff --git a/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version3/class-wc-rest-paypal-standard-controller-test.php b/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version3/class-wc-rest-paypal-standard-controller-test.php
index ea599b85a85..5e11e65dd32 100644
--- a/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version3/class-wc-rest-paypal-standard-controller-test.php
+++ b/plugins/woocommerce/tests/php/includes/rest-api/Controllers/Version3/class-wc-rest-paypal-standard-controller-test.php
@@ -43,13 +43,6 @@ class WC_REST_Paypal_Standard_Controller_Test extends WC_REST_Unit_Test_Case {
*/
private $order;
- /**
- * Customer before the test; the endpoint replaces WC()->customer.
- *
- * @var WC_Customer|null
- */
- private $previous_customer;
-
/**
* Session before the test; the endpoint may replace WC()->session.
*
@@ -70,8 +63,7 @@ class WC_REST_Paypal_Standard_Controller_Test extends WC_REST_Unit_Test_Case {
public function setUp(): void {
parent::setUp();
- $this->previous_customer = WC()->customer;
- $this->previous_session = WC()->session;
+ $this->previous_session = WC()->session;
$this->product_order_item_meta_id = null;
@@ -109,8 +101,7 @@ class WC_REST_Paypal_Standard_Controller_Test extends WC_REST_Unit_Test_Case {
* Restore the customer and session replaced by the endpoint.
*/
public function tearDown(): void {
- WC()->customer = $this->previous_customer;
- WC()->session = $this->previous_session;
+ WC()->session = $this->previous_session;
remove_filter( 'woocommerce_shipping_legacy_flat_rate_is_available', array( $this, 'disable_legacy_flat_rate_shipping' ), 99999 );
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 c2a9c5299fe..fa36c3d130f 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
@@ -299,7 +299,6 @@ class WC_REST_Authentication_Tests extends WC_REST_Unit_Test_Case {
$this->assertEquals( 1, $this->sut->authenticate( false ), 'The same key must authenticate once WordPress is dispatching the request as REST.' );
} finally {
$wpdb->delete( $wpdb->prefix . 'woocommerce_api_keys', array( 'consumer_key' => wc_api_hash( $consumer_key ) ) );
- unset( $_SERVER['HTTPS'], $_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'] );
}
}
@@ -592,9 +591,6 @@ class WC_REST_Authentication_Tests extends WC_REST_Unit_Test_Case {
public function test_reject_out_of_scope_route_rejects_method_override_to_foreign_route(): void {
global $wp;
- // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.ValidatedSanitizedInput.MissingUnslash -- Saved and restored verbatim, never output or stored.
- $original_method = $_SERVER['REQUEST_METHOD'] ?? null;
-
// The scope check ignores the HTTP method, including a '_method' override in the query string,
// and only compares the resolved route to the one the URI names. A resolved route the URI never
// named is rejected either way.
@@ -604,18 +600,10 @@ class WC_REST_Authentication_Tests extends WC_REST_Unit_Test_Case {
$this->authenticate_as( 1 );
- try {
- $result = $this->sut->reject_out_of_scope_route( null );
+ $result = $this->sut->reject_out_of_scope_route( null );
- $this->assertWPError( $result, 'A method override must not let a key reach a route the URI never named.' );
- $this->assertSame( 'woocommerce_rest_authentication_error', $result->get_error_code() );
- } finally {
- if ( null === $original_method ) {
- unset( $_SERVER['REQUEST_METHOD'] );
- } else {
- $_SERVER['REQUEST_METHOD'] = $original_method;
- }
- }
+ $this->assertWPError( $result, 'A method override must not let a key reach a route the URI never named.' );
+ $this->assertSame( 'woocommerce_rest_authentication_error', $result->get_error_code() );
}
/**
@@ -659,7 +647,6 @@ class WC_REST_Authentication_Tests extends WC_REST_Unit_Test_Case {
$this->assertSame( 401, $result->get_error_data()['status'] );
} finally {
$wpdb->delete( $wpdb->prefix . 'woocommerce_api_keys', array( 'consumer_key' => wc_api_hash( $consumer_key ) ) );
- unset( $_SERVER['HTTPS'], $_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'] );
wp_set_current_user( 0 );
}
}
@@ -707,7 +694,6 @@ class WC_REST_Authentication_Tests extends WC_REST_Unit_Test_Case {
$this->assertTrue( $authenticated, 'The fallback must still authenticate a genuine WooCommerce route.' );
} finally {
$wpdb->delete( $wpdb->prefix . 'woocommerce_api_keys', array( 'consumer_key' => wc_api_hash( $consumer_key ) ) );
- unset( $_SERVER['HTTPS'], $_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'] );
wp_set_current_user( 0 );
}
}
@@ -758,7 +744,6 @@ class WC_REST_Authentication_Tests extends WC_REST_Unit_Test_Case {
} finally {
remove_filter( 'rest_authentication_errors', '__return_true', 5 );
$wpdb->delete( $wpdb->prefix . 'woocommerce_api_keys', array( 'consumer_key' => wc_api_hash( $consumer_key ) ) );
- unset( $_SERVER['HTTPS'], $_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'] );
wp_set_current_user( 0 );
}
}
@@ -814,7 +799,6 @@ class WC_REST_Authentication_Tests extends WC_REST_Unit_Test_Case {
} finally {
$wp_rest_application_password_status = $original_status;
$wpdb->delete( $wpdb->prefix . 'woocommerce_api_keys', array( 'consumer_key' => wc_api_hash( $consumer_key ) ) );
- unset( $_SERVER['HTTPS'], $_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'] );
wp_set_current_user( 0 );
}
}
diff --git a/plugins/woocommerce/tests/php/includes/wc-order-step-logger-functions-test.php b/plugins/woocommerce/tests/php/includes/wc-order-step-logger-functions-test.php
index 5f6dba261b4..d932dca511a 100644
--- a/plugins/woocommerce/tests/php/includes/wc-order-step-logger-functions-test.php
+++ b/plugins/woocommerce/tests/php/includes/wc-order-step-logger-functions-test.php
@@ -16,13 +16,6 @@ use Automattic\WooCommerce\Utilities\OrderUtil;
*/
class WC_Order_Step_Logger_Functions_Test extends \WC_Unit_Test_Case {
- /**
- * Original REQUEST_METHOD value to restore after tests.
- *
- * @var string|null
- */
- private $original_request_method;
-
/**
* Whether HPOS was in use before a test changed the order storage, or null if it did not.
*
@@ -39,10 +32,7 @@ class WC_Order_Step_Logger_Functions_Test extends \WC_Unit_Test_Case {
// Clean up any previous log files.
$this->clean_up_log_files();
- // Save the original REQUEST_METHOD and set it to POST for the test.
- // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.ValidatedSanitizedInput.MissingUnslash -- Test setup, not user input.
- $this->original_request_method = $_SERVER['REQUEST_METHOD'] ?? null;
- $_SERVER['REQUEST_METHOD'] = 'POST';
+ $_SERVER['REQUEST_METHOD'] = 'POST';
}
/**
@@ -60,13 +50,6 @@ class WC_Order_Step_Logger_Functions_Test extends \WC_Unit_Test_Case {
// Reset logging settings.
delete_option( 'woocommerce_logs_level_threshold' );
- // Restore the original REQUEST_METHOD.
- if ( null === $this->original_request_method ) {
- unset( $_SERVER['REQUEST_METHOD'] );
- } else {
- $_SERVER['REQUEST_METHOD'] = $this->original_request_method;
- }
-
parent::tearDown();
}
diff --git a/plugins/woocommerce/tests/php/src/Admin/API/MobileAppQRLoginTest.php b/plugins/woocommerce/tests/php/src/Admin/API/MobileAppQRLoginTest.php
index 4e151696587..4bbd43b8271 100644
--- a/plugins/woocommerce/tests/php/src/Admin/API/MobileAppQRLoginTest.php
+++ b/plugins/woocommerce/tests/php/src/Admin/API/MobileAppQRLoginTest.php
@@ -136,40 +136,6 @@ class MobileAppQRLoginTest extends WC_Unit_Test_Case {
*/
private $subscriber_id;
- /**
- * Original value of $_SERVER['HTTPS'] (if any) before each test.
- *
- * @var string|null
- */
- private $original_https;
-
- /**
- * Original value of $_SERVER['SERVER_PORT'] (if any) before each test.
- *
- * Captured alongside HTTPS because `is_ssl()` returns true when
- * SERVER_PORT === '443', regardless of the HTTPS header.
- *
- * @var string|null
- */
- private $original_server_port;
-
- /**
- * Original value of $_SERVER['HTTP_X_FORWARDED_PROTO'] (if any) before each test.
- *
- * Some hosts and reverse-proxy plugins use this header to derive scheme,
- * so we normalize it across tests to keep `is_ssl()` deterministic.
- *
- * @var string|null
- */
- private $original_http_x_forwarded_proto;
-
- /**
- * Original value of $_SERVER['REMOTE_ADDR'] (if any) before each test.
- *
- * @var string|null
- */
- private $original_remote_addr;
-
/**
* Filters registered via force_site_url() so tearDown() can remove them.
*
@@ -204,14 +170,6 @@ class MobileAppQRLoginTest extends WC_Unit_Test_Case {
$this->shop_manager_id = self::$fixture_shop_manager_id;
$this->subscriber_id = self::$fixture_subscriber_id;
- // Remember existing $_SERVER values so we can restore them in tearDown.
- // phpcs:disable WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Unit-test fixture: values are captured for restoration only, never used for processing.
- $this->original_https = isset( $_SERVER['HTTPS'] ) ? (string) $_SERVER['HTTPS'] : null;
- $this->original_server_port = isset( $_SERVER['SERVER_PORT'] ) ? (string) $_SERVER['SERVER_PORT'] : null;
- $this->original_http_x_forwarded_proto = isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) ? (string) $_SERVER['HTTP_X_FORWARDED_PROTO'] : null;
- $this->original_remote_addr = isset( $_SERVER['REMOTE_ADDR'] ) ? (string) $_SERVER['REMOTE_ADDR'] : null;
- // phpcs:enable WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
-
// Default to HTTPS on for most tests; disable explicitly where needed.
$this->force_https( true );
@@ -239,33 +197,6 @@ class MobileAppQRLoginTest extends WC_Unit_Test_Case {
// Clear any QR login data the tests may have written.
$this->delete_all_qr_login_data();
- // Restore $_SERVER state.
- if ( null === $this->original_https ) {
- unset( $_SERVER['HTTPS'] );
- } else {
- $_SERVER['HTTPS'] = $this->original_https;
- }
-
- if ( null === $this->original_server_port ) {
- unset( $_SERVER['SERVER_PORT'] );
- } else {
- $_SERVER['SERVER_PORT'] = $this->original_server_port;
- }
-
- if ( null === $this->original_http_x_forwarded_proto ) {
- unset( $_SERVER['HTTP_X_FORWARDED_PROTO'] );
- } else {
- $_SERVER['HTTP_X_FORWARDED_PROTO'] = $this->original_http_x_forwarded_proto;
- }
-
- if ( null === $this->original_remote_addr ) {
- unset( $_SERVER['REMOTE_ADDR'] );
- } else {
- $_SERVER['REMOTE_ADDR'] = $this->original_remote_addr;
- }
-
- unset( $_SERVER['HTTP_X_FORWARDED_FOR'] );
-
// Remove any pre_option_siteurl filters force_site_url() registered.
foreach ( $this->site_url_filters as $priority => $filter ) {
remove_filter( 'pre_option_siteurl', $filter, $priority );
diff --git a/plugins/woocommerce/tests/php/src/Blocks/Domain/Services/Hydration.php b/plugins/woocommerce/tests/php/src/Blocks/Domain/Services/Hydration.php
index 856d734696c..4d88296f048 100644
--- a/plugins/woocommerce/tests/php/src/Blocks/Domain/Services/Hydration.php
+++ b/plugins/woocommerce/tests/php/src/Blocks/Domain/Services/Hydration.php
@@ -158,7 +158,5 @@ class Hydration extends \WC_Unit_Test_Case {
has_filter( 'woocommerce_store_api_disable_nonce_check', array( $this->sut, 'disable_nonce_check_callback' ) ),
'Hydration must re-enable the nonce check even when dispatching throws.'
);
-
- wc_clear_notices();
}
}
diff --git a/plugins/woocommerce/tests/php/src/Blocks/Shipping/ShippingControllerTest.php b/plugins/woocommerce/tests/php/src/Blocks/Shipping/ShippingControllerTest.php
index 7a4ab2dc517..e463e3801ec 100644
--- a/plugins/woocommerce/tests/php/src/Blocks/Shipping/ShippingControllerTest.php
+++ b/plugins/woocommerce/tests/php/src/Blocks/Shipping/ShippingControllerTest.php
@@ -812,16 +812,11 @@ class ShippingControllerTest extends \WC_Unit_Test_Case {
$this->shopper_is_on_the_block_checkout();
update_option( 'woocommerce_shipping_cost_requires_address', 'yes' );
- $customer = WC()->customer;
WC()->customer = null;
- try {
- $packages = $this->shipping_controller->remove_shipping_if_no_address(
- array( $this->package_offering( array( 'flat_rate:1', 'pickup_location:0' ) ) )
- );
- } finally {
- WC()->customer = $customer;
- }
+ $packages = $this->shipping_controller->remove_shipping_if_no_address(
+ array( $this->package_offering( array( 'flat_rate:1', 'pickup_location:0' ) ) )
+ );
$this->assertSame(
array( 'pickup_location:0' ),
diff --git a/plugins/woocommerce/tests/php/src/Blocks/StoreApi/RateLimitsTests.php b/plugins/woocommerce/tests/php/src/Blocks/StoreApi/RateLimitsTests.php
index 84ddc78887a..c28c6a4ca37 100644
--- a/plugins/woocommerce/tests/php/src/Blocks/StoreApi/RateLimitsTests.php
+++ b/plugins/woocommerce/tests/php/src/Blocks/StoreApi/RateLimitsTests.php
@@ -263,34 +263,28 @@ class RateLimitsTests extends \WC_Unit_Test_Case {
* @throws ReflectionException On failing invoked private method through reflection class.
*/
public function test_is_only_post_request_method( string $method, ?string $override, bool $expected ) {
- $original_server = $_SERVER;
+ $authentication = new ReflectionClass( Authentication::class );
+ $is_only_post_request = $authentication->getMethod( 'is_only_post_request' );
+ $authentication_instance = $authentication->newInstance();
+ $is_only_post_request->setAccessible( true );
- try {
- $authentication = new ReflectionClass( Authentication::class );
- $is_only_post_request = $authentication->getMethod( 'is_only_post_request' );
- $authentication_instance = $authentication->newInstance();
- $is_only_post_request->setAccessible( true );
+ $_SERVER['REQUEST_METHOD'] = $method;
- $_SERVER['REQUEST_METHOD'] = $method;
-
- if ( null === $override ) {
- unset( $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'] );
- } else {
- $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'] = $override;
- }
-
- $this->assertSame(
- $expected,
- $is_only_post_request->invoke( $authentication_instance ),
- sprintf(
- 'is_only_post_request() should return %s for REQUEST_METHOD=%s with override=%s',
- $expected ? 'true' : 'false',
- $method,
- $override ?? 'null'
- )
- );
- } finally {
- $_SERVER = $original_server;
+ if ( null === $override ) {
+ unset( $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'] );
+ } else {
+ $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'] = $override;
}
+
+ $this->assertSame(
+ $expected,
+ $is_only_post_request->invoke( $authentication_instance ),
+ sprintf(
+ 'is_only_post_request() should return %s for REQUEST_METHOD=%s with override=%s',
+ $expected ? 'true' : 'false',
+ $method,
+ $override ?? 'null'
+ )
+ );
}
}
diff --git a/plugins/woocommerce/tests/php/src/Blocks/StoreApi/SessionHandlerTest.php b/plugins/woocommerce/tests/php/src/Blocks/StoreApi/SessionHandlerTest.php
index 1f893be44ff..3e5bcda09f5 100644
--- a/plugins/woocommerce/tests/php/src/Blocks/StoreApi/SessionHandlerTest.php
+++ b/plugins/woocommerce/tests/php/src/Blocks/StoreApi/SessionHandlerTest.php
@@ -31,14 +31,6 @@ class SessionHandlerTest extends WC_Unit_Test_Case {
$this->sut = new SessionHandler();
}
- /**
- * Tear down test fixtures.
- */
- public function tearDown(): void {
- unset( $_SERVER['HTTP_CART_TOKEN'] );
- parent::tearDown();
- }
-
/**
* @testdox SessionHandler extends WC_Session.
*/
diff --git a/plugins/woocommerce/tests/php/src/Blocks/Utils/UtilsTest.php b/plugins/woocommerce/tests/php/src/Blocks/Utils/UtilsTest.php
index a93f9d95729..25366dfce31 100644
--- a/plugins/woocommerce/tests/php/src/Blocks/Utils/UtilsTest.php
+++ b/plugins/woocommerce/tests/php/src/Blocks/Utils/UtilsTest.php
@@ -164,8 +164,6 @@ class UtilsTest extends WC_Unit_Test_Case {
global $wp, $wp_rewrite;
$original_request = $wp->request;
- $original_query_string_exists = array_key_exists( 'QUERY_STRING', $_SERVER ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
- $original_query_string = $_SERVER['QUERY_STRING'] ?? null; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.ValidatedSanitizedInput.MissingUnslash
$original_use_trailing_slashes = $wp_rewrite->use_trailing_slashes;
$original_permalink_structure = $wp_rewrite->permalink_structure;
@@ -185,12 +183,6 @@ class UtilsTest extends WC_Unit_Test_Case {
$wp->request = $original_request;
$wp_rewrite->use_trailing_slashes = $original_use_trailing_slashes;
$wp_rewrite->permalink_structure = $original_permalink_structure;
-
- if ( $original_query_string_exists ) {
- $_SERVER['QUERY_STRING'] = $original_query_string;
- } else {
- unset( $_SERVER['QUERY_STRING'] );
- }
}
}
diff --git a/plugins/woocommerce/tests/php/src/Checkout/Helpers/ReserveStockOwnHoldsTest.php b/plugins/woocommerce/tests/php/src/Checkout/Helpers/ReserveStockOwnHoldsTest.php
index c03fc4844eb..247c36b0a28 100644
--- a/plugins/woocommerce/tests/php/src/Checkout/Helpers/ReserveStockOwnHoldsTest.php
+++ b/plugins/woocommerce/tests/php/src/Checkout/Helpers/ReserveStockOwnHoldsTest.php
@@ -41,13 +41,6 @@ class ReserveStockOwnHoldsTest extends WC_Unit_Test_Case {
*/
private $original_session;
- /**
- * The customer the bootstrap set up, put back in tearDown.
- *
- * @var WC_Customer|null
- */
- private $original_customer;
-
/**
* $_COOKIE as it was before the test, put back in tearDown.
*
@@ -65,8 +58,7 @@ class ReserveStockOwnHoldsTest extends WC_Unit_Test_Case {
update_option( 'woocommerce_schema_version', 430 );
update_option( 'woocommerce_hold_stock_minutes', self::HOLD_MINUTES );
- $this->original_session = WC()->session;
- $this->original_customer = WC()->customer;
+ $this->original_session = WC()->session;
// Earlier suites can leave a valid session cookie in $_COOKIE (the test
// framework never resets it), and WC_Session_Handler::init() would then
@@ -94,9 +86,8 @@ class ReserveStockOwnHoldsTest extends WC_Unit_Test_Case {
wp_set_current_user( 0 );
- $_COOKIE = $this->original_cookies;
- WC()->session = $this->original_session;
- WC()->customer = $this->original_customer;
+ $_COOKIE = $this->original_cookies;
+ WC()->session = $this->original_session;
parent::tearDown();
}
diff --git a/plugins/woocommerce/tests/php/src/Internal/Admin/AnalyticsTest.php b/plugins/woocommerce/tests/php/src/Internal/Admin/AnalyticsTest.php
index 7351fb8aed7..04f064958c7 100644
--- a/plugins/woocommerce/tests/php/src/Internal/Admin/AnalyticsTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/Admin/AnalyticsTest.php
@@ -990,7 +990,6 @@ class AnalyticsTest extends WC_Unit_Test_Case {
'Admin footer action should not be registered in REST context.'
);
} finally {
- Constants::clear_single_constant( 'REST_REQUEST' );
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' ) );
@@ -1046,7 +1045,6 @@ class AnalyticsTest extends WC_Unit_Test_Case {
'Admin footer action should not be registered in WP-CLI context.'
);
} finally {
- Constants::clear_single_constant( 'WP_CLI' );
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' ) );
diff --git a/plugins/woocommerce/tests/php/src/Internal/CustomerEmailVerification/MyAccountPromptTest.php b/plugins/woocommerce/tests/php/src/Internal/CustomerEmailVerification/MyAccountPromptTest.php
index 603a1ba9c70..009f3e1edb2 100644
--- a/plugins/woocommerce/tests/php/src/Internal/CustomerEmailVerification/MyAccountPromptTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/CustomerEmailVerification/MyAccountPromptTest.php
@@ -49,7 +49,6 @@ class MyAccountPromptTest extends WC_Unit_Test_Case {
*/
public function tearDown(): void {
wp_set_current_user( 0 );
- wc_clear_notices();
$this->restore_option( 'woocommerce_enable_guest_checkout', $this->previous_guest_checkout_option );
parent::tearDown();
}
diff --git a/plugins/woocommerce/tests/php/src/Internal/OrderWithdrawal/OrderWithdrawalTest.php b/plugins/woocommerce/tests/php/src/Internal/OrderWithdrawal/OrderWithdrawalTest.php
index a737b7c09e3..cbfac24ec16 100644
--- a/plugins/woocommerce/tests/php/src/Internal/OrderWithdrawal/OrderWithdrawalTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/OrderWithdrawal/OrderWithdrawalTest.php
@@ -47,34 +47,6 @@ class OrderWithdrawalTest extends WC_Unit_Test_Case {
*/
private array $original_post = array();
- /**
- * Original REQUEST_METHOD value.
- *
- * @var string|null
- */
- private ?string $original_request_method = null;
-
- /**
- * Whether REQUEST_METHOD existed before the test.
- *
- * @var bool
- */
- private bool $had_request_method = false;
-
- /**
- * Original REMOTE_ADDR value.
- *
- * @var string|null
- */
- private ?string $original_remote_addr = null;
-
- /**
- * Whether REMOTE_ADDR existed before the test.
- *
- * @var bool
- */
- private bool $had_remote_addr = false;
-
/**
* Original WooCommerce session.
*
@@ -122,10 +94,6 @@ class OrderWithdrawalTest extends WC_Unit_Test_Case {
$this->sut = new OrderWithdrawalFormProcessor();
$this->original_post = $_POST; // phpcs:ignore WordPress.Security.NonceVerification.Missing
- $this->had_request_method = filter_has_var( INPUT_SERVER, 'REQUEST_METHOD' );
- $this->original_request_method = $this->had_request_method ? filter_input( INPUT_SERVER, 'REQUEST_METHOD', FILTER_SANITIZE_FULL_SPECIAL_CHARS ) : null;
- $this->had_remote_addr = array_key_exists( 'REMOTE_ADDR', $_SERVER );
- $this->original_remote_addr = $this->had_remote_addr ? sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ) : null;
$this->original_session = WC()->session;
$this->original_feature_option = get_option( self::FEATURE_OPTION, self::MISSING_OPTION_MARK );
$this->original_endpoint_option = get_option( OrderWithdrawalEndpoint::ENDPOINT_OPTION, self::MISSING_OPTION_MARK );
@@ -151,22 +119,9 @@ class OrderWithdrawalTest extends WC_Unit_Test_Case {
public function tearDown(): void {
$_POST = $this->original_post;
- if ( $this->had_request_method ) {
- $_SERVER['REQUEST_METHOD'] = (string) $this->original_request_method;
- } else {
- unset( $_SERVER['REQUEST_METHOD'] );
- }
-
- if ( $this->had_remote_addr ) {
- $_SERVER['REMOTE_ADDR'] = (string) $this->original_remote_addr;
- } else {
- unset( $_SERVER['REMOTE_ADDR'] );
- }
-
$this->restore_option( self::FEATURE_OPTION, $this->original_feature_option );
$this->restore_option( OrderWithdrawalEndpoint::ENDPOINT_OPTION, $this->original_endpoint_option );
$this->restore_option( self::FLUSH_QUEUE_OPTION, $this->original_flush_queue_option );
- wc_clear_notices();
$this->clear_order_withdrawal_rate_limits();
$this->delete_created_inbox_notes();
$this->delete_created_orders();
diff --git a/plugins/woocommerce/tests/php/src/Internal/StockNotifications/Frontend/MyAccountEndpointTests.php b/plugins/woocommerce/tests/php/src/Internal/StockNotifications/Frontend/MyAccountEndpointTests.php
index 3c80440b3fe..4e39581ea30 100644
--- a/plugins/woocommerce/tests/php/src/Internal/StockNotifications/Frontend/MyAccountEndpointTests.php
+++ b/plugins/woocommerce/tests/php/src/Internal/StockNotifications/Frontend/MyAccountEndpointTests.php
@@ -48,7 +48,6 @@ class MyAccountEndpointTests extends \WC_Unit_Test_Case {
public function tearDown(): void {
remove_filter( 'wp_redirect', array( $this, 'capture_redirect' ) );
$this->redirect_location = null;
- \wc_clear_notices();
\wp_set_current_user( 0 );
delete_option( MyAccountEndpoint::ENDPOINT_OPTION );
// phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
diff --git a/plugins/woocommerce/tests/php/src/Internal/StockNotifications/Frontend/SignupRateLimiterTests.php b/plugins/woocommerce/tests/php/src/Internal/StockNotifications/Frontend/SignupRateLimiterTests.php
index fad7013f19c..6fd33c69df3 100644
--- a/plugins/woocommerce/tests/php/src/Internal/StockNotifications/Frontend/SignupRateLimiterTests.php
+++ b/plugins/woocommerce/tests/php/src/Internal/StockNotifications/Frontend/SignupRateLimiterTests.php
@@ -12,23 +12,12 @@ use WC_Unit_Test_Case;
*/
class SignupRateLimiterTests extends WC_Unit_Test_Case {
- /**
- * The server values seen before the test replaced them.
- *
- * @var array<string, string|null>
- */
- private $original_server = array();
-
/**
* Set up test fixtures.
*/
public function setUp(): void {
parent::setUp();
- foreach ( array( 'REMOTE_ADDR', 'HTTP_X_FORWARDED_FOR' ) as $key ) {
- $this->original_server[ $key ] = isset( $_SERVER[ $key ] ) ? sanitize_text_field( wp_unslash( $_SERVER[ $key ] ) ) : null;
- }
-
$_SERVER['REMOTE_ADDR'] = '192.0.2.10';
unset( $_SERVER['HTTP_X_FORWARDED_FOR'] );
}
@@ -38,14 +27,6 @@ class SignupRateLimiterTests extends WC_Unit_Test_Case {
*/
public function tearDown(): void {
try {
- foreach ( $this->original_server as $key => $value ) {
- if ( null === $value ) {
- unset( $_SERVER[ $key ] );
- } else {
- $_SERVER[ $key ] = $value;
- }
- }
-
wp_set_current_user( 0 );
} finally {
parent::tearDown();
diff --git a/plugins/woocommerce/tests/php/src/Internal/StockNotifications/Frontend/SignupServiceTests.php b/plugins/woocommerce/tests/php/src/Internal/StockNotifications/Frontend/SignupServiceTests.php
index e52bb840928..8c8dccf98df 100644
--- a/plugins/woocommerce/tests/php/src/Internal/StockNotifications/Frontend/SignupServiceTests.php
+++ b/plugins/woocommerce/tests/php/src/Internal/StockNotifications/Frontend/SignupServiceTests.php
@@ -40,13 +40,6 @@ class SignupServiceTests extends \WC_Unit_Test_Case {
*/
private $email_manager;
- /**
- * The remote address seen before the test replaced it.
- *
- * @var string|null
- */
- private $original_remote_addr;
-
/**
* Set up test fixtures.
*/
@@ -54,8 +47,7 @@ class SignupServiceTests extends \WC_Unit_Test_Case {
parent::setUp();
$this->enable_stock_notifications_feature();
- $this->original_remote_addr = isset( $_SERVER['REMOTE_ADDR'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ) : null;
- $_SERVER['REMOTE_ADDR'] = '192.0.2.10';
+ $_SERVER['REMOTE_ADDR'] = '192.0.2.10';
update_option( 'woocommerce_customer_stock_notifications_allow_signups', 'yes' );
@@ -75,12 +67,6 @@ class SignupServiceTests extends \WC_Unit_Test_Case {
* Tear down test fixtures.
*/
public function tearDown(): void {
- if ( null === $this->original_remote_addr ) {
- unset( $_SERVER['REMOTE_ADDR'] );
- } else {
- $_SERVER['REMOTE_ADDR'] = $this->original_remote_addr;
- }
-
delete_option( 'woocommerce_customer_stock_notifications_allow_signups' );
delete_option( 'woocommerce_customer_stock_notifications_require_double_opt_in' );
delete_option( 'woocommerce_customer_stock_notifications_create_account_on_signup' );