diff --git a/src/XML/wsa_200508/RelatesTo.php b/src/XML/wsa_200508/RelatesTo.php index d3e04f8..d9c8deb 100644 --- a/src/XML/wsa_200508/RelatesTo.php +++ b/src/XML/wsa_200508/RelatesTo.php @@ -9,10 +9,9 @@ use SimpleSAML\XML\Exception\InvalidDOMElementException; use SimpleSAML\XML\Exception\SchemaViolationException; use SimpleSAML\XML\ExtendableAttributesTrait; +use SimpleSAML\XML\URIElementTrait; use SimpleSAML\XML\XsNamespace as NS; -use function is_null; - /** * Class representing a wsa:RelatesTo element. * @@ -21,6 +20,7 @@ final class RelatesTo extends AbstractWsaElement { use ExtendableAttributesTrait; + use URIElementTrait; /** The namespace-attribute for the xs:anyAttribute element */ public const XS_ANY_ATTR_NAMESPACE = NS::OTHER; @@ -29,15 +29,18 @@ final class RelatesTo extends AbstractWsaElement /** * Initialize a wsa:RelatesTo * + * @param string $content * @param string|null $RelationshipType * @param list<\SimpleSAML\XML\Attribute> $namespacedAttributes */ public function __construct( + string $content, protected ?string $RelationshipType = 'http://www.w3.org/2005/08/addressing/reply', array $namespacedAttributes = [], ) { Assert::nullOrValidURI($RelationshipType, SchemaViolationException::class); + $this->setContent($content); $this->setAttributesNS($namespacedAttributes); } @@ -53,17 +56,6 @@ public function getRelationshipType(): ?string } - /** - * Test if an object, at the state it's in, would produce an empty XML-element - * - * @return bool - */ - public function isEmptyElement(): bool - { - return is_null($this->RelationshipType) && empty($this->namespacedAttributes); - } - - /* * Convert XML into an RelatesTo element * @@ -79,6 +71,7 @@ public static function fromXML(DOMElement $xml): static Assert::same($xml->namespaceURI, RelatesTo::NS, InvalidDOMElementException::class); return new static( + $xml->textContent, self::getOptionalAttribute($xml, 'RelationshipType', null), self::getAttributesNSFromXML($xml), ); @@ -94,6 +87,7 @@ public static function fromXML(DOMElement $xml): static public function toXML(?DOMElement $parent = null): DOMElement { $e = $this->instantiateParentElement($parent); + $e->textContent = $this->getContent(); if ($this->getRelationshipType() !== null) { $e->setAttribute('RelationshipType', $this->getRelationshipType()); diff --git a/tests/WSSecurity/XML/wsa_200508/RelatesToTest.php b/tests/WSSecurity/XML/wsa_200508/RelatesToTest.php index e43c52e..059cbf5 100644 --- a/tests/WSSecurity/XML/wsa_200508/RelatesToTest.php +++ b/tests/WSSecurity/XML/wsa_200508/RelatesToTest.php @@ -50,25 +50,15 @@ public function testMarshalling(): void { $domAttr = new Attribute('urn:test:something', 'test', 'attr1', 'testval1'); - $relatesTo = new RelatesTo('http://www.w3.org/2005/08/addressing/reply', [$domAttr]); - $this->assertFalse($relatesTo->isEmptyElement()); - - $this->assertEquals( - self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), - strval($relatesTo), + $relatesTo = new RelatesTo( + 'urn:x-simplesamlphp:namespace', + 'http://www.w3.org/2005/08/addressing/reply', + [$domAttr], ); - } - - /** - */ - public function testMarshallingWithNoContent(): void - { - $relatesTo = new RelatesTo(null, []); $this->assertEquals( - '', + self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), strval($relatesTo), ); - $this->assertTrue($relatesTo->isEmptyElement()); } } diff --git a/tests/resources/xml/wsa/200508/RelatesTo.xml b/tests/resources/xml/wsa/200508/RelatesTo.xml index 19c57de..b25c54d 100644 --- a/tests/resources/xml/wsa/200508/RelatesTo.xml +++ b/tests/resources/xml/wsa/200508/RelatesTo.xml @@ -1 +1 @@ - +urn:x-simplesamlphp:namespace