Skip to content

Commit 55bab02

Browse files
committed
MQE-2229: Deprecation Error When Deprecated ActionGroup References Deprecated Element
Verification test
1 parent 4d54ae4 commit 55bab02

File tree

13 files changed

+277
-5
lines changed

13 files changed

+277
-5
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
10+
<actionGroup name="DeprecationCheckActionGroup">
11+
<see stepKey="deprecatedSee" userInput="text" selector="{{DeprecationCheckSection.deprecationCheckElement}}" />
12+
</actionGroup>
13+
</actionGroups>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
10+
<actionGroup name="DeprecationCheckDeprecatedActionGroup" deprecated="deprecated">
11+
<see stepKey="deprecatedSee" userInput="text" selector="{{DeprecationCheckSection.deprecationCheckElement}}" />
12+
</actionGroup>
13+
</actionGroups>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<entities xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:DataGenerator/etc/dataProfileSchema.xsd">
11+
<entity name="DeprecationCheckData" type="type1" deprecated="deprecated">
12+
<data key="field">value</data>
13+
</entity>
14+
</entities>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<operations xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:DataGenerator/etc/dataOperation.xsd">
11+
<operation name="DeprecationCheckMeta" dataType="type1" type="create" auth="adminFormKey" url="/V1/test" method="POST" deprecated="deprecated">
12+
<contentType>application/json</contentType>
13+
<object key="category" dataType="type1">
14+
<field key="key1">value1</field>
15+
<field key="key2">value2</field>
16+
</object>
17+
</operation>
18+
</operations>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<pages xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/PageObject.xsd">
11+
<page name="DeprecationCheckPage" url="/test.html" area="storefront" module="UnknownVendor_DeprecationCheckModule" deprecated="Deprecated page">
12+
<section name="DeprecationCheckSection"/>
13+
</page>
14+
</pages>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<sections xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/SectionObject.xsd">
11+
<section name="DeprecationCheckSection" deprecated="deprecated">
12+
<element name="deprecationCheckElement" type="button" selector="#elementOne" deprecated="deprecated"/>
13+
<element name="elementTwo" type="button" selector="#elementTwo"/>
14+
<element name="elementThree" type="button" selector="#elementThree"/>
15+
</section>
16+
</sections>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<suites xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Suite/etc/suiteSchema.xsd">
10+
<suite name="deprecationCheckSuite">
11+
<include>
12+
<test name="DeprecationCheckDeprecatedTest"/>
13+
<test name="DeprecationCheckTest"/>
14+
</include>
15+
</suite>
16+
</suites>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
11+
<test name="DeprecationCheckDeprecatedTest" deprecated="deprecated">
12+
<createData entity="DeprecationCheckData" stepKey="deprecatedCreateData"/>
13+
<actionGroup ref="DeprecationCheckActionGroup" stepKey="deprecationCheckActionGroup" />
14+
<amOnPage url="{{DeprecationCheckPage.url}}" stepKey="deprecatedAmOnPage" />
15+
<actionGroup ref="DeprecationCheckDeprecatedActionGroup" stepKey="deprecationCheckDeprecatedActionGroup" />
16+
</test>
17+
</tests>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
11+
<test name="DeprecationCheckTest">
12+
<createData entity="DeprecationCheckData" stepKey="deprecatedCreateData"/>
13+
<actionGroup ref="DeprecationCheckActionGroup" stepKey="deprecationCheckActionGroup" />
14+
<amOnPage url="{{DeprecationCheckPage.url}}" stepKey="deprecatedAmOnPage" />
15+
<actionGroup ref="DeprecationCheckDeprecatedActionGroup" stepKey="deprecationCheckDeprecatedActionGroup" />
16+
</test>
17+
</tests>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
File "/verification/DeprecationCheckModule/Test/DeprecationCheckTest.xml" contains:
3+
- Deprecated Page(s):
4+
"DeprecationCheckPage" in /verification/DeprecationCheckModule/Page/DeprecationCheckPage.xml
5+
- Deprecated ActionGroup(s):
6+
"DeprecationCheckDeprecatedActionGroup" in /verification/DeprecationCheckModule/ActionGroup/DeprecationCheckDeprecatedActionGroup.xml
7+
- Deprecated Data(s):
8+
"DeprecationCheckData" in /verification/DeprecationCheckModule/Data/DeprecationCheckData.xml
9+
- "DeprecationCheckData" references deprecated:
10+
"type1" in metadata xml file
11+
12+
13+
File "/verification/DeprecationCheckModule/ActionGroup/DeprecationCheckActionGroup.xml" contains:
14+
- Deprecated Section(s):
15+
"DeprecationCheckSection" in /verification/DeprecationCheckModule/Section/DeprecationCheckSection.xml
16+
- Deprecated Element(s):
17+
"DeprecationCheckSection.deprecationCheckElement" in /verification/DeprecationCheckModule/Section/DeprecationCheckSection.xml
18+
19+
20+
File "/verification/DeprecationCheckModule/Suite/deprecationCheckSuite.xml" contains:
21+
- Deprecated Test(s):
22+
"DeprecationCheckDeprecatedTest" in /verification/DeprecationCheckModule/Test/DeprecationCheckDeprecatedTest.xml
23+
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace tests\verification\Tests;
7+
8+
use AspectMock\Test as AspectMock;
9+
use Magento\FunctionalTestingFramework\StaticCheck\DeprecatedEntityUsageCheck;
10+
use Magento\FunctionalTestingFramework\StaticCheck\StaticChecksList;
11+
use Magento\FunctionalTestingFramework\Util\Filesystem\DirSetupUtil;
12+
use PHPUnit\Framework\TestCase;
13+
use Symfony\Component\Console\Input\InputInterface;
14+
15+
class DeprecationStaticCheckTest extends TestCase
16+
{
17+
const STATIC_RESULTS_DIR = TESTS_MODULE_PATH .
18+
DIRECTORY_SEPARATOR .
19+
'_output' .
20+
DIRECTORY_SEPARATOR .
21+
'static-results';
22+
23+
const LOG_FILE = self::STATIC_RESULTS_DIR .
24+
DIRECTORY_SEPARATOR .
25+
DeprecatedEntityUsageCheck::ERROR_LOG_FILENAME .
26+
'.txt';
27+
28+
const TEST_MODULE_PATH = TESTS_MODULE_PATH .
29+
DIRECTORY_SEPARATOR .
30+
'DeprecationCheckModule'.
31+
DIRECTORY_SEPARATOR;
32+
33+
const RESOURCES_PATH = TESTS_MODULE_PATH .
34+
DIRECTORY_SEPARATOR .
35+
"Resources" .
36+
DIRECTORY_SEPARATOR .
37+
'StaticChecks';
38+
39+
public static function setUpBeforeClass(): void
40+
{
41+
// remove static-results if it exists
42+
if (file_exists(self::STATIC_RESULTS_DIR)) {
43+
DirSetupUtil::rmdirRecursive(self::STATIC_RESULTS_DIR);
44+
}
45+
}
46+
47+
/**
48+
* test static-check DeprecatedEntityUsageCheck.
49+
*
50+
* @throws \Exception
51+
*/
52+
public function testDeprecatedEntityUsageCheck()
53+
{
54+
$staticCheck = new DeprecatedEntityUsageCheck();
55+
56+
$input = $this->mockInputInterface(self::TEST_MODULE_PATH);
57+
AspectMock::double(StaticChecksList::class, ['getErrorFilesPath' => self::STATIC_RESULTS_DIR]);
58+
59+
/** @var InputInterface $input */
60+
$staticCheck->execute($input);
61+
62+
$this->assertTrue(file_exists(self::LOG_FILE));
63+
$this->assertFileEquals(
64+
self::RESOURCES_PATH.
65+
DIRECTORY_SEPARATOR .
66+
DeprecatedEntityUsageCheck::ERROR_LOG_FILENAME .
67+
".txt",
68+
self::LOG_FILE
69+
);
70+
}
71+
72+
/**
73+
* Sets input interface
74+
* @param $path
75+
* @return \PHPUnit\Framework\MockObject\MockObject
76+
*/
77+
public function mockInputInterface($path)
78+
{
79+
$input = $this->getMockBuilder(InputInterface::class)
80+
->disableOriginalConstructor()
81+
->getMock();
82+
$input->method('getOption')
83+
->with('path')
84+
->willReturn($path);
85+
return $input;
86+
}
87+
88+
public function tearDown(): void
89+
{
90+
DirSetupUtil::rmdirRecursive(self::STATIC_RESULTS_DIR);
91+
}
92+
}

