Skip to content

Commit 73f9a9a

Browse files
committed
MQE-654: Allow easy access to custom/extension attributes values in test.
(cherry picked from commit 967929d)
1 parent 1bdb9ec commit 73f9a9a

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

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

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,10 @@ private function setCreatedObject($response, $index, $requestDataArray, $isJson)
182182
$responseData = $responseData[$index];
183183
}
184184
if (is_array($responseData)) {
185-
$persistedData = $this->convertToFlatArray(array_merge($requestDataArray, $responseData));
185+
$persistedData = $this->convertToFlatArray(array_merge(
186+
$requestDataArray,
187+
$this->convertCustomAndExtensionAttributesArray($responseData)
188+
));
186189
} else {
187190
$persistedData = $this->convertToFlatArray(array_merge($requestDataArray, ['return' => $responseData]));
188191
}
@@ -225,4 +228,43 @@ private function convertToFlatArray($arrayIn, $rootKey = '')
225228
}
226229
return $arrayOut;
227230
}
231+
232+
/**
233+
* Convert custom_attributes and extension_attributes array from
234+
* e.g.
235+
* 'custom_attributes' => [
236+
* 0 => [
237+
* 'attribute_code' => 'code1',
238+
* 'value' => 'value1',
239+
* ],
240+
1 => [
241+
* 'attribute_code' => 'code2',
242+
* 'value' => 'value2',
243+
* ],
244+
* ]
245+
*
246+
* to
247+
*
248+
* 'custom_attributes' => [
249+
* 'code1' => 'value1',
250+
* 'code2' => 'value2',
251+
* ]
252+
*
253+
* @param array $arrayIn
254+
* @return array
255+
*/
256+
private function convertCustomAndExtensionAttributesArray($arrayIn)
257+
{
258+
$keys = ['custom_attributes', 'extension_attributes'];
259+
foreach($keys as $key) {
260+
if(!array_key_exists($key, $arrayIn)) {
261+
continue;
262+
}
263+
$arrayCopy = $arrayIn[$key];
264+
foreach($arrayCopy as $index => $attributes) {
265+
$arrayIn[$key][$attributes['attribute_code']] = $attributes['value'];
266+
}
267+
}
268+
return $arrayIn;
269+
}
228270
}

0 commit comments

Comments
 (0)