Skip to content

Commit 7a3f71b

Browse files
dmsnellsirreal
andcommitted
Add tests for extract_full_block_and_advance() (WordPress#10769)
Trac ticket: Core-64537 Initially ported from sirreal#20 Developed in: WordPress#10769 Discussed in: https://core.trac.wordpress.org/ticket/64537#ticket Follow-up to [[60939]](https://core.trac.wordpress.org/changeset/60939). Props jonsurrell, dmsnell. Fixes Core-64537 Co-authored-by: Jon Surrell <jonsurrell@git.wordpress.org> Github-PR: 10769 Github-PR-URL: WordPress#10769 Trac-Ticket: 64537 Trac-Ticket-URL: https://core.trac.wordpress.org/ticket/64537 Branch-Name: blocks/add-block-processor-tests
1 parent 1943f9b commit 7a3f71b

1 file changed

Lines changed: 92 additions & 0 deletions

File tree

tests/phpunit/tests/block-processor/wpBlockProcessor.php

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,6 +1296,98 @@ public function test_scans_directly_to_requested_block_type( string $html, strin
12961296
);
12971297
}
12981298

1299+
/**
1300+
* Ensures that block extraction matches the behavior of the default block parser.
1301+
*
1302+
* @ticket {TICKET_NUMBER}
1303+
*
1304+
* @dataProvider data_various_block_posts
1305+
*
1306+
* @param string $test_document An HTML document to parse as blocks.
1307+
*/
1308+
public function test_extracts_equivalent_parses_as_parse_blocks( string $test_document ) {
1309+
$processor = new WP_Block_Processor( $test_document );
1310+
$blocks = array();
1311+
1312+
while ( $processor->next_block( '*' ) ) {
1313+
$blocks[] = $processor->extract_full_block_and_advance();
1314+
}
1315+
1316+
$this->assertSame(
1317+
parse_blocks( $test_document ),
1318+
$blocks,
1319+
'Failed to properly parse the block structure.'
1320+
);
1321+
}
1322+
1323+
/**
1324+
* Data provider.
1325+
*
1326+
* @return Generator
1327+
*/
1328+
public static function data_various_block_posts() {
1329+
yield 'Empty post' => array( '' );
1330+
1331+
yield 'Void block' => array( '<!-- wp:void /-->' );
1332+
1333+
yield 'Empty block' => array( '<!-- wp:empty --><!-- /wp:empty -->' );
1334+
1335+
yield 'Paragraph block' => array( '<!-- wp:paragraph --><p>Test</p><!-- /wp:paragraph -->' );
1336+
1337+
yield 'Paragraph block with attributes' => array(
1338+
'<!-- wp:paragraph {"dropCaps": true} --><p>Test</p><!-- /wp:paragraph -->',
1339+
);
1340+
1341+
yield 'Group with void inner' => array(
1342+
'<!-- wp:group --><!-- wp:void /--><!-- /wp:group -->',
1343+
);
1344+
1345+
yield 'Empty columns' => array(
1346+
'<!-- wp:columns --><!-- wp:column --><!-- wp:column /--><!-- /wp:columns -->',
1347+
);
1348+
1349+
yield 'Contentful columns' => array(
1350+
<<<HTML
1351+
<!-- wp:columns -->
1352+
<ul>
1353+
<!-- wp:column -->
1354+
<li>A good point.</li>
1355+
<!-- wp:column /-->
1356+
</ul>
1357+
<!-- /wp:columns -->
1358+
HTML
1359+
);
1360+
1361+
yield 'Group with mixed content' => array(
1362+
<<<HTML
1363+
<!-- wp:group -->
1364+
<div>
1365+
<!-- wp:paragraph --><p>Test</p><!-- /wp:paragraph -->
1366+
This is freeform.
1367+
<!-- wp:void /-->
1368+
End
1369+
<!-- wp:footer ->
1370+
<footer>That&rsquo;s it!</footer>
1371+
<!-- /wp:footer -->
1372+
</div>
1373+
<!-- /wp:group -->
1374+
HTML
1375+
);
1376+
1377+
yield 'Nested blocks' => array(
1378+
<<<HTML
1379+
<!-- wp:a -->
1380+
<div>
1381+
<!-- wp:b -->
1382+
<span><!-- wp:c /--></span>
1383+
<!-- /wp:b -->
1384+
</div>
1385+
<!-- /wp:a -->
1386+
HTML
1387+
1388+
);
1389+
}
1390+
12991391
/**
13001392
* Data provider.
13011393
*

0 commit comments

Comments
 (0)