Commit 538877cd66e for woocommerce

commit 538877cd66efffc371ce8b5a50a2e39e33ceee4f
Author: Christopher Hertel <mail@christopher-hertel.de>
Date:   Mon Nov 16 10:53:58 2026 +0100

    Speed up the Core abilities PHPUnit tests (#70946)

    * Speed up the Core abilities PHPUnit tests

    Cut the Internal\Abilities suite from about 28 s to 18-19 s locally
    (PHP 8.3 cell) without dropping any checked behaviour:

    - Test the rating-ranking cap against rank() directly instead of
      writing 203 products and reviews. The new case also catches a cap
      that keeps the first 200 entries, which the old fixture could not.
    - Build the OrdersQueryTest search and tied-paging fixtures once per
      storage and loop over the terms and sorts, instead of rebuilding
      them for each of 38 data sets.
    - Use wc_create_order() where a test only needs an order to exist,
      and drop orders from refusals that return before any lookup.
    - Share the acting user, and the reviewed product, per test class.

    * Trim AbilitiesLoaderTest fixtures and teardown

    The per-test teardown force-deleted every order and product the test
    created, which the parent teardown's transaction rollback already
    undoes. Orders-query sorting and filtering tests now build orders with
    wc_create_order(), and variation tests use one variation with a single
    global attribute instead of six variations across three taxonomies.

    * Restore the uncapped summary total check in the reviews query tests

    The ranking-cap rewrite dropped the end-to-end assertion that summary.total_products counts every reviewed product, not the 200 the ranking keeps. Bulk-inserted rows bring it back without the factory cost.

    * Keep the shared review product from queueing a lookup action

    ProductReviewReplyTest and ProductReviewUpdateTest create their shared
    product in wpSetUpBeforeClass(), outside any test transaction, so the
    save queued a product attribute lookup action that outlived the class.
    Create it with direct lookup updates on instead.

    Also name the shared users by role, matching AbilitiesLoaderTest.

diff --git a/plugins/woocommerce/changelog/tweak-abilities-test-fixtures b/plugins/woocommerce/changelog/tweak-abilities-test-fixtures
new file mode 100644
index 00000000000..c59bfd39908
--- /dev/null
+++ b/plugins/woocommerce/changelog/tweak-abilities-test-fixtures
@@ -0,0 +1,3 @@
+Significance: patch
+Type: dev
+Comment: Speed up the Core abilities PHPUnit tests with smaller and shared fixtures; tests only, no production change.
diff --git a/plugins/woocommerce/tests/php/src/Internal/Abilities/AbilitiesLoaderTest.php b/plugins/woocommerce/tests/php/src/Internal/Abilities/AbilitiesLoaderTest.php
index 010d0d7611c..aa0a1bce213 100644
--- a/plugins/woocommerce/tests/php/src/Internal/Abilities/AbilitiesLoaderTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/Abilities/AbilitiesLoaderTest.php
@@ -75,20 +75,6 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 	 */
 	private $registered_category_ids = array();

-	/**
-	 * Product IDs created by these tests.
-	 *
-	 * @var array
-	 */
-	private $created_product_ids = array();
-
-	/**
-	 * Order IDs created by these tests.
-	 *
-	 * @var array
-	 */
-	private $created_order_ids = array();
-
 	/**
 	 * Original action counts captured for restoration in tearDown.
 	 *
@@ -147,22 +133,6 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 	public function tearDown(): void {
 		global $wp_actions;

-		foreach ( $this->created_order_ids as $order_id ) {
-			$order = wc_get_order( $order_id );
-
-			if ( $order ) {
-				$order->delete( true );
-			}
-		}
-
-		foreach ( $this->created_product_ids as $product_id ) {
-			$product = wc_get_product( $product_id );
-
-			if ( $product ) {
-				$product->delete( true );
-			}
-		}
-
 		foreach ( $this->registered_ability_ids as $ability_id ) {
 			if ( wp_has_ability( $ability_id ) ) {
 				wp_unregister_ability( $ability_id );
@@ -706,9 +676,8 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 	 * @testdox Should refuse a status that another order type registers, and keep the order status.
 	 */
 	public function test_order_update_status_refuses_status_of_another_order_type(): void {
-		$order                     = \WC_Helper_Order::create_order();
-		$this->created_order_ids[] = $order->get_id();
-		$status_before             = $order->get_status();
+		$order         = wc_create_order();
+		$status_before = $order->get_status();

 		$this->unregister_domain_abilities();
 		register_post_status(
@@ -757,9 +726,8 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 	 * @testdox Should check the permission against the actual type of the order ID.
 	 */
 	public function test_orders_query_refuses_id_of_unsupported_order_type(): void {
-		$order                     = \WC_Helper_Order::create_order();
-		$this->created_order_ids[] = $order->get_id();
-		$refund                    = wc_create_refund(
+		$order  = \WC_Helper_Order::create_order();
+		$refund = wc_create_refund(
 			array(
 				'order_id' => $order->get_id(),
 				'amount'   => 1,
@@ -1245,11 +1213,9 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 	 * @testdox Should require object edit and delete permissions for product mutations.
 	 */
 	public function test_product_mutations_require_object_permissions(): void {
-		$product_to_update           = \WC_Helper_Product::create_simple_product( true, array( 'name' => 'Owned by another user' ) );
-		$product_to_delete           = \WC_Helper_Product::create_simple_product( true, array( 'name' => 'Also owned by another user' ) );
-		$this->created_product_ids[] = $product_to_update->get_id();
-		$this->created_product_ids[] = $product_to_delete->get_id();
-		$limited_product_manager_id  = $this->create_user_with_caps(
+		$product_to_update          = \WC_Helper_Product::create_simple_product( true, array( 'name' => 'Owned by another user' ) );
+		$product_to_delete          = \WC_Helper_Product::create_simple_product( true, array( 'name' => 'Also owned by another user' ) );
+		$limited_product_manager_id = $this->create_user_with_caps(
 			array(
 				'edit_products',
 				'edit_published_products',
@@ -1281,9 +1247,8 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 	 * @testdox Should require object edit permissions for order mutations.
 	 */
 	public function test_order_mutations_require_object_edit_permissions(): void {
-		$order                     = \WC_Helper_Order::create_order();
-		$this->created_order_ids[] = $order->get_id();
-		$limited_order_manager_id  = $this->create_user_with_caps(
+		$order                    = \WC_Helper_Order::create_order();
+		$limited_order_manager_id = $this->create_user_with_caps(
 			array(
 				'edit_shop_orders',
 				'edit_published_shop_orders',
@@ -1327,8 +1292,7 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 	 */
 	public function test_order_mutations_return_not_found_for_id_that_is_not_an_order( bool $hpos_enabled ): void {
 		$this->set_order_storage_for_test( $hpos_enabled );
-		$product                     = \WC_Helper_Product::create_simple_product();
-		$this->created_product_ids[] = $product->get_id();
+		$product = \WC_Helper_Product::create_simple_product();

 		foreach ( array( 999999, $product->get_id() ) as $id ) {
 			foreach ( $this->get_order_mutation_inputs( $id ) as $ability_id => $input ) {
@@ -1367,9 +1331,8 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 	 * @testdox Should refuse permission when an order mutation receives the ID of a refund.
 	 */
 	public function test_order_mutations_refuse_id_of_refund(): void {
-		$order                     = \WC_Helper_Order::create_order();
-		$this->created_order_ids[] = $order->get_id();
-		$refund                    = wc_create_refund(
+		$order  = \WC_Helper_Order::create_order();
+		$refund = wc_create_refund(
 			array(
 				'order_id' => $order->get_id(),
 				'amount'   => 1,
@@ -1401,8 +1364,7 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 				'add_order_meta_boxes'     => false,
 			)
 		);
-		$order                     = \WC_Helper_Order::create_order();
-		$this->created_order_ids[] = $order->get_id();
+		$order = wc_create_order();
 		$wpdb->update( $wpdb->posts, array( 'post_type' => 'shop_test_hidden' ), array( 'ID' => $order->get_id() ) );
 		$wpdb->update( OrdersTableDataStore::get_orders_table_name(), array( 'type' => 'shop_test_hidden' ), array( 'id' => $order->get_id() ) );
 		clean_post_cache( $order->get_id() );
@@ -1438,8 +1400,7 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 		global $wpdb;

 		$this->set_order_storage_for_test( true );
-		$order                     = \WC_Helper_Order::create_order();
-		$this->created_order_ids[] = $order->get_id();
+		$order = wc_create_order();
 		$wpdb->update( OrdersTableDataStore::get_orders_table_name(), array( 'type' => 'shop_test_unreg' ), array( 'id' => $order->get_id() ) );
 		wp_cache_flush();
 		add_filter(
@@ -1497,8 +1458,7 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 	 * @param string $status Product status.
 	 */
 	public function test_product_update_publish_transition_requires_publish_cap( string $status ): void {
-		$product                     = \WC_Helper_Product::create_simple_product( true, array( 'status' => 'draft' ) );
-		$this->created_product_ids[] = $product->get_id();
+		$product = \WC_Helper_Product::create_simple_product( true, array( 'status' => 'draft' ) );

 		$user_id = $this->factory->user->create( array( 'role' => 'subscriber' ) );
 		$user    = get_user_by( 'id', $user_id );
@@ -1522,8 +1482,7 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 	 * @testdox Should allow non-status updates to published products without publish_products.
 	 */
 	public function test_product_update_allows_published_product_edits_without_publish_cap_when_status_is_unchanged(): void {
-		$product                     = \WC_Helper_Product::create_simple_product( true, array( 'status' => 'publish' ) );
-		$this->created_product_ids[] = $product->get_id();
+		$product = \WC_Helper_Product::create_simple_product( true, array( 'status' => 'publish' ) );

 		$user_id = $this->factory->user->create( array( 'role' => 'subscriber' ) );
 		$user    = get_user_by( 'id', $user_id );
@@ -1567,8 +1526,7 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 	 * @testdox Should reject order status updates with an unknown status slug.
 	 */
 	public function test_order_update_status_rejects_invalid_status_slug(): void {
-		$order                     = \WC_Helper_Order::create_order();
-		$this->created_order_ids[] = $order->get_id();
+		$order = wc_create_order();

 		$result = wp_get_ability( 'woocommerce/order-update-status' )->execute(
 			array(
@@ -1606,7 +1564,6 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 		$result = wp_get_ability( 'woocommerce/product-create' )->execute( array( 'name' => 'Default category product' ) );

 		$this->assertIsArray( $result );
-		$this->created_product_ids[] = $result['product']['id'];
 		$this->assertSame( array( $default ), array_column( $result['product']['categories'], 'id' ) );
 	}

@@ -1723,7 +1680,6 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 		}

 		$this->assertNotWPError( $created );
-		$this->created_product_ids[] = $created['product']['id'];
 		$this->assertSame( '10.99', $created['product']['regular_price'] );
 	}

@@ -1731,8 +1687,7 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 	 * @testdox Should reject whitespace-only order notes during schema validation.
 	 */
 	public function test_order_add_note_schema_rejects_whitespace_only_note(): void {
-		$order                     = \WC_Helper_Order::create_order();
-		$this->created_order_ids[] = $order->get_id();
+		$order = wc_create_order();

 		$result = wp_get_ability( 'woocommerce/order-add-note' )->execute(
 			array(
@@ -1749,8 +1704,7 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 	 * @testdox Should add a private order note when customer_note is the string false.
 	 */
 	public function test_order_add_note_reads_string_false_as_a_private_note(): void {
-		$order                     = \WC_Helper_Order::create_order();
-		$this->created_order_ids[] = $order->get_id();
+		$order = wc_create_order();

 		$result = wp_get_ability( 'woocommerce/order-add-note' )->execute(
 			array(
@@ -1910,7 +1864,6 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 		$order->set_customer_id( 0 );
 		$order->set_billing_email( $email );
 		$order->save();
-		$this->created_order_ids[] = $order->get_id();

 		$result = wp_get_ability( 'woocommerce/orders-query' )->execute(
 			array(
@@ -1945,20 +1898,18 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 	 * @testdox Should not force products-query to published products by default.
 	 */
 	public function test_products_query_does_not_force_publish_status_by_default(): void {
-		$published                   = \WC_Helper_Product::create_simple_product(
+		$published = \WC_Helper_Product::create_simple_product(
 			true,
 			array( 'name' => 'Public Item' )
 		);
-		$this->created_product_ids[] = $published->get_id();

-		$draft                       = \WC_Helper_Product::create_simple_product(
+		$draft = \WC_Helper_Product::create_simple_product(
 			true,
 			array(
 				'name'   => 'Draft Item',
 				'status' => 'draft',
 			)
 		);
-		$this->created_product_ids[] = $draft->get_id();

 		$result = wp_get_ability( 'woocommerce/products-query' )->execute( array() );

@@ -1972,7 +1923,7 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 	 * @testdox Should return drafts when explicitly filtered by status=draft.
 	 */
 	public function test_products_query_returns_drafts_when_explicitly_requested(): void {
-		$draft                       = \WC_Helper_Product::create_simple_product(
+		$draft = \WC_Helper_Product::create_simple_product(
 			true,
 			array(
 				'name'   => 'Hidden Draft',
@@ -1980,7 +1931,6 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 				'sku'    => 'hidden-draft-sku',
 			)
 		);
-		$this->created_product_ids[] = $draft->get_id();

 		$result = wp_get_ability( 'woocommerce/products-query' )->execute(
 			array(
@@ -2006,7 +1956,6 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 		);

 		$this->assertNotWPError( $created );
-		$this->created_product_ids[] = $created['product']['id'];

 		$this->assertSame( get_woocommerce_currency(), $created['product']['currency'] );
 		$this->assertNotEmpty( $created['product']['currency_symbol'] );
@@ -2028,7 +1977,6 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 		);

 		$this->assertNotWPError( $created );
-		$this->created_product_ids[] = $created['product']['id'];
 		$this->assertSame( 'simple', $created['product']['type'] );
 		$this->assertTrue( $created['product']['virtual'] );
 		$this->assertTrue( $created['product']['downloadable'] );
@@ -2048,7 +1996,6 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 		);

 		$this->assertNotWPError( $created );
-		$this->created_product_ids[] = $created['product']['id'];
 		$this->assertSame( 'simple', $created['product']['type'] );
 		$this->assertTrue( $created['product']['virtual'] );
 		$this->assertFalse( $created['product']['downloadable'] );
@@ -2072,7 +2019,6 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 		);

 		$this->assertNotWPError( $physical );
-		$this->created_product_ids[] = $physical['product']['id'];

 		$virtual = wp_get_ability( 'woocommerce/product-create' )->execute(
 			array(
@@ -2084,7 +2030,6 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 		);

 		$this->assertNotWPError( $virtual );
-		$this->created_product_ids[] = $virtual['product']['id'];

 		$digital = wp_get_ability( 'woocommerce/product-create' )->execute(
 			array(
@@ -2097,14 +2042,12 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 		);

 		$this->assertNotWPError( $digital );
-		$this->created_product_ids[] = $digital['product']['id'];

 		$hybrid = \WC_Helper_Product::create_simple_product();
 		$hybrid->set_sku( $hybrid_sku );
 		$hybrid->set_virtual( false );
 		$hybrid->set_downloadable( true );
 		$hybrid->save();
-		$this->created_product_ids[] = $hybrid->get_id();

 		$physical_result = wp_get_ability( 'woocommerce/products-query' )->execute(
 			array(
@@ -2205,7 +2148,6 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 		);

 		$this->assertNotWPError( $created );
-		$this->created_product_ids[] = $created['product']['id'];
 		$this->assertSame( 'external', $created['product']['type'] );
 		$this->assertSame( 'https://example.com/buy', $created['product']['external_url'] );
 		$this->assertSame( 'Buy elsewhere', $created['product']['button_text'] );
@@ -2215,8 +2157,7 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 	 * @testdox Should create grouped products with children.
 	 */
 	public function test_product_create_creates_grouped_product(): void {
-		$child                       = \WC_Helper_Product::create_simple_product();
-		$this->created_product_ids[] = $child->get_id();
+		$child = \WC_Helper_Product::create_simple_product();

 		$created = wp_get_ability( 'woocommerce/product-create' )->execute(
 			array(
@@ -2227,7 +2168,6 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 		);

 		$this->assertNotWPError( $created );
-		$this->created_product_ids[] = $created['product']['id'];
 		$this->assertSame( 'grouped', $created['product']['type'] );
 		$this->assertSame( array( $child->get_id() ), $created['product']['grouped_products'] );
 	}
@@ -2275,9 +2215,7 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 		}

 		$this->assertNotWPError( $bundle );
-		$this->created_product_ids[] = $bundle['product']['id'];
 		$this->assertNotWPError( $subscription );
-		$this->created_product_ids[] = $subscription['product']['id'];

 		$this->assertContains( 'test-bundle', $create_schema['properties']['type']['enum'] );
 		$this->assertNotContains( 'test-missing', $create_schema['properties']['type']['enum'] );
@@ -2298,8 +2236,7 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 	 * @testdox Should change a product to a type that an extension registers, and query by the type.
 	 */
 	public function test_product_update_changes_the_type_to_a_registered_product_type(): void {
-		$product                     = \WC_Helper_Product::create_simple_product();
-		$this->created_product_ids[] = $product->get_id();
+		$product = \WC_Helper_Product::create_simple_product();

 		$this->unregister_domain_abilities();
 		add_filter( 'product_type_selector', array( $this, 'add_test_product_types' ) );
@@ -2330,7 +2267,6 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 		}

 		$this->assertNotWPError( $bundle );
-		$this->created_product_ids[] = $bundle['product']['id'];

 		$this->assertNotWPError( $subscription );
 		$this->assertSame( 'test-subscription', $subscription['product']['type'] );
@@ -2367,7 +2303,6 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 		}

 		$this->assertNotWPError( $bundle );
-		$this->created_product_ids[] = $bundle['product']['id'];

 		$this->assertSame( '9.00', $bundle['product']['regular_price'] );
 	}
@@ -2395,7 +2330,6 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 		$created = wp_get_ability( 'woocommerce/product-create' )->execute( $this->get_shirt_input() );

 		$this->assertNotWPError( $created );
-		$this->created_product_ids[] = $created['product']['id'];

 		$parent = wc_get_product( $created['product']['id'] );
 		$this->assertInstanceOf( \WC_Product_Variable::class, $parent );
@@ -2510,8 +2444,7 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 	public function test_product_create_checks_a_new_variation_against_its_siblings(): void {
 		$created = wp_get_ability( 'woocommerce/product-create' )->execute( $this->get_shirt_input() );
 		$this->assertNotWPError( $created );
-		$this->created_product_ids[] = $created['product']['id'];
-		$parent_id                   = $created['product']['id'];
+		$parent_id = $created['product']['id'];

 		$resized = wp_get_ability( 'woocommerce/product-update' )->execute(
 			array(
@@ -2565,9 +2498,8 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 	public function test_variations_are_products_in_the_other_abilities(): void {
 		$created = wp_get_ability( 'woocommerce/product-create' )->execute( $this->get_shirt_input() );
 		$this->assertNotWPError( $created );
-		$this->created_product_ids[] = $created['product']['id'];
-		$parent_id                   = $created['product']['id'];
-		$small_id                    = $created['product']['variation_ids'][0];
+		$parent_id = $created['product']['id'];
+		$small_id  = $created['product']['variation_ids'][0];

 		$updated = wp_get_ability( 'woocommerce/product-update' )->execute(
 			array(
@@ -2710,7 +2642,6 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 	public function test_product_update_changes_adds_and_deletes_variations(): void {
 		$created = wp_get_ability( 'woocommerce/product-create' )->execute( $this->get_shirt_input() );
 		$this->assertNotWPError( $created );
-		$this->created_product_ids[]  = $created['product']['id'];
 		$parent_id                    = $created['product']['id'];
 		list( $small_id, $medium_id ) = $created['product']['variation_ids'];

@@ -2766,12 +2697,10 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 		$this->assertSame( array(), $deleted['variations'] );
 		$this->assertNull( get_post( $medium_id ) );

-		$other                       = \WC_Helper_Product::create_variation_product();
-		$this->created_product_ids[] = $other->get_id();
-		$foreign                     = wp_get_ability( 'woocommerce/product-update' )->execute_change(
+		$foreign = wp_get_ability( 'woocommerce/product-update' )->execute_change(
 			array(
 				'id'         => $parent_id,
-				'variations' => array( array( 'id' => $other->get_children()[0] ) ),
+				'variations' => array( array( 'id' => $this->create_variation_product_id_for_test() ) ),
 			)
 		);
 		$this->assertWPError( $foreign );
@@ -2795,9 +2724,8 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 		$this->assertWPError( $duplicate );
 		$this->assertSame( 'woocommerce_product_variation_duplicate', $duplicate->get_error_code() );

-		$simple                      = \WC_Helper_Product::create_simple_product();
-		$this->created_product_ids[] = $simple->get_id();
-		$not_variable                = wp_get_ability( 'woocommerce/product-update' )->execute(
+		$simple       = \WC_Helper_Product::create_simple_product();
+		$not_variable = wp_get_ability( 'woocommerce/product-update' )->execute(
 			array(
 				'id'         => $simple->get_id(),
 				'variations' => array( array( 'regular_price' => '1.00' ) ),
@@ -2813,8 +2741,7 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 	public function test_product_update_rolls_back_every_save_when_a_variation_fails(): void {
 		$created = wp_get_ability( 'woocommerce/product-create' )->execute( $this->get_shirt_input() );
 		$this->assertNotWPError( $created );
-		$this->created_product_ids[] = $created['product']['id'];
-		$small_id                    = $created['product']['variation_ids'][0];
+		$small_id = $created['product']['variation_ids'][0];

 		$fail = static function ( $product ) {
 			if ( $product instanceof \WC_Product_Variation && 'shirt-l' === $product->get_sku( 'edit' ) ) {
@@ -2868,9 +2795,8 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 	public function test_variation_permissions_follow_the_parent(): void {
 		$created = wp_get_ability( 'woocommerce/product-create' )->execute( $this->get_shirt_input() );
 		$this->assertNotWPError( $created );
-		$this->created_product_ids[] = $created['product']['id'];
-		$parent_id                   = $created['product']['id'];
-		$small_id                    = $created['product']['variation_ids'][0];
+		$parent_id = $created['product']['id'];
+		$small_id  = $created['product']['variation_ids'][0];

 		$checked = array();
 		$capture = static function ( $caps, $cap, $user_id, $args ) use ( &$checked ) {
@@ -2898,8 +2824,7 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 	public function test_variation_delete_through_the_parent_requires_the_delete_permission(): void {
 		$created = wp_get_ability( 'woocommerce/product-create' )->execute( $this->get_shirt_input() );
 		$this->assertNotWPError( $created );
-		$this->created_product_ids[] = $created['product']['id'];
-		$update                      = array(
+		$update = array(
 			'id'         => $created['product']['id'],
 			'variations' => array(
 				array(
@@ -2908,7 +2833,7 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 				),
 			),
 		);
-		$delete                      = array(
+		$delete = array(
 			'id'         => $created['product']['id'],
 			'variations' => array(
 				array(
@@ -2936,9 +2861,8 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 	public function test_variation_publish_through_the_parent_requires_publish_cap(): void {
 		$created = wp_get_ability( 'woocommerce/product-create' )->execute( $this->get_shirt_input() );
 		$this->assertNotWPError( $created );
-		$this->created_product_ids[] = $created['product']['id'];
-		$variation_id                = $created['product']['variation_ids'][0];
-		$variation                   = wc_get_product( $variation_id );
+		$variation_id = $created['product']['variation_ids'][0];
+		$variation    = wc_get_product( $variation_id );
 		$variation->set_status( 'private' );
 		$variation->save();

@@ -2990,7 +2914,6 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 		array_pop( $input['variations'] );
 		$created = wp_get_ability( 'woocommerce/product-create' )->execute( $input );
 		$this->assertNotWPError( $created );
-		$this->created_product_ids[] = $created['product']['id'];

 		$user_id = $this->factory->user->create( array( 'role' => 'subscriber' ) );
 		$user    = get_user_by( 'id', $user_id );
@@ -3047,8 +2970,7 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 	public function test_a_variation_item_with_a_false_delete_flag_is_a_change( $flag ): void {
 		$created = wp_get_ability( 'woocommerce/product-create' )->execute( $this->get_shirt_input() );
 		$this->assertNotWPError( $created );
-		$this->created_product_ids[] = $created['product']['id'];
-		$variation_id                = $created['product']['variation_ids'][0];
+		$variation_id = $created['product']['variation_ids'][0];

 		$result = wp_get_ability( 'woocommerce/product-update' )->execute(
 			array(
@@ -3087,8 +3009,7 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 	 * @testdox Should move a product to the trash when force is the string false.
 	 */
 	public function test_product_delete_with_force_string_false_trashes(): void {
-		$product                     = \WC_Helper_Product::create_simple_product();
-		$this->created_product_ids[] = $product->get_id();
+		$product = \WC_Helper_Product::create_simple_product();

 		$result = wp_get_ability( 'woocommerce/product-delete' )->execute(
 			array(
@@ -3105,7 +3026,7 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 	 * @testdox Should check the permissions of a direct call with a numeric string id or no input, as the MCP adapter sends them.
 	 */
 	public function test_check_permissions_converts_raw_input(): void {
-		$order   = \WC_Helper_Order::create_order();
+		$order   = wc_create_order();
 		$ability = wp_get_ability( 'woocommerce/orders-query' );

 		$this->assertTrue( $ability->check_permissions( array( 'id' => (string) $order->get_id() ) ), 'A numeric string id is converted.' );
@@ -3125,8 +3046,7 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 		$created = wp_get_ability( 'woocommerce/product-create' )->execute( $input );

 		$this->assertNotWPError( $created );
-		$this->created_product_ids[] = $created['product']['id'];
-		$attribute                   = $created['product']['attributes'][0];
+		$attribute = $created['product']['attributes'][0];
 		$this->assertFalse( $attribute['visible'] );
 		$this->assertFalse( $attribute['variation'] );
 		$this->assertSame( 0, $attribute['id'] );
@@ -3138,9 +3058,8 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 	public function test_a_blocked_variation_delete_through_the_parent_fails(): void {
 		$created = wp_get_ability( 'woocommerce/product-create' )->execute( $this->get_shirt_input() );
 		$this->assertNotWPError( $created );
-		$this->created_product_ids[] = $created['product']['id'];
-		$variation_id                = $created['product']['variation_ids'][0];
-		$block                       = static fn( $check, $post ) => 'product_variation' === $post->post_type ? false : $check;
+		$variation_id = $created['product']['variation_ids'][0];
+		$block        = static fn( $check, $post ) => 'product_variation' === $post->post_type ? false : $check;

 		add_filter( 'pre_delete_post', $block, 10, 2 );
 		try {
@@ -3186,9 +3105,8 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 	public function test_variation_items_follow_the_product_type_fields_filter(): void {
 		$created = wp_get_ability( 'woocommerce/product-create' )->execute( $this->get_shirt_input() );
 		$this->assertNotWPError( $created );
-		$this->created_product_ids[] = $created['product']['id'];
-		$variation_id                = $created['product']['variation_ids'][0];
-		$drop                        = static fn( array $fields, string $type ) => 'variation' === $type ? array_values( array_diff( $fields, array( 'regular_price' ) ) ) : $fields;
+		$variation_id = $created['product']['variation_ids'][0];
+		$drop         = static fn( array $fields, string $type ) => 'variation' === $type ? array_values( array_diff( $fields, array( 'regular_price' ) ) ) : $fields;

 		add_filter( 'woocommerce_ability_product_type_fields', $drop, 10, 2 );
 		try {
@@ -3233,7 +3151,6 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 		$unknown                          = wp_get_ability( 'woocommerce/product-create' )->execute_change( $input );

 		$this->assertNotWPError( $local );
-		$this->created_product_ids[] = $local['product']['id'];
 		$this->assertSame( 0, $local['product']['attributes'][0]['id'] );
 		$this->assertArrayHasKey( 'size', wc_get_product( $local['product']['id'] )->get_attributes() );
 		$this->assertWPError( $unknown );
@@ -3259,7 +3176,6 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 		$created = wp_get_ability( 'woocommerce/product-create' )->execute( $input );

 		$this->assertNotWPError( $created );
-		$this->created_product_ids[] = $created['product']['id'];
 		$this->assertSame( '', wc_get_product( $created['product']['variation_ids'][0] )->get_attributes()['color'] );
 	}

@@ -3280,7 +3196,6 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {

 		$created = wp_get_ability( 'woocommerce/product-create' )->execute( $input );
 		$this->assertNotWPError( $created );
-		$this->created_product_ids[] = $created['product']['id'];

 		$small = wp_get_ability( 'woocommerce/products-query' )->execute( array( 'id' => $created['product']['variation_ids'][0] ) );
 		$this->assertNotWPError( $small );
@@ -3320,7 +3235,6 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {

 		$created = wp_get_ability( 'woocommerce/product-create' )->execute( $input );
 		$this->assertNotWPError( $created );
-		$this->created_product_ids[] = $created['product']['id'];

 		$this->assertCount( 2, $created['product']['variation_ids'] );
 		$this->assertSame( array( true, false ), array_column( $created['product']['attributes'], 'variation' ) );
@@ -3333,7 +3247,6 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 	public function test_variation_checks_ignore_the_get_children_filter(): void {
 		$created = wp_get_ability( 'woocommerce/product-create' )->execute( $this->get_shirt_input() );
 		$this->assertNotWPError( $created );
-		$this->created_product_ids[] = $created['product']['id'];

 		add_filter( 'woocommerce_get_children', '__return_empty_array' );
 		try {
@@ -3367,7 +3280,6 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 		$attribute = \WC_Helper_Product::create_attribute( 'size', array( 'small', 'large' ) );
 		$created   = wp_get_ability( 'woocommerce/product-create' )->execute( $this->get_global_size_shirt_input( $attribute['attribute_id'], 'large' ) );
 		$this->assertNotWPError( $created );
-		$this->created_product_ids[] = $created['product']['id'];

 		$product = wc_get_product( $created['product']['id'] );
 		$stored  = $product->get_attributes()['pa_size'] ?? null;
@@ -3405,7 +3317,6 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 		$attribute = \WC_Helper_Product::create_attribute( 'size', array( 'small', 'large' ) );
 		$created   = wp_get_ability( 'woocommerce/product-create' )->execute( $this->get_global_size_shirt_input( $attribute['attribute_id'], 'large' ) );
 		$this->assertNotWPError( $created );
-		$this->created_product_ids[] = $created['product']['id'];

 		$parent     = wp_get_ability( 'woocommerce/products-query' )->execute( array( 'id' => $created['product']['id'] ) );
 		$variations = wp_get_ability( 'woocommerce/products-query' )->execute( array( 'parent_id' => $created['product']['id'] ) );
@@ -3556,7 +3467,6 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 		);

 		$this->assertNotWPError( $sku_product );
-		$this->created_product_ids[] = $sku_product['product']['id'];

 		$no_sku_product = wp_get_ability( 'woocommerce/product-create' )->execute(
 			array(
@@ -3565,7 +3475,6 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 		);

 		$this->assertNotWPError( $no_sku_product );
-		$this->created_product_ids[] = $no_sku_product['product']['id'];

 		$result = wp_get_ability( 'woocommerce/products-query' )->execute(
 			array(
@@ -3663,7 +3572,6 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 			);

 			$this->assertNotWPError( $created );
-			$this->created_product_ids[] = $created['product']['id'];
 			$this->assertSame( 1.5, $created['product']['stock_quantity'] );
 		} finally {
 			remove_filter( 'woocommerce_stock_amount', array( $this, 'preserve_fractional_stock_amount' ) );
@@ -3684,9 +3592,8 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 	 */
 	public function test_product_output_handles_filtered_dates( $date ): void {
 		update_option( 'timezone_string', 'Europe/Amsterdam' );
-		$product                     = \WC_Helper_Product::create_simple_product();
-		$this->created_product_ids[] = $product->get_id();
-		$filter                      = static function () use ( $date ) {
+		$product = \WC_Helper_Product::create_simple_product();
+		$filter  = static function () use ( $date ) {
 			return $date;
 		};
 		add_filter( 'woocommerce_product_get_date_created', $filter );
@@ -3714,10 +3621,9 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 	 */
 	public function test_order_output_preserves_filtered_date_object(): void {
 		update_option( 'timezone_string', 'Europe/Amsterdam' );
-		$order                     = wc_create_order();
-		$this->created_order_ids[] = $order->get_id();
-		$date                      = new \WC_DateTime( '2026-07-15T12:00:00', new \DateTimeZone( 'Asia/Kathmandu' ) );
-		$timestamp                 = $date->getTimestamp();
+		$order     = wc_create_order();
+		$date      = new \WC_DateTime( '2026-07-15T12:00:00', new \DateTimeZone( 'Asia/Kathmandu' ) );
+		$timestamp = $date->getTimestamp();
 		add_filter(
 			'woocommerce_order_get_date_created',
 			static function () use ( $date ) {
@@ -3748,8 +3654,7 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 		$product = \WC_Helper_Product::create_simple_product();
 		$product->set_date_created( $created );
 		$product->save();
-		$this->created_product_ids[] = $product->get_id();
-		$modified                    = new \WC_DateTime( $created, wp_timezone() );
+		$modified = new \WC_DateTime( $created, wp_timezone() );
 		add_filter(
 			'woocommerce_product_get_date_modified',
 			static function () use ( $modified ) {
@@ -3798,7 +3703,6 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 		$order->set_date_created( $created );
 		$order->set_date_modified( $created );
 		$order->save();
-		$this->created_order_ids[] = $order->get_id();
 		$this->set_order_modified_date_for_query_test( $order, $created );

 		$result = wp_get_ability( 'woocommerce/orders-query' )->execute( array( 'id' => $order->get_id() ) );
@@ -3842,8 +3746,7 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {

 		try {
 			$this->register_domain_abilities();
-			$order                     = \WC_Helper_Order::create_order();
-			$this->created_order_ids[] = $order->get_id();
+			$order = \WC_Helper_Order::create_order();
 			foreach ( $order->get_items() as $item ) {
 				$item->set_quantity( 1.5 );
 				$item->save();
@@ -3870,7 +3773,6 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 		$product = new \WC_Product_External();
 		$product->set_name( 'External product' );
 		$product->save();
-		$this->created_product_ids[] = $product->get_id();

 		$result = wp_get_ability( 'woocommerce/products-query' )->execute( array( 'id' => $product->get_id() ) );
 		$this->assertNotWPError( $result );
@@ -4052,7 +3954,7 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 	 * @param mixed $date Filtered date.
 	 */
 	public function test_order_output_handles_filtered_dates( $date ): void {
-		$order  = \WC_Helper_Order::create_order();
+		$order  = wc_create_order();
 		$filter = static function () use ( $date ) {
 			return $date;
 		};
@@ -4079,7 +3981,7 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 	 * @testdox Should omit an absent order note date while preserving false and empty strings.
 	 */
 	public function test_order_note_output_omits_absent_date(): void {
-		$order = \WC_Helper_Order::create_order();
+		$order = wc_create_order();
 		$order->add_order_note( 'Internal note.' );
 		$omit_date = static function ( $note ) {
 			$note['date_created'] = null;
@@ -4138,8 +4040,7 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 	 * @testdox Should update a per-type field such as regular_price without a type in the input.
 	 */
 	public function test_product_update_changes_props_and_returns_updated_response(): void {
-		$product                     = \WC_Helper_Product::create_simple_product();
-		$this->created_product_ids[] = $product->get_id();
+		$product = \WC_Helper_Product::create_simple_product();

 		$result = wp_get_ability( 'woocommerce/product-update' )->execute(
 			array(
@@ -4158,8 +4059,7 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 	 * @testdox Should refuse an update field that the type of the loaded product does not support.
 	 */
 	public function test_product_update_rejects_fields_not_supported_by_loaded_product_type(): void {
-		$product                     = \WC_Helper_Product::create_grouped_product();
-		$this->created_product_ids[] = $product->get_id();
+		$product = \WC_Helper_Product::create_grouped_product();

 		$result = wp_get_ability( 'woocommerce/product-update' )->execute(
 			array(
@@ -4177,13 +4077,12 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 	 * @testdox Should return a structured error when product updates throw during save.
 	 */
 	public function test_product_update_returns_error_when_save_throws_exception(): void {
-		$product                     = \WC_Helper_Product::create_simple_product();
-		$this->created_product_ids[] = $product->get_id();
-		$throw_on_update             = static function (): void {
+		$product         = \WC_Helper_Product::create_simple_product();
+		$throw_on_update = static function (): void {
 			throw new \Exception( 'Generic product save failure.' );
 		};
-		$logger                      = $this->getMockBuilder( \WC_Logger_Interface::class )->getMock();
-		$logger_filter               = static function () use ( $logger ) {
+		$logger          = $this->getMockBuilder( \WC_Logger_Interface::class )->getMock();
+		$logger_filter   = static function () use ( $logger ) {
 			return $logger;
 		};

@@ -4229,8 +4128,7 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 	 * @testdox Should apply product type configuration when updating a product type.
 	 */
 	public function test_product_update_applies_product_type_configuration(): void {
-		$product                     = \WC_Helper_Product::create_simple_product();
-		$this->created_product_ids[] = $product->get_id();
+		$product = \WC_Helper_Product::create_simple_product();

 		$result = wp_get_ability( 'woocommerce/product-update' )->execute(
 			array(
@@ -4256,10 +4154,8 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 		$grouped->set_manage_stock( true );
 		$grouped->set_stock_quantity( 5 );
 		$grouped->save();
-		$this->created_product_ids[] = $grouped->get_id();

-		$simple                      = \WC_Helper_Product::create_simple_product();
-		$this->created_product_ids[] = $simple->get_id();
+		$simple = \WC_Helper_Product::create_simple_product();
 		$simple->set_manage_stock( true );
 		$simple->set_stock_quantity( 5 );
 		$simple->save();
@@ -4290,8 +4186,7 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 	 * @testdox Should reject product updates that include no changed fields.
 	 */
 	public function test_product_update_requires_at_least_one_mutation_field(): void {
-		$product                     = \WC_Helper_Product::create_simple_product();
-		$this->created_product_ids[] = $product->get_id();
+		$product = \WC_Helper_Product::create_simple_product();

 		$result = wp_get_ability( 'woocommerce/product-update' )->execute(
 			array(
@@ -4344,8 +4239,7 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 	 * @testdox Should trash a product by default.
 	 */
 	public function test_product_delete_defaults_to_trash(): void {
-		$product                     = \WC_Helper_Product::create_simple_product();
-		$this->created_product_ids[] = $product->get_id();
+		$product = \WC_Helper_Product::create_simple_product();

 		$result = wp_get_ability( 'woocommerce/product-delete' )->execute(
 			array(
@@ -4362,8 +4256,7 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 	 * @testdox Should reject soft deletes when product trashing is not supported.
 	 */
 	public function test_product_delete_rejects_soft_delete_when_trash_not_supported(): void {
-		$product                     = \WC_Helper_Product::create_simple_product();
-		$this->created_product_ids[] = $product->get_id();
+		$product = \WC_Helper_Product::create_simple_product();

 		add_filter( 'woocommerce_product_object_trashable', '__return_false' );

@@ -4386,8 +4279,7 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 	 * @testdox Should return an error when product deletion is blocked.
 	 */
 	public function test_product_delete_returns_error_when_delete_is_blocked(): void {
-		$product                     = \WC_Helper_Product::create_simple_product();
-		$this->created_product_ids[] = $product->get_id();
+		$product = \WC_Helper_Product::create_simple_product();

 		$callback = static function () {
 			return false;
@@ -4480,7 +4372,6 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 		$product = \WC_Helper_Product::create_simple_product();
 		$product->set_status( 'auto-draft' );
 		$product->save();
-		$this->created_product_ids[] = $product->get_id();

 		$filter_permalink = static function ( $permalink, $post ) use ( $product ) {
 			return $post instanceof \WP_Post && $post->ID === $product->get_id() ? false : $permalink;
@@ -4569,7 +4460,7 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 	 * @param string $hint  Text that the message must have.
 	 */
 	public function test_order_update_refuses_invalid_input( array $input, string $code, string $hint ): void {
-		$order = $this->create_order_for_update( 'pending' );
+		$order = wc_create_order();
 		$order->set_shipping_country( 'US' );
 		$order->set_shipping_state( 'CA' );
 		$order->set_shipping_city( 'Before' );
@@ -4587,7 +4478,7 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 	 * @testdox Should return every address and line refusal of an order update in one message, and save nothing.
 	 */
 	public function test_order_update_returns_every_refusal_in_one_message(): void {
-		$order = $this->create_order_for_update( 'pending' );
+		$order = wc_create_order();
 		$order->set_shipping_country( 'US' );
 		$order->set_shipping_city( 'Before' );
 		$order->save();
@@ -5140,7 +5031,6 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 		$order = \WC_Helper_Order::create_order();
 		$order->set_status( $status );
 		$order->save();
-		$this->created_order_ids[] = $order->get_id();

 		return wc_get_order( $order->get_id() );
 	}
@@ -5152,7 +5042,6 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 		$order = \WC_Helper_Order::create_order();
 		$order->set_billing_email( 'domain-order-query@example.com' );
 		$order->save();
-		$this->created_order_ids[] = $order->get_id();

 		$result = wp_get_ability( 'woocommerce/orders-query' )->execute(
 			array(
@@ -5178,8 +5067,7 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 	public function test_order_notes_query_lists_every_note( bool $hpos_enabled ): void {
 		$this->set_order_storage_for_test( $hpos_enabled );

-		$order                     = \WC_Helper_Order::create_order();
-		$this->created_order_ids[] = $order->get_id();
+		$order = wc_create_order();

 		$newer_note_id = $order->add_order_note( 'Internal note.' );
 		$order->add_order_note( 'Customer note.', true );
@@ -5224,9 +5112,8 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 	 * @testdox Should check the order-notes-query permission against the actual type of the order ID.
 	 */
 	public function test_order_notes_query_refuses_id_of_unsupported_order_type(): void {
-		$order                     = \WC_Helper_Order::create_order();
-		$this->created_order_ids[] = $order->get_id();
-		$refund                    = wc_create_refund(
+		$order  = \WC_Helper_Order::create_order();
+		$refund = wc_create_refund(
 			array(
 				'order_id' => $order->get_id(),
 				'amount'   => 1,
@@ -5254,8 +5141,7 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 				'add_order_meta_boxes'     => false,
 			)
 		);
-		$order                     = \WC_Helper_Order::create_order();
-		$this->created_order_ids[] = $order->get_id();
+		$order = wc_create_order();
 		$wpdb->update( $wpdb->posts, array( 'post_type' => 'shop_test_private' ), array( 'ID' => $order->get_id() ) );
 		$wpdb->update( OrdersTableDataStore::get_orders_table_name(), array( 'type' => 'shop_test_private' ), array( 'id' => $order->get_id() ) );
 		clean_post_cache( $order->get_id() );
@@ -5293,17 +5179,15 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {

 		$email = wp_unique_id( 'abilities-checkout-draft-' ) . '@example.com';

-		$processing_order = \WC_Helper_Order::create_order();
+		$processing_order = wc_create_order();
 		$processing_order->set_billing_email( $email );
 		$processing_order->set_status( 'processing' );
 		$processing_order->save();
-		$this->created_order_ids[] = $processing_order->get_id();

-		$checkout_draft = \WC_Helper_Order::create_order();
+		$checkout_draft = wc_create_order();
 		$checkout_draft->set_billing_email( $email );
 		$checkout_draft->set_status( 'checkout-draft' );
 		$checkout_draft->save();
-		$this->created_order_ids[] = $checkout_draft->get_id();

 		$result = wp_get_ability( 'woocommerce/orders-query' )->execute(
 			array(
@@ -5385,7 +5269,6 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 		$order = wc_create_order();
 		$this->assertNotWPError( $order );
 		$order->save();
-		$this->created_order_ids[] = $order->get_id();

 		$result = wp_get_ability( 'woocommerce/orders-query' )->execute(
 			array(
@@ -5401,17 +5284,15 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 	 * @testdox Should narrow orders-query results by date range.
 	 */
 	public function test_orders_query_filters_by_date_range(): void {
-		$old_order = \WC_Helper_Order::create_order();
+		$old_order = wc_create_order();
 		$old_order->set_date_created( '2020-01-15T00:00:00' );
 		$old_order->set_billing_email( 'date-range@example.com' );
 		$old_order->save();
-		$this->created_order_ids[] = $old_order->get_id();

-		$new_order = \WC_Helper_Order::create_order();
+		$new_order = wc_create_order();
 		$new_order->set_date_created( '2025-01-15T00:00:00' );
 		$new_order->set_billing_email( 'date-range@example.com' );
 		$new_order->save();
-		$this->created_order_ids[] = $new_order->get_id();

 		$result = wp_get_ability( 'woocommerce/orders-query' )->execute(
 			array(
@@ -5572,8 +5453,7 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 	 * @testdox Should change order status and surface failure when status update fails.
 	 */
 	public function test_order_update_status_changes_status(): void {
-		$order                     = \WC_Helper_Order::create_order();
-		$this->created_order_ids[] = $order->get_id();
+		$order = wc_create_order();

 		$result = wp_get_ability( 'woocommerce/order-update-status' )->execute(
 			array(
@@ -5591,9 +5471,8 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 	 * @testdox Should reject unchanged order status updates without adding notes.
 	 */
 	public function test_order_update_status_rejects_unchanged_status_without_adding_notes(): void {
-		$order                     = \WC_Helper_Order::create_order();
-		$this->created_order_ids[] = $order->get_id();
-		$note_count_before         = count(
+		$order             = wc_create_order();
+		$note_count_before = count(
 			wc_get_order_notes(
 				array(
 					'order_id' => $order->get_id(),
@@ -5628,9 +5507,8 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 	 * @testdox Should treat order status updates as manual status changes.
 	 */
 	public function test_order_update_status_uses_manual_status_update(): void {
-		$order                     = \WC_Helper_Order::create_order();
-		$this->created_order_ids[] = $order->get_id();
-		$manual_update_observed    = false;
+		$order                  = wc_create_order();
+		$manual_update_observed = false;

 		$callback = static function ( $order_id, $status ) use ( $order, &$manual_update_observed ) {
 			if ( $order->get_id() === $order_id && 'processing' === $status ) {
@@ -5659,8 +5537,7 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 	 * @testdox Should attribute order notes to the acting user.
 	 */
 	public function test_order_add_note_attributes_to_acting_user(): void {
-		$order                     = \WC_Helper_Order::create_order();
-		$this->created_order_ids[] = $order->get_id();
+		$order = wc_create_order();

 		$user_id = $this->factory->user->create(
 			array(
@@ -5688,8 +5565,7 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 	 * @testdox Should preserve safe HTML in order notes.
 	 */
 	public function test_order_add_note_preserves_safe_html(): void {
-		$order                     = \WC_Helper_Order::create_order();
-		$this->created_order_ids[] = $order->get_id();
+		$order = wc_create_order();

 		$result = wp_get_ability( 'woocommerce/order-add-note' )->execute(
 			array(
@@ -5709,8 +5585,7 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 	 * @testdox Should reject whitespace-only order notes during execution.
 	 */
 	public function test_order_add_note_execute_rejects_whitespace_only_note(): void {
-		$order                     = \WC_Helper_Order::create_order();
-		$this->created_order_ids[] = $order->get_id();
+		$order = wc_create_order();

 		$result = OrderAddNote::execute(
 			array(
@@ -5727,8 +5602,7 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 	 * @testdox Should mark notes as customer-facing when customer_note=true.
 	 */
 	public function test_order_add_note_persists_customer_note_flag(): void {
-		$order                     = \WC_Helper_Order::create_order();
-		$this->created_order_ids[] = $order->get_id();
+		$order = wc_create_order();

 		$result = wp_get_ability( 'woocommerce/order-add-note' )->execute(
 			array(
@@ -6101,18 +5975,18 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 	}

 	/**
-	 * Create a product variation and track it for cleanup.
+	 * Create one variation of a variable product with a single global attribute.
 	 *
 	 * @return int Variation product ID.
 	 */
 	private function create_variation_product_id_for_test(): int {
-		$parent       = \WC_Helper_Product::create_variation_product();
-		$variation_id = $parent->get_children()[0];
-
-		$this->created_product_ids[] = $variation_id;
-		$this->created_product_ids[] = $parent->get_id();
+		list( , $variation ) = \WC_Helper_Product::create_variation_product_with_global_attributes(
+			'Variable product',
+			array( 'pa_size' => 'small' ),
+			array( 'size' => array( 'small' ) )
+		);

-		return $variation_id;
+		return $variation->get_id();
 	}

 	/**
@@ -6146,13 +6020,12 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
 	 * @return \WC_Order
 	 */
 	private function create_order_for_query_sorting( string $billing_email, string $date_created, string $date_modified ): \WC_Order {
-		$order = \WC_Helper_Order::create_order();
+		$order = wc_create_order();
 		$order->set_billing_email( $billing_email );
 		$order->set_date_created( $date_created );
 		$order->set_date_modified( $date_modified );
 		$order->save();

-		$this->created_order_ids[] = $order->get_id();
 		$this->set_order_modified_date_for_query_test( $order, $date_modified );

 		return $order;
diff --git a/plugins/woocommerce/tests/php/src/Internal/Abilities/Domain/CustomersQueryTest.php b/plugins/woocommerce/tests/php/src/Internal/Abilities/Domain/CustomersQueryTest.php
index a1b310e39f2..6d35638e3d1 100644
--- a/plugins/woocommerce/tests/php/src/Internal/Abilities/Domain/CustomersQueryTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/Abilities/Domain/CustomersQueryTest.php
@@ -24,12 +24,28 @@ class CustomersQueryTest extends \WC_Unit_Test_Case {
 	 */
 	private $sut;

+	/**
+	 * An administrator that every test acts as.
+	 *
+	 * @var int
+	 */
+	private static $administrator_id;
+
+	/**
+	 * Create the fixtures that no test changes beyond its own transaction.
+	 *
+	 * @param \WP_UnitTest_Factory $factory WordPress unit test factory.
+	 */
+	public static function wpSetUpBeforeClass( $factory ): void {
+		self::$administrator_id = $factory->user->create( array( 'role' => 'administrator' ) );
+	}
+
 	/**
 	 * Set up an authorized caller.
 	 */
 	public function setUp(): void {
 		parent::setUp();
-		wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
+		wp_set_current_user( self::$administrator_id );
 		$this->sut = new \WP_Ability( CustomersQuery::get_name(), CustomersQuery::get_registration_args() );
 	}

diff --git a/plugins/woocommerce/tests/php/src/Internal/Abilities/Domain/OrdersQueryTest.php b/plugins/woocommerce/tests/php/src/Internal/Abilities/Domain/OrdersQueryTest.php
index 1bac5f56a8b..7ed6edf1021 100644
--- a/plugins/woocommerce/tests/php/src/Internal/Abilities/Domain/OrdersQueryTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/Abilities/Domain/OrdersQueryTest.php
@@ -125,8 +125,8 @@ class OrdersQueryTest extends WC_Unit_Test_Case {
 	public function test_include_without_per_page_returns_one_page(): void {
 		wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
 		$order_ids = array();
-		foreach ( range( 1, 15 ) as $unused ) {
-			$order_ids[] = OrderHelper::create_order()->get_id();
+		foreach ( range( 1, 11 ) as $unused ) {
+			$order_ids[] = wc_create_order()->get_id();
 		}

 		$all_ids = wp_get_ability( 'woocommerce/orders-query' )->execute( array( 'include' => $order_ids ) );
@@ -163,12 +163,10 @@ class OrdersQueryTest extends WC_Unit_Test_Case {
 	 * @testdox Should refuse an id together with include.
 	 */
 	public function test_refuses_id_with_include(): void {
-		$order = OrderHelper::create_order();
-
 		$result = OrdersQuery::execute(
 			array(
-				'id'      => $order->get_id(),
-				'include' => array( $order->get_id() ),
+				'id'      => 1,
+				'include' => array( 1 ),
 			)
 		);

@@ -178,11 +176,15 @@ class OrdersQueryTest extends WC_Unit_Test_Case {
 	}

 	/**
-	 * Search terms that each match one detail of the order that create_detailed_order() builds, on both storages.
+	 * @testdox Should find an order by each customer and item detail the search input describes.
 	 *
-	 * @return array<string, array{0: bool, 1: string}>
+	 * @dataProvider storage_modes
+	 * @param bool $hpos Whether to use the custom orders table.
 	 */
-	public function search_terms(): array {
+	public function test_search_matches_order_details( bool $hpos ): void {
+		$this->use_storage( $hpos );
+		$order = $this->create_detailed_order();
+		$this->create_customer_order( 'John', 'Smith', 'john@example.com' );
 		$terms = array(
 			'first name'         => 'Jane',
 			'last name'          => 'doe',
@@ -197,30 +199,11 @@ class OrdersQueryTest extends WC_Unit_Test_Case {
 			'padded term'        => ' Enamel ',
 		);

-		$cases = array();
-		foreach ( $this->storage_modes() as $storage => list( $hpos ) ) {
-			foreach ( $terms as $detail => $term ) {
-				$cases[ "$detail, $storage" ] = array( $hpos, $term );
-			}
-		}
-		return $cases;
-	}
+		foreach ( $terms as $detail => $search ) {
+			$result = OrdersQuery::execute( array( 'search' => $search ) );

-	/**
-	 * @testdox Should find an order by each customer and item detail the search input describes.
-	 *
-	 * @dataProvider search_terms
-	 * @param bool   $hpos   Whether to use the custom orders table.
-	 * @param string $search Search text.
-	 */
-	public function test_search_matches_order_details( bool $hpos, string $search ): void {
-		$this->use_storage( $hpos );
-		$order = $this->create_detailed_order();
-		$this->create_customer_order( 'John', 'Smith', 'john@example.com' );
-
-		$result = OrdersQuery::execute( array( 'search' => $search ) );
-
-		$this->assertSame( array( $order ), array_column( $result['orders'], 'id' ) );
+			$this->assertSame( array( $order ), array_column( $result['orders'], 'id' ), "Search by $detail." );
+		}
 	}

 	/**
@@ -245,11 +228,9 @@ class OrdersQueryTest extends WC_Unit_Test_Case {
 	 * @testdox Should refuse an id together with search.
 	 */
 	public function test_refuses_id_with_search(): void {
-		$order = OrderHelper::create_order();
-
 		$result = OrdersQuery::execute(
 			array(
-				'id'     => $order->get_id(),
+				'id'     => 1,
 				'search' => 'Jane',
 			)
 		);
@@ -334,28 +315,12 @@ class OrdersQueryTest extends WC_Unit_Test_Case {
 	}

 	/**
-	 * @testdox Should return each order exactly once across pages when orders tie on $orderby $order, with HPOS $hpos.
-	 * @testWith [true, "date", "asc"]
-	 *           [true, "date", "desc"]
-	 *           [true, "date_modified", "asc"]
-	 *           [true, "date_modified", "desc"]
-	 *           [true, "total", "asc"]
-	 *           [true, "total", "desc"]
-	 *           [true, "id", "asc"]
-	 *           [true, "id", "desc"]
-	 *           [false, "date", "asc"]
-	 *           [false, "date", "desc"]
-	 *           [false, "date_modified", "asc"]
-	 *           [false, "date_modified", "desc"]
-	 *           [false, "total", "asc"]
-	 *           [false, "total", "desc"]
-	 *           [false, "id", "asc"]
-	 *           [false, "id", "desc"]
-	 * @param bool   $hpos    Whether to use the custom orders table.
-	 * @param string $orderby Sort field.
-	 * @param string $order   Sort direction.
+	 * @testdox Should return each order exactly once across pages when orders tie on every sort field.
+	 *
+	 * @dataProvider storage_modes
+	 * @param bool $hpos Whether to use the custom orders table.
 	 */
-	public function test_pages_tied_orders_once_each( bool $hpos, string $orderby, string $order ): void {
+	public function test_pages_tied_orders_once_each( bool $hpos ): void {
 		$this->use_storage( $hpos );
 		$ids = array();
 		for ( $i = 0; $i < 7; $i++ ) {
@@ -363,24 +328,29 @@ class OrdersQueryTest extends WC_Unit_Test_Case {
 		}
 		$this->set_modified_date( $ids, $hpos );

-		$paged = array();
-		for ( $page = 1; $page <= 3; $page++ ) {
-			$result = OrdersQuery::execute(
-				array(
-					'orderby'  => $orderby,
-					'order'    => $order,
-					'page'     => $page,
-					'per_page' => 3,
-				)
-			);
-			$this->assertIsArray( $result );
-			$paged = array_merge( $paged, array_column( $result['orders'], 'id' ) );
-		}
-
-		if ( 'desc' === $order ) {
-			rsort( $ids );
+		foreach ( array( 'date', 'date_modified', 'total', 'id' ) as $orderby ) {
+			foreach ( array( 'asc', 'desc' ) as $order ) {
+				$paged = array();
+				for ( $page = 1; $page <= 3; $page++ ) {
+					$result = OrdersQuery::execute(
+						array(
+							'orderby'  => $orderby,
+							'order'    => $order,
+							'page'     => $page,
+							'per_page' => 3,
+						)
+					);
+					$this->assertIsArray( $result );
+					$paged = array_merge( $paged, array_column( $result['orders'], 'id' ) );
+				}
+
+				$expected = $ids;
+				if ( 'desc' === $order ) {
+					rsort( $expected );
+				}
+				$this->assertSame( $expected, $paged, "Tied orders should be sorted by ID when sorting by $orderby $order." );
+			}
 		}
-		$this->assertSame( $ids, $paged, 'Tied orders should be sorted by ID in the requested direction.' );
 	}

 	/**
diff --git a/plugins/woocommerce/tests/php/src/Internal/Abilities/Domain/ProductAttributeCreateTest.php b/plugins/woocommerce/tests/php/src/Internal/Abilities/Domain/ProductAttributeCreateTest.php
index c5beb73532b..80bf3a32f42 100644
--- a/plugins/woocommerce/tests/php/src/Internal/Abilities/Domain/ProductAttributeCreateTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/Abilities/Domain/ProductAttributeCreateTest.php
@@ -32,6 +32,22 @@ class ProductAttributeCreateTest extends WC_Unit_Test_Case {
 	 */
 	private array $taxonomies_before;

+	/**
+	 * An administrator that every test acts as.
+	 *
+	 * @var int
+	 */
+	private static $administrator_id;
+
+	/**
+	 * Create the fixtures that no test changes beyond its own transaction.
+	 *
+	 * @param \WP_UnitTest_Factory $factory WordPress unit test factory.
+	 */
+	public static function wpSetUpBeforeClass( $factory ): void {
+		self::$administrator_id = $factory->user->create( array( 'role' => 'administrator' ) );
+	}
+
 	/**
 	 * Set up the ability and an administrator.
 	 */
@@ -40,7 +56,7 @@ class ProductAttributeCreateTest extends WC_Unit_Test_Case {
 		$this->taxonomies_before = get_taxonomies();
 		update_option( 'woocommerce_feature_extensible_abilities_enabled', 'no' );
 		$this->sut = new Ability( ProductAttributeCreate::get_name(), ProductAttributeCreate::get_registration_args() );
-		wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
+		wp_set_current_user( self::$administrator_id );
 	}

 	/**
diff --git a/plugins/woocommerce/tests/php/src/Internal/Abilities/Domain/ProductAttributesQueryTest.php b/plugins/woocommerce/tests/php/src/Internal/Abilities/Domain/ProductAttributesQueryTest.php
index 797dbdd4fb1..070a6aae53a 100644
--- a/plugins/woocommerce/tests/php/src/Internal/Abilities/Domain/ProductAttributesQueryTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/Abilities/Domain/ProductAttributesQueryTest.php
@@ -24,13 +24,29 @@ class ProductAttributesQueryTest extends WC_Unit_Test_Case {
 	 */
 	private $sut;

+	/**
+	 * An administrator that every test acts as.
+	 *
+	 * @var int
+	 */
+	private static $administrator_id;
+
+	/**
+	 * Create the fixtures that no test changes beyond its own transaction.
+	 *
+	 * @param \WP_UnitTest_Factory $factory WordPress unit test factory.
+	 */
+	public static function wpSetUpBeforeClass( $factory ): void {
+		self::$administrator_id = $factory->user->create( array( 'role' => 'administrator' ) );
+	}
+
 	/**
 	 * Set up the ability and an administrator.
 	 */
 	public function setUp(): void {
 		parent::setUp();
 		$this->sut = new Ability( ProductAttributesQuery::get_name(), ProductAttributesQuery::get_registration_args() );
-		wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
+		wp_set_current_user( self::$administrator_id );
 	}

 	/**
diff --git a/plugins/woocommerce/tests/php/src/Internal/Abilities/Domain/ProductReviewReplyTest.php b/plugins/woocommerce/tests/php/src/Internal/Abilities/Domain/ProductReviewReplyTest.php
index 5e936d9bb83..23108d730e2 100644
--- a/plugins/woocommerce/tests/php/src/Internal/Abilities/Domain/ProductReviewReplyTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/Abilities/Domain/ProductReviewReplyTest.php
@@ -28,14 +28,47 @@ class ProductReviewReplyTest extends \WC_Unit_Test_Case {
 	 */
 	private $product_id;

+	/**
+	 * A shop manager that every test acts as.
+	 *
+	 * @var int
+	 */
+	private static $shop_manager_id;
+
+	/**
+	 * The product every test reviews; each test's changes to it roll back.
+	 *
+	 * @var int
+	 */
+	private static $shared_product_id;
+
+	/**
+	 * Create the fixtures that no test changes beyond its own transaction.
+	 *
+	 * @param \WP_UnitTest_Factory $factory WordPress unit test factory.
+	 */
+	public static function wpSetUpBeforeClass( $factory ): void {
+		self::$shop_manager_id   = $factory->user->create( array( 'role' => 'shop_manager' ) );
+		self::$shared_product_id = self::with_direct_product_attribute_lookup_updates(
+			static fn() => \WC_Helper_Product::create_simple_product()
+		)->get_id();
+	}
+
+	/**
+	 * Delete the shared product, whose lookup rows the WordPress class cleanup leaves behind.
+	 */
+	public static function wpTearDownAfterClass(): void {
+		wc_get_product( self::$shared_product_id )->delete( true );
+	}
+
 	/**
 	 * Set up a shop manager and a product.
 	 */
 	public function setUp(): void {
 		parent::setUp();
-		wp_set_current_user( self::factory()->user->create( array( 'role' => 'shop_manager' ) ) );
+		wp_set_current_user( self::$shop_manager_id );
 		$this->sut        = new \WP_Ability( ProductReviewReply::get_name(), ProductReviewReply::get_registration_args() );
-		$this->product_id = \WC_Helper_Product::create_simple_product()->get_id();
+		$this->product_id = self::$shared_product_id;
 	}

 	/**
diff --git a/plugins/woocommerce/tests/php/src/Internal/Abilities/Domain/ProductReviewUpdateTest.php b/plugins/woocommerce/tests/php/src/Internal/Abilities/Domain/ProductReviewUpdateTest.php
index c79c598fb90..96377c7d9dd 100644
--- a/plugins/woocommerce/tests/php/src/Internal/Abilities/Domain/ProductReviewUpdateTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/Abilities/Domain/ProductReviewUpdateTest.php
@@ -28,14 +28,47 @@ class ProductReviewUpdateTest extends \WC_Unit_Test_Case {
 	 */
 	private $product_id;

+	/**
+	 * A shop manager that every test acts as.
+	 *
+	 * @var int
+	 */
+	private static $shop_manager_id;
+
+	/**
+	 * The product every test reviews; each test's changes to it roll back.
+	 *
+	 * @var int
+	 */
+	private static $shared_product_id;
+
+	/**
+	 * Create the fixtures that no test changes beyond its own transaction.
+	 *
+	 * @param \WP_UnitTest_Factory $factory WordPress unit test factory.
+	 */
+	public static function wpSetUpBeforeClass( $factory ): void {
+		self::$shop_manager_id   = $factory->user->create( array( 'role' => 'shop_manager' ) );
+		self::$shared_product_id = self::with_direct_product_attribute_lookup_updates(
+			static fn() => \WC_Helper_Product::create_simple_product()
+		)->get_id();
+	}
+
+	/**
+	 * Delete the shared product, whose lookup rows the WordPress class cleanup leaves behind.
+	 */
+	public static function wpTearDownAfterClass(): void {
+		wc_get_product( self::$shared_product_id )->delete( true );
+	}
+
 	/**
 	 * Set up a shop manager and a product.
 	 */
 	public function setUp(): void {
 		parent::setUp();
-		wp_set_current_user( self::factory()->user->create( array( 'role' => 'shop_manager' ) ) );
+		wp_set_current_user( self::$shop_manager_id );
 		$this->sut        = new \WP_Ability( ProductReviewUpdate::get_name(), ProductReviewUpdate::get_registration_args() );
-		$this->product_id = \WC_Helper_Product::create_simple_product()->get_id();
+		$this->product_id = self::$shared_product_id;
 	}

 	/**
diff --git a/plugins/woocommerce/tests/php/src/Internal/Abilities/Domain/ProductReviewsQueryTest.php b/plugins/woocommerce/tests/php/src/Internal/Abilities/Domain/ProductReviewsQueryTest.php
index f673c116ddd..0435050f303 100644
--- a/plugins/woocommerce/tests/php/src/Internal/Abilities/Domain/ProductReviewsQueryTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/Abilities/Domain/ProductReviewsQueryTest.php
@@ -23,12 +23,28 @@ class ProductReviewsQueryTest extends \WC_Unit_Test_Case {
 	 */
 	private $sut;

+	/**
+	 * An administrator that every test acts as.
+	 *
+	 * @var int
+	 */
+	private static $administrator_id;
+
+	/**
+	 * Create the fixtures that no test changes beyond its own transaction.
+	 *
+	 * @param \WP_UnitTest_Factory $factory WordPress unit test factory.
+	 */
+	public static function wpSetUpBeforeClass( $factory ): void {
+		self::$administrator_id = $factory->user->create( array( 'role' => 'administrator' ) );
+	}
+
 	/**
 	 * Set up an authorized caller.
 	 */
 	public function setUp(): void {
 		parent::setUp();
-		wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
+		wp_set_current_user( self::$administrator_id );
 		$this->sut = new \WP_Ability( ProductReviewsQuery::get_name(), ProductReviewsQuery::get_registration_args() );
 	}

@@ -188,26 +204,77 @@ class ProductReviewsQueryTest extends \WC_Unit_Test_Case {
 	 * @testdox Should retain both ends of a large rating ranking and omit unrated products above the cap.
 	 */
 	public function test_large_ranking(): void {
-		for ( $i = 0; $i < 202; ++$i ) {
-			$product = self::factory()->post->create( array( 'post_type' => 'product' ) );
-			$this->review( $product, 100 > $i ? 1 : 5 );
+		$rank = new \ReflectionMethod( ProductReviewsQuery::class, 'rank' );
+		$rank->setAccessible( true );
+		$row  = static fn( int $id, float $rating ): array => array(
+			'product_id'     => $id,
+			'average_rating' => $rating,
+			'review_count'   => 1,
+		);
+		$rows = array( $row( 1, 0.0 ) );
+		for ( $id = 2; $id <= 203; ++$id ) {
+			$rows[] = $row( $id, 102 > $id ? 1.0 : ( 104 > $id ? 3.0 : 5.0 ) );
 		}
-		$unrated = self::factory()->post->create( array( 'post_type' => 'product' ) );
-		$this->review( $unrated, 0 );
-		$result = $this->sut->execute( array( 'per_page' => 1 ) );
-		$this->assertIsArray( $result );
-		$this->assertSame( 203, $result['total'] );
-		$this->assertSame( 203, $result['summary']['total_products'] );
-		$this->assertCount( 200, $result['by_product'] );
-		$ratings = array_count_values( array_map( 'strval', array_column( $result['by_product'], 'average_rating' ) ) );
+
+		$capped = $rank->invoke( null, $rows );
+
+		$this->assertCount( 200, $capped );
 		$this->assertSame(
 			array(
 				1 => 100,
 				5 => 100,
 			),
-			$ratings
+			array_count_values( array_map( 'intval', array_column( $capped, 'average_rating' ) ) ),
+			'Both ends of the rated ranking are kept, not its first entries.'
 		);
-		$this->assertNotContains( $unrated, array_column( $result['by_product'], 'product_id' ) );
+		$this->assertNotContains( 1, array_column( $capped, 'product_id' ) );
+
+		$rated_within_cap = $rank->invoke( null, array_merge( array_slice( $rows, 0, 3 ), array_slice( $rows, 5, 198 ), array( $row( 204, 0.0 ) ) ) );
+
+		$this->assertCount( 200, $rated_within_cap, 'Only the unrated products are dropped when the rated ones fit.' );
+		$this->assertNotContains( 0.0, array_column( $rated_within_cap, 'average_rating' ) );
+	}
+
+	/**
+	 * @testdox Should count every reviewed product in the summary when the ranking is capped.
+	 */
+	public function test_summary_counts_products_beyond_the_ranking_cap(): void {
+		global $wpdb;
+		$products = 201;
+		$marker   = wp_unique_id( 'ranking-cap-' );
+		$now      = current_time( 'mysql', true );
+
+		// Bulk rows keep this end-to-end check cheap; the factories cost seconds at this size.
+		$posts = array();
+		for ( $i = 0; $i < $products; ++$i ) {
+			$posts[] = $wpdb->prepare( "(%s, %s, '', '', '', '', '', 'publish', 'product', %s, %s, %s, %s)", $marker, '', $now, $now, $now, $now );
+		}
+		// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery -- Every row is prepared above.
+		$wpdb->query( "INSERT INTO {$wpdb->posts} (post_title, post_content, post_excerpt, to_ping, pinged, post_content_filtered, post_password, post_status, post_type, post_date, post_date_gmt, post_modified, post_modified_gmt) VALUES " . implode( ', ', $posts ) );
+		$product_ids = array_map( 'intval', $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_title = %s", $marker ) ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
+
+		$comments = array();
+		foreach ( $product_ids as $product_id ) {
+			$comments[] = $wpdb->prepare( "(%d, 'review', '1', 'Lovely item', 'Reviewer', '', '', '', %s, %s)", $product_id, $now, $now );
+		}
+		// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery -- Every row is prepared above.
+		$wpdb->query( "INSERT INTO {$wpdb->comments} (comment_post_ID, comment_type, comment_approved, comment_content, comment_author, comment_author_email, comment_author_url, comment_author_IP, comment_date, comment_date_gmt) VALUES " . implode( ', ', $comments ) );
+		$wpdb->query( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
+			$wpdb->prepare(
+				"INSERT INTO {$wpdb->commentmeta} (comment_id, meta_key, meta_value)
+				SELECT c.comment_ID, 'rating', '4' FROM {$wpdb->comments} c INNER JOIN {$wpdb->posts} p ON p.ID = c.comment_post_ID WHERE p.post_title = %s",
+				$marker
+			)
+		);
+		wp_cache_set_last_changed( 'posts' );
+		wp_cache_set_comments_last_changed();
+
+		$result = $this->sut->execute( array( 'per_page' => 1 ) );
+
+		$this->assertIsArray( $result );
+		$this->assertSame( $products, $result['total'] );
+		$this->assertSame( $products, $result['summary']['total_products'], 'The summary counts the products the ranking leaves out.' );
+		$this->assertCount( 200, $result['by_product'] );
 	}

 	/**
diff --git a/plugins/woocommerce/tests/php/src/Internal/Abilities/Domain/ProductTermWritesTest.php b/plugins/woocommerce/tests/php/src/Internal/Abilities/Domain/ProductTermWritesTest.php
index 97977926258..dc2a5770e19 100644
--- a/plugins/woocommerce/tests/php/src/Internal/Abilities/Domain/ProductTermWritesTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/Abilities/Domain/ProductTermWritesTest.php
@@ -35,6 +35,22 @@ class ProductTermWritesTest extends WC_Unit_Test_Case {
 	 */
 	private array $taxonomies_before;

+	/**
+	 * An administrator that every test acts as.
+	 *
+	 * @var int
+	 */
+	private static $administrator_id;
+
+	/**
+	 * Create the fixtures that no test changes beyond its own transaction.
+	 *
+	 * @param \WP_UnitTest_Factory $factory WordPress unit test factory.
+	 */
+	public static function wpSetUpBeforeClass( $factory ): void {
+		self::$administrator_id = $factory->user->create( array( 'role' => 'administrator' ) );
+	}
+
 	/**
 	 * Set up an administrator with extension fields switched off.
 	 */
@@ -48,7 +64,7 @@ class ProductTermWritesTest extends WC_Unit_Test_Case {
 		}
 		$this->taxonomies_before = get_taxonomies();
 		update_option( 'woocommerce_feature_extensible_abilities_enabled', 'no' );
-		wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
+		wp_set_current_user( self::$administrator_id );
 	}

 	/**
diff --git a/plugins/woocommerce/tests/php/src/Internal/Abilities/Domain/ProductTermsQueryTest.php b/plugins/woocommerce/tests/php/src/Internal/Abilities/Domain/ProductTermsQueryTest.php
index 2dfde379c53..2065ca3aa8a 100644
--- a/plugins/woocommerce/tests/php/src/Internal/Abilities/Domain/ProductTermsQueryTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/Abilities/Domain/ProductTermsQueryTest.php
@@ -25,6 +25,22 @@ class ProductTermsQueryTest extends \WC_Unit_Test_Case {
 	 */
 	private $saved_state = array();

+	/**
+	 * An administrator that every test acts as.
+	 *
+	 * @var int
+	 */
+	private static $administrator_id;
+
+	/**
+	 * Create the fixtures that no test changes beyond its own transaction.
+	 *
+	 * @param \WP_UnitTest_Factory $factory WordPress unit test factory.
+	 */
+	public static function wpSetUpBeforeClass( $factory ): void {
+		self::$administrator_id = $factory->user->create( array( 'role' => 'administrator' ) );
+	}
+
 	/**
 	 * Set up ability registration.
 	 */
@@ -37,7 +53,7 @@ class ProductTermsQueryTest extends \WC_Unit_Test_Case {
 			$property->setValue( null, array() );
 		}
 		update_option( 'woocommerce_feature_extensible_abilities_enabled', 'no' );
-		wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
+		wp_set_current_user( self::$administrator_id );
 	}

 	/**
diff --git a/plugins/woocommerce/tests/php/src/Internal/Abilities/Domain/ProductWritesTest.php b/plugins/woocommerce/tests/php/src/Internal/Abilities/Domain/ProductWritesTest.php
index 490cf3fa8ea..2126d36ec9e 100644
--- a/plugins/woocommerce/tests/php/src/Internal/Abilities/Domain/ProductWritesTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/Abilities/Domain/ProductWritesTest.php
@@ -12,13 +12,29 @@ use WC_Unit_Test_Case;
  */
 class ProductWritesTest extends WC_Unit_Test_Case {

+	/**
+	 * An administrator that every test acts as.
+	 *
+	 * @var int
+	 */
+	private static $administrator_id;
+
+	/**
+	 * Create the fixtures that no test changes beyond its own transaction.
+	 *
+	 * @param \WP_UnitTest_Factory $factory WordPress unit test factory.
+	 */
+	public static function wpSetUpBeforeClass( $factory ): void {
+		self::$administrator_id = $factory->user->create( array( 'role' => 'administrator' ) );
+	}
+
 	/**
 	 * Log in as an administrator, who may create, edit and publish products.
 	 */
 	public function setUp(): void {
 		parent::setUp();

-		wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
+		wp_set_current_user( self::$administrator_id );
 	}

 	/**