Skip to content

Commit 4ffefa7

Browse files
committed
MQE-1963: Update XSD Schema to verify that file has only single entity
1 parent 1c9e996 commit 4ffefa7

File tree

6 files changed

+113
-14
lines changed

6 files changed

+113
-14
lines changed

dev/tests/verification/_suite/functionalSuite/functionalSuite1.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
*/
77
-->
88

9-
<suites xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../src/Magento/FunctionalTestingFramework/Suite/etc/suiteSchema.xsd">
9+
<suites xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../src/Magento/FunctionalTestingFramework/Suite/etc/suiteSchema.xsd">
1010
<suite name="functionalSuite1">
1111
<include>
12-
<group name="include"/>
12+
<group name = "include" />
1313
<test name="IncludeTest"/>
14-
<module name="TestModule" file="SampleSuite2Test/AdditionalIncludeTest2.xml"/>
15-
<module name="TestModule" file="SampleSuite2Test/AdditionalExcludeTest2.xml"/>
14+
<test name="additionalExcludeTest2"/>
15+
<test name="additionalIncludeTest2"/>
1616
</include>
1717
<exclude>
1818
<group name="exclude"/>

dev/tests/verification/_suite/functionalSuite/functionalSuite2.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
*/
77
-->
88

9-
<suites xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../src/Magento/FunctionalTestingFramework/Suite/etc/suiteSchema.xsd">
9+
<suites xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../src/Magento/FunctionalTestingFramework/Suite/etc/suiteSchema.xsd">
1010
<suite name="functionalSuite2">
1111
<include>
1212
<group name="include"/>
1313
<test name="IncludeTest"/>
14-
<module name="TestModule" file="SampleSuite2Test/AdditionalIncludeTest2.xml"/>
15-
<module name="TestModule" file="SampleSuite2Test/AdditionalExcludeTest2.xml"/>
14+
<test name="additionalExcludeTest2"/>
15+
<test name="additionalIncludeTest2"/>
1616
</include>
1717
<exclude>
1818
<group name="exclude"/>

src/Magento/FunctionalTestingFramework/Suite/etc/mergedSuiteSchema.xsd

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
<xs:simpleContent>
3030
<xs:extension base="xs:string">
3131
<xs:attribute type="xs:string" name="name" use="optional"/>
32-
<xs:attribute type="xs:string" name="file" use="optional"/>
3332
<xs:attribute type="xs:boolean" name="remove" use="optional"/>
3433
</xs:extension>
3534
</xs:simpleContent>
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\FunctionalTestingFramework\Upgrade;
8+
9+
use Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException;
10+
use Magento\FunctionalTestingFramework\Util\Script\ScriptUtil;
11+
use Symfony\Component\Console\Input\InputInterface;
12+
use Symfony\Component\Console\Output\OutputInterface;
13+
14+
/**
15+
* Class RemoveModuleFileInSuiteFiles
16+
* @package Magento\FunctionalTestingFramework\Upgrade
17+
*/
18+
class RemoveModuleFileInSuiteFiles implements UpgradeInterface
19+
{
20+
/**
21+
* OutputInterface
22+
*
23+
* @var OutputInterface
24+
*/
25+
private $output;
26+
27+
/**
28+
* Number of test being updated
29+
*
30+
* @var int
31+
*/
32+
private $testsUpdated = 0;
33+
34+
/**
35+
* Scan all suite xml files, remove <module file="".../> node, and print update message
36+
*
37+
* @param InputInterface $input
38+
* @param OutputInterface $output
39+
* @return string
40+
* @throws TestFrameworkException
41+
*/
42+
public function execute(InputInterface $input, OutputInterface $output)
43+
{
44+
$this->output = $output;
45+
$testPaths[] = $input->getArgument('path');
46+
if (empty($testPaths[0])) {
47+
$testPaths = ScriptUtil::getAllModulePaths();
48+
}
49+
50+
$xmlFiles = ScriptUtil::buildFileList(
51+
$testPaths,
52+
DIRECTORY_SEPARATOR . 'Suite' . DIRECTORY_SEPARATOR
53+
);
54+
55+
foreach ($xmlFiles as $file) {
56+
$contents = $file->getContents();
57+
$filePath = $file->getRealPath();
58+
file_put_contents($filePath, $this->removeModuleFileAttributeInSuite($contents, $filePath));
59+
}
60+
return ("Removed module file reference in {$this->testsUpdated} suite file(s).");
61+
}
62+
63+
/**
64+
* Remove module file attribute in Suite xml file
65+
*
66+
* @param $contents
67+
* @param $file
68+
* @return string|string[]|null
69+
*/
70+
private function removeModuleFileAttributeInSuite($contents, $file)
71+
{
72+
$count = 0;
73+
$pattern = '/<module[^\<\>]+file[\s]*=[\s]*"(?<file>[^"\<\>]*)"[^\>\<]*>/';
74+
$contents = preg_replace_callback(
75+
$pattern,
76+
function ($matches) use ($file, $count) {
77+
$this->output->writeln(
78+
PHP_EOL
79+
. '"' . trim($matches[0]) . '"' . PHP_EOL
80+
. 'is removed from suite xml file: ' . $file . PHP_EOL
81+
. 'Please update test reference from <module file=""/> to <test name=""/>.' . PHP_EOL
82+
);
83+
$count++;
84+
return '';
85+
},
86+
$contents
87+
);
88+
$this->testsUpdated += $count;
89+
return $contents;
90+
}
91+
}

