Skip to content

Commit 8190fb8

Browse files
authored
Merge branch 'develop' into master
2 parents bb1518a + ba061e6 commit 8190fb8

File tree

15 files changed

+188
-15
lines changed

15 files changed

+188
-15
lines changed

dev/tests/unit/Magento/FunctionalTestFramework/Test/Config/ActionGroupDomTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace Tests\unit\Magento\FunctionalTestFramework\Test\Config;
77

88
use Magento\FunctionalTestingFramework\Exceptions\Collector\ExceptionCollector;
9+
use Magento\FunctionalTestingFramework\Config\Dom\ValidationException;
910
use Magento\FunctionalTestingFramework\Test\Config\ActionGroupDom;
1011
use Magento\FunctionalTestingFramework\Util\MagentoTestCase;
1112

@@ -29,4 +30,21 @@ public function testActionGroupDomStepKeyValidation()
2930
$this->expectException(\Exception::class);
3031
$exceptionCollector->throwException();
3132
}
33+
34+
/**
35+
* Test Action Group invalid XML
36+
*/
37+
public function testActionGroupDomInvalidXmlValidation()
38+
{
39+
$sampleXml = "<actionGroups>
40+
<actionGroup name=\"sampleActionGroup\">
41+
<wait>
42+
</actionGroup>
43+
</actionGroups>";
44+
45+
$exceptionCollector = new ExceptionCollector();
46+
$this->expectException(ValidationException::class);
47+
$this->expectExceptionMessage("XML Parse Error: invalid.xml\n");
48+
new ActionGroupDom($sampleXml, 'invalid.xml', $exceptionCollector);
49+
}
3250
}

dev/tests/unit/Magento/FunctionalTestFramework/Test/Objects/ActionGroupObjectTest.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,62 @@ public function testExceptionOnMissingArguments()
261261
$actionGroupUnderTest->getSteps(null, self::ACTION_GROUP_MERGE_KEY);
262262
}
263263

