|null */
+ /** @var (WP_CSS_ID_Selector|WP_CSS_Class_Selector|WP_CSS_Attribute_Selector)[]|null */
public $subclass_selectors;
/**
diff --git a/tests/phpunit/tests/html-api/wpCssComplexSelectorList.php b/tests/phpunit/tests/html-api/wpCssComplexSelectorList.php
index 0b17e57847662..795e230033cdb 100644
--- a/tests/phpunit/tests/html-api/wpCssComplexSelectorList.php
+++ b/tests/phpunit/tests/html-api/wpCssComplexSelectorList.php
@@ -20,7 +20,7 @@ public function __construct() {
parent::__construct( array() );
}
- public static function test_parse_complex_selector( string $input, int &$offset ) {
+ public static function test_parse_complex_selector( string $input, int &$offset ): ?WP_CSS_Complex_Selector {
return self::parse_complex_selector( $input, $offset );
}
};
@@ -30,21 +30,24 @@ public static function test_parse_complex_selector( string $input, int &$offset
* @ticket 62653
*/
public function test_parse_complex_selector() {
- $input = 'el1 > .child#bar[baz=quux] , rest';
+ $input = 'el1 el2 > .child#bar[baz=quux] , rest';
$offset = 0;
- $sel = $this->test_class::test_parse_complex_selector( $input, $offset );
- $this->assertSame( 3, count( $sel->selectors ) );
+ /** @var WP_CSS_Complex_Selector|null */
+ $sel = $this->test_class::test_parse_complex_selector( $input, $offset );
- $this->assertSame( 'el1', $sel->selectors[2]->type_selector->ident );
- $this->assertNull( $sel->selectors[2]->subclass_selectors );
+ $this->assertSame( 2, count( $sel->relative_selectors ) );
- $this->assertSame( WP_CSS_Complex_Selector::COMBINATOR_CHILD, $sel->selectors[1] );
+ // Relative selectors should be reverse ordered.
+ $this->assertSame( 'el2', $sel->relative_selectors[0][0]->ident );
+ $this->assertSame( WP_CSS_Complex_Selector::COMBINATOR_CHILD, $sel->relative_selectors[0][1] );
- $this->assertSame( 3, count( $sel->selectors[0]->subclass_selectors ) );
- $this->assertNull( $sel->selectors[0]->type_selector );
- $this->assertSame( 3, count( $sel->selectors[0]->subclass_selectors ) );
- $this->assertSame( 'child', $sel->selectors[0]->subclass_selectors[0]->ident );
+ $this->assertSame( 'el1', $sel->relative_selectors[1][0]->ident );
+ $this->assertSame( WP_CSS_Complex_Selector::COMBINATOR_DESCENDANT, $sel->relative_selectors[1][1] );
+
+ $this->assertSame( 3, count( $sel->self_selector->subclass_selectors ) );
+ $this->assertNull( $sel->self_selector->type_selector );
+ $this->assertSame( 'child', $sel->self_selector->subclass_selectors[0]->ident );
$this->assertSame( ', rest', substr( $input, $offset ) );
}
diff --git a/tests/phpunit/tests/html-api/wpHtmlProcessor-select.php b/tests/phpunit/tests/html-api/wpHtmlProcessor-select.php
index d94190ff91077..21828faf42e80 100644
--- a/tests/phpunit/tests/html-api/wpHtmlProcessor-select.php
+++ b/tests/phpunit/tests/html-api/wpHtmlProcessor-select.php
@@ -47,14 +47,15 @@ public function test_select_all( string $html, string $selector, int $match_coun
*/
public static function data_selectors(): array {
return array(
- 'any' => array( '', '*', 5 ),
- 'quirks mode ID' => array( '
In quirks mode, ID matching is case-insensitive.', '#id', 2 ),
- 'quirks mode class' => array( '
In quirks mode, class matching is case-insensitive.', '.c', 2 ),
- 'no-quirks mode ID' => array( '
In no-quirks mode, ID matching is case-sensitive.', '#id', 1 ),
- 'no-quirks mode class' => array( '
In no-quirks mode, class matching is case-sensitive.', '.c', 1 ),
- 'any descendant' => array( '', 'section *', 4 ),
- 'any child 1' => array( '', 'section > *', 2 ),
- 'any child 2' => array( '
', 'div > *', 1 ),
+ 'any' => array( '
', '*', 5 ),
+ 'quirks mode ID' => array( '
In quirks mode, ID matching is case-insensitive.', '#id', 2 ),
+ 'quirks mode class' => array( '
In quirks mode, class matching is case-insensitive.', '.c', 2 ),
+ 'no-quirks mode ID' => array( '
In no-quirks mode, ID matching is case-sensitive.', '#id', 1 ),
+ 'no-quirks mode class' => array( '
In no-quirks mode, class matching is case-sensitive.', '.c', 1 ),
+ 'any descendant' => array( '', 'section *', 4 ),
+ 'any child matches all children' => array( '', 'section > *', 2 ),
+
+ 'multiple complex selectors' => array( '', 'section > div p > i', 1 ),
);
}