Skip to content

Tests: Reset the entity actions registry before each Tests_Entity_Actions test. - #16259

Open
mayankmajeji wants to merge 2 commits into
WordPress:trunkfrom
mayankmajeji:tests/66755-entity-actions-registry
Open

mayankmajeji wants to merge 2 commits into
WordPress:trunkfrom
mayankmajeji:tests/66755-entity-actions-registry

Conversation

@mayankmajeji

@mayankmajeji mayankmajeji commented Nov 26, 2026 •

Copy link
Copy Markdown

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

Tests_Entity_Actions::set_up() replaces register_core_entity_actions() on wp_entity_actions_api_init with the test defaults (the rename and trash actions of pages), but it only resets the WP_Entity_Actions_Registry singleton in tear_down(). When an earlier class has already read the registry, the first test of the class gets that registry, which holds the actions WordPress registers, and wp_entity_actions_api_init does not fire again.

That happens after Tests_Blocks_Editor::test_block_editor_rest_api_preload_discards_assets_enqueued_during_preload(), which runs the block editor preload and so reads the registry with the core actions. If test_the_preloaded_actions_path_serves_the_actions() is the first Tests_Entity_Actions test to run after it, the preloaded response for pages holds the 11 core actions instead of the 2 defaults:

Failed asserting that two arrays are identical.
-    0 => 'rename-post'
-    1 => 'move-to-trash'
+    0 => 'view-post'
+    1 => 'view-post-revisions'
+    2 => 'rename-post'
...

What changes

  • Tests_Entity_Actions::set_up() also resets the registry, after hooking the test defaults, so every test starts from an empty registry as the class expects.

Testing

Locally with PHP 8.4.28, MySQL 9.7.4 and PHPUnit 9.6.39, on trunk at r65798 (90582b1).

The config below runs blocks/editor.php and entity-actions.php, and the --filter keeps the two tests above, in that order.

  • vendor/bin/phpunit -c chain.xml --filter '/Tests_Blocks_Editor::test_block_editor_rest_api_preload_discards_assets_enqueued_during_preload|Tests_Entity_Actions::test_the_preloaded_actions_path_serves_the_actions/': 1 failure on trunk, OK (2 tests, 6 assertions) with this change.
  • The same on multisite (the config with <const name="WP_TESTS_MULTISITE" value="1" /> added).
  • Both classes in full with the same config: OK (83 tests).
  • Tests_Entity_Actions in default order, with --order-by=reverse, and with --order-by=random and seeds 7, 1717 and 20261126: OK (66 tests) with this change.
  • Tests_Entity_Actions, Tests_Blocks_Editor, WP_Test_REST_Entity_Actions_Controller and the Tests_Entity_Fields classes together with --order-by=random --random-order-seed=3: OK (206 tests).
  • Found with --order-by=random --random-order-seed=20261126 on single site (1 failure). With this change, the same full run has no failures (32402 tests).
  • PHPCS reports nothing on the changed file.
<phpunit bootstrap="tests/phpunit/includes/bootstrap.php" backupGlobals="false" convertErrorsToExceptions="true" convertWarningsToExceptions="true" convertNoticesToExceptions="true" convertDeprecationsToExceptions="true">
	<testsuites>
		<testsuite name="chain">
			<file>tests/phpunit/tests/blocks/editor.php</file>
			<file>tests/phpunit/tests/entity-actions.php</file>
		</testsuite>
	</testsuites>
	<php>
		<const name="WP_RUN_CORE_TESTS" value="1" />
	</php>
</phpunit>

…tions` test.

The class only reset the registry after each test, so when an earlier class had read it, the first test of the class saw the actions WordPress registers instead of the test defaults. Reset it in `set_up()` as well.

See #66755.
@github-actions

github-actions Bot commented Nov 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.

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

Props mayankmajeji, mukesh27, lancewillett.

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


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub or WordPress.org user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

Comment thread tests/phpunit/tests/entity-actions.php Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are identified for the change that resets the registry between tests.

No open issues 🎉

What changed in this PR

This PR fixes an order-dependent failure in Tests_Entity_Actions by ensuring each test starts with a fresh registry that uses the class’s test defaults rather than actions retained from earlier tests.

Changes:

  • Reset the registry in set_up() after installing the test-default registration callback.
  • Update the setup documentation to explain why the reset is needed.
File Description
tests/​phpunit/​tests/​entity-actions.php Reset the registry before each test and document the isolation requirement.

Review effort: Balanced

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

I reproduced the preload test failing after the block-editor preload test on both single-site and multisite. Resetting the registry during setup made the same pair pass all six assertions in both modes. The existing teardown can only reset the registry after the class has started running. The code is good to go. Please apply Mukesh’s wording suggestion so the comment accurately describes when the reset runs.

AI review · gpt-6.2-astra

@lancewillett

Copy link
Copy Markdown
Member

One separate finding for the isolation ticket. With seed 20261126 on single-site, this patch fixed the entity-action preload failure. The other failure also reproduces on trunk with just test_the_script_modules_of_the_core_fields_are_registered, on both single-site and multisite.

Calling wp_scripts() at the start of that test runs the normal script-module registration hook. The class then passed all 39 tests and 145 assertions in both modes. Removing the core callback still made the assertion fail. That looks like a small follow-up for the entity-field test and can stay separate from this PR.

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

Verified the wording change and resolved the thread. The block-editor preload test followed by the entity-actions preload test failed before the reset and passed all six assertions after it in both site modes.

AI review · gpt-6.2-astra

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

Labels

None yet

Projects

Status: In review

Development

Successfully merging this pull request may close these issues.

4 participants