From 837931eceda532d8ad2f679f48cb880046bb7dd3 Mon Sep 17 00:00:00 2001 From: Joe Fusco Date: Thu, 4 Jan 2024 16:17:17 -0500 Subject: [PATCH 01/22] Gracefully handle scenarios where *.asset.php is absent Signed-off-by: Joe Fusco --- src/wp-includes/blocks.php | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/wp-includes/blocks.php b/src/wp-includes/blocks.php index 431e2b015332c..d48e3af96a9a4 100644 --- a/src/wp-includes/blocks.php +++ b/src/wp-includes/blocks.php @@ -162,18 +162,8 @@ function register_block_script_handle( $metadata, $field_name, $index = 0 ) { realpath( $script_asset_raw_path ) ); + // Ensure graceful handling of scenarios where *.asset.php is not present or accessible. if ( empty( $script_asset_path ) ) { - _doing_it_wrong( - __FUNCTION__, - sprintf( - /* translators: 1: Asset file location, 2: Field name, 3: Block name. */ - __( 'The asset file (%1$s) for the "%2$s" defined in "%3$s" block definition is missing.' ), - $script_asset_raw_path, - $field_name, - $metadata['name'] - ), - '5.5.0' - ); return false; } @@ -185,7 +175,16 @@ function register_block_script_handle( $metadata, $field_name, $index = 0 ) { $script_args['strategy'] = 'defer'; } - $script_asset = require $script_asset_path; + if ( file_exists( $script_asset_path ) ) { + $script_asset = require $script_asset_path; + } else { + // Ensure graceful fallback for missing or inaccessible *.asset.php by setting default dependencies and version. + $script_asset = array( + 'dependencies' => array(), + 'version' => false, + ); + } + $script_dependencies = isset( $script_asset['dependencies'] ) ? $script_asset['dependencies'] : array(); $result = wp_register_script( $script_handle, From 36d3af1030e7b2269444138942867a4968f7f899 Mon Sep 17 00:00:00 2001 From: Joe Fusco Date: Thu, 4 Jan 2024 17:20:22 -0500 Subject: [PATCH 02/22] Add test coverage Signed-off-by: Joe Fusco --- .../data/blocks/no-asset-php/block-rtl.css | 1 + .../data/blocks/no-asset-php/block.css | 1 + .../phpunit/data/blocks/no-asset-php/block.js | 1 + .../data/blocks/no-asset-php/block.json | 73 +++++++++++++++++++ .../data/blocks/no-asset-php/render.php | 1 + tests/phpunit/tests/blocks/register.php | 46 ++++++++++++ 6 files changed, 123 insertions(+) create mode 100644 tests/phpunit/data/blocks/no-asset-php/block-rtl.css create mode 100644 tests/phpunit/data/blocks/no-asset-php/block.css create mode 100644 tests/phpunit/data/blocks/no-asset-php/block.js create mode 100644 tests/phpunit/data/blocks/no-asset-php/block.json create mode 100644 tests/phpunit/data/blocks/no-asset-php/render.php diff --git a/tests/phpunit/data/blocks/no-asset-php/block-rtl.css b/tests/phpunit/data/blocks/no-asset-php/block-rtl.css new file mode 100644 index 0000000000000..2572f27aaf2d9 --- /dev/null +++ b/tests/phpunit/data/blocks/no-asset-php/block-rtl.css @@ -0,0 +1 @@ +/* Test CSS file - RTL version */ diff --git a/tests/phpunit/data/blocks/no-asset-php/block.css b/tests/phpunit/data/blocks/no-asset-php/block.css new file mode 100644 index 0000000000000..5bbe1134f7048 --- /dev/null +++ b/tests/phpunit/data/blocks/no-asset-php/block.css @@ -0,0 +1 @@ +/* Test CSS file */ diff --git a/tests/phpunit/data/blocks/no-asset-php/block.js b/tests/phpunit/data/blocks/no-asset-php/block.js new file mode 100644 index 0000000000000..0bdf0f5ad91f7 --- /dev/null +++ b/tests/phpunit/data/blocks/no-asset-php/block.js @@ -0,0 +1 @@ +/* Test JavaScript file. */ diff --git a/tests/phpunit/data/blocks/no-asset-php/block.json b/tests/phpunit/data/blocks/no-asset-php/block.json new file mode 100644 index 0000000000000..909137252a1bc --- /dev/null +++ b/tests/phpunit/data/blocks/no-asset-php/block.json @@ -0,0 +1,73 @@ +{ + "apiVersion": 2, + "name": "tests/notice", + "title": "Notice", + "category": "common", + "parent": [ + "tests/group" + ], + "ancestor": [ + "tests/section" + ], + "providesContext": { + "tests/message": "message" + }, + "usesContext": [ + "groupId" + ], + "icon": "star", + "description": "Shows warning, error or success notices…", + "keywords": [ + "alert", + "message" + ], + "textdomain": "notice", + "attributes": { + "message": { + "type": "string" + } + }, + "selectors": { + "root": ".wp-block-notice" + }, + "blockHooks": { + "tests/before": "before", + "tests/after": "after", + "tests/first-child": "firstChild", + "tests/last-child": "lastChild" + }, + "supports": { + "align": true, + "lightBlockWrapper": true + }, + "styles": [ + { + "name": "default", + "label": "Default", + "isDefault": true + }, + { + "name": "other", + "label": "Other" + } + ], + "variations": [ + { + "name": "error", + "title": "Error", + "description": "Shows error.", + "keywords": [ "failure" ] + } + ], + "example": { + "attributes": { + "message": "This is a notice!" + } + }, + "editorScript": "tests-notice-editor-script", + "script": "tests-notice-script", + "viewScript": [ "tests-notice-view-script", "tests-notice-view-script-2" ], + "editorStyle": "tests-notice-editor-style", + "style": [ "tests-notice-style", "tests-notice-style-2" ], + "render": "file:./render.php" +} diff --git a/tests/phpunit/data/blocks/no-asset-php/render.php b/tests/phpunit/data/blocks/no-asset-php/render.php new file mode 100644 index 0000000000000..12a49c1a5958c --- /dev/null +++ b/tests/phpunit/data/blocks/no-asset-php/render.php @@ -0,0 +1 @@ +

