Repository navigation
Tests: Cover get_search_form() return, aria_label escaping, HTML5 markup, and boolean back-compat - #16237
Tests: Cover get_search_form() return, aria_label escaping, HTML5 markup, and boolean back-compat#16237shail-mehta wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the added get_search_form() unit coverage.
No open issues 🎉
What changed in this PR
Adds dedicated unit coverage for WordPress’s get_search_form() to protect return behavior, accessibility labeling, and boolean argument compatibility.
Changes:
- Checks that
echo => falsereturns a string containing default XHTML form markup. - Verifies that
aria_labelappears in the generated markup. - Tests that legacy boolean arguments control returning versus echoing the form.
| File | Description |
|---|---|
tests/phpunit/tests/general/getSearchForm.php |
Adds three tests covering form returns, accessibility labeling, and boolean backward compatibility. |
Review effort: Balanced
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
|
|
||
| $this->expectOutputRegex( '/name="s"/' ); | ||
| get_search_form( true ); | ||
| } |
There was a problem hiding this comment.
All three tests use the XHTML markup. The HTML5 branch, which most modern themes use, isn't covered yet. This test covers it. I ran it locally, and it fails when the format is forced to xhtml. set_up() already removes html5 support before each test, so no cleanup is needed:
| } | |
| } | |
| /** | |
| * Tests that the HTML5 markup is used when the theme supports it. | |
| * | |
| * @ticket 66757 | |
| */ | |
| public function test_get_search_form_uses_html5_markup_with_theme_support() { | |
| add_theme_support( 'html5', array( 'search-form' ) ); | |
| $form = get_search_form( array( 'echo' => false ) ); | |
| $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.' ); | |
| } |
lancewillett
left a comment
There was a problem hiding this comment.
Please exercise the label with a value such as News & reviews and expect News & reviews in the attribute. The current three tests still passed when I removed the escaping. Changing only that fixture caught the regression. You can make that same case use HTML5 search-form support to cover Mukesh’s point without adding a fourth test.
Before landing, please link a ticket in the component that owns the code under test, per the 7.3 ticket guidance. Related coverage can share a component ticket.
AI review · gpt-6.2-astra
get_search_form() return, aria_label, and boolean back-compat|
Thanks for the review! I've addressed both points. The aria_label test now uses News & reviews and asserts the escaped |
lancewillett
left a comment
There was a problem hiding this comment.
The ampersand makes the escaping assertion meaningful: dropping esc_attr() failed this case. It also exercises the HTML5 branch. Core resets HTML5 theme support between tests, and the class passed in both site modes.
AI review · gpt-6.2-astra
Trac ticket: #66830
What
Adds unit tests for
get_search_form()covering:echo => false→ returns default XHTML search form markup as a stringaria_label+ HTML5search-formtheme support → escapesaria_label(News & reviews→aria-label="News & reviews") and renders HTML5 markup (class="search-form",type="search", withoutid="searchform")falsereturns markup,trueechoes itWhy
get_search_form()had no dedicated coverage. Removing theecho => falsereturn path,aria_labelescaping, HTML5 markup branch, or boolean$echoback-compat left existing tests green.How
New
Tests_General_GetSearchFormasserts fixed substrings (role="search",name="s",id="searchform",aria-label="News & reviews",class="search-form",type="search"), not values derived by re-callingget_search_form()for an expected baseline.WP_UnitTestCase::set_up()resets theme support before each test, so the default tests exercise XHTML markup and thearia_labeltest enablesadd_theme_support( 'html5', array( 'search-form' ) )without extra teardown.Testing
npm run test:php -- --filter Tests_General_GetSearchForm— 3 tests passUse of AI Tools