Skip to content

Commit

Permalink
Implement saml:DoNotCacheCondition
Browse files Browse the repository at this point in the history
  • Loading branch information
tvdijen committed Feb 27, 2024
1 parent 388d1d8 commit 2812fca
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 0 deletions.
58 changes: 58 additions & 0 deletions src/SAML11/XML/saml/AbstractDoNotCacheConditionType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

declare(strict_types=1);

namespace SimpleSAML\SAML11\XML\saml;

use DOMElement;
use SimpleSAML\Assert\Assert;
use SimpleSAML\SAML11\XML\saml\AbstractConditionType;
use SimpleSAML\SAML11\Constants as C;
use SimpleSAML\XML\Exception\InvalidDOMElementException;
use SimpleSAML\XML\Exception\MissingElementException;
use SimpleSAML\XML\Exception\SchemaViolationException;

use function array_pop;

/**
* @package simplesamlphp\saml11
*/
abstract class AbstractDoNotCacheConditionType extends AbstractConditionType
{
/**
* DoNotCacheConditionType constructor.
*/
public function __construct(
) {
}


/**
* Convert XML into a DoNotCacheCondition
*
* @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::getNamespaceURI(), InvalidDOMElementException::class);

return new static();
}


/**
* Convert this DoNotCacheCondition to XML.
*
* @param \DOMElement $parent The element we are converting to XML.
* @return \DOMElement The XML element after adding the data corresponding to this DoNotCacheCondition.
*/
public function toXML(DOMElement $parent = null): DOMElement
{
return $this->instantiateParentElement($parent);
}
}
14 changes: 14 additions & 0 deletions src/SAML11/XML/saml/DoNotCacheCondition.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

namespace SimpleSAML\SAML11\XML\saml;

/**
* Class representing a saml:DoNotCacheCondition element.
*
* @package simplesamlphp/saml11
*/
final class DoNotCacheCondition extends AbstractDoNotCacheConditionType
{
}
14 changes: 14 additions & 0 deletions src/SAML11/XML/saml/DoNotCacheConditionType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

namespace SimpleSAML\SAML11\XML\saml;

/**
* Class representing a saml:DoNotCacheCondition element.
*
* @package simplesamlphp/saml11
*/
final class DoNotCacheCondition extends AbstractConditionType
{
}
1 change: 1 addition & 0 deletions tests/resources/xml/saml_DoNotCacheCondition.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<saml:DoNotCacheCondition xmlns:saml="urn:oasis:names:tc:SAML:1.0:assertion" />
60 changes: 60 additions & 0 deletions tests/src/SAML11/XML/saml/DoNotCacheConditionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

declare(strict_types=1);

namespace SimpleSAML\Test\SAML11\XML\saml;

use PHPUnit\Framework\TestCase;
use SimpleSAML\SAML11\XML\saml\DoNotCacheCondition;
use SimpleSAML\XML\DOMDocumentFactory;
use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait;
use SimpleSAML\XML\TestUtils\SerializableElementTestTrait;

use function dirname;
use function strval;

/**
* Tests for DoNotCacheCondition elements.
*
* @covers \SimpleSAML\SAML11\XML\saml\DoNotCacheCondition
* @covers \SimpleSAML\SAML11\XML\saml\AbstractConditionType
* @covers \SimpleSAML\SAML11\XML\saml\AbstractSamlElement
*
* @package simplesamlphp/saml11
*/
final class DoNotCacheConditionTest extends TestCase
{
use SchemaValidationTestTrait;
use SerializableElementTestTrait;


/**
*/
public static function setUpBeforeClass(): void
{
self::$schemaFile = dirname(__FILE__, 6) . '/resources/schemas/oasis-sstc-saml-schema-assertion-1.1.xsd';

self::$testedClass = DoNotCacheCondition::class;

self::$xmlRepresentation = DOMDocumentFactory::fromFile(
dirname(__FILE__, 5) . '/resources/xml/saml_DoNotCacheCondition.xml',
);
}


// marshalling


/**
* Test creating an DoNotCacheCondition from scratch
*/
public function testMarshalling(): void
{
$DoNotCacheCondition = new DoNotCacheCondition();

$this->assertEquals(
self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement),
strval($DoNotCacheCondition),
);
}
}

0 comments on commit 2812fca

Please sign in to comment.