|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace SimpleSAML\XMLSecurity\Test\XML\xenc; |
|
6
|
|
|
|
|
7
|
|
|
use PHPUnit\Framework\TestCase; |
|
8
|
|
|
use SimpleSAML\XML\DOMDocumentFactory; |
|
9
|
|
|
use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; |
|
10
|
|
|
use SimpleSAML\XMLSecurity\Constants as C; |
|
11
|
|
|
use SimpleSAML\XMLSecurity\XML\ds\Transform; |
|
12
|
|
|
use SimpleSAML\XMLSecurity\XML\ds\XPath; |
|
13
|
|
|
use SimpleSAML\XMLSecurity\XML\xenc\Transforms; |
|
14
|
|
|
|
|
15
|
|
|
use function dirname; |
|
16
|
|
|
use function strval; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Class \SimpleSAML\XMLSecurity\Test\XML\xenc\TransformsTest |
|
20
|
|
|
* |
|
21
|
|
|
* @covers \SimpleSAML\XMLSecurity\XML\xenc\Transforms |
|
22
|
|
|
* @covers \SimpleSAML\XMLSecurity\XML\xenc\AbstractXencElement |
|
23
|
|
|
* |
|
24
|
|
|
* @package simplesamlphp/xml-security |
|
25
|
|
|
*/ |
|
26
|
|
|
final class TransformsTest extends TestCase |
|
27
|
|
|
{ |
|
28
|
|
|
use SerializableElementTestTrait; |
|
|
|
|
|
|
29
|
|
|
|
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
*/ |
|
33
|
|
|
public static function setUpBeforeClass(): void |
|
34
|
|
|
{ |
|
35
|
|
|
self::$testedClass = Transforms::class; |
|
36
|
|
|
|
|
37
|
|
|
self::$xmlRepresentation = DOMDocumentFactory::fromFile( |
|
38
|
|
|
dirname(__FILE__, 3) . '/resources/xml/xenc_Transforms.xml', |
|
39
|
|
|
); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
*/ |
|
45
|
|
|
public function testMarshalling(): void |
|
46
|
|
|
{ |
|
47
|
|
|
$transforms = new Transforms( |
|
48
|
|
|
[ |
|
49
|
|
|
new Transform( |
|
50
|
|
|
C::XPATH_URI, |
|
51
|
|
|
new XPath( |
|
52
|
|
|
'count(//. | //@* | //namespace::*)', |
|
53
|
|
|
), |
|
54
|
|
|
), |
|
55
|
|
|
], |
|
56
|
|
|
); |
|
57
|
|
|
|
|
58
|
|
|
$this->assertEquals( |
|
59
|
|
|
self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), |
|
60
|
|
|
strval($transforms), |
|
61
|
|
|
); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
*/ |
|
67
|
|
|
public function testUnmarshalling(): void |
|
68
|
|
|
{ |
|
69
|
|
|
$transforms = Transforms::fromXML(self::$xmlRepresentation->documentElement); |
|
70
|
|
|
|
|
71
|
|
|
$this->assertEquals( |
|
72
|
|
|
self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), |
|
73
|
|
|
strval($transforms), |
|
74
|
|
|
); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Adding an empty Transforms element should yield an empty element. |
|
80
|
|
|
*/ |
|
81
|
|
|
public function testMarshallingEmptyElement(): void |
|
82
|
|
|
{ |
|
83
|
|
|
$xenc_ns = Transforms::NS; |
|
84
|
|
|
$transforms = new Transforms([]); |
|
85
|
|
|
$this->assertEquals( |
|
86
|
|
|
"<xenc:Transforms xmlns:xenc=\"$xenc_ns\"/>", |
|
87
|
|
|
strval($transforms), |
|
88
|
|
|
); |
|
89
|
|
|
$this->assertTrue($transforms->isEmptyElement()); |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|