@@ -22,47 +22,123 @@ protected function createValidator()
2222 return new LocaleValidator ();
2323 }
2424
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 ()
2632 {
2733 $ this ->validator ->validate (null , new Locale ());
2834
2935 $ this ->assertNoViolation ();
3036 }
3137
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 ()
3352 {
3453 $ this ->validator ->validate ('' , new Locale ());
3554
3655 $ this ->assertNoViolation ();
3756 }
3857
58+ public function testEmptyStringIsValid ()
59+ {
60+ $ this ->validator ->validate ('' , new Locale (array ('canonicalize ' => true )));
61+
62+ $ this ->assertNoViolation ();
63+ }
64+
3965 /**
66+ * @group legacy
67+ * @expectedDeprecation The "canonicalize" option with value "false" is deprecated since Symfony 4.1, set it to "true" instead.
4068 * @expectedException \Symfony\Component\Validator\Exception\UnexpectedTypeException
4169 */
42- public function testExpectsStringCompatibleType ()
70+ public function testLegacyExpectsStringCompatibleType ()
4371 {
4472 $ this ->validator ->validate (new \stdClass (), new Locale ());
4573 }
4674
4775 /**
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+ *
4887 * @dataProvider getValidLocales
4988 */
50- public function testValidLocales ( $ locale )
89+ public function testLegacyValidLocales ( string $ locale )
5190 {
5291 $ this ->validator ->validate ($ locale , new Locale ());
5392
5493 $ this ->assertNoViolation ();
5594 }
5695
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+
57106 public function getValidLocales ()
58107 {
59108 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 ' ),
66142 );
67143 }
68144
@@ -73,6 +149,7 @@ public function testInvalidLocales($locale)
73149 {
74150 $ constraint = new Locale (array (
75151 'message ' => 'myMessage ' ,
152+ 'canonicalize ' => true ,
76153 ));
77154
78155 $ this ->validator ->validate ($ locale , $ constraint );
@@ -86,12 +163,14 @@ public function testInvalidLocales($locale)
86163 public function getInvalidLocales ()
87164 {
88165 return array (
89- array ('EN ' ),
166+ array ('baz ' ),
90167 array ('foobar ' ),
91168 );
92169 }
93170
94171 /**
172+ * @group legacy
173+ * @expectedDeprecation The "canonicalize" option with value "false" is deprecated since Symfony 4.1, set it to "true" instead.
95174 * @dataProvider getUncanonicalizedLocales
96175 */
97176 public function testInvalidLocalesWithoutCanonicalization (string $ locale )
0 commit comments