Commit 1936b4b9704 for woocommerce
commit 1936b4b97044b2475e80d998f4fe4aead957d5fe
Author: Albert Juhé Lluveras <contact@albertjuhe.com>
Date: Tue Sep 15 10:55:17 2026 +0200
Block-based Single Product template password-form logic: add extra test (#68695)
* Block-based Single Product template password-form logic: add extra test
* Add changelog
diff --git a/plugins/woocommerce/changelog/fix-add-extra-test-68477 b/plugins/woocommerce/changelog/fix-add-extra-test-68477
new file mode 100644
index 00000000000..c958254da41
--- /dev/null
+++ b/plugins/woocommerce/changelog/fix-add-extra-test-68477
@@ -0,0 +1,5 @@
+Significance: patch
+Type: dev
+Comment: Block-based Single Product template password-form logic: add extra test
+
+
diff --git a/plugins/woocommerce/tests/php/src/Blocks/Templates/SingleProductTemplateTests.php b/plugins/woocommerce/tests/php/src/Blocks/Templates/SingleProductTemplateTests.php
index e528734943e..54f9c7c844f 100644
--- a/plugins/woocommerce/tests/php/src/Blocks/Templates/SingleProductTemplateTests.php
+++ b/plugins/woocommerce/tests/php/src/Blocks/Templates/SingleProductTemplateTests.php
@@ -426,4 +426,63 @@ class SingleProductTemplateTests extends WP_UnitTestCase {
TemplateContentUtils::strip_whitespace_and_password_form_ids( $result )
);
}
+
+ /**
+ * @testdox Adds the password form when generic and product-related blocks are on the template.
+ */
+ public function test_replace_single_product_blocks_next_to_paragraph_with_input_form() {
+ $default_single_product_template = '
+ <!-- wp:template-part {"slug":"header","theme":"twentytwentythree","tagName":"header"} /-->
+ <!-- wp:columns {"align":"wide"} -->
+ <div class="wp-block-columns alignwide">
+ <!-- wp:column {"width":"512px"} -->
+ <div class="wp-block-column" style="flex-basis:512px">
+ <!-- wp:woocommerce/product-image-gallery /-->
+ </div>
+ <!-- /wp:column -->
+ <!-- wp:column -->
+ <div class="wp-block-column">
+ <!-- wp:woocommerce/product-price {"isDescendentOfSingleProductTemplate":true} /-->
+ <!-- wp:paragraph -->
+ <p>Additional information.</p>
+ <!-- /wp:paragraph -->
+ <!-- wp:woocommerce/add-to-cart-form /-->
+ </div>
+ <!-- /wp:column -->
+ </div>
+ <!-- /wp:columns -->
+ <!-- wp:template-part {"slug":"footer","theme":"twentytwentythree","tagName":"footer"} /-->';
+
+ $expected_single_product_template = sprintf(
+ '
+ <!-- wp:template-part {"slug":"header","theme":"twentytwentythree","tagName":"header"} /-->
+ <!-- wp:columns {"align":"wide"} -->
+ <div class="wp-block-columns alignwide">
+ <!-- wp:column {"width":"512px"} -->
+ <div class="wp-block-column" style="flex-basis:512px">
+ <!-- wp:html -->%s<!-- /wp:html -->
+ </div>
+ <!-- /wp:column -->
+ <!-- wp:column -->
+ <div class="wp-block-column">
+ <!-- wp:paragraph -->
+ <p>Additional information.</p>
+ <!-- /wp:paragraph -->
+ </div>
+ <!-- /wp:column -->
+ </div>
+ <!-- /wp:columns -->
+ <!-- wp:template-part {"slug":"footer","theme":"twentytwentythree","tagName":"footer"} /-->',
+ get_the_password_form()
+ );
+
+ $result = SingleProductTemplate::add_password_form(
+ $default_single_product_template
+ );
+
+ $this->assertEquals(
+ TemplateContentUtils::strip_whitespace_and_password_form_ids( $expected_single_product_template ),
+ TemplateContentUtils::strip_whitespace_and_password_form_ids( $result )
+ );
+ }
}