Skip to content

Commit f353e42

Browse files
committed
MQE-1963: Update XSD Schema to verify that file has only single entity
1 parent 55ac3b8 commit f353e42

31 files changed

+921
-571
lines changed

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

Lines changed: 0 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -55,108 +55,4 @@ public function testGetTestModulesFromPaths()
5555
$output = $composer->getTestModulesFromPaths([$baseDir]);
5656
$this->assertEquals($expected, $output);
5757
}
58-
59-
/**
60-
* Test findComposerJsonFilesAtDepth()
61-
*
62-
* @dataProvider findComposerJsonFilesAtDepthDataProvider
63-
* @param string $dir
64-
* @param integer $depth
65-
* @param array $expected
66-
* @throws \ReflectionException
67-
*/
68-
public function testFindComposerJsonFilesAtDepth($dir, $depth, $expected)
69-
{
70-
$composer = new ComposerModuleResolver();
71-
$class = new ReflectionClass($composer);
72-
$method = $class->getMethod('findComposerJsonFilesAtDepth');
73-
$method->setAccessible(true);
74-
$output = $method->invoke($composer, $dir, $depth);
75-
$this->assertEquals($expected, $output);
76-
}
77-
78-
/**
79-
* Test findAllComposerJsonFiles()
80-
*
81-
* @dataProvider findAllComposerJsonFilesDataProvider
82-
* @param string $dir
83-
* @param array $expected
84-
* @throws \ReflectionException
85-
*/
86-
public function testFindAllComposerJsonFiles($dir, $expected)
87-
{
88-
$composer = new ComposerModuleResolver();
89-
$class = new ReflectionClass($composer);
90-
$method = $class->getMethod('findAllComposerJsonFiles');
91-
$method->setAccessible(true);
92-
$output = $method->invoke($composer, $dir);
93-
$this->assertEquals($expected, $output);
94-
}
95-
96-
/**
97-
* Data provider for testFindComposerJsonFilesAtDepth()
98-
*
99-
* @return array
100-
*/
101-
public function findComposerJsonFilesAtDepthDataProvider()
102-
{
103-
$baseDir = dirname(__DIR__) . DIRECTORY_SEPARATOR . 'Composer' . DIRECTORY_SEPARATOR . '_files'
104-
. DIRECTORY_SEPARATOR . 'dir1' . DIRECTORY_SEPARATOR . 'dir2';
105-
return [
106-
[
107-
$baseDir,
108-
0,
109-
[
110-
$baseDir . DIRECTORY_SEPARATOR . 'composer.json'
111-
]
112-
],
113-
[
114-
$baseDir,
115-
1,
116-
[
117-
$baseDir . DIRECTORY_SEPARATOR . 'dir31' . DIRECTORY_SEPARATOR . 'composer.json',
118-
$baseDir . DIRECTORY_SEPARATOR . 'dir32' . DIRECTORY_SEPARATOR . 'composer.json',
119-
]
120-
],
121-
[
122-
$baseDir,
123-
2,
124-
[
125-
$baseDir . DIRECTORY_SEPARATOR . 'dir31' . DIRECTORY_SEPARATOR . 'dir41' . DIRECTORY_SEPARATOR
126-
. 'composer.json',
127-
$baseDir . DIRECTORY_SEPARATOR . 'dir32' . DIRECTORY_SEPARATOR . 'dir41' . DIRECTORY_SEPARATOR
128-
. 'composer.json',
129-
$baseDir . DIRECTORY_SEPARATOR . 'dir32' . DIRECTORY_SEPARATOR . 'dir42' . DIRECTORY_SEPARATOR
130-
. 'composer.json',
131-
]
132-
]
133-
];
134-
}
135-
136-
/**
137-
* Data provider for testFindAllComposerJsonFiles()
138-
*
139-
* @return array
140-
*/
141-
public function findAllComposerJsonFilesDataProvider()
142-
{
143-
$baseDir = dirname(__DIR__) . DIRECTORY_SEPARATOR . 'Composer' . DIRECTORY_SEPARATOR . '_files'
144-
. DIRECTORY_SEPARATOR . 'dir1' . DIRECTORY_SEPARATOR . 'dir2';
145-
return [
146-
[
147-
$baseDir,
148-
[
149-
$baseDir . DIRECTORY_SEPARATOR . 'dir31' . DIRECTORY_SEPARATOR . 'dir41' . DIRECTORY_SEPARATOR
150-
. 'composer.json',
151-
$baseDir . DIRECTORY_SEPARATOR . 'dir31' . DIRECTORY_SEPARATOR . 'composer.json',
152-
$baseDir . DIRECTORY_SEPARATOR . 'dir32' . DIRECTORY_SEPARATOR . 'dir41' . DIRECTORY_SEPARATOR
153-
. 'composer.json',
154-
$baseDir . DIRECTORY_SEPARATOR . 'dir32' . DIRECTORY_SEPARATOR . 'dir42' . DIRECTORY_SEPARATOR
155-
. 'composer.json',
156-
$baseDir . DIRECTORY_SEPARATOR . 'dir32' . DIRECTORY_SEPARATOR . 'composer.json',
157-
$baseDir . DIRECTORY_SEPARATOR . 'composer.json',
158-
]
159-
]
160-
];
161-
}
16258
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace tests\unit\Magento\FunctionalTestFramework\Test\Util\Filesystem;
8+
9+
use ReflectionClass;
10+
use Magento\FunctionalTestingFramework\Util\Filesystem\RecursiveGlobUtil;
11+
use Magento\FunctionalTestingFramework\Util\MagentoTestCase;
12+
13+
class RecursiveGlobUtilTest extends MagentoTestCase
14+
{
15+
/**
16+
* Test globAtDepth()
17+
*
18+
* @dataProvider globAtDepthDataProvider
19+
* @param string $dir
20+
* @param integer $depth
21+
* @param array $expected
22+
* @throws \ReflectionException
23+
*/
24+
public function testGlobAtDepth($dir, $depth, $expected)
25+
{
26+
$output = RecursiveGlobUtil::globAtDepth('composer.json', $dir, $depth);
27+
$this->assertEquals($expected, $output);
28+
}
29+
30+
/**
31+
* Test glob()
32+
*
33+
* @dataProvider globDataProvider
34+
* @param string $dir
35+
* @param array $expected
36+
* @throws \ReflectionException
37+
*/
38+
public function testGlob($dir, $expected)
39+
{
40+
$output = RecursiveGlobUtil::glob('composer.json', $dir);
41+
$this->assertEquals($expected, $output);
42+
}
43+
44+
/**
45+
* Data provider for testGlobAtDepth()
46+
*
47+
* @return array
48+
*/
49+
public function globAtDepthDataProvider()
50+
{
51+
$baseDir = dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR . 'Composer' . DIRECTORY_SEPARATOR . '_files'
52+
. DIRECTORY_SEPARATOR . 'dir1' . DIRECTORY_SEPARATOR . 'dir2';
53+
return [
54+
[
55+
$baseDir,
56+
0,
57+
[
58+
$baseDir . DIRECTORY_SEPARATOR . 'composer.json'
59+
]
60+
],
61+
[
62+
$baseDir,
63+
1,
64+
[
65+
$baseDir . DIRECTORY_SEPARATOR . 'dir31' . DIRECTORY_SEPARATOR . 'composer.json',
66+
$baseDir . DIRECTORY_SEPARATOR . 'dir32' . DIRECTORY_SEPARATOR . 'composer.json',
67+
]
68+
],
69+
[
70+
$baseDir,
71+
2,
72+
[
73+
$baseDir . DIRECTORY_SEPARATOR . 'dir31' . DIRECTORY_SEPARATOR . 'dir41' . DIRECTORY_SEPARATOR
74+
. 'composer.json',
75+
$baseDir . DIRECTORY_SEPARATOR . 'dir32' . DIRECTORY_SEPARATOR . 'dir41' . DIRECTORY_SEPARATOR
76+
. 'composer.json',
77+
$baseDir . DIRECTORY_SEPARATOR . 'dir32' . DIRECTORY_SEPARATOR . 'dir42' . DIRECTORY_SEPARATOR
78+
. 'composer.json',
79+
]
80+
]
81+
];
82+
}
83+
84+
/**
85+
* Data provider for testGlob()
86+
*
87+
* @return array
88+
*/
89+
public function globDataProvider()
90+
{
91+
$baseDir = dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR . 'Composer' . DIRECTORY_SEPARATOR . '_files'
92+
. DIRECTORY_SEPARATOR . 'dir1' . DIRECTORY_SEPARATOR . 'dir2';
93+
return [
94+
[
95+
$baseDir,
96+
[
97+
$baseDir . DIRECTORY_SEPARATOR . 'dir31' . DIRECTORY_SEPARATOR . 'dir41' . DIRECTORY_SEPARATOR
98+
. 'composer.json',
99+
$baseDir . DIRECTORY_SEPARATOR . 'dir31' . DIRECTORY_SEPARATOR . 'composer.json',
100+
$baseDir . DIRECTORY_SEPARATOR . 'dir32' . DIRECTORY_SEPARATOR . 'dir41' . DIRECTORY_SEPARATOR
101+
. 'composer.json',
102+
$baseDir . DIRECTORY_SEPARATOR . 'dir32' . DIRECTORY_SEPARATOR . 'dir42' . DIRECTORY_SEPARATOR
103+
. 'composer.json',
104+
$baseDir . DIRECTORY_SEPARATOR . 'dir32' . DIRECTORY_SEPARATOR . 'composer.json',
105+
$baseDir . DIRECTORY_SEPARATOR . 'composer.json',
106+
]
107+
]
108+
];
109+
}
110+
}

