-
Notifications
You must be signed in to change notification settings - Fork 132
/
Copy pathActionMergeUtilTest.php
166 lines (143 loc) · 5.78 KB
/
ActionMergeUtilTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace tests\unit\Magento\FunctionalTestFramework\Test\Util;
use AspectMock\Test as AspectMock;
use Magento\FunctionalTestingFramework\DataGenerator\Handlers\DataObjectHandler;
use Magento\FunctionalTestingFramework\DataGenerator\Objects\EntityDataObject;
use Magento\FunctionalTestingFramework\Test\Objects\ActionObject;
use Magento\FunctionalTestingFramework\Test\Util\ActionMergeUtil;
use Magento\FunctionalTestingFramework\Test\Util\ActionObjectExtractor;
use PHPUnit\Framework\TestCase;
use tests\unit\Util\DataObjectHandlerReflectionUtil;
class ActionMergeUtilTest extends TestCase
{
/**
* Test to validate actions are properly ordered during a merge.
*
* @return void
*/
public function testResolveActionStepOrdering()
{
$actions = [];
$actionsLength = 11;
$testObjNamePosBeforeFirst = 'testBeforeBeforeMerge';
$testObjNamePosFirst = 'testBeforeMerge0';
$testObjNamePosEnd = 'testAfterMerge10';
$testObjNamePosAfterEnd = 'testAfterAfterMerge10';
for ($i = 1; $i < $actionsLength; $i++) {
$stepKey = 'stepKey'. $i;
$type = 'testType';
$actionAttributes = [];
$actions[] = new ActionObject($stepKey, $type, $actionAttributes);
}
$actions[] = new ActionObject(
$testObjNamePosAfterEnd,
'stepType',
[],
$testObjNamePosEnd,
ActionObject::MERGE_ACTION_ORDER_AFTER
);
$actions[] = new ActionObject(
$testObjNamePosBeforeFirst,
'stepType',
[],
$testObjNamePosFirst,
ActionObjectExtractor::TEST_ACTION_BEFORE
);
$actions[] = new ActionObject(
$testObjNamePosFirst,
'stepType',
[],
'stepKey1',
ActionObjectExtractor::TEST_ACTION_BEFORE
);
$actions[] = new ActionObject(
$testObjNamePosEnd,
'stepType',
[],
'stepKey' . (string)($actionsLength - 1),
ActionObject::MERGE_ACTION_ORDER_AFTER
);
$mergeUtil = new ActionMergeUtil("actionMergeUtilTest", "TestCase");
$orderedActions = $mergeUtil->resolveActionSteps($actions);
$orderedActionKeys = array_keys($orderedActions);
$this->assertEquals($testObjNamePosBeforeFirst, $orderedActionKeys[0]);
$this->assertEquals($testObjNamePosFirst, $orderedActionKeys[1]);
$this->assertEquals($testObjNamePosEnd, $orderedActionKeys[$actionsLength + 1]);
$this->assertEquals($testObjNamePosAfterEnd, $orderedActionKeys[$actionsLength + 2]);
}
/**
* Test to validate action steps properly resolve entity data references.
*
* @return void
*/
public function testResolveActionStepEntityData()
{
$dataObjectName = 'myObject';
$dataObjectType = 'testObject';
$dataFieldName = 'myfield';
$dataFieldValue = 'myValue';
$userInputKey = "userInput";
$userinputValue = "{{" . "${dataObjectName}.${dataFieldName}}}";
$actionName = "myAction";
$actionType = "myCustomType";
// Set up mock data object
$mockData = [$dataFieldName => $dataFieldValue];
$mockDataObject = new EntityDataObject($dataObjectName, $dataObjectType, $mockData, null, null, null);
// Set up mock DataObject Handler
$mockDOHInstance = AspectMock::double(DataObjectHandler::class, ['getObject' => $mockDataObject])->make();
AspectMock::double(DataObjectHandler::class, ['getInstance' => $mockDOHInstance]);
// Create test object and action object
$actionAttributes = [$userInputKey => $userinputValue];
$actions[$actionName] = new ActionObject($actionName, $actionType, $actionAttributes);
$this->assertEquals($userinputValue, $actions[$actionName]->getCustomActionAttributes()[$userInputKey]);
$mergeUtil = new ActionMergeUtil("test", "TestCase");
$resolvedActions = $mergeUtil->resolveActionSteps($actions);
$this->assertEquals($dataFieldValue, $resolvedActions[$actionName]->getCustomActionAttributes()[$userInputKey]);
}
/**
* Verify that an XmlException is thrown when an action references a non-existant action.
*
* @return void
*/
public function testNoActionException()
{
$actionObjects = [];
$actionObjects[] = new ActionObject('actionKey1', 'bogusType', []);
$actionObjects[] = new ActionObject(
'actionKey2',
'bogusType',
[],
'badActionReference',
ActionObject::MERGE_ACTION_ORDER_BEFORE
);
$this->expectException("\Magento\FunctionalTestingFramework\Exceptions\XmlException");
$actionMergeUtil = new ActionMergeUtil("actionMergeUtilTest", "TestCase");
$actionMergeUtil->resolveActionSteps($actionObjects);
}
/**
* Verify that a <waitForPageLoad> action is added after actions that have a wait (timeout property).
*
* @return void
*/
public function testInsertWait()
{
$actionObjectOne = new ActionObject('actionKey1', 'bogusType', []);
$actionObjectOne->setTimeout(42);
$actionObjects = [$actionObjectOne];
$actionMergeUtil = new ActionMergeUtil("actionMergeUtilTest", "TestCase");
$result = $actionMergeUtil->resolveActionSteps($actionObjects);
$actual = $result['actionKey1WaitForPageLoad'];
$expected = new ActionObject(
'actionKey1WaitForPageLoad',
'waitForPageLoad',
['timeout' => 42],
'actionKey1',
0
);
$this->assertEquals($expected, $actual);
}
}