Skip to content

Commit 284ec7b

Browse files
committed
MQE-483: Sanitize test naming to prevent Jenkins build failure
- add new validation util - update test object extractor to use validation util - add new unit test
1 parent 4acbb80 commit 284ec7b

File tree

3 files changed

+108
-0
lines changed

3 files changed

+108
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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;
8+
9+
use Magento\FunctionalTestingFramework\Exceptions\XmlException;
10+
use Magento\FunctionalTestingFramework\Test\Util\TestNameValidationUtil;
11+
use PHPUnit\Framework\TestCase;
12+
13+
class TestNameValidationUtilTest extends TestCase
14+
{
15+
/**
16+
* Validate name with curly braces throws exception
17+
*/
18+
public function testCurlyBracesInTestName()
19+
{
20+
$this->validateBlacklistedTestName("{{curlyBraces}}");
21+
}
22+
23+
/**
24+
* Validate name with quotation marks throws exception
25+
*/
26+
public function testQuotesInTestName()
27+
{
28+
$this->validateBlacklistedTestName("\"quotes\"");
29+
}
30+
31+
/**
32+
* Validate name with single quotes throws exception
33+
*/
34+
public function testSingleQuotesInTestName()
35+
{
36+
$this->validateBlacklistedTestName("'singleQuotes'");
37+
}
38+
39+
/**
40+
* Validate name with parenthesis throws execption
41+
*/
42+
public function testParenthesesInTestName()
43+
{
44+
$this->validateBlacklistedTestName("(parenthesis)");
45+
}
46+
47+
/**
48+
* Validate name with dollar signs throws exception
49+
*/
50+
public function testDollarSignInTestName()
51+
{
52+
$this->validateBlacklistedTestName("\$dollarSign\$");
53+
}
54+
55+
/**
56+
* Validate name with spaces throws exception
57+
*/
58+
public function testSpacesInTestName()
59+
{
60+
$this->validateBlacklistedTestName("Test Name With Spaces");
61+
}
62+
63+
/**
64+
* Method which takes the name of the test expecting an invalid char. Runs the validation method against name.
65+
*
66+
* @param string $testName
67+
*/
68+
private function validateBlacklistedTestName($testName)
69+
{
70+
$this->expectException(XmlException::class);
71+
TestNameValidationUtil::validateName($testName);
72+
}
73+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\FunctionalTestingFramework\Test\Util;
8+
9+
use Magento\FunctionalTestingFramework\Exceptions\XmlException;
10+
11+
class TestNameValidationUtil
12+
{
13+
const BLACKLISTED_CHAR = [" ", ",", "'", "\"" , "{", "}", "$", "(", ")" ];
14+
15+
/**
16+
* Function which runs a validation against the blacklisted char defined in this class. Validation occurs to insure
17+
* allure report does not error/future devOps builds do not error against illegal char.
18+
*
19+
* @param string $testName
20+
* @return void
21+
* @throws XmlException
22+
*/
23+
public static function validateName($testName)
24+
{
25+
$testChars = str_split($testName);
26+
27+
$diff = array_diff($testChars, self::BLACKLISTED_CHAR);
28+
if (count($diff) != count($testChars)) {
29+
throw new XmlException("Test name ${testName} contains illegal characters, please fix and re-run");
30+
}
31+
}
32+
}

src/Magento/FunctionalTestingFramework/Test/Util/TestObjectExtractor.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ public function extractTestData($cestTestData)
6363
continue;
6464
}
6565

66+
// validate the test name for blacklisted char (will cause allure report issues) MQE-483
67+
TestNameValidationUtil::validateName($testName);
68+
6669
$testAnnotations = [];
6770
$testActions = $this->stripDescriptorTags(
6871
$testData,

0 commit comments

Comments
 (0)