Skip to content

Commit d1d4d55

Browse files
committed
HTML API: Simplify self-closing flag tests
1 parent 463c883 commit d1d4d55

2 files changed

Lines changed: 7 additions & 78 deletions

File tree

tests/phpunit/tests/html-api/wpHtmlProcessor.php

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -589,29 +589,20 @@ public function test_expects_closer_foreign_content_self_closing() {
589589
* @ticket 61576
590590
*/
591591
public function test_trailing_slash_in_unquoted_attribute_value_does_not_self_close_foreign_content() {
592-
$processor = WP_HTML_Processor::create_fragment( '<math><mi disabled=abc/>text</math>' );
592+
$processor = WP_HTML_Processor::create_fragment( '<math><mtext a=b/>This mtext tag is not self-closing, it has [a="b/"] attribute.' );
593593

594-
$this->assertTrue( $processor->next_tag( 'MI' ), 'Could not find MI tag: check test setup.' );
595-
$this->assertSame(
596-
'abc/',
597-
$processor->get_attribute( 'disabled' ),
598-
'Trailing slash in unquoted attribute value should belong to the attribute value.'
599-
);
594+
$this->assertTrue( $processor->next_tag( 'MTEXT' ), 'Could not find MTEXT tag: check test setup.' );
595+
$this->assertSame( 'b/', $processor->get_attribute( 'a' ), 'Trailing slash in unquoted attribute value should belong to the attribute value.' );
600596
$this->assertFalse(
601597
$processor->has_self_closing_flag(),
602598
'Trailing slash in unquoted attribute value should not be interpreted as a self-closing flag.'
603599
);
604-
$this->assertTrue(
605-
$processor->expects_closer(),
606-
'MI with a trailing slash in an unquoted attribute value should still expect a closer.'
607-
);
608600

609-
$this->assertTrue( $processor->next_token(), 'Could not find text following MI tag: check test setup.' );
610-
$this->assertSame( '#text', $processor->get_token_name(), 'Should have found the text node following the MI tag.' );
601+
$this->assertTrue( $processor->next_token(), 'Could not find text following MTEXT tag: check test setup.' );
611602
$this->assertSame(
612-
array( 'HTML', 'BODY', 'MATH', 'MI', '#text' ),
603+
array( 'HTML', 'BODY', 'MATH', 'MTEXT', '#text' ),
613604
$processor->get_breadcrumbs(),
614-
'Text following the MI tag should remain inside the MI element.'
605+
'Text following the MTEXT tag should remain inside the MTEXT element.'
615606
);
616607
}
617608

tests/phpunit/tests/html-api/wpHtmlTagProcessor.php

Lines changed: 1 addition & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -116,69 +116,7 @@ public static function data_has_self_closing_flag() {
116116
'Self-closing flag after quoted attribute' => array( '<div id="test"/>', true ),
117117
'Self-closing flag after boolean attribute' => array( '<div enabled/>', true ),
118118
'Boolean attribute that looks like a self-closer' => array( '<div / >', false ),
119-
);
120-
}
121-
122-
/**
123-
* Ensures internally consumed special-element closers do not affect the opener's
124-
* self-closing flag.
125-
*
126-
* @ticket 61576
127-
*
128-
* @covers WP_HTML_Tag_Processor::has_self_closing_flag
129-
*
130-
* @dataProvider data_special_atomic_self_closing_flags
131-
*
132-
* @param string $html Input HTML whose first tag might contain the self-closing flag `/`.
133-
* @param bool $flag_is_set Whether the input HTML's first tag contains the self-closing flag.
134-
*/
135-
public function test_special_atomic_elements_report_opening_tag_self_closing_flag( string $html, bool $flag_is_set ) {
136-
$processor = new WP_HTML_Tag_Processor( $html );
137-
138-
$this->assertTrue( $processor->next_token(), 'Expected to find complete special atomic tag.' );
139-
140-
if ( $flag_is_set ) {
141-
$this->assertTrue( $processor->has_self_closing_flag(), 'Did not find the self-closing flag on the opening tag.' );
142-
} else {
143-
$this->assertFalse( $processor->has_self_closing_flag(), 'Reported the internally consumed closing tag self-closing flag on the opening tag.' );
144-
}
145-
}
146-
147-
/**
148-
* Data provider.
149-
*
150-
* @return array[]
151-
*/
152-
public static function data_special_atomic_self_closing_flags() {
153-
return array(
154-
'SCRIPT closer self-closing flag' => array( '<script>x</script/>', false ),
155-
'STYLE closer self-closing flag' => array( '<style>x</style/>', false ),
156-
'TITLE closer self-closing flag' => array( '<title>x</title/>', false ),
157-
'TITLE opener self-closing flag' => array( '<title/>x</title>', true ),
158-
);
159-
}
160-
161-
/**
162-
* Ensures a trailing slash in an unquoted attribute value is part of the value.
163-
*
164-
* @ticket 61576
165-
*
166-
* @covers WP_HTML_Tag_Processor::get_attribute
167-
* @covers WP_HTML_Tag_Processor::has_self_closing_flag
168-
*/
169-
public function test_trailing_slash_in_unquoted_attribute_value_is_not_self_closing_flag() {
170-
$processor = new WP_HTML_Tag_Processor( '<mi disabled=abc/>text' );
171-
$this->assertTrue( $processor->next_tag(), 'Could not find MI tag: check test setup.' );
172-
173-
$this->assertSame(
174-
'abc/',
175-
$processor->get_attribute( 'disabled' ),
176-
'Trailing slash in unquoted attribute value should belong to the attribute value.'
177-
);
178-
179-
$this->assertFalse(
180-
$processor->has_self_closing_flag(),
181-
'Trailing slash in unquoted attribute value should not be interpreted as a self-closing flag.'
119+
'Self-closing flag on internally consumed special element closer' => array( '<title>x</title/>', false ),
182120
);
183121
}
184122

0 commit comments

Comments
 (0)