Skip to content

Commit

Permalink
Merge branch 'develop' into MQE-876
Browse files Browse the repository at this point in the history
  • Loading branch information
magterskine authored Apr 5, 2018
2 parents c2f07e5 + 2e466f2 commit 8f84d7e
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 37 deletions.
3 changes: 3 additions & 0 deletions dev/tests/verification/Resources/BasicFunctionalTest.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ class BasicFunctionalTestCest
$I->clickWithRightButton("#element .4123#element", 200, 300);
$I->closeTab();
$I->conditionalClick(".functionalTestSelector", ".functionalDependentTestSelector", true);
$I->amGoingTo("delete entity that has the createDataKey: createKey1");
$createKey1->deleteEntity();
$I->deleteEntityByUrl("/V1/categories{$grabbedData}");
$I->dontSee("someInput", ".functionalTestSelector");
$I->dontSeeCheckboxIsChecked(".functionalTestSelector");
$I->dontSeeCookie("someInput");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
<clickWithRightButton selector="{{SampleSection.simpleElementOneParam('4123')}}{{SampleSection.simpleElement}}" x="{{offset.x}}" y="{{offset.y}}" stepKey="clickWithRightButtonKeyXY1" />
<closeTab stepKey="closeTabKey1"/>
<conditionalClick selector=".functionalTestSelector" dependentSelector=".functionalDependentTestSelector" visible="true" stepKey="conditionalClickKey1"/>
<deleteData stepKey="deleteKey1" createDataKey="createKey1"/>
<deleteData stepKey="deleteKey2" url="/V1/categories{$grabbedData}"/>
<dontSee userInput="someInput" selector=".functionalTestSelector" stepKey="dontSeeKey1" />
<dontSeeCheckboxIsChecked selector=".functionalTestSelector" stepKey="dontSeeCheckboxIsCheckedKey1"/>
<dontSeeCookie userInput="someInput" stepKey="dontSeeCookieKey1"/>
Expand Down
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 @@ -18,6 +18,7 @@
use Codeception\Exception\ModuleException;
use Codeception\Util\Uri;
use Codeception\Util\ActionSequence;
use Magento\FunctionalTestingFramework\DataGenerator\Persist\Curl\WebapiExecutor;
use Magento\FunctionalTestingFramework\Util\Protocol\CurlTransport;
use Magento\FunctionalTestingFramework\Util\Protocol\CurlInterface;
use Magento\Setup\Exception;
Expand Down Expand Up @@ -437,7 +438,6 @@ public function scrollToTopOfPage()
*/
public function magentoCLI($command)
{

$apiURL = $this->config['url'] . getenv('MAGENTO_CLI_COMMAND_PATH');
$executor = new CurlTransport();
$executor->write($apiURL, [getenv('MAGENTO_CLI_COMMAND_PARAMETER') => $command], CurlInterface::POST, []);
Expand All @@ -446,6 +446,20 @@ public function magentoCLI($command)
return $response;
}

/**
* Runs DELETE request to delete a Magento entity against the url given.
* @param string $url
* @return string
*/
public function deleteEntityByUrl($url)
{
$executor = new WebapiExecutor(null);
$executor->write($url, [], CurlInterface::DELETE, []);
$response = $executor->read();
$executor->close();
return $response;
}

