Skip to content

Commit 942eaf0

Browse files
committed
MQE-472: refactored entity update mechanism and removed path param type.
1 parent 422271e commit 942eaf0

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
@@ -544,40 +544,48 @@ private function generateStepsPhp($stepsObject, $stepsData, $hookObject = false)
544544
}
545545
break;
546546
case "updateData":
547-
$entity = $customActionAttributes['entity'];
548-
$originalEntity = null;
549-
if (isset($customActionAttributes['createDataKey'])) {
550-
$originalEntity = $customActionAttributes['createDataKey'];
551-
}
552-
$key = $steps->getMergeKey();
547+
$key = $customActionAttributes['createDataKey'];
548+
$updateEntity = $customActionAttributes['entity'];
549+
553550
//Add an informative statement to help the user debug test runs
554551
$testSteps .= sprintf(
555-
"\t\t$%s->amGoingTo(\"update entity that has the mergeKey: %s\");\n",
552+
"\t\t$%s->amGoingTo(\"update entity that has the createdDataKey: %s\");\n",
556553
$actor,
557554
$key
558555
);
559-
//Get Entity from Static data.
560-
$testSteps .= sprintf(
561-
"\t\t$%s = DataObjectHandler::getInstance()->getObject(\"%s\");\n",
562-
$entity,
563-
$entity
564-
);
556+
557+
//HookObject End-Product needs to be created in the Class/Cest scope,
558+
//otherwise create them in the Test scope.
559+
//Determine if there are required-entities and create array of required-entities for merging.
560+
$requiredEntities = [];
561+
$requiredEntityObjects = [];
562+
foreach ($customActionAttributes as $customAttribute) {
563+
if (is_array($customAttribute) && $customAttribute['nodeName'] = 'required-entity') {
564+
if ($hookObject) {
565+
$requiredEntities [] = "\$this->" . $customAttribute[self::REQUIRED_ENTITY_REFERENCE] .
566+
"->getName() => " . "\$this->" . $customAttribute[self::REQUIRED_ENTITY_REFERENCE] .
567+
"->getType()";
568+
$requiredEntityObjects [] = '$this->' . $customAttribute
569+
[self::REQUIRED_ENTITY_REFERENCE];
570+
} else {
571+
$requiredEntities [] = "\$" . $customAttribute[self::REQUIRED_ENTITY_REFERENCE]
572+
. "->getName() => " . "\$" . $customAttribute[self::REQUIRED_ENTITY_REFERENCE] .
573+
"->getType()";
574+
$requiredEntityObjects [] = '$' . $customAttribute[self::REQUIRED_ENTITY_REFERENCE];
575+
}
576+
}
577+
}
565578

566579
if ($hookObject) {
567-
$updateEntityFunctionCall = sprintf("\t\t\$this->%s->updateEntity(", $key);
568-
$dataPersistenceHandlerFunctionCall = sprintf(
569-
"\t\t\$this->%s = new DataPersistenceHandler($%s, [\$this->%s]);\n",
570-
$key,
571-
$entity,
572-
$originalEntity
573-
);
580+
$updateEntityFunctionCall = sprintf("\t\t\$this->%s->updateEntity(\"%s\"", $key, $updateEntity);
574581
} else {
575-
$updateEntityFunctionCall = sprintf("\t\t\$%s->updateEntity(", $key);
576-
$dataPersistenceHandlerFunctionCall = sprintf(
577-
"\t\t$%s = new DataPersistenceHandler($%s, [$%s]);\n",
578-
$key,
579-
$entity,
580-
$originalEntity
582+
$updateEntityFunctionCall = sprintf("\t\t\$%s->updateEntity(\"%s\"", $key, $updateEntity);
583+
}
584+
585+
if (!empty($requiredEntities)) {
586+
$updateEntityFunctionCall .= sprintf(
587+
", [%s]",
588+
implode(', ', $requiredEntityObjects)
581589
);
582590
}
583591

@@ -587,7 +595,6 @@ private function generateStepsPhp($stepsObject, $stepsData, $hookObject = false)
587595
$updateEntityFunctionCall .= ");\n";
588596
}
589597

590-
$testSteps .= $dataPersistenceHandlerFunctionCall;
591598
$testSteps .= $updateEntityFunctionCall;
592599
break;
593600
case "getData":

0 commit comments

Comments
 (0)