Skip to content

Commit 621e9c5

Browse files
authored
MQE-993: ActionGroups that use createData are not generated correctly (#129)
* MQE-993: ActionGroups that use createData are not generated correctly - Added check in getResolvedActionsWithArgs * MQE-993: ActionGroups that use createData are not generated correctly - Abstracted method to private function * MQE-993: ActionGroups that use createData are not generated correctly - Removed broken out line in ActionGroupObject * MQE-993: ActionGroups that use createData are not generated correctly - Removed nested if
1 parent 22a1ef1 commit 621e9c5

File tree

5 files changed

+113
-2
lines changed

5 files changed

+113
-2
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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 ActionGroupUsingCreateDataCest
21+
{
22+
/**
23+
* @var DataPersistenceHandler $createCategoryKey1;
24+
*/
25+
protected $createCategoryKey1;
26+
27+
/**
28+
* @var DataPersistenceHandler $createConfigProductKey1;
29+
*/
30+
protected $createConfigProductKey1;
31+
32+
/**
33+
* @param AcceptanceTester $I
34+
* @throws \Exception
35+
*/
36+
public function _before(AcceptanceTester $I)
37+
{
38+
$I->amGoingTo("create entity that has the stepKey: createCategoryKey1");
39+
$ApiCategory = DataObjectHandler::getInstance()->getObject("ApiCategory");
40+
$this->createCategoryKey1 = new DataPersistenceHandler($ApiCategory, []);
41+
$this->createCategoryKey1->createEntity();
42+
$I->amGoingTo("create entity that has the stepKey: createConfigProductKey1");
43+
$ApiConfigurableProduct = DataObjectHandler::getInstance()->getObject("ApiConfigurableProduct");
44+
$this->createConfigProductKey1 = new DataPersistenceHandler($ApiConfigurableProduct, [$this->createCategoryKey1]);
45+
$this->createConfigProductKey1->createEntity();
46+
}
47+
48+
/**
49+
* @Features({"TestModule"})
50+
* @Parameter(name = "AcceptanceTester", value="$I")
51+
* @param AcceptanceTester $I
52+
* @return void
53+
* @throws \Exception
54+
*/
55+
public function ActionGroupUsingCreateData(AcceptanceTester $I)
56+
{
57+
}
58+
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,11 @@
9191
<actionGroup name="extendRemoveTestActionGroup" extends="extendBasicActionGroup">
9292
<remove keyForRemoval="removeMe"/>
9393
</actionGroup>
94+
95+
<actionGroup name="actionGroupWithCreateData">
96+
<createData entity="ApiCategory" stepKey="createCategory"/>
97+
<createData entity="ApiConfigurableProduct" stepKey="createConfigProduct">
98+
<requiredEntity createDataKey="createCategory"/>
99+
</createData>
100+
</actionGroup>
94101
</actionGroups>

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,10 @@
137137
<test name="ExtendedRemoveActionGroup">
138138
<actionGroup ref="extendRemoveTestActionGroup" stepKey="actionGroup"/>
139139
</test>
140+
141+
<test name="ActionGroupUsingCreateData">
142+
<before>
143+
<actionGroup ref="actionGroupWithCreateData" stepKey="Key1"/>
144+
</before>
145+
</test>
140146
</tests>

dev/tests/verification/Tests/ActionGroupGenerationTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,4 +162,15 @@ public function testExtendedRemoveActionGroup()
162162
{
163163
$this->generateAndCompareTest('ExtendedRemoveActionGroup');
164164
}
165+
166+
/**
167+
* Test generation of a test referencing an action group that uses stepKey references within the action group
168+
*
169+
* @throws \Exception
170+
* @throws \Magento\FunctionalTestingFramework\Exceptions\TestReferenceException
171+
*/
172+
public function testActionGroupWithCreateData()
173+
{
174+
$this->generateAndCompareTest('ActionGroupUsingCreateData');
175+
}
165176
}

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

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,15 +136,21 @@ private function resolveArguments($arguments)
136136
private function getResolvedActionsWithArgs($arguments, $actionReferenceKey)
137137
{
138138
$resolvedActions = [];
139+
$replacementStepKeys = [];
139140

140141
foreach ($this->parsedActions as $action) {
142+
$replacementStepKeys[$action->getStepKey()] = $action->getStepKey() . ucfirst($actionReferenceKey);
141143
$varAttributes = array_intersect($this->varAttributes, array_keys($action->getCustomActionAttributes()));
144+
145+
// replace createDataKey attributes inside the action group
146+
$resolvedActionAttributes = $this->replaceCreateDataKeys($action, $replacementStepKeys);
147+
142148
$newActionAttributes = [];
143149

144150
if (!empty($varAttributes)) {
145151
$newActionAttributes = $this->resolveAttributesWithArguments(
146152
$arguments,
147-
$action->getCustomActionAttributes()
153+
$resolvedActionAttributes
148154
);
149155
}
150156

@@ -159,7 +165,7 @@ private function getResolvedActionsWithArgs($arguments, $actionReferenceKey)
159165
$resolvedActions[$action->getStepKey() . ucfirst($actionReferenceKey)] = new ActionObject(
160166
$action->getStepKey() . ucfirst($actionReferenceKey),
161167
$action->getType(),
162-
array_replace_recursive($action->getCustomActionAttributes(), $newActionAttributes),
168+
array_replace_recursive($resolvedActionAttributes, $newActionAttributes),
163169
$action->getLinkedAction() == null ? null : $action->getLinkedAction() . ucfirst($actionReferenceKey),
164170
$orderOffset,
165171
[self::ACTION_GROUP_ORIGIN_NAME => $this->name,
@@ -432,4 +438,27 @@ function ($e) use ($name) {
432438
}
433439
return null;
434440
}
441+
442+
/**
443+
* Replaces references to step keys used earlier in an action group
444+
*
445+
* @param ActionObject $action
446+
* @param array $replacementStepKeys
447+
* @return ActionObject[]
448+
*/
449+
private function replaceCreateDataKeys($action, $replacementStepKeys)
450+
{
451+
$resolvedActionAttributes = [];
452+
453+
foreach ($action->getCustomActionAttributes() as $actionAttribute => $actionAttributeDetails) {
454+
if (is_array($actionAttributeDetails) && array_key_exists('createDataKey', $actionAttributeDetails)) {
455+
$actionAttributeDetails['createDataKey'] =
456+
$replacementStepKeys[$actionAttributeDetails['createDataKey']] ??
457+
$actionAttributeDetails['createDataKey'];
458+
}
459+
$resolvedActionAttributes[$actionAttribute] = $actionAttributeDetails;
460+
}
461+
462+
return $resolvedActionAttributes;
463+
}
435464
}

0 commit comments

Comments
 (0)