docs/best-practices.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Check out our best practices below to ensure you are getting the absolute most o
77
1. [Action group] names should be sufficiently descriptive to inform a test writer of what the action group does and when it should be used.
88
Add additional explanation in annotations if needed.
99
2. Provide default values for the arguments that apply to your most common case scenarios.
10+
3. One `<actionGroup>` tag is allowed per action group XML file.
1011

1112
## `actionGroups` vs `extends`
1213

@@ -111,7 +112,8 @@ Use a lower case first letter for:
111112

112113
## Page object
113114

114-
Use [parameterized selectors] for constructing a selector when test specific or runtime generated information is needed.
115+
1. One `<page>` tag is allowed per page XML file.
116+
2. Use [parameterized selectors] for constructing a selector when test specific or runtime generated information is needed.
115117
Do not use them for static elements.
116118

117119
<span class="color:red">
@@ -149,6 +151,7 @@ Define these three elements and reference them by name in the tests.
149151
It helps to inform the reader of what you are testing and to yield a more descriptive Allure report.
150152
- Explain in comments unclear or tricky test steps.
151153
1. Refer to [sections] instead of writing selectors.
154+
1. One `<test>` tag is allowed per test XML file.
152155

153156
## Test step merging order
154157

docs/page.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ The following conventions apply to MFTF pages:
4545
- `<page>` name must be alphanumeric.
4646
- `*Page.xml` is stored in the _Page_ directory of a module.
4747
- The name format is `{Admin|Storefront}{PageDescription}Page.xml`.
48-
48+
- One `<page>` tag is allowed per page XML file.
49+
4950
The `.url` attribute is required when using the page for [actions] that require the URL argument.
5051

