Skip to content

Commit fec2a5e

Browse files
committed
MQE-1650: Update MFTF configuration to read Test entities from new location
- update unit tests, verification tests
1 parent adf9d82 commit fec2a5e

File tree

3 files changed

+78
-21
lines changed

3 files changed

+78
-21
lines changed

dev/tests/unit/Magento/FunctionalTestFramework/Util/ModuleResolverTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ public function testGetModulePathsLocations()
131131
'globRelevantPaths',
132132
[$magentoBaseCodePath . '/dev/tests/acceptance/tests/functional', 'FunctionalTest/*', 1]
133133
);
134-
$mockResolver->verifyInvoked('globRelevantPaths', [$modulePath, 'Test/Mftf', 0]);
135-
$mockResolver->verifyInvoked('globRelevantPaths', [$modulePath, '*Test', 0]);
134+
$mockResolver->verifyInvoked('globRelevantPaths', [$modulePath, 'Test/Mftf', null]);
135+
$mockResolver->verifyInvoked('globRelevantPaths', [$modulePath, '*', 0]);
136136
}
137137

138138
/**
@@ -175,7 +175,7 @@ function ($arg1, $arg2, $arg3) {
175175
$resolver = ModuleResolver::getInstance();
176176
$this->setMockResolverProperties($resolver, null, null, ["somePath"]);
177177
$this->assertEquals(
178-
["lastPath", "lastPath", "lastPath", "lastPath", "lastPath"],
178+
["lastPath", "lastPath", "lastPath", "lastPath"],
179179
$resolver->getModulesPath()
180180
);
181181
TestLoggingUtil::getInstance()->validateMockLogStatement(

dev/tests/verification/TestModule/Page/SamplePage.xml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,25 @@
88

99
<pages xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
1010
xsi:noNamespaceSchemaLocation="../../../../../src/Magento/FunctionalTestingFramework/Page/etc/PageObject.xsd">
11-
<page name="SamplePage" url="/{{var1}}/{{var2}}.html" area="storefront" module="TestModule_Magento" parameterized="true">
11+
<page name="SamplePage" url="/{{var1}}/{{var2}}.html" area="storefront" module="Unknown_TestModule" parameterized="true">
1212
<section name="SampleSection"/>
1313
</page>
14-
<page name="NoParamPage" url="/page.html" area="storefront" module="TestModule_Magento">
14+
<page name="NoParamPage" url="/page.html" area="storefront" module="Unknown_TestModule">
1515
<section name="SampleSection"/>
1616
</page>
17-
<page name="OneParamPage" url="/{{var1}}/page.html" area="storefront" module="TestModule_Magento" parameterized="true">
17+
<page name="OneParamPage" url="/{{var1}}/page.html" area="storefront" module="Unknown_TestModule" parameterized="true">
1818
<section name="SampleSection"/>
1919
</page>
20-
<page name="TwoParamPage" url="/{{var1}}/{{var2}}.html" area="storefront" module="TestModule_Magento" parameterized="true">
20+
<page name="TwoParamPage" url="/{{var1}}/{{var2}}.html" area="storefront" module="Unknown_TestModule" parameterized="true">
2121
<section name="SampleSection"/>
2222
</page>
23-
<page name="AdminPage" url="/backend" area="admin" module="TestModule_Magento">
23+
<page name="AdminPage" url="/backend" area="admin" module="Unknown_TestModule">
2424
<section name="SampleSection"/>
2525
</page>
26-
<page name="AdminOneParamPage" url="/{{var1}}/page.html" area="admin" module="TestModule_Magento" parameterized="true">
26+
<page name="AdminOneParamPage" url="/{{var1}}/page.html" area="admin" module="Unknown_TestModule" parameterized="true">
2727
<section name="SampleSection"/>
2828
</page>
29-
<page name="ExternalPage" url="http://myFullUrl.com/" area="external" module="TestModule_Magento">
29+
<page name="ExternalPage" url="http://myFullUrl.com/" area="external" module="Unknown_TestModule">
3030
<section name="SampleSection"/>
3131
</page>
3232
</pages>

src/Magento/FunctionalTestingFramework/Util/ModuleResolver.php

Lines changed: 68 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,19 @@ class ModuleResolver
4040
const REGISTRAR_CLASS = "\Magento\Framework\Component\ComponentRegistrar";
4141

4242
/**
43-
* Vendor code path
43+
* const for vendor
4444
*/
45-
const VENDOR_CODE_PATH = DIRECTORY_SEPARATOR . "vendor";
45+
const VENDOR = 'vendor';
4646

4747
/**
48-
* App code path
48+
* const for app/code
4949
*/
50-
const APP_CODE_PATH = DIRECTORY_SEPARATOR . "app" . DIRECTORY_SEPARATOR . "code";
50+
const APP_CODE = 'app' . DIRECTORY_SEPARATOR . "code";
5151

