Skip to content

MQE-1118: Handle XML merge failures gracefully #202

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
namespace Tests\unit\Magento\FunctionalTestFramework\Test\Config;

use Magento\FunctionalTestingFramework\Exceptions\Collector\ExceptionCollector;
use Magento\FunctionalTestingFramework\Config\Dom\ValidationException;
use Magento\FunctionalTestingFramework\Test\Config\ActionGroupDom;
use Magento\FunctionalTestingFramework\Util\MagentoTestCase;

Expand All @@ -29,4 +30,21 @@ public function testActionGroupDomStepKeyValidation()
$this->expectException(\Exception::class);
$exceptionCollector->throwException();
}

/**
* Test Action Group invalid XML
*/
public function testActionGroupDomInvalidXmlValidation()
{
$sampleXml = "<actionGroups>
<actionGroup name=\"sampleActionGroup\">
<wait>
</actionGroup>
</actionGroups>";

$exceptionCollector = new ExceptionCollector();
$this->expectException(ValidationException::class);
$this->expectExceptionMessage("XML Parse Error: invalid.xml\n");
new ActionGroupDom($sampleXml, 'invalid.xml', $exceptionCollector);
}
}
14 changes: 12 additions & 2 deletions src/Magento/FunctionalTestingFramework/Config/Dom.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

namespace Magento\FunctionalTestingFramework\Config;

use Magento\FunctionalTestingFramework\Config\Dom\ValidationException;

/**
* Magento configuration XML DOM utility
*/
Expand Down Expand Up @@ -354,13 +356,21 @@ public function getDom()
* Create DOM document based on $xml parameter
*
* @param string $xml
* @param string $filename
* @return \DOMDocument
* @throws \Magento\FunctionalTestingFramework\Config\Dom\ValidationException
*/
protected function initDom($xml)
protected function initDom($xml, $filename = null)
{
$dom = new \DOMDocument();
$dom->loadXML($xml);
try {
$domSuccess = $dom->loadXML($xml);
if (!$domSuccess) {
throw new \Exception();
}
} catch (\Exception $exception) {
throw new ValidationException("XML Parse Error: $filename\n");
}
if ($this->schemaFile) {
$errors = self::validateDomDocument($dom, $this->schemaFile, $this->errorFormat);
if (count($errors)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function __construct(
*/
public function initDom($xml, $filename = null)
{
$dom = parent::initDom($xml);
$dom = parent::initDom($xml, $filename);

if (strpos($filename, self::DATA_FILE_NAME_ENDING)) {
$entityNodes = $dom->getElementsByTagName('entity');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function __construct(
*/
public function initDom($xml, $filename = null)
{
$dom = parent::initDom($xml);
$dom = parent::initDom($xml, $filename);

if (strpos($filename, self::METADATA_FILE_NAME_ENDING)) {
$operationNodes = $dom->getElementsByTagName('operation');
Expand Down
2 changes: 1 addition & 1 deletion src/Magento/FunctionalTestingFramework/Page/Config/Dom.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function __construct(
*/
public function initDom($xml, $filename = null)
{
$dom = parent::initDom($xml);
$dom = parent::initDom($xml, $filename);

$pagesNode = $dom->getElementsByTagName('pages')->item(0);
$this->validationUtil->validateChildUniqueness($pagesNode, $filename);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function __construct(
*/
public function initDom($xml, $filename = null)
{
$dom = parent::initDom($xml);
$dom = parent::initDom($xml, $filename);
$sectionNodes = $dom->getElementsByTagName('section');
foreach ($sectionNodes as $sectionNode) {
$sectionNode->setAttribute(self::SECTION_META_FILENAME_ATTRIBUTE, $filename);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ActionGroupDom extends Dom
*/
public function initDom($xml, $filename = null)
{
$dom = parent::initDom($xml);
$dom = parent::initDom($xml, $filename);

if (strpos($filename, self::ACTION_GROUP_FILE_NAME_ENDING)) {
$actionGroupNodes = $dom->getElementsByTagName('actionGroup');
Expand Down
2 changes: 1 addition & 1 deletion src/Magento/FunctionalTestingFramework/Test/Config/Dom.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function __construct(
*/
public function initDom($xml, $filename = null)
{
$dom = parent::initDom($xml);
$dom = parent::initDom($xml, $filename);

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