5152
## Page examples

docs/section.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ The following conventions apply to MFTF sections:
4848
- `*Section.xml` is stored in the _Section_ directory of a module.
4949
- The name format is `{Admin|Storefront}{SectionDescription}Section.xml`.
5050
- Camel case is used for `<section>` elements.
51-
They describe the function of the element rather than attempting to describe the selector used.
51+
They describe the function of the element rather than attempting to describe the selector used.
52+
- One `<section>` tag is allowed per section XML file.
5253

5354
## Example
5455

docs/suite.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ The format of a suite:
5252

5353
- A suite must contain at least one `<include>`, or one `<exclude>`, or both.
5454
- Using `<before>` in a suite, you must add the corresponding `<after>` to restore the initial state of your testing instance.
55+
- One `<suite>` tag is allowed per suite XML file.
5556

5657
## Conditions
5758

docs/test.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,7 @@ The following conventions apply to MFTF tests:
4949
* Each action and action group has its own identifier `<stepKey>` for reference purposes.
5050
* A test may have any number of [assertions][assertion] at any point within the `<test>`.
5151
* If `<test>` is included in `<suite>`, it **cannot be generated in isolation** to the rest of the contents of the suite (see [suites] for details).
52-
53-
Multiple `<test>` tags per XML file can make it hard to find and organize tags.
54-
To simplify, we generate one `test.php` file per `<test>` tag provided, though we support both single and multiple `<test>` tags per XML file.
52+
* One `<test>` tag is allowed per test XML file.
5553

5654
## Elements reference
5755

docs/test/action-groups.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ The following conventions apply to MFTF action groups:
1515
- All action groups are declared in XML files and stored in the `<module>/Test/Mftf/ActionGroup/` directory.
1616
- Every file name ends with `ActionGroup` suffix. For exampe `LoginAsAdminActionGroup.xml`.
1717
- Action group name should be the same as file name without extension.
18-
- Single file should contain only one `<actionGroup>` node
18+
- One `<actionGroup>` tag is allowed per action group XML file.
1919

2020
The XML format for the `actionGroups` declaration is:
2121

etc/di.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,12 @@
7070

7171
<virtualType name="Magento\FunctionalTestingFramework\Config\SchemaLocator\Page" type="Magento\FunctionalTestingFramework\Config\SchemaLocator">
7272
<arguments>
73-
<argument name="schemaPath" xsi:type="string">Magento/FunctionalTestingFramework/Page/etc/PageObject.xsd</argument>
73+
<argument name="schemaPath" xsi:type="string">Magento/FunctionalTestingFramework/Page/etc/mergedPageObject.xsd</argument>
7474
</arguments>
7575
</virtualType>
7676
<virtualType name="Magento\FunctionalTestingFramework\Config\SchemaLocator\Section" type="Magento\FunctionalTestingFramework\Config\SchemaLocator">
7777
<arguments>
78-
<argument name="schemaPath" xsi:type="string">Magento/FunctionalTestingFramework/Page/etc/SectionObject.xsd</argument>
78+
<argument name="schemaPath" xsi:type="string">Magento/FunctionalTestingFramework/Page/etc/mergedSectionObject.xsd</argument>
7979
</arguments>
8080
</virtualType>
8181
<virtualType name="Magento\FunctionalTestingFramework\Config\Reader\Page" type="Magento\FunctionalTestingFramework\Config\Reader\MftfFilesystem">
@@ -286,7 +286,7 @@
286286

