Skip to content

Commit

Permalink
fixup! Add html processor select test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
sirreal committed Dec 3, 2024
1 parent 2361dea commit e87e183
Showing 1 changed file with 25 additions and 12 deletions.
37 changes: 25 additions & 12 deletions tests/phpunit/tests/html-api/wpHtmlProcessor-select.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function test_select_miss() {
public function test_select( string $html, string $selector ) {
$processor = WP_HTML_Processor::create_full_parser( $html );
$this->assertTrue( $processor->select( $selector ) );
$this->assertTrue( $processor->get_attribute( 'target' ) );
$this->assertTrue( $processor->get_attribute( 'match' ) );
}

/**
Expand All @@ -38,18 +38,31 @@ public function test_select( string $html, string $selector ) {
*/
public static function data_selectors(): array {
return array(
'simple type' => array( '<div target>', 'div' ),
'any type' => array( '<html target>', '*' ),
'simple class' => array( '<div class="x" target>', '.x' ),
'simple id' => array( '<div id="x" target>', '#x' ),
'simple attribute' => array( '<div att target>', '[att]' ),
'attribute value' => array( '<div att="val" target>', '[att=val]' ),
'attribute quoted value' => array( '<div att="::" target>', '[att="::"]' ),
'complex any descendant' => array( '<section><div target>', 'section *' ),
'complex any child' => array( '<section><div target>', 'section > *' ),
'simple type' => array( '<div match>', 'div' ),
'any type' => array( '<html match>', '*' ),
'simple class' => array( '<div class="x" match>', '.x' ),
'simple id' => array( '<div id="x" match>', '#x' ),
'simple attribute' => array( '<div att match>', '[att]' ),
'attribute value' => array( '<div att="val" match>', '[att=val]' ),
'attribute quoted value' => array( '<div att="::" match>', '[att="::"]' ),
'complex any descendant' => array( '<section><div match>', 'section *' ),
'complex any child' => array( '<section><div match>', 'section > *' ),

'list' => array( '<div><p target>', 'a, p' ),
'compound' => array( '<div att><section att="foo bar" target>', 'section[att~="bar"]' ),
'list' => array( '<div><p match>', 'a, p' ),
'compound' => array( '<div att><section att="foo bar" match>', 'section[att~="bar"]' ),
);
}

/**
* @ticket TBD
*/
public function test_select_all() {
$processor = WP_HTML_Processor::create_full_parser( '<div match><p class="x" match><svg><rect match/></svg><i id="y" match></i>' );
$count = 0;
foreach ( $processor->select_all( 'div, .x, svg>rect, #y' ) as $_ ) {
++$count;
$this->assertTrue( $processor->get_attribute( 'match' ) );
}
$this->assertSame( 4, $count );
}
}

0 comments on commit e87e183

Please sign in to comment.