Skip to content

Commit 673e47b

Browse files
committed
Merge branch 'release-3.x' into feature/dom-migration-php84
2 parents 0a4fe44 + 413f345 commit 673e47b

2 files changed

Lines changed: 78 additions & 0 deletions

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SimpleSAML\XMLSchema\Type\Helper;
6+
7+
use DOMNodeList;
8+
use DOMXPath;
9+
use SimpleSAML\Assert\Assert;
10+
use SimpleSAML\XML\DOMDocumentFactory;
11+
use SimpleSAML\XMLSchema\Type\StringValue;
12+
13+
/**
14+
* @package simplesaml/xml-common
15+
*/
16+
class XPathValue extends StringValue
17+
{
18+
/**
19+
* Validate the content of the element.
20+
*
21+
* @throws \SimpleSAML\Assert\AssertionFailedException on failure
22+
*/
23+
protected function validateValue(string $content): void
24+
{
25+
$dom = new DOMXPath(DOMDocumentFactory::create());
26+
27+
$result = $dom->evaluate($content);
28+
Assert::isInstanceOf($result, DOMNodeList::class);
29+
}
30+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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

Comments
 (0)