Skip to content

Commit 6445655

Browse files
author
Paul Bearne
committed
Align array key spacing in iis7RewriteRuleExists() test data for consistency
1 parent 29d33fd commit 6445655

2 files changed

Lines changed: 52 additions & 8 deletions

File tree

tests/phpunit/data/iis/schema.xsd

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
3+
<xs:element name="configuration">
4+
<xs:complexType>
5+
<xs:sequence>
6+
<xs:element name="system.webServer" minOccurs="0">
7+
<xs:complexType>
8+
<xs:sequence>
9+
<xs:element name="rewrite" minOccurs="0">
10+
<xs:complexType>
11+
<xs:sequence>
12+
<xs:element name="rules" minOccurs="0">
13+
<xs:complexType>
14+
<xs:sequence>
15+
<xs:element name="rule" maxOccurs="unbounded" minOccurs="0">
16+
<xs:complexType>
17+
<xs:attribute name="name" type="xs:string" use="required"/>
18+
<xs:anyAttribute processContents="skip"/>
19+
</xs:complexType>
20+
</xs:element>
21+
</xs:sequence>
22+
</xs:complexType>
23+
</xs:element>
24+
</xs:sequence>
25+
</xs:complexType>
26+
</xs:element>
27+
</xs:sequence>
28+
</xs:complexType>
29+
</xs:element>
30+
</xs:sequence>
31+
</xs:complexType>
32+
</xs:element>
33+
</xs:schema>

tests/phpunit/tests/admin/includes/misc/iis7RewriteRuleExists.php

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,22 @@ public function tear_down() {
4545
* @param string $content The XML content of the file.
4646
*/
4747
public function test_iis7_rewrite_rule_exists( $expected, $content ) {
48+
file_put_contents( $this->temp_file, $content );
49+
4850
if ( 'Not XML' === $content ) {
49-
file_put_contents( $this->temp_file, $content );
50-
$this->assertSame( $expected, iis7_rewrite_rule_exists( $this->temp_file ) );
51+
// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
52+
$this->assertSame( $expected, @iis7_rewrite_rule_exists( $this->temp_file ) );
5153
} else {
52-
file_put_contents( $this->temp_file, $content );
54+
$doc = new DOMDocument();
55+
$doc->validateOnParse = true;
56+
57+
// Validate against the schema if it's supposed to be valid XML.
58+
if ( str_starts_with( $content, '<' ) ) {
59+
$doc->loadXML( $content );
60+
$schema_path = DIR_TESTDATA . '/iis/schema.xsd';
61+
$this->assertTrue( $doc->schemaValidate( $schema_path ), 'The XML does not validate against the web.config schema.' );
62+
}
63+
5364
$this->assertSame( $expected, iis7_rewrite_rule_exists( $this->temp_file ) );
5465
}
5566
}
@@ -65,23 +76,23 @@ public function data_iis7_rewrite_rule_exists(): array {
6576
'expected' => true,
6677
'content' => '<configuration><system.webServer><rewrite><rules><rule name="wordpress-rules" /></rules></rewrite></system.webServer></configuration>',
6778
),
68-
'Rule with name "wordpress" exists' => array(
79+
'Rule with name "wordpress" exists' => array(
6980
'expected' => true,
7081
'content' => '<configuration><system.webServer><rewrite><rules><rule name="wordpress" /></rules></rewrite></system.webServer></configuration>',
7182
),
72-
'Rule with name "WordPress" exists' => array(
83+
'Rule with name "WordPress" exists' => array(
7384
'expected' => true,
7485
'content' => '<configuration><system.webServer><rewrite><rules><rule name="WordPress" /></rules></rewrite></system.webServer></configuration>',
7586
),
76-
'Rule does not exist' => array(
87+
'Rule does not exist' => array(
7788
'expected' => false,
7889
'content' => '<configuration><system.webServer><rewrite><rules><rule name="other-rule" /></rules></rewrite></system.webServer></configuration>',
7990
),
80-
'Empty configuration' => array(
91+
'Empty configuration' => array(
8192
'expected' => false,
8293
'content' => '<configuration />',
8394
),
84-
'Invalid XML' => array(
95+
'Invalid XML' => array(
8596
'expected' => false,
8697
'content' => 'Not XML',
8798
),

0 commit comments

Comments
 (0)