Skip to content

Commit 0fe97bb

Browse files
authored
Merge pull request #377 from ameysar/fix-non-api-operations
Non-API operations fixes
2 parents 3c7ed4b + 66c5214 commit 0fe97bb

File tree

9 files changed

+62
-22
lines changed

9 files changed

+62
-22
lines changed

src/Magento/FunctionalTestingFramework/DataGenerator/Handlers/OperationDefinitionObjectHandler.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class OperationDefinitionObjectHandler implements ObjectHandlerInterface
2424
const ENTITY_OPERATION_STORE_CODE = 'storeCode';
2525
const ENTITY_OPERATION_SUCCESS_REGEX = 'successRegex';
2626
const ENTITY_OPERATION_RETURN_REGEX = 'returnRegex';
27+
const ENTITY_OPERATION_RETURN_INDEX = 'returnIndex';
2728
const ENTITY_OPERATION_HEADER = 'header';
2829
const ENTITY_OPERATION_CONTENT_TYPE = 'contentType';
2930
const ENTITY_OPERATION_HEADER_PARAM = 'param';
@@ -144,6 +145,7 @@ private function initialize()
144145
$auth = $opDefArray[OperationDefinitionObjectHandler::ENTITY_OPERATION_AUTH] ?? null;
145146
$successRegex = $opDefArray[OperationDefinitionObjectHandler::ENTITY_OPERATION_SUCCESS_REGEX] ?? null;
146147
$returnRegex = $opDefArray[OperationDefinitionObjectHandler::ENTITY_OPERATION_RETURN_REGEX] ?? null;
148+
$returnIndex = $opDefArray[OperationDefinitionObjectHandler::ENTITY_OPERATION_RETURN_INDEX] ?? 0;
147149
$contentType = $opDefArray[OperationDefinitionObjectHandler::ENTITY_OPERATION_CONTENT_TYPE][0]['value']
148150
?? null;
149151
$headers = $this->initializeHeaders($opDefArray);
@@ -216,7 +218,8 @@ private function initialize()
216218
$contentType,
217219
$removeBackend,
218220
$successRegex,
219-
$returnRegex
221+
$returnRegex,
222+
$returnIndex
220223
);
221224
}
222225
}

src/Magento/FunctionalTestingFramework/DataGenerator/Objects/OperationDefinitionObject.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,13 @@ class OperationDefinitionObject
104104
*/
105105
private $returnRegex;
106106

