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

EncryptionPropertiesTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 27
c 1
b 0
f 0
dl 0
loc 60
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;
10
use SimpleSAML\XML\{Chunk, Constants as C, DOMDocumentFactory};
11
use SimpleSAML\XML\TestUtils\{SchemaValidationTestTrait, SerializableElementTestTrait};
12
use SimpleSAML\XML\Type\{AnyURIValue, IDValue, StringValue};
13
use SimpleSAML\XMLSecurity\XML\xenc\{
14
    AbstractEncryptionPropertiesType,
15
    AbstractXencElement,
16
    EncryptionProperties,
17
    EncryptionProperty,
18
};
19
20
use function dirname;
21
use function strval;
22
23
/**
24
 * Class \SimpleSAML\XMLSecurity\Test\XML\xenc\EncryptionPropertiesTest
25
 *
26
 * @covers \SimpleSAML\XMLSecurity\XML\xenc\AbstractXencElement
27
 * @covers \SimpleSAML\XMLSecurity\XML\xenc\AbstractEncryptionPropertiesType
28
 * @covers \SimpleSAML\XMLSecurity\XML\xenc\EncryptionProperties
29
 *
30
 * @package simplesamlphp/xml-security
31
 */
32
#[Group('xenc')]
33
#[CoversClass(AbstractXencElement::class)]
34
#[CoversClass(AbstractEncryptionPropertiesType::class)]
35
#[CoversClass(EncryptionProperties::class)]
36
final class EncryptionPropertiesTest extends TestCase
37
{
38
    use SchemaValidationTestTrait;
39
    use SerializableElementTestTrait;
40
41
    /**
42
     */
43
    public static function setUpBeforeClass(): void
44
    {
45
        self::$testedClass = EncryptionProperties::class;
46
47
        self::$xmlRepresentation = DOMDocumentFactory::fromFile(
48
            dirname(__FILE__, 3) . '/resources/xml/xenc_EncryptionProperties.xml',
49
        );
50
    }
51
52
53
    // marshalling
54
55
56
    /**
57
     */
58
    public function testMarshalling(): void
59
    {
60
        $someDoc = DOMDocumentFactory::fromString(
61
            '<ssp:Chunk xmlns:ssp="urn:x-simplesamlphp:namespace">Some</ssp:Chunk>',
62
        );
63
        $otherDoc = DOMDocumentFactory::fromString(
64
            '<ssp:Chunk xmlns:ssp="urn:x-simplesamlphp:namespace">Other</ssp:Chunk>',
65
        );
66
67
        /** @var \DOMElement $someElt */
68
        $someElt = $someDoc->documentElement;
69
        /** @var \DOMElement $otherElt */
70
        $otherElt = $otherDoc->documentElement;
71
72
        $attr1 = new XMLAttribute(
73
            C::NS_XML,
74
            'xml',
75
            'lang',
76
            StringValue::fromString('en'),
77
        );
78
        $attr2 = new XMLAttribute(
79
            C::NS_XML,
80
            'xml',
81
            'lang',
82
            StringValue::fromString('nl'),
83
        );
84
85
        $encryptionProperty1 = new EncryptionProperty(
86
            [new Chunk($someElt)],
87
            AnyURIValue::fromString('urn:x-simplesamlphp:phpunit'),
88
            IDValue::fromString('inner-first'),
89
            [$attr1],
90
        );
91
        $encryptionProperty2 = new EncryptionProperty(
92
            [new Chunk($otherElt)],
93
            AnyURIValue::fromString('urn:x-simplesamlphp:phpunit'),
94
            IDValue::fromString('inner-second'),
95
            [$attr2],
96
        );
97
98
        $encryptionProperties = new EncryptionProperties(
99
            [$encryptionProperty1, $encryptionProperty2],
100
            IDValue::fromString('outer'),
101
        );
102
103
        $this->assertEquals(
104
            self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement),
105
            strval($encryptionProperties),
106
        );
107
    }
108
}
109