Skip to content

Commit 6eaaa9e

Browse files
authored
MQE-759: Call Operation tags without tying them to an entity
- Test action deleteData now allows you to pass in a url, in lieu of an entity.
1 parent fc58bae commit 6eaaa9e

File tree

6 files changed

+80
-12
lines changed

6 files changed

+80
-12
lines changed

dev/tests/verification/Resources/BasicFunctionalTest.txt

+3
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ class BasicFunctionalTestCest
7575
$I->clickWithRightButton("#element .4123#element", 200, 300);
7676
$I->closeTab();
7777
$I->conditionalClick(".functionalTestSelector", ".functionalDependentTestSelector", true);
78+
$I->amGoingTo("delete entity that has the createDataKey: createKey1");
79+
$createKey1->deleteEntity();
80+
$I->deleteEntityByUrl("/V1/categories{$grabbedData}");
7881
$I->dontSee("someInput", ".functionalTestSelector");
7982
$I->dontSeeCheckboxIsChecked(".functionalTestSelector");
8083
$I->dontSeeCookie("someInput");

dev/tests/verification/TestModule/Test/BasicFunctionalTest.xml

+2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
<clickWithRightButton selector="{{SampleSection.simpleElementOneParam('4123')}}{{SampleSection.simpleElement}}" x="{{offset.x}}" y="{{offset.y}}" stepKey="clickWithRightButtonKeyXY1" />
3939
<closeTab stepKey="closeTabKey1"/>
4040
<conditionalClick selector=".functionalTestSelector" dependentSelector=".functionalDependentTestSelector" visible="true" stepKey="conditionalClickKey1"/>
41+
<deleteData stepKey="deleteKey1" createDataKey="createKey1"/>
42+
<deleteData stepKey="deleteKey2" url="/V1/categories{$grabbedData}"/>
4143
<dontSee userInput="someInput" selector=".functionalTestSelector" stepKey="dontSeeKey1" />
4244
<dontSeeCheckboxIsChecked selector=".functionalTestSelector" stepKey="dontSeeCheckboxIsCheckedKey1"/>
4345
<dontSeeCookie userInput="someInput" stepKey="dontSeeCookieKey1"/>

src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php

+16-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Codeception\Exception\ModuleException;
1919
use Codeception\Util\Uri;
2020
use Codeception\Util\ActionSequence;
21+
use Magento\FunctionalTestingFramework\DataGenerator\Persist\Curl\WebapiExecutor;
2122
use Magento\FunctionalTestingFramework\Util\Protocol\CurlTransport;
2223
use Magento\FunctionalTestingFramework\Util\Protocol\CurlInterface;
2324
use Magento\Setup\Exception;
@@ -437,7 +438,6 @@ public function scrollToTopOfPage()
437438
*/
438439
public function magentoCLI($command)
439440
{
440-
441441
$apiURL = $this->config['url'] . getenv('MAGENTO_CLI_COMMAND_PATH');
442442
$executor = new CurlTransport();
443443
$executor->write($apiURL, [getenv('MAGENTO_CLI_COMMAND_PARAMETER') => $command], CurlInterface::POST, []);
@@ -446,6 +446,21 @@ public function magentoCLI($command)
446446
return $response;
447447
}
448448

