1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SimpleSAML\XMLSecurity\Test\XML\ds; |
6
|
|
|
|
7
|
|
|
use PHPUnit\Framework\TestCase; |
8
|
|
|
use SimpleSAML\XML\DOMDocumentFactory; |
9
|
|
|
use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; |
10
|
|
|
use SimpleSAML\XMLSecurity\XML\ds\XPath; |
11
|
|
|
|
12
|
|
|
use function dirname; |
13
|
|
|
use function strval; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Class \SimpleSAML\XMLSecurity\Test\XML\ds\XPathTest |
17
|
|
|
* |
18
|
|
|
* @covers \SimpleSAML\XMLSecurity\XML\ds\XPath |
19
|
|
|
* |
20
|
|
|
* @package simplesamlphp/xml-security |
21
|
|
|
*/ |
22
|
|
|
class XPathTest extends TestCase |
23
|
|
|
{ |
24
|
|
|
use SerializableElementTestTrait; |
|
|
|
|
25
|
|
|
|
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
*/ |
29
|
|
|
public static function setUpBeforeClass(): void |
30
|
|
|
{ |
31
|
|
|
self::$testedClass = XPath::class; |
32
|
|
|
|
33
|
|
|
self::$xmlRepresentation = DOMDocumentFactory::fromFile( |
34
|
|
|
dirname(__FILE__, 3) . '/resources/xml/ds_XPath.xml', |
35
|
|
|
); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
|
39
|
|
|
public function testMarshalling(): void |
40
|
|
|
{ |
41
|
|
|
$xpath = new XPath( |
42
|
|
|
'self::xenc:CipherValue[@Id="example1"]', |
43
|
|
|
[ |
44
|
|
|
'xenc' => 'http://www.w3.org/2001/04/xmlenc#', |
45
|
|
|
], |
46
|
|
|
); |
47
|
|
|
|
48
|
|
|
$this->assertEquals('self::xenc:CipherValue[@Id="example1"]', $xpath->getExpression()); |
49
|
|
|
$namespaces = $xpath->getNamespaces(); |
50
|
|
|
$this->assertCount(1, $namespaces); |
51
|
|
|
$this->assertArrayHasKey('xenc', $namespaces); |
|
|
|
|
52
|
|
|
$this->assertEquals('http://www.w3.org/2001/04/xmlenc#', $namespaces['xenc']); |
53
|
|
|
|
54
|
|
|
$this->assertEquals( |
55
|
|
|
self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), |
56
|
|
|
strval($xpath), |
57
|
|
|
); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|