Passed
Pull Request — master (#60)
by Tim
02:12
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, Group};
8
use PHPUnit\Framework\TestCase;
9
use SimpleSAML\XML\DOMDocumentFactory;
10
use SimpleSAML\XML\TestUtils\SerializableElementTestTrait;
11
use SimpleSAML\XML\Type\{AnyURIValue, StringValue};
12
use SimpleSAML\XMLSecurity\Constants as C;
13
use SimpleSAML\XMLSecurity\XML\ds\{Transform, XPath};
14
use SimpleSAML\XMLSecurity\XML\xenc\{AbstractXencElement, Transforms};
15
16
use function dirname;
17
use function strval;
18
19
/**
20
 * Class \SimpleSAML\XMLSecurity\Test\XML\xenc\TransformsTest
21
 *
22
 * @covers \SimpleSAML\XMLSecurity\XML\xenc\Transforms
23
 * @covers \SimpleSAML\XMLSecurity\XML\xenc\AbstractXencElement
24
 *
25
 * @package simplesamlphp/xml-security
26
 */
27
#[Group('xenc')]
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
                    AnyURIValue::fromString(C::XPATH10_URI),
55
                    new XPath(
56
                        StringValue::fromString('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