107+
/**
108+
* Index of element to be returned from "returnRegex" matches.
109+
*
110+
* @var string
111+
*/
112+
private $returnIndex;
113+
107114
/**
108115
* Determines if operation should remove backend_name from URL.
109116
* @var boolean
@@ -125,6 +132,7 @@ class OperationDefinitionObject
125132
* @param boolean $removeBackend
126133
* @param string $successRegex
127134
* @param string $returnRegex
135+
* @param string $returnIndex
128136
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
129137
*/
130138
public function __construct(
@@ -140,7 +148,8 @@ public function __construct(
140148
$contentType,
141149
$removeBackend,
142150
$successRegex = null,
143-
$returnRegex = null
151+
$returnRegex = null,
152+
$returnIndex = null
144153
) {
145154
$this->name = $name;
146155
$this->operation = $operation;
@@ -153,6 +162,7 @@ public function __construct(
153162
$this->operationMetadata = $metaData;
154163
$this->successRegex = $successRegex;
155164
$this->returnRegex = $returnRegex;
165+
$this->returnIndex = $returnIndex;
156166
$this->removeBackend = $removeBackend;
157167
$this->apiUrl = null;
158168

@@ -284,6 +294,16 @@ public function getReturnRegex()
284294
return $this->returnRegex;
285295
}
286296

297+
/**
298+
* Getter for return regex matches index.
299+
*
300+
* @return string|null
301+
*/
302+
public function getReturnIndex()
303+
{
304+
return $this->returnIndex;
305+
}
306+
287307
/**
288308
* Function to append or add query parameters
289309
*

src/Magento/FunctionalTestingFramework/DataGenerator/Persist/Curl/AdminExecutor.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,13 @@ public function write($url, $data = [], $method = CurlInterface::POST, $headers
138138
/**
139139
* Read response from server.
140140
*
141-
* @param string $successRegex
142-
* @param string $returnRegex
141+
* @param string $successRegex
142+
* @param string $returnRegex
143+
* @param string|null $returnIndex
143144
* @return string|array
144145
* @throws TestFrameworkException
145146
*/
146-
public function read($successRegex = null, $returnRegex = null)
147+
public function read($successRegex = null, $returnRegex = null, $returnIndex = null)
147148
{
148149
$this->response = $this->transport->read();
149150
$this->setFormKey();
@@ -158,7 +159,7 @@ public function read($successRegex = null, $returnRegex = null)
158159
if (!empty($returnRegex)) {
159160
preg_match($returnRegex, $this->response, $returnMatches);
160161
if (!empty($returnMatches)) {
161-
return $returnMatches;
162+
return $returnMatches[$returnIndex] ?? $returnMatches[0];
162163
}
163164
}
164165
return $this->response;

src/Magento/FunctionalTestingFramework/DataGenerator/Persist/Curl/FrontendExecutor.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,13 @@ public function write($url, $data = [], $method = CurlInterface::POST, $headers
158158
/**
159159
* Read response from server.
160160
*
161-
* @param string $successRegex
162-
* @param string $returnRegex
161+
* @param string $successRegex
162+
* @param string $returnRegex
163+
* @param string|null $returnIndex
163164
* @return string|array
164165
* @throws TestFrameworkException
165166
*/
166-
public function read($successRegex = null, $returnRegex = null)
167+
public function read($successRegex = null, $returnRegex = null, $returnIndex = null)
167168
{
168169
$this->response = $this->transport->read();
169170
$this->setCookies();
@@ -179,7 +180,7 @@ public function read($successRegex = null, $returnRegex = null)
179180
if (!empty($returnRegex)) {
180181
preg_match($returnRegex, $this->response, $returnMatches);
181182
if (!empty($returnMatches)) {
182-
return $returnMatches;
183+
return $returnMatches[$returnIndex] ?? $returnMatches[0];
183184
}
184185
}
185186
return $this->response;

src/Magento/FunctionalTestingFramework/DataGenerator/Persist/Curl/WebapiExecutor.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,13 @@ public function write($url, $data = [], $method = CurlInterface::POST, $headers
137137
/**
138138
* Read response from server.
139139
*
140-
* @param string $successRegex
141-
* @param string $returnRegex
140+
* @param string $successRegex
141+
* @param string $returnRegex
142+
* @param string|null $returnIndex
142143
* @return string
143144
* @throws TestFrameworkException
144145
*/
145-
public function read($successRegex = null, $returnRegex = null)
146+
public function read($successRegex = null, $returnRegex = null, $returnIndex = null)
146147
{
147148
$this->response = $this->transport->read();
148149
return $this->response;

src/Magento/FunctionalTestingFramework/DataGenerator/Persist/CurlHandler.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ public function executeRequest($dependentEntities)
107107
$executor = null;
108108
$successRegex = null;
109109
$returnRegex = null;
110+
$returnIndex = null;
110111

111112
if ((null !== $dependentEntities) && is_array($dependentEntities)) {
112113
$entities = array_merge([$this->entityObject], $dependentEntities);
@@ -119,6 +120,8 @@ public function executeRequest($dependentEntities)
119120
$contentType = $this->operationDefinition->getContentType();
120121
$successRegex = $this->operationDefinition->getSuccessRegex();
121122
$returnRegex = $this->operationDefinition->getReturnRegex();
123+
$returnIndex = $this->operationDefinition->getReturnIndex();
124+
$method = $this->operationDefinition->getApiMethod();
122125

123126
$operationDataResolver = new OperationDataArrayResolver($dependentEntities);
124127
$this->requestData = $operationDataResolver->resolveOperationDataArray(
@@ -156,11 +159,11 @@ public function executeRequest($dependentEntities)
156159
$executor->write(
157160
$apiUrl,
158161
$this->requestData,
159-
self::$curlMethodMapping[$this->operation],
162+
$method ?? self::$curlMethodMapping[$this->operation],
160163
$headers
161164
);
162165

163-
$response = $executor->read($successRegex, $returnRegex);
166+
$response = $executor->read($successRegex, $returnRegex, $returnIndex);
164167
$executor->close();
165168

166169
return $response;

src/Magento/FunctionalTestingFramework/DataGenerator/etc/dataOperation.xsd

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@
2626
<xs:attribute type="xs:string" name="url"/>
2727
<xs:attribute type="authEnum" name="auth"/>
2828
<xs:attribute type="xs:boolean" name="removeBackend" use="optional" default="true"/>
29-
<xs:attribute type="xs:string" name="method"/>
29+
<xs:attribute type="operationMethodEnum" name="method"/>
3030
<xs:attribute type="xs:string" name="successRegex"/>
3131
<xs:attribute type="xs:string" name="returnRegex"/>
32+
<xs:attribute type="xs:string" name="returnIndex" use="optional"/>
3233
<xs:attribute type="xs:string" name="filename"/>
3334
</xs:complexType>
3435
</xs:element>
@@ -93,4 +94,12 @@
9394
<xs:enumeration value="anonymous" />
9495
</xs:restriction>
9596
</xs:simpleType>
97+
<xs:simpleType name="operationMethodEnum" final="restriction">
98+
<xs:restriction base="xs:string">
99+
<xs:enumeration value="GET" />
100+
<xs:enumeration value="PUT" />
101+
<xs:enumeration value="POST" />
102+
<xs:enumeration value="DELETE" />
103+
</xs:restriction>
104+
</xs:simpleType>
96105
</xs:schema>

src/Magento/FunctionalTestingFramework/Util/Protocol/CurlInterface.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,12 @@ public function write($url, $body = [], $method = CurlInterface::POST, $headers
4242
/**
4343
* Read response from server.
4444
*
45-
* @param string $successRegex
46-
* @param string $returnRegex
45+
* @param string $successRegex
46+
* @param string $returnRegex
47+
* @param string|null $returnIndex
4748
* @return string|array
4849
*/
49-
public function read($successRegex = null, $returnRegex = null);
50+
public function read($successRegex = null, $returnRegex = null, $returnIndex = null);
5051

5152
/**
5253
* Close the connection to the server.

src/Magento/FunctionalTestingFramework/Util/Protocol/CurlTransport.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,12 +161,13 @@ public function write($url, $body = [], $method = CurlInterface::POST, $headers
161161
/**
162162
* Read response from server.
163163
*
164-
* @param string $successRegex
165-
* @param string $returnRegex
164+
* @param string $successRegex
165+
* @param string $returnRegex
166+
* @param string|null $returnIndex
166167
* @return string
167168
* @throws TestFrameworkException
168169
*/
169-
public function read($successRegex = null, $returnRegex = null)
170+
public function read($successRegex = null, $returnRegex = null, $returnIndex = null)
170171
{
171172
$response = curl_exec($this->getResource());
172173

0 commit comments

Comments
 (0)