From 2b8fc0cafd8d93595b8bb7a604647184a50561ef Mon Sep 17 00:00:00 2001 From: Matthew Reishus Date: Mon, 23 Sep 2024 22:53:43 +0000 Subject: [PATCH] add tests --- .../tests/blocks/wpBlockMetadataRegistry.php | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 tests/phpunit/tests/blocks/wpBlockMetadataRegistry.php diff --git a/tests/phpunit/tests/blocks/wpBlockMetadataRegistry.php b/tests/phpunit/tests/blocks/wpBlockMetadataRegistry.php new file mode 100644 index 0000000000000..07ab15bbbd48d --- /dev/null +++ b/tests/phpunit/tests/blocks/wpBlockMetadataRegistry.php @@ -0,0 +1,61 @@ +temp_manifest_file = wp_tempnam( 'block-metadata-manifest' ); + } + + public function tear_down() { + unlink( $this->temp_manifest_file ); + parent::tear_down(); + } + + public function test_register_collection_and_get_metadata() { + $path = '/test/path'; + $manifest_data = array( + 'test-block' => array( + 'name' => 'test-block', + 'title' => 'Test Block', + ), + ); + + file_put_contents( $this->temp_manifest_file, 'temp_manifest_file ); + + $retrieved_metadata = WP_Block_Metadata_Registry::get_metadata( $path, 'test-block' ); + $this->assertEquals( $manifest_data['test-block'], $retrieved_metadata ); + } + + public function test_get_nonexistent_metadata() { + $path = '/nonexistent/path'; + $retrieved_metadata = WP_Block_Metadata_Registry::get_metadata( $path, 'nonexistent-block' ); + $this->assertNull( $retrieved_metadata ); + } + + public function test_has_metadata() { + $path = '/another/test/path'; + $manifest_data = array( + 'existing-block' => array( + 'name' => 'existing-block', + 'title' => 'Existing Block', + ), + ); + + file_put_contents( $this->temp_manifest_file, 'temp_manifest_file ); + + $this->assertTrue( WP_Block_Metadata_Registry::has_metadata( $path, 'existing-block' ) ); + $this->assertFalse( WP_Block_Metadata_Registry::has_metadata( $path, 'non-existing-block' ) ); + } +}