From 4ba3c7ef381d4dfbe85e920380b9dd8027dc47d9 Mon Sep 17 00:00:00 2001 From: Tim van Dijen Date: Sat, 6 Jan 2024 17:57:20 +0100 Subject: [PATCH] WIP: create fed classes --- src/XML/fed/AutomaticPseudonyms.php | 61 +++++++++++++++++++ .../XML/fed/AutomaticPseudonymsTest.php | 58 ++++++++++++++++++ .../resources/xml/fed_AutomaticPseudonyms.xml | 1 + 3 files changed, 120 insertions(+) create mode 100644 src/XML/fed/AutomaticPseudonyms.php create mode 100644 tests/WSSecurity/XML/fed/AutomaticPseudonymsTest.php create mode 100644 tests/resources/xml/fed_AutomaticPseudonyms.xml 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