-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Block API: Add new utility to register block types from metadata in P…
…HP (#20794) * Blocks: Add new utility to register block types from metadata in PHP * Add basic PHPUnit tests for block metadata registration
- Loading branch information
Showing
15 changed files
with
137 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
/** | ||
* Test `register_block_type_from_metadata`. | ||
* | ||
* @package Gutenberg | ||
*/ | ||
|
||
class Register_Block_Type_From_Metadata_Test extends WP_UnitTestCase { | ||
/** | ||
* Tests that the function returns false when the `block.json` is not found | ||
* in the WordPress core. | ||
*/ | ||
function test_metadata_not_found_in_wordpress_core() { | ||
$result = register_block_type_from_metadata( 'unknown' ); | ||
|
||
$this->assertFalse( $result ); | ||
} | ||
|
||
/** | ||
* Tests that the function returns false when the `block.json` is not found | ||
* in the current directory. | ||
*/ | ||
function test_metadata_not_found_in_the_current_directory() { | ||
$result = register_block_type_from_metadata( __DIR__ ); | ||
|
||
$this->assertFalse( $result ); | ||
} | ||
|
||
/** | ||
* Tests that the function returns the registered block when the `block.json` | ||
* is found in the fixtures directory. | ||
*/ | ||
function test_block_registers_with_metadata_fixture() { | ||
$result = register_block_type_from_metadata( | ||
__DIR__ . '/fixtures', | ||
array( | ||
'foo' => 'bar', | ||
) | ||
); | ||
|
||
$this->assertInstanceOf( 'WP_Block_Type', $result ); | ||
$this->assertEquals( 'test/block-name', $result->name ); | ||
$this->assertEquals( 'bar', $result->foo ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "test/block-name", | ||
"category": "widgets" | ||
} |