Skip to content

Commit 71607e3

Browse files
committed
Merge branch 'MQE-472-new' into sprint-develop
2 parents a25b568 + 942eaf0 commit 71607e3

File tree

5 files changed

+47
-37
lines changed

5 files changed

+47
-37
lines changed

src/Magento/FunctionalTestingFramework/DataGenerator/Handlers/OperationDefinitionObjectHandler.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ class OperationDefinitionObjectHandler implements ObjectHandlerInterface
2828
const ENTITY_OPERATION_HEADER_PARAM = 'param';
2929
const ENTITY_OPERATION_HEADER_VALUE = 'value';
3030
const ENTITY_OPERATION_URL_PARAM = 'param';
31-
const ENTITY_OPERATION_URL_PARAM_TYPE = 'type';
3231
const ENTITY_OPERATION_URL_PARAM_KEY = 'key';
3332
const ENTITY_OPERATION_URL_PARAM_VALUE = 'value';
3433
const ENTITY_OPERATION_ENTRY = 'field';
@@ -156,8 +155,7 @@ private function initDataDefinitions()
156155

157156
if (array_key_exists(OperationDefinitionObjectHandler::ENTITY_OPERATION_URL_PARAM, $opDefArray)) {
158157
foreach ($opDefArray[OperationDefinitionObjectHandler::ENTITY_OPERATION_URL_PARAM] as $paramEntry) {
159-
$params[$paramEntry[OperationDefinitionObjectHandler::ENTITY_OPERATION_URL_PARAM_TYPE]]
160-
[$paramEntry[OperationDefinitionObjectHandler::ENTITY_OPERATION_URL_PARAM_KEY]] =
158+
$params[$paramEntry[OperationDefinitionObjectHandler::ENTITY_OPERATION_URL_PARAM_KEY]] =
161159
$paramEntry[OperationDefinitionObjectHandler::ENTITY_OPERATION_URL_PARAM_VALUE];
162160
}
163161
}

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,7 @@ public function executeRequest($dependentEntities)
106106
$successRegex = null;
107107
$returnRegex = null;
108108

