Editor: Make asset file optional for block scripts

It is no longer a hard requirement that a *.asset.php file is present to register a script for block. 

Fixes #57234.
Props joefusco, gziolo, spacedmonkey, colorful-tones. 



git-svn-id: https://develop.svn.wordpress.org/trunk@57559 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Greg Ziółkowski
2024-02-08 08:16:59 +00:00
parent b3d834c132
commit 0ff0842fee
2 changed files with 26 additions and 33 deletions

View File

@@ -60,6 +60,12 @@ class Tests_Blocks_Register extends WP_UnitTestCase {
}
}
foreach ( wp_scripts()->registered as $script_handle => $script ) {
if ( str_starts_with( $script_handle, 'unit-tests-' ) ) {
wp_deregister_script( $script_handle );
}
}
parent::tear_down();
}
@@ -225,21 +231,6 @@ class Tests_Blocks_Register extends WP_UnitTestCase {
$this->assertFalse( $result );
}
/**
* @expectedIncorrectUsage register_block_script_handle
* @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 50263
*/
@@ -264,6 +255,21 @@ class Tests_Blocks_Register extends WP_UnitTestCase {
$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', $result );
}
/**
* @ticket 50263
*/