Passed
Branch master (c86cc6)
by Tim
11:28
created

ManifestTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 23
dl 0
loc 55
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testMarshalling() 0 20 1
A setUpBeforeClass() 0 8 1
A testUnmarshalling() 0 7 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\XMLSecurity\Test\XML\ds;
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\DigestMethod;
13
use SimpleSAML\XMLSecurity\XML\ds\DigestValue;
14
use SimpleSAML\XMLSecurity\XML\ds\Manifest;
15
use SimpleSAML\XMLSecurity\XML\ds\Reference;
16
use SimpleSAML\XMLSecurity\XML\ds\Transform;
17
use SimpleSAML\XMLSecurity\XML\ds\Transforms;
18
19
use function dirname;
20
use function strval;
21
22
/**
23
 * Class \SimpleSAML\XMLSecurity\Test\XML\ds\ManifestTest
24
 *
25
 * @covers \SimpleSAML\XMLSecurity\XML\ds\Manifest
26
 * @covers \SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement
27
 *
28
 * @package simplesamlphp/saml2
29
 */
30
final class ManifestTest 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\Test\XML\ds\ManifestTest: $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\Test\XML\ds\ManifestTest.
Loading history...
34
35
36
    /**
37
     */
38
    public static function setUpBeforeClass(): void
39
    {
40
        self::$testedClass = Manifest::class;
41
42
        self::$schemaFile = dirname(__FILE__, 4) . '/resources/schemas/xmldsig1-schema.xsd';
43
44
        self::$xmlRepresentation = DOMDocumentFactory::fromFile(
45
            dirname(__FILE__, 3) . '/resources/xml/ds_Manifest.xml',
46
        );
47
    }
48
49
50
    /**
51
     */
52
    public function testMarshalling(): void
53
    {
54
        $reference = new Reference(
55
            new DigestMethod(C::DIGEST_SHA256),
56
            new DigestValue('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='),
57
            new Transforms(
58
                [
59
                    new Transform(C::XMLDSIG_ENVELOPED),
60
                    new Transform(C::C14N_EXCLUSIVE_WITHOUT_COMMENTS),
61
                ],
62
            ),
63
            'abc123',
64
            C::XMLDSIG_MANIFEST,
65
            '#_1e280ee704fb1d8d9dec4bd6c1889ec96942921153',
66
        );
67
        $manifest = new Manifest([$reference], 'abc123');
68
69
        $this->assertEquals(
70
            self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement),
71
            strval($manifest),
72
        );
73
    }
74
75
76
    /**
77
     */
78
    public function testUnmarshalling(): void
79
    {
80
        $manifest = Manifest::fromXML(self::$xmlRepresentation->documentElement);
81
82
        $this->assertEquals(
83
            self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement),
84
            strval($manifest),
85
        );
86
    }
87
}
88