109-
if ($this->operation == 'update') {
110-
$entities = array_merge($dependentEntities, [$this->entityObject]);
111-
} elseif ((null !== $dependentEntities) && is_array($dependentEntities)) {
109+
if ((null !== $dependentEntities) && is_array($dependentEntities)) {
112110
$entities = array_merge([$this->entityObject], $dependentEntities);
113111
} else {
114112
$entities = [$this->entityObject];

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
namespace Magento\FunctionalTestingFramework\DataGenerator\Persist;
88

99
use Magento\FunctionalTestingFramework\DataGenerator\Objects\EntityDataObject;
10+
use Magento\FunctionalTestingFramework\DataGenerator\Handlers\DataObjectHandler;
1011

1112
/**
1213
* Class DataPersistenceHandler
@@ -80,17 +81,24 @@ public function createEntity($storeCode = null)
8081
/**
8182
* Function which executes a put request based on specific operation metadata.
8283
*
84+
* @param string $updateDataName
85+
* @param array $updateDependentObjects
8386
* @param string $storeCode
8487
* @return void
8588
*/
8689

87-
public function updateEntity($storeCode = null)
90+
public function updateEntity($updateDataName, $updateDependentObjects = [], $storeCode = null)
8891
{
8992
if (!empty($storeCode)) {
9093
$this->storeCode = $storeCode;
9194
}
92-
$curlHandler = new CurlHandler('update', $this->entityObject, $this->storeCode);
93-
$result = $curlHandler->executeRequest($this->dependentObjects);
95+
96+
foreach ($updateDependentObjects as $dependentObject) {
97+
$this->dependentObjects[] = $dependentObject->getCreatedObject();
98+
}
99+
$updateEntityObject = DataObjectHandler::getInstance()->getObject($updateDataName);
100+
$curlHandler = new CurlHandler('update', $updateEntityObject, $this->storeCode);
101+
$result = $curlHandler->executeRequest(array_merge($this->dependentObjects, [$this->createdObject]));
94102
$this->setCreatedObject(
95103
$result,
96104
null,

src/Magento/FunctionalTestingFramework/DataGenerator/etc/dataOperation.xsd

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@
7272
<xs:simpleContent>
7373
<xs:extension base="xs:string">
7474
<xs:attribute type="xs:string" name="key" use="required"/>
75-
<xs:attribute type="xs:string" name="type" use="optional"/>
7675
</xs:extension>
7776
</xs:simpleContent>
7877
</xs:complexType>

src/Magento/FunctionalTestingFramework/Util/TestGenerator.php

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -552,40 +552,48 @@ private function generateStepsPhp($stepsObject, $stepsData, $hookObject = false)
552552
}
553553
break;
554554
case "updateData":
555-
$entity = $customActionAttributes['entity'];
556-
$originalEntity = null;
557-
if (isset($customActionAttributes['createDataKey'])) {
558-
$originalEntity = $customActionAttributes['createDataKey'];
559-
}
560-
$key = $steps->getMergeKey();
555+
$key = $customActionAttributes['createDataKey'];
556+
$updateEntity = $customActionAttributes['entity'];
557+
561558
//Add an informative statement to help the user debug test runs
562559
$testSteps .= sprintf(
563-
"\t\t$%s->amGoingTo(\"update entity that has the mergeKey: %s\");\n",
560+
"\t\t$%s->amGoingTo(\"update entity that has the createdDataKey: %s\");\n",
564561
$actor,
565562
$key
566563
);
567-
//Get Entity from Static data.
568-
$testSteps .= sprintf(
569-
"\t\t$%s = DataObjectHandler::getInstance()->getObject(\"%s\");\n",
570-
$entity,
571-
$entity
572-
);
564+
565+
//HookObject End-Product needs to be created in the Class/Cest scope,
566+
//otherwise create them in the Test scope.
567+
//Determine if there are required-entities and create array of required-entities for merging.
568+
$requiredEntities = [];
569+
$requiredEntityObjects = [];
570+
foreach ($customActionAttributes as $customAttribute) {
571+
if (is_array($customAttribute) && $customAttribute['nodeName'] = 'required-entity') {
572+
if ($hookObject) {
573+
$requiredEntities [] = "\$this->" . $customAttribute[self::REQUIRED_ENTITY_REFERENCE] .
574+
"->getName() => " . "\$this->" . $customAttribute[self::REQUIRED_ENTITY_REFERENCE] .
575+
"->getType()";
576+
$requiredEntityObjects [] = '$this->' . $customAttribute
577+
[self::REQUIRED_ENTITY_REFERENCE];
578+
} else {
579+
$requiredEntities [] = "\$" . $customAttribute[self::REQUIRED_ENTITY_REFERENCE]
580+
. "->getName() => " . "\$" . $customAttribute[self::REQUIRED_ENTITY_REFERENCE] .
581+
"->getType()";
582+
$requiredEntityObjects [] = '$' . $customAttribute[self::REQUIRED_ENTITY_REFERENCE];
583+
}
584+
}
585+
}
573586

574587
if ($hookObject) {
575-
$updateEntityFunctionCall = sprintf("\t\t\$this->%s->updateEntity(", $key);
576-
$dataPersistenceHandlerFunctionCall = sprintf(
577-
"\t\t\$this->%s = new DataPersistenceHandler($%s, [\$this->%s]);\n",
578-
$key,
579-
$entity,
580-
$originalEntity
581-
);
588+
$updateEntityFunctionCall = sprintf("\t\t\$this->%s->updateEntity(\"%s\"", $key, $updateEntity);
582589
} else {
583-
$updateEntityFunctionCall = sprintf("\t\t\$%s->updateEntity(", $key);
584-
$dataPersistenceHandlerFunctionCall = sprintf(
585-
"\t\t$%s = new DataPersistenceHandler($%s, [$%s]);\n",
586-
$key,
587-
$entity,
588-
$originalEntity
590+
$updateEntityFunctionCall = sprintf("\t\t\$%s->updateEntity(\"%s\"", $key, $updateEntity);
591+
}
592+
593+
if (!empty($requiredEntities)) {
594+
$updateEntityFunctionCall .= sprintf(
595+
", [%s]",
596+
implode(', ', $requiredEntityObjects)
589597
);
590598
}
591599

@@ -595,7 +603,6 @@ private function generateStepsPhp($stepsObject, $stepsData, $hookObject = false)
595603
$updateEntityFunctionCall .= ");\n";
596604
}
597605

598-
$testSteps .= $dataPersistenceHandlerFunctionCall;
599606
$testSteps .= $updateEntityFunctionCall;
600607
break;
601608
case "getData":

0 commit comments

Comments
 (0)