287287
<virtualType name="Magento\FunctionalTestingFramework\Config\SchemaLocator\ActionGroup" type="Magento\FunctionalTestingFramework\Config\SchemaLocator">
288288
<arguments>
289-
<argument name="schemaPath" xsi:type="string">Magento/FunctionalTestingFramework/Test/etc/actionGroupSchema.xsd</argument>
289+
<argument name="schemaPath" xsi:type="string">Magento/FunctionalTestingFramework/Test/etc/mergedActionGroupSchema.xsd</argument>
290290
</arguments>
291291
</virtualType>
292292

@@ -353,7 +353,7 @@
353353
</virtualType>
354354
<virtualType name="Magento\FunctionalTestingFramework\Config\SchemaLocator\SuiteData" type="Magento\FunctionalTestingFramework\Config\SchemaLocator">
355355
<arguments>
356-
<argument name="schemaPath" xsi:type="string">Magento/FunctionalTestingFramework/Suite/etc/suiteSchema.xsd</argument>
356+
<argument name="schemaPath" xsi:type="string">Magento/FunctionalTestingFramework/Suite/etc/mergedSuiteSchema.xsd</argument>
357357
</arguments>
358358
</virtualType>
359359
<virtualType name="Magento\FunctionalTestingFramework\Config\Reader\SuiteData" type="Magento\FunctionalTestingFramework\Config\Reader\Filesystem">

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Magento\FunctionalTestingFramework\Util\Iterator\File;
1010
use Magento\FunctionalTestingFramework\Config\FileResolverInterface;
1111
use Magento\FunctionalTestingFramework\Util\ModuleResolver;
12+
use Magento\FunctionalTestingFramework\Util\Filesystem\RecursiveGlobUtil;
1213

1314
/**
1415
* Provides the list of configuration files collected through modules test folders.
@@ -58,8 +59,10 @@ protected function getPaths($filename, $scope)
5859
$modulesPath = $this->moduleResolver->getModulesPath();
5960
$paths = [];
6061
foreach ($modulesPath as $modulePath) {
61-
$path = $modulePath . DIRECTORY_SEPARATOR . $scope . DIRECTORY_SEPARATOR . $filename;
62-
$paths = array_merge($paths, glob($path));
62+
$paths = array_merge(
63+
$paths,
64+
RecursiveGlobUtil::glob($filename, $modulePath . DIRECTORY_SEPARATOR . $scope)
65+
);
6366
}
6467

6568
return $paths;

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException;
1111
use Magento\FunctionalTestingFramework\Util\Iterator\File;
1212
use Magento\FunctionalTestingFramework\Util\Path\FilePathFormatter;
13+
use Magento\FunctionalTestingFramework\Util\Filesystem\RecursiveGlobUtil;
1314

1415
class Root extends Module
1516
{
@@ -27,13 +28,10 @@ class Root extends Module
2728
public function get($filename, $scope)
2829
{
2930
// first pick up the root level test suite dir
30-
$paths = glob(
31-
FilePathFormatter::format(TESTS_BP) . self::ROOT_SUITE_DIR
32-
. DIRECTORY_SEPARATOR . $filename
33-
);
31+
$paths = RecursiveGlobUtil::glob($filename, FilePathFormatter::format(TESTS_BP) . self::ROOT_SUITE_DIR);
3432

3533
// then merge this path into the module based paths
36-
// Since we are sharing this code with Module based resolution we will unncessarily glob against modules in the
34+
// Since we are sharing this code with Module based resolution we will unnecessarily glob against modules in the
3735
// dev/tests dir tree, however as we plan to migrate to app/code this will be a temporary unneeded check.
3836
$paths = array_merge($paths, $this->getPaths($filename, $scope));
3937

src/Magento/FunctionalTestingFramework/Console/BuildProjectCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ function ($type, $buffer) use ($output) {
109109

110110
if ($input->getOption('upgrade')) {
111111
$upgradeCommand = new UpgradeTestsCommand();
112-
$upgradeOptions = new ArrayInput(['path' => FilePathFormatter::format(TESTS_MODULE_PATH)]);
112+
$upgradeOptions = new ArrayInput([]);
113113
$upgradeCommand->run($upgradeOptions, $output);
114114
}
115115
}

0 commit comments

Comments
 (0)