Passed
Branch master (c86cc6)
by Tim
03:54
created

XPathTest::testUnmarshalling()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 0
dl 0
loc 13
rs 9.9666
c 0
b 0
f 0
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;
0 ignored issues
show
Bug introduced by
The trait SimpleSAML\XML\TestUtils...lizableElementTestTrait requires the property $documentElement which is not provided by SimpleSAML\XMLSecurity\Test\XML\ds\XPathTest.
Loading history...
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
61
    /**
62
     */
63
    public function testUnmarshalling(): void
64
    {
65
        $xpath = XPath::fromXML(self::$xmlRepresentation->documentElement);
66
        $this->assertEquals('self::xenc:CipherValue[@Id="example1"]', $xpath->getExpression());
67
        $namespaces = $xpath->getNamespaces();
68
        $this->assertCount(2, $namespaces);
69
        $this->assertEquals('xenc', array_keys($namespaces)[0]);
70
        $this->assertEquals('ds', array_keys($namespaces)[1]);
71
72
73
        $this->assertEquals(
74
            self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement),
75
            strval($xpath),
76
        );
77
    }
78
}
79