From 8eba3ce371f9c00bc7a0fb52714a1b40d6400c07 Mon Sep 17 00:00:00 2001 From: Shail Mehta Date: Wed, 25 Nov 2026 15:58:53 +0530 Subject: [PATCH 1/2] Tests: Cover `get_search_form()` return, aria_label, and boolean back-compat --- tests/phpunit/tests/general/getSearchForm.php | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 tests/phpunit/tests/general/getSearchForm.php diff --git a/tests/phpunit/tests/general/getSearchForm.php b/tests/phpunit/tests/general/getSearchForm.php new file mode 100644 index 0000000000000..09ae74f0640c4 --- /dev/null +++ b/tests/phpunit/tests/general/getSearchForm.php @@ -0,0 +1,57 @@ + false returns the form markup. + * + * @ticket 66757 + */ + public function test_get_search_form_returns_markup_when_echo_false() { + $form = get_search_form( array( 'echo' => false ) ); + + $this->assertIsString( $form ); + $this->assertStringContainsString( 'role="search"', $form ); + $this->assertStringContainsString( 'name="s"', $form ); + $this->assertStringContainsString( 'id="searchform"', $form ); + } + + /** + * Tests that aria_label is added to the default form markup. + * + * @ticket 66757 + */ + public function test_get_search_form_includes_aria_label() { + $form = get_search_form( + array( + 'echo' => false, + 'aria_label' => 'Site search', + ) + ); + + $this->assertStringContainsString( 'aria-label="Site search"', $form ); + } + + /** + * Tests the boolean back-compat argument still controls returning vs echoing. + * + * @ticket 66757 + */ + public function test_get_search_form_boolean_echo_back_compat() { + $form = get_search_form( false ); + + $this->assertIsString( $form ); + $this->assertStringContainsString( 'name="s"', $form ); + + $this->expectOutputRegex( '/name="s"/' ); + get_search_form( true ); + } +} From 0aeb328d2b76df3b0047dbcaf3b1a45066bc7673 Mon Sep 17 00:00:00 2001 From: Shail Mehta Date: Thu, 26 Nov 2026 10:32:52 +0530 Subject: [PATCH 2/2] Refactor get_search_form tests for aria_label and HTML5 --- tests/phpunit/tests/general/getSearchForm.php | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/tests/phpunit/tests/general/getSearchForm.php b/tests/phpunit/tests/general/getSearchForm.php index 09ae74f0640c4..a2b847b205711 100644 --- a/tests/phpunit/tests/general/getSearchForm.php +++ b/tests/phpunit/tests/general/getSearchForm.php @@ -13,7 +13,7 @@ class Tests_General_GetSearchForm extends WP_UnitTestCase { /** * Tests that echo => false returns the form markup. * - * @ticket 66757 + * @ticket 66830 */ public function test_get_search_form_returns_markup_when_echo_false() { $form = get_search_form( array( 'echo' => false ) ); @@ -25,25 +25,30 @@ public function test_get_search_form_returns_markup_when_echo_false() { } /** - * Tests that aria_label is added to the default form markup. + * Tests that aria_label is escaped and HTML5 markup is used when supported. * - * @ticket 66757 + * @ticket 66830 */ public function test_get_search_form_includes_aria_label() { + add_theme_support( 'html5', array( 'search-form' ) ); + $form = get_search_form( array( 'echo' => false, - 'aria_label' => 'Site search', + 'aria_label' => 'News & reviews', ) ); - $this->assertStringContainsString( 'aria-label="Site search"', $form ); + $this->assertStringContainsString( 'aria-label="News & reviews"', $form, 'The aria-label attribute should be escaped.' ); + $this->assertStringContainsString( 'class="search-form"', $form, 'The HTML5 form class should be used.' ); + $this->assertStringContainsString( 'type="search"', $form, 'The HTML5 search input type should be used.' ); + $this->assertStringNotContainsString( 'id="searchform"', $form, 'The XHTML form ID should not be used.' ); } /** * Tests the boolean back-compat argument still controls returning vs echoing. * - * @ticket 66757 + * @ticket 66830 */ public function test_get_search_form_boolean_echo_back_compat() { $form = get_search_form( false );