5252
/**
53-
* Dev test code path
53+
* const for dev/tests/acceptance/tests/functional
5454
*/
55-
const DEV_TEST_CODE_PATH = DIRECTORY_SEPARATOR
56-
. 'dev'
55+
const DEV_TEST = 'dev'
5756
. DIRECTORY_SEPARATOR
5857
. 'tests'
5958
. DIRECTORY_SEPARATOR
@@ -63,6 +62,21 @@ class ModuleResolver
6362
. DIRECTORY_SEPARATOR
6463
. 'functional';
6564

65+
/**
66+
* Vendor code path
67+
*/
68+
const VENDOR_CODE_PATH = DIRECTORY_SEPARATOR . self::VENDOR;
69+
70+
/**
71+
* App code path
72+
*/
73+
const APP_CODE_PATH = DIRECTORY_SEPARATOR . self::APP_CODE;
74+
75+
/**
76+
* Dev test code path
77+
*/
78+
const DEV_TEST_CODE_PATH = DIRECTORY_SEPARATOR . self::DEV_TEST;
79+
6680
/**
6781
* Pattern for Mftf directories
6882
*/
@@ -101,6 +115,21 @@ class ModuleResolver
101115
*/
102116
const TEST_MODULE_NAME_REGEX = "~\S+" . self::TEST_MODULE_NAME_SUFFIX . "$~";
103117

118+
/**
119+
* Regex to grab vendor name in vendor
120+
*/
121+
const VENDOR_NAME_REGEX_V = "~.+\\/" . self::VENDOR . "\/(?<" . self::VENDOR . ">[^\/]+)\/.+~";
122+
123+
/**
124+
* Regex to grab vendor name in app/code
125+
*/
126+
const VENDOR_NAME_REGEX_A = "~.+\\/" . self::APP_CODE . "\/(?<" . self::VENDOR . ">[^\/]+)\/.+~";
127+
128+
/**
129+
* Regex to grab vendor name dev/tests
130+
*/
131+
const VENDOR_NAME_REGEX_D = "~.+\\/" . self::DEV_TEST . "\/(?<" . self::VENDOR . ">[^\/]+)\/.+~";
132+
104133
/**
105134
* Enabled modules.
106135
*
@@ -384,12 +413,12 @@ private function aggregateTestModulePaths()
384413
if ($newPath) {
385414
$codePathsToPattern[$modulePath] = [
386415
[
387-
'pattern' => 'Test' . DIRECTORY_SEPARATOR . 'Mftf',
416+
'pattern' => '*',
388417
'level' => 0
389418
],
390419
[
391-
'pattern' => '*' . self::TEST_MODULE_NAME_SUFFIX,
392-
'level' => 0
420+
'pattern' => 'Test' . DIRECTORY_SEPARATOR . 'Mftf',
421+
'level' => null
393422
]
394423
];
395424
}
@@ -432,6 +461,8 @@ private function globRelevantPaths($testPath, $pattern, $level)
432461
$allComponents = $this->getRegisteredModuleList();
433462

434463
foreach ($relevantPaths as $codePath) {
464+
$possibleVendorName = $this->getPossibleVendorName($codePath);
465+
435466
// Reduce magento/app/code/Magento/AdminGws/Test/MFTF to magento/app/code/Magento/AdminGws to read symlink
436467
// Symlinks must be resolved otherwise they will not match Magento's filepath to the module
437468
if ($pattern == self::MFTF_DIR_PATTERN) {
@@ -441,7 +472,7 @@ private function globRelevantPaths($testPath, $pattern, $level)
441472
$codePath = realpath($codePath);
442473
}
443474

444-
$mainModName = array_search($codePath, $allComponents) ?: basename($codePath);
475+
$mainModName = array_search($codePath, $allComponents) ?: $possibleVendorName . '_' . basename($codePath);
445476

446477
preg_match(self::INVALID_DEV_TEST_CODE_PATH_REGEX, $codePath, $match);
447478
if (empty($match)) {
@@ -820,4 +851,30 @@ private function validateModulePaths($modulePaths)
820851
}
821852
}
822853
}
854+
855+
/**
856+
* Return possible vendor name from a path given
857+
*
858+
* @param string $path
859+
* @return string
860+
*/
861+
private function getPossibleVendorName($path)
862+
{
863+
$possibleVendorName = 'Unknown';
864+
$regexs = [
865+
self::VENDOR_NAME_REGEX_A,
866+
self::VENDOR_NAME_REGEX_D,
867+
self::VENDOR_NAME_REGEX_V
868+
];
869+
870+
foreach ($regexs as $regex) {
871+
$match = [];
872+
preg_match($regex, $path, $match);
873+
if (isset($match[self::VENDOR])) {
874+
$possibleVendorName = ucfirst($match[self::VENDOR]);
875+
return $possibleVendorName;
876+
}
877+
}
878+
return $possibleVendorName;
879+
}
823880
}

0 commit comments

Comments
 (0)