Make WordPress Core

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 => false returning default XHTML search form markup as a string (role="search", name="s", id="searchform").
  • Escaping of the aria_label attribute (e.g. News & reviews -> aria-label="News & reviews") and HTML5 search form markup (class="search-form", type="search", without id="searchform") when html5 search-form theme support is enabled.
  • Boolean $echo backward compatibility (false returns markup, true echoes 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

Trac ticket: #66830

What

Adds unit tests for get_search_form() covering:

  • echo => false → returns default XHTML search form markup as a string
  • aria_label + HTML5 search-form theme support → escapes aria_label (News & reviews → aria-label="News & reviews") and renders HTML5 markup (class="search-form", type="search", without id="searchform")
  • boolean back-compat argument → false returns markup, true echoes it

Why

get_search_form() had no dedicated coverage. Removing the echo => false return path, aria_label escaping, HTML5 markup branch, or boolean $echo back-compat left existing tests green.

How

New Tests_General_GetSearchForm asserts fixed substrings (role="search", name="s", id="searchform", aria-label="News & reviews", class="search-form", type="search"), not values derived by re-calling get_search_form() for an expected baseline.

WP_UnitTestCase::set_up() resets theme support before each test, so the default tests exercise XHTML markup and the aria_label test enables add_theme_support( 'html5', array( 'search-form' ) ) without extra teardown.

Testing

  • npm run test:php -- --filter Tests_General_GetSearchForm — 3 tests pass
  • PHPCS clean

Use of AI Tools

  • Cursor

​@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.