Passed
Branch master (c86cc6)
by Tim
01:57
created

TransformTest::testUnmarshalling()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 7
rs 10
c 0
b 0
f 0
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\Transform;
13
use SimpleSAML\XMLSecurity\XML\ds\XPath;
14
use SimpleSAML\XMLSecurity\XML\ec\InclusiveNamespaces;
15
16
use function dirname;
17
use function strval;
18
19
/**
20
 * Class \SimpleSAML\XMLSecurity\Test\XML\ds\TransformTest
21
 *
22
 * @covers \SimpleSAML\XMLSecurity\XML\ds\Transform
23
 * @covers \SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement
24
 *
25
 * @package simplesamlphp/xml-security
26
 */
27
final class TransformTest extends TestCase
28
{
29
    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\TransformTest: $documentElement, $ownerDocument, $message, $line
Loading history...
30
    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\TransformTest.
Loading history...
31
32
33
    /**
34
     */
35
    public static function setUpBeforeClass(): void
36
    {
37
        self::$testedClass = Transform::class;
38
39
        self::$schemaFile = dirname(__FILE__, 4) . '/resources/schemas/xmldsig1-schema.xsd';
40
41
        self::$xmlRepresentation = DOMDocumentFactory::fromFile(
42
            dirname(__FILE__, 3) . '/resources/xml/ds_Transform.xml',
43
        );
44
    }
45
46
47
    /**
48
     */
49
    public function testMarshalling(): void
50
    {
51
        $transform = new Transform(
52
            C::XPATH_URI,
53
            new XPath('count(//. | //@* | //namespace::*)'),
54
        );
55
56
        $this->assertEquals(
57
            self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement),
58
            strval($transform),
59
        );
60
61
        $transform = new Transform(
62
            C::C14N_EXCLUSIVE_WITHOUT_COMMENTS,
63
            null,
64
            new InclusiveNamespaces(["dsig", "soap"]),
65
        );
66
67
68
        $this->assertInstanceOf(InclusiveNamespaces::class, $transform->getInclusiveNamespaces());
69
        $this->assertNull($transform->getXPath());
70
71
        $xmlRepresentation = DOMDocumentFactory::fromFile(
72
            dirname(__FILE__, 3) . '/resources/xml/ds_Transform_InclusiveNamespaces.xml',
73
        );
74
75
        $this->assertEquals(
76
            $xmlRepresentation->saveXML($xmlRepresentation->documentElement),
77
            strval($transform),
78
        );
79
    }
80
81
82
    /**
83
     */
84
    public function testUnmarshalling(): void
85
    {
86
        $transform = Transform::fromXML(self::$xmlRepresentation->documentElement);
87
88
        $this->assertEquals(
89
            self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement),
90
            strval($transform),
91
        );
92
    }
93
}
94