From 5d829fa4d9a2e325791352e43974988a87ce9620 Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Tue, 23 Jan 2024 18:20:17 +0100 Subject: [PATCH] fixup! fixup! fixup! Add tests --- tests/phpunit/tests/blocks/register.php | 31 ++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/tests/phpunit/tests/blocks/register.php b/tests/phpunit/tests/blocks/register.php index 29cc97fa2e39e..5c54caebc247c 100644 --- a/tests/phpunit/tests/blocks/register.php +++ b/tests/phpunit/tests/blocks/register.php @@ -261,7 +261,7 @@ public function test_missing_asset_file_register_block_script_handle() { } /** - * @expectedIncorrectUsage register_block_script_handle + * @expectedIncorrectUsage register_block_script_module_id * @ticket 60233 */ public function test_missing_asset_file_register_block_script_module_id() { @@ -302,6 +302,35 @@ public function test_handles_passed_register_block_script_module_ids() { $this->assertSame( 'test-id-2', $result, 1 ); } + /** + * @ticket 60233 + */ + public function test_success_register_block_script_module_id() { + $metadata = array( + 'file' => DIR_TESTDATA . '/blocks/notice/block.json', + 'name' => 'unit-tests/test-block', + 'viewScriptModule' => 'file:./block.js', + ); + $result = register_block_script_module_id( $metadata, 'viewScriptModule' ); + + $this->assertSame( 'tests-notice-view-script-module', $result ); + + // Test the behavior directly within the unit test + $this->assertFalse( + strpos( + wp_normalize_path( realpath( dirname( $metadata['file'] ) . '/' . $metadata['viewScriptModule'] ) ), + trailingslashit( wp_normalize_path( get_template_directory() ) ) + ) === 0 + ); + + $this->assertFalse( + strpos( + wp_normalize_path( realpath( dirname( $metadata['file'] ) . '/' . $metadata['viewScriptModule'] ) ), + trailingslashit( wp_normalize_path( get_stylesheet_directory() ) ) + ) === 0 + ); + } + /** * @ticket 50263 */