Skip to content

Commit a3bb056

Browse files
committed
MQE-790: Error for duplicate step keys in a single action group definition
- add new ActionGroup DOM for stepKey validation - update ActionGroup di.xml config to use new DOM - add unit test -fix verification test
1 parent 5fe3796 commit a3bb056

File tree

7 files changed

+85
-10
lines changed

7 files changed

+85
-10
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Tests\unit\Magento\FunctionalTestFramework\Test\Config;
7+
8+
use Magento\FunctionalTestingFramework\Exceptions\XmlException;
9+
use Magento\FunctionalTestingFramework\Test\Config\ActionGroupDom;
10+
use PHPUnit\Framework\TestCase;
11+
12+
class ActionGroupDomTest extends TestCase
13+
{
14+
/**
15+
* Test Action Group duplicate step key validation
16+
*/
17+
public function testActionGroupDomStepKeyValidation()
18+
{
19+
$sampleXml = "<actionGroups>
20+
<actionGroup name=\"actionGroupWithoutArguments\">
21+
<wait time=\"1\" stepKey=\"waitForNothing\" />
22+
<wait time=\"2\" stepKey=\"waitForNothing\" />
23+
</actionGroup>
24+
</actionGroups>";
25+
26+
$actionDom = new ActionGroupDom($sampleXml, 'test.xml');
27+
$this->expectException(XmlException::class);
28+
29+
// an exception is only thrown for Action Group files.
30+
$actionDom->initDom($sampleXml, 'dupeStepKeyActionGroup.xml');
31+
}
32+
}

dev/tests/verification/TestModule/ActionGroup/XmlDuplicateActionGroup.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
<amOnSubdomain stepKey="aosd2" url="1"/>
1717
<amOnUrl stepKey="aou1" url="1"/>
1818
<amOnUrl stepKey="aou2" url="1"/>
19-
<appendField selector="1" stepKey="ap1"/>
20-
<appendField selector="1" stepKey="ap2"/>
19+
<appendField selector="1" stepKey="apf1"/>
20+
<appendField selector="1" stepKey="apf2"/>
2121
<attachFile selector="1" stepKey="atf1"/>
2222
<attachFile selector="1" stepKey="atf2"/>
2323
<cancelPopup stepKey="cp1"/>
@@ -164,8 +164,8 @@
164164
<seeInField stepKey="seeinfield12"/>
165165
<seeInFormFields selector="2" parameterArray="[1]" stepKey="seeinformfields1"/>
166166
<seeInFormFields selector="2" parameterArray="[1]" stepKey="seeinformfields12"/>
167-
<seeInPageSource html="1" stepKey="seeinsource1"/>
168-
<seeInPageSource html="1" stepKey="seeinsource12"/>
167+
<seeInPageSource html="1" stepKey="seeinpgsource1"/>
168+
<seeInPageSource html="1" stepKey="seeinpgsource12"/>
169169
<seeInPopup stepKey="seeinpopup1"/>
170170
<seeInPopup stepKey="seeinpopup12"/>
171171
<seeInSource html="1" stepKey="seeinsource1"/>

etc/di.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,11 +286,12 @@
286286
</arguments>
287287
</virtualType>
288288

