13 use Magento\FunctionalTestingFramework\Test\Util\ObjectExtension;
44 private $varAttributes;
58 private $parsedActions = [];
72 private $parentActionGroup;
82 public function __construct($name, $arguments, $actions, $parentActionGroup)
84 $this->varAttributes = array_merge(
90 $this->arguments = $arguments;
91 $this->parsedActions = $actions;
92 $this->parentActionGroup = $parentActionGroup;
103 public function getSteps($arguments, $actionReferenceKey)
107 $args = $this->resolveArguments($arguments);
109 return $mergeUtil->resolveActionSteps($this->getResolvedActionsWithArgs($args, $actionReferenceKey),
true);
118 private function resolveArguments($arguments)
120 $resolvedArgumentList = [];
121 $emptyArguments = [];
123 foreach ($this->arguments as $argumentObj) {
124 if ($arguments !==
null && array_key_exists($argumentObj->getName(), $arguments)) {
126 $argumentObj->getName(),
127 $arguments[$argumentObj->getName()],
128 $argumentObj->getDataType()
130 }
elseif ($argumentObj->getValue() ===
null) {
131 $emptyArguments[] = $argumentObj->getName();
133 $resolvedArgumentList[] = $argumentObj;
137 if (!empty($emptyArguments)) {
138 $error =
'Arguments missed (' . implode(
", ", $emptyArguments) .
') for actionGroup "' . $this->
name .
'"';
139 throw new TestReferenceException($error);
142 return $resolvedArgumentList;
153 private function getResolvedActionsWithArgs($arguments, $actionReferenceKey)
155 $resolvedActions = [];
156 $replacementStepKeys = [];
158 foreach ($this->parsedActions as $action) {
159 $replacementStepKeys[$action->getStepKey()] = $action->getStepKey() . ucfirst($actionReferenceKey);
160 $varAttributes = array_intersect($this->varAttributes, array_keys($action->getCustomActionAttributes()));
163 $resolvedActionAttributes = $this->replaceCreateDataKeys($action, $replacementStepKeys);
165 $newActionAttributes = [];
167 if (!empty($varAttributes)) {
168 $newActionAttributes = $this->resolveAttributesWithArguments(
170 $resolvedActionAttributes
176 if ($action->getOrderOffset() === 1) {
182 $resolvedActions[$action->getStepKey() . ucfirst($actionReferenceKey)] =
new ActionObject(
183 $action->getStepKey() . ucfirst($actionReferenceKey),
185 array_replace_recursive($resolvedActionAttributes, $newActionAttributes),
186 $action->getLinkedAction() ==
null ? null : $action->getLinkedAction() . ucfirst($actionReferenceKey),
188 [self::ACTION_GROUP_ORIGIN_NAME => $this->name,
189 self::ACTION_GROUP_ORIGIN_TEST_REF => $actionReferenceKey]
193 return $resolvedActions;
202 private function resolveAttributesWithArguments($arguments,
$attributes)
207 $regexPattern =
'/{{([^(}]+)\(*([^)}]+)*\)*}}/';
209 $newActionAttributes = [];
210 foreach (
$attributes as $attributeKey => $attributeValue) {
211 if (is_array($attributeValue)) {
213 $newActionAttributes[$attributeKey] = $this->resolveAttributesWithArguments(
220 preg_match_all($regexPattern, $attributeValue, $matches);
222 if (empty($matches[0])) {
227 array_shift($matches);
229 $newActionAttributes[$attributeKey] = $this->replaceAttributeArguments(
235 return $newActionAttributes;
247 private function replaceAttributeArguments($arguments, $attributeValue, $matches)
249 list($mainValueList, $possibleArgumentsList) = $matches;
251 foreach ($mainValueList as
$index => $mainValue) {
252 $possibleArguments = $possibleArgumentsList[
$index];
254 $attributeValue = $this->replaceAttributeArgumentInVariable($mainValue, $arguments, $attributeValue);
257 $argumentList = array_filter(array_map(
'trim', explode(
',', $possibleArguments)));
259 foreach ($argumentList as $argumentValue) {
260 $attributeValue = $this->replaceAttributeArgumentInVariable(
269 return $attributeValue;
281 private function replaceAttributeArgumentInVariable(
285 $isInnerArgument =
false 288 $variableName = strstr(
$variable,
'.',
true);
291 if ($variableName ===
false) {
295 $matchedArgument = $this->findArgumentByName($variableName, $arguments);
296 if ($matchedArgument ===
null) {
297 return $attributeValue;
301 return $this->replaceSimpleArgument(
302 $matchedArgument->getResolvedValue($isInnerArgument),
309 $isPersisted = preg_match(
'/\$[\w.\[\]() ]+\$/', $matchedArgument->getResolvedValue($isInnerArgument));
311 return $this->replacePersistedArgument(
312 $matchedArgument->getResolvedValue($isInnerArgument),
322 "/(?<![\w]){$variableName}(?![(\w])/",
323 $matchedArgument->getResolvedValue($isInnerArgument),
337 private function replaceSimpleArgument($argumentValue, $variableName, $attributeValue, $isInnerArgument)
339 if ($isInnerArgument) {
340 return preg_replace(
"/(?<![\w]){$variableName}(?![(\w])/", $argumentValue, $attributeValue);
342 return str_replace(
"{{{$variableName}}}", $argumentValue, $attributeValue);
355 private function replacePersistedArgument(
$replacement, $attributeValue, $fullVariable,
$variable, $isParameter)
358 $hookPersistedArgumentRegex =
'/\$\$[\w.\[\]\',]+\$\$/';
359 $hookPersisted = (preg_match($hookPersistedArgumentRegex,
$replacement));
361 $newAttributeValue = $attributeValue;
364 if ($hookPersisted) {
371 $newAttributeValue = str_replace($fullVariable, $scope . $fullReplacement . $scope, $newAttributeValue);
374 $newAttributeValue = str_replace(
375 '{{' . $fullVariable .
'}}',
376 $scope . $fullReplacement . $scope,
381 return $newAttributeValue;
391 foreach ($this->parsedActions as $action) {
393 foreach (self::STEPKEY_REPLACEMENT_ENABLED_TYPES as $actionValue) {
394 if ($actionValue === $action->getType()) {
395 $originalKeys[] = $action->getStepKey();
399 return $originalKeys;
419 return $this->parentActionGroup;
429 return $this->parsedActions;
439 return $this->arguments;
448 private function findArgumentByName($name, $argumentList)
450 $matchedArgument = array_filter(
452 function ($e) use ($name) {
453 return $e->getName() == $name;
456 if (isset(array_values($matchedArgument)[0])) {
457 return array_values($matchedArgument)[0];
469 private function replaceCreateDataKeys($action, $replacementStepKeys)
471 $resolvedActionAttributes = [];
473 foreach ($action->getCustomActionAttributes() as $actionAttribute => $actionAttributeDetails) {
474 if (is_array($actionAttributeDetails) && array_key_exists(
'createDataKey', $actionAttributeDetails)) {
475 $actionAttributeDetails[
'createDataKey'] =
476 $replacementStepKeys[$actionAttributeDetails[
'createDataKey']] ??
477 $actionAttributeDetails[
'createDataKey'];
479 $resolvedActionAttributes[$actionAttribute] = $actionAttributeDetails;
482 return $resolvedActionAttributes;
const ACTION_GROUP_ORIGIN_TEST_REF
const DATA_ENABLED_ATTRIBUTES
elseif(isset( $params[ 'redirect_parent']))
getSteps($arguments, $actionReferenceKey)
__construct($name, $arguments, $actions, $parentActionGroup)
const MERGE_ACTION_ORDER_AFTER
const ACTION_GROUP_ORIGIN_NAME
const STEPKEY_REPLACEMENT_ENABLED_TYPES
const ARGUMENT_DATA_STRING
const MERGE_ACTION_ORDER_BEFORE
const SELECTOR_ENABLED_ATTRIBUTES
const ACTION_ATTRIBUTE_URL