Skip to content

Commit 2a5c521

Browse files
committed
Add unit tests to verify schema validation
1 parent 27a707e commit 2a5c521

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

tests/XML/DOMDocumentFactoryTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44

55
namespace SimpleSAML\Test\XML;
66

7+
use DOMDocument;
78
use PHPUnit\Framework\Attributes\CoversClass;
89
use PHPUnit\Framework\Attributes\Group;
910
use PHPUnit\Framework\TestCase;
1011
use RuntimeException;
1112
use SimpleSAML\Assert\AssertionFailedException;
1213
use SimpleSAML\XML\DOMDocumentFactory;
14+
use SimpleSAML\XML\Exception\SchemaViolationException;
1315
use SimpleSAML\XML\Exception\UnparseableXMLException;
1416

1517
use function strval;
@@ -114,4 +116,23 @@ public function testEmptyStringIsNotValid(): void
114116
);
115117
DOMDocumentFactory::fromString('');
116118
}
119+
120+
121+
public function testSchemaValidationPasses(): void
122+
{
123+
$file = 'tests/resources/xml/ssp_Chunk.xml';
124+
$schemaFile = 'tests/resources/schemas/simplesamlphp.xsd';
125+
$doc = DOMDocumentFactory::fromFile($file, $schemaFile);
126+
$this->assertInstanceOf(DOMDocument::class, $doc);
127+
}
128+
129+
130+
public function testSchemaValidationWrongElementFails(): void
131+
{
132+
$file = 'tests/resources/xml/ssp_BooleanElement.xml';
133+
$schemaFile = 'tests/resources/schemas/simplesamlphp.xsd';
134+
135+
$this->expectException(SchemaViolationException::class);
136+
DOMDocumentFactory::fromFile($file, $schemaFile);
137+
}
117138
}

tests/resources/xml/ssp_Chunk.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<ssp:Chunk xmlns:ssp="urn:x-simplesamlphp:namespace">Some</ssp:Chunk>

0 commit comments

Comments
 (0)