-
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
118 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,60 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SimpleSAML\SAML11\XML\samlp; | ||
|
||
use DOMElement; | ||
use SimpleSAML\Assert\Assert; | ||
use SimpleSAML\XML\Exception\InvalidDOMElementException; | ||
use SimpleSAML\XML\StringElementTrait; | ||
|
||
/** | ||
* Class representing a samlp:StatusMessage element. | ||
* | ||
* @package simplesaml/SAML11 | ||
*/ | ||
final class StatusMessage extends AbstractSamlpElement | ||
{ | ||
use StringElementTrait; | ||
|
||
|
||
/** | ||
* @param string $content | ||
*/ | ||
public function __construct(string $content) | ||
{ | ||
$this->setContent($content); | ||
} | ||
|
||
|
||
/** | ||
* Validate the content of the element. | ||
* | ||
* @param string $content The value to go in the XML textContent | ||
* @throws \Exception on failure | ||
* @return void | ||
*/ | ||
protected function validateContent(string $content): void | ||
{ | ||
Assert::notWhitespaceOnly($content); | ||
} | ||
|
||
|
||
/** | ||
* Convert XML into an StatusMessage | ||
* | ||
* @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, 'StatusMessage', InvalidDOMElementException::class); | ||
Assert::same($xml->namespaceURI, StatusMessage::NS, InvalidDOMElementException::class); | ||
|
||
return new static($xml->textContent); | ||
} | ||
} |
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 @@ | ||
<samlp:StatusMessage xmlns:samlp="urn:oasis:names:tc:SAML:1.0:protocol">Something went wrong</samlp:StatusMessage> |
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\SAML11\Test\SAML11\XML\samlp; | ||
|
||
use PHPUnit\Framework\Attributes\CoversClass; | ||
use PHPUnit\Framework\Attributes\Group; | ||
use PHPUnit\Framework\TestCase; | ||
use SimpleSAML\SAML11\XML\samlp\AbstractSamlpElement; | ||
use SimpleSAML\SAML11\XML\samlp\StatusMessage; | ||
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\StatusMessageTest | ||
* | ||
* @package simplesamlphp/SAML11 | ||
*/ | ||
#[Group('samlp')] | ||
#[CoversClass(StatusMessage::class)] | ||
#[CoversClass(AbstractSamlpElement::class)] | ||
final class StatusMessageTest extends TestCase | ||
{ | ||
use SchemaValidationTestTrait; | ||
use SerializableElementTestTrait; | ||
|
||
/** | ||
*/ | ||
public static function setUpBeforeClass(): void | ||
{ | ||
self::$schemaFile = dirname(__FILE__, 6) . '/resources/schemas/oasis-sstc-saml-schema-protocol-1.1.xsd'; | ||
|
||
self::$testedClass = StatusMessage::class; | ||
|
||
self::$xmlRepresentation = DOMDocumentFactory::fromFile( | ||
dirname(__FILE__, 5) . '/resources/xml/samlp_StatusMessage.xml', | ||
); | ||
} | ||
|
||
|
||
/** | ||
*/ | ||
public function testMarshalling(): void | ||
{ | ||
$statusMessage = new StatusMessage('Something went wrong'); | ||
|
||
$this->assertEquals( | ||
self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), | ||
strval($statusMessage), | ||
); | ||
} | ||
} |