|
7 | 7 |
|
8 | 8 | namespace WPCOMVIP\BlockDataApi; |
9 | 9 |
|
| 10 | +use WP_Error; |
| 11 | + |
10 | 12 | /** |
11 | 13 | * Content parser tests that are not source-specific. |
12 | 14 | */ |
@@ -215,4 +217,36 @@ public function test_parse_whitespace_block_removal() { |
215 | 217 | $this->assertArrayHasKey( 'blocks', $blocks, sprintf( 'Unexpected parser output: %s', wp_json_encode( $blocks ) ) ); |
216 | 218 | $this->assertEquals( $expected_blocks, $blocks['blocks'], sprintf( 'Blocks do not match: %s', wp_json_encode( $blocks ) ) ); |
217 | 219 | } |
| 220 | + |
| 221 | + /* Classic editor content */ |
| 222 | + |
| 223 | + public function test_parse_classic_editor_content() { |
| 224 | + $html = 'Hello, world!'; |
| 225 | + |
| 226 | + $content_parser = new ContentParser( $this->get_block_registry() ); |
| 227 | + $blocks = $content_parser->parse( $html ); |
| 228 | + |
| 229 | + $this->assertInstanceOf( WP_Error::class, $blocks, sprintf( 'Unexpected parser output: %s', wp_json_encode( $blocks ) ) ); |
| 230 | + |
| 231 | + $errors = $blocks->get_error_messages(); |
| 232 | + $this->assertEquals( 1, count( $errors ), 'Expected error messages but found none.' ); |
| 233 | + $this->assertStringContainsString( |
| 234 | + 'This post does not appear to contain block content.', |
| 235 | + $errors[0], |
| 236 | + sprintf( 'Unexpected error messages: %s', wp_json_encode( $errors ) ) |
| 237 | + ); |
| 238 | + } |
| 239 | + |
| 240 | + /* Empty content */ |
| 241 | + |
| 242 | + public function test_parse_empty_content() { |
| 243 | + $html = ''; |
| 244 | + $expected_blocks = []; |
| 245 | + |
| 246 | + $content_parser = new ContentParser( $this->get_block_registry() ); |
| 247 | + $blocks = $content_parser->parse( $html ); |
| 248 | + |
| 249 | + $this->assertArrayHasKey( 'blocks', $blocks, sprintf( 'Unexpected parser output: %s', wp_json_encode( $blocks ) ) ); |
| 250 | + $this->assertEquals( $expected_blocks, $blocks['blocks'], sprintf( 'Blocks do not match: %s', wp_json_encode( $blocks ) ) ); |
| 251 | + } |
218 | 252 | } |
0 commit comments