|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace SimpleSAML\Test\XMLSchema\Type\Builtin; |
| 6 | + |
| 7 | +use PHPUnit\Framework\Attributes\CoversClass; |
| 8 | +use PHPUnit\Framework\Attributes\DataProvider; |
| 9 | +use PHPUnit\Framework\TestCase; |
| 10 | +use SimpleSAML\Assert\AssertionFailedException; |
| 11 | +use SimpleSAML\XMLSchema\Type\Helper\XPathValue; |
| 12 | + |
| 13 | +/** |
| 14 | + * Class \SimpleSAML\Test\XMLSchema\Type\Helper\XPathValueTest |
| 15 | + * |
| 16 | + * @package simplesamlphp/xml-common |
| 17 | + */ |
| 18 | +#[CoversClass(XPathValue::class)] |
| 19 | +final class XPathValueTest extends TestCase |
| 20 | +{ |
| 21 | + /** |
| 22 | + * @param bool $shouldPass |
| 23 | + * @param string $xpath |
| 24 | + */ |
| 25 | + #[DataProvider('provideXPath')] |
| 26 | + public function testString(bool $shouldPass, string $xpath): void |
| 27 | + { |
| 28 | + try { |
| 29 | + $value = XPathValue::fromString($xpath); |
| 30 | + $this->assertTrue($shouldPass); |
| 31 | + } catch (AssertionFailedException $e) { |
| 32 | + $this->assertFalse($shouldPass); |
| 33 | + } |
| 34 | + } |
| 35 | + |
| 36 | + |
| 37 | + /** |
| 38 | + * @return array<string, array{0: string, 1: string}> |
| 39 | + */ |
| 40 | + public static function provideXPath(): array |
| 41 | + { |
| 42 | + return [ |
| 43 | + 'xpath' => [true, '//h1/following-sibling::ul'], |
| 44 | + 'empty string' => [false, ''], |
| 45 | + 'nonsense' => [false, 'I know nothing'], |
| 46 | + ]; |
| 47 | + } |
| 48 | +} |
0 commit comments