From ab24aa52250cb5689c3fe807a947664548086463 Mon Sep 17 00:00:00 2001 From: Asis Pattisahusiwa <79239132+asispts@users.noreply.github.com> Date: Wed, 29 Jan 2025 06:57:26 +0700 Subject: [PATCH] Update tests related to libxml2 --- .../ProcessRulesetBrokenRulesetTest.php | 62 ++++++++++++++++++- 1 file changed, 59 insertions(+), 3 deletions(-) diff --git a/tests/Core/Ruleset/ProcessRulesetBrokenRulesetTest.php b/tests/Core/Ruleset/ProcessRulesetBrokenRulesetTest.php index 9e16f83892..483ccaa252 100644 --- a/tests/Core/Ruleset/ProcessRulesetBrokenRulesetTest.php +++ b/tests/Core/Ruleset/ProcessRulesetBrokenRulesetTest.php @@ -36,11 +36,15 @@ final class ProcessRulesetBrokenRulesetTest extends AbstractRulesetTestCase */ public function testBrokenRulesetEmptyFile() { + if (version_compare(LIBXML_DOTTED_VERSION, '2.12.0', '>=') === false) { + $this->markTestSkipped('Test requires libxml2 2.12.0 or higher'); + } + $standard = __DIR__.'/ProcessRulesetBrokenRulesetEmptyFileTest.xml'; $config = new ConfigDouble(["--standard=$standard"]); $regex = '`^Ruleset \S+ProcessRulesetBrokenRulesetEmptyFileTest\.xml is not valid\R'; - $regex .= '(- On line 1, column 1: Document is empty\R)?$`'; + $regex .= '- On line 1, column 1: Document is empty\R$`'; $this->expectRuntimeExceptionRegex($regex); @@ -49,6 +53,29 @@ public function testBrokenRulesetEmptyFile() }//end testBrokenRulesetEmptyFile() + /** + * Test displaying an informative error message when an empty XML ruleset file is encountered. + * + * @return void + */ + public function testBrokenRulesetEmptyFileWithOldLibxml2() + { + if (version_compare(LIBXML_DOTTED_VERSION, '2.12.0', '<') === false) { + $this->markTestSkipped('Test requires libxml2 < 2.12.0'); + } + + $standard = __DIR__.'/ProcessRulesetBrokenRulesetEmptyFileTest.xml'; + $config = new ConfigDouble(["--standard=$standard"]); + + $regex = '`^Ruleset \S+ProcessRulesetBrokenRulesetEmptyFileTest\.xml is not valid\R$`'; + + $this->expectRuntimeExceptionRegex($regex); + + new Ruleset($config); + + }//end testBrokenRulesetEmptyFileWithOldLibxml2() + + /** * Test displaying an informative error message for a broken XML ruleset with a single XML error. * @@ -76,13 +103,16 @@ public function testBrokenRulesetSingleError() */ public function testBrokenRulesetMultiError() { + if (version_compare(LIBXML_DOTTED_VERSION, '2.12.0', '>=') === false) { + $this->markTestSkipped('Test requires libxml2 >= v2.12.0'); + } + $standard = __DIR__.'/ProcessRulesetBrokenRulesetMultiErrorTest.xml'; $config = new ConfigDouble(["--standard=$standard"]); $regex = '`^Ruleset \S+ProcessRulesetBrokenRulesetMultiErrorTest\.xml is not valid\R'; $regex .= '- On line 8, column 12: Opening and ending tag mismatch: property line 7 and rule\R'; - $regex .= '- On line 10, column 11: Opening and ending tag mismatch: properties line 5 and ruleset\R'; - $regex .= '(- On line 11, column 1: Premature end of data in tag rule line 4\R)?$`'; + $regex .= '- On line 10, column 11: Opening and ending tag mismatch: properties line 5 and ruleset\R$`'; $this->expectRuntimeExceptionRegex($regex); @@ -91,4 +121,30 @@ public function testBrokenRulesetMultiError() }//end testBrokenRulesetMultiError() + /** + * Test displaying an informative error message for a broken XML ruleset with multiple XML errors. + * + * @return void + */ + public function testBrokenRulesetMultiErrorWithOldLibxml2() + { + if (version_compare(LIBXML_DOTTED_VERSION, '2.12.0', '<') === false) { + $this->markTestSkipped('Test requires libxml2 < v2.12.0'); + } + + $standard = __DIR__.'/ProcessRulesetBrokenRulesetMultiErrorTest.xml'; + $config = new ConfigDouble(["--standard=$standard"]); + + $regex = '`^Ruleset \S+ProcessRulesetBrokenRulesetMultiErrorTest\.xml is not valid\R'; + $regex .= '- On line 8, column 12: Opening and ending tag mismatch: property line 7 and rule\R'; + $regex .= '- On line 10, column 11: Opening and ending tag mismatch: properties line 5 and ruleset\R'; + $regex .= '- On line 11, column 1: Premature end of data in tag rule line 4\R$`'; + + $this->expectRuntimeExceptionRegex($regex); + + new Ruleset($config); + + }//end testBrokenRulesetMultiErrorWithOldLibxml2() + + }//end class