Skip to content

Commit 80dc18c

Browse files
authored
Merge branch 'develop' into MQE-1918
2 parents bb62cfe + e344c6f commit 80dc18c

File tree

15 files changed

+479
-98
lines changed

15 files changed

+479
-98
lines changed

dev/tests/unit/Magento/FunctionalTestFramework/Console/BaseGenerateCommandTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,24 @@ public function testThreeTestOneSuiteOneGroupMix()
156156
$this->assertEquals($expected, $actual);
157157
}
158158

159+
public function testSuiteToTestSyntax()
160+
{
161+
$testOne = new TestObject('Test1', [], [], []);
162+
$suiteOne = new SuiteObject(
163+
'Suite1',
164+
['Test1' => $testOne],
165+
[],
166+
[]
167+
);
168+
169+
$testArray = ['Test1' => $testOne];
170+
$suiteArray = ['Suite1' => $suiteOne];
171+
$this->mockHandlers($testArray, $suiteArray);
172+
$actual = json_decode($this->callTestConfig(['Suite1:Test1']), true);
173+
$expected = ['tests' => null, 'suites' => ['Suite1' => ['Test1']]];
174+
$this->assertEquals($expected, $actual);
175+
}
176+
159177
/**
160178
* Mock handlers to skip parsing
161179
* @param array $testArray

dev/tests/unit/Magento/FunctionalTestFramework/DataGenerator/Handlers/PersistedObjectHandlerTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,30 @@ public function setUp()
3232
TestLoggingUtil::getInstance()->setMockLoggingUtil();
3333
}
3434

35+
public function testCreateEntityWithNonExistingName()
36+
{
37+
// Test Data and Variables
38+
$entityName = "InvalidEntity";
39+
$entityStepKey = "StepKey";
40+
$scope = PersistedObjectHandler::TEST_SCOPE;
41+
42+
$exceptionMessage = "Entity \"" . $entityName . "\" does not exist." .
43+
"\nException occurred executing action at StepKey \"" . $entityStepKey . "\"";
44+
45+
$this->expectException(TestReferenceException::class);
46+
47+
$this->expectExceptionMessage($exceptionMessage);
48+
49+
$handler = PersistedObjectHandler::getInstance();
50+
51+
// Call method
52+
$handler->createEntity(
53+
$entityStepKey,
54+
$scope,
55+
$entityName
56+
);
57+
}
58+
3559
public function testCreateSimpleEntity()
3660
{
3761
// Test Data and Variables

dev/tests/unit/Magento/FunctionalTestFramework/Suite/SuiteGeneratorTest.php

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

88
use AspectMock\Test as AspectMock;
9+
use Magento\FunctionalTestingFramework\Exceptions\TestReferenceException;
910
use Magento\FunctionalTestingFramework\ObjectManager\ObjectManager;
1011
use Magento\FunctionalTestingFramework\ObjectManagerFactory;
1112
use Magento\FunctionalTestingFramework\Suite\SuiteGenerator;
@@ -17,6 +18,7 @@
1718
use Magento\FunctionalTestingFramework\Test\Parsers\TestDataParser;
1819
use Magento\FunctionalTestingFramework\Util\Manifest\DefaultTestManifest;
1920
use Magento\FunctionalTestingFramework\Util\MagentoTestCase;
21+
use Magento\FunctionalTestingFramework\Util\Manifest\TestManifestFactory;
2022
use tests\unit\Util\SuiteDataArrayBuilder;
2123
use tests\unit\Util\TestDataArrayBuilder;
2224
use tests\unit\Util\TestLoggingUtil;
@@ -143,6 +145,73 @@ public function testGenerateEmptySuite()
143145
$mockSuiteGenerator->generateSuite("basicTestSuite");
144146
}
145147

148+
public function testInvalidSuiteTestPair()
149+
{
150+
// Mock Suite1 => Test1 and Suite2 => Test2
151+
$suiteDataArrayBuilder = new SuiteDataArrayBuilder();
152+
$mockData = $suiteDataArrayBuilder
153+
->withName('Suite1')
154+
->includeGroups(['group1'])
155+
->build();
156+
$suiteDataArrayBuilder = new SuiteDataArrayBuilder();
157+
$mockData2 = $suiteDataArrayBuilder
158+
->withName('Suite2')
159+
->includeGroups(['group2'])
160+
->build();
161+
$mockSuiteData = array_merge_recursive($mockData, $mockData2);
162+
163+
$testDataArrayBuilder = new TestDataArrayBuilder();
164+
$mockSimpleTest = $testDataArrayBuilder
165+
->withName('Test1')
166+
->withAnnotations(['group' => [['value' => 'group1']]])
167+
->withTestActions()
168+
->build();
169+
$testDataArrayBuilder = new TestDataArrayBuilder();
170+
$mockSimpleTest2 = $testDataArrayBuilder
171+
->withName('Test2')
172+
->withAnnotations(['group' => [['value' => 'group2']]])
173+
->withTestActions()
174+
->build();
175+
$mockTestData = ['tests' => array_merge($mockSimpleTest, $mockSimpleTest2)];
176+
$this->setMockTestAndSuiteParserOutput($mockTestData, $mockSuiteData);
177+
178+
// Make invalid manifest
179+
$suiteConfig = ['Suite2' => ['Test1']];
180+
$manifest = TestManifestFactory::makeManifest('default', $suiteConfig);
181+
182+
// Set up Expected Exception
183+
$this->expectException(TestReferenceException::class);
184+
$this->expectExceptionMessageRegExp('(Suite: "Suite2" Tests: "Test1")');
185+
186+
// parse and generate suite object with mocked data and manifest
187+
$mockSuiteGenerator = SuiteGenerator::getInstance();
188+
$mockSuiteGenerator->generateAllSuites($manifest);
189+
}
190+
191+
public function testNonExistentSuiteTestPair()
192+
{
193+
$testDataArrayBuilder = new TestDataArrayBuilder();
194+
$mockSimpleTest = $testDataArrayBuilder
195+
->withName('Test1')
196+
->withAnnotations(['group' => [['value' => 'group1']]])
197+
->withTestActions()
198+
->build();
199+
$mockTestData = ['tests' => array_merge($mockSimpleTest)];
200+
$this->setMockTestAndSuiteParserOutput($mockTestData, []);
201+
202+
// Make invalid manifest
203+
$suiteConfig = ['Suite3' => ['Test1']];
204+
$manifest = TestManifestFactory::makeManifest('default', $suiteConfig);
205+
206+
// Set up Expected Exception
207+
$this->expectException(TestReferenceException::class);
208+
$this->expectExceptionMessageRegExp('#Suite3 is not defined#');
209+
210+
// parse and generate suite object with mocked data and manifest
211+
$mockSuiteGenerator = SuiteGenerator::getInstance();
212+
$mockSuiteGenerator->generateAllSuites($manifest);
213+
}
214+
146215
/**
147216
* Function used to set mock for parser return and force init method to run between tests.
148217
*

dev/tests/verification/Resources/BasicFunctionalTest.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,12 @@ class BasicFunctionalTestCest
126126
$I->comment($magentoCli3); // stepKey: magentoCli3
127127
$magentoCli4 = $I->magentoCLISecret("config:set somePath " . $I->getSecret("someKey"), 120); // stepKey: magentoCli4
128128
$I->comment($magentoCli4); // stepKey: magentoCli4
129+
$cronAllGroups = $I->magentoCron("", 70); // stepKey: cronAllGroups
130+
$I->comment($cronAllGroups);
131+
$cronSingleGroup = $I->magentoCron("index", 70); // stepKey: cronSingleGroup
132+
$I->comment($cronSingleGroup);
133+
$cronMultipleGroups = $I->magentoCron("a b c", 70); // stepKey: cronMultipleGroups
134+
$I->comment($cronMultipleGroups);
129135
$I->makeScreenshot("screenShotInput"); // stepKey: makeScreenshotKey1
130136
$I->maximizeWindow(); // stepKey: maximizeWindowKey1
131137
$I->moveBack(); // stepKey: moveBackKey1

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@
7979
<magentoCLI command="maintenance:enable" arguments="&quot;stuffHere&quot;" timeout="120" stepKey="magentoCli2"/>
8080
<magentoCLI command="config:set somePath {{_CREDS.someKey}}" stepKey="magentoCli3"/>
8181
<magentoCLI command="config:set somePath {{_CREDS.someKey}}" timeout="120" stepKey="magentoCli4"/>
82+
<magentoCron stepKey="cronAllGroups"/>
83+
<magentoCron groups="index" stepKey="cronSingleGroup"/>
84+
<magentoCron groups="a b c" stepKey="cronMultipleGroups"/>
8285
<makeScreenshot userInput="screenShotInput" stepKey="makeScreenshotKey1"/>
8386
<maximizeWindow stepKey="maximizeWindowKey1"/>
8487
<moveBack stepKey="moveBackKey1"/>
@@ -143,4 +146,4 @@
143146
<fillField selector="#bar" userInput="bar" stepKey="fillField2"/>
144147
<fillField selector="#baz" userInput="baz" stepKey="fillField3"/>
145148
</test>
146-
</tests>
149+
</tests>

docs/commands/mftf.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ vendor/bin/mftf generate:tests
4242
vendor/bin/mftf generate:tests AdminLoginTest StorefrontPersistedCustomerLoginTest
4343
```
4444

45+
### Generate test by test and suite name
46+
47+
```bash
48+
vendor/bin/mftf generate:tests LoginSuite:AdminLoginTest
49+
```
50+
4551
### Generate and run the tests for a specified group
4652

4753
```bash
@@ -58,6 +64,14 @@ vendor/bin/mftf run:test AdminLoginTest StorefrontPersistedCustomerLoginTest -r
5864

5965
This command cleans up the previously generated tests; generates and runs the `LoginAsAdminTest` and `LoginAsCustomerTest` tests.
6066

67+
### Generate and run particular test in a specific suite's context
68+
69+
```bash
70+
vendor/bin/mftf run:test LoginSuite:AdminLoginTest -r
71+
```
72+
73+
This command cleans up previously generated tests; generates and run `AdminLoginTest` within the context of the `LoginSuite`.
74+
6175
### Generate and run a testManifest.txt file
6276

6377
```bash

docs/test/actions.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1274,6 +1274,29 @@ Attribute|Type|Use|Description
12741274
<magentoCLI command="indexer:reindex" stepKey="reindex"/>
12751275
```
12761276

1277+
### magentoCron
1278+
1279+
Used to execute Magento Cron jobs. Groups may be provided optionally. Internal mechanism of `<magentoCron>` ensures that Cron Job of single group is ran with 60 seconds interval.
1280+
1281+
Attribute|Type|Use|Description
1282+
---|---|---|---
1283+
`groups`|string |optional| Run only specified groups of Cron Jobs
1284+
`arguments`|string |optional| Unescaped arguments to be passed in with the CLI command.
1285+
`timeout`|string|optional| Number of seconds CLI command can run without outputting anything.
1286+
`stepKey`|string|required| A unique identifier of the action.
1287+
`before`|string|optional| `stepKey` of action that must be executed next.
1288+
`after`|string|optional| `stepKey` of preceding action.
1289+
1290+
1291+
#### Example
1292+
```xml
1293+
<magentoCron stepKey="runStagingCronJobs" groups="staging"/>
1294+
<!-- No interval here -->
1295+
<magentoCron stepKey="runIndexCronJobs" groups="index"/>
1296+
<!-- 60 seconds interval takes place here -->
1297+
<magentoCron stepKey="runAllCronJobs"/>
1298+
```
1299+
12771300
### makeScreenshot
12781301

12791302
See [makeScreenshot docs on codeception.com](http://codeception.com/docs/modules/WebDriver#makeScreenshot).

etc/di.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
<!-- Entity value gets replaced in Dom.php before reading $xml -->
1010
<!DOCTYPE config [
11-
<!ENTITY commonTestActions "acceptPopup|actionGroup|amOnPage|amOnUrl|amOnSubdomain|appendField|assertArrayIsSorted|assertArraySubset|assertElementContainsAttribute|attachFile|cancelPopup|checkOption|clearField|click|clickWithLeftButton|clickWithRightButton|closeAdminNotification|closeTab|comment|conditionalClick|createData|deleteData|updateData|getData|dontSee|dontSeeJsError|dontSeeCheckboxIsChecked|dontSeeCookie|dontSeeCurrentUrlEquals|dontSeeCurrentUrlMatches|dontSeeElement|dontSeeElementInDOM|dontSeeInCurrentUrl|dontSeeInField|dontSeeInFormFields|dontSeeInPageSource|dontSeeInSource|dontSeeInTitle|dontSeeLink|dontSeeOptionIsSelected|doubleClick|dragAndDrop|entity|executeJS|executeInSelenium|fillField|formatMoney|generateDate|grabAttributeFrom|grabCookie|grabFromCurrentUrl|grabMultiple|grabPageSource|grabTextFrom|grabValueFrom|loadSessionSnapshot|loginAsAdmin|magentoCLI|makeScreenshot|maximizeWindow|moveBack|moveForward|moveMouseOver|mSetLocale|mResetLocale|openNewTab|pauseExecution|parseFloat|performOn|pressKey|reloadPage|resetCookie|submitForm|resizeWindow|saveSessionSnapshot|scrollTo|scrollToTopOfPage|searchAndMultiSelectOption|see|seeCheckboxIsChecked|seeCookie|seeCurrentUrlEquals|seeCurrentUrlMatches|seeElement|seeElementInDOM|seeInCurrentUrl|seeInField|seeInFormFields|seeInPageSource|seeInPopup|seeInSource|seeInTitle|seeLink|seeNumberOfElements|seeOptionIsSelected|selectOption|setCookie|submitForm|switchToIFrame|switchToNextTab|switchToPreviousTab|switchToWindow|typeInPopup|uncheckOption|unselectOption|wait|waitForAjaxLoad|waitForElement|waitForElementChange|waitForElementNotVisible|waitForElementVisible|waitForPwaElementNotVisible|waitForPwaElementVisible|waitForJS|waitForLoadingMaskToDisappear|waitForPageLoad|waitForText|assertArrayHasKey|assertArrayNotHasKey|assertArraySubset|assertContains|assertCount|assertEmpty|assertEquals|assertFalse|assertFileExists|assertFileNotExists|assertGreaterOrEquals|assertGreaterThan|assertGreaterThanOrEqual|assertInstanceOf|assertInternalType|assertIsEmpty|assertLessOrEquals|assertLessThan|assertLessThanOrEqual|assertNotContains|assertNotEmpty|assertNotEquals|assertNotInstanceOf|assertNotNull|assertNotRegExp|assertNotSame|assertNull|assertRegExp|assertSame|assertStringStartsNotWith|assertStringStartsWith|assertTrue|expectException|fail|dontSeeFullUrlEquals|dontSee|dontSeeFullUrlMatches|dontSeeInFullUrl|seeFullUrlEquals|seeFullUrlMatches|seeInFullUrl|grabFromFullUrl">
11+
<!ENTITY commonTestActions "acceptPopup|actionGroup|amOnPage|amOnUrl|amOnSubdomain|appendField|assertArrayIsSorted|assertArraySubset|assertElementContainsAttribute|attachFile|cancelPopup|checkOption|clearField|click|clickWithLeftButton|clickWithRightButton|closeAdminNotification|closeTab|comment|conditionalClick|createData|deleteData|updateData|getData|dontSee|dontSeeJsError|dontSeeCheckboxIsChecked|dontSeeCookie|dontSeeCurrentUrlEquals|dontSeeCurrentUrlMatches|dontSeeElement|dontSeeElementInDOM|dontSeeInCurrentUrl|dontSeeInField|dontSeeInFormFields|dontSeeInPageSource|dontSeeInSource|dontSeeInTitle|dontSeeLink|dontSeeOptionIsSelected|doubleClick|dragAndDrop|entity|executeJS|executeInSelenium|fillField|formatMoney|generateDate|grabAttributeFrom|grabCookie|grabFromCurrentUrl|grabMultiple|grabPageSource|grabTextFrom|grabValueFrom|loadSessionSnapshot|loginAsAdmin|magentoCLI|magentoCron|makeScreenshot|maximizeWindow|moveBack|moveForward|moveMouseOver|mSetLocale|mResetLocale|openNewTab|pauseExecution|parseFloat|performOn|pressKey|reloadPage|resetCookie|submitForm|resizeWindow|saveSessionSnapshot|scrollTo|scrollToTopOfPage|searchAndMultiSelectOption|see|seeCheckboxIsChecked|seeCookie|seeCurrentUrlEquals|seeCurrentUrlMatches|seeElement|seeElementInDOM|seeInCurrentUrl|seeInField|seeInFormFields|seeInPageSource|seeInPopup|seeInSource|seeInTitle|seeLink|seeNumberOfElements|seeOptionIsSelected|selectOption|setCookie|submitForm|switchToIFrame|switchToNextTab|switchToPreviousTab|switchToWindow|typeInPopup|uncheckOption|unselectOption|wait|waitForAjaxLoad|waitForElement|waitForElementChange|waitForElementNotVisible|waitForElementVisible|waitForPwaElementNotVisible|waitForPwaElementVisible|waitForJS|waitForLoadingMaskToDisappear|waitForPageLoad|waitForText|assertArrayHasKey|assertArrayNotHasKey|assertArraySubset|assertContains|assertCount|assertEmpty|assertEquals|assertFalse|assertFileExists|assertFileNotExists|assertGreaterOrEquals|assertGreaterThan|assertGreaterThanOrEqual|assertInstanceOf|assertInternalType|assertIsEmpty|assertLessOrEquals|assertLessThan|assertLessThanOrEqual|assertNotContains|assertNotEmpty|assertNotEquals|assertNotInstanceOf|assertNotNull|assertNotRegExp|assertNotSame|assertNull|assertRegExp|assertSame|assertStringStartsNotWith|assertStringStartsWith|assertTrue|expectException|fail|dontSeeFullUrlEquals|dontSee|dontSeeFullUrlMatches|dontSeeInFullUrl|seeFullUrlEquals|seeFullUrlMatches|seeInFullUrl|grabFromFullUrl">
1212
]>
1313

1414
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../src/Magento/FunctionalTestingFramework/ObjectManager/etc/config.xsd">

src/Magento/FunctionalTestingFramework/Console/BaseGenerateCommand.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ protected function getTestAndSuiteConfiguration(array $tests)
8787
$suiteToTestPair = [];
8888

8989
foreach($tests as $test) {
90+
if (strpos($test, ':') !== false) {
91+
$suiteToTestPair[] = $test;
92+
continue;
93+
}
9094
if (array_key_exists($test, $testsReferencedInSuites)) {
9195
$suites = $testsReferencedInSuites[$test];
9296
foreach ($suites as $suite) {

src/Magento/FunctionalTestingFramework/DataGenerator/Handlers/PersistedObjectHandler.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,14 @@ public function createEntity(
9797
}
9898

9999
$retrievedEntity = DataObjectHandler::getInstance()->getObject($entity);
100+
101+
if ($retrievedEntity === null) {
102+
throw new TestReferenceException(
103+
"Entity \"" . $entity . "\" does not exist." .
104+
"\nException occurred executing action at StepKey \"" . $key . "\""
105+
);
106+
}
107+
100108
$persistedObject = new DataPersistenceHandler(
101109
$retrievedEntity,
102110
$retrievedDependentObjects,

0 commit comments

Comments
 (0)