Passed
Pull Request — master (#60)
by Tim
02:12
created

EncryptionPropertyTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
c 1
b 0
f 0
dl 0
loc 44
rs 10
wmc 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\XMLSecurity\Test\XML\xenc;
6
7
use PHPUnit\Framework\Attributes\{CoversClass, Group};
8
use PHPUnit\Framework\TestCase;
9
use SimpleSAML\XML\{Attribute as XMLAttribute, Chunk, Constants as C, DOMDocumentFactory};
10
use SimpleSAML\XML\TestUtils\{SchemaValidationTestTrait, SerializableElementTestTrait};
11
use SimpleSAML\XML\Type\{AnyURIValue, IDValue, StringValue};
12
use SimpleSAML\XMLSecurity\XML\xenc\{AbstractEncryptionPropertyType, AbstractXencElement, EncryptionProperty};
13
14
use function dirname;
15
use function strval;
16
17
/**
18
 * Class \SimpleSAML\XMLSecurity\Test\XML\xenc\EncryptionPropertyTest
19
 *
20
 * @covers \SimpleSAML\XMLSecurity\XML\xenc\AbstractXencElement
21
 * @covers \SimpleSAML\XMLSecurity\XML\xenc\AbstractEncryptionPropertyType
22
 * @covers \SimpleSAML\XMLSecurity\XML\xenc\EncryptionProperty
23
 *
24
 * @package simplesamlphp/xml-security
25
 */
26
#[Group('xenc')]
27
#[CoversClass(AbstractXencElement::class)]
28
#[CoversClass(AbstractEncryptionPropertyType::class)]
29
#[CoversClass(EncryptionProperty::class)]
30
final class EncryptionPropertyTest extends TestCase
31
{
32
    use SchemaValidationTestTrait;
33
    use SerializableElementTestTrait;
34
35
    /**
36
     */
37
    public static function setUpBeforeClass(): void
38
    {
39
        self::$testedClass = EncryptionProperty::class;
40
41
        self::$xmlRepresentation = DOMDocumentFactory::fromFile(
42
            dirname(__FILE__, 3) . '/resources/xml/xenc_EncryptionProperty.xml',
43
        );
44
    }
45
46
47
    // marshalling
48
49
50
    /**
51
     */
52
    public function testMarshalling(): void
53
    {
54
        $doc = DOMDocumentFactory::fromString(
55
            '<ssp:Chunk xmlns:ssp="urn:x-simplesamlphp:namespace">Some</ssp:Chunk>',
56
        );
57
        /** @var \DOMElement $elt */
58
        $elt = $doc->documentElement;
59
60
        $attr = new XMLAttribute(
61
            C::NS_XML,
62
            'xml',
63
            'lang',
64
            StringValue::fromString('en'),
65
        );
66
67
        $encryptionProperty = new EncryptionProperty(
68
            [new Chunk($elt)],
69
            AnyURIValue::fromString('urn:x-simplesamlphp:phpunit'),
70
            IDValue::fromString('phpunit'),
71
            [$attr],
72
        );
73
74
        $this->assertEquals(
75
            self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement),
76
            strval($encryptionProperty),
77
        );
78
    }
79
}
80