Passed
Push — master ( feb95e...9f38d8 )
by Tim
01:59
created

TransformTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 22
c 1
b 0
f 0
dl 0
loc 51
rs 10
wmc 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\XMLSecurity\Test\XML\ds;
6
7
use PHPUnit\Framework\Attributes\CoversClass;
8
use PHPUnit\Framework\TestCase;
9
use SimpleSAML\XML\DOMDocumentFactory;
10
use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait;
11
use SimpleSAML\XML\TestUtils\SerializableElementTestTrait;
12
use SimpleSAML\XMLSecurity\Constants as C;
13
use SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement;
14
use SimpleSAML\XMLSecurity\XML\ds\Transform;
15
use SimpleSAML\XMLSecurity\XML\ds\XPath;
16
use SimpleSAML\XMLSecurity\XML\ec\InclusiveNamespaces;
17
18
use function dirname;
19
use function strval;
20
21
/**
22
 * Class \SimpleSAML\XMLSecurity\Test\XML\ds\TransformTest
23
 *
24
 * @package simplesamlphp/xml-security
25
 */
26
#[CoversClass(AbstractDsElement::class)]
27
#[CoversClass(Transform::class)]
28
final class TransformTest extends TestCase
29
{
30
    use SchemaValidationTestTrait;
31
    use SerializableElementTestTrait;
32
33
34
    /**
35
     */
36
    public static function setUpBeforeClass(): void
37
    {
38
        self::$testedClass = Transform::class;
39
40
        self::$xmlRepresentation = DOMDocumentFactory::fromFile(
41
            dirname(__FILE__, 3) . '/resources/xml/ds_Transform.xml',
42
        );
43
    }
44
45
46
    /**
47
     */
48
    public function testMarshalling(): void
49
    {
50
        $transform = new Transform(
51
            C::XPATH10_URI,
52
            new XPath('count(//. | //@* | //namespace::*)'),
53
        );
54
55
        $this->assertEquals(
56
            self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement),
57
            strval($transform),
58
        );
59
60
        $transform = new Transform(
61
            C::C14N_EXCLUSIVE_WITHOUT_COMMENTS,
62
            null,
63
            new InclusiveNamespaces(["dsig", "soap"]),
64
        );
65
66
67
        $this->assertInstanceOf(InclusiveNamespaces::class, $transform->getInclusiveNamespaces());
68
        $this->assertNull($transform->getXPath());
69
70
        $xmlRepresentation = DOMDocumentFactory::fromFile(
71
            dirname(__FILE__, 3) . '/resources/xml/ds_Transform_InclusiveNamespaces.xml',
72
        );
73
74
        $this->assertEquals(
75
            $xmlRepresentation->saveXML($xmlRepresentation->documentElement),
76
            strval($transform),
77
        );
78
    }
79
}
80