Skip to content

Commit 423534c

Browse files
committed
MQE-369: Implement non web api data persistence.
1 parent 05190b1 commit 423534c

File tree

2 files changed

+56
-49
lines changed

2 files changed

+56
-49
lines changed

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

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ class CurlHandler
5151
*/
5252
private $dependentEntities = [];
5353

54+
/**
55+
* Persisted data array.
56+
*
57+
* @var array
58+
*/
59+
private $persistedDataArray;
60+
5461
/**
5562
* The array of entity name and number of objects being created,
5663
* we don't need to track objects in update and delete operations.
@@ -79,25 +86,11 @@ class CurlHandler
7986
];
8087

8188
/**
82-
* Persisted entity.
83-
*
84-
* @var EntityDataObject
85-
*/
86-
private $persistedEntity;
87-
88-
/**
89-
* Persisted dependent entities.
90-
*
91-
* @var array
92-
*/
93-
private $persistedDependentEntities = [];
94-
95-
/**
96-
* If it's a REST request.
89+
* If it's a web api request.
9790
*
9891
* @var bool
9992
*/
100-
private $isRestRequest;
93+
private $isWebApiRequest;
10194

10295
/**
10396
* ApiSubObject constructor.
@@ -111,7 +104,7 @@ public function __construct($operation, $entityObject, $dependentEntities = null
111104
$this->operation = $operation;
112105
$this->entityObject = $entityObject;
113106
$this->storeCode = $storeCode;
114-
$this->isRestRequest = true;
107+
$this->isWebApiRequest = true;
115108
if ($dependentEntities != null) {
116109
foreach ($dependentEntities as $entity) {
117110
$this->dependentEntities[$entity->getName()] = $entity;
@@ -150,23 +143,33 @@ public function executeRequest()
150143
$successRegex = null;
151144
$returnRegex = null;
152145
$headers = $this->dataDefinition->getHeaders();
153-
$params = $this->convertDataArray($this->entityObject, $this->dataDefinition->getMetaData());
146+
$this->persistedDataArray = $this->convertDataArray($this->entityObject, $this->dataDefinition->getMetaData());
154147

155148
$authorization = $this->dataDefinition->getAuth();
156149
switch ($authorization) {
157150
case 'adminOauth':
158151
$executor = new WebapiExecutor($this->storeCode);
159-
$executor->write($apiUrl, $params, self::$curlMethodMapping[$this->operation], $headers);
152+
$executor->write(
153+
$apiUrl,
154+
$this->persistedDataArray,
155+
self::$curlMethodMapping[$this->operation],
156+
$headers
157+
);
160158
break;
161159
case 'adminFormkey':
162-
$this->isRestRequest = false;
160+
$this->isWebApiRequest = false;
163161
$executor = new AdminExecutor();
164-
$executor->write($apiUrl, $params, self::$curlMethodMapping[$this->operation], $headers);
162+
$executor->write(
163+
$apiUrl,
164+
$this->persistedDataArray,
165+
self::$curlMethodMapping[$this->operation],
166+
$headers
167+
);
165168
$successRegex = $this->dataDefinition->getSuccessRegex();
166169
$returnRegex = $this->dataDefinition->getReturnRegex();
167170
break;
168171
case 'customFromkey':
169-
$this->isRestRequest = false;
172+
$this->isWebApiRequest = false;
170173
// TODO: add frontend request executor.
171174
break;
172175
}
@@ -176,13 +179,23 @@ public function executeRequest()
176179
}
177180

178181
/**
179-
* If the request is a Rest.
182+
* If it's a web api request.
180183
*
181184
* @return bool
182185
*/
183-
public function isRestRequest()
186+
public function isWebApiRequest()
187+
{
188+
return $this->isWebApiRequest;
189+
}
190+
191+
/**
192+
* Get persisted data array.
193+
*
194+
* @return array
195+
*/
196+
public function getPersistedDataArray()
184197
{
185-
return $this->isRestRequest;
198+
return $this->persistedDataArray;
186199
}
187200

188201
/**

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

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ class DataPersistHandler
4141
private $storeCode;
4242

4343
/**
44-
* ApiPersistenceHandler constructor.
44+
* DataPersistHandler constructor.
45+
*
4546
* @param EntityDataObject $entityObject
4647
* @param array $dependentObjects
4748
*/
@@ -66,23 +67,20 @@ public function createEntity($storeCode = null)
6667
$curlHandler = new CurlHandler('create', $this->entityObject, $this->dependentObjects, $this->storeCode);
6768
$result = $curlHandler->executeRequest();
6869

69-
if ($curlHandler->isRestRequest()) {
70-
$this->createdObject = new EntityDataObject(
71-
$this->entityObject->getName(),
72-
$this->entityObject->getType(),
73-
json_decode($result, true),
74-
null,
75-
null // No uniqueness data is needed to be further processed.
76-
);
70+
$persistedDataArray = $curlHandler->getPersistedDataArray();
71+
if ($curlHandler->isWebApiRequest()) {
72+
$persistedDataArray = array_merge($persistedDataArray, json_decode($result, true));
7773
} else {
78-
$this->createdObject = new EntityDataObject(
79-
$this->entityObject->getName(),
80-
$this->entityObject->getType(),
81-
null,
82-
null,
83-
null
84-
);
74+
$persistedDataArray = array_merge($persistedDataArray, ['return' => $result]);
8575
}
76+
77+
$this->createdObject = new EntityDataObject(
78+
$this->entityObject->getName(),
79+
$this->entityObject->getType(),
80+
$persistedDataArray,
81+
null,
82+
null
83+
);
8684
}
8785

8886
/**
@@ -93,10 +91,10 @@ public function createEntity($storeCode = null)
9391
*/
9492
public function deleteEntity($storeCode = null)
9593
{
96-
if (!$storeCode) {
97-
$storeCode = $this->storeCode;
94+
if (isset($storeCode)) {
95+
$this->storeCode = $storeCode;
9896
}
99-
$curlHandler = new CurlHandler('delete', $this->createdObject, null, $storeCode);
97+
$curlHandler = new CurlHandler('delete', $this->createdObject, null, $this->storeCode);
10098
$result = $curlHandler->executeRequest();
10199

102100
return $result;
@@ -118,11 +116,7 @@ public function getCreatedObject()
118116
*/
119117
public function getCreatedDataByName($dataName)
120118
{
121-
$data = $this->createdObject->getDataByName($dataName, EntityDataObject::NO_UNIQUE_PROCESS);
122-
if (empty($data)) {
123-
$data = $this->entityObject->getDataByName($dataName, EntityDataObject::CEST_UNIQUE_VALUE);
124-
}
125-
return $data;
119+
return $this->createdObject->getDataByName($dataName, EntityDataObject::NO_UNIQUE_PROCESS);
126120
}
127121

128122
// TODO add update function

0 commit comments

Comments
 (0)