8000 minor #54217 [Validator] backport NoSuspiciousCharactersValidator tes… · symfony/symfony@f9621d3 · GitHub
[go: up one dir, main page]

Skip to content

Commit f9621d3

Browse files
committed
minor #54217 [Validator] backport NoSuspiciousCharactersValidator test (xabbuh)
This PR was merged into the 6.4 branch. Discussion ---------- [Validator] backport NoSuspiciousCharactersValidator test | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | | License | MIT Commits ------- a788d3d backport NoSuspiciousCharactersValidator test
2 parents 04652b7 + a788d3d commit f9621d3

File tree

1 file changed

+37
-21
lines changed

1 file changed

+37
-21
lines changed

src/Symfony/Component/Validator/Tests/Constraints/NoSuspiciousCharactersValidatorTest.php

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -56,23 +56,34 @@ public static function provideNonSuspiciousStrings(): iterable
5656
/**
5757
* @dataProvider provideSuspiciousStrings
5858
*/
59-
public function testSuspiciousStrings(string $string, array $options, string $errorCode, string $errorMessage)
59+
public function testSuspiciousStrings(string $string, array $options, array $errors)
6060
{
6161
$this->validator->validate($string, new NoSuspiciousCharacters($options));
6262

63-
$this->buildViolation($errorMessage)
64-
->setCode($errorCode)
65-
->setParameter('{{ value }}', '"'.$string.'"')
66-
->assertRaised();
63+
$violations = null;
64+
65+
foreach ($errors as $code => $message) {
66+
if (null === $violations) {
67+
$violations = $this->buildViolation($message);
68+
} else {
69+
$violations = $violations->buildNextViolation($message);
70+
}
71+
72+
$violations = $violations
73+
->setCode($code)
74+
->setParameter('{{ value }}', '"'.$string.'"')
75+
;
76+
}
77+
78+
$violations->assertRaised();
6779
}
6880

6981
public static function provideSuspiciousStrings(): iterable
7082
{
7183
yield 'Fails RESTRICTION_LEVEL check because of character outside ASCII range' => [
7284
'à',
7385
['restrictionLevel' => NoSuspiciousCharacters::RESTRICTION_LEVEL_ASCII],
74-
NoSuspiciousCharacters::RESTRICTION_LEVEL_ERROR,
75-
'This value contains characters that are not allowed by the current restriction-level.',
86+
[NoSuspiciousCharacters::RESTRICTION_LEVEL_ERROR => 'This value contains characters that are not allowed by the current restriction-level.'],
7687
];
7788

7889
yield 'Fails RESTRICTION_LEVEL check because of mixed-script string' => [
@@ -81,8 +92,7 @@ public static function provideSuspiciousStrings(): iterable
8192
'restrictionLevel' => NoSuspiciousCharacters::RESTRICTION_LEVEL_SINGLE_SCRIPT,
8293
'locales' => ['en', 'zh_Hant_TW'],
8394
],
84-
NoSuspiciousCharacters::RESTRICTION_LEVEL_ERROR,
85-
'This value contains characters that are not allowed by the current restriction-level.',
95+
[NoSuspiciousCharacters::RESTRICTION_LEVEL_ERROR => 'This value contains characters that are not allowed by the current restriction-level.'],
8696
];
8797

8898
yield 'Fails RESTRICTION_LEVEL check because RESTRICTION_LEVEL_HIGH disallows Armenian script' => [
@@ -91,8 +101,7 @@ public static function provideSuspiciousStrings(): iterable
91101
'restrictionLevel' => NoSuspiciousCharacters::RESTRICTION_LEVEL_HIGH,
92102
'locales' => ['en', 'hy_AM'],
93103
],
94-
NoSuspiciousCharacters::RESTRICTION_LEVEL_ERROR,
95-
'This value contains characters that are not allowed by the current restriction-level.',
104+
[NoSuspiciousCharacters::RESTRICTION_LEVEL_ERROR => 'This value contains characters that are not allowed by the current restriction-level.'],
96105
];
97106

