Opened 2 days ago
Last modified 2 days ago
#66830 new enhancement
Add unit tests for get_search_form()
| Reported by: | shailu25 | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | General | Version: | |
| Severity: | normal | Keywords: | has-patch has-unit-tests |
| Cc: | Focuses: | tests |
Description
Add dedicated PHPUnit coverage for get_search_form() in tests/phpunit/tests/general/getSearchForm.php.
Covers:
echo => falsereturning default XHTML search form markup as a string (role="search",name="s",id="searchform").- Escaping of the
aria_labelattribute (e.g.News & reviews->aria-label="News & reviews") and HTML5 search form markup (class="search-form",type="search", withoutid="searchform") whenhtml5search-formtheme support is enabled. - Boolean
$echobackward compatibility (falsereturns markup,trueechoes it).
Change History (2)
This ticket was mentioned in PR #16237 on WordPress/wordpress-develop by @shailu25.
2 days ago
#1
- Keywords has-patch has-unit-tests added
@shailu25 commented on PR #16237:
2 days ago
#2
Thanks for the review! I've addressed both points.
The aria_label test now uses News & reviews and asserts the escaped aria-label="News & reviews". It also enables html5 search-form theme support, so it covers the HTML5 markup without adding a fourth test. The @ticket tags and PR description now link #66830.
Note:
See TracTickets
for help on using tickets.
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