Skip to content

Commit 7610008

Browse files
authored
MQE-1118: Handle XML merge failures gracefully (magento#202)
* MQE-1118: Handle XML merge failures gracefully - Added filename to error messages for loadXML usage in initDom * MQE-1118: Handle XML merge failures gracefully - Added Test and made error a tiny bit more specific (error is caught by child classes given context) * MQE-1118: Handle XML merge failures gracefully - Added exception message check in unit test * MQE-1118: Handle XML merge failures gracefully - Added check for false returns from loadXML
1 parent 229b66e commit 7610008

File tree

8 files changed

+36
-8
lines changed

8 files changed

+36
-8
lines changed

dev/tests/unit/Magento/FunctionalTestFramework/Test/Config/ActionGroupDomTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace Tests\unit\Magento\FunctionalTestFramework\Test\Config;
77

88
use Magento\FunctionalTestingFramework\Exceptions\Collector\ExceptionCollector;
9+
use Magento\FunctionalTestingFramework\Config\Dom\ValidationException;
910
use Magento\FunctionalTestingFramework\Test\Config\ActionGroupDom;
1011
use Magento\FunctionalTestingFramework\Util\MagentoTestCase;
1112

@@ -29,4 +30,21 @@ public function testActionGroupDomStepKeyValidation()
2930
$this->expectException(\Exception::class);
3031
$exceptionCollector->throwException();
3132
}
33+
34+
/**
35+
* Test Action Group invalid XML
36+
*/
37+
public function testActionGroupDomInvalidXmlValidation()
38+
{
39+
$sampleXml = "<actionGroups>
40+
<actionGroup name=\"sampleActionGroup\">
41+
<wait>
42+
</actionGroup>
43+
</actionGroups>";
44+
45+
$exceptionCollector = new ExceptionCollector();
46+
$this->expectException(ValidationException::class);
47+
$this->expectExceptionMessage("XML Parse Error: invalid.xml\n");
48+
new ActionGroupDom($sampleXml, 'invalid.xml', $exceptionCollector);
49+
}
3250
}

src/Magento/FunctionalTestingFramework/Config/Dom.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
namespace Magento\FunctionalTestingFramework\Config;
88

9+
use Magento\FunctionalTestingFramework\Config\Dom\ValidationException;
10+
911
/**
1012
* Magento configuration XML DOM utility
1113
*/
@@ -354,13 +356,21 @@ public function getDom()
354356
* Create DOM document based on $xml parameter
355357
*
356358
* @param string $xml
359+
* @param string $filename
357360
* @return \DOMDocument
358361
* @throws \Magento\FunctionalTestingFramework\Config\Dom\ValidationException
359362
*/
360-
protected function initDom($xml)
363+
protected function initDom($xml, $filename = null)
361364
{
362365
$dom = new \DOMDocument();
363-
$dom->loadXML($xml);
366+
try {
367+
$domSuccess = $dom->loadXML($xml);
368+
if (!$domSuccess) {
369+
throw new \Exception();
370+
}
371+
} catch (\Exception $exception) {
372+
throw new ValidationException("XML Parse Error: $filename\n");
373+
}
364374
if ($this->schemaFile) {
365375
$errors = self::validateDomDocument($dom, $this->schemaFile, $this->errorFormat);
366376
if (count($errors)) {

src/Magento/FunctionalTestingFramework/DataGenerator/Config/Dom.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function __construct(
6565
*/
6666
public function initDom($xml, $filename = null)
6767
{
68-
$dom = parent::initDom($xml);
68+
$dom = parent::initDom($xml, $filename);
6969

7070
if (strpos($filename, self::DATA_FILE_NAME_ENDING)) {
7171
$entityNodes = $dom->getElementsByTagName('entity');

src/Magento/FunctionalTestingFramework/DataGenerator/Config/OperationDom.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function __construct(
6565
*/
6666
public function initDom($xml, $filename = null)
6767
{
68-
$dom = parent::initDom($xml);
68+
$dom = parent::initDom($xml, $filename);
6969

7070
if (strpos($filename, self::METADATA_FILE_NAME_ENDING)) {
7171
$operationNodes = $dom->getElementsByTagName('operation');

src/Magento/FunctionalTestingFramework/Page/Config/Dom.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public function __construct(
7676
*/
7777
public function initDom($xml, $filename = null)
7878
{
79-
$dom = parent::initDom($xml);
79+
$dom = parent::initDom($xml, $filename);
8080

8181
$pagesNode = $dom->getElementsByTagName('pages')->item(0);
8282
$this->validationUtil->validateChildUniqueness($pagesNode, $filename);

src/Magento/FunctionalTestingFramework/Page/Config/SectionDom.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function __construct(
6767
*/
6868
public function initDom($xml, $filename = null)
6969
{
70-
$dom = parent::initDom($xml);
70+
$dom = parent::initDom($xml, $filename);
7171
$sectionNodes = $dom->getElementsByTagName('section');
7272
foreach ($sectionNodes as $sectionNode) {
7373
$sectionNode->setAttribute(self::SECTION_META_FILENAME_ATTRIBUTE, $filename);

src/Magento/FunctionalTestingFramework/Test/Config/ActionGroupDom.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class ActionGroupDom extends Dom
2626
*/
2727
public function initDom($xml, $filename = null)
2828
{
29-
$dom = parent::initDom($xml);
29+
$dom = parent::initDom($xml, $filename);
3030

3131
if (strpos($filename, self::ACTION_GROUP_FILE_NAME_ENDING)) {
3232
$actionGroupNodes = $dom->getElementsByTagName('actionGroup');

src/Magento/FunctionalTestingFramework/Test/Config/Dom.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function __construct(
7979
*/
8080
public function initDom($xml, $filename = null)
8181
{
82-
$dom = parent::initDom($xml);
82+
$dom = parent::initDom($xml, $filename);
8383

8484
if (strpos($filename, self::TEST_FILE_NAME_ENDING)) {
8585
$testNodes = $dom->getElementsByTagName('test');

0 commit comments

Comments
 (0)