Skip to content

Commit 6529865

Browse files
authored
MQE-1974: Report used deprecated metadata in Test (#772)
* MQE-1974: Report used deprecated metadata in Test * MQE-1974: Report used deprecated metadata in Test * MQE-1974: Report used deprecated metadata in Test * MQE-1974: Report used deprecated metadata in Test verification tests
1 parent 081aa48 commit 6529865

File tree

13 files changed

+266
-15
lines changed

13 files changed

+266
-15
lines changed

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

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,21 @@
1313
use Magento\FunctionalTestingFramework\ObjectManager;
1414
use Magento\FunctionalTestingFramework\ObjectManagerFactory;
1515
use tests\unit\Util\MagentoTestCase;
16+
use tests\unit\Util\TestLoggingUtil;
1617

1718
/**
1819
* Class DataObjectHandlerTest
1920
*/
2021
class DataObjectHandlerTest extends MagentoTestCase
2122
{
23+
/**
24+
* Setup method
25+
*/
26+
public function setUp(): void
27+
{
28+
TestLoggingUtil::getInstance()->setMockLoggingUtil();
29+
}
30+
2231
// All tests share this array, feel free to add but be careful modifying or removing
2332
const PARSER_OUTPUT = [
2433
'entity' => [
@@ -44,6 +53,22 @@ class DataObjectHandlerTest extends MagentoTestCase
4453
]
4554
];
4655

56+
const PARSER_OUTPUT_DEPRECATED = [
57+
'entity' => [
58+
'EntityOne' => [
59+
'type' => 'testType',
60+
'data' => [
61+
0 => [
62+
'key' => 'testKey',
63+
'value' => 'testValue'
64+
]
65+
],
66+
'deprecated' => "deprecation message",
67+
'filename' => "filename.xml"
68+
],
69+
]
70+
];
71+
4772
const PARSER_OUTPUT_WITH_EXTEND = [
4873
'entity' => [
4974
'EntityOne' => [
@@ -134,6 +159,24 @@ public function testGetAllObjects()
134159
$this->assertEquals($expected, $actual['EntityOne']);
135160
}
136161

162+
/**
163+
* test deprecated data object
164+
*/
165+
public function testDeprecatedDataObject()
166+
{
167+
$this->setUpMockDataObjectHander(self::PARSER_OUTPUT_DEPRECATED);
168+
169+
// Call the method under test
170+
$actual = DataObjectHandler::getInstance()->getAllObjects();
171+
172+
//validate deprecation warning
173+
TestLoggingUtil::getInstance()->validateMockLogStatement(
174+
'warning',
175+
"DEPRECATION: The data entity 'EntityOne' is deprecated.",
176+
["fileName" => "filename.xml", "deprecatedMessage" => "deprecation message"]
177+
);
178+
}
179+
137180
/**
138181
* getObject should return the expected data object if it exists
139182
*/
@@ -269,4 +312,12 @@ private function setUpMockDataObjectHander($entityDataArray)
269312
'getObjectManager' => $mockObjectManager
270313
]);
271314
}
315+
316+
/**
317+
* clean up function runs after all tests
318+
*/
319+
public static function tearDownAfterClass(): void
320+
{
321+
TestLoggingUtil::getInstance()->clearMockLoggingUtil();
322+
}
272323
}

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

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,21 @@
1414
use Magento\FunctionalTestingFramework\DataGenerator\Handlers\OperationDefinitionObjectHandler;
1515
use Magento\FunctionalTestingFramework\DataGenerator\Parsers\OperationDefinitionParser;
1616
use tests\unit\Util\MagentoTestCase;
17+
use tests\unit\Util\TestLoggingUtil;
1718

