From 5d318e47de6dd1cd963bce8ec038bc41181aa012 Mon Sep 17 00:00:00 2001 From: KevinBKozan Date: Fri, 23 Mar 2018 08:31:56 -0500 Subject: [PATCH 1/2] MQE-759: Call Operation tags without tying them to an entity - added deleteData url, magentoWebDriver actions --- .../Resources/BasicFunctionalTest.txt | 3 ++ .../TestModule/Test/BasicFunctionalTest.xml | 2 + .../Module/MagentoWebDriver.php | 15 ++++++- .../Test/Objects/ActionObject.php | 27 +++++++++++++ .../Test/etc/Actions/dataActions.xsd | 3 +- .../Util/TestGenerator.php | 40 ++++++++++++++----- 6 files changed, 78 insertions(+), 12 deletions(-) diff --git a/dev/tests/verification/Resources/BasicFunctionalTest.txt b/dev/tests/verification/Resources/BasicFunctionalTest.txt index 9d4a0a3dd..acb7e5f23 100644 --- a/dev/tests/verification/Resources/BasicFunctionalTest.txt +++ b/dev/tests/verification/Resources/BasicFunctionalTest.txt @@ -72,6 +72,9 @@ class BasicFunctionalTestCest $I->clickWithRightButton(".functionalTestSelector"); $I->closeTab(); $I->conditionalClick(".functionalTestSelector", ".functionalDependentTestSelector", true); + $I->amGoingTo("delete entity that has the createDataKey: createKey1"); + $createKey1->deleteEntity(); + $I->deleteByUrl("/V1/categories{$grabbedData}"); $I->dontSee("someInput", ".functionalTestSelector"); $I->dontSeeCheckboxIsChecked(".functionalTestSelector"); $I->dontSeeCookie("someInput"); diff --git a/dev/tests/verification/TestModule/Test/BasicFunctionalTest.xml b/dev/tests/verification/TestModule/Test/BasicFunctionalTest.xml index a2f0d11b0..ead305ee2 100644 --- a/dev/tests/verification/TestModule/Test/BasicFunctionalTest.xml +++ b/dev/tests/verification/TestModule/Test/BasicFunctionalTest.xml @@ -34,6 +34,8 @@ + + diff --git a/src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php b/src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php index 606437cd6..19df6a473 100644 --- a/src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php +++ b/src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php @@ -18,6 +18,7 @@ use Codeception\Exception\ModuleException; use Codeception\Util\Uri; use Codeception\Util\ActionSequence; +use Magento\FunctionalTestingFramework\DataGenerator\Persist\Curl\WebapiExecutor; use Magento\FunctionalTestingFramework\Util\Protocol\CurlTransport; use Magento\FunctionalTestingFramework\Util\Protocol\CurlInterface; use Magento\Setup\Exception; @@ -437,7 +438,6 @@ public function scrollToTopOfPage() */ public function magentoCLI($command) { - $apiURL = $this->config['url'] . getenv('MAGENTO_CLI_COMMAND_PATH'); $executor = new CurlTransport(); $executor->write($apiURL, [getenv('MAGENTO_CLI_COMMAND_PARAMETER') => $command], CurlInterface::POST, []); @@ -446,6 +446,19 @@ public function magentoCLI($command) return $response; } + /** + * Runs a DELETE request against the url given. + * @param string $url + * @param int $storeCode + * @return string + */ + public function deleteByUrl($url, $storeCode = null) + { + $executor = new WebapiExecutor($storeCode); + $executor->write($url, [], CurlInterface::DELETE, []); + return $executor->read(); + } + /** * Conditional click for an area that should be visible * diff --git a/src/Magento/FunctionalTestingFramework/Test/Objects/ActionObject.php b/src/Magento/FunctionalTestingFramework/Test/Objects/ActionObject.php index 24971cef5..a16ce84f8 100644 --- a/src/Magento/FunctionalTestingFramework/Test/Objects/ActionObject.php +++ b/src/Magento/FunctionalTestingFramework/Test/Objects/ActionObject.php @@ -7,6 +7,7 @@ use Magento\FunctionalTestingFramework\DataGenerator\Handlers\DataObjectHandler; use Magento\FunctionalTestingFramework\DataGenerator\Objects\EntityDataObject; +use Magento\FunctionalTestingFramework\Exceptions\XmlException; use Magento\FunctionalTestingFramework\ObjectManager\ObjectHandlerInterface; use Magento\FunctionalTestingFramework\Page\Objects\PageObject; use Magento\FunctionalTestingFramework\Page\Objects\SectionObject; @@ -34,6 +35,7 @@ class ActionObject const ASSERTION_ATTRIBUTES = ["expectedResult" => "expected", "actualResult" => "actual"]; const ASSERTION_TYPE_ATTRIBUTE = "type"; const ASSERTION_VALUE_ATTRIBUTE = "value"; + const DELETE_DATA_MUTUAL_EXCLUSIVE_ATTRIBUTES = ["url", "createDataKey"]; const EXTERNAL_URL_AREA_INVALID_ACTIONS = ['amOnPage']; const MERGE_ACTION_ORDER_AFTER = 'after'; const MERGE_ACTION_ORDER_BEFORE = 'before'; @@ -230,6 +232,9 @@ public function resolveReferences() $this->resolveSelectorReferenceAndTimeout(); $this->resolveUrlReference(); $this->resolveDataInputReferences(); + if ($this->getType() == "deleteData") { + $this->validateMutuallyExclusiveAttributes(self::DELETE_DATA_MUTUAL_EXCLUSIVE_ATTRIBUTES); + } } } @@ -497,6 +502,28 @@ private function findAndReplaceReferences($objectHandler, $inputString) return $outputString; } + /** + * Validates that the mutually exclusive attributes passed in don't all occur. + * @param array $attributes + * @return void + * @throws TestReferenceException + */ + private function validateMutuallyExclusiveAttributes(array $attributes) + { + $matches = array_intersect($attributes, array_keys($this->getCustomActionAttributes())); + if (count($matches) > 1) { + throw new TestReferenceException( + "Actions of type '{$this->getType()}' must only contain one attribute of types '" + . implode("', '", $attributes) . "'" + ); + } elseif (count($matches) == 0) { + throw new TestReferenceException( + "Actions of type '{$this->getType()}' must contain at least one attribute of types '" + . implode("', '", $attributes) . "'" + ); + } + } + /** * Validates the page objects area 'external' against a list of known incompatible types * diff --git a/src/Magento/FunctionalTestingFramework/Test/etc/Actions/dataActions.xsd b/src/Magento/FunctionalTestingFramework/Test/etc/Actions/dataActions.xsd index ad8ea9414..93c07b991 100644 --- a/src/Magento/FunctionalTestingFramework/Test/etc/Actions/dataActions.xsd +++ b/src/Magento/FunctionalTestingFramework/Test/etc/Actions/dataActions.xsd @@ -76,7 +76,8 @@ - + + diff --git a/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php b/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php index 6ca656b71..da795c20b 100644 --- a/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php +++ b/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php @@ -457,6 +457,7 @@ public function generateStepsPhp($actionObjects, $hookObject = false, $actor = " $input = $this->addUniquenessFunctionCall($customActionAttributes['userInput']); } elseif (isset($customActionAttributes['url'])) { $input = $this->addUniquenessFunctionCall($customActionAttributes['url']); + $url = $this->addUniquenessFunctionCall($customActionAttributes['url']); } elseif (isset($customActionAttributes['expectedValue'])) { //For old Assert backwards Compatibility, remove when deprecating $assertExpected = $this->addUniquenessFunctionCall($customActionAttributes['expectedValue']); @@ -660,18 +661,37 @@ public function generateStepsPhp($actionObjects, $hookObject = false, $actor = " $testSteps .= $createEntityFunctionCall; break; case "deleteData": - $key = $customActionAttributes['createDataKey']; - //Add an informative statement to help the user debug test runs - $testSteps .= sprintf( - "\t\t$%s->amGoingTo(\"delete entity that has the createDataKey: %s\");\n", - $actor, - $key - ); + if (isset($customActionAttributes['createDataKey'])) { + $key = $customActionAttributes['createDataKey']; + //Add an informative statement to help the user debug test runs + $testSteps .= sprintf( + "\t\t$%s->amGoingTo(\"delete entity that has the createDataKey: %s\");\n", + $actor, + $key + ); - if ($hookObject) { - $testSteps .= sprintf("\t\t\$this->%s->deleteEntity();\n", $key); + if ($hookObject) { + $testSteps .= sprintf("\t\t\$this->%s->deleteEntity();\n", $key); + } else { + $testSteps .= sprintf("\t\t$%s->deleteEntity();\n", $key); + } } else { - $testSteps .= sprintf("\t\t$%s->deleteEntity();\n", $key); + $output = sprintf( + "\t\t$%s->deleteByUrl(%s", + $actor, + $url + ); + $storeCode = null; + if (isset($customActionAttributes["storeCode"])) { + $storeCode = $customActionAttributes["storeCode"]; + $output .= sprintf( + ", %s", + $storeCode + ); + } + $output .= ");\n"; + $output = $this->resolveEnvReferences($output, [$url, $storeCode]); + $testSteps .= $this->resolveTestVariable($output, [$url, $storeCode], null); } break; case "updateData": From 467afac196c3d800702aa5e8d7eb1c2098eb1e88 Mon Sep 17 00:00:00 2001 From: KevinBKozan Date: Tue, 3 Apr 2018 10:06:55 -0500 Subject: [PATCH 2/2] MQE-759: Call Operation tags without tying them to an entity - Renaming of function to reflect functionality. --- dev/tests/verification/Resources/BasicFunctionalTest.txt | 2 +- .../Module/MagentoWebDriver.php | 8 +++++--- .../FunctionalTestingFramework/Util/TestGenerator.php | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/dev/tests/verification/Resources/BasicFunctionalTest.txt b/dev/tests/verification/Resources/BasicFunctionalTest.txt index acb7e5f23..1d361ad79 100644 --- a/dev/tests/verification/Resources/BasicFunctionalTest.txt +++ b/dev/tests/verification/Resources/BasicFunctionalTest.txt @@ -74,7 +74,7 @@ class BasicFunctionalTestCest $I->conditionalClick(".functionalTestSelector", ".functionalDependentTestSelector", true); $I->amGoingTo("delete entity that has the createDataKey: createKey1"); $createKey1->deleteEntity(); - $I->deleteByUrl("/V1/categories{$grabbedData}"); + $I->deleteEntityByUrl("/V1/categories{$grabbedData}"); $I->dontSee("someInput", ".functionalTestSelector"); $I->dontSeeCheckboxIsChecked(".functionalTestSelector"); $I->dontSeeCookie("someInput"); diff --git a/src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php b/src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php index 19df6a473..25bb65e07 100644 --- a/src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php +++ b/src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php @@ -447,16 +447,18 @@ public function magentoCLI($command) } /** - * Runs a DELETE request against the url given. + * Runs DELETE request to delete a Magento entity against the url given. * @param string $url * @param int $storeCode * @return string */ - public function deleteByUrl($url, $storeCode = null) + public function deleteEntityByUrl($url, $storeCode = null) { $executor = new WebapiExecutor($storeCode); $executor->write($url, [], CurlInterface::DELETE, []); - return $executor->read(); + $response = $executor->read(); + $executor->close(); + return $response; } /** diff --git a/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php b/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php index da795c20b..7fd94bf7b 100644 --- a/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php +++ b/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php @@ -677,7 +677,7 @@ public function generateStepsPhp($actionObjects, $hookObject = false, $actor = " } } else { $output = sprintf( - "\t\t$%s->deleteByUrl(%s", + "\t\t$%s->deleteEntityByUrl(%s", $actor, $url );