Commit c8426aba9d6 for woocommerce
commit c8426aba9d6e8d90fad45f32a3523e9bde097d01
Author: Taha Paksu <3295+tpaksu@users.noreply.github.com>
Date: Wed May 6 13:38:49 2026 +0300
Fix flaky review-order-url email test setUp (#64650)
Seed the Review Order page in the email-test setUp
The bootstrap install seeds the WC-managed Review Order page, but the
stored `woocommerce_review_order_page_id` option can outlive the actual
post across test runs. When that happens `Endpoint::get_url()` resolves
to an empty permalink, which makes
WC_Email_Customer_Review_Request_Test::test_review_order_url_shape
fail with: '' matches PCRE pattern "#review-order[/=]<id>#".
Defensively re-create the page in setUp when the stored option doesn't
resolve to a real post. Test-only change; production code untouched.
Surfaced by the 10.8 backport CI on PR #64628.
diff --git a/plugins/woocommerce/tests/php/includes/emails/class-wc-email-customer-review-request-test.php b/plugins/woocommerce/tests/php/includes/emails/class-wc-email-customer-review-request-test.php
index fc229759cd5..a2fb7805a25 100644
--- a/plugins/woocommerce/tests/php/includes/emails/class-wc-email-customer-review-request-test.php
+++ b/plugins/woocommerce/tests/php/includes/emails/class-wc-email-customer-review-request-test.php
@@ -25,9 +25,37 @@ class WC_Email_Customer_Review_Request_Test extends \WC_Unit_Test_Case {
require_once $bootstrap->plugin_dir . '/includes/emails/class-wc-email.php';
require_once $bootstrap->plugin_dir . '/includes/emails/class-wc-email-customer-review-request.php';
+ $this->ensure_review_order_page();
+
$this->sut = new WC_Email_Customer_Review_Request();
}
+ /**
+ * Make sure the WC-managed Review Order page exists for tests that build a
+ * URL through the endpoint. The bootstrap install seeds the page, but the
+ * stored option can outlive the post across test runs, so re-create it
+ * defensively if `woocommerce_review_order_page_id` doesn't resolve.
+ */
+ private function ensure_review_order_page(): void {
+ $page_id = (int) get_option( 'woocommerce_review_order_page_id' );
+ if ( $page_id > 0 && get_post( $page_id ) instanceof \WP_Post ) {
+ return;
+ }
+
+ $new_page_id = wp_insert_post(
+ array(
+ 'post_title' => 'Review your order',
+ 'post_name' => 'review-order',
+ 'post_status' => 'publish',
+ 'post_type' => 'page',
+ 'post_content' => '<!-- wp:shortcode -->[woocommerce_review_order]<!-- /wp:shortcode -->',
+ )
+ );
+ if ( ! is_wp_error( $new_page_id ) && $new_page_id > 0 ) {
+ update_option( 'woocommerce_review_order_page_id', $new_page_id );
+ }
+ }
+
/**
* @testdox Email is disabled by default so it has no effect on sites that don't opt in.
*/