264+
/**
265+
* Tests the stepKey replacement with "stepKey + invocationKey" process filter
266+
* Specific to actions that make it past a "require stepKey replacement" filter
267+
*/
268+
public function testStepKeyReplacementFilteredIn()
269+
{
270+
$createStepKey = "createDataStepKey";
271+
$updateStepKey = "updateDataStepKey";
272+
273+
$actionGroupUnderTest = (new ActionGroupObjectBuilder())
274+
->withActionObjects([
275+
new ActionObject(
276+
$updateStepKey,
277+
ActionGroupObject::STEPKEY_REPLACEMENT_ENABLED_TYPES[6],
278+
['selector' => 'value']
279+
),
280+
new ActionObject(
281+
$createStepKey,
282+
ActionGroupObject::STEPKEY_REPLACEMENT_ENABLED_TYPES[7],
283+
['selector' => 'value']
284+
)
285+
])
286+
->build();
287+
288+
$result = $actionGroupUnderTest->extractStepKeys();
289+
290+
$this->assertContains($updateStepKey, $result);
291+
$this->assertContains($createStepKey, $result);
292+
$this->assertCount(2, $result);
293+
}
294+
295+
/**
296+
* Tests the stepKey replacement with "stepKey + invocationKey" process filter
297+
* Specific to actions that make are removed by a "require stepKey replacement" filter
298+
*/
299+
public function testStepKeyReplacementFilteredOut()
300+
{
301+
$clickStepKey = "clickStepKey";
302+
$fillFieldStepKey = "fillFieldStepKey";
303+
$clickAction = "click";
304+
$fillFieldAction ="fillField";
305+
306+
$actionGroupUnderTest = (new ActionGroupObjectBuilder())
307+
->withActionObjects([
308+
new ActionObject($clickStepKey, $clickAction, ['selector' => 'value']),
309+
new ActionObject($fillFieldStepKey, $fillFieldAction, ['selector' => 'value'])
310+
])
311+
->build();
312+
313+
$result = $actionGroupUnderTest->extractStepKeys();
314+
315+
$this->assertNotContains($clickStepKey, $result);
316+
$this->assertNotContains($fillFieldStepKey, $result);
317+
$this->assertCount(0, $result);
318+
}
319+
264320
/**
265321
* This function takes a desired return for the EntityObjectHandler mock and performs set up of the mock for the
266322
* duration of a single test case.

dev/tests/verification/Resources/ActionGroupWithStepKeyReferences.txt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,33 @@ class ActionGroupWithStepKeyReferencesCest
3535
$createSimpleDataActionGroup->createEntity();
3636
$grabTextDataActionGroup = $I->grabTextFrom(".class");
3737
$I->fillField(".{$grabTextDataActionGroup}", $createSimpleDataActionGroup->getCreatedDataByName('field'));
38+
$I->click($action0);
39+
$I->fillField($action1);
40+
$action3ActionGroup = $I->executeJS($action3ActionGroup);
41+
$action4ActionGroup = $I->magentoCLI($action4ActionGroup, "\"stuffHere\"");
42+
$I->comment($action4ActionGroup);
43+
$date = new \DateTime();
44+
$date->setTimestamp(strtotime("{$action5}"));
45+
$date->setTimezone(new \DateTimeZone("America/Los_Angeles"));
46+
$action5ActionGroup = $date->format("H:i:s");
47+
$action6ActionGroup = $I->formatMoney($action6ActionGroup);
48+
$I->amGoingTo("delete entity that has the createDataKey: {$action7}");
49+
${$action7}->deleteEntity();
50+
$I->amGoingTo("get entity that has the stepKey: action8ActionGroup");
51+
${$action8} = DataObjectHandler::getInstance()->getObject("{$action8}");
52+
$action8ActionGroup = new DataPersistenceHandler(${$action8});
53+
$action8ActionGroup->getEntity(null);
54+
$I->amGoingTo("update entity that has the createdDataKey: 1");
55+
$1->updateEntity("{$action9}");
56+
$I->amGoingTo("create entity that has the stepKey: action10ActionGroup");
57+
${$action10} = DataObjectHandler::getInstance()->getObject("{$action10}");
58+
$action10ActionGroup = new DataPersistenceHandler(${$action10}, []);
59+
$action10ActionGroup->createEntity();
60+
$action11ActionGroup = $I->grabAttributeFrom($action11ActionGroup, "someInput");
61+
$action12ActionGroup = $I->grabCookie($action12ActionGroup, ['domain' => 'www.google.com']);
62+
$action13ActionGroup = $I->grabFromCurrentUrl($action13ActionGroup);
63+
$action14ActionGroup = $I->grabMultiple($action14ActionGroup);
64+
$action15ActionGroup = $I->grabTextFrom($action15ActionGroup);
65+
$action16ActionGroup = $I->grabValueFrom($action16ActionGroup);
3866
}
3967
}

dev/tests/verification/TestModule/ActionGroup/FunctionalActionGroup.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,24 @@
4949
<createData entity="simpleData" stepKey="createSimpleData"/>
5050
<grabTextFrom selector=".class" stepKey="grabTextData"/>
5151
<fillField stepKey="fill1" selector=".{$grabTextData}" userInput="$createSimpleData.field$"/>
52+
<!--Invocation stepKey will not be appended in non stepKey instances-->
53+
<click selector="{$action0}" stepKey="action0"/>
54+
<fillField selector="{$action1}" stepKey="action1"/>
55+
<!--Invocation stepKey will be appended to every instance of $stepKey in action-->
56+
<executeJS function="{$action3}" stepKey="action3"/>
57+
<magentoCLI command="{$action4}" arguments="&quot;stuffHere&quot;" stepKey="action4"/>
58+
<generateDate date="{$action5}" format="H:i:s" stepKey="action5"/>
59+
<formatMoney userInput="{$action6}" stepKey="action6"/>
60+
<deleteData createDataKey="{$action7}" stepKey="action7"/>
61+
<getData entity="{$action8}" stepKey="action8"/>
62+
<updateData entity="{$action9}" stepKey="action9" createDataKey="1"/>
63+
<createData entity="{$action10}" stepKey="action10"/>
64+
<grabAttributeFrom selector="{$action11}" userInput="someInput" stepKey="action11"/>
65+
<grabCookie userInput="{$action12}" parameterArray="['domain' => 'www.google.com']" stepKey="action12"/>
66+
<grabFromCurrentUrl regex="{$action13}" stepKey="action13"/>
67+
<grabMultiple selector="{$action14}" stepKey="action14"/>
68+
<grabTextFrom selector="{$action15}" stepKey="action15"/>
69+
<grabValueFrom selector="{$action16}" stepKey="action16"/>
5270
</actionGroup>
5371
<actionGroup name="FunctionalActionGroupForMassMergeBefore">
5472
<fillField selector="#foo" userInput="foo" stepKey="fillField1"/>

dev/tests/verification/Tests/ExtendedGenerationTest.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace tests\verification\Tests;
77

8+
use Magento\FunctionalTestingFramework\Test\Handlers\TestObjectHandler;
9+
use Magento\FunctionalTestingFramework\Util\TestGenerator;
810
use tests\util\MftfTestCase;
911

1012
class ExtendedGenerationTest extends MftfTestCase
@@ -87,14 +89,23 @@ public function testExtendedTestGenerationRemoveHookAction()
8789
}
8890

8991
/**
90-
* Tests generation of test that attemps to extend a test that doesn't exist
92+
* Tests to ensure extended tests with no parents are not generated
9193
*
9294
* @throws \Exception
9395
* @throws \Magento\FunctionalTestingFramework\Exceptions\TestReferenceException
9496
*/
9597
public function testExtendedTestGenerationNoParent()
9698
{
97-
$this->generateAndCompareTest('ChildExtendedTestNoParent');
99+
$testObject = TestObjectHandler::getInstance()->getObject('ChildExtendedTestNoParent');
100+
$test = TestGenerator::getInstance(null, [$testObject]);
101+
$test->createAllTestFiles();
102+
103+
$cestFile = $test->getExportDir() .
104+
DIRECTORY_SEPARATOR .
105+
$testObject->getCodeceptionName() .
106+
".php";
107+
108+
$this->assertFalse(file_exists($cestFile));
98109
}
99110

