From ac47332064911e5b847ecb24965184db735eea45 Mon Sep 17 00:00:00 2001 From: KevinBKozan Date: Wed, 4 Apr 2018 15:18:30 -0500 Subject: [PATCH 1/3] =?UTF-8?q?MQE-913:=20Nested=20Element=20Assertions=20?= =?UTF-8?q?Don=E2=80=99t=20Support=20Action=20Group=20Replacement?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - actionGroupObj now recurses through the attributes, to be able to replace nested array attributes (asserts' expected/actual arrays) --- .../ActionGroupUsingNestedArgument.txt | 33 ++++++++++ .../ActionGroup/BasicActionGroup.xml | 11 ++++ .../TestModule/Test/ActionGroupTest.xml | 6 ++ .../Tests/ActionGroupGenerationTest.php | 11 ++++ .../Test/Objects/ActionGroupObject.php | 65 ++++++++++++------- .../Test/Objects/ActionObject.php | 2 +- 6 files changed, 104 insertions(+), 24 deletions(-) create mode 100644 dev/tests/verification/Resources/ActionGroupUsingNestedArgument.txt diff --git a/dev/tests/verification/Resources/ActionGroupUsingNestedArgument.txt b/dev/tests/verification/Resources/ActionGroupUsingNestedArgument.txt new file mode 100644 index 000000000..b978a3188 --- /dev/null +++ b/dev/tests/verification/Resources/ActionGroupUsingNestedArgument.txt @@ -0,0 +1,33 @@ +grabMultiple("selector"); + $I->assertCount(99, $grabProductsActionGroup); + } +} diff --git a/dev/tests/verification/TestModule/ActionGroup/BasicActionGroup.xml b/dev/tests/verification/TestModule/ActionGroup/BasicActionGroup.xml index 1fec39772..94e7a6b60 100644 --- a/dev/tests/verification/TestModule/ActionGroup/BasicActionGroup.xml +++ b/dev/tests/verification/TestModule/ActionGroup/BasicActionGroup.xml @@ -48,4 +48,15 @@ + + + + + + + + {{count}} + grabProducts + + diff --git a/dev/tests/verification/TestModule/Test/ActionGroupTest.xml b/dev/tests/verification/TestModule/Test/ActionGroupTest.xml index 72617c858..94b9e74dd 100644 --- a/dev/tests/verification/TestModule/Test/ActionGroupTest.xml +++ b/dev/tests/verification/TestModule/Test/ActionGroupTest.xml @@ -114,4 +114,10 @@ + + + + + + diff --git a/dev/tests/verification/Tests/ActionGroupGenerationTest.php b/dev/tests/verification/Tests/ActionGroupGenerationTest.php index e62ea24a5..a26e9ad87 100644 --- a/dev/tests/verification/Tests/ActionGroupGenerationTest.php +++ b/dev/tests/verification/Tests/ActionGroupGenerationTest.php @@ -107,4 +107,15 @@ public function testActionGroupWithStepKeyReferences() { $this->generateAndCompareTest('ActionGroupWithStepKeyReferences'); } + + /** + * Test generation of a test referencing an action group that uses stepKey references (grabFrom/CreateData) + * + * @throws \Exception + * @throws \Magento\FunctionalTestingFramework\Exceptions\TestReferenceException + */ + public function testActionGroupWithNestedArgument() + { + $this->generateAndCompareTest('ActionGroupUsingNestedArgument'); + } } diff --git a/src/Magento/FunctionalTestingFramework/Test/Objects/ActionGroupObject.php b/src/Magento/FunctionalTestingFramework/Test/Objects/ActionGroupObject.php index 90be0a643..4a8f019af 100644 --- a/src/Magento/FunctionalTestingFramework/Test/Objects/ActionGroupObject.php +++ b/src/Magento/FunctionalTestingFramework/Test/Objects/ActionGroupObject.php @@ -125,33 +125,12 @@ private function getResolvedActionsWithArgs($arguments, $actionReferenceKey) { $resolvedActions = []; - // $regexPattern match on: $matches[0] {{section.element(arg.field)}} - // $matches[1] = section.element - // $matches[2] = arg.field - $regexPattern = '/{{([\w.\[\]]+)\(*([\w.$\',\s\[\]]+)*\)*}}/'; - foreach ($this->parsedActions as $action) { $varAttributes = array_intersect($this->varAttributes, array_keys($action->getCustomActionAttributes())); $newActionAttributes = []; if (!empty($varAttributes)) { - // 1 check to see if we have pertinent var - foreach ($varAttributes as $varAttribute) { - $attributeValue = $action->getCustomActionAttributes()[$varAttribute]; - preg_match_all($regexPattern, $attributeValue, $matches); - if (empty($matches[0])) { - continue; - } - - //get rid of full match {{arg.field(arg.field)}} - array_shift($matches); - - $newActionAttributes[$varAttribute] = $this->replaceAttributeArguments( - $arguments, - $attributeValue, - $matches - ); - } + $newActionAttributes = $this->resolveAttributesWithArguments($arguments, $action->getCustomActionAttributes()); } // we append the action reference key to any linked action and the action's merge key as the user might @@ -159,7 +138,7 @@ private function getResolvedActionsWithArgs($arguments, $actionReferenceKey) $resolvedActions[$action->getStepKey() . ucfirst($actionReferenceKey)] = new ActionObject( $action->getStepKey() . ucfirst($actionReferenceKey), $action->getType(), - array_merge($action->getCustomActionAttributes(), $newActionAttributes), + array_replace_recursive($action->getCustomActionAttributes(), $newActionAttributes), $action->getLinkedAction() == null ? null : $action->getLinkedAction() . ucfirst($actionReferenceKey), $action->getOrderOffset(), [self::ACTION_GROUP_ORIGIN_NAME => $this->name, @@ -170,6 +149,46 @@ private function getResolvedActionsWithArgs($arguments, $actionReferenceKey) return $resolvedActions; } + /** + * Resolves all references to arguments in attributes, and subAttributes. + * @param array $arguments + * @param array $attributes + * @return array + */ + private function resolveAttributesWithArguments($arguments, $attributes) + { + // $regexPattern match on: $matches[0] {{section.element(arg.field)}} + // $matches[1] = section.element + // $matches[2] = arg.field + $regexPattern = '/{{([\w.\[\]]+)\(*([\w.$\',\s\[\]]+)*\)*}}/'; + + $newActionAttributes = []; + foreach ($attributes as $attributeKey => $attributeValue) { + + if (is_array($attributeValue)) { + $newActionAttributes[$attributeKey] = $this->resolveAttributesWithArguments($arguments, $attributeValue); + continue; + } + + preg_match_all($regexPattern, $attributeValue, $matches); + + if (empty($matches[0])) { + continue; + } + + //get rid of full match {{arg.field(arg.field)}} + array_shift($matches); + + $newActionAttributes[$attributeKey] = $this->replaceAttributeArguments( + $arguments, + $attributeValue, + $matches + ); + } + return $newActionAttributes; + + } + /** * Function that takes an array of replacement arguments, and matches them with args in an actionGroup's attribute. * Determines if the replacement arguments are persisted data, and replaces them accordingly. diff --git a/src/Magento/FunctionalTestingFramework/Test/Objects/ActionObject.php b/src/Magento/FunctionalTestingFramework/Test/Objects/ActionObject.php index 10cd77937..b8c87f81c 100644 --- a/src/Magento/FunctionalTestingFramework/Test/Objects/ActionObject.php +++ b/src/Magento/FunctionalTestingFramework/Test/Objects/ActionObject.php @@ -20,7 +20,7 @@ class ActionObject { const __ENV = "_ENV"; - const DATA_ENABLED_ATTRIBUTES = ["userInput", "parameterArray", "expected", "actual", "x", "y"]; + const DATA_ENABLED_ATTRIBUTES = ["userInput", "parameterArray", "expected", "actual", "x", "y", "expectedResult", "actualResult"]; const SELECTOR_ENABLED_ATTRIBUTES = [ 'selector', 'dependentSelector', From 0b1a1bc4997cab3710194ee159301fd80d38d72b Mon Sep 17 00:00:00 2001 From: KevinBKozan Date: Wed, 4 Apr 2018 15:23:48 -0500 Subject: [PATCH 2/3] =?UTF-8?q?MQE-913:=20Nested=20Element=20Assertions=20?= =?UTF-8?q?Don=E2=80=99t=20Support=20Action=20Group=20Replacement?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - PHPCS fixes --- .../Test/Objects/ActionGroupObject.php | 10 ++++++++-- .../Test/Objects/ActionObject.php | 11 ++++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/Magento/FunctionalTestingFramework/Test/Objects/ActionGroupObject.php b/src/Magento/FunctionalTestingFramework/Test/Objects/ActionGroupObject.php index 4a8f019af..4b37c1166 100644 --- a/src/Magento/FunctionalTestingFramework/Test/Objects/ActionGroupObject.php +++ b/src/Magento/FunctionalTestingFramework/Test/Objects/ActionGroupObject.php @@ -130,7 +130,10 @@ private function getResolvedActionsWithArgs($arguments, $actionReferenceKey) $newActionAttributes = []; if (!empty($varAttributes)) { - $newActionAttributes = $this->resolveAttributesWithArguments($arguments, $action->getCustomActionAttributes()); + $newActionAttributes = $this->resolveAttributesWithArguments( + $arguments, + $action->getCustomActionAttributes() + ); } // we append the action reference key to any linked action and the action's merge key as the user might @@ -166,7 +169,10 @@ private function resolveAttributesWithArguments($arguments, $attributes) foreach ($attributes as $attributeKey => $attributeValue) { if (is_array($attributeValue)) { - $newActionAttributes[$attributeKey] = $this->resolveAttributesWithArguments($arguments, $attributeValue); + $newActionAttributes[$attributeKey] = $this->resolveAttributesWithArguments( + $arguments, + $attributeValue + ); continue; } diff --git a/src/Magento/FunctionalTestingFramework/Test/Objects/ActionObject.php b/src/Magento/FunctionalTestingFramework/Test/Objects/ActionObject.php index b8c87f81c..ff33423e4 100644 --- a/src/Magento/FunctionalTestingFramework/Test/Objects/ActionObject.php +++ b/src/Magento/FunctionalTestingFramework/Test/Objects/ActionObject.php @@ -20,7 +20,16 @@ class ActionObject { const __ENV = "_ENV"; - const DATA_ENABLED_ATTRIBUTES = ["userInput", "parameterArray", "expected", "actual", "x", "y", "expectedResult", "actualResult"]; + const DATA_ENABLED_ATTRIBUTES = [ + "userInput", + "parameterArray", + "expected", + "actual", + "x", + "y", + "expectedResult", + "actualResult" + ]; const SELECTOR_ENABLED_ATTRIBUTES = [ 'selector', 'dependentSelector', From 3847536f56dca7a1535a55f4bb32e60b0df20b96 Mon Sep 17 00:00:00 2001 From: KevinBKozan Date: Tue, 10 Apr 2018 09:59:36 -0500 Subject: [PATCH 3/3] =?UTF-8?q?MQE-913:=20Nested=20Element=20Assertions=20?= =?UTF-8?q?Don=E2=80=99t=20Support=20Action=20Group=20Replacement?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - CR fix --- .../Test/Objects/ActionGroupObject.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Magento/FunctionalTestingFramework/Test/Objects/ActionGroupObject.php b/src/Magento/FunctionalTestingFramework/Test/Objects/ActionGroupObject.php index 4b37c1166..fdef1107e 100644 --- a/src/Magento/FunctionalTestingFramework/Test/Objects/ActionGroupObject.php +++ b/src/Magento/FunctionalTestingFramework/Test/Objects/ActionGroupObject.php @@ -169,6 +169,7 @@ private function resolveAttributesWithArguments($arguments, $attributes) foreach ($attributes as $attributeKey => $attributeValue) { if (is_array($attributeValue)) { + // attributes with child elements are parsed as an array, need make recursive call to resolve children $newActionAttributes[$attributeKey] = $this->resolveAttributesWithArguments( $arguments, $attributeValue