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..91f0951eb 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 = 'removeBackend'; /** * The singleton instance of this class @@ -149,6 +150,7 @@ private function initialize() $headers = []; $params = []; $operationElements = []; + $removeBackend = $opDefArray[OperationDefinitionObjectHandler::ENTITY_OPERATION_BACKEND_REMOVE] ?? false; // 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..c95751173 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 @@ +