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