Repository navigation
Tests: Add unit test coverage for WP_Widget_Search - #14184
rejaulalomkhan wants to merge 3 commits into
Conversation
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.
|
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 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. |
huzaifaalmesbah
left a comment
There was a problem hiding this comment.
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
| /** | ||
| * Clean up global post and query state after each test. | ||
| */ | ||
| public function tear_down() { | ||
| parent::tear_down(); | ||
| } |
There was a problem hiding this comment.
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.
| $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", | ||
| ); |
There was a problem hiding this comment.
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?
Description
Adds a test class for
WP_Widget_Search, which had no tests. The tests cover the registration settings, the title output fromwidget()(default and custom titles), thewidget_titlefilter arguments and omitting empty filtered titles, title sanitization inupdate(), and the settings form output inform().This is a test-only change; no production code is modified.
Testing Instructions
npm run test:php -- --filter 'Tests_Widgets_wpWidgetSearch'npm run test:php -- --filter 'Tests_Widgets_wpWidgetSearch' -c tests/phpunit/multisite.xmlnpm run test:php -- --filter 'Tests_Widgets_wpWidgetSearch' --order-by=randomnpm run test:php -- --group widgetsnode ./tools/local-env/scripts/docker.js run --rm php ./vendor/bin/phpcs tests/phpunit/tests/widgets/wpWidgetSearch.phpUse 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.