/
StatementTest.php
116 lines (90 loc) · 3.44 KB
/
StatementTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php
declare(strict_types=1);
namespace SimpleSAML\Test\SAML2\XML\saml;
use DOMDocument;
use DOMElement;
use PHPUnit\Framework\TestCase;
use SimpleSAML\SAML2\Compat\ContainerSingleton;
use SimpleSAML\SAML2\Compat\MockContainer;
use SimpleSAML\SAML2\XML\saml\AbstractStatement;
use SimpleSAML\SAML2\XML\saml\Audience;
use SimpleSAML\SAML2\XML\saml\UnknownStatement;
use SimpleSAML\Test\SAML2\Constants as C;
use SimpleSAML\Test\SAML2\CustomStatement;
use SimpleSAML\XML\DOMDocumentFactory;
use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait;
use SimpleSAML\XML\TestUtils\SerializableElementTestTrait;
use function dirname;
use function strval;
/**
* Class \SAML2\XML\saml\StatementTest
*
* @covers \SimpleSAML\SAML2\XML\saml\UnknownStatement
* @covers \SimpleSAML\SAML2\XML\saml\AbstractStatement
* @covers \SimpleSAML\SAML2\XML\saml\AbstractStatementType
* @covers \SimpleSAML\SAML2\XML\saml\AbstractSamlElement
* @package simplesamlphp/saml2
*/
final class StatementTest extends TestCase
{
use SchemaValidationTestTrait;
use SerializableElementTestTrait;
/**
*/
public static function setUpBeforeClass(): void
{
self::$schemaFile = dirname(__FILE__, 4) . '/resources/schemas/simplesamlphp.xsd';
self::$testedClass = CustomStatement::class;
self::$xmlRepresentation = DOMDocumentFactory::fromFile(
dirname(__FILE__, 4) . '/resources/xml/saml_Statement.xml',
);
$container = new MockContainer();
$container->registerExtensionHandler(CustomStatement::class);
ContainerSingleton::setContainer($container);
}
// marshalling
/**
*/
public function testMarshalling(): void
{
$statement = new CustomStatement(
[new Audience('urn:some:audience')],
);
$this->assertEquals(
self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement),
strval($statement),
);
}
// unmarshalling
/**
* Test unmarshalling a registered class
*/
public function testUnmarshalling(): void
{
$statement = CustomStatement::fromXML(self::$xmlRepresentation->documentElement);
$this->assertInstanceOf(CustomStatement::class, $statement);
$this->assertEquals('ssp:CustomStatementType', $statement->getXsiType());
$audience = $statement->getAudience();
$this->assertCount(1, $audience);
$this->assertEquals('urn:some:audience', $audience[0]->getContent());
$this->assertEquals(
self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement),
strval($statement),
);
}
/**
*/
public function testUnmarshallingUnregistered(): void
{
$element = clone self::$xmlRepresentation->documentElement;
$element->setAttributeNS(C::NS_XSI, 'xsi:type', 'ssp:UnknownStatementType');
$statement = AbstractStatement::fromXML($element);
$this->assertInstanceOf(UnknownStatement::class, $statement);
$this->assertEquals('urn:x-simplesamlphp:namespace:UnknownStatementType', $statement->getXsiType());
$chunk = $statement->getRawStatement();
$this->assertEquals('saml', $chunk->getPrefix());
$this->assertEquals('Statement', $chunk->getLocalName());
$this->assertEquals(C::NS_SAML, $chunk->getNamespaceURI());
$this->assertEquals($element->ownerDocument?->saveXML($element), strval($statement));
}
}