Skip to content

Commit 44428ad

Browse files
committed
MQE-483: Sanitize test naming to prevent Jenkins build failure
- add invalid char to error message, review feedback
1 parent 284ec7b commit 44428ad

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public function testSpacesInTestName()
6464
* Method which takes the name of the test expecting an invalid char. Runs the validation method against name.
6565
*
6666
* @param string $testName
67+
* @return void
6768
*/
6869
private function validateBlacklistedTestName($testName)
6970
{

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

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,17 @@
1010

1111
class TestNameValidationUtil
1212
{
13-
const BLACKLISTED_CHAR = [" ", ",", "'", "\"" , "{", "}", "$", "(", ")" ];
13+
const BLACKLISTED_CHAR = [
14+
" " => "spaces",
15+
"," => "commas",
16+
"'" => "single quotes",
17+
"\"" => "double quotes",
18+
"{" => "curly braces",
19+
"}" => "curly braces",
20+
"$" => "dollar signs",
21+
"(" => "parenthesis",
22+
")" => "parenthesis"
23+
];
1424

1525
/**
1626
* Function which runs a validation against the blacklisted char defined in this class. Validation occurs to insure
@@ -24,9 +34,21 @@ public static function validateName($testName)
2434
{
2535
$testChars = str_split($testName);
2636

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");
37+
$diff = array_intersect($testChars, array_keys(self::BLACKLISTED_CHAR));
38+
if (count($diff) > 0) {
39+
$errorMessage = "Test name \"${testName}\" contains illegal characters, please fix and re-run.";
40+
$uniqueDiff = array_unique(array_map(['self', 'nameMapper'], $diff));
41+
42+
foreach ($uniqueDiff as $diffChar) {
43+
$errorMessage .= "\nTest names cannot contain " . $diffChar;
44+
}
45+
46+
throw new XmlException($errorMessage);
3047
}
3148
}
49+
50+
private static function nameMapper($val)
51+
{
52+
return self::BLACKLISTED_CHAR[$val];
53+
}
3254
}

0 commit comments

Comments
 (0)