|
9 | 9 | use Magento\FunctionalTestingFramework\DataGenerator\Handlers\DataObjectHandler;
|
10 | 10 | use Magento\FunctionalTestingFramework\DataGenerator\Handlers\OperationDefinitionObjectHandler;
|
11 | 11 | use Magento\FunctionalTestingFramework\DataGenerator\Persist\OperationDataArrayResolver;
|
| 12 | +use Magento\FunctionalTestingFramework\Util\Iterator\AbstractIterator; |
12 | 13 | use Magento\FunctionalTestingFramework\Util\MagentoTestCase;
|
13 | 14 | use tests\unit\Util\EntityDataObjectBuilder;
|
14 | 15 | use tests\unit\Util\OperationDefinitionBuilder;
|
@@ -355,6 +356,127 @@ public function testNestedMetadataArrayOfValue()
|
355 | 356 | $this->assertEquals(self::NESTED_METADATA_ARRAY_RESULT, $result);
|
356 | 357 | }
|
357 | 358 |
|
| 359 | + public function testNestedMetadataArrayOfDiverseObjects() |
| 360 | + { |
| 361 | + |
| 362 | + $entityDataObjBuilder = new EntityDataObjectBuilder(); |
| 363 | + $parentDataObject = $entityDataObjBuilder |
| 364 | + ->withName("parentObject") |
| 365 | + ->withType("parentType") |
| 366 | + ->withLinkedEntities(['child1Object' => 'childType1','child2Object' => 'childType2']) |
| 367 | + ->build(); |
| 368 | + |
| 369 | + $child1DataObject = $entityDataObjBuilder |
| 370 | + ->withName('child1Object') |
| 371 | + ->withType('childType1') |
| 372 | + ->withDataFields(['city' => 'Testcity','zip' => 12345]) |
| 373 | + ->build(); |
| 374 | + |
| 375 | + $child2DataObject = $entityDataObjBuilder |
| 376 | + ->withName('child2Object') |
| 377 | + ->withType('childType2') |
| 378 | + ->withDataFields(['city' => 'Testcity 2','zip' => 54321,'state' => 'Teststate']) |
| 379 | + ->build(); |
| 380 | + |
| 381 | + $mockDOHInstance = AspectMock::double( |
| 382 | + DataObjectHandler::class, |
| 383 | + [ |
| 384 | + 'getObject' => function ($name) use ($child1DataObject, $child2DataObject) { |
| 385 | + switch ($name) { |
| 386 | + case 'child1Object': |
| 387 | + return $child1DataObject; |
| 388 | + case 'child2Object': |
| 389 | + return $child2DataObject; |
| 390 | + } |
| 391 | + } |
| 392 | + ] |
| 393 | + )->make(); |
| 394 | + AspectMock::double(DataObjectHandler::class, [ |
| 395 | + 'getInstance' => $mockDOHInstance |
| 396 | + ]); |
| 397 | + |
| 398 | + $operationDefinitionBuilder = new OperationDefinitionBuilder(); |
| 399 | + $child1OperationDefinition = $operationDefinitionBuilder |
| 400 | + ->withName('createchildType1') |
| 401 | + ->withOperation('create') |
| 402 | + ->withType('childType1') |
| 403 | + ->withMetadata([ |
| 404 | + 'city' => 'string', |
| 405 | + 'zip' => 'integer' |
| 406 | + ])->build(); |
| 407 | + |
| 408 | + $child2OperationDefinition = $operationDefinitionBuilder |
| 409 | + ->withName('createchildType2') |
| 410 | + ->withOperation('create') |
| 411 | + ->withType('childType2') |
| 412 | + ->withMetadata([ |
| 413 | + 'city' => 'string', |
| 414 | + 'zip' => 'integer', |
| 415 | + 'state' => 'string' |
| 416 | + ])->build(); |
| 417 | + |
| 418 | + $mockODOHInstance = AspectMock::double( |
| 419 | + OperationDefinitionObjectHandler::class, |
| 420 | + [ |
| 421 | + 'getObject' => function ($name) use ($child1OperationDefinition, $child2OperationDefinition) { |
| 422 | + switch ($name) { |
| 423 | + case 'createchildType1': |
| 424 | + return $child1OperationDefinition; |
| 425 | + case 'createchildType2': |
| 426 | + return $child2OperationDefinition; |
| 427 | + } |
| 428 | + } |
| 429 | + ] |
| 430 | + )->make(); |
| 431 | + AspectMock::double( |
| 432 | + OperationDefinitionObjectHandler::class, |
| 433 | + [ |
| 434 | + 'getInstance' => $mockODOHInstance |
| 435 | + ] |
| 436 | + ); |
| 437 | + |
| 438 | + $arrayObElementBuilder = new OperationElementBuilder(); |
| 439 | + $arrayElement = $arrayObElementBuilder |
| 440 | + ->withKey('address') |
| 441 | + ->withType(['childType1','childType2']) |
| 442 | + ->withFields([]) |
| 443 | + ->withElementType(OperationDefinitionObjectHandler::ENTITY_OPERATION_ARRAY) |
| 444 | + //->withNestedElements(['childType1' => $child1Element, 'childType2' => $child2Element]) |
| 445 | + ->build(); |
| 446 | + |
| 447 | + $parentOpElementBuilder = new OperationElementBuilder(); |
| 448 | + $parentElement = $parentOpElementBuilder |
| 449 | + ->withKey('parentType') |
| 450 | + ->withType('parentType') |
| 451 | + ->addElements(['address' => $arrayElement]) |
| 452 | + ->build(); |
| 453 | + |
| 454 | + $operationResolver = new OperationDataArrayResolver(); |
| 455 | + $result = $operationResolver->resolveOperationDataArray($parentDataObject, [$parentElement], 'create', false); |
| 456 | + |
| 457 | + $expectedResult = [ |
| 458 | + 'parentType' => [ |
| 459 | + 'address' => [ |
| 460 | + [ |
| 461 | + 'city' => 'Testcity', |
| 462 | + 'zip' => '12345' |
| 463 | + ], |
| 464 | + [ |
| 465 | + 'city' => 'Testcity 2', |
| 466 | + 'zip' => '54321', |
| 467 | + 'state' => 'Teststate' |
| 468 | + ] |
| 469 | + ], |
| 470 | + 'name' => 'Hopper', |
| 471 | + 'gpa' => '3.5678', |
| 472 | + 'phone' => '5555555', |
| 473 | + 'isPrimary' => '1' |
| 474 | + ] |
| 475 | + ]; |
| 476 | + |
| 477 | + $this->assertEquals($expectedResult, $result); |
| 478 | + } |
| 479 | + |
358 | 480 | /**
|
359 | 481 | * After class functionality
|
360 | 482 | * @return void
|
|
0 commit comments