src/Magento/FunctionalTestingFramework/StaticCheck/DeprecatedEntityUsageCheck.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,6 @@ private function loadAllXmlFiles($input)
178178
MftfApplicationConfig::LEVEL_DEFAULT,
179179
true
180180
);
181-
putenv('CUSTOM_MODULE_PATHS=' . realpath($path));
182181
$modulePaths[] = realpath($path);
183182
$includeRootPath = false;
184183
} else {
@@ -629,9 +628,9 @@ private function findViolatingReferences($references)
629628
$name = $key;
630629
list($section,) = explode('.', $key, 2);
631630
/** @var SectionObject $references[$section] */
632-
$file = $references[$section]->getFilename();
631+
$file = StaticChecksList::getFilePath($references[$section]->getFilename());
633632
} else {
634-
$file = $entity->getFilename();
633+
$file = StaticChecksList::getFilePath($entity->getFilename());
635634
}
636635
$violatingReferences[$this->getSubjectFromClassType($classType)][] = [
637636
'name' => $name,
@@ -653,16 +652,18 @@ private function setErrorOutput($violatingReferences, $path)
653652
{
654653
$testErrors = [];
655654

655+
$filePath = StaticChecksList::getFilePath($path->getRealPath());
656+
656657
if (!empty($violatingReferences)) {
657658
// Build error output
658-
$errorOutput = "\nFile \"{$path->getRealPath()}\" contains:\n";
659+
$errorOutput = "\nFile \"{$filePath}\" contains:\n";
659660
foreach ($violatingReferences as $subject => $data) {
660661
$errorOutput .= "\t- {$subject}:\n";
661662
foreach ($data as $item) {
662663
$errorOutput .= "\t\t\"" . $item['name'] . "\" in " . $item['file'] . "\n";
663664
}
664665
}
665-
$testErrors[$path->getRealPath()][] = $errorOutput;
666+
$testErrors[$filePath][] = $errorOutput;
666667
}
667668

668669
return $testErrors;

src/Magento/FunctionalTestingFramework/StaticCheck/StaticChecksList.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,22 @@ public static function getErrorFilesPath()
6969
{
7070
return self::$errorFilesPath;
7171
}
72+
73+
/**
74+
* Return relative path to files for unit testing purposes.
75+
* @param string $fileNames
76+
* @return string
77+
*/
78+
public static function getFilePath($fileNames)
79+
{
80+
if (!empty($fileNames)) {
81+
$relativeFileNames = ltrim(
82+
str_replace(MAGENTO_BP, '', $fileNames)
83+
);
84+
if (!empty($relativeFileNames)) {
85+
return $relativeFileNames;
86+
}
87+
}
88+
return $fileNames;
89+
}
7290
}

0 commit comments

Comments
 (0)