@@ -22,47 +22,123 @@ protected function createValidator()
22
22
return new LocaleValidator ();
23
23
}
24
24
25
- public function testNullIsValid ()
25
+ /**
26
+ * @group legacy
27
+ * @expectedDeprecation The "canonicalize" option with value `false` is deprecated since Symfony 4.1. Set it to `true` instead.
28
+ *
29
+ * @dataProvider getValidLocales
30
+ */
31
+ public function testLegacyNullIsValid ()
26
32
{
27
33
$ this ->validator ->validate (null , new Locale ());
28
34
29
35
$ this ->assertNoViolation ();
30
36
}
31
37
32
- public function testEmptyStringIsValid ()
38
+ public function testNullIsValid ()
39
+ {
40
+ $ this ->validator ->validate (null , new Locale (array ('canonicalize ' => true )));
41
+
42
+ $ this ->assertNoViolation ();
43
+ }
44
+
45
+ /**
46
+ * @group legacy
47
+ * @expectedDeprecation The "canonicalize" option with value `false` is deprecated since Symfony 4.1. Set it to `true` instead.
48
+ *
49
+ * @dataProvider getValidLocales
50
+ */
51
+ public function testLegacyEmptyStringIsValid ()
33
52
{
34
53
$ this ->validator ->validate ('' , new Locale ());
35
54
36
55
$ this ->assertNoViolation ();
37
56
}
38
57
58
+ public function testEmptyStringIsValid ()
59
+ {
60
+ $ this ->validator ->validate ('' , new Locale (array ('canonicalize ' => true )));
61
+
62
+ $ this ->assertNoViolation ();
63
+ }
64
+
39
65
/**
66
+ * @group legacy
67
+ * @expectedDeprecation The "canonicalize" option with value `false` is deprecated since Symfony 4.1. Set it to `true` instead.
40
68
* @expectedException \Symfony\Component\Validator\Exception\UnexpectedTypeException
41
69
*/
42
- public function testExpectsStringCompatibleType ()
70
+ public function testLegacyExpectsStringCompatibleType ()
43
71
{
44
72
$ this ->validator ->validate (new \stdClass (), new Locale ());
45
73
}
46
74
47
75
/**
76
+ * @expectedException \Symfony\Component\Validator\Exception\UnexpectedTypeException
77
+ */
78
+ public function testExpectsStringCompatibleType ()
79
+ {
80
+ $ this ->validator ->validate (new \stdClass (), new Locale (array ('canonicalize ' => true )));
81
+ }
82
+
83
+ /**
84
+ * @group legacy
85
+ * @expectedDeprecation The "canonicalize" option with value `false` is deprecated since Symfony 4.1. Set it to `true` instead.
86
+ *
48
87
* @dataProvider getValidLocales
49
88
*/
50
- public function testValidLocales ( $ locale )
89
+ public function testLegacyValidLocales ( string $ locale )
51
90
{
52
91
$ this ->validator ->validate ($ locale , new Locale ());
53
92
54
93
$ this ->assertNoViolation ();
55
94
}
56
95
96
+ /**
97
+ * @dataProvider getValidLocales
98
+ */
99
+ public function testValidLocales ($ locale , array $ options )
100
+ {
101
+ $ this ->validator ->validate ($ locale , new Locale ($ options ));
102
+
103
+ $ this ->assertNoViolation ();
104
+ }
105
+
57
106
public function getValidLocales ()
58
107
{
59
108
return array (
60
- array ('en ' ),
61
- array ('en_US ' ),
62
- array ('pt ' ),
63
- array ('pt_PT ' ),
64
- array ('zh_Hans ' ),
65
- array ('fil_PH ' ),
109
+ array ('en ' , array ('canonicalize ' => true )),
110
+ array ('en_US ' , array ('canonicalize ' => true )),
111
+ array ('pt ' , array ('canonicalize ' => true )),
112
+ array ('pt_PT ' , array ('canonicalize ' => true )),
113
+ array ('zh_Hans ' , array ('canonicalize ' => true )),
114
+ array ('fil_PH ' , array ('canonicalize ' => true )),
115
+ );
116
+ }
117
+
118
+ /**
119
+ * @group legacy
120
+ * @expectedDeprecation The "canonicalize" option with value `false` is deprecated since Symfony 4.1. Set it to `true` instead.
121
+ * @dataProvider getLegacyInvalidLocales
122
+ */
123
+ public function testLegacyInvalidLocales (string $ locale )
124
+ {
125
+ $ constraint = new Locale (array (
126
+ 'message ' => 'myMessage ' ,
127
+ ));
128
+
129
+ $ this ->validator ->validate ($ locale , $ constraint );
130
+
131
+ $ this ->buildViolation ('myMessage ' )
132
+ ->setParameter ('{{ value }} ' , '" ' .$ locale .'" ' )
133
+ ->setCode (Locale::NO_SUCH_LOCALE_ERROR )
134
+ ->assertRaised ();
135
+ }
136
+
137
+ public function getLegacyInvalidLocales ()
138
+ {
139
+ return array (
140
+ array ('EN ' ),
141
+ array ('foobar ' ),
66
142
);
67
143
}
68
144
@@ -73,6 +149,7 @@ public function testInvalidLocales($locale)
73
149
{
74
150
$ constraint = new Locale (array (
75
151
'message ' => 'myMessage ' ,
152
+ 'canonicalize ' => true ,
76
153
));
77
154
78
155
$ this ->validator ->validate ($ locale , $ constraint );
@@ -86,12 +163,14 @@ public function testInvalidLocales($locale)
86
163
public function getInvalidLocales ()
87
164
{
88
165
return array (
89
- array ('EN ' ),
166
+ array ('baz ' ),
90
167
array ('foobar ' ),
91
168
);
92
169
}
93
170
94
171
/**
172
+ * @group legacy
173
+ * @expectedDeprecation The "canonicalize" option with value `false` is deprecated since Symfony 4.1. Set it to `true` instead.
95
174
* @dataProvider getUncanonicalizedLocales
96
175
*/
97
176
public function testInvalidLocalesWithoutCanonicalization (string $ locale )
0 commit comments