449+
/**
450+
* Runs DELETE request to delete a Magento entity against the url given.
451+
* @param string $url
452+
* @param int $storeCode
453+
* @return string
454+
*/
455+
public function deleteEntityByUrl($url, $storeCode = null)
456+
{
457+
$executor = new WebapiExecutor($storeCode);
458+
$executor->write($url, [], CurlInterface::DELETE, []);
459+
$response = $executor->read();
460+
$executor->close();
461+
return $response;
462+
}
463+
449464
/**
450465
* Conditional click for an area that should be visible
451466
*

src/Magento/FunctionalTestingFramework/Test/Objects/ActionObject.php

+27
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
use Magento\FunctionalTestingFramework\DataGenerator\Handlers\DataObjectHandler;
99
use Magento\FunctionalTestingFramework\DataGenerator\Objects\EntityDataObject;
10+
use Magento\FunctionalTestingFramework\Exceptions\XmlException;
1011
use Magento\FunctionalTestingFramework\ObjectManager\ObjectHandlerInterface;
1112
use Magento\FunctionalTestingFramework\Page\Objects\PageObject;
1213
use Magento\FunctionalTestingFramework\Page\Objects\SectionObject;
@@ -34,6 +35,7 @@ class ActionObject
3435
const ASSERTION_ATTRIBUTES = ["expectedResult" => "expected", "actualResult" => "actual"];
3536
const ASSERTION_TYPE_ATTRIBUTE = "type";
3637
const ASSERTION_VALUE_ATTRIBUTE = "value";
38+
const DELETE_DATA_MUTUAL_EXCLUSIVE_ATTRIBUTES = ["url", "createDataKey"];
3739
const EXTERNAL_URL_AREA_INVALID_ACTIONS = ['amOnPage'];
3840
const MERGE_ACTION_ORDER_AFTER = 'after';
3941
const MERGE_ACTION_ORDER_BEFORE = 'before';
@@ -229,6 +231,9 @@ public function resolveReferences()
229231
$this->resolveSelectorReferenceAndTimeout();
230232
$this->resolveUrlReference();
231233
$this->resolveDataInputReferences();
234+
if ($this->getType() == "deleteData") {
235+
$this->validateMutuallyExclusiveAttributes(self::DELETE_DATA_MUTUAL_EXCLUSIVE_ATTRIBUTES);
236+
}
232237
}
233238
}
234239

@@ -496,6 +501,28 @@ private function findAndReplaceReferences($objectHandler, $inputString)
496501
return $outputString;
497502
}
498503

504+
/**
505+
* Validates that the mutually exclusive attributes passed in don't all occur.
506+
* @param array $attributes
507+
* @return void
508+
* @throws TestReferenceException
509+
*/
510+
private function validateMutuallyExclusiveAttributes(array $attributes)
511+
{
512+
$matches = array_intersect($attributes, array_keys($this->getCustomActionAttributes()));
513+
if (count($matches) > 1) {
514+
throw new TestReferenceException(
515+
"Actions of type '{$this->getType()}' must only contain one attribute of types '"
516+
. implode("', '", $attributes) . "'"
517+
);
518+
} elseif (count($matches) == 0) {
519+
throw new TestReferenceException(
520+
"Actions of type '{$this->getType()}' must contain at least one attribute of types '"
521+
. implode("', '", $attributes) . "'"
522+
);
523+
}
524+
}
525+
499526
/**
500527
* Validates the page objects area 'external' against a list of known incompatible types
501528
*

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@
7676
</xs:annotation>
7777
<xs:simpleContent>
7878
<xs:extension base="xs:string">
79-
<xs:attribute ref="createDataKey" use="required"/>
79+
<xs:attribute ref="url"/>
80+
<xs:attribute ref="createDataKey"/>
8081
<xs:attributeGroup ref="commonActionAttributes"/>
8182
<xs:attribute ref="storeCode"/>
8283
</xs:extension>

src/Magento/FunctionalTestingFramework/Util/TestGenerator.php

+30-10
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,7 @@ public function generateStepsPhp($actionObjects, $hookObject = false, $actor = "
510510
$input = $this->addUniquenessFunctionCall($customActionAttributes['userInput']);
511511
} elseif (isset($customActionAttributes['url'])) {
512512
$input = $this->addUniquenessFunctionCall($customActionAttributes['url']);
513+
$url = $this->addUniquenessFunctionCall($customActionAttributes['url']);
513514
} elseif (isset($customActionAttributes['expectedValue'])) {
514515
//For old Assert backwards Compatibility, remove when deprecating
515516
$assertExpected = $this->addUniquenessFunctionCall($customActionAttributes['expectedValue']);
@@ -712,18 +713,37 @@ public function generateStepsPhp($actionObjects, $hookObject = false, $actor = "
712713
$testSteps .= $createEntityFunctionCall;
713714
break;
714715
case "deleteData":
715-
$key = $customActionAttributes['createDataKey'];
716-
//Add an informative statement to help the user debug test runs
717-
$testSteps .= sprintf(
718-
"\t\t$%s->amGoingTo(\"delete entity that has the createDataKey: %s\");\n",
719-
$actor,
720-
$key
721-
);
716+
if (isset($customActionAttributes['createDataKey'])) {
717+
$key = $customActionAttributes['createDataKey'];
718+
//Add an informative statement to help the user debug test runs
719+
$testSteps .= sprintf(
720+
"\t\t$%s->amGoingTo(\"delete entity that has the createDataKey: %s\");\n",
721+
$actor,
722+
$key
723+
);
722724

723-
if ($hookObject) {
724-
$testSteps .= sprintf("\t\t\$this->%s->deleteEntity();\n", $key);
725+
if ($hookObject) {
726+
$testSteps .= sprintf("\t\t\$this->%s->deleteEntity();\n", $key);
727+
} else {
728+
$testSteps .= sprintf("\t\t$%s->deleteEntity();\n", $key);
729+
}
725730
} else {
726-
$testSteps .= sprintf("\t\t$%s->deleteEntity();\n", $key);
731+
$output = sprintf(
732+
"\t\t$%s->deleteEntityByUrl(%s",
733+
$actor,
734+
$url
735+
);
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);
727747
}
728748
break;
729749
case "updateData":

0 commit comments

Comments
 (0)