-
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
4 changed files
with
166 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,92 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SimpleSAML\SAML11\XML\samlp; | ||
|
||
use DOMElement; | ||
use SimpleSAML\Assert\Assert; | ||
use SimpleSAML\XML\Chunk; | ||
use SimpleSAML\XML\Exception\InvalidDOMElementException; | ||
use SimpleSAML\XML\ExtendableElementTrait; | ||
use SimpleSAML\XML\XsNamespace as NS; | ||
|
||
/** | ||
* SAML StatusDetail data type. | ||
* | ||
* @package simplesamlphp/saml11 | ||
*/ | ||
abstract class AbstractStatusDetailType extends AbstractSamlpElement | ||
{ | ||
use ExtendableElementTrait; | ||
|
||
/** The namespace-attribute for the xs:any element */ | ||
public const XS_ANY_ELT_NAMESPACE = NS::ANY; | ||
|
||
|
||
/** | ||
* Initialize a samlp:StatusDetail | ||
* | ||
* @param \SimpleSAML\XML\Chunk[] $details | ||
*/ | ||
public function __construct(array $details = []) | ||
{ | ||
$this->setElements($details); | ||
} | ||
|
||
|
||
/** | ||
* Test if an object, at the state it's in, would produce an empty XML-element | ||
* | ||
* @return bool | ||
*/ | ||
public function isEmptyElement(): bool | ||
{ | ||
return empty($this->elements); | ||
} | ||
|
||
|
||
/** | ||
* Convert XML into a StatusDetail | ||
* | ||
* @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, 'StatusDetail', InvalidDOMElementException::class); | ||
Assert::same($xml->namespaceURI, StatusDetail::NS, InvalidDOMElementException::class); | ||
|
||
$details = []; | ||
foreach ($xml->childNodes as $detail) { | ||
if (!($detail instanceof DOMElement)) { | ||
continue; | ||
} | ||
|
||
$details[] = new Chunk($detail); | ||
} | ||
|
||
return new static($details); | ||
} | ||
|
||
|
||
/** | ||
* Convert this StatusDetail to XML. | ||
* | ||
* @param \DOMElement|null $parent The element we are converting to XML. | ||
* @return \DOMElement The XML element after adding the data corresponding to this StatusDetail. | ||
*/ | ||
public function toXML(DOMElement $parent = null): DOMElement | ||
{ | ||
$e = $this->instantiateParentElement($parent); | ||
|
||
foreach ($this->getElements() as $detail) { | ||
$detail->toXML($e); | ||
} | ||
|
||
return $e; | ||
} | ||
} |
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,14 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SimpleSAML\SAML11\XML\samlp; | ||
|
||
/** | ||
* Class representing a saml:StatusDetail element. | ||
* | ||
* @package simplesamlphp/saml11 | ||
*/ | ||
final class StatusDetail extends AbstractStatusDetailType | ||
{ | ||
} |
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,3 @@ | ||
<samlp:StatusDetail xmlns:samlp="urn:oasis:names:tc:SAML:1.0:protocol"> | ||
<samlp:StatusMessage>phpunit</samlp:StatusMessage> | ||
</samlp:StatusDetail> |
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,57 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SimpleSAML\Test\SAML11\XML\saml; | ||
|
||
use DOMDocument; | ||
use PHPUnit\Framework\Attributes\CoversClass; | ||
use PHPUnit\Framework\TestCase; | ||
use SimpleSAML\SAML11\XML\samlp\AbstractStatusDetailType; | ||
use SimpleSAML\SAML11\XML\samlp\StatusDetail; | ||
use SimpleSAML\SAML11\XML\samlp\StatusMessage; | ||
use SimpleSAML\XML\Chunk; | ||
use SimpleSAML\XML\DOMDocumentFactory; | ||
use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait; | ||
use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; | ||
|
||
use function dirname; | ||
use function strval; | ||
|
||
/** | ||
* Class \SimpleSAML\SAML11\XML\samlp\StatusDetailTest | ||
* | ||
* @package simplesamlphp/saml11 | ||
*/ | ||
#[CoversClass(StatusDetail::class)] | ||
#[CoversClass(AbstractStatusDetailType::class)] | ||
#[CoversClass(AbstractSamlpElement::class)] | ||
final class StatusDetailTest extends TestCase | ||
{ | ||
use SchemaValidationTestTrait; | ||
use SerializableElementTestTrait; | ||
|
||
/** | ||
*/ | ||
public static function setUpBeforeClass(): void | ||
{ | ||
self::$testedClass = StatusDetail::class; | ||
|
||
self::$xmlRepresentation = DOMDocumentFactory::fromFile( | ||
dirname(__FILE__, 5) . '/resources/xml/samlp_StatusDetail.xml', | ||
); | ||
} | ||
|
||
|
||
/** | ||
*/ | ||
public function testMarshalling(): void | ||
{ | ||
$statusDetail = new StatusDetail([new StatusMessage('phpunit')]); | ||
|
||
$this->assertEquals( | ||
self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), | ||
strval($statusDetail), | ||
); | ||
} | ||
} |