From d7a15d434d6b14df5ffed6cf5deeecabe2ee2d3c Mon Sep 17 00:00:00 2001 From: KevinBKozan Date: Thu, 29 Mar 2018 13:55:22 -0500 Subject: [PATCH 1/3] MQE-743: Can't run tests without a store having "default" store code - Persistence mechanisms now do not append 'default' where no store code is given (rely on magento web api to redirect to the default) - update/delete data actions no longer allow for a storeCode, relies on handler's storeCode for overrides - create/get data actions take a storeCode, and overwrite the handler's storeCode if given - TestGenerator updates and fixes to make sure create/delete/update/get work and generate as expected. --- .../Persist/Curl/WebapiExecutor.php | 10 ++++++--- .../DataGenerator/Persist/CurlHandler.php | 2 +- .../Persist/DataPersistenceHandler.php | 15 +++---------- .../Test/etc/Actions/dataActions.xsd | 2 -- .../Util/TestGenerator.php | 21 +++++++++++++------ 5 files changed, 26 insertions(+), 24 deletions(-) diff --git a/src/Magento/FunctionalTestingFramework/DataGenerator/Persist/Curl/WebapiExecutor.php b/src/Magento/FunctionalTestingFramework/DataGenerator/Persist/Curl/WebapiExecutor.php index e0a58d470..4994873cb 100644 --- a/src/Magento/FunctionalTestingFramework/DataGenerator/Persist/Curl/WebapiExecutor.php +++ b/src/Magento/FunctionalTestingFramework/DataGenerator/Persist/Curl/WebapiExecutor.php @@ -55,12 +55,16 @@ class WebapiExecutor extends AbstractExecutor implements CurlInterface * * @param string $storeCode */ - public function __construct($storeCode = 'default') + public function __construct($storeCode = null) { if (!isset(parent::$baseUrl)) { parent::resolveBaseUrl(); } + $this->storeCode = $storeCode; + if ($storeCode !== null) { + $this->storeCode = "{$storeCode}/"; + } $this->transport = new CurlTransport(); $this->authorize(); } @@ -72,7 +76,7 @@ public function __construct($storeCode = 'default') */ protected function authorize() { - $authUrl = parent::$baseUrl . 'rest/' . $this->storeCode . self::ADMIN_AUTH_URL; + $authUrl = parent::$baseUrl . 'rest/' . $this->storeCode . trim(self::ADMIN_AUTH_URL, '/'); $authCreds = [ 'username' => getenv('MAGENTO_ADMIN_USERNAME'), 'password' => getenv('MAGENTO_ADMIN_PASSWORD') @@ -97,7 +101,7 @@ protected function authorize() public function write($url, $data = [], $method = CurlInterface::POST, $headers = []) { $this->transport->write( - parent::$baseUrl . 'rest/' . $this->storeCode . '/' . trim($url, '/'), + parent::$baseUrl . 'rest/' . $this->storeCode . trim($url, '/'), json_encode($data, JSON_PRETTY_PRINT), $method, array_unique(array_merge($headers, $this->headers)) diff --git a/src/Magento/FunctionalTestingFramework/DataGenerator/Persist/CurlHandler.php b/src/Magento/FunctionalTestingFramework/DataGenerator/Persist/CurlHandler.php index c72cafc25..63144a9ff 100644 --- a/src/Magento/FunctionalTestingFramework/DataGenerator/Persist/CurlHandler.php +++ b/src/Magento/FunctionalTestingFramework/DataGenerator/Persist/CurlHandler.php @@ -81,7 +81,7 @@ class CurlHandler * @param EntityDataObject $entityObject * @param string $storeCode */ - public function __construct($operation, $entityObject, $storeCode = 'default') + public function __construct($operation, $entityObject, $storeCode = null) { $this->operation = $operation; $this->entityObject = $entityObject; diff --git a/src/Magento/FunctionalTestingFramework/DataGenerator/Persist/DataPersistenceHandler.php b/src/Magento/FunctionalTestingFramework/DataGenerator/Persist/DataPersistenceHandler.php index 6e2f8d2b7..290a14c4e 100644 --- a/src/Magento/FunctionalTestingFramework/DataGenerator/Persist/DataPersistenceHandler.php +++ b/src/Magento/FunctionalTestingFramework/DataGenerator/Persist/DataPersistenceHandler.php @@ -63,7 +63,7 @@ public function __construct($entityObject, $dependentObjects = [], $customFields } else { $this->entityObject = clone $entityObject; } - $this->storeCode = 'default'; + $this->storeCode = null; foreach ($dependentObjects as $dependentObject) { $this->dependentObjects[] = $dependentObject->getCreatedObject(); @@ -96,16 +96,11 @@ public function createEntity($storeCode = null) * * @param string $updateDataName * @param array $updateDependentObjects - * @param string $storeCode * @return void */ - public function updateEntity($updateDataName, $updateDependentObjects = [], $storeCode = null) + public function updateEntity($updateDataName, $updateDependentObjects = []) { - if (!empty($storeCode)) { - $this->storeCode = $storeCode; - } - foreach ($updateDependentObjects as $dependentObject) { $this->dependentObjects[] = $dependentObject->getCreatedObject(); } @@ -146,14 +141,10 @@ public function getEntity($index = null, $storeCode = null) /** * Function which executes a delete request based on specific operation metadata * - * @param string $storeCode * @return void */ - public function deleteEntity($storeCode = null) + public function deleteEntity() { - if (!empty($storeCode)) { - $this->storeCode = $storeCode; - } $curlHandler = new CurlHandler('delete', $this->createdObject, $this->storeCode); $curlHandler->executeRequest($this->dependentObjects); } diff --git a/src/Magento/FunctionalTestingFramework/Test/etc/Actions/dataActions.xsd b/src/Magento/FunctionalTestingFramework/Test/etc/Actions/dataActions.xsd index ad8ea9414..dd8978400 100644 --- a/src/Magento/FunctionalTestingFramework/Test/etc/Actions/dataActions.xsd +++ b/src/Magento/FunctionalTestingFramework/Test/etc/Actions/dataActions.xsd @@ -67,7 +67,6 @@ - @@ -78,7 +77,6 @@ - diff --git a/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php b/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php index c57d7e2c8..6a7792a08 100644 --- a/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php +++ b/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php @@ -669,17 +669,26 @@ public function generateStepsPhp($actionObjects, $hookObject = false, $actor = " case "deleteData": $key = $customActionAttributes['createDataKey']; //Add an informative statement to help the user debug test runs - $testSteps .= sprintf( + $contextSetter = sprintf( "\t\t$%s->amGoingTo(\"delete entity that has the createDataKey: %s\");\n", $actor, $key ); - + $deleteEntityFunctionCall = ""; if ($hookObject) { - $testSteps .= sprintf("\t\t\$this->%s->deleteEntity();\n", $key); + $deleteEntityFunctionCall .= sprintf("\t\t\$this->%s->deleteEntity(", $key); } else { - $testSteps .= sprintf("\t\t$%s->deleteEntity();\n", $key); + $deleteEntityFunctionCall .= sprintf("\t\t$%s->deleteEntity(", $key); } + + if (isset($customActionAttributes['storeCode'])) { + $deleteEntityFunctionCall .= sprintf("\"%s\");\n", $customActionAttributes['storeCode']); + } else { + $deleteEntityFunctionCall .= ");\n"; + } + + $testSteps .= $contextSetter; + $testSteps .= $deleteEntityFunctionCall; break; case "updateData": $key = $customActionAttributes['createDataKey']; @@ -728,7 +737,7 @@ public function generateStepsPhp($actionObjects, $hookObject = false, $actor = " } if (isset($customActionAttributes['storeCode'])) { - $updateEntityFunctionCall .= sprintf("\"%s\");\n", $customActionAttributes['storeCode']); + $updateEntityFunctionCall .= sprintf(", \"%s\");\n", $customActionAttributes['storeCode']); } else { $updateEntityFunctionCall .= ");\n"; } @@ -789,7 +798,7 @@ public function generateStepsPhp($actionObjects, $hookObject = false, $actor = " } if (isset($customActionAttributes['index'])) { - $getEntityFunctionCall .= sprintf("%s", (int)$customActionAttributes['index']); + $getEntityFunctionCall .= sprintf(", %s", (int)$customActionAttributes['index']); } else { $getEntityFunctionCall .= 'null'; } From a368082a3fde0b93051728e8c0f4a6a7cf527eed Mon Sep 17 00:00:00 2001 From: KevinBKozan Date: Wed, 4 Apr 2018 08:41:53 -0500 Subject: [PATCH 2/3] MQE-743: Can't run tests without a store having "default" store code - CR Fixes --- .../Persist/Curl/WebapiExecutor.php | 19 ++++++++++++++++-- .../Util/TestGenerator.php | 20 +++++++++++-------- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/src/Magento/FunctionalTestingFramework/DataGenerator/Persist/Curl/WebapiExecutor.php b/src/Magento/FunctionalTestingFramework/DataGenerator/Persist/Curl/WebapiExecutor.php index 4994873cb..f06aa6c4b 100644 --- a/src/Magento/FunctionalTestingFramework/DataGenerator/Persist/Curl/WebapiExecutor.php +++ b/src/Magento/FunctionalTestingFramework/DataGenerator/Persist/Curl/WebapiExecutor.php @@ -76,7 +76,7 @@ public function __construct($storeCode = null) */ protected function authorize() { - $authUrl = parent::$baseUrl . 'rest/' . $this->storeCode . trim(self::ADMIN_AUTH_URL, '/'); + $authUrl = $this->getFormattedUrl(self::ADMIN_AUTH_URL); $authCreds = [ 'username' => getenv('MAGENTO_ADMIN_USERNAME'), 'password' => getenv('MAGENTO_ADMIN_PASSWORD') @@ -101,7 +101,7 @@ protected function authorize() public function write($url, $data = [], $method = CurlInterface::POST, $headers = []) { $this->transport->write( - parent::$baseUrl . 'rest/' . $this->storeCode . trim($url, '/'), + $this->getFormattedUrl($url), json_encode($data, JSON_PRETTY_PRINT), $method, array_unique(array_merge($headers, $this->headers)) @@ -142,4 +142,19 @@ public function close() { $this->transport->close(); } + + /** + * Builds and returns URL for request, appending storeCode if needed. + * @param string $resource + * @return string + */ + public function getFormattedUrl($resource) + { + $urlResult = parent::$baseUrl . 'rest/'; + if ($this->storeCode != null) { + $urlResult .= $this->storeCode . "/"; + } + $urlResult.= trim($resource, "/"); + return $urlResult; + } } diff --git a/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php b/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php index c967d40be..a1d5ad2de 100644 --- a/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php +++ b/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php @@ -438,6 +438,7 @@ public function generateStepsPhp($actionObjects, $hookObject = false, $actor = " $visible = null; $command = null; $sortOrder = null; + $storeCode = null; $assertExpected = null; $assertActual = null; @@ -592,6 +593,9 @@ public function generateStepsPhp($actionObjects, $hookObject = false, $actor = " $visible = $customActionAttributes['visible']; } + if (isset($customActionAttributes['storeCode'])) { + $storeCode = $customActionAttributes['storeCode']; + } switch ($actionObject->getType()) { case "createData": $entity = $customActionAttributes['entity']; @@ -648,8 +652,8 @@ public function generateStepsPhp($actionObjects, $hookObject = false, $actor = " ); } - if (isset($customActionAttributes['storeCode'])) { - $createEntityFunctionCall .= sprintf("\"%s\");\n", $customActionAttributes['storeCode']); + if (isset($storeCode)) { + $createEntityFunctionCall .= sprintf("\"%s\");\n", $storeCode); } else { $createEntityFunctionCall .= ");\n"; } @@ -684,8 +688,8 @@ public function generateStepsPhp($actionObjects, $hookObject = false, $actor = " $deleteEntityFunctionCall .= sprintf("\t\t$%s->deleteEntity(", $key); } - if (isset($customActionAttributes['storeCode'])) { - $deleteEntityFunctionCall .= sprintf("\"%s\");\n", $customActionAttributes['storeCode']); + if (isset($storeCode)) { + $deleteEntityFunctionCall .= sprintf("\"%s\");\n", $storeCode); } else { $deleteEntityFunctionCall .= ");\n"; } @@ -739,8 +743,8 @@ public function generateStepsPhp($actionObjects, $hookObject = false, $actor = " ); } - if (isset($customActionAttributes['storeCode'])) { - $updateEntityFunctionCall .= sprintf(", \"%s\");\n", $customActionAttributes['storeCode']); + if (isset($storeCode)) { + $updateEntityFunctionCall .= sprintf(", \"%s\");\n", $storeCode); } else { $updateEntityFunctionCall .= ");\n"; } @@ -806,8 +810,8 @@ public function generateStepsPhp($actionObjects, $hookObject = false, $actor = " $getEntityFunctionCall .= 'null'; } - if (isset($customActionAttributes['storeCode'])) { - $getEntityFunctionCall .= sprintf(", \"%s\");\n", $customActionAttributes['storeCode']); + if (isset($storeCode)) { + $getEntityFunctionCall .= sprintf(", \"%s\");\n", $storeCode); } else { $getEntityFunctionCall .= ");\n"; } From ef12078136e04b0db6384621f2424d6e305fb688 Mon Sep 17 00:00:00 2001 From: KevinBKozan Date: Wed, 4 Apr 2018 08:43:59 -0500 Subject: [PATCH 3/3] MQE-743: Can't run tests without a store having "default" store code - CR Fixes --- .../DataGenerator/Persist/Curl/WebapiExecutor.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Magento/FunctionalTestingFramework/DataGenerator/Persist/Curl/WebapiExecutor.php b/src/Magento/FunctionalTestingFramework/DataGenerator/Persist/Curl/WebapiExecutor.php index f06aa6c4b..9a93cded3 100644 --- a/src/Magento/FunctionalTestingFramework/DataGenerator/Persist/Curl/WebapiExecutor.php +++ b/src/Magento/FunctionalTestingFramework/DataGenerator/Persist/Curl/WebapiExecutor.php @@ -62,9 +62,6 @@ public function __construct($storeCode = null) } $this->storeCode = $storeCode; - if ($storeCode !== null) { - $this->storeCode = "{$storeCode}/"; - } $this->transport = new CurlTransport(); $this->authorize(); }