Skip to content

Tests: Add unit test coverage for WP_Widget_Meta - #14181

Open
huzaifaalmesbah wants to merge 1 commit into
WordPress:trunkfrom
huzaifaalmesbah:tests/widget-meta
Open

huzaifaalmesbah wants to merge 1 commit into
WordPress:trunkfrom
huzaifaalmesbah:tests/widget-meta

Conversation

@huzaifaalmesbah

Copy link
Copy Markdown
Member

Description

Adds a test class for WP_Widget_Meta, which had no tests. The tests cover the registration settings, the title shown by widget() (custom, default and falsy values), the widget_title filter arguments and the omitted title wrapper when it returns an empty string, the <nav> wrapper and its aria-label for the html5 format and its absence for xhtml, the log in, feed and WordPress.org links for a logged-out visitor, the Site Admin and log out links for a logged-in user, the widget_meta_poweredby filter arguments and return value, and the wp_meta action. They also cover title sanitization in update(), that update() keeps the other settings of the old instance, and the escaped title field rendered by 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_wpWidgetMeta'
  2. Run them on multisite:
    npm run test:php -- --filter 'Tests_Widgets_wpWidgetMeta' -c tests/phpunit/multisite.xml
  3. Run them in random order:
    npm run test:php -- --filter 'Tests_Widgets_wpWidgetMeta' --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/wpWidgetMeta.php

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

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Brainstorming edge-case scenarios and drafting test boilerplate; test architecture, assertions, and local PHPUnit verification were written and validated by me.

@github-actions

github-actions Bot commented Oct 10, 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 huzaifaalmesbah, rejaulalomkhan.

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

@rejaulalomkhan

Copy link
Copy Markdown

Great work adding comprehensive test coverage for WP_Widget_Meta, @huzaifaalmesbah!

The suite nicely covers both logged-in and logged-out views, the wp_meta hook placement, and the widget_meta_poweredby filter.

A couple of minor observations:

  1. In test_widget_displays_links_for_logged_in_user(), switching users with wp_set_current_user() can sometimes leak the authenticated state into subsequent tests if not reset in tear_down(). Calling wp_set_current_user( 0 ) in tear_down() might add an extra layer of test isolation.
  2. For test_widget_displays_links_for_logged_out_visitor(), would it make sense to also assert that the Register link is displayed when users_can_register is 1?

Overall, the class structure is very clean and adheres well to Core conventions!

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