@@ -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