diff --git a/src/Magento/FunctionalTestingFramework/DataGenerator/Handlers/OperationDefinitionObjectHandler.php b/src/Magento/FunctionalTestingFramework/DataGenerator/Handlers/OperationDefinitionObjectHandler.php index 78deef0ef..b768d9bd8 100644 --- a/src/Magento/FunctionalTestingFramework/DataGenerator/Handlers/OperationDefinitionObjectHandler.php +++ b/src/Magento/FunctionalTestingFramework/DataGenerator/Handlers/OperationDefinitionObjectHandler.php @@ -24,6 +24,7 @@ class OperationDefinitionObjectHandler implements ObjectHandlerInterface const ENTITY_OPERATION_STORE_CODE = 'storeCode'; const ENTITY_OPERATION_SUCCESS_REGEX = 'successRegex'; const ENTITY_OPERATION_RETURN_REGEX = 'returnRegex'; + const ENTITY_OPERATION_RETURN_INDEX = 'returnIndex'; const ENTITY_OPERATION_HEADER = 'header'; const ENTITY_OPERATION_CONTENT_TYPE = 'contentType'; const ENTITY_OPERATION_HEADER_PARAM = 'param'; @@ -144,6 +145,7 @@ private function initialize() $auth = $opDefArray[OperationDefinitionObjectHandler::ENTITY_OPERATION_AUTH] ?? null; $successRegex = $opDefArray[OperationDefinitionObjectHandler::ENTITY_OPERATION_SUCCESS_REGEX] ?? null; $returnRegex = $opDefArray[OperationDefinitionObjectHandler::ENTITY_OPERATION_RETURN_REGEX] ?? null; + $returnIndex = $opDefArray[OperationDefinitionObjectHandler::ENTITY_OPERATION_RETURN_INDEX] ?? 0; $contentType = $opDefArray[OperationDefinitionObjectHandler::ENTITY_OPERATION_CONTENT_TYPE][0]['value'] ?? null; $headers = $this->initializeHeaders($opDefArray); @@ -216,7 +218,8 @@ private function initialize() $contentType, $removeBackend, $successRegex, - $returnRegex + $returnRegex, + $returnIndex ); } } diff --git a/src/Magento/FunctionalTestingFramework/DataGenerator/Objects/OperationDefinitionObject.php b/src/Magento/FunctionalTestingFramework/DataGenerator/Objects/OperationDefinitionObject.php index d6237a437..721a9dcc9 100644 --- a/src/Magento/FunctionalTestingFramework/DataGenerator/Objects/OperationDefinitionObject.php +++ b/src/Magento/FunctionalTestingFramework/DataGenerator/Objects/OperationDefinitionObject.php @@ -104,6 +104,13 @@ class OperationDefinitionObject */ private $returnRegex; + /** + * Index of element to be returned from "returnRegex" matches. + * + * @var string + */ + private $returnIndex; + /** * Determines if operation should remove backend_name from URL. * @var boolean @@ -125,6 +132,7 @@ class OperationDefinitionObject * @param boolean $removeBackend * @param string $successRegex * @param string $returnRegex + * @param string $returnIndex * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( @@ -140,7 +148,8 @@ public function __construct( $contentType, $removeBackend, $successRegex = null, - $returnRegex = null + $returnRegex = null, + $returnIndex = null ) { $this->name = $name; $this->operation = $operation; @@ -153,6 +162,7 @@ public function __construct( $this->operationMetadata = $metaData; $this->successRegex = $successRegex; $this->returnRegex = $returnRegex; + $this->returnIndex = $returnIndex; $this->removeBackend = $removeBackend; $this->apiUrl = null; @@ -284,6 +294,16 @@ public function getReturnRegex() return $this->returnRegex; } + /** + * Getter for return regex matches index. + * + * @return string|null + */ + public function getReturnIndex() + { + return $this->returnIndex; + } + /** * Function to append or add query parameters * diff --git a/src/Magento/FunctionalTestingFramework/DataGenerator/Persist/Curl/AdminExecutor.php b/src/Magento/FunctionalTestingFramework/DataGenerator/Persist/Curl/AdminExecutor.php index 1f7ae70d7..4e11f5cec 100644 --- a/src/Magento/FunctionalTestingFramework/DataGenerator/Persist/Curl/AdminExecutor.php +++ b/src/Magento/FunctionalTestingFramework/DataGenerator/Persist/Curl/AdminExecutor.php @@ -138,12 +138,13 @@ public function write($url, $data = [], $method = CurlInterface::POST, $headers /** * Read response from server. * - * @param string $successRegex - * @param string $returnRegex + * @param string $successRegex + * @param string $returnRegex + * @param string|null $returnIndex * @return string|array * @throws TestFrameworkException */ - public function read($successRegex = null, $returnRegex = null) + public function read($successRegex = null, $returnRegex = null, $returnIndex = null) { $this->response = $this->transport->read(); $this->setFormKey(); @@ -158,7 +159,7 @@ public function read($successRegex = null, $returnRegex = null) if (!empty($returnRegex)) { preg_match($returnRegex, $this->response, $returnMatches); if (!empty($returnMatches)) { - return $returnMatches; + return $returnMatches[$returnIndex] ?? $returnMatches[0]; } } return $this->response; diff --git a/src/Magento/FunctionalTestingFramework/DataGenerator/Persist/Curl/FrontendExecutor.php b/src/Magento/FunctionalTestingFramework/DataGenerator/Persist/Curl/FrontendExecutor.php index 7e7485a82..799cd6d5c 100644 --- a/src/Magento/FunctionalTestingFramework/DataGenerator/Persist/Curl/FrontendExecutor.php +++ b/src/Magento/FunctionalTestingFramework/DataGenerator/Persist/Curl/FrontendExecutor.php @@ -158,12 +158,13 @@ public function write($url, $data = [], $method = CurlInterface::POST, $headers /** * Read response from server. * - * @param string $successRegex - * @param string $returnRegex + * @param string $successRegex + * @param string $returnRegex + * @param string|null $returnIndex * @return string|array * @throws TestFrameworkException */ - public function read($successRegex = null, $returnRegex = null) + public function read($successRegex = null, $returnRegex = null, $returnIndex = null) { $this->response = $this->transport->read(); $this->setCookies(); @@ -179,7 +180,7 @@ public function read($successRegex = null, $returnRegex = null) if (!empty($returnRegex)) { preg_match($returnRegex, $this->response, $returnMatches); if (!empty($returnMatches)) { - return $returnMatches; + return $returnMatches[$returnIndex] ?? $returnMatches[0]; } } return $this->response; diff --git a/src/Magento/FunctionalTestingFramework/DataGenerator/Persist/Curl/WebapiExecutor.php b/src/Magento/FunctionalTestingFramework/DataGenerator/Persist/Curl/WebapiExecutor.php index 6aec3e58a..281eaa24d 100644 --- a/src/Magento/FunctionalTestingFramework/DataGenerator/Persist/Curl/WebapiExecutor.php +++ b/src/Magento/FunctionalTestingFramework/DataGenerator/Persist/Curl/WebapiExecutor.php @@ -137,12 +137,13 @@ public function write($url, $data = [], $method = CurlInterface::POST, $headers /** * Read response from server. * - * @param string $successRegex - * @param string $returnRegex + * @param string $successRegex + * @param string $returnRegex + * @param string|null $returnIndex * @return string * @throws TestFrameworkException */ - public function read($successRegex = null, $returnRegex = null) + public function read($successRegex = null, $returnRegex = null, $returnIndex = null) { $this->response = $this->transport->read(); return $this->response; diff --git a/src/Magento/FunctionalTestingFramework/DataGenerator/Persist/CurlHandler.php b/src/Magento/FunctionalTestingFramework/DataGenerator/Persist/CurlHandler.php index 9c8a9e175..f6d8773bc 100644 --- a/src/Magento/FunctionalTestingFramework/DataGenerator/Persist/CurlHandler.php +++ b/src/Magento/FunctionalTestingFramework/DataGenerator/Persist/CurlHandler.php @@ -107,6 +107,7 @@ public function executeRequest($dependentEntities) $executor = null; $successRegex = null; $returnRegex = null; + $returnIndex = null; if ((null !== $dependentEntities) && is_array($dependentEntities)) { $entities = array_merge([$this->entityObject], $dependentEntities); @@ -119,6 +120,8 @@ public function executeRequest($dependentEntities) $contentType = $this->operationDefinition->getContentType(); $successRegex = $this->operationDefinition->getSuccessRegex(); $returnRegex = $this->operationDefinition->getReturnRegex(); + $returnIndex = $this->operationDefinition->getReturnIndex(); + $method = $this->operationDefinition->getApiMethod(); $operationDataResolver = new OperationDataArrayResolver($dependentEntities); $this->requestData = $operationDataResolver->resolveOperationDataArray( @@ -156,11 +159,11 @@ public function executeRequest($dependentEntities) $executor->write( $apiUrl, $this->requestData, - self::$curlMethodMapping[$this->operation], + $method ?? self::$curlMethodMapping[$this->operation], $headers ); - $response = $executor->read($successRegex, $returnRegex); + $response = $executor->read($successRegex, $returnRegex, $returnIndex); $executor->close(); return $response; diff --git a/src/Magento/FunctionalTestingFramework/DataGenerator/etc/dataOperation.xsd b/src/Magento/FunctionalTestingFramework/DataGenerator/etc/dataOperation.xsd index 7a455dc2b..8b59ccae0 100644 --- a/src/Magento/FunctionalTestingFramework/DataGenerator/etc/dataOperation.xsd +++ b/src/Magento/FunctionalTestingFramework/DataGenerator/etc/dataOperation.xsd @@ -26,9 +26,10 @@ - + + @@ -93,4 +94,12 @@ + + + + + + + + \ No newline at end of file diff --git a/src/Magento/FunctionalTestingFramework/Util/Protocol/CurlInterface.php b/src/Magento/FunctionalTestingFramework/Util/Protocol/CurlInterface.php index 171fd01e6..a2d6bc344 100644 --- a/src/Magento/FunctionalTestingFramework/Util/Protocol/CurlInterface.php +++ b/src/Magento/FunctionalTestingFramework/Util/Protocol/CurlInterface.php @@ -42,11 +42,12 @@ public function write($url, $body = [], $method = CurlInterface::POST, $headers /** * Read response from server. * - * @param string $successRegex - * @param string $returnRegex + * @param string $successRegex + * @param string $returnRegex + * @param string|null $returnIndex * @return string|array */ - public function read($successRegex = null, $returnRegex = null); + public function read($successRegex = null, $returnRegex = null, $returnIndex = null); /** * Close the connection to the server. diff --git a/src/Magento/FunctionalTestingFramework/Util/Protocol/CurlTransport.php b/src/Magento/FunctionalTestingFramework/Util/Protocol/CurlTransport.php index 5a9133a05..16c716e22 100644 --- a/src/Magento/FunctionalTestingFramework/Util/Protocol/CurlTransport.php +++ b/src/Magento/FunctionalTestingFramework/Util/Protocol/CurlTransport.php @@ -161,12 +161,13 @@ public function write($url, $body = [], $method = CurlInterface::POST, $headers /** * Read response from server. * - * @param string $successRegex - * @param string $returnRegex + * @param string $successRegex + * @param string $returnRegex + * @param string|null $returnIndex * @return string * @throws TestFrameworkException */ - public function read($successRegex = null, $returnRegex = null) + public function read($successRegex = null, $returnRegex = null, $returnIndex = null) { $response = curl_exec($this->getResource());