Skip to content

Commit 5217322

Browse files
authored
Merge branch 'develop' into MQE-914
2 parents 21ea982 + 586fd5c commit 5217322

39 files changed

+1110
-295
lines changed

bin/static-checks

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ set -e
88
echo "==============================="
99
echo " CODE SNIFFER"
1010
echo "==============================="
11-
vendor/bin/phpcs ./src --standard=./dev/tests/static/Magento
11+
vendor/bin/phpcs ./src --standard=./dev/tests/static/Magento --ignore=src/Magento/FunctionalTestingFramework/Group,src/Magento/FunctionalTestingFramework/AcceptanceTester.php
1212
vendor/bin/phpcs ./dev/tests/unit --standard=./dev/tests/static/Magento
1313
vendor/bin/phpcs ./dev/tests/verification --standard=./dev/tests/static/Magento --ignore=dev/tests/verification/_generated
1414
echo ""
@@ -22,7 +22,7 @@ echo ""
2222
echo "==============================="
2323
echo " MESS DETECTOR"
2424
echo "==============================="
25-
vendor/bin/phpmd ./src text /dev/tests/static/Magento/CodeMessDetector/ruleset.xml --exclude _generated
25+
vendor/bin/phpmd ./src text /dev/tests/static/Magento/CodeMessDetector/ruleset.xml --exclude _generated,src/Magento/FunctionalTestingFramework/Group,src/Magento/FunctionalTestingFramework/AcceptanceTester.php
2626
echo ""
2727

2828
echo "==============================="

bin/static-checks.bat

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55

66
@echo off
77
@echo ===============================PHP CODE SNIFFER REPORT===============================
8-
call vendor\bin\phpcs .\src --standard=.\dev\tests\static\Magento
8+
call vendor\bin\phpcs .\src --standard=.\dev\tests\static\Magento --ignore=src\Magento\FunctionalTestingFramework\Group,src\Magento\FunctionalTestingFramework\AcceptanceTester.php
99
call vendor\bin\phpcs .\dev\tests\unit --standard=.\dev\tests\static\Magento
1010
call vendor\bin\phpcs .\dev\tests\verification --standard=.\dev\tests\static\Magento --ignore=dev\tests\verification\_generated
1111

1212
@echo ===============================COPY PASTE DETECTOR REPORT===============================
1313
call vendor\bin\phpcpd .\src
1414

1515
@echo "===============================PHP MESS DETECTOR REPORT===============================
16-
vendor\bin\phpmd .\src text \dev\tests\static\Magento\CodeMessDetector\ruleset.xml --exclude _generated
16+
vendor\bin\phpmd .\src text \dev\tests\static\Magento\CodeMessDetector\ruleset.xml --exclude _generated,src\Magento\FunctionalTestingFramework\Group,src\Magento\FunctionalTestingFramework\AcceptanceTester.php
1717

1818
@echo ===============================MAGENTO COPYRIGHT REPORT===============================
1919
echo msgbox "INFO:Copyright check currently not run as part of .bat implementation" > "%temp%\popup.vbs"

dev/tests/_bootstrap.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,12 @@
1616
'includePaths' => [PROJECT_ROOT . '/src']
1717
]);
1818

19-
// force php to generate
20-
$GLOBALS['FORCE_PHP_GENERATE'] = true;
19+
// set mftf appplication context
20+
\Magento\FunctionalTestingFramework\Config\MftfApplicationConfig::create(
21+
true,
22+
\Magento\FunctionalTestingFramework\Config\MftfApplicationConfig::GENERATION_PHASE,
23+
true
24+
);
2125

