Skip to content

Commit f2138fb

Browse files
committed
MQE-496: Allow passing multiple ActionGroup arguments into parameterized selector. (Patch from Anthoula)
1 parent 7cc6d1c commit f2138fb

File tree

1 file changed

+60
-30
lines changed

1 file changed

+60
-30
lines changed

src/Magento/FunctionalTestingFramework/Test/Objects/ActionGroupObject.php

Lines changed: 60 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -84,23 +84,22 @@ private function getResolvedActionsWithArgs($arguments, $actionReferenceKey)
8484
// $regexPattern match on: $matches[0] {{section.element(arg.field)}}
8585
// $matches[1] = section.element
8686
// $matches[2] = arg.field
87-
$regexPattern = '/{{([\w.]+)\(*([\w.$\']+)*\)*}}/';
88-
87+
$regexPattern ='/{{([\w.]+)\(?([\w.$\',\s]+)?\)?}}/';
8988
foreach ($this->parsedActions as $action) {
9089
$varAttributes = array_intersect(self::VAR_ATTRIBUTES, array_keys($action->getCustomActionAttributes()));
9190
$newActionAttributes = [];
91+
9292
if (!empty($varAttributes)) {
9393
// 1 check to see if we have pertinent var
9494
foreach ($varAttributes as $varAttribute) {
9595
$attributeValue = $action->getCustomActionAttributes()[$varAttribute];
9696
preg_match_all($regexPattern, $attributeValue, $matches);
97-
9897
if (empty($matches[0])) {
9998
continue;
10099
}
101100

102101
//get rid of full match {{arg.field(arg.field)}}
103-
unset($matches[0]);
102+
array_shift($matches);
104103

105104
$newActionAttributes[$varAttribute] = $this->replaceAttributeArguments(
106105
$arguments,
@@ -132,36 +131,67 @@ private function getResolvedActionsWithArgs($arguments, $actionReferenceKey)
132131
*/
133132
private function replaceAttributeArguments($arguments, $attributeValue, $matches)
134133
{
135-
$matchParametersKey = 2;
136-
$newAttributeVal = $attributeValue;
134+
list($mainValueList, $possibleArgumentsList) = $matches;
137135

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-
);
158-
} else {
159-
$newAttributeVal = str_replace($variableName, $arguments[$variableName], $attributeValue);
160-
}
136+
foreach ($mainValueList as $index => $mainValue) {
137+
$possibleArguments = $possibleArgumentsList[$index];
138+
139+
$attributeValue = $this->replaceAttributeArgumentInVariable($mainValue, $arguments, $attributeValue);
140+
141+
$argumentList = array_filter(array_map('trim', explode(',', $possibleArguments)));
142+
143+
foreach ($argumentList as $argumentValue) {
144+
$attributeValue = $this->replaceAttributeArgumentInVariable(
145+
$argumentValue,
146+
$arguments,
147+
$attributeValue,
148+
true
149+
);
161150
}
162151
}
163152

164-
return $newAttributeVal;
153+
return $attributeValue;
154+
}
155+
156+
/**
157+
* Replace attribute arguments in variable.
158+
*
159+
* @param string $variable
160+
* @param array $arguments
161+
* @param string $attributeValue
162+
* @param bool $isInnerArgument
163+
* @return string
164+
*/
165+
private function replaceAttributeArgumentInVariable(
166+
$variable,
167+
$arguments,
168+
$attributeValue,
169+
$isInnerArgument = false
170+
) {
171+
// Truncate arg.field into arg
172+
$variableName = strstr($variable, '.', true);
173+
// Check if arguments has a mapping for the given variableName
174+
175+
if ($variableName === false) {
176+
$variableName = $variable;
177+
}
178+
179+
if (!array_key_exists($variableName, $arguments)) {
180+
return $attributeValue;
181+
}
182+
183+
$isPersisted = strstr($arguments[$variableName], '$');
184+
if ($isPersisted) {
185+
return $this->replacePersistedArgument(
186+
$arguments[$variableName],
187+
$attributeValue,
188+
$variable,
189+
$variableName,
190+
$isInnerArgument
191+
);
192+
}
193+
194+
return str_replace($variableName, $arguments[$variableName], $attributeValue);
165195
}
166196

167197
/**

0 commit comments

Comments
 (0)