Skip to content

Commit 7dbf22b

Browse files
authored
Merge pull request #13 from magento-commerce/imported-magento-magento2-functional-testing-framework-806
[Imported] Enable an extending entity to overwrite a requiredEntity binding
2 parents f99fbbc + 1232cee commit 7dbf22b

File tree

2 files changed

+57
-2
lines changed

2 files changed

+57
-2
lines changed

dev/tests/unit/Magento/FunctionalTestFramework/DataGenerator/Persist/OperationDataArrayResolverTest.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,60 @@ public function testNestedMetadataArrayOfDiverseObjects()
477477
$this->assertEquals($expectedResult, $result);
478478
}
479479

480+
public function testExtendedWithRequiredEntity()
481+
{
482+
$entityDataObjectBuilder = new EntityDataObjectBuilder();
483+
$extEntityDataObject = $entityDataObjectBuilder
484+
->withName("extEntity")
485+
->withType("entity")
486+
->withLinkedEntities(["baseSubentity" => "subentity","extSubentity" => "subentity"])
487+
->build();
488+
489+
$mockDOHInstance = AspectMock::double(DataObjectHandler::class, ["getObject" => function ($name) {
490+
$entityDataObjectBuilder = new EntityDataObjectBuilder();
491+
492+
if ($name == "baseSubentity") {
493+
return $entityDataObjectBuilder
494+
->withName("baseSubentity")
495+
->withType("subentity")
496+
->withDataFields(["subtest" => "BaseSubtest"])
497+
->build();
498+
}
499+
500+
if ($name == "extSubentity") {
501+
return $entityDataObjectBuilder
502+
->withName("extSubentity")
503+
->withType("subentity")
504+
->withDataFields(["subtest" => "ExtSubtest"])
505+
->build();
506+
}
507+
}])->make();
508+
AspectMock::double(DataObjectHandler::class, ['getInstance' => $mockDOHInstance]);
509+
510+
$subentityOpElementBuilder = new OperationElementBuilder();
511+
$subentityOpElement = $subentityOpElementBuilder
512+
->withKey("sub")
513+
->withType("subentity")
514+
->withElementType("object")
515+
->withFields(["subtest" => "string"])
516+
->build();
517+
518+
$operationResolver = new OperationDataArrayResolver();
519+
$result = $operationResolver->resolveOperationDataArray(
520+
$extEntityDataObject,
521+
[$subentityOpElement],
522+
"create",
523+
false
524+
);
525+
526+
$expected = [
527+
"sub" => [
528+
"subtest" => "ExtSubtest"
529+
]
530+
];
531+
532+
$this->assertEquals($expected, $result);
533+
}
480534
/**
481535
* After class functionality
482536
* @return void

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,10 +245,11 @@ private function getDependentEntitiesOfType($type)
245245
private function resolveOperationObjectAndEntityData($entityObject, $operationElementValue)
246246
{
247247
if ($operationElementValue != $entityObject->getType()) {
248-
// if we have a mismatch attempt to retrieve linked data and return just the first linkage
248+
// if we have a mismatch attempt to retrieve linked data and return just the last linkage
249+
// this enables overwriting of required entity fields
249250
$linkName = $entityObject->getLinkedEntitiesOfType($operationElementValue);
250251
if (!empty($linkName)) {
251-
$linkName = $linkName[0];
252+
$linkName = array_pop($linkName);
252253
return DataObjectHandler::getInstance()->getObject($linkName);
253254
}
254255
return null;

0 commit comments

Comments
 (0)