Skip to content

Commit 9d7e4ce

Browse files
committed
MQE-812: Tests/Action Groups should infer order based on the top level argument
- Test/Dom.php now checks for a test to have a before/after attribute, if found it appends the before/after to all child actions for merging down the line.
1 parent 4e1affe commit 9d7e4ce

File tree

4 files changed

+56
-3
lines changed

4 files changed

+56
-3
lines changed

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

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ class Dom extends \Magento\FunctionalTestingFramework\Config\Dom
1717
const TEST_META_FILENAME_ATTRIBUTE = 'filename';
1818
const TEST_META_NAME_ATTRIBUTE = 'name';
1919
const TEST_HOOK_NAMES = ["after", "before"];
20+
const TEST_MERGE_POINTER_BEFORE = "before";
21+
const TEST_MERGE_POINTER_AFTER = "after";
2022

2123
/**
2224
* TestDom constructor.
@@ -63,6 +65,23 @@ public function initDom($xml, $filename = null, $exceptionCollector = null)
6365
/** @var \DOMElement $testNode */
6466
$testNode->setAttribute(self::TEST_META_FILENAME_ATTRIBUTE, $filename);
6567
$this->validateDomStepKeys($testNode, $filename, 'Test', $exceptionCollector);
68+
if ($testNode->getAttribute(self::TEST_MERGE_POINTER_AFTER) !== "") {
69+
$this->appendMergePointerToActions(
70+
$testNode,
71+
self::TEST_MERGE_POINTER_AFTER,
72+
$testNode->getAttribute(self::TEST_MERGE_POINTER_AFTER),
73+
$filename,
74+
$exceptionCollector
75+
);
76+
} elseif ($testNode->getAttribute(self::TEST_MERGE_POINTER_BEFORE) !== "") {
77+
$this->appendMergePointerToActions(
78+
$testNode,
79+
self::TEST_MERGE_POINTER_BEFORE,
80+
$testNode->getAttribute(self::TEST_MERGE_POINTER_BEFORE),
81+
$filename,
82+
$exceptionCollector
83+
);
84+
}
6685
}
6786
}
6887

@@ -83,6 +102,36 @@ public function merge($xml, $filename = null, $exceptionCollector = null)
83102
$this->mergeNode($dom->documentElement, '');
84103
}
85104

105+
/**
106+
* Parses DOM Structure's actions and appends a before/after attribute along with the parent's stepkey reference.
107+
*
108+
* @param \DOMElement $testNode
109+
* @param string $pointerType
110+
* @param string $pointerKey
111+
* @param string $filename
112+
* @param ExceptionCollector $exceptionCollector
113+
* @return void
114+
*/
115+
protected function appendMergePointerToActions($testNode, $pointerType, $pointerKey, $filename, $exceptionCollector)
116+
{
117+
$childNodes = $testNode->childNodes;
118+
for ($i = 0; $i < $childNodes->length; $i++) {
119+
$currentNode = $childNodes->item($i);
120+
if (!is_a($currentNode, \DOMElement::class)) {
121+
continue;
122+
}
123+
if ($currentNode->hasAttribute('stepKey')) {
124+
if ($currentNode->hasAttribute($pointerType) && $testNode->hasAttribute($pointerType)) {
125+
$errorMsg = "Actions cannot have a before/after pointer if they are in a test that provides a merge pointer.";
126+
$errorMsg .= "\n\tstepKey: {$currentNode->getAttribute('stepKey')}\tin file: {$filename}";
127+
$exceptionCollector->addError($filename, $errorMsg);
128+
continue;
129+
}
130+
$currentNode->setAttribute($pointerType, $pointerKey);
131+
}
132+
}
133+
}
134+
86135
/**
87136
* Parses an individual DOM structure for repeated stepKey attributes
88137
*

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class ActionMergeUtil
1818
{
1919
const STEP_MISSING_ERROR_MSG =
2020
"Merge Error - Step could not be found in either TestXML or DeltaXML.
21-
\t%s = '%s'\tTestStep='%s'\tLinkedStep'%s'";
21+
\t%s: '%s'\tTestStep: '%s'\tLinkedStep: '%s'";
2222

2323
const WAIT_ATTR = 'timeout';
2424
const WAIT_ACTION_NAME = 'waitForPageLoad';

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ class TestObjectExtractor extends BaseObjectExtractor
2121
const TEST_BEFORE_HOOK = 'before';
2222
const TEST_AFTER_HOOK = 'after';
2323
const TEST_FAILED_HOOK = 'failed';
24+
const TEST_BEFORE_ATTRIBUTE = 'before';
25+
const TEST_AFTER_ATTRIBUTE = 'after';
2426

2527
/**
2628
* Action Object Extractor object
@@ -85,15 +87,15 @@ public function extractTestData($testData)
8587
}
8688

8789
// extract before
88-
if (array_key_exists(self::TEST_BEFORE_HOOK, $testData)) {
90+
if (array_key_exists(self::TEST_BEFORE_HOOK, $testData) && is_array($testData[self::TEST_BEFORE_HOOK])) {
8991
$testHooks[self::TEST_BEFORE_HOOK] = $this->testHookObjectExtractor->extractHook(
9092
$testData[self::NAME],
9193
'before',
9294
$testData[self::TEST_BEFORE_HOOK]
9395
);
9496
}
9597

96-
if (array_key_exists(self::TEST_AFTER_HOOK, $testData)) {
98+
if (array_key_exists(self::TEST_AFTER_HOOK, $testData) && is_array($testData[self::TEST_AFTER_HOOK])) {
9799
// extract after
98100
$testHooks[self::TEST_AFTER_HOOK] = $this->testHookObjectExtractor->extractHook(
99101
$testData[self::NAME],

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@
7070
<xs:attribute type="xs:string" name="name"/>
7171
<xs:attribute type="xs:boolean" name="remove" default="false"/>
7272
<xs:attribute type="xs:string" name="filename"/>
73+
<xs:attribute type="xs:string" name="before"/>
74+
<xs:attribute type="xs:string" name="after"/>
7375
</xs:complexType>
7476
<xs:group name="testTypeTags">
7577
<xs:choice>

0 commit comments

Comments
 (0)