@@ -747,6 +747,46 @@ public function test_reports_if_block_is_of_type( $html, $block_type ) {
747747 }
748748 }
749749
750+ /**
751+ * Verifies that innerHTML only matches as a block type when checking with the wildcard '*'.
752+ *
753+ * @ticket 64485
754+ *
755+ * @covers ::is_block_type()
756+ */
757+ public function test_inner_html_is_only_a_block_type_match_with_the_wildcard () {
758+ $ processor = new WP_Block_Processor ( '0<!-- wp:b1 -->1<!-- wp:b2 --> ' );
759+
760+ $ processor ->next_token ();
761+ $ this ->assertTrue (
762+ $ processor ->is_block_type ( 'freeform ' ),
763+ 'Failed to detect top-level freeform HTML as freeform block: check test setup. '
764+ );
765+
766+ $ processor ->next_token ();
767+ $ this ->assertTrue (
768+ $ processor ->is_block_type ( 'b1 ' ),
769+ 'Failed to detect opening delimiter as b1 block type: check test setup. '
770+ );
771+
772+ $ processor ->next_token ();
773+ $ this ->assertFalse (
774+ (
775+ $ processor ->is_block_type ( 'freeform ' ) ||
776+ $ processor ->is_block_type ( 'b1 ' ) ||
777+ $ processor ->is_block_type ( 'core/freeform ' ) ||
778+ $ processor ->is_block_type ( 'core/b1 ' ) ||
779+ $ processor ->is_block_type ( '' )
780+ ),
781+ 'Failed to reject innerHTML as a matched block type. '
782+ );
783+
784+ $ this ->assertTrue (
785+ $ processor ->is_block_type ( '* ' ),
786+ 'Failed to accept innerHTML as a wildcard block-type match. '
787+ );
788+ }
789+
750790 /**
751791 * Verifies that the processor indicates if the currently-matched delimiter
752792 * opens a block of a given block type. This is true for openers and void delimiters.
@@ -1211,6 +1251,65 @@ public static function data_content_and_delimiter_spans() {
12111251 );
12121252 }
12131253
1254+ /**
1255+ * Verifies that next_block( $block_type ) scans directly to the appropriate tokens.
1256+ *
1257+ * @ticket 64485
1258+ *
1259+ * @dataProvider data_markup_with_block_of_given_type
1260+ *
1261+ * @param string $html Contains block markup, including the tested block type.
1262+ * @param string $block_type Jump to this block type.
1263+ */
1264+ public function test_scans_directly_to_requested_block_type ( string $ html , string $ block_type ) {
1265+ $ processor = new WP_Block_Processor ( $ html );
1266+
1267+ $ this ->assertTrue (
1268+ $ processor ->next_block ( $ block_type ),
1269+ 'Failed to find block of requested type. '
1270+ );
1271+
1272+ $ full_block_type = WP_Block_Processor::normalize_block_type ( $ block_type );
1273+
1274+ if ( 'core/freeform ' === $ full_block_type ) {
1275+ $ this ->assertTrue (
1276+ $ processor ->is_html (),
1277+ 'Failed to match on HTML token when looking for freeform content. '
1278+ );
1279+
1280+ $ this ->assertSame (
1281+ 0 ,
1282+ $ processor ->get_depth (),
1283+ 'Failed to scan to top-level freeform content when searching for freeform. '
1284+ );
1285+ } else {
1286+ $ this ->assertFalse (
1287+ $ processor ->is_html (),
1288+ 'Matched on HTML token when looking for block delimiter. '
1289+ );
1290+ }
1291+
1292+ $ this ->assertSame (
1293+ $ full_block_type ,
1294+ $ processor ->get_printable_block_type (),
1295+ 'Scanned to token of wrong block type. '
1296+ );
1297+ }
1298+
1299+ /**
1300+ * Data provider.
1301+ *
1302+ * @return array[]
1303+ */
1304+ public static function data_markup_with_block_of_given_type () {
1305+ return array (
1306+ 'At start of HTML ' => array ( '<!-- wp:target --> ' , 'target ' ),
1307+ 'After freeform text ' => array ( 'prefix<!-- wp:target --> ' , 'target ' ),
1308+ 'After outer block ' => array ( 'prefix<!-- wp:group --><!-- wp:target --> ' , 'target ' ),
1309+ 'After innerHTML ' => array ( 'prefix<!-- wp:group -->inner<!-- wp:target --> ' , 'target ' ),
1310+ );
1311+ }
1312+
12141313 //
12151314 // Test helpers.
12161315 //
0 commit comments