Skip to content

Commit 775d163

Browse files
committed
Add html processor select test suite
1 parent 989a382 commit 775d163

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
/**
3+
* Unit tests covering WP_HTML_Processor functionality.
4+
*
5+
* @package WordPress
6+
* @subpackage HTML-API
7+
*
8+
* @since TBD
9+
*
10+
* @group html-api
11+
*
12+
* @coversDefaultClass WP_HTML_Processor
13+
*/
14+
class Tests_HtmlApi_WpHtmlProcessor_Select extends WP_UnitTestCase {
15+
/**
16+
* @ticket TBD
17+
*/
18+
public function test_select_miss() {
19+
$processor = WP_HTML_Processor::create_full_parser( '<span>' );
20+
$this->assertFalse( $processor->select( 'div' ) );
21+
}
22+
23+
/**
24+
* @ticket TBD
25+
*
26+
* @dataProvider data_selectors
27+
*/
28+
public function test_select( string $html, string $selector ) {
29+
$processor = WP_HTML_Processor::create_full_parser( $html );
30+
$this->assertTrue( $processor->select( $selector ) );
31+
$this->assertTrue( $processor->get_attribute( 'target' ) );
32+
}
33+
34+
/**
35+
* Data provider.
36+
*
37+
* @return array
38+
*/
39+
public static function data_selectors(): array {
40+
return array(
41+
'simple type' => array( '<div target>', 'div' ),
42+
'any type' => array( '<html target>', '*' ),
43+
'simple class' => array( '<div class="x" target>', '.x' ),
44+
'simple id' => array( '<div id="x" target>', '#x' ),
45+
'simple attribute' => array( '<div att target>', '[att]' ),
46+
'attribute value' => array( '<div att="val" target>', '[att=val]' ),
47+
'attribute quoted value' => array( '<div att="::" target>', '[att="::"]' ),
48+
'complex any descendant' => array( '<section><div target>', 'section *' ),
49+
'complex any child' => array( '<section><div target>', 'section > *' ),
50+
51+
'list' => array( '<div><p target>', 'a, p' ),
52+
'compound' => array( '<div att><section att="foo bar" target>', 'section[att~="bar"]' ),
53+
);
54+
}
55+
}

0 commit comments

Comments
 (0)