diff --git a/src/Magento/FunctionalTestingFramework/DataGenerator/Persist/Curl/WebapiExecutor.php b/src/Magento/FunctionalTestingFramework/DataGenerator/Persist/Curl/WebapiExecutor.php index e0a58d470..9a93cded3 100644 --- a/src/Magento/FunctionalTestingFramework/DataGenerator/Persist/Curl/WebapiExecutor.php +++ b/src/Magento/FunctionalTestingFramework/DataGenerator/Persist/Curl/WebapiExecutor.php @@ -55,11 +55,12 @@ 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; $this->transport = new CurlTransport(); $this->authorize(); @@ -72,7 +73,7 @@ public function __construct($storeCode = 'default') */ protected function authorize() { - $authUrl = parent::$baseUrl . 'rest/' . $this->storeCode . self::ADMIN_AUTH_URL; + $authUrl = $this->getFormattedUrl(self::ADMIN_AUTH_URL); $authCreds = [ 'username' => getenv('MAGENTO_ADMIN_USERNAME'), 'password' => getenv('MAGENTO_ADMIN_PASSWORD') @@ -97,7 +98,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)) @@ -138,4 +139,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/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/Module/MagentoWebDriver.php b/src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php index 25bb65e07..cfffac9bc 100644 --- a/src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php +++ b/src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php @@ -449,12 +449,11 @@ public function magentoCLI($command) /** * Runs DELETE request to delete a Magento entity against the url given. * @param string $url - * @param int $storeCode * @return string */ - public function deleteEntityByUrl($url, $storeCode = null) + public function deleteEntityByUrl($url) { - $executor = new WebapiExecutor($storeCode); + $executor = new WebapiExecutor(null); $executor->write($url, [], CurlInterface::DELETE, []); $response = $executor->read(); $executor->close(); diff --git a/src/Magento/FunctionalTestingFramework/Test/etc/Actions/dataActions.xsd b/src/Magento/FunctionalTestingFramework/Test/etc/Actions/dataActions.xsd index 93c07b991..1a7ea2d78 100644 --- a/src/Magento/FunctionalTestingFramework/Test/etc/Actions/dataActions.xsd +++ b/src/Magento/FunctionalTestingFramework/Test/etc/Actions/dataActions.xsd @@ -67,7 +67,6 @@ - @@ -79,7 +78,6 @@ - diff --git a/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php b/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php index 0d30717a2..73be6295a 100644 --- a/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php +++ b/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php @@ -481,6 +481,7 @@ public function generateStepsPhp($actionObjects, $hookObject = false, $actor = " $visible = null; $command = null; $sortOrder = null; + $storeCode = null; $assertExpected = null; $assertActual = null; @@ -635,6 +636,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']; @@ -691,8 +695,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"; } @@ -716,34 +720,29 @@ public function generateStepsPhp($actionObjects, $hookObject = false, $actor = " if (isset($customActionAttributes['createDataKey'])) { $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();\n", $key); } else { - $testSteps .= sprintf("\t\t$%s->deleteEntity();\n", $key); + $deleteEntityFunctionCall .= sprintf("\t\t$%s->deleteEntity();\n", $key); } + + $testSteps .= $contextSetter; + $testSteps .= $deleteEntityFunctionCall; } else { $output = sprintf( - "\t\t$%s->deleteEntityByUrl(%s", + "\t\t$%s->deleteEntityByUrl(%s);\n", $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); + $output = $this->resolveEnvReferences($output, [$url]); + $testSteps .= $this->resolveTestVariable($output, [$url], null); } break; case "updateData": @@ -792,8 +791,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"; } @@ -854,13 +853,13 @@ 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'; } - if (isset($customActionAttributes['storeCode'])) { - $getEntityFunctionCall .= sprintf(", \"%s\");\n", $customActionAttributes['storeCode']); + if (isset($storeCode)) { + $getEntityFunctionCall .= sprintf(", \"%s\");\n", $storeCode); } else { $getEntityFunctionCall .= ");\n"; }