src/Magento/FunctionalTestingFramework/Upgrade/SplitMultipleEntitiesFiles.php

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

99
use Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException;
1010
use Magento\FunctionalTestingFramework\Util\Script\ScriptUtil;
11-
use PHP_CodeSniffer\Exceptions\DeepExitException;
1211
use Symfony\Component\Console\Input\InputInterface;
1312
use Symfony\Component\Console\Output\OutputInterface;
1413

@@ -31,6 +30,13 @@ class SplitMultipleEntitiesFiles implements UpgradeInterface
3130
const FILENAME_BASE = 'base';
3231
const FILENAME_SUFFIX = 'type';
3332

33+
/**
34+
* OutputInterface
35+
*
36+
* @var OutputInterface
37+
*/
38+
private $output;
39+
3440
/**
3541
* Entity categories for the upgrade script
3642
*
@@ -45,7 +51,7 @@ class SplitMultipleEntitiesFiles implements UpgradeInterface
4551
];
4652

4753
/**
48-
* Scan all test xml files and split xml files that contains more than one entities
54+
* Scan all xml files and split xml files that contains more than one entities
4955
* for Test, Action Group, Page, Section, Suite types.
5056
*
5157
* @param InputInterface $input
@@ -55,6 +61,7 @@ class SplitMultipleEntitiesFiles implements UpgradeInterface
5561
*/
5662
public function execute(InputInterface $input, OutputInterface $output)
5763
{
64+
$this->output = $output;
5865
$testsUpdated = 0;
5966
$testPaths[] = $input->getArgument('path');
6067
if (empty($testPaths[0])) {
@@ -72,7 +79,7 @@ public function execute(InputInterface $input, OutputInterface $output)
7279
$entityContents = $this->getEntityContents($contents, $type);
7380
if (count($entityContents) > 1) {
7481
$filename = $file->getRealPath();
75-
$output->writeln('Processing file:' . $filename);
82+
$this->output->writeln('Processing file:' . $filename);
7683
foreach ($entityContents as $entityName => $entityContent) {
7784
$dir = dirname($file);
7885
$dir .= DIRECTORY_SEPARATOR . ucfirst(basename($file, '.xml'));
@@ -83,13 +90,13 @@ public function execute(InputInterface $input, OutputInterface $output)
8390
$urn,
8491
$entityContent
8592
);
86-
$output->writeln(
93+
$this->output->writeln(
8794
'Created file:' . $dir . DIRECTORY_SEPARATOR . $splitFileName . '.xml'
8895
);
8996
$testsUpdated++;
9097
}
9198
unlink($file);
92-
$output->writeln('Unlinked file:' . $filename . PHP_EOL);
99+
$this->output->writeln('Unlinked file:' . $filename . PHP_EOL);
93100
}
94101
}
95102
}
@@ -137,6 +144,7 @@ private function filePutContents($fullPath, $type, $urn, $contents)
137144
mkdir($dir, 0777, true);
138145
}
139146

147+
// Make sure not overwriting an existing file
140148
$fullPath = $this->getNonExistingFileFullPath($fullPath, $type);
141149

142150
$fullContents = self::XML_VERSION

src/Magento/FunctionalTestingFramework/Upgrade/UpgradeScriptList.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ public function __construct(array $scripts = [])
2929
{
3030
$this->scripts = [
3131
'upgradeTestSchema' => new UpdateTestSchemaPaths(),
32-
'splitMultipleEntitiesFiles' => new SplitMultipleEntitiesFiles()
32+
'splitMultipleEntitiesFiles' => new SplitMultipleEntitiesFiles(),
33+
'removeModuleFileInSuiteFiles' => new RemoveModuleFileInSuiteFiles(),
3334
] + $scripts;
3435
}
3536

0 commit comments

Comments
 (0)