Commit 208cc797ed0 for woocommerce

commit 208cc797ed0ca2b0857da140234f9fe50e413999
Author: Taha Paksu <3295+tpaksu@users.noreply.github.com>
Date:   Mon Nov 2 14:01:29 2026 +0300

    Fix the PHPUnit suite on WordPress 7.2's isolated test upload directory (#70515)

    * Derive PHPUnit upload paths from wp_upload_dir() instead of hardcoding wp-content/uploads

    * Add changefile(s) from automation for the following project(s): woocommerce

    * Add temporary upload diagnostics for the WordPress 7.2 pre-release job

    * Revert "Add temporary upload diagnostics for the WordPress 7.2 pre-release job"

    This reverts commit a2861e6cfb57b10aacddc6b17267bfa31debc893.

    * Recreate the test upload directory the WordPress bootstrap deletes after loading

    * Recreate the test upload directory only on WordPress 7.2 and later

    * Keep the pre-7.2 upload path expectations behind a WordPress version check

    * Add changefile(s) from automation for the following project(s): woocommerce

    ---------

    Co-authored-by: woocommercebot <woocommercebot@users.noreply.github.com>

diff --git a/plugins/woocommerce/changelog/70515-fix-wp-7.2-test-suite-uploads b/plugins/woocommerce/changelog/70515-fix-wp-7.2-test-suite-uploads
new file mode 100644
index 00000000000..59e70cb017e
--- /dev/null
+++ b/plugins/woocommerce/changelog/70515-fix-wp-7.2-test-suite-uploads
@@ -0,0 +1,5 @@
+Significance: patch
+Type: dev
+Comment: Fix the PHPUnit suite on WordPress 7.2's isolated test upload directory; test-only, no production change.
+
+
diff --git a/plugins/woocommerce/tests/legacy/bootstrap.php b/plugins/woocommerce/tests/legacy/bootstrap.php
index 9e257d95f47..1457d0af958 100644
--- a/plugins/woocommerce/tests/legacy/bootstrap.php
+++ b/plugins/woocommerce/tests/legacy/bootstrap.php
@@ -92,6 +92,14 @@ class WC_Unit_Tests_Bootstrap {
 		// load the WP testing environment.
 		require_once $this->wp_tests_dir . '/includes/bootstrap.php';

+		/*
+		 * WordPress 7.2's test bootstrap deletes its isolated upload directory after loading, by
+		 * which point wp_upload_dir() has memoised the path as created, so nothing recreates it.
+		 */
+		if ( version_compare( $GLOBALS['wp_version'], '7.2-alpha', '>=' ) ) {
+			wp_mkdir_p( wp_upload_dir()['path'] );
+		}
+
 		// Ensure theme install tests use direct filesystem method.
 		if ( ! defined( 'FS_METHOD' ) ) {
 			define( 'FS_METHOD', 'direct' );
diff --git a/plugins/woocommerce/tests/legacy/unit-tests/integrations/maxmind-geolocation/class-wc-tests-maxmind-database.php b/plugins/woocommerce/tests/legacy/unit-tests/integrations/maxmind-geolocation/class-wc-tests-maxmind-database.php
index d80b4d56b27..f4cafecb884 100644
--- a/plugins/woocommerce/tests/legacy/unit-tests/integrations/maxmind-geolocation/class-wc-tests-maxmind-database.php
+++ b/plugins/woocommerce/tests/legacy/unit-tests/integrations/maxmind-geolocation/class-wc-tests-maxmind-database.php
@@ -28,8 +28,13 @@ class WC_Tests_MaxMind_Database extends WC_Unit_Test_Case {
 	public function test_database_path_filters() {
 		$database_service = new WC_Integration_MaxMind_Database_Service( '' );

+		// WordPress 7.2 moves test uploads out of wp-content/uploads.
+		$uploads_dir = version_compare( $GLOBALS['wp_version'], '7.2-alpha', '>=' )
+			? trailingslashit( wp_upload_dir()['basedir'] ) . 'woocommerce_uploads/'
+			: WP_CONTENT_DIR . '/uploads/woocommerce_uploads/';
+
 		$path = $database_service->get_database_path();
-		$this->assertEquals( WP_CONTENT_DIR . '/uploads/woocommerce_uploads/' . WC_Integration_MaxMind_Database_Service::DATABASE . WC_Integration_MaxMind_Database_Service::DATABASE_EXTENSION, $path );
+		$this->assertEquals( $uploads_dir . WC_Integration_MaxMind_Database_Service::DATABASE . WC_Integration_MaxMind_Database_Service::DATABASE_EXTENSION, $path );

 		add_filter( 'woocommerce_geolocation_local_database_path', array( $this, 'filter_database_path_deprecated' ), 1, 2 );
 		$path = $database_service->get_database_path();
@@ -47,7 +52,7 @@ class WC_Tests_MaxMind_Database extends WC_Unit_Test_Case {
 		$database_service = new WC_Integration_MaxMind_Database_Service( 'testing' );

 		$path = $database_service->get_database_path();
-		$this->assertEquals( WP_CONTENT_DIR . '/uploads/woocommerce_uploads/testing-' . WC_Integration_MaxMind_Database_Service::DATABASE . WC_Integration_MaxMind_Database_Service::DATABASE_EXTENSION, $path );
+		$this->assertEquals( $uploads_dir . 'testing-' . WC_Integration_MaxMind_Database_Service::DATABASE . WC_Integration_MaxMind_Database_Service::DATABASE_EXTENSION, $path );
 	}

 	/**
diff --git a/plugins/woocommerce/tests/php/includes/class-wc-download-handler-tests.php b/plugins/woocommerce/tests/php/includes/class-wc-download-handler-tests.php
index 4cb9f4d2271..6fffbd17416 100644
--- a/plugins/woocommerce/tests/php/includes/class-wc-download-handler-tests.php
+++ b/plugins/woocommerce/tests/php/includes/class-wc-download-handler-tests.php
@@ -168,13 +168,13 @@ class WC_Download_Handler_Tests extends \WC_Unit_Test_Case {
 	public function test_downloads_remaining_count(): void {
 		self::remove_download_handlers();
 		// phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_file_put_contents -- Ok for unit tests.
-		file_put_contents( WP_CONTENT_DIR . '/uploads/woocommerce_uploads/supersheet-123.ods', str_pad( '', 100 ) );
+		file_put_contents( $this->woocommerce_upload_path( 'supersheet-123.ods' ), str_pad( '', 100 ) );

 		list( $product, $order ) = $this->build_downloadable_product_and_order_one(
 			array(
 				array(
 					'name' => 'Supersheet 123',
-					'file' => content_url( 'uploads/woocommerce_uploads/supersheet-123.ods' ),
+					'file' => $this->woocommerce_upload_url( 'supersheet-123.ods' ),
 				),
 			)
 		);
@@ -948,7 +948,7 @@ class WC_Download_Handler_Tests extends \WC_Unit_Test_Case {
 				array(
 					array(
 						'name' => 'Protected download',
-						'file' => content_url( 'uploads/woocommerce_uploads/protected-download.pdf' ),
+						'file' => $this->woocommerce_upload_url( 'protected-download.pdf' ),
 					),
 				)
 			);
@@ -993,7 +993,7 @@ class WC_Download_Handler_Tests extends \WC_Unit_Test_Case {
 			array(
 				array(
 					'name' => 'Protected download',
-					'file' => content_url( 'uploads/woocommerce_uploads/protected-download.pdf' ),
+					'file' => $this->woocommerce_upload_url( 'protected-download.pdf' ),
 				),
 			)
 		);
@@ -1018,7 +1018,7 @@ class WC_Download_Handler_Tests extends \WC_Unit_Test_Case {
 			array(
 				array(
 					'name' => 'Protected download',
-					'file' => content_url( 'uploads/woocommerce_uploads/protected-download.pdf' ),
+					'file' => $this->woocommerce_upload_url( 'protected-download.pdf' ),
 				),
 			)
 		);
@@ -1045,7 +1045,7 @@ class WC_Download_Handler_Tests extends \WC_Unit_Test_Case {
 				array(
 					array(
 						'name' => 'Protected download',
-						'file' => content_url( 'uploads/woocommerce_uploads/protected-download.pdf' ),
+						'file' => $this->woocommerce_upload_url( 'protected-download.pdf' ),
 					),
 				)
 			);
@@ -1095,6 +1095,32 @@ class WC_Download_Handler_Tests extends \WC_Unit_Test_Case {
 		);
 	}

+	/**
+	 * Filesystem path of a file in the WooCommerce uploads directory, which WordPress 7.2
+	 * relocates for the test suite.
+	 *
+	 * @param string $file File name.
+	 * @return string
+	 */
+	private function woocommerce_upload_path( string $file ): string {
+		return version_compare( $GLOBALS['wp_version'], '7.2-alpha', '>=' )
+			? trailingslashit( wp_upload_dir()['basedir'] ) . 'woocommerce_uploads/' . $file
+			: WP_CONTENT_DIR . '/uploads/woocommerce_uploads/' . $file;
+	}
+
+	/**
+	 * URL of a file in the WooCommerce uploads directory, which WordPress 7.2 relocates for
+	 * the test suite.
+	 *
+	 * @param string $file File name.
+	 * @return string
+	 */
+	private function woocommerce_upload_url( string $file ): string {
+		return version_compare( $GLOBALS['wp_version'], '7.2-alpha', '>=' )
+			? trailingslashit( wp_upload_dir()['baseurl'] ) . 'woocommerce_uploads/' . $file
+			: content_url( 'uploads/woocommerce_uploads/' . $file );
+	}
+
 	/**
 	 * Creates a downloadable product, and then places (and completes) an order for that
 	 * object.