/** * Add this endpoint to an XML element. * * @param \DOMElement $parent The element we should append this endpoint to. * @param string $name The name of the element we should create. * @return \DOMElement */ public function toXML(\DOMElement $parent, $name) { assert('is_string($name)'); assert('is_int($this->index)'); assert('is_null($this->isDefault) || is_bool($this->isDefault)'); $e = parent::toXML($parent, $name); $e->setAttribute('index', (string) $this->index); if ($this->isDefault === true) { $e->setAttribute('isDefault', 'true'); } elseif ($this->isDefault === false) { $e->setAttribute('isDefault', 'false'); } return $e; }
public function testUnmarshalling() { $mdNamespace = Constants::NS_MD; $document = DOMDocumentFactory::fromString(<<<XML <md:Test xmlns:md="{$mdNamespace}" Binding="urn:something" Location="https://whatever/" xmlns:test="urn:test" test:attr="value" /> XML ); $endpointType = new EndpointType($document->firstChild); $this->assertEquals(true, $endpointType->hasAttributeNS('urn:test', 'attr')); $this->assertEquals('value', $endpointType->getAttributeNS('urn:test', 'attr')); $this->assertEquals(false, $endpointType->hasAttributeNS('urn:test', 'invalid')); $this->assertEquals('', $endpointType->getAttributeNS('urn:test', 'invalid')); $endpointType->removeAttributeNS('urn:test', 'attr'); $this->assertEquals(false, $endpointType->hasAttributeNS('urn:test', 'attr')); $this->assertEquals('', $endpointType->getAttributeNS('urn:test', 'attr')); $endpointType->setAttributeNS('urn:test2', 'test2:attr2', 'value2'); $this->assertEquals('value2', $endpointType->getAttributeNS('urn:test2', 'attr2')); $document->loadXML('<root />'); $endpointTypeElement = $endpointType->toXML($document->firstChild, 'md:Test'); $endpointTypeElements = Utils::xpQuery($endpointTypeElement, '/root/saml_metadata:Test'); $this->assertCount(1, $endpointTypeElements); $endpointTypeElement = $endpointTypeElements[0]; $this->assertEquals('value2', $endpointTypeElement->getAttributeNS('urn:test2', 'attr2')); $this->assertEquals(false, $endpointTypeElement->hasAttributeNS('urn:test', 'attr')); }