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\Transforms; |
13
|
|
|
use SimpleSAML\XMLSecurity\XML\ds\XPath; |
14
|
|
|
use SimpleSAML\XMLSecurity\XML\xenc\DataReference; |
15
|
|
|
|
16
|
|
|
use function dirname; |
17
|
|
|
use function strval; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Class \SimpleSAML\XMLSecurity\Test\XML\xenc\DataReferenceTest |
21
|
|
|
* |
22
|
|
|
* @covers \SimpleSAML\XMLSecurity\XML\xenc\AbstractXencElement |
23
|
|
|
* @covers \SimpleSAML\XMLSecurity\XML\xenc\AbstractReference |
24
|
|
|
* @covers \SimpleSAML\XMLSecurity\XML\xenc\DataReference |
25
|
|
|
* |
26
|
|
|
* @package simplesamlphp/xml-security |
27
|
|
|
*/ |
28
|
|
|
final class DataReferenceTest extends TestCase |
29
|
|
|
{ |
30
|
|
|
use SerializableElementTestTrait; |
|
|
|
|
31
|
|
|
|
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
*/ |
35
|
|
|
public static function setUpBeforeClass(): void |
36
|
|
|
{ |
37
|
|
|
self::$testedClass = DataReference::class; |
38
|
|
|
|
39
|
|
|
self::$xmlRepresentation = DOMDocumentFactory::fromFile( |
40
|
|
|
dirname(__FILE__, 3) . '/resources/xml/xenc_DataReference.xml', |
41
|
|
|
); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
// marshalling |
45
|
|
|
|
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
*/ |
49
|
|
|
public function testMarshalling(): void |
50
|
|
|
{ |
51
|
|
|
$dataReference = new DataReference( |
52
|
|
|
'#Encrypted_DATA_ID', |
53
|
|
|
[ |
54
|
|
|
new Transforms( |
55
|
|
|
[ |
56
|
|
|
new Transform( |
57
|
|
|
C::XPATH_URI, |
58
|
|
|
new XPath('self::xenc:EncryptedData[@Id="example1"]'), |
59
|
|
|
), |
60
|
|
|
], |
61
|
|
|
), |
62
|
|
|
], |
63
|
|
|
); |
64
|
|
|
|
65
|
|
|
$this->assertEquals( |
66
|
|
|
self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), |
67
|
|
|
strval($dataReference), |
68
|
|
|
); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
|
72
|
|
|
// unmarshalling |
73
|
|
|
|
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
*/ |
77
|
|
|
public function testUnmarshalling(): void |
78
|
|
|
{ |
79
|
|
|
$dataReference = DataReference::fromXML(self::$xmlRepresentation->documentElement); |
80
|
|
|
|
81
|
|
|
$this->assertEquals( |
82
|
|
|
self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), |
83
|
|
|
strval($dataReference), |
84
|
|
|
); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|