From 445d3394b950ae8fd4c0e7c81a48c68de04c4610 Mon Sep 17 00:00:00 2001 From: KevinBKozan Date: Mon, 26 Feb 2018 14:09:37 -0600 Subject: [PATCH 1/3] MQE-820: MSI form posts use a single "/admin/" vs "/admin/admin/" URLs used in other areas of the Admin. - Merge of test branch into proper MQE branch. - Renamed to removeBackend - test fixes --- .../unit/Util/OperationDefinitionBuilder.php | 9 ++++++++- .../OperationDefinitionObjectHandler.php | 3 +++ .../Objects/OperationDefinitionObject.php | 20 +++++++++++++++++++ .../Persist/Curl/AdminExecutor.php | 15 +++++++++++++- .../DataGenerator/Persist/CurlHandler.php | 2 +- .../DataGenerator/etc/dataOperation.xsd | 1 + 6 files changed, 47 insertions(+), 3 deletions(-) diff --git a/dev/tests/unit/Util/OperationDefinitionBuilder.php b/dev/tests/unit/Util/OperationDefinitionBuilder.php index 366cb6f86..abd5c38f1 100644 --- a/dev/tests/unit/Util/OperationDefinitionBuilder.php +++ b/dev/tests/unit/Util/OperationDefinitionBuilder.php @@ -37,6 +37,12 @@ class OperationDefinitionBuilder */ private $metadata = []; + /** + * Determines if api URL should remove magento_backend_name. + * @var bool + */ + private $removeBackend; + /** * Function which builds an operation defintions based on the fields set by the user. * @@ -54,7 +60,8 @@ public function build() null, null, $this->metadata, - null + null, + false ); } diff --git a/src/Magento/FunctionalTestingFramework/DataGenerator/Handlers/OperationDefinitionObjectHandler.php b/src/Magento/FunctionalTestingFramework/DataGenerator/Handlers/OperationDefinitionObjectHandler.php index bdca97e72..50b8fe039 100644 --- a/src/Magento/FunctionalTestingFramework/DataGenerator/Handlers/OperationDefinitionObjectHandler.php +++ b/src/Magento/FunctionalTestingFramework/DataGenerator/Handlers/OperationDefinitionObjectHandler.php @@ -42,6 +42,7 @@ class OperationDefinitionObjectHandler implements ObjectHandlerInterface const ENTITY_OPERATION_OBJECT_KEY = 'key'; const ENTITY_OPERATION_OBJECT_VALUE = 'value'; const ENTITY_OPERATION_REQUIRED = 'required'; + const ENTITY_OPERATION_BACKEND_REMOVE = 'removeBackendName'; /** * The singleton instance of this class @@ -149,6 +150,7 @@ private function initialize() $headers = []; $params = []; $operationElements = []; + $removeBackend = $opDefArray[OperationDefinitionObjectHandler::ENTITY_OPERATION_BACKEND_REMOVE] ?? true; // TODO remove this warning with 2.1.0 release $backendName = getenv('MAGENTO_BACKEND_NAME'); @@ -238,6 +240,7 @@ private function initialize() $params, $operationElements, $contentType, + $removeBackend, $successRegex, $returnRegex ); diff --git a/src/Magento/FunctionalTestingFramework/DataGenerator/Objects/OperationDefinitionObject.php b/src/Magento/FunctionalTestingFramework/DataGenerator/Objects/OperationDefinitionObject.php index 043eb8883..335516144 100644 --- a/src/Magento/FunctionalTestingFramework/DataGenerator/Objects/OperationDefinitionObject.php +++ b/src/Magento/FunctionalTestingFramework/DataGenerator/Objects/OperationDefinitionObject.php @@ -104,6 +104,12 @@ class OperationDefinitionObject */ private $returnRegex; + /** + * Determines if operation should remove backend_name from URL. + * @var bool + */ + private $removeBackend; + /** * OperationDefinitionObject constructor. * @param string $name @@ -116,6 +122,7 @@ class OperationDefinitionObject * @param array $params * @param array $metaData * @param string $contentType + * @param bool $removeBackend * @param string $successRegex * @param string $returnRegex * @SuppressWarnings(PHPMD.ExcessiveParameterList) @@ -131,6 +138,7 @@ public function __construct( $params, $metaData, $contentType, + $removeBackend, $successRegex = null, $returnRegex = null ) { @@ -145,6 +153,7 @@ public function __construct( $this->operationMetadata = $metaData; $this->successRegex = $successRegex; $this->returnRegex = $returnRegex; + $this->removeBackend = $removeBackend; $this->apiUrl = null; if (!empty($contentType)) { @@ -152,6 +161,7 @@ public function __construct( } else { $this->contentType = 'application/x-www-form-urlencoded'; } + // add content type as a header $this->headers[] = self::HTTP_CONTENT_TYPE_HEADER . ': ' . $this->contentType; } @@ -231,6 +241,16 @@ public function getHeaders() return $this->headers; } + /** + * Getter for removeBackend + * + * @return bool + */ + public function removeUrlBackend() + { + return $this->removeBackend; + } + /** * Getter for Content-type * diff --git a/src/Magento/FunctionalTestingFramework/DataGenerator/Persist/Curl/AdminExecutor.php b/src/Magento/FunctionalTestingFramework/DataGenerator/Persist/Curl/AdminExecutor.php index 3fe613771..421302d8a 100644 --- a/src/Magento/FunctionalTestingFramework/DataGenerator/Persist/Curl/AdminExecutor.php +++ b/src/Magento/FunctionalTestingFramework/DataGenerator/Persist/Curl/AdminExecutor.php @@ -36,6 +36,12 @@ class AdminExecutor extends AbstractExecutor implements CurlInterface */ private $response; + /** + * Should executor remove backend_name from api url + * @var bool + */ + private $removeBackend; + /** * Backend url. * @@ -45,15 +51,17 @@ class AdminExecutor extends AbstractExecutor implements CurlInterface /** * Constructor. + * @param bool $removeBackend * * @constructor */ - public function __construct() + public function __construct($removeBackend) { if (!isset(parent::$baseUrl)) { parent::resolveBaseUrl(); } self::$adminUrl = parent::$baseUrl . getenv('MAGENTO_BACKEND_NAME') . '/'; + $this->removeBackend = $removeBackend; $this->transport = new CurlTransport(); $this->authorize(); } @@ -110,6 +118,11 @@ private function setFormKey() public function write($url, $data = [], $method = CurlInterface::POST, $headers = []) { $apiUrl = self::$adminUrl . $url; + + if (!$this->removeBackend) { + $apiUrl = parent::$baseUrl . ltrim($url, '/'); + } + if ($this->formKey) { $data['form_key'] = $this->formKey; } else { diff --git a/src/Magento/FunctionalTestingFramework/DataGenerator/Persist/CurlHandler.php b/src/Magento/FunctionalTestingFramework/DataGenerator/Persist/CurlHandler.php index 488e45829..15c3677d7 100644 --- a/src/Magento/FunctionalTestingFramework/DataGenerator/Persist/CurlHandler.php +++ b/src/Magento/FunctionalTestingFramework/DataGenerator/Persist/CurlHandler.php @@ -131,7 +131,7 @@ public function executeRequest($dependentEntities) $this->isJson = true; $executor = new WebapiExecutor($this->storeCode); } elseif ($authorization === 'adminFormKey') { - $executor = new AdminExecutor(); + $executor = new AdminExecutor($this->operationDefinition->removeUrlBackend()); } elseif ($authorization === 'customerFormKey') { $executor = new FrontendExecutor( $this->requestData['customer_email'], diff --git a/src/Magento/FunctionalTestingFramework/DataGenerator/etc/dataOperation.xsd b/src/Magento/FunctionalTestingFramework/DataGenerator/etc/dataOperation.xsd index 429e0e212..4d2a93c8f 100644 --- a/src/Magento/FunctionalTestingFramework/DataGenerator/etc/dataOperation.xsd +++ b/src/Magento/FunctionalTestingFramework/DataGenerator/etc/dataOperation.xsd @@ -25,6 +25,7 @@ + From 2b0717bde88e727ffe5329738ad16cc018428975 Mon Sep 17 00:00:00 2001 From: KevinBKozan Date: Tue, 27 Feb 2018 09:33:35 -0600 Subject: [PATCH 2/3] MQE-820: MSI form posts use a single "/admin/" vs "/admin/admin/" URLs used in other areas of the Admin. - backwards logic reversal. --- .../DataGenerator/Handlers/OperationDefinitionObjectHandler.php | 2 +- .../DataGenerator/Persist/Curl/AdminExecutor.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Magento/FunctionalTestingFramework/DataGenerator/Handlers/OperationDefinitionObjectHandler.php b/src/Magento/FunctionalTestingFramework/DataGenerator/Handlers/OperationDefinitionObjectHandler.php index 50b8fe039..e34ca29f1 100644 --- a/src/Magento/FunctionalTestingFramework/DataGenerator/Handlers/OperationDefinitionObjectHandler.php +++ b/src/Magento/FunctionalTestingFramework/DataGenerator/Handlers/OperationDefinitionObjectHandler.php @@ -150,7 +150,7 @@ private function initialize() $headers = []; $params = []; $operationElements = []; - $removeBackend = $opDefArray[OperationDefinitionObjectHandler::ENTITY_OPERATION_BACKEND_REMOVE] ?? true; + $removeBackend = $opDefArray[OperationDefinitionObjectHandler::ENTITY_OPERATION_BACKEND_REMOVE] ?? false; // TODO remove this warning with 2.1.0 release $backendName = getenv('MAGENTO_BACKEND_NAME'); diff --git a/src/Magento/FunctionalTestingFramework/DataGenerator/Persist/Curl/AdminExecutor.php b/src/Magento/FunctionalTestingFramework/DataGenerator/Persist/Curl/AdminExecutor.php index 421302d8a..c95751173 100644 --- a/src/Magento/FunctionalTestingFramework/DataGenerator/Persist/Curl/AdminExecutor.php +++ b/src/Magento/FunctionalTestingFramework/DataGenerator/Persist/Curl/AdminExecutor.php @@ -119,7 +119,7 @@ public function write($url, $data = [], $method = CurlInterface::POST, $headers { $apiUrl = self::$adminUrl . $url; - if (!$this->removeBackend) { + if ($this->removeBackend) { $apiUrl = parent::$baseUrl . ltrim($url, '/'); } From 1f6ac08921e74261667fe6fd16abf7e61995dfa7 Mon Sep 17 00:00:00 2001 From: KevinBKozan Date: Tue, 27 Feb 2018 10:18:54 -0600 Subject: [PATCH 3/3] MQE-820: MSI form posts use a single "/admin/" vs "/admin/admin/" URLs used in other areas of the Admin. - CR fixes --- .../DataGenerator/Handlers/OperationDefinitionObjectHandler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Magento/FunctionalTestingFramework/DataGenerator/Handlers/OperationDefinitionObjectHandler.php b/src/Magento/FunctionalTestingFramework/DataGenerator/Handlers/OperationDefinitionObjectHandler.php index e34ca29f1..91f0951eb 100644 --- a/src/Magento/FunctionalTestingFramework/DataGenerator/Handlers/OperationDefinitionObjectHandler.php +++ b/src/Magento/FunctionalTestingFramework/DataGenerator/Handlers/OperationDefinitionObjectHandler.php @@ -42,7 +42,7 @@ class OperationDefinitionObjectHandler implements ObjectHandlerInterface const ENTITY_OPERATION_OBJECT_KEY = 'key'; const ENTITY_OPERATION_OBJECT_VALUE = 'value'; const ENTITY_OPERATION_REQUIRED = 'required'; - const ENTITY_OPERATION_BACKEND_REMOVE = 'removeBackendName'; + const ENTITY_OPERATION_BACKEND_REMOVE = 'removeBackend'; /** * The singleton instance of this class