Skip to content

Commit eac8f86

Browse files
committed
MQE-1017: Better Error Messaging When Non-Whitespace Characters Are
Outside XML Elements - Adding verification test for filesystem to check error
1 parent 5afa47e commit eac8f86

File tree

3 files changed

+92
-5
lines changed

3 files changed

+92
-5
lines changed

dev/tests/util/MftfTestCase.php

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,20 @@
55
*/
66
namespace tests\util;
77

8+
use Magento\FunctionalTestingFramework\ObjectManager;
89
use Magento\FunctionalTestingFramework\Test\Handlers\TestObjectHandler;
910
use Magento\FunctionalTestingFramework\Util\TestGenerator;
1011
use PHPUnit\Framework\TestCase;
1112

1213
abstract class MftfTestCase extends TestCase
1314
{
14-
const RESOURCES_PATH = __DIR__ . '/../verification/Resources';
15+
const RESOURCES_PATH = __DIR__ .
16+
DIRECTORY_SEPARATOR .
17+
'..' .
18+
DIRECTORY_SEPARATOR .
19+
'verification' .
20+
DIRECTORY_SEPARATOR .
21+
'Resources';
1522

1623
/**
1724
* Private function which takes a test name, generates the test and compares with a correspondingly named txt file
@@ -37,4 +44,57 @@ public function generateAndCompareTest($testName)
3744
$cestFile
3845
);
3946
}
40-
}
47+
48+
/**
49+
* Private function which attempts to generate tests given an invalid shcema of a various type
50+
*
51+
* @param string[] $fileContents
52+
* @param string $objectType
53+
* @param string $expectedError
54+
* @throws \Exception
55+
*/
56+
public function validateSchemaErrorWithTest($fileContents, $objectType ,$expectedError)
57+
{
58+
$this->clearHandler();
59+
$fullTestModulePath = TESTS_MODULE_PATH .
60+
DIRECTORY_SEPARATOR .
61+
'TestModule' .
62+
DIRECTORY_SEPARATOR .
63+
$objectType .
64+
DIRECTORY_SEPARATOR;
65+
66+
foreach ($fileContents as $fileName => $fileContent) {
67+
$tempFile = $fullTestModulePath . $fileName;
68+
$handle = fopen($tempFile, 'w') or die('Cannot open file: ' . $tempFile);
69+
fwrite($handle, $fileContent);
70+
fclose($handle);
71+
}
72+
try {
73+
$this->expectExceptionMessage($expectedError);
74+
TestObjectHandler::getInstance()->getObject("someTest");
75+
} finally {
76+
foreach (array_keys($fileContents) as $fileName) {
77+
unlink($fullTestModulePath . $fileName);
78+
}
79+
$this->clearHandler();
80+
}
81+
}
82+
83+
/**
84+
* Clears test handler and object manager to force recollection of test data
85+
*
86+
* @throws \Exception
87+
*/
88+
private function clearHandler()
89+
{
90+
// clear test object handler to force recollection of test data
91+
$property = new \ReflectionProperty(TestObjectHandler::class, 'testObjectHandler');
92+
$property->setAccessible(true);
93+
$property->setValue(null);
94+
95+
// clear test object handler to force recollection of test data
96+
$property = new \ReflectionProperty(ObjectManager::class, 'instance');
97+
$property->setAccessible(true);
98+
$property->setValue(null);
99+
}
100+
}

dev/tests/verification/TestModule/Test/PageReplacementTest.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,4 @@
2222
<amOnPage stepKey="oneParamAdminPageString" url="{{AdminOneParamPage.url('StringLiteral')}}"/>
2323
<amOnUrl stepKey="onExternalPage" url="{{ExternalPage.url}}"/>
2424
</test>
25-
<test name="ExternalPageTestBadReference">
26-
<amOnPage stepKey="onExternalPage" url="{{ExternalPage.url}}"/>
27-
</test>
2825
</tests>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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 tests\util\MftfTestCase;
9+
10+
class SchemaValidationTest extends MftfTestCase
11+
{
12+
/**
13+
* Test generation of a test referencing an action group with no arguments
14+
*
15+
* @throws \Exception
16+
* @throws \Magento\FunctionalTestingFramework\Exceptions\TestReferenceException
17+
*/
18+
public function testInvalidTestSchema()
19+
{
20+
$testFile = ['testFile.xml' => "<tests><test name='testName'><annotations>a</annotations></test></tests>"];
21+
$expectedError = TESTS_MODULE_PATH .
22+
DIRECTORY_SEPARATOR .
23+
"TestModule" .
24+
DIRECTORY_SEPARATOR .
25+
"Test" .
26+
DIRECTORY_SEPARATOR .
27+
"testFile.xml";
28+
$this->validateSchemaErrorWithTest($testFile, 'Test', $expectedError);
29+
}
30+
}

0 commit comments

Comments
 (0)