Skip to content

Commit 274b2b0

Browse files
authored
MQE-913: Nested Element Assertions Don’t Support Action Group Replacement
- Fixed above bug. Attribute/argument resolution is now recursive.
1 parent 4ece405 commit 274b2b0

File tree

6 files changed

+120
-24
lines changed

6 files changed

+120
-24
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
namespace Magento\AcceptanceTest\_default\Backend;
3+
4+
use Magento\FunctionalTestingFramework\AcceptanceTester;
5+
use Magento\FunctionalTestingFramework\DataGenerator\Handlers\DataObjectHandler;
6+
use Magento\FunctionalTestingFramework\DataGenerator\Persist\DataPersistenceHandler;
7+
use Magento\FunctionalTestingFramework\DataGenerator\Objects\EntityDataObject;
8+
use \Codeception\Util\Locator;
9+
use Yandex\Allure\Adapter\Annotation\Features;
10+
use Yandex\Allure\Adapter\Annotation\Stories;
11+
use Yandex\Allure\Adapter\Annotation\Title;
12+
use Yandex\Allure\Adapter\Annotation\Description;
13+
use Yandex\Allure\Adapter\Annotation\Parameter;
14+
use Yandex\Allure\Adapter\Annotation\Severity;
15+
use Yandex\Allure\Adapter\Model\SeverityLevel;
16+
use Yandex\Allure\Adapter\Annotation\TestCaseId;
17+
18+
/**
19+
*/
20+
class ActionGroupUsingNestedArgumentCest
21+
{
22+
/**
23+
* @Parameter(name = "AcceptanceTester", value="$I")
24+
* @param AcceptanceTester $I
25+
* @return void
26+
* @throws \Exception
27+
*/
28+
public function ActionGroupUsingNestedArgument(AcceptanceTester $I)
29+
{
30+
$grabProductsActionGroup = $I->grabMultiple("selector");
31+
$I->assertCount(99, $grabProductsActionGroup);
32+
}
33+
}

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

+11
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,15 @@
4848
</arguments>
4949
<see selector="{{SampleSection.oneParamElement(someArgument)}}" userInput="{{someArgument}}" stepKey="see1" />
5050
</actionGroup>
51+
52+
<actionGroup name="actionGroupWithNestedArgument">
53+
<arguments>
54+
<argument name="count" defaultValue="10" type="string"/>
55+
</arguments>
56+
<grabMultiple selector="selector" stepKey="grabProducts"/>
57+
<assertCount stepKey="assertCount">
58+
<expectedResult type="int">{{count}}</expectedResult>
59+
<actualResult type="variable">grabProducts</actualResult>
60+
</assertCount>
61+
</actionGroup>
5162
</actionGroups>

dev/tests/verification/TestModule/Test/ActionGroupTest.xml

+6
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,10 @@
114114
<test name="ActionGroupWithStepKeyReferences">
115115
<actionGroup ref="FunctionActionGroupWithStepKeyReferences" stepKey="actionGroup"/>
116116
</test>
117+
118+
<test name="ActionGroupUsingNestedArgument">
119+
<actionGroup ref="actionGroupWithNestedArgument" stepKey="actionGroup">
120+
<argument name="count" value="99"/>
121+
</actionGroup>
122+
</test>
117123
</tests>

dev/tests/verification/Tests/ActionGroupGenerationTest.php

+11
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,15 @@ public function testActionGroupWithStepKeyReferences()
107107
{
108108
$this->generateAndCompareTest('ActionGroupWithStepKeyReferences');
109109
}
110+
111+
/**
112+
* Test generation of a test referencing an action group that uses stepKey references (grabFrom/CreateData)
113+
*
114+
* @throws \Exception
115+
* @throws \Magento\FunctionalTestingFramework\Exceptions\TestReferenceException
116+
*/
117+
public function testActionGroupWithNestedArgument()
118+
{
119+
$this->generateAndCompareTest('ActionGroupUsingNestedArgument');
120+
}
110121
}

src/Magento/FunctionalTestingFramework/Test/Objects/ActionGroupObject.php

