13
13
*/
14
14
class ActionGroupObject
15
15
{
16
- const VAR_ATTRIBUTES = ['userInput ' , 'selector ' , 'page ' ];
16
+ const VAR_ATTRIBUTES = ['userInput ' , 'selector ' , 'page ' , ' url ' ];
17
17
18
18
/**
19
19
* The name of the action group
@@ -80,7 +80,11 @@ public function getSteps($arguments, $actionReferenceKey)
80
80
private function getResolvedActionsWithArgs ($ arguments , $ actionReferenceKey )
81
81
{
82
82
$ resolvedActions = [];
83
- $ regexPattern = '/{{([\w]+)/ ' ;
83
+
84
+ // $regexPattern match on: $matches[0] {{section.element(arg.field)}}
85
+ // $matches[1] = section.element
86
+ // $matches[2] = arg.field
87
+ $ regexPattern = '/{{([\w.]+)\(*([\w.$ \']+)*\)*}}/ ' ;
84
88
85
89
foreach ($ this ->parsedActions as $ action ) {
86
90
$ varAttributes = array_intersect (self ::VAR_ATTRIBUTES , array_keys ($ action ->getCustomActionAttributes ()));
@@ -90,11 +94,15 @@ private function getResolvedActionsWithArgs($arguments, $actionReferenceKey)
90
94
foreach ($ varAttributes as $ varAttribute ) {
91
95
$ attributeValue = $ action ->getCustomActionAttributes ()[$ varAttribute ];
92
96
preg_match_all ($ regexPattern , $ attributeValue , $ matches );
93
- if (empty ($ matches [0 ]) & empty ($ matches [1 ])) {
97
+
98
+ if (empty ($ matches [0 ])) {
94
99
continue ;
95
100
}
96
101
97
- $ newActionAttributes [$ varAttribute ] = $ this ->resolveNewAttribute (
102
+ //get rid of full match {{arg.field(arg.field)}}
103
+ unset($ matches [0 ]);
104
+
105
+ $ newActionAttributes [$ varAttribute ] = $ this ->replaceAttributeArguments (
98
106
$ arguments ,
99
107
$ attributeValue ,
100
108
$ matches
@@ -114,34 +122,78 @@ private function getResolvedActionsWithArgs($arguments, $actionReferenceKey)
114
122
}
115
123
116
124
/**
117
- * Function which takes an array of arguments to use for replacement of var name, the string which contains
118
- * the variable for replacement, an array of matching vars .
125
+ * Function that takes an array of replacement arguments, and matches them with args in an actionGroup's attribute.
126
+ * Determines if the replacement arguments are persisted data, and replaces them accordingly .
119
127
*
120
128
* @param array $arguments
121
129
* @param string $attributeValue
122
130
* @param array $matches
123
131
* @return string
124
132
*/
125
- private function resolveNewAttribute ($ arguments , $ attributeValue , $ matches )
133
+ private function replaceAttributeArguments ($ arguments , $ attributeValue , $ matches )
126
134
{
135
+ $ matchParametersKey = 2 ;
127
136
$ newAttributeVal = $ attributeValue ;
128
- foreach ($ matches [1 ] as $ var ) {
129
- if (array_key_exists ($ var , $ arguments )) {
130
- if (preg_match ('/\$\$[\w.\[\] \',]+\$\$/ ' , $ arguments [$ var ])) {
131
- //if persisted $$data$$ was passed, return $$param.id$$ instead of {{$$param$$.id}}
132
- $ newAttributeVal = str_replace ($ var , trim ($ arguments [$ var ], '$ ' ), $ newAttributeVal );
133
- $ newAttributeVal = str_replace ('{{ ' , '$$ ' , str_replace ('}} ' , '$$ ' , $ newAttributeVal ));
134
- } elseif (preg_match ('/\$[\w.\[\] \',]+\$/ ' , $ arguments [$ var ])) {
135
- //elseif persisted $data$ was passed, return $param.id$ instead of {{$param$.id}}
136
- $ newAttributeVal = str_replace ($ var , trim ($ arguments [$ var ], '$ ' ), $ newAttributeVal );
137
- $ newAttributeVal = str_replace ('{{ ' , '$ ' , str_replace ('}} ' , '$ ' , $ newAttributeVal ));
137
+
138
+ foreach ($ matches as $ key => $ match ) {
139
+ foreach ($ match as $ variable ) {
140
+ if (empty ($ variable )) {
141
+ continue ;
142
+ }
143
+ // Truncate arg.field into arg
144
+ $ variableName = strstr ($ variable , '. ' , true );
145
+ // Check if arguments has a mapping for the given variableName
146
+ if (!array_key_exists ($ variableName , $ arguments )) {
147
+ continue ;
148
+ }
149
+ $ isPersisted = strstr ($ arguments [$ variableName ], '$ ' );
150
+ if ($ isPersisted ) {
151
+ $ newAttributeVal = $ this ->replacePersistedArgument (
152
+ $ arguments [$ variableName ],
153
+ $ attributeValue ,
154
+ $ variable ,
155
+ $ variableName ,
156
+ $ key == $ matchParametersKey ? true : false
157
+ );
138
158
} else {
139
- //else normal param replacement
140
- $ newAttributeVal = str_replace ($ var , $ arguments [$ var ], $ newAttributeVal );
159
+ $ newAttributeVal = str_replace ($ variableName , $ arguments [$ variableName ], $ attributeValue );
141
160
}
142
161
}
143
162
}
144
163
145
164
return $ newAttributeVal ;
146
165
}
166
+
167
+ /**
168
+ * Replaces args with replacements given, behavior is specific to persisted arguments.
169
+ * @param string $replacement
170
+ * @param string $attributeValue
171
+ * @param string $fullVariable
172
+ * @param string $variable
173
+ * @param boolean $isParameter
174
+ * @return string
175
+ */
176
+ private function replacePersistedArgument ($ replacement , $ attributeValue , $ fullVariable , $ variable , $ isParameter )
177
+ {
178
+ //hookPersisted will be true if replacement passed in is $$arg.field$$, otherwise assume it's $arg.field$
179
+ $ hookPersistedArgumentRegex = '/\$\$[\w.\[\] \',]+\$\$/ ' ;
180
+ $ hookPersisted = (preg_match ($ hookPersistedArgumentRegex , $ replacement ));
181
+
182
+ $ newAttributeValue = $ attributeValue ;
183
+
184
+ $ scope = '$ ' ;
185
+ if ($ hookPersisted ) {
186
+ $ scope = '$$ ' ;
187
+ }
188
+
189
+ // parameter replacements require changing of (arg.field) to ($arg.field$)
190
+ if ($ isParameter ) {
191
+ $ newAttributeValue = str_replace ($ fullVariable , $ scope . $ fullVariable . $ scope , $ newAttributeValue );
192
+ } else {
193
+ $ newAttributeValue = str_replace ('{{ ' , $ scope , str_replace ('}} ' , $ scope , $ newAttributeValue ));
194
+ }
195
+ $ newAttributeValue = str_replace ($ variable , trim ($ replacement , '$ ' ), $ newAttributeValue );
196
+
197
+ return $ newAttributeValue ;
198
+ }
147
199
}
0 commit comments