Skip to content

Commit 2e466f2

Browse files
authored
MQE-743: Can't run tests without a store having "default" store code
- Persistence mechanisms now do not append 'default' where no store code is given (rely on magento web api to redirect to the default) - update/delete data actions no longer allow for a storeCode, relies on handler's storeCode for overrides - create/get data actions take a storeCode, and overwrite the handler's storeCode if given
1 parent 6eaaa9e commit 2e466f2

File tree

6 files changed

+46
-43
lines changed

6 files changed

+46
-43
lines changed

src/Magento/FunctionalTestingFramework/DataGenerator/Persist/Curl/WebapiExecutor.php

+19-3
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,12 @@ class WebapiExecutor extends AbstractExecutor implements CurlInterface
5555
*
5656
* @param string $storeCode
5757
*/
58-
public function __construct($storeCode = 'default')
58+
public function __construct($storeCode = null)
5959
{
6060
if (!isset(parent::$baseUrl)) {
6161
parent::resolveBaseUrl();
6262
}
63+
6364
$this->storeCode = $storeCode;
6465
$this->transport = new CurlTransport();
6566
$this->authorize();
@@ -72,7 +73,7 @@ public function __construct($storeCode = 'default')
7273
*/
7374
protected function authorize()
7475
{
75-
$authUrl = parent::$baseUrl . 'rest/' . $this->storeCode . self::ADMIN_AUTH_URL;
76+
$authUrl = $this->getFormattedUrl(self::ADMIN_AUTH_URL);
7677
$authCreds = [
7778
'username' => getenv('MAGENTO_ADMIN_USERNAME'),
7879
'password' => getenv('MAGENTO_ADMIN_PASSWORD')
@@ -97,7 +98,7 @@ protected function authorize()
9798
public function write($url, $data = [], $method = CurlInterface::POST, $headers = [])
9899
{
99100
$this->transport->write(
100-
parent::$baseUrl . 'rest/' . $this->storeCode . '/' . trim($url, '/'),
101+
$this->getFormattedUrl($url),
101102
json_encode($data, JSON_PRETTY_PRINT),
102103
$method,
103104
array_unique(array_merge($headers, $this->headers))
@@ -138,4 +139,19 @@ public function close()
138139
{
139140
$this->transport->close();
140141
}
142+
143+
/**
144+
* Builds and returns URL for request, appending storeCode if needed.
145+
* @param string $resource
146+
* @return string
147+
*/
148+
public function getFormattedUrl($resource)
149+
{
150+
$urlResult = parent::$baseUrl . 'rest/';
151+
if ($this->storeCode != null) {
152+
$urlResult .= $this->storeCode . "/";
153+
}
154+
$urlResult.= trim($resource, "/");
155+
return $urlResult;
156+
}
141157
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class CurlHandler
8181
* @param EntityDataObject $entityObject
8282
* @param string $storeCode
8383
*/
84-
public function __construct($operation, $entityObject, $storeCode = 'default')
84+
public function __construct($operation, $entityObject, $storeCode = null)
8585
{
8686
$this->operation = $operation;
8787
$this->entityObject = $entityObject;

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

+3-12
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function __construct($entityObject, $dependentObjects = [], $customFields
6363
} else {
6464
$this->entityObject = clone $entityObject;
6565
}
66-
$this->storeCode = 'default';
66+
$this->storeCode = null;
6767

6868
foreach ($dependentObjects as $dependentObject) {
6969
$this->dependentObjects[] = $dependentObject->getCreatedObject();
@@ -96,16 +96,11 @@ public function createEntity($storeCode = null)
9696
*
9797
* @param string $updateDataName
9898
* @param array $updateDependentObjects
99-
* @param string $storeCode
10099
* @return void
101100
*/
102101

103-
public function updateEntity($updateDataName, $updateDependentObjects = [], $storeCode = null)
102+
public function updateEntity($updateDataName, $updateDependentObjects = [])
104103
{
105-
if (!empty($storeCode)) {
106-
$this->storeCode = $storeCode;
107-
}
108-
109104
foreach ($updateDependentObjects as $dependentObject) {
110105
$this->dependentObjects[] = $dependentObject->getCreatedObject();
111106
}
@@ -146,14 +141,10 @@ public function getEntity($index = null, $storeCode = null)
146141
/**
147142
* Function which executes a delete request based on specific operation metadata
148143
*
149-
* @param string $storeCode
150144
* @return void
151145
*/
152-
public function deleteEntity($storeCode = null)
146+
public function deleteEntity()
153147
{
154-
if (!empty($storeCode)) {
155-
$this->storeCode = $storeCode;
156-
}
157148
$curlHandler = new CurlHandler('delete', $this->createdObject, $this->storeCode);
158149
$curlHandler->executeRequest($this->dependentObjects);
159150
}

src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -449,12 +449,11 @@ public function magentoCLI($command)
449449
/**
450450
* Runs DELETE request to delete a Magento entity against the url given.
451451
* @param string $url
452-
* @param int $storeCode
453452
* @return string
454453
*/
455-
public function deleteEntityByUrl($url, $storeCode = null)
454+
public function deleteEntityByUrl($url)
456455
{
457-
$executor = new WebapiExecutor($storeCode);
456+
$executor = new WebapiExecutor(null);
458457
$executor->write($url, [], CurlInterface::DELETE, []);
459458
$response = $executor->read();
460459
$executor->close();

src/Magento/FunctionalTestingFramework/Test/etc/Actions/dataActions.xsd

-2
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@
6767
<xs:attribute ref="entity" use="required"/>
6868
<xs:attribute ref="createDataKey" use="required"/>
6969
<xs:attributeGroup ref="commonActionAttributes"/>
70-
<xs:attribute ref="storeCode"/>
7170
</xs:complexType>
7271

7372
<xs:complexType name="deleteDataType">
@@ -79,7 +78,6 @@
7978
<xs:attribute ref="url"/>
8079
<xs:attribute ref="createDataKey"/>
8180
<xs:attributeGroup ref="commonActionAttributes"/>
82-
<xs:attribute ref="storeCode"/>
8381
</xs:extension>
8482
</xs:simpleContent>
8583
</xs:complexType>

src/Magento/FunctionalTestingFramework/Util/TestGenerator.php

+21-22
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,7 @@ public function generateStepsPhp($actionObjects, $hookObject = false, $actor = "
481481
$visible = null;
482482
$command = null;
483483
$sortOrder = null;
484+
$storeCode = null;
484485

485486
$assertExpected = null;
486487
$assertActual = null;
@@ -635,6 +636,9 @@ public function generateStepsPhp($actionObjects, $hookObject = false, $actor = "
635636
$visible = $customActionAttributes['visible'];
636637
}
637638

639+
if (isset($customActionAttributes['storeCode'])) {
640+
$storeCode = $customActionAttributes['storeCode'];
641+
}
638642
switch ($actionObject->getType()) {
639643
case "createData":
640644
$entity = $customActionAttributes['entity'];
@@ -691,8 +695,8 @@ public function generateStepsPhp($actionObjects, $hookObject = false, $actor = "
691695
);
692696
}
693697

694-
if (isset($customActionAttributes['storeCode'])) {
695-
$createEntityFunctionCall .= sprintf("\"%s\");\n", $customActionAttributes['storeCode']);
698+
if (isset($storeCode)) {
699+
$createEntityFunctionCall .= sprintf("\"%s\");\n", $storeCode);
696700
} else {
697701
$createEntityFunctionCall .= ");\n";
698702
}
@@ -716,34 +720,29 @@ public function generateStepsPhp($actionObjects, $hookObject = false, $actor = "
716720
if (isset($customActionAttributes['createDataKey'])) {
717721
$key = $customActionAttributes['createDataKey'];
718722
//Add an informative statement to help the user debug test runs
719-
$testSteps .= sprintf(
723+
$contextSetter = sprintf(
720724
"\t\t$%s->amGoingTo(\"delete entity that has the createDataKey: %s\");\n",
721725
$actor,
722726
$key
723727
);
728+
$deleteEntityFunctionCall = "";
724729

725730
if ($hookObject) {
726-
$testSteps .= sprintf("\t\t\$this->%s->deleteEntity();\n", $key);
731+
$deleteEntityFunctionCall .= sprintf("\t\t\$this->%s->deleteEntity();\n", $key);
727732
} else {
728-
$testSteps .= sprintf("\t\t$%s->deleteEntity();\n", $key);
733+
$deleteEntityFunctionCall .= sprintf("\t\t$%s->deleteEntity();\n", $key);
729734
}
735+
736+
$testSteps .= $contextSetter;
737+
$testSteps .= $deleteEntityFunctionCall;
730738
} else {
731739
$output = sprintf(
732-
"\t\t$%s->deleteEntityByUrl(%s",
740+
"\t\t$%s->deleteEntityByUrl(%s);\n",
733741
$actor,
734742
$url
735743
);
736-
$storeCode = null;
737-
if (isset($customActionAttributes["storeCode"])) {
738-
$storeCode = $customActionAttributes["storeCode"];
739-
$output .= sprintf(
740-
", %s",
741-
$storeCode
742-
);
743-
}
744-
$output .= ");\n";
745-
$output = $this->resolveEnvReferences($output, [$url, $storeCode]);
746-
$testSteps .= $this->resolveTestVariable($output, [$url, $storeCode], null);
744+
$output = $this->resolveEnvReferences($output, [$url]);
745+
$testSteps .= $this->resolveTestVariable($output, [$url], null);
747746
}
748747
break;
749748
case "updateData":
@@ -792,8 +791,8 @@ public function generateStepsPhp($actionObjects, $hookObject = false, $actor = "
792791
);
793792
}
794793

795-
if (isset($customActionAttributes['storeCode'])) {
796-
$updateEntityFunctionCall .= sprintf("\"%s\");\n", $customActionAttributes['storeCode']);
794+
if (isset($storeCode)) {
795+
$updateEntityFunctionCall .= sprintf(", \"%s\");\n", $storeCode);
797796
} else {
798797
$updateEntityFunctionCall .= ");\n";
799798
}
@@ -854,13 +853,13 @@ public function generateStepsPhp($actionObjects, $hookObject = false, $actor = "
854853
}
855854

856855
if (isset($customActionAttributes['index'])) {
857-
$getEntityFunctionCall .= sprintf("%s", (int)$customActionAttributes['index']);
856+
$getEntityFunctionCall .= sprintf(", %s", (int)$customActionAttributes['index']);
858857
} else {
859858
$getEntityFunctionCall .= 'null';
860859
}
861860

862-
if (isset($customActionAttributes['storeCode'])) {
863-
$getEntityFunctionCall .= sprintf(", \"%s\");\n", $customActionAttributes['storeCode']);
861+
if (isset($storeCode)) {
862+
$getEntityFunctionCall .= sprintf(", \"%s\");\n", $storeCode);
864863
} else {
865864
$getEntityFunctionCall .= ");\n";
866865
}

0 commit comments

Comments
 (0)