diff --git a/tests/graphql/test-graphql-api-v1.php b/tests/graphql/test-graphql-api-v1.php index 9a5d74f2..48bb901f 100644 --- a/tests/graphql/test-graphql-api-v1.php +++ b/tests/graphql/test-graphql-api-v1.php @@ -37,7 +37,7 @@ public function test_is_graphql_enabled_false() { // get_blocks_data() tests public function test_get_blocks_data() { - $this->register_global_block_with_attributes( 'test/custom-paragraph', [ + $this->register_block_with_attributes( 'test/custom-paragraph', [ 'content' => [ 'type' => 'rich-text', 'source' => 'rich-text', @@ -53,7 +53,7 @@ public function test_get_blocks_data() { ], ] ); - $this->register_global_block_with_attributes( 'test/custom-quote', [ + $this->register_block_with_attributes( 'test/custom-quote', [ 'value' => [ 'type' => 'string', 'source' => 'html', @@ -70,7 +70,7 @@ public function test_get_blocks_data() { ], ] ); - $this->register_global_block_with_attributes( 'test/custom-heading', [ + $this->register_block_with_attributes( 'test/custom-heading', [ 'content' => [ 'type' => 'rich-text', 'source' => 'rich-text', @@ -192,7 +192,7 @@ public function test_get_blocks_data() { // get_blocks_data() attribute type tests public function test_array_data_in_attribute() { - $this->register_global_block_with_attributes( 'test/custom-table', [ + $this->register_block_with_attributes( 'test/custom-table', [ 'head' => [ 'type' => 'array', 'default' => [], diff --git a/tests/graphql/test-graphql-api-v2.php b/tests/graphql/test-graphql-api-v2.php index 326c35eb..4de67c1a 100644 --- a/tests/graphql/test-graphql-api-v2.php +++ b/tests/graphql/test-graphql-api-v2.php @@ -37,7 +37,7 @@ public function test_is_graphql_enabled_false() { // get_blocks_data() tests public function test_get_blocks_data() { - $this->register_global_block_with_attributes( 'test/custom-paragraph', [ + $this->register_block_with_attributes( 'test/custom-paragraph', [ 'content' => [ 'type' => 'rich-text', 'source' => 'rich-text', @@ -53,7 +53,7 @@ public function test_get_blocks_data() { ], ] ); - $this->register_global_block_with_attributes( 'test/custom-quote', [ + $this->register_block_with_attributes( 'test/custom-quote', [ 'value' => [ 'type' => 'string', 'source' => 'html', @@ -70,7 +70,7 @@ public function test_get_blocks_data() { ], ] ); - $this->register_global_block_with_attributes( 'test/custom-heading', [ + $this->register_block_with_attributes( 'test/custom-heading', [ 'content' => [ 'type' => 'rich-text', 'source' => 'rich-text', @@ -193,7 +193,7 @@ public function test_get_blocks_data() { // get_blocks_data() attribute type tests public function test_array_data_in_attribute() { - $this->register_global_block_with_attributes( 'test/custom-table', [ + $this->register_block_with_attributes( 'test/custom-table', [ 'head' => [ 'type' => 'array', 'default' => [], @@ -339,7 +339,7 @@ public function test_array_data_in_attribute() { } public function test_get_block_data_with_boolean_attributes() { - $this->register_global_block_with_attributes( 'test/toggle-text', [ + $this->register_block_with_attributes( 'test/toggle-text', [ 'isVisible' => [ 'type' => 'boolean', ], @@ -386,7 +386,7 @@ public function test_get_block_data_with_boolean_attributes() { } public function test_get_block_data_with_number_attributes() { - $this->register_global_block_with_attributes( 'test/gallery-block', [ + $this->register_block_with_attributes( 'test/gallery-block', [ 'tileCount' => [ 'type' => 'number', ], @@ -441,7 +441,7 @@ public function test_get_block_data_with_number_attributes() { } public function test_get_block_data_with_string_attribute() { - $this->register_global_block_with_attributes( 'test/custom-block', [ + $this->register_block_with_attributes( 'test/custom-block', [ 'myComment' => [ 'type' => 'string', ], diff --git a/tests/parser/blocks/test-unregistered-block.php b/tests/parser/blocks/test-unregistered-block.php index e884d37d..2cc5a39a 100644 --- a/tests/parser/blocks/test-unregistered-block.php +++ b/tests/parser/blocks/test-unregistered-block.php @@ -31,7 +31,7 @@ public function test_parse_unregistered_block() { 'Block type "test/unknown-block" is not server-side registered. Sourced block attributes will not be available.', ]; - $content_parser = new ContentParser( $this->registry ); + $content_parser = new ContentParser( $this->get_block_registry() ); $blocks = $content_parser->parse( $html ); $this->assertArrayHasKey( 'blocks', $blocks, sprintf( 'Unexpected parser output: %s', wp_json_encode( $blocks ) ) ); $this->assertArrayHasKey( 'warnings', $blocks, sprintf( 'Expected parser to have warnings, none received: %s', wp_json_encode( $blocks ) ) ); diff --git a/tests/parser/sources/test-source-attribute.php b/tests/parser/sources/test-source-attribute.php index 5214695a..2273127b 100644 --- a/tests/parser/sources/test-source-attribute.php +++ b/tests/parser/sources/test-source-attribute.php @@ -37,7 +37,7 @@ public function test_parse_attribute_source() { ], ]; - $content_parser = new ContentParser( $this->registry ); + $content_parser = new ContentParser( $this->get_block_registry() ); $blocks = $content_parser->parse( $html ); $this->assertArrayHasKey( 'blocks', $blocks, sprintf( 'Unexpected parser output: %s', wp_json_encode( $blocks ) ) ); $this->assertArraySubset( $expected_blocks, $blocks['blocks'], true ); @@ -69,7 +69,7 @@ public function test_parse_attribute_source__with_default_value() { ], ]; - $content_parser = new ContentParser( $this->registry ); + $content_parser = new ContentParser( $this->get_block_registry() ); $blocks = $content_parser->parse( $html ); $this->assertArrayHasKey( 'blocks', $blocks, sprintf( 'Unexpected parser output: %s', wp_json_encode( $blocks ) ) ); $this->assertArraySubset( $expected_blocks, $blocks['blocks'], true ); @@ -100,7 +100,7 @@ public function test_parse_attribute_source__with_asterisk_selector() { ], ]; - $content_parser = new ContentParser( $this->registry ); + $content_parser = new ContentParser( $this->get_block_registry() ); $blocks = $content_parser->parse( $html ); $this->assertArrayHasKey( 'blocks', $blocks, sprintf( 'Unexpected parser output: %s', wp_json_encode( $blocks ) ) ); $this->assertArraySubset( $expected_blocks, $blocks['blocks'], true ); diff --git a/tests/parser/sources/test-source-children.php b/tests/parser/sources/test-source-children.php index d5a5506e..198fd61f 100644 --- a/tests/parser/sources/test-source-children.php +++ b/tests/parser/sources/test-source-children.php @@ -52,7 +52,7 @@ public function test_parse_children__with_list_elements() { ], ]; - $content_parser = new ContentParser( $this->registry ); + $content_parser = new ContentParser( $this->get_block_registry() ); $blocks = $content_parser->parse( $html ); $this->assertArrayHasKey( 'blocks', $blocks, sprintf( 'Unexpected parser output: %s', wp_json_encode( $blocks ) ) ); $this->assertArraySubset( $expected_blocks, $blocks['blocks'], true ); @@ -86,7 +86,7 @@ public function test_parse_children__with_single_child() { ], ]; - $content_parser = new ContentParser( $this->registry ); + $content_parser = new ContentParser( $this->get_block_registry() ); $blocks = $content_parser->parse( $html ); $this->assertArrayHasKey( 'blocks', $blocks, sprintf( 'Unexpected parser output: %s', wp_json_encode( $blocks ) ) ); $this->assertArraySubset( $expected_blocks, $blocks['blocks'], true ); @@ -126,7 +126,7 @@ public function test_parse_children__with_mixed_nodes_and_text() { ], ]; - $content_parser = new ContentParser( $this->registry ); + $content_parser = new ContentParser( $this->get_block_registry() ); $blocks = $content_parser->parse( $html ); $this->assertArrayHasKey( 'blocks', $blocks, sprintf( 'Unexpected parser output: %s', wp_json_encode( $blocks ) ) ); $this->assertArraySubset( $expected_blocks, $blocks['blocks'], true ); @@ -157,7 +157,7 @@ public function test_parse_children__with_default_value() { ], ]; - $content_parser = new ContentParser( $this->registry ); + $content_parser = new ContentParser( $this->get_block_registry() ); $blocks = $content_parser->parse( $html ); $this->assertArrayHasKey( 'blocks', $blocks, sprintf( 'Unexpected parser output: %s', wp_json_encode( $blocks ) ) ); $this->assertArraySubset( $expected_blocks, $blocks['blocks'], true ); diff --git a/tests/parser/sources/test-source-delimiter.php b/tests/parser/sources/test-source-delimiter.php index 5ee0b5fe..93e08cf2 100644 --- a/tests/parser/sources/test-source-delimiter.php +++ b/tests/parser/sources/test-source-delimiter.php @@ -45,7 +45,7 @@ public function test_parse_block_delimiter_attributes() { ], ]; - $content_parser = new ContentParser( $this->registry ); + $content_parser = new ContentParser( $this->get_block_registry() ); $blocks = $content_parser->parse( $html ); $this->assertArrayHasKey( 'blocks', $blocks, sprintf( 'Unexpected parser output: %s', wp_json_encode( $blocks ) ) ); $this->assertArraySubset( $expected_blocks, $blocks['blocks'], true ); @@ -75,7 +75,7 @@ public function test_parse_block_delimiter_attributes__are_overridden_by_sourced ], ]; - $content_parser = new ContentParser( $this->registry ); + $content_parser = new ContentParser( $this->get_block_registry() ); $blocks = $content_parser->parse( $html ); $this->assertArrayHasKey( 'blocks', $blocks, sprintf( 'Unexpected parser output: %s', wp_json_encode( $blocks ) ) ); $this->assertArraySubset( $expected_blocks, $blocks['blocks'], true ); diff --git a/tests/parser/sources/test-source-html.php b/tests/parser/sources/test-source-html.php index 3b5ef245..61d6d87c 100644 --- a/tests/parser/sources/test-source-html.php +++ b/tests/parser/sources/test-source-html.php @@ -36,7 +36,7 @@ public function test_parse_html_source() { ], ]; - $content_parser = new ContentParser( $this->registry ); + $content_parser = new ContentParser( $this->get_block_registry() ); $blocks = $content_parser->parse( $html ); $this->assertArrayHasKey( 'blocks', $blocks, sprintf( 'Unexpected parser output: %s', wp_json_encode( $blocks ) ) ); $this->assertArraySubset( $expected_blocks, $blocks['blocks'], true ); @@ -71,7 +71,7 @@ public function test_parse_html_source__with_multiline_selector() { ], ]; - $content_parser = new ContentParser( $this->registry ); + $content_parser = new ContentParser( $this->get_block_registry() ); $blocks = $content_parser->parse( $html ); $this->assertArrayHasKey( 'blocks', $blocks, sprintf( 'Unexpected parser output: %s', wp_json_encode( $blocks ) ) ); $this->assertArraySubset( $expected_blocks, $blocks['blocks'], true ); @@ -102,7 +102,7 @@ public function test_parse_html_source__with_default_value() { ], ]; - $content_parser = new ContentParser( $this->registry ); + $content_parser = new ContentParser( $this->get_block_registry() ); $blocks = $content_parser->parse( $html ); $this->assertArrayHasKey( 'blocks', $blocks, sprintf( 'Unexpected parser output: %s', wp_json_encode( $blocks ) ) ); $this->assertArraySubset( $expected_blocks, $blocks['blocks'], true ); diff --git a/tests/parser/sources/test-source-meta.php b/tests/parser/sources/test-source-meta.php index 972fd3e1..758d6704 100644 --- a/tests/parser/sources/test-source-meta.php +++ b/tests/parser/sources/test-source-meta.php @@ -39,7 +39,7 @@ public function test_parse_meta_source() { return $post_id; }; - $content_parser = new ContentParser( $this->registry ); + $content_parser = new ContentParser( $this->get_block_registry() ); $blocks = $content_parser->parse( $html, $post_id ); $this->assertArrayHasKey( 'blocks', $blocks, sprintf( 'Unexpected parser output: %s', wp_json_encode( $blocks ) ) ); @@ -69,7 +69,7 @@ public function test_parse_meta_source__with_default_value() { ], ]; - $content_parser = new ContentParser( $this->registry ); + $content_parser = new ContentParser( $this->get_block_registry() ); $blocks = $content_parser->parse( $html, $post_id ); $this->assertArrayHasKey( 'blocks', $blocks, sprintf( 'Unexpected parser output: %s', wp_json_encode( $blocks ) ) ); diff --git a/tests/parser/sources/test-source-node.php b/tests/parser/sources/test-source-node.php index 602532e7..875277ea 100644 --- a/tests/parser/sources/test-source-node.php +++ b/tests/parser/sources/test-source-node.php @@ -43,7 +43,7 @@ public function test_parse_node__with_object_value() { ], ]; - $content_parser = new ContentParser( $this->registry ); + $content_parser = new ContentParser( $this->get_block_registry() ); $blocks = $content_parser->parse( $html ); $this->assertArrayHasKey( 'blocks', $blocks, sprintf( 'Unexpected parser output: %s', wp_json_encode( $blocks ) ) ); $this->assertArraySubset( $expected_blocks, $blocks['blocks'], true ); diff --git a/tests/parser/sources/test-source-query.php b/tests/parser/sources/test-source-query.php index 42b9263c..58548c1c 100644 --- a/tests/parser/sources/test-source-query.php +++ b/tests/parser/sources/test-source-query.php @@ -59,7 +59,7 @@ public function test_parse_query_source() { ], ]; - $content_parser = new ContentParser( $this->registry ); + $content_parser = new ContentParser( $this->get_block_registry() ); $blocks = $content_parser->parse( $html ); $this->assertArrayHasKey( 'blocks', $blocks, sprintf( 'Unexpected parser output: %s', wp_json_encode( $blocks ) ) ); @@ -145,7 +145,7 @@ public function test_parse_query_source__with_nested_query() { ], ]; - $content_parser = new ContentParser( $this->registry ); + $content_parser = new ContentParser( $this->get_block_registry() ); $blocks = $content_parser->parse( $html ); $this->assertArrayHasKey( 'blocks', $blocks, sprintf( 'Unexpected parser output: %s', wp_json_encode( $blocks ) ) ); @@ -193,7 +193,7 @@ public function test_parse_query_source__with_default_value() { ], ]; - $content_parser = new ContentParser( $this->registry ); + $content_parser = new ContentParser( $this->get_block_registry() ); $blocks = $content_parser->parse( $html ); $this->assertArrayHasKey( 'blocks', $blocks, sprintf( 'Unexpected parser output: %s', wp_json_encode( $blocks ) ) ); diff --git a/tests/parser/sources/test-source-raw.php b/tests/parser/sources/test-source-raw.php index 1fd4723b..f6d52b97 100644 --- a/tests/parser/sources/test-source-raw.php +++ b/tests/parser/sources/test-source-raw.php @@ -33,7 +33,7 @@ public function test_parse_raw_source() { ], ]; - $content_parser = new ContentParser( $this->registry ); + $content_parser = new ContentParser( $this->get_block_registry() ); $blocks = $content_parser->parse( $html ); $this->assertArrayHasKey( 'blocks', $blocks, sprintf( 'Unexpected parser output: %s', wp_json_encode( $blocks ) ) ); $this->assertArraySubset( $expected_blocks, $blocks['blocks'], true ); @@ -74,7 +74,7 @@ public function test_parse_raw_source__nested() { ], ]; - $content_parser = new ContentParser( $this->registry ); + $content_parser = new ContentParser( $this->get_block_registry() ); $blocks = $content_parser->parse( $html ); $this->assertArrayHasKey( 'blocks', $blocks, sprintf( 'Unexpected parser output: %s', wp_json_encode( $blocks ) ) ); $this->assertArraySubset( $expected_blocks, $blocks['blocks'], true ); diff --git a/tests/parser/sources/test-source-rich-text.php b/tests/parser/sources/test-source-rich-text.php index 286bc691..26421cc3 100644 --- a/tests/parser/sources/test-source-rich-text.php +++ b/tests/parser/sources/test-source-rich-text.php @@ -36,7 +36,7 @@ public function test_parse_rich_text_source() { ], ]; - $content_parser = new ContentParser( $this->registry ); + $content_parser = new ContentParser( $this->get_block_registry() ); $blocks = $content_parser->parse( $html ); $this->assertArrayHasKey( 'blocks', $blocks, sprintf( 'Unexpected parser output: %s', wp_json_encode( $blocks ) ) ); $this->assertArraySubset( $expected_blocks, $blocks['blocks'], true ); @@ -69,7 +69,7 @@ public function test_parse_rich_text_source__with_formatting() { ], ]; - $content_parser = new ContentParser( $this->registry ); + $content_parser = new ContentParser( $this->get_block_registry() ); $blocks = $content_parser->parse( $html ); $this->assertArrayHasKey( 'blocks', $blocks, sprintf( 'Unexpected parser output: %s', wp_json_encode( $blocks ) ) ); $this->assertArraySubset( $expected_blocks, $blocks['blocks'], true ); @@ -100,7 +100,7 @@ public function test_parse_rich_text_source__with_default_value() { ], ]; - $content_parser = new ContentParser( $this->registry ); + $content_parser = new ContentParser( $this->get_block_registry() ); $blocks = $content_parser->parse( $html ); $this->assertArrayHasKey( 'blocks', $blocks, sprintf( 'Unexpected parser output: %s', wp_json_encode( $blocks ) ) ); $this->assertArraySubset( $expected_blocks, $blocks['blocks'], true ); @@ -131,7 +131,7 @@ public function test_parse_rich_text_source__with_default_value_with_formatting( ], ]; - $content_parser = new ContentParser( $this->registry ); + $content_parser = new ContentParser( $this->get_block_registry() ); $blocks = $content_parser->parse( $html ); $this->assertArrayHasKey( 'blocks', $blocks, sprintf( 'Unexpected parser output: %s', wp_json_encode( $blocks ) ) ); $this->assertArraySubset( $expected_blocks, $blocks['blocks'], true ); diff --git a/tests/parser/sources/test-source-tag.php b/tests/parser/sources/test-source-tag.php index 93f4c4a9..51cfb2e1 100644 --- a/tests/parser/sources/test-source-tag.php +++ b/tests/parser/sources/test-source-tag.php @@ -35,7 +35,7 @@ public function test_parse_tag_source() { ], ]; - $content_parser = new ContentParser( $this->registry ); + $content_parser = new ContentParser( $this->get_block_registry() ); $blocks = $content_parser->parse( $html ); $this->assertArrayHasKey( 'blocks', $blocks, sprintf( 'Unexpected parser output: %s', wp_json_encode( $blocks ) ) ); $this->assertArraySubset( $expected_blocks, $blocks['blocks'], true ); @@ -79,7 +79,7 @@ public function test_parse_tag_source__in_query() { ], ]; - $content_parser = new ContentParser( $this->registry ); + $content_parser = new ContentParser( $this->get_block_registry() ); $blocks = $content_parser->parse( $html ); $this->assertArrayHasKey( 'blocks', $blocks, sprintf( 'Unexpected parser output: %s', wp_json_encode( $blocks ) ) ); $this->assertArraySubset( $expected_blocks, $blocks['blocks'], true ); @@ -106,7 +106,7 @@ public function test_parse_tag_source__with_default_value() { ], ]; - $content_parser = new ContentParser( $this->registry ); + $content_parser = new ContentParser( $this->get_block_registry() ); $blocks = $content_parser->parse( $html ); $this->assertArrayHasKey( 'blocks', $blocks, sprintf( 'Unexpected parser output: %s', wp_json_encode( $blocks ) ) ); $this->assertArraySubset( $expected_blocks, $blocks['blocks'], true ); diff --git a/tests/parser/sources/test-source-text.php b/tests/parser/sources/test-source-text.php index 6432d8eb..b63e12ce 100644 --- a/tests/parser/sources/test-source-text.php +++ b/tests/parser/sources/test-source-text.php @@ -38,7 +38,7 @@ public function test_parse_text_source() { ], ]; - $content_parser = new ContentParser( $this->registry ); + $content_parser = new ContentParser( $this->get_block_registry() ); $blocks = $content_parser->parse( $html ); $this->assertArrayHasKey( 'blocks', $blocks, sprintf( 'Unexpected parser output: %s', wp_json_encode( $blocks ) ) ); $this->assertArraySubset( $expected_blocks, $blocks['blocks'], true ); @@ -72,7 +72,7 @@ public function test_parse_text_source__with_html_tags() { ], ]; - $content_parser = new ContentParser( $this->registry ); + $content_parser = new ContentParser( $this->get_block_registry() ); $blocks = $content_parser->parse( $html ); $this->assertArrayHasKey( 'blocks', $blocks, sprintf( 'Unexpected parser output: %s', wp_json_encode( $blocks ) ) ); $this->assertArraySubset( $expected_blocks, $blocks['blocks'], true ); @@ -104,7 +104,7 @@ public function test_parse_text_source__with_default_value() { ], ]; - $content_parser = new ContentParser( $this->registry ); + $content_parser = new ContentParser( $this->get_block_registry() ); $blocks = $content_parser->parse( $html ); $this->assertArrayHasKey( 'blocks', $blocks, sprintf( 'Unexpected parser output: %s', wp_json_encode( $blocks ) ) ); $this->assertArraySubset( $expected_blocks, $blocks['blocks'], true ); diff --git a/tests/parser/test-content-parser.php b/tests/parser/test-content-parser.php index d11b65ec..0a077bec 100644 --- a/tests/parser/test-content-parser.php +++ b/tests/parser/test-content-parser.php @@ -47,7 +47,7 @@ public function test_parse_multiple_attributes_from_block() { ], ]; - $content_parser = new ContentParser( $this->registry ); + $content_parser = new ContentParser( $this->get_block_registry() ); $blocks = $content_parser->parse( $html ); $this->assertArrayHasKey( 'blocks', $blocks, sprintf( 'Unexpected parser output: %s', wp_json_encode( $blocks ) ) ); $this->assertArraySubset( $expected_blocks, $blocks['blocks'], true ); @@ -98,7 +98,7 @@ public function test_parse_multiple_blocks() { ], ]; - $content_parser = new ContentParser( $this->registry ); + $content_parser = new ContentParser( $this->get_block_registry() ); $blocks = $content_parser->parse( $html ); $this->assertArrayHasKey( 'blocks', $blocks, sprintf( 'Unexpected parser output: %s', wp_json_encode( $blocks ) ) ); $this->assertArraySubset( $expected_blocks, $blocks['blocks'], true ); @@ -157,7 +157,7 @@ public function test_parse_block_missing_attributes_and_defaults() { ], ]; - $content_parser = new ContentParser( $this->registry ); + $content_parser = new ContentParser( $this->get_block_registry() ); $blocks = $content_parser->parse( $html ); $this->assertArrayHasKey( 'blocks', $blocks, sprintf( 'Unexpected parser output: %s', wp_json_encode( $blocks ) ) ); $this->assertArraySubset( $expected_blocks, $blocks['blocks'], true ); diff --git a/tests/parser/test-inner-blocks.php b/tests/parser/test-inner-blocks.php index 07f5d016..2348761c 100644 --- a/tests/parser/test-inner-blocks.php +++ b/tests/parser/test-inner-blocks.php @@ -88,7 +88,7 @@ public function test_parse_inner_blocks__one_layer() { ], ]; - $content_parser = new ContentParser( $this->registry ); + $content_parser = new ContentParser( $this->get_block_registry() ); $blocks = $content_parser->parse( $html ); $this->assertArrayHasKey( 'blocks', $blocks, sprintf( 'Unexpected parser output: %s', wp_json_encode( $blocks ) ) ); $this->assertArraySubset( $expected_blocks, $blocks['blocks'], true ); @@ -181,7 +181,7 @@ public function test_parse_inner_blocks__two_layers() { ], ]; - $content_parser = new ContentParser( $this->registry ); + $content_parser = new ContentParser( $this->get_block_registry() ); $blocks = $content_parser->parse( $html ); $this->assertArrayHasKey( 'blocks', $blocks, sprintf( 'Unexpected parser output: %s', wp_json_encode( $blocks ) ) ); $this->assertArraySubset( $expected_blocks, $blocks['blocks'], true ); diff --git a/tests/parser/test-parser-filters.php b/tests/parser/test-parser-filters.php index de99543f..8b993e8e 100644 --- a/tests/parser/test-parser-filters.php +++ b/tests/parser/test-parser-filters.php @@ -59,7 +59,7 @@ public function test_allow_block_filter_via_code() { }; add_filter( 'vip_block_data_api__allow_block', $block_filter_function, 10, 2 ); - $content_parser = new ContentParser( $this->registry ); + $content_parser = new ContentParser( $this->get_block_registry() ); $blocks = $content_parser->parse( $html ); remove_filter( 'vip_block_data_api__allow_block', $block_filter_function, 10, 2 ); @@ -100,7 +100,7 @@ public function test_before_parse_post_content_filter() { }; add_filter( 'vip_block_data_api__before_parse_post_content', $replace_post_content_filter ); - $content_parser = new ContentParser( $this->registry ); + $content_parser = new ContentParser( $this->get_block_registry() ); $blocks = $content_parser->parse( $html ); remove_filter( 'vip_block_data_api__before_parse_post_content', $replace_post_content_filter ); @@ -143,7 +143,7 @@ public function test_after_parse_filter() { }; add_filter( 'vip_block_data_api__after_parse_blocks', $add_extra_data_filter ); - $content_parser = new ContentParser( $this->registry ); + $content_parser = new ContentParser( $this->get_block_registry() ); $result = $content_parser->parse( $html ); remove_filter( 'vip_block_data_api__after_parse_blocks', $add_extra_data_filter ); diff --git a/tests/registry-test-case.php b/tests/registry-test-case.php index d2d4004c..fcb76a48 100644 --- a/tests/registry-test-case.php +++ b/tests/registry-test-case.php @@ -12,18 +12,10 @@ class RegistryTestCase extends WP_UnitTestCase { use ArraySubsetAsserts; - protected $registry; - protected $globally_registered_blocks = []; - - protected function setUp(): void { - parent::setUp(); - - $this->registry = new WP_Block_Type_Registry(); - } - protected function tearDown(): void { - foreach ( $this->globally_registered_blocks as $block_name ) { - $this->unregister_global_block( $block_name ); + $block_registry = WP_Block_Type_Registry::get_instance(); + foreach ( $block_registry->get_all_registered() as $block ) { + $block_registry->unregister( $block->name ); } parent::tearDown(); @@ -31,31 +23,14 @@ protected function tearDown(): void { /* Helper methods */ - protected function register_block_with_attributes( $block_name, $attributes ) { - $this->registry->register( $block_name, [ - 'apiVersion' => 2, - 'attributes' => $attributes, - ] ); + protected function get_block_registry(): WP_Block_Type_Registry { + return WP_Block_Type_Registry::get_instance(); } - /* Global registrations */ - - protected function register_global_block_with_attributes( $block_name, $attributes ) { - // Use this function for mocking blocks definitions that need to persist across HTTP requests, like GraphQL tests. - - WP_Block_Type_Registry::get_instance()->register( $block_name, [ + protected function register_block_with_attributes( string $block_name, array $attributes ): void { + $this->get_block_registry()->register( $block_name, [ 'apiVersion' => 2, 'attributes' => $attributes, ] ); - - $this->globally_registered_blocks[] = $block_name; - } - - protected function unregister_global_block( $block_name ) { - $registry = WP_Block_Type_Registry::get_instance(); - - if ( $registry->is_registered( $block_name ) ) { - $registry->unregister( $block_name ); - } } } diff --git a/tests/rest/test-rest-api.php b/tests/rest/test-rest-api.php index 0955bdb4..bc6b5386 100644 --- a/tests/rest/test-rest-api.php +++ b/tests/rest/test-rest-api.php @@ -8,17 +8,14 @@ namespace WPCOMVIP\BlockDataApi; use Exception; -use WP_Block_Type_Registry; -use WP_UnitTestCase; use WP_REST_Server; use WP_REST_Request; /** * e2e tests to ensure that the REST API endpoint is available. */ -class RestApiTest extends WP_UnitTestCase { +class RestApiTest extends RegistryTestCase { private $server; - private $globally_registered_blocks = []; protected function setUp(): void { parent::setUp(); @@ -34,15 +31,11 @@ protected function tearDown(): void { global $wp_rest_server; $wp_rest_server = null; - foreach ( $this->globally_registered_blocks as $block_name ) { - $this->unregister_global_block( $block_name ); - } - parent::tearDown(); } public function test_rest_api_returns_blocks_for_post() { - $this->register_global_block_with_attributes( 'test/custom-heading', [ + $this->register_block_with_attributes( 'test/custom-heading', [ 'content' => [ 'type' => 'rich-text', 'source' => 'rich-text', @@ -55,7 +48,7 @@ public function test_rest_api_returns_blocks_for_post() { ], ] ); - $this->register_global_block_with_attributes( 'test/custom-quote', [ + $this->register_block_with_attributes( 'test/custom-quote', [ 'value' => [ 'type' => 'string', 'source' => 'html', @@ -72,7 +65,7 @@ public function test_rest_api_returns_blocks_for_post() { ], ] ); - $this->register_global_block_with_attributes( 'test/custom-paragraph', [ + $this->register_block_with_attributes( 'test/custom-paragraph', [ 'content' => [ 'type' => 'rich-text', 'source' => 'rich-text', @@ -88,14 +81,14 @@ public function test_rest_api_returns_blocks_for_post() { ], ] ); - $this->register_global_block_with_attributes( 'test/custom-separator', [ + $this->register_block_with_attributes( 'test/custom-separator', [ 'opacity' => [ 'type' => 'string', 'default' => 'alpha-channel', ], ] ); - $this->register_global_block_with_attributes( 'test/custom-media-text', [ + $this->register_block_with_attributes( 'test/custom-media-text', [ 'align' => [ 'type' => 'string', 'default' => 'none', @@ -245,7 +238,7 @@ public function test_rest_api_returns_blocks_for_post() { } public function test_rest_api_does_not_return_excluded_blocks_for_post() { - $this->register_global_block_with_attributes( 'test/custom-heading', [ + $this->register_block_with_attributes( 'test/custom-heading', [ 'content' => [ 'type' => 'rich-text', 'source' => 'rich-text', @@ -258,7 +251,7 @@ public function test_rest_api_does_not_return_excluded_blocks_for_post() { ], ] ); - $this->register_global_block_with_attributes( 'test/custom-quote', [ + $this->register_block_with_attributes( 'test/custom-quote', [ 'value' => [ 'type' => 'string', 'source' => 'html', @@ -275,7 +268,7 @@ public function test_rest_api_does_not_return_excluded_blocks_for_post() { ], ] ); - $this->register_global_block_with_attributes( 'test/custom-paragraph', [ + $this->register_block_with_attributes( 'test/custom-paragraph', [ 'content' => [ 'type' => 'rich-text', 'source' => 'rich-text', @@ -291,14 +284,14 @@ public function test_rest_api_does_not_return_excluded_blocks_for_post() { ], ] ); - $this->register_global_block_with_attributes( 'test/custom-separator', [ + $this->register_block_with_attributes( 'test/custom-separator', [ 'opacity' => [ 'type' => 'string', 'default' => 'alpha-channel', ], ] ); - $this->register_global_block_with_attributes( 'test/custom-media-text', [ + $this->register_block_with_attributes( 'test/custom-media-text', [ 'align' => [ 'type' => 'string', 'default' => 'none', @@ -426,7 +419,7 @@ public function test_rest_api_does_not_return_excluded_blocks_for_post() { } public function test_rest_api_only_returns_included_blocks_for_post() { - $this->register_global_block_with_attributes( 'test/custom-heading', [ + $this->register_block_with_attributes( 'test/custom-heading', [ 'content' => [ 'type' => 'rich-text', 'source' => 'rich-text', @@ -439,7 +432,7 @@ public function test_rest_api_only_returns_included_blocks_for_post() { ], ] ); - $this->register_global_block_with_attributes( 'test/custom-quote', [ + $this->register_block_with_attributes( 'test/custom-quote', [ 'value' => [ 'type' => 'string', 'source' => 'html', @@ -456,7 +449,7 @@ public function test_rest_api_only_returns_included_blocks_for_post() { ], ] ); - $this->register_global_block_with_attributes( 'test/custom-paragraph', [ + $this->register_block_with_attributes( 'test/custom-paragraph', [ 'content' => [ 'type' => 'rich-text', 'source' => 'rich-text', @@ -472,14 +465,14 @@ public function test_rest_api_only_returns_included_blocks_for_post() { ], ] ); - $this->register_global_block_with_attributes( 'test/custom-separator', [ + $this->register_block_with_attributes( 'test/custom-separator', [ 'opacity' => [ 'type' => 'string', 'default' => 'alpha-channel', ], ] ); - $this->register_global_block_with_attributes( 'test/custom-media-text', [ + $this->register_block_with_attributes( 'test/custom-media-text', [ 'align' => [ 'type' => 'string', 'default' => 'none', @@ -590,7 +583,7 @@ public function test_rest_api_returns_blocks_for_custom_post_type() { 'show_in_rest' => true, ]); - $this->register_global_block_with_attributes( 'test/custom-paragraph', [ + $this->register_block_with_attributes( 'test/custom-paragraph', [ 'content' => [ 'type' => 'rich-text', 'source' => 'rich-text', @@ -645,7 +638,7 @@ public function test_rest_api_returns_error_for_non_public_post_type() { 'public' => false, ]); - $this->register_global_block_with_attributes( 'test/custom-paragraph', [ + $this->register_block_with_attributes( 'test/custom-paragraph', [ 'content' => [ 'type' => 'rich-text', 'source' => 'rich-text', @@ -681,7 +674,7 @@ public function test_rest_api_returns_error_for_non_rest_post_type() { 'show_in_rest' => false, ]); - $this->register_global_block_with_attributes( 'test/custom-paragraph', [ + $this->register_block_with_attributes( 'test/custom-paragraph', [ 'content' => [ 'type' => 'rich-text', 'source' => 'rich-text', @@ -712,7 +705,7 @@ public function test_rest_api_returns_error_for_non_rest_post_type() { } public function test_rest_api_returns_error_for_unpublished_post() { - $this->register_global_block_with_attributes( 'test/custom-paragraph', [ + $this->register_block_with_attributes( 'test/custom-paragraph', [ 'content' => [ 'type' => 'rich-text', 'source' => 'rich-text', @@ -763,7 +756,7 @@ public function test_rest_api_returns_error_for_classic_content() { } public function test_rest_api_returns_error_for_include_and_exclude_filter() { - $this->register_global_block_with_attributes( 'test/custom-paragraph', [ + $this->register_block_with_attributes( 'test/custom-paragraph', [ 'content' => [ 'type' => 'rich-text', 'source' => 'rich-text', @@ -798,7 +791,7 @@ public function test_rest_api_returns_error_for_include_and_exclude_filter() { } public function test_rest_api_returns_error_for_unexpected_exception() { - $this->register_global_block_with_attributes( 'test/custom-paragraph', [ + $this->register_block_with_attributes( 'test/custom-paragraph', [ 'content' => [ 'type' => 'rich-text', 'source' => 'rich-text', @@ -857,21 +850,4 @@ static function ( int $errno, string $errstr ): never { E_USER_WARNING ); } - - private function register_global_block_with_attributes( $block_name, $attributes ) { - WP_Block_Type_Registry::get_instance()->register( $block_name, [ - 'apiVersion' => 2, - 'attributes' => $attributes, - ] ); - - $this->globally_registered_blocks[] = $block_name; - } - - private function unregister_global_block( $block_name ) { - $registry = WP_Block_Type_Registry::get_instance(); - - if ( $registry->is_registered( $block_name ) ) { - $registry->unregister( $block_name ); - } - } }