Skip to content

Commit 0369375

Browse files
committed
MQE-549: [Unit Test] ActionMergeUtil.php
1 parent da10983 commit 0369375

File tree

2 files changed

+64
-39
lines changed

2 files changed

+64
-39
lines changed

dev/tests/unit/Magento/FunctionalTestFramework/Test/Util/ActionMergeUtilTest.php

Lines changed: 52 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,6 @@
1616

1717
class ActionMergeUtilTest extends TestCase
1818
{
19-
/**
20-
* Static ActionMergeUtil for all tests.
21-
*
22-
* @var ActionMergeUtil
23-
*/
24-
private static $MERGE_UTIL;
25-
26-
/**
27-
* Set up method for ActionMergeUtil tests.
28-
*
29-
* @return void
30-
*/
31-
public static function setUpBeforeClass()
32-
{
33-
self::$MERGE_UTIL = new ActionMergeUtil("actionMergeUtilTest", "TestCase");
34-
}
35-
3619
/**
3720
* Test to validate actions are properly ordered during a merge.
3821
*
@@ -85,7 +68,8 @@ public function testResolveActionStepOrdering()
8568
ActionObject::MERGE_ACTION_ORDER_AFTER
8669
);
8770

88-
$orderedActions = self::$MERGE_UTIL->resolveActionSteps($actions);
71+
$mergeUtil = new ActionMergeUtil("actionMergeUtilTest", "TestCase");
72+
$orderedActions = $mergeUtil->resolveActionSteps($actions);
8973
$orderedActionKeys = array_keys($orderedActions);
9074

9175
$this->assertEquals($testObjNamePosBeforeFirst, $orderedActionKeys[0]);
@@ -94,26 +78,6 @@ public function testResolveActionStepOrdering()
9478
$this->assertEquals($testObjNamePosAfterEnd, $orderedActionKeys[$actionsLength + 2]);
9579
}
9680

97-
/**
98-
* Test to validate action steps properly resolve section element references.
99-
*
100-
* @return void
101-
*/
102-
public function testResolveActionStepSectionData()
103-
{
104-
$this->markTestIncomplete('TODO');
105-
}
106-
107-
/**
108-
* Test to validate action steps properly resolve page references.
109-
*
110-
* @return void
111-
*/
112-
public function testResolveActionStepPageData()
113-
{
114-
$this->markTestIncomplete('TODO');
115-
}
116-
11781
/**
11882
* Test to validate action steps properly resolve entity data references.
11983
*
@@ -149,4 +113,54 @@ public function testResolveActionStepEntityData()
149113

150114
$this->assertEquals($dataFieldValue, $resolvedActions[$actionName]->getCustomActionAttributes()[$userInputKey]);
151115
}
116+
117+
/**
118+
* Verify that an XmlException is thrown when an action references a non-existant action.
119+
*
120+
* @return void
121+
*/
122+
public function testNoActionException()
123+
{
124+
$actionObjects = [];
125+
126+
$actionObjects[] = new ActionObject('actionKey1', 'bogusType', []);
127+
$actionObjects[] = new ActionObject(
128+
'actionKey2',
129+
'bogusType',
130+
[],
131+
'badActionReference',
132+
ActionObject::MERGE_ACTION_ORDER_BEFORE
133+
);
134+
135+
$this->expectException("\Magento\FunctionalTestingFramework\Exceptions\XmlException");
136+
137+
$actionMergeUtil = new ActionMergeUtil("actionMergeUtilTest", "TestCase");
138+
$actionMergeUtil->resolveActionSteps($actionObjects);
139+
}
140+
141+
/**
142+
* Verify that a <waitForPageLoad> action is added after actions that have a wait (timeout property).
143+
*
144+
* @return void
145+
*/
146+
public function testInsertWait()
147+
{
148+
$actionObjectOne = new ActionObject('actionKey1', 'bogusType', []);
149+
$actionObjectOne->setTimeout(42);
150+
$actionObjects = [$actionObjectOne];
151+
152+
$actionMergeUtil = new ActionMergeUtil("actionMergeUtilTest", "TestCase");
153+
$result = $actionMergeUtil->resolveActionSteps($actionObjects);
154+
155+
$actual = $result['actionKey1WaitForPageLoad'];
156+
$expected = new ActionObject(
157+
'actionKey1WaitForPageLoad',
158+
'waitForPageLoad',
159+
['timeout' => 42],
160+
'actionKey1',
161+
0
162+
);
163+
$this->assertEquals($expected, $actual);
164+
165+
}
152166
}

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,17 @@ public function getTimeout()
169169
return $this->timeout;
170170
}
171171

172+
/**
173+
* Set the timeout value.
174+
*
175+
* @param int $timeout
176+
* @return void
177+
*/
178+
public function setTimeout($timeout)
179+
{
180+
$this->timeout = $timeout;
181+
}
182+
172183
/**
173184
* Populate the resolved custom attributes array with lookup values for the following attributes:
174185
* selector
@@ -332,7 +343,7 @@ private function findAndReplaceReferences($objectHandler, $inputString)
332343
// If no Selector is defined, assume element has LocatorFunction
333344
$replacement = $obj->getElement($objField)->getSelector() ?:
334345
$obj->getElement($objField)->getLocatorFunction();
335-
$this->timeout = $obj->getElement($objField)->getTimeout();
346+
$this->setTimeout($obj->getElement($objField)->getTimeout());
336347
break;
337348
case (get_class($obj) == EntityDataObject::class):
338349
list(,$objField) = $this->stripAndSplitReference($match);

0 commit comments

Comments
 (0)