Skip to content

Commit a368082

Browse files
committed
MQE-743: Can't run tests without a store having "default" store code
- CR Fixes
1 parent e3a0d37 commit a368082

File tree

2 files changed

+29
-10
lines changed

2 files changed

+29
-10
lines changed

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public function __construct($storeCode = null)
7676
*/
7777
protected function authorize()
7878
{
79-
$authUrl = parent::$baseUrl . 'rest/' . $this->storeCode . trim(self::ADMIN_AUTH_URL, '/');
79+
$authUrl = $this->getFormattedUrl(self::ADMIN_AUTH_URL);
8080
$authCreds = [
8181
'username' => getenv('MAGENTO_ADMIN_USERNAME'),
8282
'password' => getenv('MAGENTO_ADMIN_PASSWORD')
@@ -101,7 +101,7 @@ protected function authorize()
101101
public function write($url, $data = [], $method = CurlInterface::POST, $headers = [])
102102
{
103103
$this->transport->write(
104-
parent::$baseUrl . 'rest/' . $this->storeCode . trim($url, '/'),
104+
$this->getFormattedUrl($url),
105105
json_encode($data, JSON_PRETTY_PRINT),
106106
$method,
107107
array_unique(array_merge($headers, $this->headers))
@@ -142,4 +142,19 @@ public function close()
142142
{
143143
$this->transport->close();
144144
}
145+
146+
/**
147+
* Builds and returns URL for request, appending storeCode if needed.
148+
* @param string $resource
149+
* @return string
150+
*/
151+
public function getFormattedUrl($resource)
152+
{
153+
$urlResult = parent::$baseUrl . 'rest/';
154+
if ($this->storeCode != null) {
155+
$urlResult .= $this->storeCode . "/";
156+
}
157+
$urlResult.= trim($resource, "/");
158+
return $urlResult;
159+
}
145160
}

src/Magento/FunctionalTestingFramework/Util/TestGenerator.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,7 @@ public function generateStepsPhp($actionObjects, $hookObject = false, $actor = "
438438
$visible = null;
439439
$command = null;
440440
$sortOrder = null;
441+
$storeCode = null;
441442

442443
$assertExpected = null;
443444
$assertActual = null;
@@ -592,6 +593,9 @@ public function generateStepsPhp($actionObjects, $hookObject = false, $actor = "
592593
$visible = $customActionAttributes['visible'];
593594
}
594595

596+
if (isset($customActionAttributes['storeCode'])) {
597+
$storeCode = $customActionAttributes['storeCode'];
598+
}
595599
switch ($actionObject->getType()) {
596600
case "createData":
597601
$entity = $customActionAttributes['entity'];
@@ -648,8 +652,8 @@ public function generateStepsPhp($actionObjects, $hookObject = false, $actor = "
648652
);
649653
}
650654

651-
if (isset($customActionAttributes['storeCode'])) {
652-
$createEntityFunctionCall .= sprintf("\"%s\");\n", $customActionAttributes['storeCode']);
655+
if (isset($storeCode)) {
656+
$createEntityFunctionCall .= sprintf("\"%s\");\n", $storeCode);
653657
} else {
654658
$createEntityFunctionCall .= ");\n";
655659
}
@@ -684,8 +688,8 @@ public function generateStepsPhp($actionObjects, $hookObject = false, $actor = "
684688
$deleteEntityFunctionCall .= sprintf("\t\t$%s->deleteEntity(", $key);
685689
}
686690

687-
if (isset($customActionAttributes['storeCode'])) {
688-
$deleteEntityFunctionCall .= sprintf("\"%s\");\n", $customActionAttributes['storeCode']);
691+
if (isset($storeCode)) {
692+
$deleteEntityFunctionCall .= sprintf("\"%s\");\n", $storeCode);
689693
} else {
690694
$deleteEntityFunctionCall .= ");\n";
691695
}
@@ -739,8 +743,8 @@ public function generateStepsPhp($actionObjects, $hookObject = false, $actor = "
739743
);
740744
}
741745

742-
if (isset($customActionAttributes['storeCode'])) {
743-
$updateEntityFunctionCall .= sprintf(", \"%s\");\n", $customActionAttributes['storeCode']);
746+
if (isset($storeCode)) {
747+
$updateEntityFunctionCall .= sprintf(", \"%s\");\n", $storeCode);
744748
} else {
745749
$updateEntityFunctionCall .= ");\n";
746750
}
@@ -806,8 +810,8 @@ public function generateStepsPhp($actionObjects, $hookObject = false, $actor = "
806810
$getEntityFunctionCall .= 'null';
807811
}
808812

809-
if (isset($customActionAttributes['storeCode'])) {
810-
$getEntityFunctionCall .= sprintf(", \"%s\");\n", $customActionAttributes['storeCode']);
813+
if (isset($storeCode)) {
814+
$getEntityFunctionCall .= sprintf(", \"%s\");\n", $storeCode);
811815
} else {
812816
$getEntityFunctionCall .= ");\n";
813817
}

0 commit comments

Comments
 (0)