1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SimpleSAML\XMLSecurity\Test\XML\ds; |
6
|
|
|
|
7
|
|
|
use DOMDocument; |
8
|
|
|
use PHPUnit\Framework\TestCase; |
9
|
|
|
use SimpleSAML\XML\Chunk; |
10
|
|
|
use SimpleSAML\XML\DOMDocumentFactory; |
11
|
|
|
use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait; |
12
|
|
|
use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; |
13
|
|
|
use SimpleSAML\XMLSecurity\Constants; |
14
|
|
|
use SimpleSAML\XMLSecurity\XML\ds\DsObject; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Class \SimpleSAML\XMLSecurity\XML\Test\ds\ObjectTest |
18
|
|
|
* |
19
|
|
|
* @covers \SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement |
20
|
|
|
* @covers \SimpleSAML\XMLSecurity\XML\ds\DsObject |
21
|
|
|
* |
22
|
|
|
* @package simplesamlphp/xml-security |
23
|
|
|
*/ |
24
|
|
|
final class ObjectTest extends TestCase |
25
|
|
|
{ |
26
|
|
|
use SchemaValidationTestTrait; |
|
|
|
|
27
|
|
|
use SerializableElementTestTrait; |
|
|
|
|
28
|
|
|
|
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
*/ |
32
|
|
|
public static function setUpBeforeClass(): void |
33
|
|
|
{ |
34
|
|
|
self::$testedClass = DsObject::class; |
35
|
|
|
|
36
|
|
|
self::$schemaFile = dirname(__FILE__, 4) . '/resources/schemas/xmldsig1-schema.xsd'; |
37
|
|
|
|
38
|
|
|
self::$xmlRepresentation = DOMDocumentFactory::fromFile( |
39
|
|
|
dirname(__FILE__, 3) . '/resources/xml/ds_Object.xml' |
40
|
|
|
); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
*/ |
46
|
|
|
public function testMarshalling(): void |
47
|
|
|
{ |
48
|
|
|
$img = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII='; |
49
|
|
|
$obj = new DsObject( |
50
|
|
|
'abc123', |
51
|
|
|
'image/png', |
52
|
|
|
'http://www.w3.org/2000/09/xmldsig#base64', |
53
|
|
|
[ |
54
|
|
|
new Chunk( |
55
|
|
|
DOMDocumentFactory::fromString(sprintf( |
56
|
|
|
'<ssp:data xmlns:ssp="urn:ssp:custom">%s</ssp:data>', |
57
|
|
|
$img |
58
|
|
|
))->documentElement |
59
|
|
|
) |
60
|
|
|
], |
61
|
|
|
); |
62
|
|
|
|
63
|
|
|
$this->assertEquals( |
64
|
|
|
self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), |
65
|
|
|
strval($obj) |
66
|
|
|
); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Adding an empty Object-element should yield an empty element. |
72
|
|
|
*/ |
73
|
|
|
public function testMarshallingEmptyElement(): void |
74
|
|
|
{ |
75
|
|
|
$ds_ns = DsObject::NS; |
76
|
|
|
$obj = new DsObject(null, null, null, []); |
77
|
|
|
$this->assertEquals( |
78
|
|
|
"<ds:Object xmlns:ds=\"$ds_ns\"/>", |
79
|
|
|
strval($obj) |
80
|
|
|
); |
81
|
|
|
$this->assertTrue($obj->isEmptyElement()); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|