Skip to content

Commit 4cfe451

Browse files
committed
Test that next_tag() without query defaults to visiting tag closers (for now)
1 parent b45e4bb commit 4cfe451

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

plugins/optimization-detective/tests/test-class-od-html-tag-processor.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,57 @@ public function test_next_tag_with_query(): void {
526526
$this->assertSame( 5, $p->get_current_depth() );
527527
}
528528

529+
/**
530+
* Test next_tag() without passing query.
531+
*
532+
* @todo This test will need to be updated once next_tag() defaults to not visiting closers by default.
533+
*
534+
* @covers ::next_tag
535+
*/
536+
public function test_next_tag_without_query(): void {
537+
$html = '
538+
<!DOCTYPE html>
539+
<html>
540+
<head>
541+
<title></title>
542+
</head>
543+
<body></body>
544+
</html>
545+
';
546+
547+
$p = new OD_HTML_Tag_Processor( $html );
548+
$this->assertTrue( $p->next_tag() );
549+
$this->assertSame( 'HTML', $p->get_tag() );
550+
$this->assertFalse( $p->is_tag_closer() );
551+
552+
$this->assertTrue( $p->next_tag() );
553+
$this->assertSame( 'HEAD', $p->get_tag() );
554+
$this->assertFalse( $p->is_tag_closer() );
555+
556+
$this->assertTrue( $p->next_tag() );
557+
$this->assertSame( 'TITLE', $p->get_tag() );
558+
$this->assertFalse( $p->is_tag_closer() );
559+
560+
// Note: This is not a closing TITLE tag as would be expected since it is special.
561+
$this->assertTrue( $p->next_tag() );
562+
$this->assertSame( 'HEAD', $p->get_tag() );
563+
$this->assertTrue( $p->is_tag_closer() );
564+
565+
$this->assertTrue( $p->next_tag() );
566+
$this->assertSame( 'BODY', $p->get_tag() );
567+
$this->assertFalse( $p->is_tag_closer() );
568+
569+
$this->assertTrue( $p->next_tag() );
570+
$this->assertSame( 'BODY', $p->get_tag() );
571+
$this->assertTrue( $p->is_tag_closer() );
572+
573+
$this->assertTrue( $p->next_tag() );
574+
$this->assertSame( 'HTML', $p->get_tag() );
575+
$this->assertTrue( $p->is_tag_closer() );
576+
577+
$this->assertFalse( $p->next_tag() );
578+
}
579+
529580
/**
530581
* Test expects_closer().
531582
*

0 commit comments

Comments
 (0)