Skip to content

Commit 78d8b11

Browse files
committed
Tests: Isolate script module registration in the entity action tests.
Register the default modules for the assertion and restore the previous script module and Interactivity API instances afterward. Developed in: #16146 Props ekamran. See #66755. git-svn-id: https://develop.svn.wordpress.org/trunk@65736 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 4038eb0 commit 78d8b11

1 file changed

Lines changed: 22 additions & 3 deletions

File tree

‎tests/phpunit/tests/entity-actions/registerCoreEntityActions.php‎

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -483,12 +483,31 @@ public function test_the_rest_route_serves_the_core_actions() {
483483
* @ticket 66343
484484
*/
485485
public function test_the_script_modules_of_the_core_actions_are_registered() {
486+
global $wp_script_modules, $wp_interactivity;
487+
486488
wp_set_current_user( self::$admin_id );
487489

488-
foreach ( wp_get_all_registered_entity_action_modules()['postType'] as $post_type => $modules ) {
489-
foreach ( $modules as $module ) {
490-
$this->assertNotNull( wp_script_modules()->get_registered( $module ), "The $module module of $post_type is registered." );
490+
/*
491+
* Register the default script modules in fresh instances, so the test neither
492+
* depends on nor changes the shared ones. Registering them also marks the
493+
* block library modules in the Interactivity API.
494+
*/
495+
$original_script_modules = $wp_script_modules;
496+
$original_interactivity = $wp_interactivity;
497+
$wp_script_modules = null;
498+
$wp_interactivity = null;
499+
500+
try {
501+
wp_default_script_modules();
502+
503+
foreach ( wp_get_all_registered_entity_action_modules()['postType'] as $post_type => $modules ) {
504+
foreach ( $modules as $module ) {
505+
$this->assertNotNull( wp_script_modules()->get_registered( $module ), "The $module module of $post_type is registered." );
506+
}
491507
}
508+
} finally {
509+
$wp_script_modules = $original_script_modules;
510+
$wp_interactivity = $original_interactivity;
492511
}
493512
}
494513

0 commit comments

Comments
 (0)