Passed
Pull Request — master (#61)
by
unknown
12:50
created

TransformsTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
eloc 18
dl 0
loc 53
rs 10
c 4
b 0
f 0
wmc 3
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\DOMDocumentFactory;
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\xenc\AbstractXencElement;
15
use SimpleSAML\XMLSecurity\XML\xenc\Transforms;
16
17
use function dirname;
18
use function strval;
19
20
/**
21
 * Class \SimpleSAML\XMLSecurity\Test\XML\xenc\TransformsTest
22
 *
23
 * @covers \SimpleSAML\XMLSecurity\XML\xenc\Transforms
24
 * @covers \SimpleSAML\XMLSecurity\XML\xenc\AbstractXencElement
25
 *
26
 * @package simplesamlphp/xml-security
27
 */
28
#[CoversClass(AbstractXencElement::class)]
29
#[CoversClass(Transforms::class)]
30
final class TransformsTest extends TestCase
31
{
32
    use SerializableElementTestTrait;
33
34
35
    /**
36
     */
37
    public static function setUpBeforeClass(): void
38
    {
39
        self::$testedClass = Transforms::class;
40
41
        self::$xmlRepresentation = DOMDocumentFactory::fromFile(
42
            dirname(__FILE__, 3) . '/resources/xml/xenc_Transforms.xml',
43
        );
44
    }
45
46
47
    /**
48
     */
49
    public function testMarshalling(): void
50
    {
51
        $transforms = new Transforms(
52
            [
53
                new Transform(
54
                    C::XPATH10_URI,
55
                    new XPath(
56
                        'count(//. | //@* | //namespace::*)',
57
                    ),
58
                ),
59
            ],
60
        );
61
62
        $this->assertEquals(
63
            self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement),
64
            strval($transforms),
65
        );
66
    }
67
68
69
    /**
70
     * Adding an empty Transforms element should yield an empty element.
71
     */
72
    public function testMarshallingEmptyElement(): void
73
    {
74
        $xenc_ns = Transforms::NS;
75
        $transforms = new Transforms([]);
76
        $this->assertEquals(
77
            "<xenc:Transforms xmlns:xenc=\"$xenc_ns\"/>",
78
            strval($transforms),
79
        );
80
        $this->assertTrue($transforms->isEmptyElement());
81
    }
82
}
83