Skip to content

MQE-743: Can't run tests without a store having "default" store code #86

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,12 @@ class WebapiExecutor extends AbstractExecutor implements CurlInterface
*
* @param string $storeCode
*/
public function __construct($storeCode = 'default')
public function __construct($storeCode = null)
{
if (!isset(parent::$baseUrl)) {
parent::resolveBaseUrl();
}

$this->storeCode = $storeCode;
$this->transport = new CurlTransport();
$this->authorize();
Expand All @@ -72,7 +73,7 @@ public function __construct($storeCode = 'default')
*/
protected function authorize()
{
$authUrl = parent::$baseUrl . 'rest/' . $this->storeCode . self::ADMIN_AUTH_URL;
$authUrl = $this->getFormattedUrl(self::ADMIN_AUTH_URL);
$authCreds = [
'username' => getenv('MAGENTO_ADMIN_USERNAME'),
'password' => getenv('MAGENTO_ADMIN_PASSWORD')
Expand All @@ -97,7 +98,7 @@ protected function authorize()
public function write($url, $data = [], $method = CurlInterface::POST, $headers = [])
{
$this->transport->write(
parent::$baseUrl . 'rest/' . $this->storeCode . '/' . trim($url, '/'),
$this->getFormattedUrl($url),
json_encode($data, JSON_PRETTY_PRINT),
$method,
array_unique(array_merge($headers, $this->headers))
Expand Down Expand Up @@ -138,4 +139,19 @@ public function close()
{
$this->transport->close();
}

/**
* Builds and returns URL for request, appending storeCode if needed.
* @param string $resource
* @return string
*/
public function getFormattedUrl($resource)
{
$urlResult = parent::$baseUrl . 'rest/';
if ($this->storeCode != null) {
$urlResult .= $this->storeCode . "/";
}
$urlResult.= trim($resource, "/");
return $urlResult;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class CurlHandler
* @param EntityDataObject $entityObject
* @param string $storeCode
*/
public function __construct($operation, $entityObject, $storeCode = 'default')
public function __construct($operation, $entityObject, $storeCode = null)
{
$this->operation = $operation;
$this->entityObject = $entityObject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function __construct($entityObject, $dependentObjects = [], $customFields
} else {
$this->entityObject = clone $entityObject;
}
$this->storeCode = 'default';
$this->storeCode = null;

foreach ($dependentObjects as $dependentObject) {
$this->dependentObjects[] = $dependentObject->getCreatedObject();
Expand Down Expand Up @@ -96,16 +96,11 @@ public function createEntity($storeCode = null)
*
* @param string $updateDataName
* @param array $updateDependentObjects
* @param string $storeCode
* @return void
*/

public function updateEntity($updateDataName, $updateDependentObjects = [], $storeCode = null)
public function updateEntity($updateDataName, $updateDependentObjects = [])
{
if (!empty($storeCode)) {
$this->storeCode = $storeCode;
}

foreach ($updateDependentObjects as $dependentObject) {
$this->dependentObjects[] = $dependentObject->getCreatedObject();
}
Expand Down Expand Up @@ -146,14 +141,10 @@ public function getEntity($index = null, $storeCode = null)
/**
* Function which executes a delete request based on specific operation metadata
*
* @param string $storeCode
* @return void
*/
public function deleteEntity($storeCode = null)
public function deleteEntity()
{
if (!empty($storeCode)) {
$this->storeCode = $storeCode;
}
$curlHandler = new CurlHandler('delete', $this->createdObject, $this->storeCode);
$curlHandler->executeRequest($this->dependentObjects);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -449,12 +449,11 @@ public function magentoCLI($command)
/**
* Runs DELETE request to delete a Magento entity against the url given.
* @param string $url
* @param int $storeCode
* @return string
*/
public function deleteEntityByUrl($url, $storeCode = null)
public function deleteEntityByUrl($url)
{
$executor = new WebapiExecutor($storeCode);
$executor = new WebapiExecutor(null);
$executor->write($url, [], CurlInterface::DELETE, []);
$response = $executor->read();
$executor->close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
<xs:attribute ref="entity" use="required"/>
<xs:attribute ref="createDataKey" use="required"/>
<xs:attributeGroup ref="commonActionAttributes"/>
<xs:attribute ref="storeCode"/>
</xs:complexType>

<xs:complexType name="deleteDataType">
Expand All @@ -79,7 +78,6 @@
<xs:attribute ref="url"/>
<xs:attribute ref="createDataKey"/>
<xs:attributeGroup ref="commonActionAttributes"/>
<xs:attribute ref="storeCode"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
Expand Down
43 changes: 21 additions & 22 deletions src/Magento/FunctionalTestingFramework/Util/TestGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,7 @@ public function generateStepsPhp($actionObjects, $hookObject = false, $actor = "
$visible = null;
$command = null;
$sortOrder = null;
$storeCode = null;

$assertExpected = null;
$assertActual = null;
Expand Down Expand Up @@ -635,6 +636,9 @@ public function generateStepsPhp($actionObjects, $hookObject = false, $actor = "
$visible = $customActionAttributes['visible'];
}

if (isset($customActionAttributes['storeCode'])) {
$storeCode = $customActionAttributes['storeCode'];
}
switch ($actionObject->getType()) {
case "createData":
$entity = $customActionAttributes['entity'];
Expand Down Expand Up @@ -691,8 +695,8 @@ public function generateStepsPhp($actionObjects, $hookObject = false, $actor = "
);
}

if (isset($customActionAttributes['storeCode'])) {
$createEntityFunctionCall .= sprintf("\"%s\");\n", $customActionAttributes['storeCode']);
if (isset($storeCode)) {
$createEntityFunctionCall .= sprintf("\"%s\");\n", $storeCode);
} else {
$createEntityFunctionCall .= ");\n";
}
Expand All @@ -716,34 +720,29 @@ public function generateStepsPhp($actionObjects, $hookObject = false, $actor = "
if (isset($customActionAttributes['createDataKey'])) {
$key = $customActionAttributes['createDataKey'];
//Add an informative statement to help the user debug test runs
$testSteps .= sprintf(
$contextSetter = sprintf(
"\t\t$%s->amGoingTo(\"delete entity that has the createDataKey: %s\");\n",
$actor,
$key
);
$deleteEntityFunctionCall = "";

if ($hookObject) {
$testSteps .= sprintf("\t\t\$this->%s->deleteEntity();\n", $key);
$deleteEntityFunctionCall .= sprintf("\t\t\$this->%s->deleteEntity();\n", $key);
} else {
$testSteps .= sprintf("\t\t$%s->deleteEntity();\n", $key);
$deleteEntityFunctionCall .= sprintf("\t\t$%s->deleteEntity();\n", $key);
}

$testSteps .= $contextSetter;
$testSteps .= $deleteEntityFunctionCall;
} else {
$output = sprintf(
"\t\t$%s->deleteEntityByUrl(%s",
"\t\t$%s->deleteEntityByUrl(%s);\n",
$actor,
$url
);
$storeCode = null;
if (isset($customActionAttributes["storeCode"])) {
$storeCode = $customActionAttributes["storeCode"];
$output .= sprintf(
", %s",
$storeCode
);
}
$output .= ");\n";
$output = $this->resolveEnvReferences($output, [$url, $storeCode]);
$testSteps .= $this->resolveTestVariable($output, [$url, $storeCode], null);
$output = $this->resolveEnvReferences($output, [$url]);
$testSteps .= $this->resolveTestVariable($output, [$url], null);
}
break;
case "updateData":
Expand Down Expand Up @@ -792,8 +791,8 @@ public function generateStepsPhp($actionObjects, $hookObject = false, $actor = "
);
}

if (isset($customActionAttributes['storeCode'])) {
$updateEntityFunctionCall .= sprintf("\"%s\");\n", $customActionAttributes['storeCode']);
if (isset($storeCode)) {
$updateEntityFunctionCall .= sprintf(", \"%s\");\n", $storeCode);
} else {
$updateEntityFunctionCall .= ");\n";
}
Expand Down Expand Up @@ -854,13 +853,13 @@ public function generateStepsPhp($actionObjects, $hookObject = false, $actor = "
}

if (isset($customActionAttributes['index'])) {
$getEntityFunctionCall .= sprintf("%s", (int)$customActionAttributes['index']);
$getEntityFunctionCall .= sprintf(", %s", (int)$customActionAttributes['index']);
} else {
$getEntityFunctionCall .= 'null';
}

if (isset($customActionAttributes['storeCode'])) {
$getEntityFunctionCall .= sprintf(", \"%s\");\n", $customActionAttributes['storeCode']);
if (isset($storeCode)) {
$getEntityFunctionCall .= sprintf(", \"%s\");\n", $storeCode);
} else {
$getEntityFunctionCall .= ");\n";
}
Expand Down