100111
/**

src/Magento/FunctionalTestingFramework/Config/Dom.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
namespace Magento\FunctionalTestingFramework\Config;
88

9+
use Magento\FunctionalTestingFramework\Config\Dom\ValidationException;
10+
911
/**
1012
* Magento configuration XML DOM utility
1113
*/
@@ -354,13 +356,21 @@ public function getDom()
354356
* Create DOM document based on $xml parameter
355357
*
356358
* @param string $xml
359+
* @param string $filename
357360
* @return \DOMDocument
358361
* @throws \Magento\FunctionalTestingFramework\Config\Dom\ValidationException
359362
*/
360-
protected function initDom($xml)
363+
protected function initDom($xml, $filename = null)
361364
{
362365
$dom = new \DOMDocument();
363-
$dom->loadXML($xml);
366+
try {
367+
$domSuccess = $dom->loadXML($xml);
368+
if (!$domSuccess) {
369+
throw new \Exception();
370+
}
371+
} catch (\Exception $exception) {
372+
throw new ValidationException("XML Parse Error: $filename\n");
373+
}
364374
if ($this->schemaFile) {
365375
$errors = self::validateDomDocument($dom, $this->schemaFile, $this->errorFormat);
366376
if (count($errors)) {

src/Magento/FunctionalTestingFramework/DataGenerator/Config/Dom.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function __construct(
6565
*/
6666
public function initDom($xml, $filename = null)
6767
{
68-
$dom = parent::initDom($xml);
68+
$dom = parent::initDom($xml, $filename);
6969

7070
if (strpos($filename, self::DATA_FILE_NAME_ENDING)) {
7171
$entityNodes = $dom->getElementsByTagName('entity');

src/Magento/FunctionalTestingFramework/DataGenerator/Config/OperationDom.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function __construct(
6565
*/
6666
public function initDom($xml, $filename = null)
6767
{
68-
$dom = parent::initDom($xml);
68+
$dom = parent::initDom($xml, $filename);
6969

7070
if (strpos($filename, self::METADATA_FILE_NAME_ENDING)) {
7171
$operationNodes = $dom->getElementsByTagName('operation');

src/Magento/FunctionalTestingFramework/Page/Config/Dom.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public function __construct(
7676
*/
7777
public function initDom($xml, $filename = null)
7878
{
79-
$dom = parent::initDom($xml);
79+
$dom = parent::initDom($xml, $filename);
8080

8181
$pagesNode = $dom->getElementsByTagName('pages')->item(0);
8282
$this->validationUtil->validateChildUniqueness($pagesNode, $filename);

src/Magento/FunctionalTestingFramework/Page/Config/SectionDom.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function __construct(
6767
*/
6868
public function initDom($xml, $filename = null)
6969
{
70-
$dom = parent::initDom($xml);
70+
$dom = parent::initDom($xml, $filename);
7171
$sectionNodes = $dom->getElementsByTagName('section');
7272
foreach ($sectionNodes as $sectionNode) {
7373
$sectionNode->setAttribute(self::SECTION_META_FILENAME_ATTRIBUTE, $filename);

src/Magento/FunctionalTestingFramework/Test/Config/ActionGroupDom.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class ActionGroupDom extends Dom
2626
*/
2727
public function initDom($xml, $filename = null)
2828
{
29-
$dom = parent::initDom($xml);
29+
$dom = parent::initDom($xml, $filename);
3030

3131
if (strpos($filename, self::ACTION_GROUP_FILE_NAME_ENDING)) {
3232
$actionGroupNodes = $dom->getElementsByTagName('actionGroup');

src/Magento/FunctionalTestingFramework/Test/Config/Dom.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function __construct(
7979
*/
8080
public function initDom($xml, $filename = null)
8181
{
82-
$dom = parent::initDom($xml);
82+
$dom = parent::initDom($xml, $filename);
8383

8484
if (strpos($filename, self::TEST_FILE_NAME_ENDING)) {
8585
$testNodes = $dom->getElementsByTagName('test');

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

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,23 @@ class ActionGroupObject
1919
{
2020
const ACTION_GROUP_ORIGIN_NAME = "actionGroupName";
2121
const ACTION_GROUP_ORIGIN_TEST_REF = "testInvocationRef";
22+
const STEPKEY_REPLACEMENT_ENABLED_TYPES = [
23+
"executeJS",
24+
"magentoCLI",
25+
"generateDate",
26+
"formatMoney",
27+
"deleteData",
28+
"getData",
29+
"updateData",
30+
"createData",
31+
"grabAttributeFrom",
32+
"grabCookie",
33+
"grabFromCurrentUrl",
34+
"grabMultiple",
35+
"grabPageSource",
36+
"grabTextFrom",
37+
"grabValueFrom"
38+
];
2239

2340
/**
2441
* Array of variable-enabled attributes.
@@ -372,7 +389,12 @@ public function extractStepKeys()
372389
{
373390
$originalKeys = [];
374391
foreach ($this->parsedActions as $action) {
375-
$originalKeys[] = $action->getStepKey();
392+
//limit actions returned to list that are relevant
393+
foreach (self::STEPKEY_REPLACEMENT_ENABLED_TYPES as $actionValue) {
394+
if ($actionValue === $action->getType()) {
395+
$originalKeys[] = $action->getStepKey();
396+
}
397+
}
376398
}
377399
return $originalKeys;
378400
}

src/Magento/FunctionalTestingFramework/Test/Util/ObjectExtensionUtil.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,10 @@ public function skipTest($testObject)
210210
$annotations = $testObject->getAnnotations();
211211

212212
// Add skip to the group array if it doesn't already exist
213-
if (array_key_exists('group', $annotations) && !in_array('skip', $annotations['group'])) {
214-
array_push($annotations['group'], 'skip');
215-
} elseif (!array_key_exists('group', $annotations)) {
216-
$annotations['group'] = ['skip'];
213+
if (array_key_exists('skip', $annotations)) {
214+
return $testObject;
215+
} elseif (!array_key_exists('skip', $annotations)) {
216+
$annotations['skip'] = ['issueId' => "ParentTestDoesNotExist"];
217217
}
218218

219219
$skippedTest = new TestObject(

src/Magento/FunctionalTestingFramework/Util/TestGenerator.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,16 @@ private function assembleAllTestPhp($testManifest, array $testsToIgnore)
244244
$cestPhpArray = [];
245245

246246
foreach ($testObjects as $test) {
247+
// Do not generate test if it is an extended test and parent does not exist
248+
if ($test->isSkipped() && !empty($test->getParentName())) {
249+
try {
250+
TestObjectHandler::getInstance()->getObject($test->getParentName());
251+
} catch (TestReferenceException $e) {
252+
print("{$test->getName()} will not be generated. Parent {$e->getMessage()} \n");
253+
continue;
254+
}
255+
}
256+
247257
$this->debug("<comment>Start creating test: " . $test->getCodeceptionName() . "</comment>");
248258
$php = $this->assembleTestPhp($test);
249259
$cestPhpArray[] = [$test->getCodeceptionName(), $php];

0 commit comments

Comments
 (0)