Skip to content

Tests: Add unit test coverage for WP_Widget_Search - #14184

Open
rejaulalomkhan wants to merge 3 commits into
WordPress:trunkfrom
rejaulalomkhan:tests/widget-search
Open

rejaulalomkhan wants to merge 3 commits into
WordPress:trunkfrom
rejaulalomkhan:tests/widget-search

Conversation

@rejaulalomkhan

@rejaulalomkhan rejaulalomkhan commented Oct 11, 2026 •

Copy link
Copy Markdown

Description

Adds a test class for WP_Widget_Search, which had no tests. The tests cover the registration settings, the title output from widget() (default and custom titles), the widget_title filter arguments and omitting empty filtered titles, title sanitization in update(), and the settings form output in form().

This is a test-only change; no production code is modified.

Testing Instructions

  1. Run the tests on single site:
    npm run test:php -- --filter 'Tests_Widgets_wpWidgetSearch'
  2. Run them on multisite:
    npm run test:php -- --filter 'Tests_Widgets_wpWidgetSearch' -c tests/phpunit/multisite.xml
  3. Run them in random order:
    npm run test:php -- --filter 'Tests_Widgets_wpWidgetSearch' --order-by=random
  4. Run the whole group to confirm nothing else is affected:
    npm run test:php -- --group widgets
  5. Run PHPCS on the test file:
    node ./tools/local-env/scripts/docker.js run --rm php ./vendor/bin/phpcs tests/phpunit/tests/widgets/wpWidgetSearch.php

Use of AI Tools

Yes, an AI assistant was used for scaffolding and initial test generation. All tests, assertions, and coding standards were manually reviewed, verified, and run locally.

Trac ticket: https://core.trac.wordpress.org/ticket/65819


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request outside of WordPress Core Trac.

Adds a test class for WP_Widget_Search, which had no tests. The tests cover the registration settings, the title output from widget() with default and custom titles, the widget_title filter arguments and omitting empty filtered titles, title sanitization in update(), and the settings form output in form().

This is a test-only change; no production code is modified.

See #65819.
@github-actions

github-actions Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props rejaulalomkhan, huzaifaalmesbah.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@huzaifaalmesbah huzaifaalmesbah left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this, @rejaulalomkhan! I really appreciate you giving WP_Widget_Search its own test class; the constructor, widget(), update() and form() are all covered now, and the '0' title and quoted title cases in the data providers are a nice touch.

I checked the tests against the widget class and they match what the source does.

One small thing on the description: it is missing the ## Use of AI Tools section from the pull request template. Could you add it, even if the answer is that none were used?

I left a couple of small notes inline as well.

AI Review: Opus 5.5

Comment on lines +18 to +23
/**
* Clean up global post and query state after each test.
*/
public function tear_down() {
parent::tear_down();
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This tear_down() only calls the parent, so it can be removed. The comment also mentions cleaning up post and query state, which doesn't happen here.

Comment on lines +52 to +57
$args = array(
'before_widget' => '<section id="search-2" class="widget widget_search">',
'after_widget' => "</section>\n",
'before_title' => '<h2 class="widget-title">',
'after_title' => "</h2>\n",
);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same $args array is repeated in five tests. Would you be open to moving it to a class property, the way wpWidgetArchives.php and wpWidgetCalendar.php in your other PRs do?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants