Skip to content

Commit 9da3384

Browse files
committed
Add XPath tests and missing file
1 parent 567c67c commit 9da3384

3 files changed

Lines changed: 81 additions & 0 deletions

File tree

tests/XML/ds/XPathTest.php

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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\Test\XML\SerializableXMLTestTrait;
9+
use SimpleSAML\XML\DOMDocumentFactory;
10+
use SimpleSAML\XMLSecurity\XML\ds\XPath;
11+
12+
/**
13+
* Class \SimpleSAML\XMLSecurity\Test\XML\ds\XPathTest
14+
*
15+
* @covers \SimpleSAML\XMLSecurity\XML\ds\XPath
16+
*
17+
* @package simplesamlphp/xml-security
18+
*/
19+
class XPathTest extends TestCase
20+
{
21+
use SerializableXMLTestTrait;
22+
23+
24+
/**
25+
*/
26+
public function setUp(): void
27+
{
28+
$this->testedClass = XPath::class;
29+
30+
$this->xmlRepresentation = DOMDocumentFactory::fromFile(
31+
dirname(dirname(dirname(__FILE__))) . '/resources/xml/ds_XPath.xml'
32+
);
33+
}
34+
35+
36+
public function testMarshalling(): void
37+
{
38+
$xpath = new XPath(
39+
'self::xenc:CipherValue[@Id="example1"]',
40+
[
41+
'xenc' => 'http://www.w3.org/2001/04/xmlenc#'
42+
]
43+
);
44+
45+
$this->assertEquals('self::xenc:CipherValue[@Id="example1"]', $xpath->getExpression());
46+
$namespaces = $xpath->getNamespaces();
47+
$this->assertCount(1, $namespaces);
48+
$this->assertArrayHasKey('xenc', $namespaces);
49+
$this->assertEquals('http://www.w3.org/2001/04/xmlenc#', $namespaces['xenc']);
50+
51+
$this->assertEquals(
52+
$this->xmlRepresentation->saveXML($this->xmlRepresentation->documentElement),
53+
strval($xpath)
54+
);
55+
}
56+
57+
58+
/**
59+
*/
60+
public function testUnmarshalling(): void
61+
{
62+
$xpath = XPath::fromXML($this->xmlRepresentation->documentElement);
63+
$this->assertEquals('self::xenc:CipherValue[@Id="example1"]', $xpath->getExpression());
64+
$namespaces = $xpath->getNamespaces();
65+
$this->assertCount(2, $namespaces);
66+
$this->assertEquals('xenc', array_keys($namespaces)[0]);
67+
$this->assertEquals('ds', array_keys($namespaces)[1]);
68+
69+
70+
$this->assertEquals(
71+
$this->xmlRepresentation->saveXML($this->xmlRepresentation->documentElement),
72+
strval($xpath)
73+
);
74+
}
75+
76+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<ds:Transform xmlns:ds="http://www.w3.org/2000/09/xmldsig#" Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#">
2+
<ec:InclusiveNamespaces PrefixList="dsig soap #default"
3+
xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#"/>
4+
</ds:Transform>

tests/resources/xml/ds_XPath.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<ds:XPath xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:xenc="http://www.w3.org/2001/04/xmlenc#">self::xenc:CipherValue[@Id="example1"]</ds:XPath>

0 commit comments

Comments
 (0)