Skip to content

Commit dbc03a9

Browse files
committed
MQE-364:[Data Input] Metadata nest jsonObject not working as expected.
- add method for parsing nested jsonObjects - add method for root level jsonObjects
1 parent 65a0f1e commit dbc03a9

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/Magento/FunctionalTestingFramework/DataGenerator/Api/ApiExecutor.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,10 @@ private function convertJsonArray($entityObject, $jsonArrayMetadata)
161161

162162
foreach ($jsonArrayMetadata as $jsonElement) {
163163
if ($jsonElement->getType() == JsonObjectExtractor::JSON_OBJECT_OBJ_NAME) {
164+
$entityObj = $this->resolveJsonObjectAndEntityData($entityObject, $jsonElement->getValue());
164165
$jsonArray[$jsonElement->getValue()] =
165-
$this->convertJsonArray($entityObject, $jsonElement->getNestedMetadata());
166+
$this->convertJsonArray($entityObj, $jsonElement->getNestedMetadata());
167+
continue;
166168
}
167169

168170
$jsonElementType = $jsonElement->getValue();
@@ -222,6 +224,25 @@ private function convertJsonArray($entityObject, $jsonArrayMetadata)
222224
return $jsonArray;
223225
}
224226

227+
/**
228+
* This function does a comparison of the entity object being matched to the json element. If there is a mismatch in
229+
* type we attempt to use a nested entity, if the entities are properly matched, we simply return the object.
230+
*
231+
* @param EntityDataObject $entityObject
232+
* @param string $jsonElementValue
233+
* @return EntityDataObject|null
234+
*/
235+
private function resolveJsonObjectAndEntityData($entityObject, $jsonElementValue)
236+
{
237+
if ($jsonElementValue != $entityObject->getType()) {
238+
// if we have a mismatch attempt to retrieve linked data and return just the first linkage
239+
$linkName = $entityObject->getLinkedEntitiesOfType($jsonElementValue)[0];
240+
return DataObjectHandler::getInstance()->getObject($linkName);
241+
}
242+
243+
return $entityObject;
244+
}
245+
225246
/**
226247
* Resolves JsonObjects and pre-defined metadata (in other operation.xml file) referenced by the json metadata
227248
*
@@ -233,6 +254,7 @@ private function resolveNonPrimitiveElement($entityName, $jsonElement)
233254
{
234255
$linkedEntityObj = $this->resolveLinkedEntityObject($entityName);
235256

257+
// in array case
236258
if (!empty($jsonElement->getNestedJsonElement($jsonElement->getValue()))
237259
&& $jsonElement->getType() == 'array'
238260
) {

src/Magento/FunctionalTestingFramework/DataGenerator/Util/JsonObjectExtractor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function extractJsonObject($jsonObjectArray)
5858
if (array_key_exists(JsonObjectExtractor::JSON_OBJECT_OBJ_NAME, $jsonObjectArray)) {
5959
foreach ($jsonObjectArray[JsonObjectExtractor::JSON_OBJECT_OBJ_NAME] as $jsonObject) {
6060
$nestedJsonElement = $this->extractJsonObject($jsonObject);
61-
$nestedJsonElements[$nestedJsonElement->getKey()] = $nestedJsonElement;
61+
$jsonMetadata[] = $nestedJsonElement;
6262
}
6363
}
6464

0 commit comments

Comments
 (0)