88use AspectMock \Test as AspectMock ;
99use Magento \FunctionalTestingFramework \DataGenerator \Handlers \DataObjectHandler ;
1010use Magento \FunctionalTestingFramework \DataGenerator \Objects \EntityDataObject ;
11+ use Magento \FunctionalTestingFramework \Exceptions \TestReferenceException ;
12+ use Magento \FunctionalTestingFramework \Exceptions \XmlException ;
1113use Magento \FunctionalTestingFramework \Test \Objects \ActionObject ;
1214use Magento \FunctionalTestingFramework \Test \Util \ActionMergeUtil ;
1315use Magento \FunctionalTestingFramework \Test \Util \ActionObjectExtractor ;
@@ -100,7 +102,7 @@ public function testResolveActionStepEntityData()
100102 $ dataFieldName = 'myfield ' ;
101103 $ dataFieldValue = 'myValue ' ;
102104 $ userInputKey = "userInput " ;
103- $ userinputValue = "{{ " . "$ {dataObjectName}. $ {dataFieldName}}} " ;
105+ $ userInputValue = "{{ " . "$ {dataObjectName}. $ {dataFieldName}}} " ;
104106 $ actionName = "myAction " ;
105107 $ actionType = "myCustomType " ;
106108
@@ -113,10 +115,10 @@ public function testResolveActionStepEntityData()
113115 AspectMock::double (DataObjectHandler::class, ['getInstance ' => $ mockDOHInstance ]);
114116
115117 // Create test object and action object
116- $ actionAttributes = [$ userInputKey => $ userinputValue ];
118+ $ actionAttributes = [$ userInputKey => $ userInputValue ];
117119 $ actions [$ actionName ] = new ActionObject ($ actionName , $ actionType , $ actionAttributes );
118120
119- $ this ->assertEquals ($ userinputValue , $ actions [$ actionName ]->getCustomActionAttributes ()[$ userInputKey ]);
121+ $ this ->assertEquals ($ userInputValue , $ actions [$ actionName ]->getCustomActionAttributes ()[$ userInputKey ]);
120122
121123 $ mergeUtil = new ActionMergeUtil ("test " , "TestCase " );
122124 $ resolvedActions = $ mergeUtil ->resolveActionSteps ($ actions );
@@ -127,8 +129,14 @@ public function testResolveActionStepEntityData()
127129 /**
128130 * Verify that an XmlException is thrown when an action references a non-existant action.
129131 *
132+ * @throws TestReferenceException
133+ * @throws XmlException
130134 * @return void
131135 */
136+ /**
137+ * @throws TestReferenceException
138+ * @throws XmlException
139+ */
132140 public function testNoActionException ()
133141 {
134142 $ actionObjects = [];
@@ -151,6 +159,8 @@ public function testNoActionException()
151159 /**
152160 * Verify that a <waitForPageLoad> action is added after actions that have a wait (timeout property).
153161 *
162+ * @throws TestReferenceException
163+ * @throws XmlException
154164 * @return void
155165 */
156166 public function testInsertWait ()
@@ -173,6 +183,111 @@ public function testInsertWait()
173183 $ this ->assertEquals ($ expected , $ actual );
174184 }
175185
186+ /**
187+ * Verify that a <fillField> action is replaced by <fillSecretField> when secret _CREDS are referenced.
188+ *
189+ * @throws TestReferenceException
190+ * @throws XmlException
191+ */
192+ public function testValidFillFieldSecretFunction ()
193+ {
194+ $ actionObjectOne = new ActionObject (
195+ 'actionKey1 ' ,
196+ 'fillField ' ,
197+ ['userInput ' => '{{_CREDS.username}} ' ]
198+ );
199+ $ actionObject = [$ actionObjectOne ];
200+
201+ $ actionMergeUtil = new ActionMergeUtil ('actionMergeUtilTest ' , 'TestCase ' );
202+
203+ $ result = $ actionMergeUtil ->resolveActionSteps ($ actionObject );
204+
205+ $ expectedValue = new ActionObject (
206+ 'actionKey1 ' ,
207+ 'fillSecretField ' ,
208+ ['userInput ' => '{{_CREDS.username}} ' ]
209+ );
210+ $ this ->assertEquals ($ expectedValue , $ result ['actionKey1 ' ]);
211+ }
212+
213+ /**
214+ * Verify that a <magentoCLI> action uses <magentoCLI> when secret _CREDS are referenced.
215+ *
216+ * @throws TestReferenceException
217+ * @throws XmlException
218+ */
219+ public function testValidMagentoCLISecretFunction ()
220+ {
221+ $ actionObjectOne = new ActionObject (
222+ 'actionKey1 ' ,
223+ 'magentoCLI ' ,
224+ ['command ' => 'config:set cms/wysiwyg/enabled {{_CREDS.payment_authorizenet_login}} ' ]
225+ );
226+ $ actionObject = [$ actionObjectOne ];
227+
228+ $ actionMergeUtil = new ActionMergeUtil ('actionMergeUtilTest ' , 'TestCase ' );
229+
230+ $ result = $ actionMergeUtil ->resolveActionSteps ($ actionObject );
231+
232+ $ expectedValue = new ActionObject (
233+ 'actionKey1 ' ,
234+ 'magentoCLISecret ' ,
235+ ['command ' => 'config:set cms/wysiwyg/enabled {{_CREDS.payment_authorizenet_login}} ' ]
236+ );
237+ $ this ->assertEquals ($ expectedValue , $ result ['actionKey1 ' ]);
238+ }
239+
240+ /**
241+ * Verify that a <field> override in a <createData> action uses <field> when secret _CREDS are referenced.
242+ *
243+ * @throws TestReferenceException
244+ * @throws XmlException
245+ */
246+ public function testValidCreateDataSecretFunction ()
247+ {
248+ $ actionObjectOne = new ActionObject (
249+ 'actionKey1 ' ,
250+ 'field ' ,
251+ ['value ' => '{{_CREDS.payment_authorizenet_login}} ' ]
252+ );
253+ $ actionObject = [$ actionObjectOne ];
254+
255+ $ actionMergeUtil = new ActionMergeUtil ('actionMergeUtilTest ' , 'TestCase ' );
256+
257+ $ result = $ actionMergeUtil ->resolveActionSteps ($ actionObject );
258+
259+ $ expectedValue = new ActionObject (
260+ 'actionKey1 ' ,
261+ 'field ' ,
262+ ['value ' => '{{_CREDS.payment_authorizenet_login}} ' ]
263+ );
264+ $ this ->assertEquals ($ expectedValue , $ result ['actionKey1 ' ]);
265+ }
266+
267+ /**
268+ * Verify that a <click> action throws an exception when secret _CREDS are referenced.
269+ *
270+ * @throws TestReferenceException
271+ * @throws XmlException
272+ */
273+ public function testInvalidSecretFunctions ()
274+ {
275+ $ this ->expectException (TestReferenceException::class);
276+ $ this ->expectExceptionMessage (
277+ 'You cannot reference secret data outside of the fillField, magentoCLI and createData actions '
278+ );
279+
280+ $ actionObjectOne = new ActionObject (
281+ 'actionKey1 ' ,
282+ 'click ' ,
283+ ['userInput ' => '{{_CREDS.username}} ' ]
284+ );
285+ $ actionObject = [$ actionObjectOne ];
286+
287+ $ actionMergeUtil = new ActionMergeUtil ('actionMergeUtilTest ' , 'TestCase ' );
288+ $ actionMergeUtil ->resolveActionSteps ($ actionObject );
289+ }
290+
176291 /**
177292 * After class functionality
178293 * @return void
0 commit comments