Passed
Branch master (c86cc6)
by Tim
03:54
created

ReferenceListTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 22
dl 0
loc 63
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUpBeforeClass() 0 8 1
A testUnmarshalling() 0 7 1
A testMarshalling() 0 23 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\XMLSecurity\Test\XML\xenc;
6
7
use PHPUnit\Framework\TestCase;
8
use SimpleSAML\XML\DOMDocumentFactory;
9
use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait;
10
use SimpleSAML\XML\TestUtils\SerializableElementTestTrait;
11
use SimpleSAML\XMLSecurity\Constants as C;
12
use SimpleSAML\XMLSecurity\XML\ds\Transform;
13
use SimpleSAML\XMLSecurity\XML\ds\Transforms;
14
use SimpleSAML\XMLSecurity\XML\ds\XPath;
15
use SimpleSAML\XMLSecurity\XML\xenc\DataReference;
16
use SimpleSAML\XMLSecurity\XML\xenc\KeyReference;
17
use SimpleSAML\XMLSecurity\XML\xenc\ReferenceList;
18
19
use function dirname;
20
use function strval;
21
22
/**
23
 * Class \SimpleSAML\XMLSecurity\Test\XML\xenc\ReferenceListTest
24
 *
25
 * @covers \SimpleSAML\XMLSecurity\XML\xenc\AbstractXencElement
26
 * @covers \SimpleSAML\XMLSecurity\XML\xenc\ReferenceList
27
 *
28
 * @package simplesamlphp/xml-security
29
 */
30
final class ReferenceListTest extends TestCase
31
{
32
    use SchemaValidationTestTrait;
0 ignored issues
show
introduced by
The trait SimpleSAML\XML\TestUtils\SchemaValidationTestTrait requires some properties which are not provided by SimpleSAML\XMLSecurity\T...\xenc\ReferenceListTest: $documentElement, $ownerDocument, $message, $line
Loading history...
33
    use SerializableElementTestTrait;
0 ignored issues
show
Bug introduced by
The trait SimpleSAML\XML\TestUtils...lizableElementTestTrait requires the property $documentElement which is not provided by SimpleSAML\XMLSecurity\T...\xenc\ReferenceListTest.
Loading history...
34
35
    /**
36
     */
37
    public static function setUpBeforeClass(): void
38
    {
39
        self::$testedClass = ReferenceList::class;
40
41
        self::$schemaFile = dirname(__FILE__, 4) . '/resources/schemas/xenc-schema.xsd';
42
43
        self::$xmlRepresentation = DOMDocumentFactory::fromFile(
44
            dirname(__FILE__, 3) . '/resources/xml/xenc_ReferenceList.xml',
45
        );
46
    }
47
48
49
    // marshalling
50
51
52
    /**
53
     */
54
    public function testMarshalling(): void
55
    {
56
        $transformData = new Transform(
57
            C::XPATH_URI,
58
            new XPath('self::xenc:EncryptedData[@Id="example1"]'),
59
        );
60
        $transformKey = new Transform(
61
            C::XPATH_URI,
62
            new XPath('self::xenc:EncryptedKey[@Id="example1"]'),
63
        );
64
65
        $referenceList = new ReferenceList(
66
            [
67
                new DataReference('#Encrypted_DATA_ID', [new Transforms([$transformData])])
68
            ],
69
            [
70
                new KeyReference('#Encrypted_KEY_ID', [new Transforms([$transformKey])])
71
            ],
72
        );
73
74
        $this->assertEquals(
75
            self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement),
76
            strval($referenceList),
77
        );
78
    }
79
80
81
    // unmarshalling
82
83
84
    /**
85
     */
86
    public function testUnmarshalling(): void
87
    {
88
        $referenceList = ReferenceList::fromXML(self::$xmlRepresentation->documentElement);
89
90
        $this->assertEquals(
91
            self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement),
92
            strval($referenceList),
93
        );
94
    }
95
}
96