13
13
*/
14
14
class ActionGroupObject
15
15
{
16
+ const VAR_ATTRIBUTES = ['userInput ' , 'selector ' , 'page ' ];
17
+
16
18
/**
17
19
* The name of the action group
18
20
*
@@ -28,79 +30,110 @@ class ActionGroupObject
28
30
private $ parsedActions = [];
29
31
30
32
/**
31
- * A string used as the default entity if the user does not specify one
33
+ * An array used to store the default entities if the user does not specify any
32
34
*
33
- * @var string
35
+ * @var array
34
36
*/
35
- private $ defaultEntity ;
37
+ private $ arguments ;
36
38
37
39
/**
38
40
* ActionGroupObject constructor.
39
41
*
40
42
* @param string $name
41
- * @param string $defaultEntity
43
+ * @param string $arguments
42
44
* @param array $actions
43
45
*/
44
- public function __construct ($ name , $ defaultEntity , $ actions )
46
+ public function __construct ($ name , $ arguments , $ actions )
45
47
{
46
48
$ this ->name = $ name ;
47
- $ this ->defaultEntity = $ defaultEntity ;
49
+ $ this ->arguments = $ arguments ;
48
50
$ this ->parsedActions = $ actions ;
49
51
}
50
52
51
53
/**
52
54
* Gets the ordered steps including merged waits
53
55
*
54
- * @param string $entity
56
+ * @param array $arguments
55
57
* @return array
56
58
*/
57
- public function getSteps ($ entity )
59
+ public function getSteps ($ arguments )
58
60
{
59
61
$ mergeUtil = new ActionMergeUtil ();
60
- if (!$ entity ) {
61
- $ entity = $ this ->defaultEntity ;
62
+ $ args = $ this ->arguments ;
63
+
64
+ if ($ arguments ) {
65
+ $ args = array_merge ($ args , $ arguments );
62
66
}
63
- return $ mergeUtil ->mergeStepsAndInsertWaits ($ this ->getResolvedActions ($ entity ));
67
+
68
+ return $ mergeUtil ->mergeStepsAndInsertWaits ($ this ->getResolvedActionsWithArgs ($ args ));
64
69
}
65
70
66
71
/**
67
- * Function which takes the name of the entity object to be appended to an action objects fields returns resulting
68
- * action objects with proper entity .field references.
72
+ * Function which takes a set of arguments to be appended to an action objects fields returns resulting
73
+ * action objects with proper argument .field references.
69
74
*
70
- * @param string $entity
75
+ * @param array $arguments
71
76
* @return array
72
77
*/
73
- private function getResolvedActions ( $ entity )
78
+ private function getResolvedActionsWithArgs ( $ arguments )
74
79
{
75
80
$ resolvedActions = [];
81
+ $ regexPattern = '/{{([\w]+)/ ' ;
76
82
77
83
foreach ($ this ->parsedActions as $ action ) {
78
- /**@var \Magento\AcceptanceTestFramework\Test\Objects\ActionObject $action **/
79
- if (array_key_exists ( ' userInput ' , $ action -> getCustomActionAttributes () )) {
80
- $ regexPattern = ' /{{.[\w]+}}/ ' ;
81
- preg_match_all ( $ regexPattern , $ action -> getCustomActionAttributes ()[ ' userInput ' ], $ matches );
82
-
83
- $ userInputString = $ action ->getCustomActionAttributes ()[' userInput ' ];
84
- foreach ( $ matches [ 0 ] as $ match ) {
85
- $ search = str_replace ( ' }} ' , '' , str_replace ( ' {{ ' , '' , $ match ));
86
- $ userInputString = str_replace ( $ search , $ entity . $ search , $ userInputString ) ;
87
- }
84
+ $ varAttributes = array_intersect ( self :: VAR_ATTRIBUTES , array_keys ( $ action-> getCustomActionAttributes ()));
85
+ if (! empty ( $ varAttributes )) {
86
+ $ newActionAttributes = [] ;
87
+ // 1 check to see if we have pertinent var
88
+ foreach ( $ varAttributes as $ varAttribute ) {
89
+ $ attributeValue = $ action ->getCustomActionAttributes ()[$ varAttribute ];
90
+ preg_match_all ( $ regexPattern , $ attributeValue , $ matches );
91
+ if ( empty ( $ matches [ 0 ]) & empty ( $ matches [ 1 ])) {
92
+ continue ;
93
+ }
88
94
89
- $ attribute ['userInput ' ] = $ userInputString ;
95
+ $ newActionAttributes [$ varAttribute ] = $ this ->resolveNewAttribute (
96
+ $ arguments ,
97
+ $ attributeValue ,
98
+ $ matches
99
+ );
100
+ }
90
101
91
102
$ resolvedActions [$ action ->getMergeKey ()] = new ActionObject (
92
103
$ action ->getMergeKey (),
93
104
$ action ->getType (),
94
- array_merge ($ action ->getCustomActionAttributes (), $ attribute ),
105
+ array_merge ($ action ->getCustomActionAttributes (), $ newActionAttributes ),
95
106
$ action ->getLinkedAction (),
96
107
$ action ->getOrderOffset ()
97
108
);
98
109
} else {
99
110
// add action here if we do not see any userInput in this particular action
100
111
$ resolvedActions [$ action ->getMergeKey ()] = $ action ;
101
112
}
113
+
102
114
}
103
115
104
116
return $ resolvedActions ;
105
117
}
118
+
119
+ /**
120
+ * Function which takes an array of arguments to use for replacement of var name, the string which contains
121
+ * the variable for replacement, an array of matching vars.
122
+ *
123
+ * @param array $arguments
124
+ * @param string $attributeValue
125
+ * @param array $matches
126
+ * @return string
127
+ */
128
+ private function resolveNewAttribute ($ arguments , $ attributeValue , $ matches )
129
+ {
130
+ $ newAttributeVal = $ attributeValue ;
131
+ foreach ($ matches [1 ] as $ var ) {
132
+ if (array_key_exists ($ var , $ arguments )) {
133
+ $ newAttributeVal = str_replace ($ var , $ arguments [$ var ], $ newAttributeVal );
134
+ }
135
+ }
136
+
137
+ return $ newAttributeVal ;
138
+ }
106
139
}
0 commit comments