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

ObjectTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 27
c 1
b 0
f 1
dl 0
loc 58
rs 10
wmc 3
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\Chunk;
10
use SimpleSAML\XML\DOMDocumentFactory;
11
use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait;
12
use SimpleSAML\XML\TestUtils\SerializableElementTestTrait;
13
use SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement;
14
use SimpleSAML\XMLSecurity\XML\ds\DsObject;
15
16
/**
17
 * Class \SimpleSAML\XMLSecurity\XML\Test\ds\ObjectTest
18
 *
19
 * @package simplesamlphp/xml-security
20
 */
21
#[CoversClass(AbstractDsElement::class)]
22
#[CoversClass(DsObject::class)]
23
final class ObjectTest extends TestCase
24
{
25
    use SchemaValidationTestTrait;
26
    use SerializableElementTestTrait;
27
28
29
    /**
30
     */
31
    public static function setUpBeforeClass(): void
32
    {
33
        self::$testedClass = DsObject::class;
34
35
        self::$xmlRepresentation = DOMDocumentFactory::fromFile(
36
            dirname(__FILE__, 3) . '/resources/xml/ds_Object.xml',
37
        );
38
    }
39
40
41
    /**
42
     */
43
    public function testMarshalling(): void
44
    {
45
        $img = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=';
46
        $obj = new DsObject(
47
            'abc123',
48
            'image/png',
49
            'http://www.w3.org/2000/09/xmldsig#base64',
50
            [
51
                new Chunk(
52
                    DOMDocumentFactory::fromString(sprintf(
53
                        '<ssp:data xmlns:ssp="urn:ssp:custom">%s</ssp:data>',
54
                        $img,
55
                    ))->documentElement,
56
                ),
57
            ],
58
        );
59
60
        $this->assertEquals(
61
            self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement),
62
            strval($obj),
63
        );
64
    }
65
66
67
    /**
68
     * Adding an empty Object-element should yield an empty element.
69
     */
70
    public function testMarshallingEmptyElement(): void
71
    {
72
        $ds_ns = DsObject::NS;
73
        $obj = new DsObject(null, null, null, []);
74
        $this->assertEquals(
75
            "<ds:Object xmlns:ds=\"$ds_ns\"/>",
76
            strval($obj),
77
        );
78
        $this->assertTrue($obj->isEmptyElement());
79
    }
80
}
81