>

diff --git a/tests/phpunit/tests/blocks/register.php b/tests/phpunit/tests/blocks/register.php index 012171e38acfe..6b44b8c7f9ea8 100644 --- a/tests/phpunit/tests/blocks/register.php +++ b/tests/phpunit/tests/blocks/register.php @@ -234,6 +234,52 @@ public function test_missing_asset_file_register_block_script_handle() { $this->assertFalse( $result ); } + /** + * @ticket 57234 + */ + public function test_missing_asset_php_for_traditionally_registered_block() { + $metadata = array( + 'file' => DIR_TESTDATA . '/blocks/notice/block.json', + 'name' => 'unit-test/traditional-block', + 'script' => 'file:./blocks/notice/block.js', + ); + $result = register_block_script_handle( $metadata, 'script' ); + + // Assert that the result is false due to missing .asset.php + $this->assertFalse( $result ); + } + + /** + * @ticket 57234 + */ + public function test_inaccessible_asset_php_path() { + $metadata = array( + 'file' => DIR_TESTDATA . '/blocks/notice/block.json', + 'name' => 'unit-test/inaccessible-asset', + 'script' => 'file:./blocks/notice/inaccessible-asset.php', + ); + $result = register_block_script_handle( $metadata, 'script' ); + + // Assert that the result is false due to inaccessible .asset.php path + $this->assertFalse( $result ); + } + + /** + * @ticket 57234 + */ + public function test_missing_asset_php_for_non_traditional_block() { + $metadata = array( + 'file' => DIR_TESTDATA . '/blocks/no-asset-php/block.json', + 'name' => 'unit-test/non-traditional-block', + // Assuming non-traditional registration doesn't use the script field + // or has a different mechanism that doesn't involve .asset.php + ); + $result = register_block_script_handle( $metadata, 'script' ); + + // Assert that the result is false as expected in non-traditional scenarios + $this->assertFalse( $result ); + } + /** * @ticket 50263 */ From 1142150fa57bc3ca376ae510701f700c1a074c2a Mon Sep 17 00:00:00 2001 From: Joe Fusco Date: Thu, 4 Jan 2024 17:23:13 -0500 Subject: [PATCH 03/22] Linting issues Signed-off-by: Joe Fusco --- tests/phpunit/tests/blocks/register.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/phpunit/tests/blocks/register.php b/tests/phpunit/tests/blocks/register.php index 6b44b8c7f9ea8..6ee2a394bdb1d 100644 --- a/tests/phpunit/tests/blocks/register.php +++ b/tests/phpunit/tests/blocks/register.php @@ -243,7 +243,7 @@ public function test_missing_asset_php_for_traditionally_registered_block() { 'name' => 'unit-test/traditional-block', 'script' => 'file:./blocks/notice/block.js', ); - $result = register_block_script_handle( $metadata, 'script' ); + $result = register_block_script_handle( $metadata, 'script' ); // Assert that the result is false due to missing .asset.php $this->assertFalse( $result ); @@ -258,7 +258,7 @@ public function test_inaccessible_asset_php_path() { 'name' => 'unit-test/inaccessible-asset', 'script' => 'file:./blocks/notice/inaccessible-asset.php', ); - $result = register_block_script_handle( $metadata, 'script' ); + $result = register_block_script_handle( $metadata, 'script' ); // Assert that the result is false due to inaccessible .asset.php path $this->assertFalse( $result ); @@ -269,12 +269,12 @@ public function test_inaccessible_asset_php_path() { */ public function test_missing_asset_php_for_non_traditional_block() { $metadata = array( - 'file' => DIR_TESTDATA . '/blocks/no-asset-php/block.json', - 'name' => 'unit-test/non-traditional-block', + 'file' => DIR_TESTDATA . '/blocks/no-asset-php/block.json', + 'name' => 'unit-test/non-traditional-block', // Assuming non-traditional registration doesn't use the script field // or has a different mechanism that doesn't involve .asset.php ); - $result = register_block_script_handle( $metadata, 'script' ); + $result = register_block_script_handle( $metadata, 'script' ); // Assert that the result is false as expected in non-traditional scenarios $this->assertFalse( $result ); From 511c6f1be6c7d94a0d79fdcba610c64fbd83f17d Mon Sep 17 00:00:00 2001 From: Joe Fusco Date: Thu, 4 Jan 2024 17:24:44 -0500 Subject: [PATCH 04/22] Correct linting issue Signed-off-by: Joe Fusco --- tests/phpunit/tests/blocks/register.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/phpunit/tests/blocks/register.php b/tests/phpunit/tests/blocks/register.php index 6ee2a394bdb1d..197a3404e717a 100644 --- a/tests/phpunit/tests/blocks/register.php +++ b/tests/phpunit/tests/blocks/register.php @@ -274,7 +274,7 @@ public function test_missing_asset_php_for_non_traditional_block() { // Assuming non-traditional registration doesn't use the script field // or has a different mechanism that doesn't involve .asset.php ); - $result = register_block_script_handle( $metadata, 'script' ); + $result = register_block_script_handle( $metadata, 'script' ); // Assert that the result is false as expected in non-traditional scenarios $this->assertFalse( $result ); From 5c67d336cc762757a2123e0e6c0f982efd52d12c Mon Sep 17 00:00:00 2001 From: Joe Fusco Date: Fri, 5 Jan 2024 13:36:45 -0500 Subject: [PATCH 05/22] Remove _doing_it_wrong check Signed-off-by: Joe Fusco --- tests/phpunit/tests/blocks/register.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/phpunit/tests/blocks/register.php b/tests/phpunit/tests/blocks/register.php index 197a3404e717a..5bb4e9734fa39 100644 --- a/tests/phpunit/tests/blocks/register.php +++ b/tests/phpunit/tests/blocks/register.php @@ -220,7 +220,6 @@ public function test_wrong_array_index_do_not_register_block_script_handle() { } /** - * @expectedIncorrectUsage register_block_script_handle * @ticket 50263 */ public function test_missing_asset_file_register_block_script_handle() { From f3fad9e41ecee36c80845f7a104a41042dd72b01 Mon Sep 17 00:00:00 2001 From: Joe Fusco Date: Mon, 8 Jan 2024 11:59:43 -0500 Subject: [PATCH 06/22] Remove early return Signed-off-by: Joe Fusco --- src/wp-includes/blocks.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/wp-includes/blocks.php b/src/wp-includes/blocks.php index d48e3af96a9a4..b92551c32a631 100644 --- a/src/wp-includes/blocks.php +++ b/src/wp-includes/blocks.php @@ -162,11 +162,6 @@ function register_block_script_handle( $metadata, $field_name, $index = 0 ) { realpath( $script_asset_raw_path ) ); - // Ensure graceful handling of scenarios where *.asset.php is not present or accessible. - if ( empty( $script_asset_path ) ) { - return false; - } - $script_path_norm = wp_normalize_path( realpath( $path . '/' . $script_path ) ); $script_uri = get_block_asset_url( $script_path_norm ); From 21c52a52361403ca14b465e98e62c5ee9f088663 Mon Sep 17 00:00:00 2001 From: Joe Fusco Date: Mon, 8 Jan 2024 12:24:08 -0500 Subject: [PATCH 07/22] Reduce complexities Signed-off-by: Joe Fusco --- src/wp-includes/blocks.php | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/wp-includes/blocks.php b/src/wp-includes/blocks.php index b92551c32a631..fae59a0b76718 100644 --- a/src/wp-includes/blocks.php +++ b/src/wp-includes/blocks.php @@ -170,16 +170,7 @@ function register_block_script_handle( $metadata, $field_name, $index = 0 ) { $script_args['strategy'] = 'defer'; } - if ( file_exists( $script_asset_path ) ) { - $script_asset = require $script_asset_path; - } else { - // Ensure graceful fallback for missing or inaccessible *.asset.php by setting default dependencies and version. - $script_asset = array( - 'dependencies' => array(), - 'version' => false, - ); - } - + $script_asset = @include $script_asset_path; $script_dependencies = isset( $script_asset['dependencies'] ) ? $script_asset['dependencies'] : array(); $result = wp_register_script( $script_handle, From 7219bde5ee7f4f9f942d348f316eeb45db847225 Mon Sep 17 00:00:00 2001 From: Joe Fusco Date: Mon, 8 Jan 2024 12:24:55 -0500 Subject: [PATCH 08/22] Test for return of expected handle Signed-off-by: Joe Fusco --- tests/phpunit/tests/blocks/register.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/phpunit/tests/blocks/register.php b/tests/phpunit/tests/blocks/register.php index 5bb4e9734fa39..5fdb1b89aa379 100644 --- a/tests/phpunit/tests/blocks/register.php +++ b/tests/phpunit/tests/blocks/register.php @@ -243,9 +243,12 @@ public function test_missing_asset_php_for_traditionally_registered_block() { 'script' => 'file:./blocks/notice/block.js', ); $result = register_block_script_handle( $metadata, 'script' ); - - // Assert that the result is false due to missing .asset.php - $this->assertFalse( $result ); + + // Expected generated script handle (modify as per the function's actual handle generation logic) + $expected_handle = generate_block_asset_handle( $metadata['name'], 'script', 0 ); + + // Assert that the result is the generated script handle name + $this->assertEquals( $expected_handle, $result ); } /** From c9d758b85378ea1a3238285c3959d1c89afcb1ca Mon Sep 17 00:00:00 2001 From: Joe Fusco Date: Mon, 8 Jan 2024 12:35:59 -0500 Subject: [PATCH 09/22] Resolve whitespace linting issues Signed-off-by: Joe Fusco --- tests/phpunit/tests/blocks/register.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/phpunit/tests/blocks/register.php b/tests/phpunit/tests/blocks/register.php index 5fdb1b89aa379..d2415cc74fff8 100644 --- a/tests/phpunit/tests/blocks/register.php +++ b/tests/phpunit/tests/blocks/register.php @@ -243,10 +243,10 @@ public function test_missing_asset_php_for_traditionally_registered_block() { 'script' => 'file:./blocks/notice/block.js', ); $result = register_block_script_handle( $metadata, 'script' ); - + // Expected generated script handle (modify as per the function's actual handle generation logic) $expected_handle = generate_block_asset_handle( $metadata['name'], 'script', 0 ); - + // Assert that the result is the generated script handle name $this->assertEquals( $expected_handle, $result ); } From 610a40a58e1cb4d9add7aaa61000e7fc7d24d519 Mon Sep 17 00:00:00 2001 From: Joe Fusco Date: Mon, 8 Jan 2024 12:56:06 -0500 Subject: [PATCH 10/22] Update tests Signed-off-by: Joe Fusco --- tests/phpunit/tests/blocks/register.php | 39 +++---------------------- 1 file changed, 4 insertions(+), 35 deletions(-) diff --git a/tests/phpunit/tests/blocks/register.php b/tests/phpunit/tests/blocks/register.php index d2415cc74fff8..c7b321c2828aa 100644 --- a/tests/phpunit/tests/blocks/register.php +++ b/tests/phpunit/tests/blocks/register.php @@ -236,11 +236,11 @@ public function test_missing_asset_file_register_block_script_handle() { /** * @ticket 57234 */ - public function test_missing_asset_php_for_traditionally_registered_block() { + public function test_missing_asset_php_fails_gracefully() { $metadata = array( - 'file' => DIR_TESTDATA . '/blocks/notice/block.json', - 'name' => 'unit-test/traditional-block', - 'script' => 'file:./blocks/notice/block.js', + 'file' => DIR_TESTDATA . '/blocks/no-asset-php/block.json', + 'name' => 'unit-test/test-block', + 'script' => 'file:./blocks/no-asset-php/block.js', ); $result = register_block_script_handle( $metadata, 'script' ); @@ -251,37 +251,6 @@ public function test_missing_asset_php_for_traditionally_registered_block() { $this->assertEquals( $expected_handle, $result ); } - /** - * @ticket 57234 - */ - public function test_inaccessible_asset_php_path() { - $metadata = array( - 'file' => DIR_TESTDATA . '/blocks/notice/block.json', - 'name' => 'unit-test/inaccessible-asset', - 'script' => 'file:./blocks/notice/inaccessible-asset.php', - ); - $result = register_block_script_handle( $metadata, 'script' ); - - // Assert that the result is false due to inaccessible .asset.php path - $this->assertFalse( $result ); - } - - /** - * @ticket 57234 - */ - public function test_missing_asset_php_for_non_traditional_block() { - $metadata = array( - 'file' => DIR_TESTDATA . '/blocks/no-asset-php/block.json', - 'name' => 'unit-test/non-traditional-block', - // Assuming non-traditional registration doesn't use the script field - // or has a different mechanism that doesn't involve .asset.php - ); - $result = register_block_script_handle( $metadata, 'script' ); - - // Assert that the result is false as expected in non-traditional scenarios - $this->assertFalse( $result ); - } - /** * @ticket 50263 */ From 543274b80edbd8db45bde4675e63070f06983f3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Zi=C3=B3=C5=82kowski?= Date: Wed, 7 Feb 2024 13:54:38 +0100 Subject: [PATCH 11/22] Fix unit test failures --- tests/phpunit/tests/blocks/register.php | 47 ++++++++----------------- 1 file changed, 15 insertions(+), 32 deletions(-) diff --git a/tests/phpunit/tests/blocks/register.php b/tests/phpunit/tests/blocks/register.php index c7b321c2828aa..0696b2a995c2b 100644 --- a/tests/phpunit/tests/blocks/register.php +++ b/tests/phpunit/tests/blocks/register.php @@ -219,38 +219,6 @@ public function test_wrong_array_index_do_not_register_block_script_handle() { $this->assertFalse( $result ); } - /** - * @ticket 50263 - */ - public function test_missing_asset_file_register_block_script_handle() { - $metadata = array( - 'file' => __FILE__, - 'name' => 'unit-tests/test-block', - 'script' => 'file:./blocks/notice/missing-asset.js', - ); - $result = register_block_script_handle( $metadata, 'script' ); - - $this->assertFalse( $result ); - } - - /** - * @ticket 57234 - */ - public function test_missing_asset_php_fails_gracefully() { - $metadata = array( - 'file' => DIR_TESTDATA . '/blocks/no-asset-php/block.json', - 'name' => 'unit-test/test-block', - 'script' => 'file:./blocks/no-asset-php/block.js', - ); - $result = register_block_script_handle( $metadata, 'script' ); - - // Expected generated script handle (modify as per the function's actual handle generation logic) - $expected_handle = generate_block_asset_handle( $metadata['name'], 'script', 0 ); - - // Assert that the result is the generated script handle name - $this->assertEquals( $expected_handle, $result ); - } - /** * @ticket 50263 */ @@ -275,6 +243,21 @@ public function test_handles_passed_register_block_script_handles() { $this->assertSame( 'test-script-handle-2', $result, 1 ); } + /** + * @ticket 50263 + * @ticket 60460 + */ + public function test_missing_asset_file_register_block_script_handle_with_default_settings() { + $metadata = array( + 'file' => __FILE__, + 'name' => 'unit-tests/test-block', + 'script' => 'file:./blocks/notice/missing-asset.js', + ); + $result = register_block_script_handle( $metadata, 'script' ); + + $this->assertSame( 'unit-tests-test-block-script' ); + } + /** * @ticket 50263 */ From 0847e7dc1f37eba1cd23fdc24812b2b4db7cb166 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Zi=C3=B3=C5=82kowski?= Date: Wed, 7 Feb 2024 14:09:06 +0100 Subject: [PATCH 12/22] Update tests/phpunit/tests/blocks/register.php --- tests/phpunit/tests/blocks/register.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/phpunit/tests/blocks/register.php b/tests/phpunit/tests/blocks/register.php index 0696b2a995c2b..be2e0957e195e 100644 --- a/tests/phpunit/tests/blocks/register.php +++ b/tests/phpunit/tests/blocks/register.php @@ -255,7 +255,7 @@ public function test_missing_asset_file_register_block_script_handle_with_defaul ); $result = register_block_script_handle( $metadata, 'script' ); - $this->assertSame( 'unit-tests-test-block-script' ); + $this->assertSame( 'unit-tests-test-block-script', $result ); } /** From 5c4bb7248ffe43a179cc4b1cf247fdf6c9571e72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Zi=C3=B3=C5=82kowski?= Date: Wed, 7 Feb 2024 14:09:30 +0100 Subject: [PATCH 13/22] Delete tests/phpunit/data/blocks/no-asset-php/block-rtl.css --- tests/phpunit/data/blocks/no-asset-php/block-rtl.css | 1 - 1 file changed, 1 deletion(-) delete mode 100644 tests/phpunit/data/blocks/no-asset-php/block-rtl.css diff --git a/tests/phpunit/data/blocks/no-asset-php/block-rtl.css b/tests/phpunit/data/blocks/no-asset-php/block-rtl.css deleted file mode 100644 index 2572f27aaf2d9..0000000000000 --- a/tests/phpunit/data/blocks/no-asset-php/block-rtl.css +++ /dev/null @@ -1 +0,0 @@ -/* Test CSS file - RTL version */ From 081e4fca0c4eafa866d83e0a8b3176e563885150 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Zi=C3=B3=C5=82kowski?= Date: Wed, 7 Feb 2024 14:09:41 +0100 Subject: [PATCH 14/22] Delete tests/phpunit/data/blocks/no-asset-php/block.json --- .../data/blocks/no-asset-php/block.json | 73 ------------------- 1 file changed, 73 deletions(-) delete mode 100644 tests/phpunit/data/blocks/no-asset-php/block.json diff --git a/tests/phpunit/data/blocks/no-asset-php/block.json b/tests/phpunit/data/blocks/no-asset-php/block.json deleted file mode 100644 index 909137252a1bc..0000000000000 --- a/tests/phpunit/data/blocks/no-asset-php/block.json +++ /dev/null @@ -1,73 +0,0 @@ -{ - "apiVersion": 2, - "name": "tests/notice", - "title": "Notice", - "category": "common", - "parent": [ - "tests/group" - ], - "ancestor": [ - "tests/section" - ], - "providesContext": { - "tests/message": "message" - }, - "usesContext": [ - "groupId" - ], - "icon": "star", - "description": "Shows warning, error or success notices…", - "keywords": [ - "alert", - "message" - ], - "textdomain": "notice", - "attributes": { - "message": { - "type": "string" - } - }, - "selectors": { - "root": ".wp-block-notice" - }, - "blockHooks": { - "tests/before": "before", - "tests/after": "after", - "tests/first-child": "firstChild", - "tests/last-child": "lastChild" - }, - "supports": { - "align": true, - "lightBlockWrapper": true - }, - "styles": [ - { - "name": "default", - "label": "Default", - "isDefault": true - }, - { - "name": "other", - "label": "Other" - } - ], - "variations": [ - { - "name": "error", - "title": "Error", - "description": "Shows error.", - "keywords": [ "failure" ] - } - ], - "example": { - "attributes": { - "message": "This is a notice!" - } - }, - "editorScript": "tests-notice-editor-script", - "script": "tests-notice-script", - "viewScript": [ "tests-notice-view-script", "tests-notice-view-script-2" ], - "editorStyle": "tests-notice-editor-style", - "style": [ "tests-notice-style", "tests-notice-style-2" ], - "render": "file:./render.php" -} From 9af46c525e15352e7f60b883b128ff2163538f6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Zi=C3=B3=C5=82kowski?= Date: Wed, 7 Feb 2024 14:09:56 +0100 Subject: [PATCH 15/22] Delete tests/phpunit/data/blocks/no-asset-php/render.php --- tests/phpunit/data/blocks/no-asset-php/render.php | 1 - 1 file changed, 1 deletion(-) delete mode 100644 tests/phpunit/data/blocks/no-asset-php/render.php diff --git a/tests/phpunit/data/blocks/no-asset-php/render.php b/tests/phpunit/data/blocks/no-asset-php/render.php deleted file mode 100644 index 12a49c1a5958c..0000000000000 --- a/tests/phpunit/data/blocks/no-asset-php/render.php +++ /dev/null @@ -1 +0,0 @@ -

>

From ffd38f960e3855523df6b50403628b4a7e2f3806 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Zi=C3=B3=C5=82kowski?= Date: Wed, 7 Feb 2024 14:10:06 +0100 Subject: [PATCH 16/22] Delete tests/phpunit/data/blocks/no-asset-php/block.js --- tests/phpunit/data/blocks/no-asset-php/block.js | 1 - 1 file changed, 1 deletion(-) delete mode 100644 tests/phpunit/data/blocks/no-asset-php/block.js diff --git a/tests/phpunit/data/blocks/no-asset-php/block.js b/tests/phpunit/data/blocks/no-asset-php/block.js deleted file mode 100644 index 0bdf0f5ad91f7..0000000000000 --- a/tests/phpunit/data/blocks/no-asset-php/block.js +++ /dev/null @@ -1 +0,0 @@ -/* Test JavaScript file. */ From 2f16a535cf568a7c71a5cc13cc89912598408845 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Zi=C3=B3=C5=82kowski?= Date: Wed, 7 Feb 2024 14:10:17 +0100 Subject: [PATCH 17/22] Delete tests/phpunit/data/blocks/no-asset-php/block.css --- tests/phpunit/data/blocks/no-asset-php/block.css | 1 - 1 file changed, 1 deletion(-) delete mode 100644 tests/phpunit/data/blocks/no-asset-php/block.css diff --git a/tests/phpunit/data/blocks/no-asset-php/block.css b/tests/phpunit/data/blocks/no-asset-php/block.css deleted file mode 100644 index 5bbe1134f7048..0000000000000 --- a/tests/phpunit/data/blocks/no-asset-php/block.css +++ /dev/null @@ -1 +0,0 @@ -/* Test CSS file */ From 8cfe4fc7a55690f59a9f0bdd23436ca9cc25029d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Zi=C3=B3=C5=82kowski?= Date: Wed, 7 Feb 2024 14:12:44 +0100 Subject: [PATCH 18/22] Update src/wp-includes/blocks.php --- src/wp-includes/blocks.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/wp-includes/blocks.php b/src/wp-includes/blocks.php index fae59a0b76718..9e0792be1e662 100644 --- a/src/wp-includes/blocks.php +++ b/src/wp-includes/blocks.php @@ -170,6 +170,7 @@ function register_block_script_handle( $metadata, $field_name, $index = 0 ) { $script_args['strategy'] = 'defer'; } + // Asset file for blocks is optional. See https://core.trac.wordpress.org/ticket/60460. $script_asset = @include $script_asset_path; $script_dependencies = isset( $script_asset['dependencies'] ) ? $script_asset['dependencies'] : array(); $result = wp_register_script( From 267f49c194173d9323cd697000c634c62ddd2192 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Zi=C3=B3=C5=82kowski?= Date: Wed, 7 Feb 2024 14:44:08 +0100 Subject: [PATCH 19/22] Update register.php --- tests/phpunit/tests/blocks/register.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/phpunit/tests/blocks/register.php b/tests/phpunit/tests/blocks/register.php index be2e0957e195e..5b53343969231 100644 --- a/tests/phpunit/tests/blocks/register.php +++ b/tests/phpunit/tests/blocks/register.php @@ -60,6 +60,12 @@ public function tear_down() { } } + foreach ( wp_scripts()->registered as $script_handle => $script ) { + if ( str_starts_with( $script_handle, 'unit-tests-' ) ) { + wp_deregister_script( $script_handle ); + } + } + parent::tear_down(); } From c000be192ff5790bf5f8653bd76af0da0fd1fbfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Zi=C3=B3=C5=82kowski?= Date: Thu, 8 Feb 2024 06:58:41 +0100 Subject: [PATCH 20/22] Fix the failures reported for PHP 8 --- src/wp-includes/blocks.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-includes/blocks.php b/src/wp-includes/blocks.php index 9e0792be1e662..3019c04d10426 100644 --- a/src/wp-includes/blocks.php +++ b/src/wp-includes/blocks.php @@ -171,7 +171,7 @@ function register_block_script_handle( $metadata, $field_name, $index = 0 ) { } // Asset file for blocks is optional. See https://core.trac.wordpress.org/ticket/60460. - $script_asset = @include $script_asset_path; + $script_asset = ! empty( $script_asset_path ) ? $script_asset_path : array(); $script_dependencies = isset( $script_asset['dependencies'] ) ? $script_asset['dependencies'] : array(); $result = wp_register_script( $script_handle, From e362c64cfe91c3671908205b98b3f56117addb64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Zi=C3=B3=C5=82kowski?= Date: Thu, 8 Feb 2024 06:59:21 +0100 Subject: [PATCH 21/22] Update blocks.php --- src/wp-includes/blocks.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-includes/blocks.php b/src/wp-includes/blocks.php index 3019c04d10426..da1c9232f98d4 100644 --- a/src/wp-includes/blocks.php +++ b/src/wp-includes/blocks.php @@ -172,7 +172,7 @@ function register_block_script_handle( $metadata, $field_name, $index = 0 ) { // Asset file for blocks is optional. See https://core.trac.wordpress.org/ticket/60460. $script_asset = ! empty( $script_asset_path ) ? $script_asset_path : array(); - $script_dependencies = isset( $script_asset['dependencies'] ) ? $script_asset['dependencies'] : array(); + $script_dependencies = isset( $script_asset['dependencies'] ) ? require $script_asset['dependencies'] : array(); $result = wp_register_script( $script_handle, $script_uri, From c3edb3d381d17a4b70702582a450a7fd138d2366 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Zi=C3=B3=C5=82kowski?= Date: Thu, 8 Feb 2024 07:00:18 +0100 Subject: [PATCH 22/22] Update blocks.php --- src/wp-includes/blocks.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/blocks.php b/src/wp-includes/blocks.php index da1c9232f98d4..97cb68692927e 100644 --- a/src/wp-includes/blocks.php +++ b/src/wp-includes/blocks.php @@ -171,8 +171,8 @@ function register_block_script_handle( $metadata, $field_name, $index = 0 ) { } // Asset file for blocks is optional. See https://core.trac.wordpress.org/ticket/60460. - $script_asset = ! empty( $script_asset_path ) ? $script_asset_path : array(); - $script_dependencies = isset( $script_asset['dependencies'] ) ? require $script_asset['dependencies'] : array(); + $script_asset = ! empty( $script_asset_path ) ? require $script_asset_path : array(); + $script_dependencies = isset( $script_asset['dependencies'] ) ? $script_asset['dependencies'] : array(); $result = wp_register_script( $script_handle, $script_uri,