Skip to content

Commit 0ef90bf

Browse files
committed
Default v1 and UTF-8
1 parent 3c8c8d9 commit 0ef90bf

4 files changed

Lines changed: 17 additions & 27 deletions

File tree

tests/src/SimpleSAML/Metadata/SAMLParserTest.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -219,12 +219,9 @@ public function testAttributeConsumingServiceParsing(): void
219219
/**
220220
* @return \DOMDocument
221221
*/
222-
public function makeTestDocument(): \DOMDocument
222+
public function makeTestDocument(): DOMDocument
223223
{
224-
$doc = new DOMDocument();
225-
$doc->loadXML(
226-
<<<XML
227-
<?xml version="1.0"?>
224+
$doc = DOMDocumentFactory::fromString(<<<XML
228225
<EntitiesDescriptor xmlns="urn:oasis:names:tc:SAML:2.0:metadata">
229226
<EntityDescriptor entityID="theEntityID">
230227
<SPSSODescriptor protocolSupportEnumeration="urn:oasis:names:tc:SAML:2.0:protocol"/>

tests/src/SimpleSAML/Utils/XMLTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use DOMText;
1212
use InvalidArgumentException;
1313
use PHPUnit\Framework\TestCase;
14+
use SAML2\DOMDocumentFactory;
1415
use SimpleSAML\Configuration;
1516
use SimpleSAML\Error;
1617
use SimpleSAML\Utils;
@@ -291,12 +292,11 @@ public function testIsValidMetadata(): void
291292
{
292293
$xmlUtils = new Utils\XML();
293294

294-
$schema = 'saml-schema-metadata-2.0.xsd';
295-
$xml = file_get_contents(self::FRAMEWORK . '/metadata/valid-metadata-selfsigned.xml');
296-
297-
$dom = new DOMDocument('1.0');
298-
$dom->loadXML($xml, LIBXML_NONET);
295+
$dom = DOMDocumentFactory::fromFile(
296+
self::FRAMEWORK . '/metadata/valid-metadata-selfsigned.xml',
297+
);
299298

299+
$schema = 'saml-schema-metadata-2.0.xsd';
300300
$res = $xmlUtils->isValid($dom, $schema);
301301
$this->assertTrue($res === true);
302302
}

tests/src/SimpleSAML/XML/SignerTest.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use org\bovigo\vfs\vfsStream;
1111
use PHPUnit\Framework\TestCase;
1212
use ReflectionClass;
13+
use SAML2\DOMDocumentFactory;
1314
use SimpleSAML\Configuration;
1415
use SimpleSAML\Test\SigningTestCase;
1516
use SimpleSAML\XML\Signer;
@@ -80,8 +81,7 @@ public function testSignerBasic(): void
8081
*/
8182
public function testSignBasic(): void
8283
{
83-
$node = new DOMDocument();
84-
$node->loadXML('<?xml version="1.0"?><node>value</node>');
84+
$node = DOMDocumentFactory::fromString('<node>value</node>');
8585

8686
/** @psalm-var DOMElement $element */
8787
$element = $node->getElementsByTagName("node")->item(0);
@@ -120,8 +120,7 @@ private static function getCertificateValue(string $certificate): string
120120
*/
121121
public function testSignWithCertificate(): void
122122
{
123-
$node = new DOMDocument();
124-
$node->loadXML('<?xml version="1.0"?><node>value</node>');
123+
$node = DOMDocumentFactory::fromString('<node>value</node>');
125124

126125
/** @psalm-var DOMElement $element */
127126
$element = $node->getElementsByTagName("node")->item(0);
@@ -149,8 +148,7 @@ public function testSignWithMultiCertificate(): void
149148
{
150149
$this->other_certificate_file = $this->certdir . DIRECTORY_SEPARATOR . self::OTHER_CERTIFICATE;
151150

152-
$node = new DOMDocument();
153-
$node->loadXML('<?xml version="1.0"?><node>value</node>');
151+
$node = DOMDocumentFactory::fromString('<node>value</node>');
154152

155153
/** @psalm-var DOMElement $element */
156154
$element = $node->getElementsByTagName("node")->item(0);
@@ -179,8 +177,7 @@ public function testSignWithMultiCertificate(): void
179177
*/
180178
public function testSignMissingPrivateKey(): void
181179
{
182-
$node = new DOMDocument();
183-
$node->loadXML('<?xml version="1.0"?><node>value</node>');
180+
$node = DOMDocumentFactory::fromString('<node>value</node>');
184181

185182
/** @psalm-var DOMElement $element */
186183
$element = $node->getElementsByTagName("node")->item(0);

tests/src/SimpleSAML/XML/ValidatorTest.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
namespace SimpleSAML\Test\XML;
66

7-
use DOMDocument;
87
use DOMElement;
98
use Exception;
109
use org\bovigo\vfs\vfsStream;
1110
use PHPUnit\Framework\TestCase;
11+
use SAML2\DOMDocumentFactory;
1212
use SimpleSAML\Test\SigningTestCase;
1313
use SimpleSAML\XML\Signer;
1414
use SimpleSAML\XML\Validator;
@@ -24,8 +24,7 @@ class ValidatorTest extends SigningTestCase
2424
*/
2525
public function testValidatorMissingSignature(): void
2626
{
27-
$doc = new DOMDocument();
28-
$doc->loadXML('<?xml version="1.0"?><node>value</node>');
27+
$doc = DOMDocumentFactory::fromString('<node>value</node>');
2928

3029
$this->expectException(Exception::class);
3130
new Validator($doc);
@@ -36,8 +35,7 @@ public function testValidatorMissingSignature(): void
3635
*/
3736
public function testGetX509Certificate(): void
3837
{
39-
$doc = new DOMDocument();
40-
$doc->loadXML('<?xml version="1.0"?><node>value</node>');
38+
$doc = DOMDocumentFactory::fromString('<node>value</node>');
4139

4240
/** @psalm-var DOMElement $node */
4341
$node = $doc->getElementsByTagName('node')->item(0);
@@ -64,8 +62,7 @@ public function testGetX509Certificate(): void
6462
*/
6563
public function testIsNodeValidatedSuccess(): void
6664
{
67-
$doc = new DOMDocument();
68-
$doc->loadXML('<?xml version="1.0"?><node>value</node>');
65+
$doc = DOMDocumentFactory::fromString('<node>value</node>');
6966

7067
/** @psalm-var DOMElement $node */
7168
$node = $doc->getElementsByTagName('node')->item(0);
@@ -92,8 +89,7 @@ public function testIsNodeValidatedSuccess(): void
9289
*/
9390
public function testIsNodeValidatedFailure(): void
9491
{
95-
$doc = new DOMDocument();
96-
$doc->loadXML('<?xml version="1.0"?><parent><node1>value1</node1><node2>value2</node2></parent>');
92+
$doc = DOMDocumentFactory::fromString('<parent><node1>value1</node1><node2>value2</node2></parent>');
9793

9894
/** @psalm-var DOMElement $node1 */
9995
$node1 = $doc->getElementsByTagName('node1')->item(0);

0 commit comments

Comments
 (0)