@@ -86,14 +86,104 @@ public function testReverseTransformWithGrouping()
86
86
{
87
87
$ transformer = new NumberToLocalizedStringTransformer (null , true );
88
88
89
+ // completely valid format
89
90
$ this ->assertEquals (1234.5 , $ transformer ->reverseTransform ('1.234,5 ' ));
90
91
$ this ->assertEquals (12345.912 , $ transformer ->reverseTransform ('12.345,912 ' ));
92
+ // omit group separator
91
93
$ this ->assertEquals (1234.5 , $ transformer ->reverseTransform ('1234,5 ' ));
92
94
$ this ->assertEquals (12345.912 , $ transformer ->reverseTransform ('12345,912 ' ));
93
95
}
94
96
97
+ public function testDecimalSeparatorMayBeDotIfGroupingSeparatorIsNotDot ()
98
+ {
99
+ \Locale::setDefault ('fr ' );
100
+ $ transformer = new NumberToLocalizedStringTransformer (null , true );
101
+
102
+ // completely valid format
103
+ $ this ->assertEquals (1234.5 , $ transformer ->reverseTransform ('1 234,5 ' ));
104
+ // accept dots
105
+ $ this ->assertEquals (1234.5 , $ transformer ->reverseTransform ('1 234.5 ' ));
106
+ // omit group separator
107
+ $ this ->assertEquals (1234.5 , $ transformer ->reverseTransform ('1234,5 ' ));
108
+ $ this ->assertEquals (1234.5 , $ transformer ->reverseTransform ('1234.5 ' ));
109
+ }
110
+
111
+ /**
112
+ * @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
113
+ */
114
+ public function testDecimalSeparatorMayNotBeDotIfGroupingSeparatorIsDot ()
115
+ {
116
+ $ transformer = new NumberToLocalizedStringTransformer (null , true );
117
+
118
+ $ transformer ->reverseTransform ('1.234.5 ' );
119
+ }
120
+
121
+ /**
122
+ * @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
123
+ */
124
+ public function testDecimalSeparatorMayNotBeDotIfGroupingSeparatorIsDot_noGroupSep ()
125
+ {
126
+ $ transformer = new NumberToLocalizedStringTransformer (null , true );
127
+
128
+ $ transformer ->reverseTransform ('1234.5 ' );
129
+ }
130
+
131
+ public function testDecimalSeparatorMayBeDotIfGroupingSeparatorIsDotButNoGroupingUsed ()
132
+ {
133
+ \Locale::setDefault ('fr ' );
134
+ $ transformer = new NumberToLocalizedStringTransformer ();
135
+
136
+ $ this ->assertEquals (1234.5 , $ transformer ->reverseTransform ('1234,5 ' ));
137
+ $ this ->assertEquals (1234.5 , $ transformer ->reverseTransform ('1234.5 ' ));
138
+ }
139
+
140
+ public function testDecimalSeparatorMayBeCommaIfGroupingSeparatorIsNotComma ()
141
+ {
142
+ \Locale::setDefault ('ak ' );
143
+ $ transformer = new NumberToLocalizedStringTransformer (null , true );
144
+
145
+ // completely valid format
146
+ $ this ->assertEquals (1234.5 , $ transformer ->reverseTransform ('1 234.5 ' ));
147
+ // accept commas
148
+ $ this ->assertEquals (1234.5 , $ transformer ->reverseTransform ('1 234,5 ' ));
149
+ // omit group separator
150
+ $ this ->assertEquals (1234.5 , $ transformer ->reverseTransform ('1234.5 ' ));
151
+ $ this ->assertEquals (1234.5 , $ transformer ->reverseTransform ('1234,5 ' ));
152
+ }
153
+
154
+ /**
155
+ * @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
156
+ */
157
+ public function testDecimalSeparatorMayNotBeCommaIfGroupingSeparatorIsComma ()
158
+ {
159
+ \Locale::setDefault ('en ' );
160
+ $ transformer = new NumberToLocalizedStringTransformer (null , true );
161
+
162
+ $ transformer ->reverseTransform ('1,234,5 ' );
163
+ }
164
+
165
+ /**
166
+ * @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
167
+ */
168
+ public function testDecimalSeparatorMayNotBeCommaIfGroupingSeparatorIsComma_noGroupSep ()
169
+ {
170
+ \Locale::setDefault ('en ' );
171
+ $ transformer = new NumberToLocalizedStringTransformer (null , true );
172
+
173
+ $ transformer ->reverseTransform ('1234,5 ' );
174
+ }
175
+
176
+ public function testDecimalSeparatorMayBeCommaIfGroupingSeparatorIsCommaButNoGroupingUsed ()
177
+ {
178
+ \Locale::setDefault ('en ' );
179
+ $ transformer = new NumberToLocalizedStringTransformer ();
180
+
181
+ $ this ->assertEquals (1234.5 , $ transformer ->reverseTransform ('1234,5 ' ));
182
+ $ this ->assertEquals (1234.5 , $ transformer ->reverseTransform ('1234.5 ' ));
183
+ }
184
+
95
185
/**
96
- * @expectedException Symfony\Component\Form\Exception\UnexpectedTypeException
186
+ * @expectedException \ Symfony\Component\Form\Exception\UnexpectedTypeException
97
187
*/
98
188
public function testTransformExpectsNumeric ()
99
189
{
@@ -103,7 +193,7 @@ public function testTransformExpectsNumeric()
103
193
}
104
194
105
195
/**
106
- * @expectedException Symfony\Component\Form\Exception\UnexpectedTypeException
196
+ * @expectedException \ Symfony\Component\Form\Exception\UnexpectedTypeException
107
197
*/
108
198
public function testReverseTransformExpectsString ()
109
199
{
@@ -113,7 +203,7 @@ public function testReverseTransformExpectsString()
113
203
}
114
204
115
205
/**
116
- * @expectedException Symfony\Component\Form\Exception\TransformationFailedException
206
+ * @expectedException \ Symfony\Component\Form\Exception\TransformationFailedException
117
207
*/
118
208
public function testReverseTransformExpectsValidNumber ()
119
209
{
@@ -123,7 +213,7 @@ public function testReverseTransformExpectsValidNumber()
123
213
}
124
214
125
215
/**
126
- * @expectedException Symfony\Component\Form\Exception\TransformationFailedException
216
+ * @expectedException \ Symfony\Component\Form\Exception\TransformationFailedException
127
217
* @link https://github.com/symfony/symfony/issues/3161
128
218
*/
129
219
public function testReverseTransformDisallowsNaN ()
@@ -134,7 +224,7 @@ public function testReverseTransformDisallowsNaN()
134
224
}
135
225
136
226
/**
137
- * @expectedException Symfony\Component\Form\Exception\TransformationFailedException
227
+ * @expectedException \ Symfony\Component\Form\Exception\TransformationFailedException
138
228
*/
139
229
public function testReverseTransformDisallowsNaN2 ()
140
230
{
@@ -144,7 +234,7 @@ public function testReverseTransformDisallowsNaN2()
144
234
}
145
235
146
236
/**
147
- * @expectedException Symfony\Component\Form\Exception\TransformationFailedException
237
+ * @expectedException \ Symfony\Component\Form\Exception\TransformationFailedException
148
238
*/
149
239
public function testReverseTransformDisallowsInfinity ()
150
240
{
@@ -154,7 +244,7 @@ public function testReverseTransformDisallowsInfinity()
154
244
}
155
245
156
246
/**
157
- * @expectedException Symfony\Component\Form\Exception\TransformationFailedException
247
+ * @expectedException \ Symfony\Component\Form\Exception\TransformationFailedException
158
248
*/
159
249
public function testReverseTransformDisallowsInfinity2 ()
160
250
{
@@ -164,7 +254,7 @@ public function testReverseTransformDisallowsInfinity2()
164
254
}
165
255
166
256
/**
167
- * @expectedException Symfony\Component\Form\Exception\TransformationFailedException
257
+ * @expectedException \ Symfony\Component\Form\Exception\TransformationFailedException
168
258
*/
169
259
public function testReverseTransformDisallowsNegativeInfinity ()
170
260
{
0 commit comments