2226
// Load needed framework env params
2327
$TEST_ENVS = [
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Tests\unit\Magento\FunctionalTestFramework\Test\Config;
7+
8+
use Magento\FunctionalTestingFramework\Exceptions\Collector\ExceptionCollector;
9+
use Magento\FunctionalTestingFramework\Test\Config\ActionGroupDom;
10+
use PHPUnit\Framework\TestCase;
11+
12+
class ActionGroupDomTest extends TestCase
13+
{
14+
/**
15+
* Test Action Group duplicate step key validation
16+
*/
17+
public function testActionGroupDomStepKeyValidation()
18+
{
19+
$sampleXml = "<actionGroups>
20+
<actionGroup name=\"actionGroupWithoutArguments\">
21+
<wait time=\"1\" stepKey=\"waitForNothing\" />
22+
<wait time=\"2\" stepKey=\"waitForNothing\" />
23+
</actionGroup>
24+
</actionGroups>";
25+
26+
$exceptionCollector = new ExceptionCollector();
27+
$actionDom = new ActionGroupDom($sampleXml, 'dupeStepKeyActionGroup.xml', $exceptionCollector);
28+
29+
$this->expectException(\Exception::class);
30+
$exceptionCollector->throwException();
31+
}
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace tests\unit\Magento\FunctionalTestFramework\Test\Util;
7+
8+
use Magento\FunctionalTestingFramework\Test\Objects\ActionObject;
9+
use Magento\FunctionalTestingFramework\Test\Util\ActionObjectExtractor;
10+
use PHPUnit\Framework\TestCase;
11+
12+
class ActionObjectExtractorTest extends TestCase
13+
{
14+
/** @var ActionObjectExtractor */
15+
private $testActionObjectExtractor;
16+
17+
/**
18+
* Setup method
19+
*/
20+
public function setUp()
21+
{
22+
$this->testActionObjectExtractor = new ActionObjectExtractor();
23+
}
24+
25+
/**
26+
* Tests basic action object extraction with a valid parser array.
27+
*/
28+
public function testBasicActionObjectExtration()
29+
{
30+
$actionObjects = $this->testActionObjectExtractor->extractActions($this->createBasicActionObjectArray());
31+
$this->assertCount(1, $actionObjects);
32+
33+
/** @var ActionObject $firstElement */
34+
$firstElement = array_values($actionObjects)[0];
35+
$this->assertEquals('testAction1', $firstElement->getStepKey());
36+
$this->assertCount(1, $firstElement->getCustomActionAttributes());
37+
}
38+
39+
/**
40+
* Tests an invalid merge order reference (i.e. a step referencing itself).
41+
*/
42+
public function testInvalidMergeOrderReference()
43+
{
44+
$invalidArray = $this->createBasicActionObjectArray('invalidTestAction1', 'invalidTestAction1');
45+
46+
$this->expectException('\Magento\FunctionalTestingFramework\Exceptions\TestReferenceException');
47+
$expectedExceptionMessage = "Invalid ordering configuration in test TestWithSelfReferencingStepKey with step" .
48+
" key(s):\n\tinvalidTestAction1\n";
49+
$this->expectExceptionMessage($expectedExceptionMessage);
50+
51+
$this->testActionObjectExtractor->extractActions($invalidArray, 'TestWithSelfReferencingStepKey');
52+
}
53+
54+
/**
55+
* Validates a warning is printed to the console when multiple actions reference the same actions for merging.
56+
*/
57+
public function testAmbiguousMergeOrderRefernece()
58+
{
59+
$ambiguousArray = $this->createBasicActionObjectArray('testAction1');
60+
$ambiguousArray = array_merge(
61+
$ambiguousArray,
62+
$this->createBasicActionObjectArray('testAction2', 'testAction1')
63+
);
64+
65+
$ambiguousArray = array_merge(
66+
$ambiguousArray,
67+
$this->createBasicActionObjectArray('testAction3', null, 'testAction1')
68+
);
69+
70+
$outputString = "multiple actions referencing step key testAction1 in test AmbiguousRefTest:\n" .
71+
"\ttestAction2\n" .
72+
"\ttestAction3\n";
73+
74+
$this->expectOutputString($outputString);
75+
$this->testActionObjectExtractor->extractActions($ambiguousArray, 'AmbiguousRefTest');
76+
}
77+
78+
/**
79+
* Utility function to return mock parser output for testing extraction into ActionObjects.
80+
*
81+
* @param string $stepKey
82+
* @param string $before
83+
* @param string $after
84+
* @return array
85+
*/
86+
private function createBasicActionObjectArray($stepKey = 'testAction1', $before = null, $after = null)
87+
{
88+
$baseArray = [
89+
$stepKey => [
90+
"nodeName" => "sampleAction",
91+
"stepKey" => $stepKey,
92+
"someAttribute" => "someAttributeValue"
93+
]
94+
];
95+
96+
if ($before) {
97+
$baseArray[$stepKey] = array_merge($baseArray[$stepKey], ['before' => $before]);
98+
}
99+
100+
if ($after) {
101+
$baseArray[$stepKey] = array_merge($baseArray[$stepKey], ['after' => $after]);
102+
}
103+
104+
return $baseArray;
105+
}
106+
}

dev/tests/unit/Magento/FunctionalTestFramework/Util/Sorter/ParallelGroupSorterTest.php

+1-11
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,6 @@ public function testSortWithSuites()
7676

7777
AspectMock::double(TestObjectHandler::class, ['getInstance' => $mockHandler])->make();
7878

79-
// mock a suite object
80-
$mockSuite = AspectMock::double(SuiteObject::class, [
81-
'getBeforeHook' => null,
82-
'getAfterHook' => null,
83-
'getName' => 'mockSuite1'
84-
])->make();
85-
$mockSuiteHandler = AspectMock::double(SuiteObjectHandler::class, ['getObject' => $mockSuite])->make();
86-
AspectMock::double(SuiteObjectHandler::class, ['getInstance' => $mockSuiteHandler]);
87-
8879
// create test to size array
8980
$sampleTestArray = [
9081
'test1' => 100,
@@ -96,8 +87,7 @@ public function testSortWithSuites()
9687

9788
// create mock suite references
9889
$sampleSuiteArray = [
99-
'mockTest1' => ['mockSuite1'],
100-
'mockTest2' => ['mockSuite1']
90+
'mockSuite1' => ['mockTest1', 'mockTest2']
10191
];
10292

10393
// perform sort
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
namespace Magento\AcceptanceTest\_default\Backend;
3+
4+
use Magento\FunctionalTestingFramework\AcceptanceTester;
5+
use Magento\FunctionalTestingFramework\DataGenerator\Handlers\DataObjectHandler;
6+
use Magento\FunctionalTestingFramework\DataGenerator\Persist\DataPersistenceHandler;
7+
use Magento\FunctionalTestingFramework\DataGenerator\Objects\EntityDataObject;
8+
use \Codeception\Util\Locator;
9+
use Yandex\Allure\Adapter\Annotation\Features;
10+
use Yandex\Allure\Adapter\Annotation\Stories;
11+
use Yandex\Allure\Adapter\Annotation\Title;
12+
use Yandex\Allure\Adapter\Annotation\Description;
13+
use Yandex\Allure\Adapter\Annotation\Parameter;
14+
use Yandex\Allure\Adapter\Annotation\Severity;
15+
use Yandex\Allure\Adapter\Model\SeverityLevel;
16+
use Yandex\Allure\Adapter\Annotation\TestCaseId;
17+
18+
/**
19+
*/
20+
class ActionGroupUsingNestedArgumentCest
21+
{
22+
/**
23+
* @Parameter(name = "AcceptanceTester", value="$I")
24+
* @param AcceptanceTester $I
25+
* @return void
26+
* @throws \Exception
27+
*/
28+
public function ActionGroupUsingNestedArgument(AcceptanceTester $I)
29+
{
30+
$grabProductsActionGroup = $I->grabMultiple("selector");
31+
$I->assertCount(99, $grabProductsActionGroup);
32+
}
33+
}

dev/tests/verification/Resources/PersistedReplacementTest.txt

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class PersistedReplacementTestCest
5050
$createdData->createEntity();
5151
$I->fillField("#selector", "StringBefore " . $createdData->getCreatedDataByName('firstname') . " StringAfter");
5252
$I->fillField("#" . $createdData->getCreatedDataByName('firstname'), "input");
53+
$I->fillField("#" . getenv("MAGENTO_BASE_URL") . "#" . $createdData->getCreatedDataByName('firstname'), "input");
5354
$I->dragAndDrop("#" . $createdData->getCreatedDataByName('firstname'), $createdData->getCreatedDataByName('lastname'));
5455
$I->conditionalClick($createdData->getCreatedDataByName('lastname'), "#" . $createdData->getCreatedDataByName('firstname'), true);
5556
$I->amOnUrl($createdData->getCreatedDataByName('firstname') . ".html");

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

+11
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,15 @@
4848
</arguments>
4949
<see selector="{{SampleSection.oneParamElement(someArgument)}}" userInput="{{someArgument}}" stepKey="see1" />
5050
</actionGroup>
51+
52+
<actionGroup name="actionGroupWithNestedArgument">
53+
<arguments>
54+
<argument name="count" defaultValue="10" type="string"/>
55+
</arguments>
56+
<grabMultiple selector="selector" stepKey="grabProducts"/>
57+
<assertCount stepKey="assertCount">
58+
<expectedResult type="int">{{count}}</expectedResult>
59+
<actualResult type="variable">grabProducts</actualResult>
60+
</assertCount>
61+
</actionGroup>
5162
</actionGroups>

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
<amOnSubdomain stepKey="aosd2" url="1"/>
1717
<amOnUrl stepKey="aou1" url="1"/>
1818
<amOnUrl stepKey="aou2" url="1"/>
19-
<appendField selector="1" stepKey="ap1"/>
20-
<appendField selector="1" stepKey="ap2"/>
19+
<appendField selector="1" stepKey="apf1"/>
20+
<appendField selector="1" stepKey="apf2"/>
2121
<attachFile selector="1" stepKey="atf1"/>
2222
<attachFile selector="1" stepKey="atf2"/>
2323
<cancelPopup stepKey="cp1"/>
@@ -164,8 +164,8 @@
164164
<seeInField stepKey="seeinfield12"/>
165165
<seeInFormFields selector="2" parameterArray="[1]" stepKey="seeinformfields1"/>
166166
<seeInFormFields selector="2" parameterArray="[1]" stepKey="seeinformfields12"/>
167-
<seeInPageSource html="1" stepKey="seeinsource1"/>
168-
<seeInPageSource html="1" stepKey="seeinsource12"/>
167+
<seeInPageSource html="1" stepKey="seeinpgsource1"/>
168+
<seeInPageSource html="1" stepKey="seeinpgsource12"/>
169169
<seeInPopup stepKey="seeinpopup1"/>
170170
<seeInPopup stepKey="seeinpopup12"/>
171171
<seeInSource html="1" stepKey="seeinsource1"/>

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

+6
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,10 @@
114114
<test name="ActionGroupWithStepKeyReferences">
115115
<actionGroup ref="FunctionActionGroupWithStepKeyReferences" stepKey="actionGroup"/>
116116
</test>
117+
118+
<test name="ActionGroupUsingNestedArgument">
119+
<actionGroup ref="actionGroupWithNestedArgument" stepKey="actionGroup">
120+
<argument name="count" value="99"/>
121+
</actionGroup>
122+
</test>
117123
</tests>

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

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
<fillField stepKey="inputReplace" selector="#selector" userInput="StringBefore $createdData.firstname$ StringAfter"/>
1818
<fillField stepKey="selectorReplace" selector="#$createdData.firstname$" userInput="input"/>
19+
<fillField stepKey="selectorReplace2" selector="#{{_ENV.MAGENTO_BASE_URL}}#$createdData.firstname$" userInput="input"/>
1920
<dragAndDrop stepKey="selector12Replace" selector1="#$createdData.firstname$" selector2="$createdData.lastname$"/>
2021
<conditionalClick stepKey="dependentSelectorReplace" dependentSelector="#$createdData.firstname$" selector="$createdData.lastname$" visible="true"/>
2122
<amOnUrl stepKey="urlReplace" url="$createdData.firstname$.html"/>

dev/tests/verification/Tests/ActionGroupGenerationTest.php

+11
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,15 @@ public function testActionGroupWithStepKeyReferences()
107107
{
108108
$this->generateAndCompareTest('ActionGroupWithStepKeyReferences');
109109
}
110+
111+
/**
112+
* Test generation of a test referencing an action group that uses stepKey references (grabFrom/CreateData)
113+
*
114+
* @throws \Exception
115+
* @throws \Magento\FunctionalTestingFramework\Exceptions\TestReferenceException
116+
*/
117+
public function testActionGroupWithNestedArgument()
118+
{
119+
$this->generateAndCompareTest('ActionGroupUsingNestedArgument');
120+
}
110121
}

etc/di.xml

+3-2
Original file line numberDiff line numberDiff line change
@@ -286,11 +286,12 @@
286286
</arguments>
287287
</virtualType>
288288

289-
<virtualType name="Magento\FunctionalTestingFramework\Config\Reader\ActionGroupData" type="Magento\FunctionalTestingFramework\Config\Reader\Filesystem">
289+
<virtualType name="Magento\FunctionalTestingFramework\Config\Reader\ActionGroupData" type="Magento\FunctionalTestingFramework\Test\Config\Reader\Filesystem">
290290
<arguments>
291291
<argument name="fileResolver" xsi:type="object">Magento\FunctionalTestingFramework\Config\FileResolver\Module</argument>
292292
<argument name="converter" xsi:type="object">Magento\FunctionalTestingFramework\Config\ActionGroupDataConverter</argument>
293293
<argument name="schemaLocator" xsi:type="object">Magento\FunctionalTestingFramework\Config\SchemaLocator\ActionGroup</argument>
294+
<argument name="domDocumentClass" xsi:type="string">Magento\FunctionalTestingFramework\Test\Config\ActionGroupDom</argument>
294295
<argument name="idAttributes" xsi:type="array">
295296
<item name="/actionGroups/actionGroup" xsi:type="string">name</item>
296297
<item name="/actionGroups/actionGroup/arguments/argument" xsi:type="string">name</item>
@@ -366,7 +367,7 @@
366367
<item name="/suites/suite/exclude/(group|test|module)" xsi:type="string">name</item>
367368
</argument>
368369
<argument name="fileName" xsi:type="string">*.xml</argument>
369-
<argument name="defaultScope" xsi:type="string">_suite</argument>
370+
<argument name="defaultScope" xsi:type="string">Suite</argument>
370371
</arguments>
371372
</virtualType>
372373

src/Magento/FunctionalTestingFramework/Config/FileResolver/Module.php

+16-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Module implements FileResolverInterface
2020
*
2121
* @var ModuleResolver
2222
*/
23-
private $moduleResolver;
23+
protected $moduleResolver;
2424

2525
/**
2626
* Module constructor.
@@ -40,6 +40,20 @@ public function __construct(ModuleResolver $moduleResolver = null)
4040
* @return array|\Iterator,\Countable
4141
*/
4242
public function get($filename, $scope)
43+
{
44+
$iterator = new File($this->getPaths($filename, $scope));
45+
return $iterator;
46+
}
47+
48+
/**
49+
* Function which takes a string representing filename and a scope represnting directory scope to glob for matched
50+
* patterns against. Returns the file matching the patterns given by the module resolver.
51+
*
52+
* @param string $filename
53+
* @param string $scope
54+
* @return array
55+
*/
56+
protected function getPaths($filename, $scope)
4357
{
4458
$modulesPath = $this->moduleResolver->getModulesPath();
4559
$paths = [];
@@ -48,7 +62,6 @@ public function get($filename, $scope)
4862
$paths = array_merge($paths, glob($path));
4963
}
5064

51-
$iterator = new File($paths);
52-
return $iterator;
65+
return $paths;
5366
}
5467
}

0 commit comments

Comments
 (0)