289-
<virtualType name="Magento\FunctionalTestingFramework\Config\Reader\ActionGroupData" type="Magento\FunctionalTestingFramework\Config\Reader\Filesystem">
289+
<virtualType name="Magento\FunctionalTestingFramework\Config\Reader\ActionGroupData" type="Magento\FunctionalTestingFramework\Test\Config\Reader\Filesystem">
290290
<arguments>
291291
<argument name="fileResolver" xsi:type="object">Magento\FunctionalTestingFramework\Config\FileResolver\Module</argument>
292292
<argument name="converter" xsi:type="object">Magento\FunctionalTestingFramework\Config\ActionGroupDataConverter</argument>
293293
<argument name="schemaLocator" xsi:type="object">Magento\FunctionalTestingFramework\Config\SchemaLocator\ActionGroup</argument>
294+
<argument name="domDocumentClass" xsi:type="string">Magento\FunctionalTestingFramework\Test\Config\ActionGroupDom</argument>
294295
<argument name="idAttributes" xsi:type="array">
295296
<item name="/actionGroups/actionGroup" xsi:type="string">name</item>
296297
<item name="/actionGroups/actionGroup/arguments/argument" xsi:type="string">name</item>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\FunctionalTestingFramework\Test\Config;
7+
8+
class ActionGroupDom extends Dom
9+
{
10+
const ACTION_GROUP_FILE_NAME_ENDING = "ActionGroup.xml";
11+
12+
/**
13+
* Takes a dom element from xml and appends the filename based on location while also validating the action group
14+
* step key.
15+
*
16+
* @param string $xml
17+
* @param string|null $filename
18+
* @return \DOMDocument
19+
*/
20+
public function initDom($xml, $filename = null)
21+
{
22+
$dom = parent::initDom($xml);
23+
24+
if (strpos($filename, self::ACTION_GROUP_FILE_NAME_ENDING)) {
25+
$actionGroupNodes = $dom->getElementsByTagName('actionGroup');
26+
foreach ($actionGroupNodes as $actionGroupNode) {
27+
/** @var \DOMElement $actionGroupNode */
28+
$actionGroupNode->setAttribute(self::TEST_META_FILENAME_ATTRIBUTE, $filename);
29+
$this->validateDomStepKeys($actionGroupNode, $filename, 'Action Group');
30+
}
31+
}
32+
33+
return $dom;
34+
}
35+
}

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function initDom($xml, $filename = null)
5858
foreach ($testNodes as $testNode) {
5959
/** @var \DOMElement $testNode */
6060
$testNode->setAttribute(self::TEST_META_FILENAME_ATTRIBUTE, $filename);
61-
$this->validateTestDomStepKeys($testNode, $filename);
61+
$this->validateDomStepKeys($testNode, $filename, 'Test');
6262
}
6363
}
6464

@@ -83,10 +83,11 @@ public function merge($xml, $filename = null)
8383
*
8484
* @param \DOMElement $testNode
8585
* @param string $filename
86+
* @param string $type
8687
* @return void
8788
* @throws XmlException
8889
*/
89-
private function validateTestDomStepKeys($testNode, $filename)
90+
protected function validateDomStepKeys($testNode, $filename, $type)
9091
{
9192
$childNodes = $testNode->childNodes;
9293

@@ -99,7 +100,7 @@ private function validateTestDomStepKeys($testNode, $filename)
99100
}
100101

101102
if (in_array($currentNode->nodeName, self::TEST_HOOK_NAMES)) {
102-
$this->validateTestDomStepKeys($currentNode, $filename);
103+
$this->validateDomStepKeys($currentNode, $filename, $type);
103104
}
104105

105106
if ($currentNode->hasAttribute('stepKey')) {
@@ -116,7 +117,9 @@ private function validateTestDomStepKeys($testNode, $filename)
116117
$stepKeyError .= "\tstepKey: {$duplicateValue} is used more than once.\n";
117118
}
118119

119-
throw new XmlException("Tests cannot use stepKey more than once!\t\n{$stepKeyError}\tin file: {$filename}");
120+
throw new XmlException(
121+
"{$type}s cannot use stepKey more than once!\t\n{$stepKeyError}\tin file: {$filename}"
122+
);
120123
}
121124
}
122125
}

src/Magento/FunctionalTestingFramework/Test/Util/ActionGroupObjectExtractor.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class ActionGroupObjectExtractor extends BaseObjectExtractor
1717
{
1818
const DEFAULT_VALUE = 'defaultValue';
1919
const ACTION_GROUP_ARGUMENTS = 'arguments';
20+
const FILENAME = 'filename';
2021

2122
/**
2223
* Action Object Extractor for converting actions into objects
@@ -47,9 +48,11 @@ public function extractActionGroup($actionGroupData)
4748
$actionGroupData,
4849
self::NODE_NAME,
4950
self::ACTION_GROUP_ARGUMENTS,
50-
self::NAME
51+
self::NAME,
52+
self::FILENAME
5153
);
5254

55+
// TODO filename is now available to the ActionGroupObject, integrate this into debug and error statements
5356
$actions = $this->actionObjectExtractor->extractActions($actionData);
5457

5558
if (array_key_exists(self::ACTION_GROUP_ARGUMENTS, $actionGroupData)) {

src/Magento/FunctionalTestingFramework/Test/etc/actionGroupSchema.xsd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
</xs:element>
3333
</xs:choice>
3434
<xs:attribute type="xs:string" name="name" use="required"/>
35+
<xs:attribute type="xs:string" name="filename"/>
3536
</xs:complexType>
3637
<xs:simpleType name="dataTypeEnum" final="restriction">
3738
<xs:restriction base="xs:string">

0 commit comments

Comments
 (0)