Skip to content

Commit 4592567

Browse files
committed
Add tests
1 parent 3116115 commit 4592567

2 files changed

Lines changed: 327 additions & 20 deletions

File tree

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

Lines changed: 0 additions & 20 deletions
This file was deleted.
Lines changed: 327 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,327 @@
1+
<?php
2+
/**
3+
* Unit tests covering WP_HTML_Processor compliance with HTML5 semantic parsing rules
4+
* for the LI list item element.
5+
*
6+
* @package WordPress
7+
* @subpackage HTML-API
8+
*
9+
* @since 6.5.0
10+
*
11+
* @group html-api
12+
*
13+
* @coversDefaultClass WP_HTML_Processor
14+
*/
15+
class Tests_HtmlApi_WpHtmlProcessorSemanticRulesListElements extends WP_UnitTestCase {
16+
/*******************************************************************
17+
* RULES FOR "IN BODY" MODE
18+
*******************************************************************/
19+
20+
public function test_in_body_li_closes_open_li() {
21+
$processor = WP_HTML_Processor::create_fragment( '<li><li><li target>' );
22+
23+
while (
24+
null === $processor->get_attribute( 'target' ) &&
25+
$processor->next_tag()
26+
) {
27+
continue;
28+
}
29+
30+
$this->assertTrue(
31+
$processor->get_attribute( 'target' ),
32+
'Failed to find target node.'
33+
);
34+
35+
$this->assertSame(
36+
array( 'HTML', 'BODY', 'LI' ),
37+
$processor->get_breadcrumbs(),
38+
"LI should have closed open LI, but didn't."
39+
);
40+
}
41+
42+
public function test_in_body_li_generates_implied_end_tags_inside_open_li() {
43+
$processor = WP_HTML_Processor::create_fragment( '<li><li><div><li target>' );
44+
45+
while (
46+
null === $processor->get_attribute( 'target' ) &&
47+
$processor->next_tag()
48+
) {
49+
continue;
50+
}
51+
52+
$this->assertTrue(
53+
$processor->get_attribute( 'target' ),
54+
'Failed to find target node.'
55+
);
56+
57+
$this->assertSame(
58+
array( 'HTML', 'BODY', 'LI' ),
59+
$processor->get_breadcrumbs(),
60+
"LI should have closed open LI, but didn't."
61+
);
62+
}
63+
64+
public function test_in_body_li_generates_implied_end_tags_inside_open_li_but_stopping_at_special_tags() {
65+
$processor = WP_HTML_Processor::create_fragment( '<li><li><blockquote><li target>' );
66+
67+
while (
68+
null === $processor->get_attribute( 'target' ) &&
69+
$processor->next_tag()
70+
) {
71+
continue;
72+
}
73+
74+
$this->assertTrue(
75+
$processor->get_attribute( 'target' ),
76+
'Failed to find target node.'
77+
);
78+
79+
$this->assertSame(
80+
array( 'HTML', 'BODY', 'LI', 'BLOCKQUOTE', 'LI' ),
81+
$processor->get_breadcrumbs(),
82+
'LI should have left the BLOCKQOUTE open, but closed it.'
83+
);
84+
}
85+
86+
public function test_in_body_li_in_li_closes_p_in_button_scope() {
87+
$processor = WP_HTML_Processor::create_fragment( '<li><li><p><button><p><li target>' );
88+
89+
while (
90+
null === $processor->get_attribute( 'target' ) &&
91+
$processor->next_tag()
92+
) {
93+
continue;
94+
}
95+
96+
$this->assertTrue(
97+
$processor->get_attribute( 'target' ),
98+
'Failed to find target node.'
99+
);
100+
101+
$this->assertSame(
102+
array( 'HTML', 'BODY', 'LI', 'P', 'BUTTON', 'LI' ),
103+
$processor->get_breadcrumbs(),
104+
'LI should have left the outer P open, but closed it.'
105+
);
106+
}
107+
108+
public function test_in_body_dd_closes_open_dd() {
109+
$processor = WP_HTML_Processor::create_fragment( '<dd><dd><dd target>' );
110+
111+
while (
112+
null === $processor->get_attribute( 'target' ) &&
113+
$processor->next_tag()
114+
) {
115+
continue;
116+
}
117+
118+
$this->assertTrue(
119+
$processor->get_attribute( 'target' ),
120+
'Failed to find target node.'
121+
);
122+
123+
$this->assertSame(
124+
array( 'HTML', 'BODY', 'DD' ),
125+
$processor->get_breadcrumbs(),
126+
"DD should have closed open DD, but didn't."
127+
);
128+
}
129+
130+
public function test_in_body_dd_closes_open_dt() {
131+
$processor = WP_HTML_Processor::create_fragment( '<dt><dt><dd target>' );
132+
133+
while (
134+
null === $processor->get_attribute( 'target' ) &&
135+
$processor->next_tag()
136+
) {
137+
continue;
138+
}
139+
140+
$this->assertTrue(
141+
$processor->get_attribute( 'target' ),
142+
'Failed to find target node.'
143+
);
144+
145+
$this->assertSame(
146+
array( 'HTML', 'BODY', 'DD' ),
147+
$processor->get_breadcrumbs(),
148+
"DD should have closed open DD, but didn't."
149+
);
150+
}
151+
152+
public function test_in_body_dd_generates_impdded_end_tags_inside_open_dd() {
153+
$processor = WP_HTML_Processor::create_fragment( '<dd><dd><div><dd target>' );
154+
155+
while (
156+
null === $processor->get_attribute( 'target' ) &&
157+
$processor->next_tag()
158+
) {
159+
continue;
160+
}
161+
162+
$this->assertTrue(
163+
$processor->get_attribute( 'target' ),
164+
'Failed to find target node.'
165+
);
166+
167+
$this->assertSame(
168+
array( 'HTML', 'BODY', 'DD' ),
169+
$processor->get_breadcrumbs(),
170+
"DD should have closed open DD, but didn't."
171+
);
172+
}
173+
174+
public function test_in_body_dd_generates_impdded_end_tags_inside_open_dd_but_stopping_at_special_tags() {
175+
$processor = WP_HTML_Processor::create_fragment( '<dd><dd><blockquote><dd target>' );
176+
177+
while (
178+
null === $processor->get_attribute( 'target' ) &&
179+
$processor->next_tag()
180+
) {
181+
continue;
182+
}
183+
184+
$this->assertTrue(
185+
$processor->get_attribute( 'target' ),
186+
'Failed to find target node.'
187+
);
188+
189+
$this->assertSame(
190+
array( 'HTML', 'BODY', 'DD', 'BLOCKQUOTE', 'DD' ),
191+
$processor->get_breadcrumbs(),
192+
'DD should have left the BLOCKQOUTE open, but closed it.'
193+
);
194+
}
195+
196+
public function test_in_body_dd_in_dd_closes_p_in_button_scope() {
197+
$processor = WP_HTML_Processor::create_fragment( '<dd><dd><p><button><p><dd target>' );
198+
199+
while (
200+
null === $processor->get_attribute( 'target' ) &&
201+
$processor->next_tag()
202+
) {
203+
continue;
204+
}
205+
206+
$this->assertTrue(
207+
$processor->get_attribute( 'target' ),
208+
'Failed to find target node.'
209+
);
210+
211+
$this->assertSame(
212+
array( 'HTML', 'BODY', 'DD', 'P', 'BUTTON', 'DD' ),
213+
$processor->get_breadcrumbs(),
214+
'DD should have left the outer P open, but closed it.'
215+
);
216+
}
217+
218+
public function test_in_body_dt_closes_open_dt() {
219+
$processor = WP_HTML_Processor::create_fragment( '<dt><dt><dt target>' );
220+
221+
while (
222+
null === $processor->get_attribute( 'target' ) &&
223+
$processor->next_tag()
224+
) {
225+
continue;
226+
}
227+
228+
$this->assertTrue(
229+
$processor->get_attribute( 'target' ),
230+
'Failed to find target node.'
231+
);
232+
233+
$this->assertSame(
234+
array( 'HTML', 'BODY', 'DT' ),
235+
$processor->get_breadcrumbs(),
236+
"DT should have closed open DT, but didn't."
237+
);
238+
}
239+
240+
public function test_in_body_dt_closes_open_dd() {
241+
$processor = WP_HTML_Processor::create_fragment( '<dd><dd><dt target>' );
242+
243+
while (
244+
null === $processor->get_attribute( 'target' ) &&
245+
$processor->next_tag()
246+
) {
247+
continue;
248+
}
249+
250+
$this->assertTrue(
251+
$processor->get_attribute( 'target' ),
252+
'Failed to find target node.'
253+
);
254+
255+
$this->assertSame(
256+
array( 'HTML', 'BODY', 'DT' ),
257+
$processor->get_breadcrumbs(),
258+
"DT should have closed open DT, but didn't."
259+
);
260+
}
261+
262+
public function test_in_body_dt_generates_impdted_end_tags_inside_open_dt() {
263+
$processor = WP_HTML_Processor::create_fragment( '<dt><dt><div><dt target>' );
264+
265+
while (
266+
null === $processor->get_attribute( 'target' ) &&
267+
$processor->next_tag()
268+
) {
269+
continue;
270+
}
271+
272+
$this->assertTrue(
273+
$processor->get_attribute( 'target' ),
274+
'Failed to find target node.'
275+
);
276+
277+
$this->assertSame(
278+
array( 'HTML', 'BODY', 'DT' ),
279+
$processor->get_breadcrumbs(),
280+
"DT should have closed open DT, but didn't."
281+
);
282+
}
283+
284+
public function test_in_body_dt_generates_impdted_end_tags_inside_open_dt_but_stopping_at_special_tags() {
285+
$processor = WP_HTML_Processor::create_fragment( '<dt><dt><blockquote><dt target>' );
286+
287+
while (
288+
null === $processor->get_attribute( 'target' ) &&
289+
$processor->next_tag()
290+
) {
291+
continue;
292+
}
293+
294+
$this->assertTrue(
295+
$processor->get_attribute( 'target' ),
296+
'Failed to find target node.'
297+
);
298+
299+
$this->assertSame(
300+
array( 'HTML', 'BODY', 'DT', 'BLOCKQUOTE', 'DT' ),
301+
$processor->get_breadcrumbs(),
302+
'DT should have left the BLOCKQOUTE open, but closed it.'
303+
);
304+
}
305+
306+
public function test_in_body_dt_in_dt_closes_p_in_button_scope() {
307+
$processor = WP_HTML_Processor::create_fragment( '<dt><dt><p><button><p><dt target>' );
308+
309+
while (
310+
null === $processor->get_attribute( 'target' ) &&
311+
$processor->next_tag()
312+
) {
313+
continue;
314+
}
315+
316+
$this->assertTrue(
317+
$processor->get_attribute( 'target' ),
318+
'Failed to find target node.'
319+
);
320+
321+
$this->assertSame(
322+
array( 'HTML', 'BODY', 'DT', 'P', 'BUTTON', 'DT' ),
323+
$processor->get_breadcrumbs(),
324+
'DT should have left the outer P open, but closed it.'
325+
);
326+
}
327+
}

0 commit comments

Comments
 (0)