/**
* Conditional click for an area that should be visible
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

use Magento\FunctionalTestingFramework\DataGenerator\Handlers\DataObjectHandler;
use Magento\FunctionalTestingFramework\DataGenerator\Objects\EntityDataObject;
use Magento\FunctionalTestingFramework\Exceptions\XmlException;
use Magento\FunctionalTestingFramework\ObjectManager\ObjectHandlerInterface;
use Magento\FunctionalTestingFramework\Page\Objects\PageObject;
use Magento\FunctionalTestingFramework\Page\Objects\SectionObject;
Expand Down Expand Up @@ -34,6 +35,7 @@ class ActionObject
const ASSERTION_ATTRIBUTES = ["expectedResult" => "expected", "actualResult" => "actual"];
const ASSERTION_TYPE_ATTRIBUTE = "type";
const ASSERTION_VALUE_ATTRIBUTE = "value";
const DELETE_DATA_MUTUAL_EXCLUSIVE_ATTRIBUTES = ["url", "createDataKey"];
const EXTERNAL_URL_AREA_INVALID_ACTIONS = ['amOnPage'];
const MERGE_ACTION_ORDER_AFTER = 'after';
const MERGE_ACTION_ORDER_BEFORE = 'before';
Expand Down Expand Up @@ -229,6 +231,9 @@ public function resolveReferences()
$this->resolveSelectorReferenceAndTimeout();
$this->resolveUrlReference();
$this->resolveDataInputReferences();
if ($this->getType() == "deleteData") {
$this->validateMutuallyExclusiveAttributes(self::DELETE_DATA_MUTUAL_EXCLUSIVE_ATTRIBUTES);
}
}
}

Expand Down Expand Up @@ -496,6 +501,28 @@ private function findAndReplaceReferences($objectHandler, $inputString)
return $outputString;
}

/**
* Validates that the mutually exclusive attributes passed in don't all occur.
* @param array $attributes
* @return void
* @throws TestReferenceException
*/
private function validateMutuallyExclusiveAttributes(array $attributes)
{
$matches = array_intersect($attributes, array_keys($this->getCustomActionAttributes()));
if (count($matches) > 1) {
throw new TestReferenceException(
"Actions of type '{$this->getType()}' must only contain one attribute of types '"
. implode("', '", $attributes) . "'"
);
} elseif (count($matches) == 0) {
throw new TestReferenceException(
"Actions of type '{$this->getType()}' must contain at least one attribute of types '"
. implode("', '", $attributes) . "'"
);
}
}

/**
* Validates the page objects area 'external' against a list of known incompatible types
*
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 @@ -76,9 +75,9 @@
</xs:annotation>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute ref="createDataKey" use="required"/>
<xs:attribute ref="url"/>
<xs:attribute ref="createDataKey"/>
<xs:attributeGroup ref="commonActionAttributes"/>
<xs:attribute ref="storeCode"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
Expand Down
53 changes: 36 additions & 17 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 @@ -510,6 +511,7 @@ public function generateStepsPhp($actionObjects, $hookObject = false, $actor = "
$input = $this->addUniquenessFunctionCall($customActionAttributes['userInput']);
} elseif (isset($customActionAttributes['url'])) {
$input = $this->addUniquenessFunctionCall($customActionAttributes['url']);
$url = $this->addUniquenessFunctionCall($customActionAttributes['url']);
} elseif (isset($customActionAttributes['expectedValue'])) {
//For old Assert backwards Compatibility, remove when deprecating
$assertExpected = $this->addUniquenessFunctionCall($customActionAttributes['expectedValue']);
Expand Down Expand Up @@ -634,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 @@ -690,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 @@ -712,18 +717,32 @@ public function generateStepsPhp($actionObjects, $hookObject = false, $actor = "
$testSteps .= $createEntityFunctionCall;
break;
case "deleteData":
$key = $customActionAttributes['createDataKey'];
//Add an informative statement to help the user debug test runs
$testSteps .= sprintf(
"\t\t$%s->amGoingTo(\"delete entity that has the createDataKey: %s\");\n",
$actor,
$key
);
if (isset($customActionAttributes['createDataKey'])) {
$key = $customActionAttributes['createDataKey'];
//Add an informative statement to help the user debug test runs
$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);
if ($hookObject) {
$deleteEntityFunctionCall .= sprintf("\t\t\$this->%s->deleteEntity();\n", $key);
} else {
$deleteEntityFunctionCall .= sprintf("\t\t$%s->deleteEntity();\n", $key);
}

$testSteps .= $contextSetter;
$testSteps .= $deleteEntityFunctionCall;
} else {
$testSteps .= sprintf("\t\t$%s->deleteEntity();\n", $key);
$output = sprintf(
"\t\t$%s->deleteEntityByUrl(%s);\n",
$actor,
$url
);
$output = $this->resolveEnvReferences($output, [$url]);
$testSteps .= $this->resolveTestVariable($output, [$url], null);
}
break;
case "updateData":
Expand Down Expand Up @@ -772,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 @@ -834,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

0 comments on commit 8f84d7e

Please sign in to comment.