Skip to content

Commit

Permalink
Add element xenc:Q
Browse files Browse the repository at this point in the history
  • Loading branch information
tvdijen committed Nov 27, 2024
1 parent 3392644 commit 1efc995
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/XML/xenc/Q.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace SimpleSAML\XMLSecurity\XML\xenc;

use SimpleSAML\XML\Base64ElementTrait;

/**
* Class representing a xenc:Q element.
*
* @package simplesaml/xml-security
*/
final class Q extends AbstractXencElement
{
use Base64ElementTrait;


/**
* @param string $content
*/
public function __construct(string $content)
{
$this->setContent($content);
}
}
65 changes: 65 additions & 0 deletions tests/XML/xenc/QTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

declare(strict_types=1);

namespace SimpleSAML\XMLSecurity\Test\XML\xenc;

use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use SimpleSAML\Assert\AssertionFailedException;
use SimpleSAML\XML\DOMDocumentFactory;
use SimpleSAML\XML\TestUtils\SerializableElementTestTrait;
use SimpleSAML\XMLSecurity\Test\XML\XMLDumper;
use SimpleSAML\XMLSecurity\XML\xenc\AbstractXencElement;
use SimpleSAML\XMLSecurity\XML\xenc\Q;

use function dirname;
use function strval;

/**
* Class \SimpleSAML\XMLSecurity\Test\XML\xenc\QTest
*
* @covers \SimpleSAML\XMLSecurity\XML\xenc\AbstractXencElement
* @covers \SimpleSAML\XMLSecurity\XML\xenc\Q
*
* @package simplesamlphp/xml-security
*/
#[CoversClass(AbstractXencElement::class)]
#[CoversClass(Q::class)]
final class QTest extends TestCase
{
use SerializableElementTestTrait;

/**
*/
public static function setUpBeforeClass(): void
{
self::$testedClass = Q::class;

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


/**
*/
public function testMarshalling(): void
{
$q = new Q('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI=');

$this->assertEquals(
XMLDumper::dumpDOMDocumentXMLWithBase64Content(self::$xmlRepresentation),
strval($q),
);
}


/**
*/
public function testMarshallingNotBase64(): void
{
$this->expectException(AssertionFailedException::class);
new Q('/CTj3d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI=');
}
}
1 change: 1 addition & 0 deletions tests/resources/xml/xenc_Q.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<xenc:Q xmlns:xenc="http://www.w3.org/2001/04/xmlenc#">/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI=</xenc:Q>

0 comments on commit 1efc995

Please sign in to comment.