1819
/**
1920
* Class OperationDefinitionObjectHandlerTest
2021
*/
2122
class OperationDefinitionObjectHandlerTest extends MagentoTestCase
2223
{
24+
/**
25+
* Setup method
26+
*/
27+
public function setUp(): void
28+
{
29+
TestLoggingUtil::getInstance()->setMockLoggingUtil();
30+
}
31+
2332
public function testGetMultipleObjects()
2433
{
2534
// Data Variables for Assertions
@@ -72,6 +81,56 @@ public function testGetMultipleObjects()
7281
$this->assertArrayHasKey($operationType2 . $dataType1, $operations);
7382
}
7483

84+
public function testDeprecatedOperation()
85+
{
86+
// Data Variables for Assertions
87+
$dataType1 = "type1";
88+
$operationType1 = "create";
89+
90+
/**
91+
* Parser Output. Just one metadata with 1 field
92+
* operationName
93+
* createType1
94+
* has field
95+
* key=id, value=integer
96+
*/
97+
$mockData = [OperationDefinitionObjectHandler::ENTITY_OPERATION_ROOT_TAG => [
98+
"testOperationName" => [
99+
OperationDefinitionObjectHandler::ENTITY_OPERATION_DATA_TYPE => $dataType1,
100+
OperationDefinitionObjectHandler::ENTITY_OPERATION_TYPE => $operationType1,
101+
OperationDefinitionObjectHandler::ENTITY_OPERATION_AUTH => "auth",
102+
OperationDefinitionObjectHandler::ENTITY_OPERATION_URL => "V1/Type1",
103+
OperationDefinitionObjectHandler::ENTITY_OPERATION_METHOD => "POST",
104+
OperationDefinitionObjectHandler::ENTITY_OPERATION_ENTRY => [
105+
0 => [
106+
OperationDefinitionObjectHandler::ENTITY_OPERATION_ENTRY_KEY => "id",
107+
OperationDefinitionObjectHandler::ENTITY_OPERATION_ENTRY_VALUE => "integer"
108+
],
109+
],
110+
OperationDefinitionObjectHandler::OBJ_DEPRECATED => 'deprecation message'
111+
]]];
112+
$this->setMockParserOutput($mockData);
113+
114+
//Perform Assertions
115+
$operationDefinitionManager = OperationDefinitionObjectHandler::getInstance();
116+
$operations = $operationDefinitionManager->getAllObjects();
117+
118+
$this->assertArrayHasKey($operationType1 . $dataType1, $operations);
119+
TestLoggingUtil::getInstance()->validateMockLogStatement(
120+
'notice',
121+
"NOTICE: 1 metadata operation name violations detected. See mftf.log for details.",
122+
[]
123+
);
124+
// test run time deprecation notice
125+
$operation = $operationDefinitionManager->getOperationDefinition($operationType1, $dataType1);
126+
$operation->logDeprecated();
127+
TestLoggingUtil::getInstance()->validateMockLogStatement(
128+
'warning',
129+
"DEPRECATION: The operation testOperationName is deprecated.",
130+
['operationType' => 'create', 'deprecatedMessage' => 'deprecation message']
131+
);
132+
}
133+
75134
public function testObjectCreation()
76135
{
77136
// Data Variables for Assertions
@@ -379,4 +438,12 @@ private function setMockParserOutput($data)
379438
$instance = AspectMock::double(ObjectManager::class, ['create' => $mockOperationParser])->make();
380439
AspectMock::double(ObjectManagerFactory::class, ['getObjectManager' => $instance]);
381440
}
441+
442+
/**
443+
* clean up function runs after all tests
444+
*/
445+
public static function tearDownAfterClass(): void
446+
{
447+
TestLoggingUtil::getInstance()->clearMockLoggingUtil();
448+
}
382449
}

dev/tests/unit/Magento/FunctionalTestFramework/Page/Handlers/PageObjectHandlerTest.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,18 @@
1212
use Magento\FunctionalTestingFramework\Page\Handlers\PageObjectHandler;
1313
use Magento\FunctionalTestingFramework\XmlParser\PageParser;
1414
use tests\unit\Util\MagentoTestCase;
15+
use tests\unit\Util\TestLoggingUtil;
1516