98107
yield 'Fails RESTRICTION_LEVEL check because RESTRICTION_LEVEL_MODERATE disallows Greek script' => [
@@ -101,8 +110,7 @@ public static function provideSuspiciousStrings(): iterable
101110
'restrictionLevel' => NoSuspiciousCharacters::RESTRICTION_LEVEL_MODERATE,
102111
'locales' => ['en', 'el_GR'],
103112
],
104-
NoSuspiciousCharacters::RESTRICTION_LEVEL_ERROR,
105-
'This value contains characters that are not allowed by the current restriction-level.',
113+
[NoSuspiciousCharacters::RESTRICTION_LEVEL_ERROR => 'This value contains characters that are not allowed by the current restriction-level.'],
106114
];
107115

108116
yield 'Fails RESTRICTION_LEVEL check because of characters missing from the configured locales’ scripts' => [
@@ -111,35 +119,43 @@ public static function provideSuspiciousStrings(): iterable
111119
'restrictionLevel' => NoSuspiciousCharacters::RESTRICTION_LEVEL_MINIMAL,
112120
'locales' => ['en'],
113121
],
114-
NoSuspiciousCharacters::RESTRICTION_LEVEL_ERROR,
115-
'This value contains characters that are not allowed by the current restriction-level.',
122+
[NoSuspiciousCharacters::RESTRICTION_LEVEL_ERROR => 'This value contains characters that are not allowed by the current restriction-level.'],
116123
];
117124

118125
yield 'Fails INVISIBLE check because of duplicated non-spacing mark' => [
119126
'à̀',
120127
[
121128
'checks' => NoSuspiciousCharacters::CHECK_INVISIBLE,
122129
],
123-
NoSuspiciousCharacters::INVISIBLE_ERROR,
124-
'Using invisible characters is not allowed.',
130+
[NoSuspiciousCharacters::INVISIBLE_ERROR => 'Using invisible characters is not allowed.'],
125131
];
126132

127133
yield 'Fails MIXED_NUMBERS check because of different numbering systems' => [
128134
'8৪',
129135
[
130136
'checks' => NoSuspiciousCharacters::CHECK_MIXED_NUMBERS,
131137
],
132-
NoSuspiciousCharacters::MIXED_NUMBERS_ERROR,
133-
'Mixing numbers from different scripts is not allowed.',
138+
[NoSuspiciousCharacters::MIXED_NUMBERS_ERROR => 'Mixing numbers from different scripts is not allowed.'],
134139
];
135140

136141
yield 'Fails HIDDEN_OVERLAY check because of hidden combining character' => [
137142
'',
138143
[
139144
'checks' => NoSuspiciousCharacters::CHECK_HIDDEN_OVERLAY,
140145
],
141-
NoSuspiciousCharacters::HIDDEN_OVERLAY_ERROR,
142-
'Using hidden overlay characters is not allowed.',
146+
[NoSuspiciousCharacters::HIDDEN_OVERLAY_ERROR => 'Using hidden overlay characters is not allowed.'],
147+
];
148+
149+
yield 'Fails both HIDDEN_OVERLAY and RESTRICTION_LEVEL checks' => [
150+
'',
151+
[
152+
'checks' => NoSuspiciousCharacters::CHECK_HIDDEN_OVERLAY,
153+
'restrictionLevel' => NoSuspiciousCharacters::RESTRICTION_LEVEL_ASCII,
154+
],
155+
[
156+
NoSuspiciousCharacters::RESTRICTION_LEVEL_ERROR => 'This value contains characters that are not allowed by the current restriction-level.',
157+
NoSuspiciousCharacters::HIDDEN_OVERLAY_ERROR => 'Using hidden overlay characters is not allowed.',
158+
],
143159
];
144160
}
145161

0 commit comments

Comments
 (0)
0