-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SimpleSAML\WSSecurity\XML\fed; | ||
|
||
use DOMElement; | ||
use SimpleSAML\Assert\Assert; | ||
use SimpleSAML\XML\Exception\InvalidDOMElementException; | ||
use SimpleSAML\XML\StringElementTrait; | ||
|
||
use function in_array; | ||
use function sprintf; | ||
|
||
/** | ||
* A AutomaticPseudonyms element | ||
* | ||
* @package tvdijen/ws-security | ||
*/ | ||
final class AutomaticPseudonyms extends AbstractFedElement | ||
{ | ||
use StringElementTrait; | ||
|
||
|
||
/** | ||
* @param bool $content | ||
*/ | ||
public function __construct(bool $content) | ||
{ | ||
$this->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)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SimpleSAML\Test\WSSecurity\XML\sp; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use SimpleSAML\WSSecurity\XML\fed\AutomaticPseudonyms; | ||
use SimpleSAML\XML\DOMDocumentFactory; | ||
use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait; | ||
use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; | ||
|
||
use function dirname; | ||
|
||
/** | ||
* Class \SimpleSAML\WSSecurity\XML\fed\AutomaticPseudonymsTest | ||
* | ||
* @covers \SimpleSAML\WSSecurity\XML\fed\AutomaticPseudonyms | ||
* @covers \SimpleSAML\WSSecurity\XML\fed\AbstractFedElement | ||
* | ||
* @package tvdijen/ws-security | ||
*/ | ||
final class AutomaticPseudonymsTest extends TestCase | ||
{ | ||
use SchemaValidationTestTrait; | ||
use SerializableElementTestTrait; | ||
|
||
|
||
/** | ||
*/ | ||
public static function setUpBeforeClass(): void | ||
{ | ||
self::$schemaFile = dirname(__FILE__, 5) . '/resources/schemas/ws-federation.xsd'; | ||
|
||
self::$testedClass = AutomaticPseudonyms::class; | ||
|
||
self::$xmlRepresentation = DOMDocumentFactory::fromFile( | ||
dirname(__FILE__, 4) . '/resources/xml/fed_AutomaticPseudonyms.xml', | ||
); | ||
} | ||
|
||
|
||
// test marshalling | ||
|
||
|
||
/** | ||
* Test creating a AutomaticPseudonyms object from scratch. | ||
*/ | ||
public function testMarshalling(): void | ||
{ | ||
$automaticPseudonyms = new AutomaticPseudonyms(true); | ||
|
||
$this->assertEquals( | ||
self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), | ||
strval($automaticPseudonyms), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<fed:AutomaticPseudonyms xmlns:fed="http://docs.oasis-open.org/wsfed/federation/200706">true</fed:AutomaticPseudonyms> |