+49-23
Original file line numberDiff line numberDiff line change
@@ -125,41 +125,23 @@ private function getResolvedActionsWithArgs($arguments, $actionReferenceKey)
125125
{
126126
$resolvedActions = [];
127127

128-
// $regexPattern match on: $matches[0] {{section.element(arg.field)}}
129-
// $matches[1] = section.element
130-
// $matches[2] = arg.field
131-
$regexPattern = '/{{([\w.\[\]]+)\(*([\w.$\',\s\[\]]+)*\)*}}/';
132-
133128
foreach ($this->parsedActions as $action) {
134129
$varAttributes = array_intersect($this->varAttributes, array_keys($action->getCustomActionAttributes()));
135130
$newActionAttributes = [];
136131

137132
if (!empty($varAttributes)) {
138-
// 1 check to see if we have pertinent var
139-
foreach ($varAttributes as $varAttribute) {
140-
$attributeValue = $action->getCustomActionAttributes()[$varAttribute];
141-
preg_match_all($regexPattern, $attributeValue, $matches);
142-
if (empty($matches[0])) {
143-
continue;
144-
}
145-
146-
//get rid of full match {{arg.field(arg.field)}}
147-
array_shift($matches);
148-
149-
$newActionAttributes[$varAttribute] = $this->replaceAttributeArguments(
150-
$arguments,
151-
$attributeValue,
152-
$matches
153-
);
154-
}
133+
$newActionAttributes = $this->resolveAttributesWithArguments(
134+
$arguments,
135+
$action->getCustomActionAttributes()
136+
);
155137
}
156138

157139
// we append the action reference key to any linked action and the action's merge key as the user might
158140
// use this action group multiple times in the same test.
159141
$resolvedActions[$action->getStepKey() . ucfirst($actionReferenceKey)] = new ActionObject(
160142
$action->getStepKey() . ucfirst($actionReferenceKey),
161143
$action->getType(),
162-
array_merge($action->getCustomActionAttributes(), $newActionAttributes),
144+
array_replace_recursive($action->getCustomActionAttributes(), $newActionAttributes),
163145
$action->getLinkedAction() == null ? null : $action->getLinkedAction() . ucfirst($actionReferenceKey),
164146
$action->getOrderOffset(),
165147
[self::ACTION_GROUP_ORIGIN_NAME => $this->name,
@@ -170,6 +152,50 @@ private function getResolvedActionsWithArgs($arguments, $actionReferenceKey)
170152
return $resolvedActions;
171153
}
172154

155+
/**
156+
* Resolves all references to arguments in attributes, and subAttributes.
157+
* @param array $arguments
158+
* @param array $attributes
159+
* @return array
160+
*/
161+
private function resolveAttributesWithArguments($arguments, $attributes)
162+
{
163+
// $regexPattern match on: $matches[0] {{section.element(arg.field)}}
164+
// $matches[1] = section.element
165+
// $matches[2] = arg.field
166+
$regexPattern = '/{{([\w.\[\]]+)\(*([\w.$\',\s\[\]]+)*\)*}}/';
167+
168+
$newActionAttributes = [];
169+
foreach ($attributes as $attributeKey => $attributeValue) {
170+
171+
if (is_array($attributeValue)) {
172+
// attributes with child elements are parsed as an array, need make recursive call to resolve children
173+
$newActionAttributes[$attributeKey] = $this->resolveAttributesWithArguments(
174+
$arguments,
175+
$attributeValue
176+
);
177+
continue;
178+
}
179+
180+
preg_match_all($regexPattern, $attributeValue, $matches);
181+
182+
if (empty($matches[0])) {
183+
continue;
184+
}
185+
186+
//get rid of full match {{arg.field(arg.field)}}
187+
array_shift($matches);
188+
189+
$newActionAttributes[$attributeKey] = $this->replaceAttributeArguments(
190+
$arguments,
191+
$attributeValue,
192+
$matches
193+
);
194+
}
195+
return $newActionAttributes;
196+
197+
}
198+
173199
/**
174200
* Function that takes an array of replacement arguments, and matches them with args in an actionGroup's attribute.
175201
* Determines if the replacement arguments are persisted data, and replaces them accordingly.

src/Magento/FunctionalTestingFramework/Test/Objects/ActionObject.php

+10-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,16 @@
2121
class ActionObject
2222
{
2323
const __ENV = "_ENV";
24-
const DATA_ENABLED_ATTRIBUTES = ["userInput", "parameterArray", "expected", "actual", "x", "y"];
24+
const DATA_ENABLED_ATTRIBUTES = [
25+
"userInput",
26+
"parameterArray",
27+
"expected",
28+
"actual",
29+
"x",
30+
"y",
31+
"expectedResult",
32+
"actualResult"
33+
];
2534
const SELECTOR_ENABLED_ATTRIBUTES = [
2635
'selector',
2736
'dependentSelector',

0 commit comments

Comments
 (0)