1617
class PageObjectHandlerTest extends MagentoTestCase
1718
{
19+
/**
20+
* Setup method
21+
*/
22+
public function setUp(): void
23+
{
24+
TestLoggingUtil::getInstance()->setMockLoggingUtil();
25+
}
26+
1827
public function testGetPageObject()
1928
{
2029
$mockData = [
@@ -70,6 +79,30 @@ public function testGetEmptyPage()
7079
$this->addToAssertionCount(1);
7180
}
7281

82+
public function testDeprecatedPage()
83+
{
84+
$mockData = [
85+
"testPage1" => [
86+
"url" => "testURL1",
87+
"module" => "testModule1",
88+
"section" => [
89+
],
90+
"area" => "test",
91+
"deprecated" => "deprecation message",
92+
"filename" => "filename.xml"
93+
]];
94+
$this->setMockParserOutput($mockData);
95+
96+
// get pages
97+
$page = PageObjectHandler::getInstance()->getObject('testPage1');
98+
99+
TestLoggingUtil::getInstance()->validateMockLogStatement(
100+
'notice',
101+
"NOTICE: 1 Page name violations detected. See mftf.log for details.",
102+
[]
103+
);
104+
}
105+
73106
/**
74107
* Function used to set mock for parser return and force init method to run between tests.
75108
*
@@ -86,4 +119,12 @@ private function setMockParserOutput($data)
86119
$instance = AspectMock::double(ObjectManager::class, ['get' => $mockSectionParser])->make();
87120
AspectMock::double(ObjectManagerFactory::class, ['getObjectManager' => $instance]);
88121
}
122+
123+
/**
124+
* clean up function runs after all tests
125+
*/
126+
public static function tearDownAfterClass(): void
127+
{
128+
TestLoggingUtil::getInstance()->clearMockLoggingUtil();
129+
}
89130
}

dev/tests/unit/Magento/FunctionalTestFramework/Page/Handlers/SectionObjectHandlerTest.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,18 @@
1212
use Magento\FunctionalTestingFramework\Page\Handlers\SectionObjectHandler;
1313
use Magento\FunctionalTestingFramework\XmlParser\SectionParser;
1414
use tests\unit\Util\MagentoTestCase;
15+
use tests\unit\Util\TestLoggingUtil;
1516

1617
class SectionObjectHandlerTest extends MagentoTestCase
1718
{
19+
/**
20+
* Setup method
21+
*/
22+
public function setUp(): void
23+
{
24+
TestLoggingUtil::getInstance()->setMockLoggingUtil();
25+
}
26+
1827
public function testGetSectionObject()
1928
{
2029
$mockData = [
@@ -52,6 +61,36 @@ public function testGetSectionObject()
5261
$this->assertNull($invalidSection);
5362
}
5463

64+
public function testDeprecatedSection()
65+
{
66+
$mockData = [
67+
"testSection1" => [
68+
"element" => [
69+
"testElement" => [
70+
"type" => "input",
71+
"selector" => "#element",
72+
"deprecated" => "element deprecation message"
73+
]
74+
],
75+
"filename" => "filename.xml",
76+
"deprecated" => "section deprecation message"
77+
]
78+
];
79+
80+
$this->setMockParserOutput($mockData);
81+
82+
// get sections
83+
$sectionHandler = SectionObjectHandler::getInstance();
84+
$section = $sectionHandler->getObject("testSection1");
85+
86+
//validate deprecation warning
87+
TestLoggingUtil::getInstance()->validateMockLogStatement(
88+
'notice',
89+
"NOTICE: 1 Section name violations detected. See mftf.log for details.",
90+
[]
91+
);
92+
}
93+
5594
/**
5695
* Set the mock parser return value
5796
*
@@ -68,4 +107,12 @@ private function setMockParserOutput($data)
68107
$instance = AspectMock::double(ObjectManager::class, ["get" => $mockSectionParser])->make();
69108
AspectMock::double(ObjectManagerFactory::class, ["getObjectManager" => $instance]);
70109
}
110+
111+
/**
112+
* clean up function runs after all tests
113+
*/
114+
public static function tearDownAfterClass(): void
115+
{
116+
TestLoggingUtil::getInstance()->clearMockLoggingUtil();
117+
}
71118
}

dev/tests/unit/Magento/FunctionalTestFramework/Test/Util/ActionGroupObjectExtractorTest.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,47 @@ public function testEmptyStepKey()
3434
$this->testActionGroupObjectExtractor->extractActionGroup($this->createBasicActionObjectArray(""));
3535
}
3636

37+
/**
38+
* Tests deprecation message for an action group
39+
*/
40+
public function testDeprecationMessage()
41+
{
42+
$this->testActionGroupObjectExtractor->extractActionGroup(
43+
$this->createBasicActionObjectArray(
44+
"testDeprecatedAction1",
45+
"actionGroup",
46+
"filename1.xml",
47+
"message"
48+
)
49+
);
50+
51+
TestLoggingUtil::getInstance()->validateMockLogStatement(
52+
'warning',
53+
"DEPRECATION: The action group 'actionGroup' is deprecated.",
54+
["fileName" => "filename1.xml", "deprecatedMessage" => "message"]
55+
);
56+
}
57+
3758
/**
3859
* Utility function to return mock parser output for testing extraction into ActionObjects.
3960
*
4061
* @param string $stepKey
4162
* @param string $actionGroup
4263
* @param string $filename
64+
* @param string $deprecated
4365
* @return array
4466
*/
4567
private function createBasicActionObjectArray(
4668
$stepKey = 'testAction1',
4769
$actionGroup = "actionGroup",
48-
$filename = "filename.xml"
70+
$filename = "filename.xml",
71+
$deprecated = null
4972
) {
5073
$baseArray = [
5174
'nodeName' => 'actionGroup',
5275
'name' => $actionGroup,
5376
'filename' => $filename,
77+
'deprecated' => $deprecated,
5478
$stepKey => [
5579
"nodeName" => "sampleAction",
5680
"stepKey" => $stepKey,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,8 @@ private function processParserOutput($parserOutput)
191191
if (array_key_exists(self::OBJ_DEPRECATED, $rawEntity)) {
192192
$deprecated = $rawEntity[self::OBJ_DEPRECATED];
193193
LoggingUtil::getInstance()->getLogger(self::class)->deprecation(
194-
$deprecated,
195-
["dataName" => $filename, "deprecatedEntity" => $deprecated]
194+
"The data entity '{$name}' is deprecated.",
195+
["fileName" => $filename, "deprecatedMessage" => $deprecated]
196196
);
197197
}
198198

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,8 @@ private function initialize()
215215

216216
if ($deprecated !== null) {
217217
LoggingUtil::getInstance()->getLogger(self::class)->deprecation(
218-
$deprecated,
219-
["operationName" => $dataDefName, "deprecatedOperation" => $deprecated]
218+
$message = "The operation {$dataDefName} is deprecated.",
219+
["operationType" => $operation, "deprecatedMessage" => $deprecated]
220220
);
221221
}
222222

0 commit comments

Comments
 (0)