Skip to content

test for wp_maybe_load_widgets#3682

Open
pbearne wants to merge 5 commits into
WordPress:trunkfrom
pbearne:57201_wp_maybe_load_widgets
Open

test for wp_maybe_load_widgets#3682
pbearne wants to merge 5 commits into
WordPress:trunkfrom
pbearne:57201_wp_maybe_load_widgets

Conversation

@pbearne

@pbearne pbearne commented Nov 25, 2022

Copy link
Copy Markdown

@costdev costdev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the PR @pbearne and for working to implement standards early to save time in reviewing / implementing review feedback! Much appreciated and look forward to seeing that in future PRs!

I've left some thoughts below which should help with an unmet standard (message parameter) and test stability. 🙂

Comment thread tests/phpunit/tests/functions/wpMaybeLoadWidgets.php Outdated
* @ticket 57201
*/
public function test_wp_maybe_load_widgets() {
$this->assertFalse( class_exists( 'WP_Nav_Menu_Widget' ) );

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A couple of thoughts:

  1. Test methods with multiple assertions should have a message parameter to explain what went wrong.

For similar assertions (i.e. multiple assertion of class_exists()), the message can be:

  • WP_Nav_Menu_Widget should not exist before doing something.
  • WP_Nav_Menu_Widget should not exist after doing something.
  • WP_Nav_Menu_Widget should exist after doing something.
  1. It may be best to split this into two test methods:
  • test_wp_maybe_load_widgets_should_respect_falsy_load_default_widgets_filter() - Use a data provider with falsy values to send to the filter hook via static closure, then assertFalse() for class_exists() and has_action().
  • test_wp_maybe_load_widgets_should_load_widgets() - assertFalse() for class_exists() and has_action(), then call wp_maybe_load_widgets(), then assertTrue() on class_exists() and has_action() (all assertions should have the message parameter)

Co-authored-by: Colin Stewart <79332690+costdev@users.noreply.github.com>
@github-actions

github-actions Bot commented Jun 26, 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.

Unlinked Accounts

The following contributors have not linked their GitHub and WordPress.org accounts: @pbearne@git.wordpress.org.

Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases.

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

Props pbearne, costdev.

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

@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@pbearne pbearne requested a review from costdev June 26, 2026 17:54
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