44
55namespace SAML2 \XML \md ;
66
7+ use InvalidArgumentException ;
8+ use SAML2 \Constants ;
79use SAML2 \DOMDocumentFactory ;
10+ use SAML2 \XML \idpdisc \DiscoveryResponse ;
811use SAML2 \XML \md \IndexedEndpointType ;
912use SAML2 \Utils ;
1013
@@ -16,7 +19,7 @@ class IndexedEndpointTypeTest extends \PHPUnit\Framework\TestCase
1619 /**
1720 * @return void
1821 */
19- public function testMarshalling () : void
22+ public function testMarshalling (): void
2023 {
2124 $ indexedEndpointType = new IndexedEndpointType ();
2225 $ indexedEndpointType ->setBinding ('TestBinding ' );
@@ -50,4 +53,41 @@ public function testMarshalling() : void
5053 $ this ->assertCount (1 , $ indexedEndpointTypeElement );
5154 $ this ->assertTrue (!$ indexedEndpointTypeElement [0 ]->hasAttribute ('isDefault ' ));
5255 }
56+
57+
58+ /**
59+ * @return void
60+ */
61+ public function testMarshallingDiscoveryResponse (): void
62+ {
63+ $ discoResponse = new DiscoveryResponse ();
64+ $ discoResponse ->setBinding (Constants::NS_IDPDISC );
65+ $ discoResponse ->setLocation ('TestLocation ' );
66+ $ discoResponse ->setIndex (42 );
67+ $ discoResponse ->setIsDefault (false );
68+
69+ $ document = DOMDocumentFactory::fromString ('<root /> ' );
70+ $ discoResponseElement = $ discoResponse ->toXML ($ document ->firstChild , 'idpdisc:DiscoverResponse ' );
71+
72+ $ discoResponseElements = Utils::xpQuery ($ discoResponseElement , '/root/saml_idpdisc:DiscoveryResponse ' );
73+ $ this ->assertCount (1 , $ discoResponseElements );
74+ $ discoResponseElement = $ discoResponseElements [0 ];
75+
76+ $ this ->assertEquals (Constants::NS_IDPDISC , $ discoResponseElement ->getAttribute ('Binding ' ));
77+ $ this ->assertEquals ('TestLocation ' , $ discoResponseElement ->getAttribute ('Location ' ));
78+ $ this ->assertEquals ('42 ' , $ discoResponseElement ->getAttribute ('index ' ));
79+ $ this ->assertEquals ('false ' , $ discoResponseElement ->getAttribute ('isDefault ' ));
80+ }
81+
82+
83+ /**
84+ * @return void
85+ */
86+ public function testMarshallingDiscoveryResponseWrongBindingFails (): void
87+ {
88+ $ discoResponse = new DiscoveryResponse ();
89+
90+ $ this ->expectException (InvalidArgumentException::class);
91+ $ discoResponse ->setBinding ('This is not OK. ' );
92+ }
5393}
0 commit comments