Passed
Push — master ( feb95e...9f38d8 )
by Tim
01:59
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;
8
use PHPUnit\Framework\TestCase;
9
use SimpleSAML\XML\Attribute as XMLAttribute;
10
use SimpleSAML\XML\Chunk;
11
use SimpleSAML\XML\Constants as C;
12
use SimpleSAML\XML\DOMDocumentFactory;
13
use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait;
14
use SimpleSAML\XML\TestUtils\SerializableElementTestTrait;
15
use SimpleSAML\XMLSecurity\XML\xenc\AbstractEncryptionPropertiesType;
16
use SimpleSAML\XMLSecurity\XML\xenc\AbstractXencElement;
17
use SimpleSAML\XMLSecurity\XML\xenc\EncryptionProperties;
18
use SimpleSAML\XMLSecurity\XML\xenc\EncryptionProperty;
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
#[CoversClass(AbstractXencElement::class)]
33
#[CoversClass(AbstractEncryptionPropertiesType::class)]
34
#[CoversClass(EncryptionProperties::class)]
35
final class EncryptionPropertiesTest extends TestCase
36
{
37
    use SchemaValidationTestTrait;
38
    use SerializableElementTestTrait;
39
40
    /**
41
     */
42
    public static function setUpBeforeClass(): void
43
    {
44
        self::$testedClass = EncryptionProperties::class;
45
46
        self::$xmlRepresentation = DOMDocumentFactory::fromFile(
47
            dirname(__FILE__, 3) . '/resources/xml/xenc_EncryptionProperties.xml',
48
        );
49
    }
50
51
52
    // marshalling
53
54
55
    /**
56
     */
57
    public function testMarshalling(): void
58
    {
59
        $someDoc = DOMDocumentFactory::fromString(
60
            '<ssp:Chunk xmlns:ssp="urn:x-simplesamlphp:namespace">Some</ssp:Chunk>',
61
        );
62
        $otherDoc = DOMDocumentFactory::fromString(
63
            '<ssp:Chunk xmlns:ssp="urn:x-simplesamlphp:namespace">Other</ssp:Chunk>',
64
        );
65
66
        /** @var \DOMElement $someElt */
67
        $someElt = $someDoc->documentElement;
68
        /** @var \DOMElement $otherElt */
69
        $otherElt = $otherDoc->documentElement;
70
71
        $attr1 = new XMLAttribute(C::NS_XML, 'xml', 'lang', 'en');
72
        $attr2 = new XMLAttribute(C::NS_XML, 'xml', 'lang', 'nl');
73
74
        $encryptionProperty1 = new EncryptionProperty(
75
            [new Chunk($someElt)],
76
            'urn:x-simplesamlphp:phpunit',
77
            'inner-first',
78
            [$attr1],
79
        );
80
        $encryptionProperty2 = new EncryptionProperty(
81
            [new Chunk($otherElt)],
82
            'urn:x-simplesamlphp:phpunit',
83
            'inner-second',
84
            [$attr2],
85
        );
86
87
        $encryptionProperties = new EncryptionProperties([$encryptionProperty1, $encryptionProperty2], 'outer');
88
89
        $this->assertEquals(
90
            self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement),
91
            strval($encryptionProperties),
92
        );
93
    }
94
}
95