14
14
use Magento \FunctionalTestingFramework \Page \Objects \SectionObject ;
15
15
use Magento \FunctionalTestingFramework \Test \Objects \ActionGroupObject ;
16
16
use Magento \FunctionalTestingFramework \Test \Objects \ActionObject ;
17
+ use Magento \FunctionalTestingFramework \Test \Objects \ArgumentObject ;
17
18
use PHPUnit \Framework \TestCase ;
18
19
use tests \unit \Util \ActionGroupObjectBuilder ;
19
20
use tests \unit \Util \EntityDataObjectBuilder ;
@@ -49,10 +50,29 @@ public function testGetStepsWithCustomArgs()
49
50
50
51
$ actionGroupUnderTest = (new ActionGroupObjectBuilder ())
51
52
->withActionObjects ([new ActionObject ('action1 ' , 'testAction ' , ['userInput ' => '{{arg1.field2}} ' ])])
53
+ ->withArguments ([new ArgumentObject ('arg1 ' , null , 'entity ' )])
52
54
->build ();
53
55
54
56
$ steps = $ actionGroupUnderTest ->getSteps (['arg1 ' => 'data2 ' ], self ::ACTION_GROUP_MERGE_KEY );
55
57
$ this ->assertOnMergeKeyAndActionValue ($ steps , ['userInput ' => 'testValue2 ' ]);
58
+
59
+ // entity.field as argument
60
+ $ actionGroupUnderTest = (new ActionGroupObjectBuilder ())
61
+ ->withActionObjects ([new ActionObject ('action1 ' , 'testAction ' , ['userInput ' => '{{arg1}} ' ])])
62
+ ->withArguments ([new ArgumentObject ('arg1 ' , null , 'entity ' )])
63
+ ->build ();
64
+
65
+ $ steps = $ actionGroupUnderTest ->getSteps (['arg1 ' => 'data2.field2 ' ], self ::ACTION_GROUP_MERGE_KEY );
66
+ $ this ->assertOnMergeKeyAndActionValue ($ steps , ['userInput ' => 'testValue2 ' ]);
67
+
68
+ // String Data
69
+ $ actionGroupUnderTest = (new ActionGroupObjectBuilder ())
70
+ ->withActionObjects ([new ActionObject ('action1 ' , 'testAction ' , ['userInput ' => '{{simple}} ' ])])
71
+ ->withArguments ([new ArgumentObject ('simple ' , null , 'string ' )])
72
+ ->build ();
73
+
74
+ $ steps = $ actionGroupUnderTest ->getSteps (['simple ' => 'override ' ], self ::ACTION_GROUP_MERGE_KEY );
75
+ $ this ->assertOnMergeKeyAndActionValue ($ steps , ['userInput ' => 'override ' ]);
56
76
}
57
77
58
78
/**
@@ -62,10 +82,20 @@ public function testGetStepsWithPersistedArgs()
62
82
{
63
83
$ actionGroupUnderTest = (new ActionGroupObjectBuilder ())
64
84
->withActionObjects ([new ActionObject ('action1 ' , 'testAction ' , ['userInput ' => '{{arg1.field2}} ' ])])
85
+ ->withArguments ([new ArgumentObject ('arg1 ' , null , 'entity ' )])
65
86
->build ();
66
87
67
88
$ steps = $ actionGroupUnderTest ->getSteps (['arg1 ' => '$data3$ ' ], self ::ACTION_GROUP_MERGE_KEY );
68
89
$ this ->assertOnMergeKeyAndActionValue ($ steps , ['userInput ' => '$data3.field2$ ' ]);
90
+
91
+ // Simple Data
92
+ $ actionGroupUnderTest = (new ActionGroupObjectBuilder ())
93
+ ->withActionObjects ([new ActionObject ('action1 ' , 'testAction ' , ['userInput ' => '{{simple}} ' ])])
94
+ ->withArguments ([new ArgumentObject ('simple ' , null , 'string ' )])
95
+ ->build ();
96
+
97
+ $ steps = $ actionGroupUnderTest ->getSteps (['simple ' => '$data3.field2$ ' ], self ::ACTION_GROUP_MERGE_KEY );
98
+ $ this ->assertOnMergeKeyAndActionValue ($ steps , ['userInput ' => '$data3.field2$ ' ]);
69
99
}
70
100
71
101
/**
@@ -81,6 +111,7 @@ public function testGetStepsWithNoFieldArg()
81
111
82
112
$ actionGroupUnderTest = (new ActionGroupObjectBuilder ())
83
113
->withActionObjects ([new ActionObject ('action1 ' , 'testAction ' , ['userInput ' => '{{arg1}} ' ])])
114
+ ->withArguments ([new ArgumentObject ('arg1 ' , null , 'entity ' )])
84
115
->build ();
85
116
86
117
$ steps = $ actionGroupUnderTest ->getSteps (['arg1 ' => 'data2.field2 ' ], self ::ACTION_GROUP_MERGE_KEY );
@@ -111,6 +142,12 @@ public function testGetStepsWithNoArgs()
111
142
*/
112
143
public function testGetStepsWithParameterizedArg ()
113
144
{
145
+ // Mock Entity Object Handler
146
+ $ this ->setEntityObjectHandlerReturn (function ($ entityName ) {
147
+ if ($ entityName == "data2 " ) {
148
+ return (new EntityDataObjectBuilder ())->withDataFields (['field2 ' => 'testValue2 ' ])->build ();
149
+ }
150
+ });
114
151
// mock the section object handler response
115
152
$ element = new ElementObject ("element1 " , "textArea " , ".selector {{var1}} " , null , null , true );
116
153
$ section = new SectionObject ("testSection " , ["element1 " => $ element ]);
@@ -120,11 +157,55 @@ public function testGetStepsWithParameterizedArg()
120
157
121
158
$ actionGroupUnderTest = (new ActionGroupObjectBuilder ())
122
159
->withActionObjects (
123
- [new ActionObject ('action1 ' , 'testAction ' , ['selector ' => '{{section1.element1(arg1.field1 )}} ' ])]
160
+ [new ActionObject ('action1 ' , 'testAction ' , ['selector ' => '{{section1.element1(arg1.field2 )}} ' ])]
124
161
)
162
+ ->withArguments ([new ArgumentObject ('arg1 ' , null , 'entity ' )])
125
163
->build ();
126
164
127
- $ steps = $ actionGroupUnderTest ->getSteps (['arg1 ' => '$someData$ ' ], self ::ACTION_GROUP_MERGE_KEY );
165
+ // XML Data
166
+ $ steps = $ actionGroupUnderTest ->getSteps (['arg1 ' => 'data2 ' ], self ::ACTION_GROUP_MERGE_KEY );
167
+ $ this ->assertOnMergeKeyAndActionValue ($ steps , ['selector ' => '.selector testValue2 ' ]);
168
+
169
+ // Persisted Data
170
+ $ steps = $ actionGroupUnderTest ->getSteps (['arg1 ' => '$data2$ ' ], self ::ACTION_GROUP_MERGE_KEY );
171
+ $ this ->assertOnMergeKeyAndActionValue ($ steps , ['selector ' => '.selector $data2.field2$ ' ]);
172
+ }
173
+
174
+ /**
175
+ * Tests a parameterized section reference in an action group resolved with user simpleArgs.
176
+ */
177
+ public function testGetStepsWithParameterizedSimpleArg ()
178
+ {
179
+ // Mock Entity Object Handler
180
+ $ this ->setEntityObjectHandlerReturn (function ($ entityName ) {
181
+ if ($ entityName == "data2 " ) {
182
+ return (new EntityDataObjectBuilder ())->withDataFields (['field2 ' => 'testValue2 ' ])->build ();
183
+ }
184
+ });
185
+ // mock the section object handler response
186
+ $ element = new ElementObject ("element1 " , "textArea " , ".selector {{var1}} " , null , null , true );
187
+ $ section = new SectionObject ("testSection " , ["element1 " => $ element ]);
188
+ // bypass the private constructor
189
+ $ sectionInstance = AspectMock::double (SectionObjectHandler::class, ['getObject ' => $ section ])->make ();
190
+ AspectMock::double (SectionObjectHandler::class, ['getInstance ' => $ sectionInstance ]);
191
+
192
+ $ actionGroupUnderTest = (new ActionGroupObjectBuilder ())
193
+ ->withActionObjects (
194
+ [new ActionObject ('action1 ' , 'testAction ' , ['selector ' => '{{section1.element1(simple)}} ' ])]
195
+ )
196
+ ->withArguments ([new ArgumentObject ('simple ' , null , 'string ' )])
197
+ ->build ();
198
+
199
+ // String Literal
200
+ $ steps = $ actionGroupUnderTest ->getSteps (['simple ' => 'stringLiteral ' ], self ::ACTION_GROUP_MERGE_KEY );
201
+ $ this ->assertOnMergeKeyAndActionValue ($ steps , ['selector ' => '.selector stringLiteral ' ]);
202
+
203
+ // String Literal w/ data-like structure
204
+ $ steps = $ actionGroupUnderTest ->getSteps (['simple ' => 'data2.field2 ' ], self ::ACTION_GROUP_MERGE_KEY );
205
+ $ this ->assertOnMergeKeyAndActionValue ($ steps , ['selector ' => '.selector data2.field2 ' ]);
206
+
207
+ // Persisted Data
208
+ $ steps = $ actionGroupUnderTest ->getSteps (['simple ' => '$someData.field1$ ' ], self ::ACTION_GROUP_MERGE_KEY );
128
209
$ this ->assertOnMergeKeyAndActionValue ($ steps , ['selector ' => '.selector $someData.field1$ ' ]);
129
210
}
130
211
@@ -135,6 +216,7 @@ public function testGetStepsWithOuterScopePersistence()
135
216
{
136
217
$ actionGroupUnderTest = (new ActionGroupObjectBuilder ())
137
218
->withActionObjects ([new ActionObject ('action1 ' , 'testAction ' , ['userInput ' => '{{arg1.field1}} ' ])])
219
+ ->withArguments ([new ArgumentObject ('arg1 ' , null , 'entity ' )])
138
220
->build ();
139
221
140
222
$ steps = $ actionGroupUnderTest ->getSteps (['arg1 ' => '$$someData$$ ' ], self ::ACTION_GROUP_MERGE_KEY );
@@ -147,11 +229,11 @@ public function testGetStepsWithOuterScopePersistence()
147
229
public function testExceptionOnMissingActions ()
148
230
{
149
231
$ actionGroupUnderTest = (new ActionGroupObjectBuilder ())
150
- ->withArguments (['arg1 ' => null ])
232
+ ->withArguments ([new ArgumentObject ( 'arg1 ' , null , ' entity ' ) ])
151
233
->build ();
152
234
153
235
$ this ->expectException (TestReferenceException::class);
154
- $ this ->expectExceptionMessageRegExp ('/Argument\(s\) missed .* for actionGroup/ ' );
236
+ $ this ->expectExceptionMessageRegExp ('/Arguments missed .* for actionGroup/ ' );
155
237
$ actionGroupUnderTest ->getSteps (['arg2 ' => 'data1 ' ], self ::ACTION_GROUP_MERGE_KEY );
156
238
}
157
239
@@ -161,11 +243,11 @@ public function testExceptionOnMissingActions()
161
243
public function testExceptionOnMissingArguments ()
162
244
{
163
245
$ actionGroupUnderTest = (new ActionGroupObjectBuilder ())
164
- ->withArguments (['arg1 ' => null ])
246
+ ->withArguments ([new ArgumentObject ( 'arg1 ' , null , ' entity ' ) ])
165
247
->build ();
166
248
167
249
$ this ->expectException (TestReferenceException::class);
168
- $ this ->expectExceptionMessageRegExp ('/Not enough arguments given for actionGroup .* / ' );
250
+ $ this ->expectExceptionMessageRegExp ('/Arguments missed .* for actionGroup/ ' );
169
251
$ actionGroupUnderTest ->getSteps (null , self ::ACTION_GROUP_MERGE_KEY );
170
252
}
171
253
0 commit comments