diff --git a/src/XML/fed/AutomaticPseudonyms.php b/src/XML/fed/AutomaticPseudonyms.php new file mode 100644 index 00000000..5a69b258 --- /dev/null +++ b/src/XML/fed/AutomaticPseudonyms.php @@ -0,0 +1,61 @@ +setContent($content ? 'true' : 'false'); + } + + + /** + * Convert XML into a class instance + * + * @param \DOMElement $xml The XML element we should load + * @return static + * + * @throws \SimpleSAML\XML\Exception\InvalidDOMElementException + * If the qualified name of the supplied element is wrong + */ + public static function fromXML(DOMElement $xml): static + { + Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class); + Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class); + + Assert::oneOf( + $xml->textContent, + ['0', '1', 'false', 'true'], + sprintf( + 'The value \'%s\' of an %s:%s element must be a boolean.', + $xml->textContent, + static::NS_PREFIX, + static::getLocalName(), + ), + ); + + return new static(in_array($xml->textContent, ['1', 'true'], true)); + } +} diff --git a/tests/WSSecurity/XML/fed/AutomaticPseudonymsTest.php b/tests/WSSecurity/XML/fed/AutomaticPseudonymsTest.php new file mode 100644 index 00000000..40d22c48 --- /dev/null +++ b/tests/WSSecurity/XML/fed/AutomaticPseudonymsTest.php @@ -0,0 +1,58 @@ +assertEquals( + self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), + strval($automaticPseudonyms), + ); + } +} diff --git a/tests/resources/xml/fed_AutomaticPseudonyms.xml b/tests/resources/xml/fed_AutomaticPseudonyms.xml new file mode 100644 index 00000000..0df2a32e --- /dev/null +++ b/tests/resources/xml/fed_AutomaticPseudonyms.xml @@ -0,0 +1 @@ +true