@@ -437,6 +437,83 @@ public function test_other_editors_do_not_preload_the_actions() {
437437 $ this ->assertSame ( array ( '/wp/v2/types ' ), _wp_preload_entity_actions ( array ( '/wp/v2/types ' ), $ context ), 'The paths are unchanged. ' );
438438 }
439439
440+ /**
441+ * The script modules of every entity are listed by entity kind, then by
442+ * entity name, in registration order.
443+ *
444+ * @ticket 65819
445+ */
446+ public function test_all_registered_action_modules_are_listed_by_kind_and_name () {
447+ $ this ->register_actions ( 'postType ' , 'post ' , array ( $ this ->action ( 'feature ' ) ), 'plugin/post-actions ' );
448+ $ this ->register_actions ( 'taxonomy ' , 'category ' , array ( $ this ->action ( 'merge ' ) ), 'plugin/term-actions ' );
449+
450+ $ this ->assertSame (
451+ array (
452+ 'postType ' => array (
453+ 'page ' => array ( 'core/defaults ' ),
454+ 'post ' => array ( 'plugin/post-actions ' ),
455+ ),
456+ 'taxonomy ' => array (
457+ 'category ' => array ( 'plugin/term-actions ' ),
458+ ),
459+ ),
460+ wp_get_all_registered_entity_action_modules ()
461+ );
462+ }
463+
464+ /**
465+ * A numeric script module id is listed as a string, although PHP turns it
466+ * into an integer as an array key.
467+ *
468+ * @ticket 65819
469+ */
470+ public function test_all_registered_action_modules_lists_a_numeric_module_id_as_a_string () {
471+ $ this ->register_actions ( 'postType ' , 'post ' , array ( $ this ->action ( 'feature ' ) ), '42 ' );
472+
473+ $ modules = wp_get_all_registered_entity_action_modules ();
474+
475+ $ this ->assertSame ( array ( '42 ' ), $ modules ['postType ' ]['post ' ] );
476+ }
477+
478+ /**
479+ * An entity whose actions have no script module is not listed.
480+ *
481+ * @ticket 65819
482+ */
483+ public function test_all_registered_action_modules_skips_entities_without_a_module () {
484+ $ this ->register_actions ( 'postType ' , 'post ' , array ( $ this ->action ( 'feature ' ) ) );
485+
486+ $ modules = wp_get_all_registered_entity_action_modules ();
487+
488+ $ this ->assertArrayNotHasKey ( 'post ' , $ modules ['postType ' ] );
489+ $ this ->assertSame ( array ( 'core/defaults ' ), $ modules ['postType ' ]['page ' ], 'The entities with a module are still listed. ' );
490+ }
491+
492+ /**
493+ * Reading the script modules while `init` runs is refused: nothing is
494+ * listed, and the registry is not read, so the action is not fired.
495+ *
496+ * @ticket 65819
497+ */
498+ public function test_all_registered_action_modules_are_empty_while_init_runs () {
499+ global $ wp_current_filter ;
500+
501+ $ this ->setExpectedIncorrectUsage ( 'WP_Entity_Actions_Registry::initialize ' );
502+ self ::reset_registry ();
503+ $ fired = did_action ( 'wp_entity_actions_api_init ' );
504+
505+ // Act as if a callback hooked to `init` read the modules.
506+ $ wp_current_filter [] = 'init ' ;
507+ try {
508+ $ modules = wp_get_all_registered_entity_action_modules ();
509+ } finally {
510+ array_pop ( $ wp_current_filter );
511+ }
512+
513+ $ this ->assertSame ( array (), $ modules );
514+ $ this ->assertSame ( $ fired , did_action ( 'wp_entity_actions_api_init ' ), 'The action is not fired. ' );
515+ }
516+
440517 /**
441518 * Reading the registry fires `wp_entity_actions_api_init` once, whichever
442519 * getter is read first and however many times it is read.
0 commit comments