forked from simplesamlphp/xml-common
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSchemaValidatableElementTraitTest.php
More file actions
62 lines (48 loc) · 1.81 KB
/
SchemaValidatableElementTraitTest.php
File metadata and controls
62 lines (48 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
declare(strict_types=1);
namespace SimpleSAML\Test\XML;
use DOMDocument;
use PHPUnit\Framework\TestCase;
use SimpleSAML\Test\Helper\Base64BinaryElement;
use SimpleSAML\Test\Helper\BooleanElement;
use SimpleSAML\Test\Helper\StringElement;
use SimpleSAML\XML\DOMDocumentFactory;
use SimpleSAML\XML\Exception\IOException;
use SimpleSAML\XMLSchema\Exception\SchemaViolationException;
/**
* Class \SimpleSAML\XML\SchemaValidatableElementTraitTest
*
* @package simplesamlphp\xml-common
*/
final class SchemaValidatableElementTraitTest extends TestCase
{
public function testSchemaValidationPasses(): void
{
$file = 'tests/resources/xml/ssp_StringElement.xml';
$chunk = DOMDocumentFactory::fromFile($file);
$document = StringElement::schemaValidate($chunk);
// @phpstan-ignore-next-line
$this->assertInstanceOf(DOMDocument::class, $document);
}
public function testSchemaValidationFails(): void
{
$file = 'tests/resources/xml/invalid_ExtendableElement.xml';
$chunk = DOMDocumentFactory::fromFile($file);
$this->expectException(SchemaViolationException::class);
$document = StringElement::schemaValidate($chunk);
}
public function testSchemaValidationWrongElementFails(): void
{
$file = 'tests/resources/xml/ssp_Base64BinaryElement.xml';
$chunk = DOMDocumentFactory::fromFile($file);
$this->expectException(SchemaViolationException::class);
BooleanElement::schemaValidate($chunk);
}
public function testSchemaValidationUnknownSchemaFileFails(): void
{
$file = 'tests/resources/xml/ssp_Base64BinaryElement.xml';
$chunk = DOMDocumentFactory::fromFile($file);
$this->expectException(IOException::class);
Base64BinaryElement::schemaValidate($chunk);
}
}