@@ -51,10 +51,7 @@ public function testResolveElementInSelector()
51
51
'userInput ' => 'Hello world '
52
52
]);
53
53
$ elementObject = new ElementObject ('elementObject ' , 'button ' , '#replacementSelector ' , null , '42 ' , false );
54
- $ sectionObject = new SectionObject ('SectionObject ' , ['elementObject ' => $ elementObject ]);
55
- $ instance = AspectMock::double (SectionObjectHandler::class, ['getObject ' => $ sectionObject ])
56
- ->make (); // bypass the private constructor
57
- AspectMock::double (SectionObjectHandler::class, ['getInstance ' => $ instance ]);
54
+ $ this ->mockSectionHandlerWithElement ($ elementObject );
58
55
59
56
// Call the method under test
60
57
$ actionObject ->resolveReferences ();
@@ -68,19 +65,109 @@ public function testResolveElementInSelector()
68
65
}
69
66
70
67
/**
71
- * {{Section.element(param)}} should be replaced
68
+ * {{Section.element(param)}} should replace correctly with 'stringLiterals'
72
69
*/
73
- public function testResolveSelectorWithOneParam ()
70
+ public function testResolveSelectorWithOneStringLiteral ()
74
71
{
75
- $ this ->markTestIncomplete ('TODO ' );
72
+ $ actionObject = new ActionObject ('key123 ' , 'fillField ' , [
73
+ 'selector ' => "{{SectionObject.elementObject('stringliteral')}} " ,
74
+ 'userInput ' => 'Input '
75
+ ]);
76
+ $ elementObject = new ElementObject ('elementObject ' , 'button ' , '#{{var1}} ' , null , '42 ' , true );
77
+ $ this ->mockSectionHandlerWithElement ($ elementObject );
78
+
79
+ // Call the method under test
80
+ $ actionObject ->resolveReferences ();
81
+
82
+ // Verify
83
+ $ expected = [
84
+ 'selector ' => '#stringliteral ' ,
85
+ 'userInput ' => 'Input '
86
+ ];
87
+ $ this ->assertEquals ($ expected , $ actionObject ->getCustomActionAttributes ());
88
+ }
89
+
90
+ /**
91
+ * {{Section.element(param)}} should replace correctly with {{data.key}} references
92
+ */
93
+ public function testResolveSelectorWithOneDataReference ()
94
+ {
95
+ $ actionObject = new ActionObject ('key123 ' , 'fillField ' , [
96
+ 'selector ' => "{{SectionObject.elementObject(dataObject.key)}} " ,
97
+ 'userInput ' => 'Input '
98
+ ]);
99
+
100
+ // Mock SectionHandler
101
+ $ elementObject = new ElementObject ('elementObject ' , 'button ' , '#{{var1}} ' , null , '42 ' , true );
102
+ $ this ->mockSectionHandlerWithElement ($ elementObject );
103
+
104
+ // Mock DataHandler
105
+ $ dataObject = new EntityDataObject ('dataObject ' , 'dataType ' , ["key " => 'myValue ' ], null , null , null );
106
+ $ this ->mockDataHandlerWithData ($ dataObject );
107
+
108
+ // Call the method under test
109
+ $ actionObject ->resolveReferences ();
110
+
111
+ // Verify
112
+ $ expected = [
113
+ 'selector ' => '#myValue ' ,
114
+ 'userInput ' => 'Input '
115
+ ];
116
+ $ this ->assertEquals ($ expected , $ actionObject ->getCustomActionAttributes ());
117
+ }
118
+
119
+ /**
120
+ * {{Section.element(param)}} should replace correctly with $data.key$ references
121
+ */
122
+ public function testResolveSelectorWithOnePersistedReference ()
123
+ {
124
+ $ actionObject = new ActionObject ('key123 ' , 'fillField ' , [
125
+ 'selector ' => '{{SectionObject.elementObject($data.key$)}} ' ,
126
+ 'userInput ' => 'Input '
127
+ ]);
128
+
129
+ // Mock SectionHandler
130
+ $ elementObject = new ElementObject ('elementObject ' , 'button ' , '#{{var1}} ' , null , '42 ' , true );
131
+ $ this ->mockSectionHandlerWithElement ($ elementObject );
132
+
133
+ // Call the method under test
134
+ $ actionObject ->resolveReferences ();
135
+
136
+ // Verify
137
+ $ expected = [
138
+ 'selector ' => '#$data.key$ ' ,
139
+ 'userInput ' => 'Input '
140
+ ];
141
+ $ this ->assertEquals ($ expected , $ actionObject ->getCustomActionAttributes ());
76
142
}
77
143
78
144
/**
79
- * {{Section.element(param1,param2)}} should be replaced
145
+ * {{Section.element(param1,param2,param3 )}} should replace correctly with all 3 data types.
80
146
*/
81
147
public function testResolveSelectorWithManyParams ()
82
148
{
83
- $ this ->markTestIncomplete ('TODO ' );
149
+ $ actionObject = new ActionObject ('key123 ' , 'fillField ' , [
150
+ 'selector ' => "{{SectionObject.elementObject('stringLiteral', data.key, \$data.key \$)}} " ,
151
+ 'userInput ' => 'Input '
152
+ ]);
153
+
154
+ // Mock SectionHandler
155
+ $ elementObject = new ElementObject ('elementObject ' , 'button ' , '#{{var1}}[{{var2}},{{var3}}] ' , null , '42 ' , true );
156
+ $ this ->mockSectionHandlerWithElement ($ elementObject );
157
+
158
+ // Mock DataHandler
159
+ $ dataObject = new EntityDataObject ('dataObject ' , 'dataType ' , ["key " => 'myValue ' ], null , null , null );
160
+ $ this ->mockDataHandlerWithData ($ dataObject );
161
+
162
+ // Call the method under test
163
+ $ actionObject ->resolveReferences ();
164
+
165
+ // Verify
166
+ $ expected = [
167
+ 'selector ' => '#stringLiteral[myValue,$data.key$] ' ,
168
+ 'userInput ' => 'Input '
169
+ ];
170
+ $ this ->assertEquals ($ expected , $ actionObject ->getCustomActionAttributes ());
84
171
}
85
172
86
173
/**
@@ -93,10 +180,7 @@ public function testTimeoutFromElement()
93
180
'selector ' => '{{SectionObject.elementObject}} '
94
181
]);
95
182
$ elementObject = new ElementObject ('elementObject ' , 'button ' , '#replacementSelector ' , null , '42 ' , false );
96
- $ sectionObject = new SectionObject ('SectionObject ' , ['elementObject ' => $ elementObject ]);
97
- $ instance = AspectMock::double (SectionObjectHandler::class, ['getObject ' => $ sectionObject ])
98
- ->make (); // bypass the private constructor
99
- AspectMock::double (SectionObjectHandler::class, ['getInstance ' => $ instance ]);
183
+ $ this ->mockSectionHandlerWithElement ($ elementObject );
100
184
101
185
// Call the method under test
102
186
$ actionObject ->resolveReferences ();
@@ -158,9 +242,7 @@ public function testResolveDataInUserInput()
158
242
$ entityDataObject = new EntityDataObject ('EntityDataObject ' , 'test ' , [
159
243
'key ' => 'replacementData '
160
244
], [], '' , '' );
161
- $ instance = AspectMock::double (DataObjectHandler::class, ['getObject ' => $ entityDataObject ])
162
- ->make (); // bypass the private constructor
163
- AspectMock::double (DataObjectHandler::class, ['getInstance ' => $ instance ]);
245
+ $ this ->mockDataHandlerWithData ($ entityDataObject );
164
246
165
247
// Call the method under test
166
248
$ actionObject ->resolveReferences ();
@@ -174,18 +256,53 @@ public function testResolveDataInUserInput()
174
256
}
175
257
176
258
/**
177
- * $testScopeData$ (single dollar sign) should be replaced
259
+ * Action object should throw an exception if a reference to a parameterized selector has too few given args.
178
260
*/
179
- public function testTestScopeDataResolution ()
261
+ public function testTooFewArgumentException ()
180
262
{
181
- $ this ->markTestIncomplete ('TODO ' );
263
+ $ this ->expectException ('Magento\FunctionalTestingFramework\Exceptions\TestReferenceException ' );
264
+
265
+ $ actionObject = new ActionObject ('key123 ' , 'fillField ' , [
266
+ 'selector ' => "{{SectionObject.elementObject('arg1')}} " ,
267
+ 'userInput ' => 'Input '
268
+ ]);
269
+ $ elementObject = new ElementObject ('elementObject ' , 'button ' , '#{{var1}} {{var2}} ' , null , '42 ' , true );
270
+ $ this ->mockSectionHandlerWithElement ($ elementObject );
271
+
272
+ // Call the method under test
273
+ $ actionObject ->resolveReferences ();
182
274
}
183
275
184
276
/**
185
- * $$cestScopeData$$ (double dollar sign) should be replaced
277
+ * Action object should throw an exception if a reference to a parameterized selector has too many given args.
186
278
*/
187
- public function testCestScopeDataResolution ()
279
+ public function testTooManyArgumentException ()
188
280
{
189
- $ this ->markTestIncomplete ('TODO ' );
281
+ $ this ->expectException ('Magento\FunctionalTestingFramework\Exceptions\TestReferenceException ' );
282
+
283
+ $ actionObject = new ActionObject ('key123 ' , 'fillField ' , [
284
+ 'selector ' => "{{SectionObject.elementObject('arg1', 'arg2', 'arg3')}} " ,
285
+ 'userInput ' => 'Input '
286
+ ]);
287
+ $ elementObject = new ElementObject ('elementObject ' , 'button ' , '#{{var1}} ' , null , '42 ' , true );
288
+ $ this ->mockSectionHandlerWithElement ($ elementObject );
289
+
290
+ // Call the method under test
291
+ $ actionObject ->resolveReferences ();
292
+ }
293
+
294
+ private function mockSectionHandlerWithElement ($ elementObject )
295
+ {
296
+ $ sectionObject = new SectionObject ('SectionObject ' , ['elementObject ' => $ elementObject ]);
297
+ $ instance = AspectMock::double (SectionObjectHandler::class, ['getObject ' => $ sectionObject ])
298
+ ->make (); // bypass the private constructor
299
+ AspectMock::double (SectionObjectHandler::class, ['getInstance ' => $ instance ]);
300
+ }
301
+
302
+ private function mockDataHandlerWithData ($ dataObject )
303
+ {
304
+ $ dataInstance = AspectMock::double (DataObjectHandler::class, ['getObject ' => $ dataObject ])
305
+ ->make ();
306
+ AspectMock::double (DataObjectHandler::class, ['getInstance ' => $ dataInstance ]);
190
307
}
191
308
}
0 commit comments