|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace SimpleSAML\XSD\Test\XML\xsd; |
| 6 | + |
| 7 | +use DOMText; |
| 8 | +use PHPUnit\Framework\Attributes\{CoversClass, Group}; |
| 9 | +use PHPUnit\Framework\TestCase; |
| 10 | +use SimpleSAML\XML\Attribute as XMLAttribute; |
| 11 | +use SimpleSAML\XML\Constants as C; |
| 12 | +use SimpleSAML\XML\DOMDocumentFactory; |
| 13 | +use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; |
| 14 | +use SimpleSAML\XML\Type\{AnyURIValue, IDValue, NCNameValue, StringValue, QNameValue}; |
| 15 | +use SimpleSAML\XSD\Type\{MinOccursValue, MaxOccursValue, NamespaceListValue, ProcessContentsValue}; |
| 16 | +use SimpleSAML\XSD\XML\xsd\AbstractAnnotated; |
| 17 | +use SimpleSAML\XSD\XML\xsd\AbstractGroup; |
| 18 | +use SimpleSAML\XSD\XML\xsd\AbstractRealGroup; |
| 19 | +use SimpleSAML\XSD\XML\xsd\AbstractOpenAttrs; |
| 20 | +use SimpleSAML\XSD\XML\xsd\AbstractXsdElement; |
| 21 | +use SimpleSAML\XSD\XML\xsd\Annotation; |
| 22 | +use SimpleSAML\XSD\XML\xsd\Appinfo; |
| 23 | +use SimpleSAML\XSD\XML\xsd\Sequence; |
| 24 | +use SimpleSAML\XSD\XML\xsd\Documentation; |
| 25 | +use SimpleSAML\XSD\XML\xsd\ReferencedGroup; |
| 26 | + |
| 27 | +use function dirname; |
| 28 | +use function strval; |
| 29 | + |
| 30 | +/** |
| 31 | + * Tests for xs:sequence |
| 32 | + * |
| 33 | + * @package simplesamlphp/xml-xsd |
| 34 | + */ |
| 35 | +#[Group('xs')] |
| 36 | +#[CoversClass(Sequence::class)] |
| 37 | +#[CoversClass(AbstractRealGroup::class)] |
| 38 | +#[CoversClass(AbstractGroup::class)] |
| 39 | +#[CoversClass(AbstractAnnotated::class)] |
| 40 | +#[CoversClass(AbstractOpenAttrs::class)] |
| 41 | +#[CoversClass(AbstractXsdElement::class)] |
| 42 | +final class SequenceTest extends TestCase |
| 43 | +{ |
| 44 | + use SerializableElementTestTrait; |
| 45 | + |
| 46 | + |
| 47 | + /** |
| 48 | + */ |
| 49 | + public static function setUpBeforeClass(): void |
| 50 | + { |
| 51 | + self::$testedClass = SequenceGroup::class; |
| 52 | + |
| 53 | + self::$xmlRepresentation = DOMDocumentFactory::fromFile( |
| 54 | + dirname(__FILE__, 3) . '/resources/xml/sequence.xml', |
| 55 | + ); |
| 56 | + } |
| 57 | + |
| 58 | + |
| 59 | + // test marshalling |
| 60 | + |
| 61 | + |
| 62 | + /** |
| 63 | + * Test creating an Sequence object from scratch. |
| 64 | + */ |
| 65 | + public function testMarshalling(): void |
| 66 | + { |
| 67 | + $appinfoDocument = DOMDocumentFactory::create(); |
| 68 | + $text = new DOMText('Application Information'); |
| 69 | + $appinfoDocument->appendChild($text); |
| 70 | + |
| 71 | + $otherAppinfoDocument = DOMDocumentFactory::create(); |
| 72 | + $otherText = new DOMText('Other Application Information'); |
| 73 | + $otherAppinfoDocument->appendChild($otherText); |
| 74 | + |
| 75 | + $documentationDocument = DOMDocumentFactory::create(); |
| 76 | + $text = new DOMText('Some Documentation'); |
| 77 | + $documentationDocument->appendChild($text); |
| 78 | + |
| 79 | + $otherDocumentationDocument = DOMDocumentFactory::create(); |
| 80 | + $text = new DOMText('Other Documentation'); |
| 81 | + $otherDocumentationDocument->appendChild($text); |
| 82 | + |
| 83 | + $attr1 = new XMLAttribute('urn:x-simplesamlphp:namespace', 'ssp', 'attr1', StringValue::fromString('value1')); |
| 84 | + $attr2 = new XMLAttribute('urn:x-simplesamlphp:namespace', 'ssp', 'attr2', StringValue::fromString('value2')); |
| 85 | + $attr3 = new XMLAttribute('urn:x-simplesamlphp:namespace', 'ssp', 'attr3', StringValue::fromString('value3')); |
| 86 | + $attr4 = new XMLAttribute('urn:x-simplesamlphp:namespace', 'ssp', 'attr4', StringValue::fromString('value4')); |
| 87 | + $langattr = new XMLAttribute(C::NS_XML, 'xml', 'lang', StringValue::fromString('nl')); |
| 88 | + |
| 89 | + $appinfo1 = new Appinfo( |
| 90 | + $appinfoDocument->childNodes, |
| 91 | + AnyURIValue::fromString('urn:x-simplesamlphp:source'), |
| 92 | + [$attr1], |
| 93 | + ); |
| 94 | + $appinfo2 = new Appinfo( |
| 95 | + $otherAppinfoDocument->childNodes, |
| 96 | + AnyURIValue::fromString('urn:x-simplesamlphp:source'), |
| 97 | + [$attr2], |
| 98 | + ); |
| 99 | + |
| 100 | + $documentation1 = new Documentation( |
| 101 | + $documentationDocument->childNodes, |
| 102 | + $langattr, |
| 103 | + AnyURIValue::fromString('urn:x-simplesamlphp:source'), |
| 104 | + [$attr1], |
| 105 | + ); |
| 106 | + $documentation2 = new Documentation( |
| 107 | + $otherDocumentationDocument->childNodes, |
| 108 | + $langattr, |
| 109 | + AnyURIValue::fromString('urn:x-simplesamlphp:source'), |
| 110 | + [$attr2], |
| 111 | + ); |
| 112 | + |
| 113 | + $annotation = new Annotation( |
| 114 | + [$appinfo1, $appinfo2], |
| 115 | + [$documentation1, $documentation2], |
| 116 | + IDValue::fromString('phpunit_annotation'), |
| 117 | + [$attr3], |
| 118 | + ); |
| 119 | + |
| 120 | + $referencedGroup = new ReferencedGroup( |
| 121 | + QNameValue::fromString("{http://www.w3.org/2001/XMLSchema}xsd:nestedParticle"), |
| 122 | + ); |
| 123 | + |
| 124 | + $sequence = new Sequence( |
| 125 | + MinOccursValue::fromInteger(0), |
| 126 | + MaxOccursValue::fromString('unbounded'), |
| 127 | + [$referencedGroup], |
| 128 | + $annotation, |
| 129 | + IDValue::fromString('phpunit_sequence'), |
| 130 | + [$attr4], |
| 131 | + ); |
| 132 | + |
| 133 | + $this->assertEquals( |
| 134 | + self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), |
| 135 | + strval($sequence), |
| 136 | + ); |
| 137 | + } |
| 138 | +} |
0 commit comments