diff options
author | Stefan Giehl <stefan@piwik.org> | 2017-11-20 00:13:40 +0300 |
---|---|---|
committer | Matthieu Aubry <mattab@users.noreply.github.com> | 2017-11-20 00:13:40 +0300 |
commit | 113ca8962fce945222236aa3b228a6385e870cde (patch) | |
tree | d66175ba2288680b3f8786845e639a2a7c448669 /tests/PHPUnit | |
parent | 89569c9c6f223456c0139f41add2e941b2368c55 (diff) |
check for valid xml (#12247)
Diffstat (limited to 'tests/PHPUnit')
-rwxr-xr-x | tests/PHPUnit/Framework/TestCase/SystemTestCase.php | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/PHPUnit/Framework/TestCase/SystemTestCase.php b/tests/PHPUnit/Framework/TestCase/SystemTestCase.php index 3048352b43..125ca9ed20 100755 --- a/tests/PHPUnit/Framework/TestCase/SystemTestCase.php +++ b/tests/PHPUnit/Framework/TestCase/SystemTestCase.php @@ -316,6 +316,11 @@ abstract class SystemTestCase extends PHPUnit_Framework_TestCase $processedResponse->save($processedFilePath); } + $response = $processedResponse->getResponseText(); + if (strpos($response, '<?xml') === 0) { + $this->assertValidXML($response); + } + try { $expectedResponse = Response::loadFromFile($expectedFilePath, $options, $requestParams); } catch (Exception $ex) { @@ -333,6 +338,22 @@ abstract class SystemTestCase extends PHPUnit_Framework_TestCase $this->printApiTestFailures(); } + protected function assertValidXML($xml) + { + libxml_use_internal_errors(true); + $sxe = simplexml_load_string($xml); + + if ($sxe === false) { + $errors = []; + foreach (libxml_get_errors() as $error) { + $errors[] = trim($error->message) . ' @' . $error->line . ':' . $error->column; + } + static::fail('Response is no valid xml: ' . implode("\n", $errors)); + } + + libxml_clear_errors(); + } + /** * @param $requestUrl * @return string @@ -361,6 +382,11 @@ abstract class SystemTestCase extends PHPUnit_Framework_TestCase $processedResponse->save($processedFilePath); } + $response = $processedResponse->getResponseText(); + if (strpos($response, '<?xml') === 0) { + $this->assertValidXML($response); + } + $_GET = $originalGET; try { |