feat: add Related Stories editor controls

This commit is contained in:
chrnx committed 2026-08-12 20:21:42 -05:00
1 parent 3bc62358d7
commit 2fede7cfcc
6 files changed
+503

No files matched your search

+44
View File
@@ -124,4 +124,48 @@ class EditorAssetsTest extends WP_UnitTestCase {
$this->assertFalse( wp_script_is( 'chrnx-editor-podcast', 'enqueued' ) );
}
}
/** Related Stories editor metadata registers one local translated script with exact dependencies. */
public function test_related_posts_registers_exact_editor_asset_metadata() {
do_action( 'init' );
$type = WP_Block_Type_Registry::get_instance()->get_registered( 'chrnx/related-posts' );
$this->assertInstanceOf( WP_Block_Type::class, $type );
$this->assertCount( 1, $type->editor_script_handles );
$handle = $type->editor_script_handles[0];
$this->assertNotEmpty( $handle );
$manifest_path = get_theme_file_path( 'assets/js/editor-related-posts.asset.php' );
$this->assertFileExists( $manifest_path );
$manifest = require $manifest_path;
$this->assertSame(
array( 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-element', 'wp-i18n', 'wp-server-side-render' ),
$manifest['dependencies']
);
$scripts = wp_scripts();
$this->assertArrayHasKey( $handle, $scripts->registered );
$registered = $scripts->registered[ $handle ];
$this->assertSame( get_theme_file_uri( 'assets/js/editor-related-posts.js' ), $registered->src );
$this->assertSame( $manifest['dependencies'], $registered->deps );
$this->assertSame( CHRNX_VERSION, $registered->ver );
$this->assertSame( 'chrnx', $registered->textdomain );
}
/** Related Stories remains metadata-registered on post, Site Editor, and screenless init. */
public function test_related_posts_registration_is_not_post_screen_guarded() {
foreach ( array( null, 'post', 'site-editor' ) as $screen_id ) {
if ( null === $screen_id ) {
$GLOBALS['current_screen'] = null;
} else {
$this->set_screen( $screen_id, true );
}
do_action( 'init' );
$this->assertInstanceOf(
WP_Block_Type::class,
WP_Block_Type_Registry::get_instance()->get_registered( 'chrnx/related-posts' ),
(string) $screen_id
);
}
}
}