From 6c773971d5b81098180340f1e59ceb5009edcc7f Mon Sep 17 00:00:00 2001 From: KevinBKozan Date: Wed, 4 Apr 2018 13:56:55 -0500 Subject: [PATCH 1/3] MQE-905: Persistent entity variable not interpolated with page urls with type "admin" - resolveEnvReferences now alters the passed in set of $args, allowing further use of the new $args. --- .../verification/Resources/PersistedReplacementTest.txt | 1 + .../TestModule/Test/PersistedReplacementTest.xml | 1 + .../FunctionalTestingFramework/Util/TestGenerator.php | 8 ++++++-- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/dev/tests/verification/Resources/PersistedReplacementTest.txt b/dev/tests/verification/Resources/PersistedReplacementTest.txt index ca09c767e..2c335c7f0 100644 --- a/dev/tests/verification/Resources/PersistedReplacementTest.txt +++ b/dev/tests/verification/Resources/PersistedReplacementTest.txt @@ -50,6 +50,7 @@ class PersistedReplacementTestCest $createdData->createEntity(); $I->fillField("#selector", "StringBefore " . $createdData->getCreatedDataByName('firstname') . " StringAfter"); $I->fillField("#" . $createdData->getCreatedDataByName('firstname'), "input"); + $I->fillField("#" . getenv("MAGENTO_BASE_URL") . "#" . $createdData->getCreatedDataByName('firstname'), "input"); $I->dragAndDrop("#" . $createdData->getCreatedDataByName('firstname'), $createdData->getCreatedDataByName('lastname')); $I->conditionalClick($createdData->getCreatedDataByName('lastname'), "#" . $createdData->getCreatedDataByName('firstname'), true); $I->amOnUrl($createdData->getCreatedDataByName('firstname') . ".html"); diff --git a/dev/tests/verification/TestModule/Test/PersistedReplacementTest.xml b/dev/tests/verification/TestModule/Test/PersistedReplacementTest.xml index d46381748..26885fda4 100644 --- a/dev/tests/verification/TestModule/Test/PersistedReplacementTest.xml +++ b/dev/tests/verification/TestModule/Test/PersistedReplacementTest.xml @@ -16,6 +16,7 @@ + diff --git a/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php b/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php index 4a51906c0..bf0a03215 100644 --- a/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php +++ b/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php @@ -1685,13 +1685,14 @@ private function wrapFunctionCallWithReturnValue($returnVariable, $actor, $actio * @param array $args * @return string */ - private function resolveEnvReferences($inputString, $args) + private function resolveEnvReferences($inputString, &$args) { $envRegex = "/{{_ENV\.([\w]+)}}/"; $outputString = $inputString; + $newArgs = []; - foreach ($args as $arg) { + foreach ($args as $key => $arg) { preg_match_all($envRegex, $arg, $matches); if (!empty($matches[0])) { $fullMatch = $matches[0][0]; @@ -1701,9 +1702,12 @@ private function resolveEnvReferences($inputString, $args) $outputArg = $this->processQuoteBreaks($fullMatch, $arg, $replacement); $outputString = str_replace($arg, $outputArg, $outputString); + $newArgs[$key] = $outputArg; } } + // override passed in args for use later. + $args = array_merge($args, $newArgs); return $outputString; } From 219761592f84b627bc72c415dd09d8f051e19bff Mon Sep 17 00:00:00 2001 From: KevinBKozan Date: Thu, 5 Apr 2018 15:57:46 -0500 Subject: [PATCH 2/3] MQE-905: Persistent entity variable not interpolated with page urls with type "admin" - Refactored resolve* functions to consume and transform $args instead of the whole string. --- .../Util/TestGenerator.php | 67 ++++++++----------- 1 file changed, 28 insertions(+), 39 deletions(-) diff --git a/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php b/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php index 9a311f8c1..b895a53f5 100644 --- a/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php +++ b/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php @@ -736,13 +736,14 @@ public function generateStepsPhp($actionObjects, $hookObject = false, $actor = " $testSteps .= $contextSetter; $testSteps .= $deleteEntityFunctionCall; } else { + $url = $this->resolveEnvReferences([$url])[0]; + $url = $this->resolveTestVariable([$url], null)[0]; $output = sprintf( "\t\t$%s->deleteEntityByUrl(%s);\n", $actor, $url ); - $output = $this->resolveEnvReferences($output, [$url]); - $testSteps .= $this->resolveTestVariable($output, [$url], null); + $testSteps .= $output; } break; case "updateData": @@ -1215,9 +1216,10 @@ public function generateStepsPhp($actionObjects, $hookObject = false, $actor = " break; case "field": $fieldKey = $actionObject->getCustomActionAttributes()['key']; + $input = $this->resolveTestVariable([$input], $actionObject->getActionOrigin())[0]; $argRef = "\t\t\$"; $argRef .= str_replace(ucfirst($fieldKey), "", $stepKey) . "Fields['{$fieldKey}'] = ${input};\n"; - $testSteps .= $this->resolveTestVariable($argRef, [$input], $actionObject->getActionOrigin()); + $testSteps .= $argRef; break; default: $testSteps .= $this->wrapFunctionCall($actor, $actionObject, $selector, $input, $parameter); @@ -1246,18 +1248,15 @@ private function resolveLocatorFunctionInAttribute($attribute) * Resolves replacement of $input$ and $$input$$ in given function, recursing and replacing individual arguments * Also determines if each argument requires any quote replacement. * - * @param string $inputString * @param array $args * @param array $actionOrigin - * @return string + * @return array * @throws \Exception */ - private function resolveTestVariable($inputString, $args, $actionOrigin) + private function resolveTestVariable($args, $actionOrigin) { - $outputString = $inputString; - //Loop through each argument, replace and then replace - foreach ($args as $arg) { + foreach ($args as $key => $arg) { if ($arg == null) { continue; } @@ -1275,10 +1274,10 @@ private function resolveTestVariable($inputString, $args, $actionOrigin) $outputArg = $this->resolveStepKeyReferences($outputArg, $actionOrigin); - $outputString = str_replace($arg, $outputArg, $outputString); + $args[$key] = $outputArg; } - return $outputString; + return $args; } /** @@ -1653,20 +1652,17 @@ private function wrapFunctionCall($actor, $action, ...$args) if (null === $args[$i]) { continue; } - if (!$isFirst) { - $output .= ', '; - } if ($args[$i] === "") { $args[$i] = '"' . $args[$i] . '"'; } - $output .= $args[$i]; - $isFirst = false; } - $output .= ");\n"; - - $output = $this->resolveEnvReferences($output, $args); - - return $this->resolveTestVariable($output, $args, $action->getActionOrigin()); + if (!is_array($args)) { + $args = [$args]; + } + $newArgs = $this->resolveEnvReferences($args); + $newArgs = $this->resolveTestVariable($newArgs, $action->getActionOrigin()); + $output .= implode(", ", array_filter($newArgs, function($value) { return $value !== null; })) . ");\n"; + return $output; } /** @@ -1687,34 +1683,29 @@ private function wrapFunctionCallWithReturnValue($returnVariable, $actor, $actio if (null === $args[$i]) { continue; } - if (!$isFirst) { - $output .= ', '; - } if ($args[$i] === "") { $args[$i] = '"' . $args[$i] . '"'; } - $output .= $args[$i]; - $isFirst = false; } - $output .= ");\n"; - - $output = $this->resolveEnvReferences($output, $args); - - return $this->resolveTestVariable($output, $args, $action->getActionOrigin()); + if (!is_array($args)) { + $args = [$args]; + } + $newArgs = $this->resolveEnvReferences($args); + $newArgs = $this->resolveTestVariable($newArgs, $action->getActionOrigin()); + $output .= implode(", ", array_filter($newArgs, function($value) { return $value !== null; })) . ");\n"; + return $output; } // @codingStandardsIgnoreEnd /** * Resolves {{_ENV.variable}} into getenv("variable") for test-runtime ENV referencing. - * @param string $inputString * @param array $args - * @return string + * @return array */ - private function resolveEnvReferences($inputString, &$args) + private function resolveEnvReferences($args) { $envRegex = "/{{_ENV\.([\w]+)}}/"; - $outputString = $inputString; $newArgs = []; foreach ($args as $key => $arg) { @@ -1726,14 +1717,12 @@ private function resolveEnvReferences($inputString, &$args) $replacement = "getenv(\"{$envVariable}\")"; $outputArg = $this->processQuoteBreaks($fullMatch, $arg, $replacement); - $outputString = str_replace($arg, $outputArg, $outputString); - $newArgs[$key] = $outputArg; + $args[$key] = $outputArg; } } // override passed in args for use later. - $args = array_merge($args, $newArgs); - return $outputString; + return $args; } /** From c6236513866e92864492adc114d43f8c6b848b62 Mon Sep 17 00:00:00 2001 From: KevinBKozan Date: Mon, 9 Apr 2018 15:57:20 -0500 Subject: [PATCH 3/3] MQE-905: Persistent entity variable not interpolated with page urls with type "admin" - CR Fixes - verification fixes. --- .../Util/TestGenerator.php | 32 ++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php b/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php index b895a53f5..83ef48d6a 100644 --- a/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php +++ b/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php @@ -695,7 +695,7 @@ public function generateStepsPhp($actionObjects, $hookObject = false, $actor = " ); } - if (isset($storeCode)) { + if ($storeCode) { $createEntityFunctionCall .= sprintf("\"%s\");\n", $storeCode); } else { $createEntityFunctionCall .= ");\n"; @@ -792,7 +792,7 @@ public function generateStepsPhp($actionObjects, $hookObject = false, $actor = " ); } - if (isset($storeCode)) { + if ($storeCode) { $updateEntityFunctionCall .= sprintf(", \"%s\");\n", $storeCode); } else { $updateEntityFunctionCall .= ");\n"; @@ -859,7 +859,7 @@ public function generateStepsPhp($actionObjects, $hookObject = false, $actor = " $getEntityFunctionCall .= 'null'; } - if (isset($storeCode)) { + if ($storeCode) { $getEntityFunctionCall .= sprintf(", \"%s\");\n", $storeCode); } else { $getEntityFunctionCall .= ");\n"; @@ -1255,9 +1255,9 @@ private function resolveLocatorFunctionInAttribute($attribute) */ private function resolveTestVariable($args, $actionOrigin) { - //Loop through each argument, replace and then replace + $newArgs = []; foreach ($args as $key => $arg) { - if ($arg == null) { + if ($arg === null) { continue; } $outputArg = $arg; @@ -1274,10 +1274,10 @@ private function resolveTestVariable($args, $actionOrigin) $outputArg = $this->resolveStepKeyReferences($outputArg, $actionOrigin); - $args[$key] = $outputArg; + $newArgs[$key] = $outputArg; } - return $args; + return $newArgs; } /** @@ -1659,9 +1659,9 @@ private function wrapFunctionCall($actor, $action, ...$args) if (!is_array($args)) { $args = [$args]; } - $newArgs = $this->resolveEnvReferences($args); - $newArgs = $this->resolveTestVariable($newArgs, $action->getActionOrigin()); - $output .= implode(", ", array_filter($newArgs, function($value) { return $value !== null; })) . ");\n"; + $args = $this->resolveEnvReferences($args); + $args = $this->resolveTestVariable($args, $action->getActionOrigin()); + $output .= implode(", ", array_filter($args, function($value) { return $value !== null; })) . ");\n"; return $output; } @@ -1690,9 +1690,9 @@ private function wrapFunctionCallWithReturnValue($returnVariable, $actor, $actio if (!is_array($args)) { $args = [$args]; } - $newArgs = $this->resolveEnvReferences($args); - $newArgs = $this->resolveTestVariable($newArgs, $action->getActionOrigin()); - $output .= implode(", ", array_filter($newArgs, function($value) { return $value !== null; })) . ");\n"; + $args = $this->resolveEnvReferences($args); + $args = $this->resolveTestVariable($args, $action->getActionOrigin()); + $output .= implode(", ", array_filter($args, function($value) { return $value !== null; })) . ");\n"; return $output; } // @codingStandardsIgnoreEnd @@ -1717,12 +1717,14 @@ private function resolveEnvReferences($args) $replacement = "getenv(\"{$envVariable}\")"; $outputArg = $this->processQuoteBreaks($fullMatch, $arg, $replacement); - $args[$key] = $outputArg; + $newArgs[$key] = $outputArg; + continue; } + $newArgs[$key] = $arg; } // override passed in args for use later. - return $args; + return $newArgs; } /**