diff --git a/CHANGELOG.md b/CHANGELOG.md index 83e57bbf..fe3133c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,7 +34,7 @@ Please also have a look at our - Use more native type declarations and strict mode (#641, #772, #774, #778, #804, #841, #873, #875, #891, #922, #923, #933, #958, #964, #967, #1000, #1044, #1134, #1136, #1137, #1139, #1140, #1141, #1145, - #1162, #1163, #1166, #1172) + #1162, #1163, #1166, #1172, #1174) - Add visibility to all class/interface constants (#469) ### Deprecated diff --git a/src/Property/Selector.php b/src/Property/Selector.php index f1bbbcef..f8008e44 100644 --- a/src/Property/Selector.php +++ b/src/Property/Selector.php @@ -37,13 +37,14 @@ class Selector implements Renderable private $selector; /** - * @return bool - * * @internal since V8.8.0 */ - public static function isValid(string $selector) + public static function isValid(string $selector): bool { - return \preg_match(static::SELECTOR_VALIDATION_RX, $selector); + // Note: We need to use `static::` here as the constant is overridden in the `KeyframeSelector` class. + $numberOfMatches = \preg_match(static::SELECTOR_VALIDATION_RX, $selector); + + return $numberOfMatches === 1; } public function __construct(string $selector) diff --git a/tests/Unit/Property/SelectorTest.php b/tests/Unit/Property/SelectorTest.php index de888fd5..c2d59b60 100644 --- a/tests/Unit/Property/SelectorTest.php +++ b/tests/Unit/Property/SelectorTest.php @@ -98,4 +98,44 @@ public function getSpecificityReturnsSpecificityOfSelectorLastProvidedViaSetSele self::assertSame($expectedSpecificity, $subject->getSpecificity()); } + + /** + * @test + * + * @dataProvider provideSelectorsAndSpecificities + */ + public function isValidForValidSelectorReturnsTrue(string $selector): void + { + self::assertTrue(Selector::isValid($selector)); + } + + /** + * @return array + */ + public static function provideInvalidSelectors(): array + { + return [ + // This is currently broken. + // 'empty string' => [''], + 'percent sign' => ['%'], + // This is currently broken. + // 'hash only' => ['#'], + // This is currently broken. + // 'dot only' => ['.'], + 'slash' => ['/'], + 'less-than sign' => ['<'], + // This is currently broken. + // 'whitespace only' => [" \t\n\r"], + ]; + } + + /** + * @test + * + * @dataProvider provideInvalidSelectors + */ + public function isValidForInvalidSelectorReturnsFalse(string $selector): void + { + self::assertFalse(Selector::isValid($selector)); + } }