Skip to content

MQE-759: Call Operation tags without tying them to an entity #82

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 4 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
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 @@ -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,21 @@ public function magentoCLI($command)
return $response;
}

/**
* 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)
{
$executor = new WebapiExecutor($storeCode);
$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 @@ -76,7 +76,8 @@
</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>
Expand Down
40 changes: 30 additions & 10 deletions src/Magento/FunctionalTestingFramework/Util/TestGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,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 @@ -712,18 +713,37 @@ 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
$testSteps .= sprintf(
"\t\t$%s->amGoingTo(\"delete entity that has the createDataKey: %s\");\n",
$actor,
$key
);

if ($hookObject) {
$testSteps .= sprintf("\t\t\$this->%s->deleteEntity();\n", $key);
if ($hookObject) {
$testSteps .= sprintf("\t\t\$this->%s->deleteEntity();\n", $key);
} else {
$testSteps .= sprintf("\t\t$%s->deleteEntity();\n", $key);
}
} else {
$testSteps .= sprintf("\t\t$%s->deleteEntity();\n", $key);
$output = sprintf(
"\t\t$%s->deleteEntityByUrl(%s",
$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);
}
break;
case "updateData":
Expand Down