@@ -133,25 +133,28 @@ public function testGetIdIncludesParent()
133
133
$ this ->assertEquals ('news_article_title ' , $ this ->field ->getId ());
134
134
}
135
135
136
- public function testLocaleIsPassedToLocalizableValueTransformer_setLocaleCalledBefore ()
137
- {
138
- $ transformer = $ this ->getMock ('Symfony\Component\Form\ValueTransformer\ValueTransformerInterface ' );
139
- $ transformer ->expects ($ this ->once ())
140
- ->method ('setLocale ' )
141
- ->with ($ this ->equalTo ('de_DE ' ));
142
-
143
- $ this ->field ->setLocale ('de_DE ' );
144
- $ this ->field ->setValueTransformer ($ transformer );
145
- }
136
+ // public function testLocaleIsPassedToLocalizableValueTransformer_setLocaleCalledBefore()
137
+ // {
138
+ // $transformer = $this->getMock('Symfony\Component\Form\ValueTransformer\ValueTransformerInterface');
139
+ // $transformer->expects($this->once())
140
+ // ->method('setLocale')
141
+ // ->with($this->equalTo('de_DE'));
142
+ //
143
+ // $this->field->setLocale('de_DE');
144
+ // $this->field->setValueTransformer($transformer);
145
+ // }
146
146
147
147
public function testLocaleIsPassedToValueTransformer_setLocaleCalledAfter ()
148
148
{
149
149
$ transformer = $ this ->getMock ('Symfony\Component\Form\ValueTransformer\ValueTransformerInterface ' );
150
150
$ transformer ->expects ($ this ->exactly (2 ))
151
151
->method ('setLocale ' ); // we can't test the params cause they differ :(
152
152
153
- $ this ->field ->setValueTransformer ($ transformer );
154
- $ this ->field ->setLocale ('de_DE ' );
153
+ $ field = new TestField ('title ' , array (
154
+ 'value_transformer ' => $ transformer ,
155
+ ));
156
+
157
+ $ field ->setLocale ('de_DE ' );
155
158
}
156
159
157
160
public function testIsRequiredReturnsOwnValueIfNoParent ()
@@ -231,21 +234,24 @@ public function testValuesAreTransformedCorrectlyIfNull_noValueTransformer()
231
234
232
235
public function testBoundValuesAreTransformedCorrectly ()
233
236
{
237
+ $ valueTransformer = $ this ->createMockTransformer ();
238
+ $ normTransformer = $ this ->createMockTransformer ();
239
+
234
240
$ field = $ this ->getMock (
235
241
'Symfony\Tests\Component\Form\Fixtures\TestField ' ,
236
242
array ('processData ' ), // only mock processData()
237
- array ('title ' )
243
+ array ('title ' , array (
244
+ 'value_transformer ' => $ valueTransformer ,
245
+ 'normalization_transformer ' => $ normTransformer ,
246
+ ))
238
247
);
239
248
240
249
// 1a. The value is converted to a string and passed to the value transformer
241
- $ valueTransformer = $ this ->createMockTransformer ();
242
250
$ valueTransformer ->expects ($ this ->once ())
243
251
->method ('reverseTransform ' )
244
252
->with ($ this ->identicalTo ('0 ' ))
245
253
->will ($ this ->returnValue ('reverse[0] ' ));
246
254
247
- $ field ->setValueTransformer ($ valueTransformer );
248
-
249
255
// 2. The output of the reverse transformation is passed to processData()
250
256
// The processed data is accessible through getNormalizedData()
251
257
$ field ->expects ($ this ->once ())
@@ -255,14 +261,11 @@ public function testBoundValuesAreTransformedCorrectly()
255
261
256
262
// 3. The processed data is denormalized and then accessible through
257
263
// getData()
258
- $ normTransformer = $ this ->createMockTransformer ();
259
264
$ normTransformer ->expects ($ this ->once ())
260
265
->method ('reverseTransform ' )
261
266
->with ($ this ->identicalTo ('processed[reverse[0]] ' ))
262
267
->will ($ this ->returnValue ('denorm[processed[reverse[0]]] ' ));
263
268
264
- $ field ->setNormalizationTransformer ($ normTransformer );
265
-
266
269
// 4. The processed data is transformed again and then accessible
267
270
// through getDisplayedData()
268
271
$ valueTransformer ->expects ($ this ->once ())
@@ -279,21 +282,22 @@ public function testBoundValuesAreTransformedCorrectly()
279
282
280
283
public function testBoundValuesAreTransformedCorrectlyIfEmpty_processDataReturnsValue ()
281
284
{
285
+ $ transformer = $ this ->createMockTransformer ();
286
+
282
287
$ field = $ this ->getMock (
283
288
'Symfony\Tests\Component\Form\Fixtures\TestField ' ,
284
289
array ('processData ' ), // only mock processData()
285
- array ('title ' )
290
+ array ('title ' , array (
291
+ 'value_transformer ' => $ transformer ,
292
+ ))
286
293
);
287
294
288
295
// 1. Empty values are converted to NULL by convention
289
- $ transformer = $ this ->createMockTransformer ();
290
296
$ transformer ->expects ($ this ->once ())
291
297
->method ('reverseTransform ' )
292
298
->with ($ this ->identicalTo ('' ))
293
299
->will ($ this ->returnValue (null ));
294
300
295
- $ field ->setValueTransformer ($ transformer );
296
-
297
301
// 2. NULL is passed to processData()
298
302
$ field ->expects ($ this ->once ())
299
303
->method ('processData ' )
@@ -314,26 +318,29 @@ public function testBoundValuesAreTransformedCorrectlyIfEmpty_processDataReturns
314
318
315
319
public function testBoundValuesAreTransformedCorrectlyIfEmpty_processDataReturnsNull ()
316
320
{
317
- // 1. Empty values are converted to NULL by convention
318
321
$ transformer = $ this ->createMockTransformer ();
322
+
323
+ $ field = new TestField ('title ' , array (
324
+ 'value_transformer ' => $ transformer ,
325
+ ));
326
+
327
+ // 1. Empty values are converted to NULL by convention
319
328
$ transformer ->expects ($ this ->once ())
320
329
->method ('reverseTransform ' )
321
330
->with ($ this ->identicalTo ('' ))
322
331
->will ($ this ->returnValue (null ));
323
332
324
- $ this ->field ->setValueTransformer ($ transformer );
325
-
326
333
// 2. The processed data is NULL and therefore transformed to an empty
327
334
// string by convention
328
335
$ transformer ->expects ($ this ->once ())
329
336
->method ('transform ' )
330
337
->with ($ this ->identicalTo (null ))
331
338
->will ($ this ->returnValue ('' ));
332
339
333
- $ this -> field ->bind ('' );
340
+ $ field ->bind ('' );
334
341
335
- $ this ->assertSame (null , $ this -> field ->getData ());
336
- $ this ->assertEquals ('' , $ this -> field ->getDisplayedData ());
342
+ $ this ->assertSame (null , $ field ->getData ());
343
+ $ this ->assertEquals ('' , $ field ->getDisplayedData ());
337
344
}
338
345
339
346
public function testBoundValuesAreTransformedCorrectlyIfEmpty_processDataReturnsNull_noValueTransformer ()
@@ -348,25 +355,30 @@ public function testValuesAreTransformedCorrectly()
348
355
{
349
356
// The value is first passed to the normalization transformer...
350
357
$ normTransformer = $ this ->createMockTransformer ();
351
- $ normTransformer ->expects ($ this ->once ( ))
358
+ $ normTransformer ->expects ($ this ->exactly ( 2 ))
352
359
->method ('transform ' )
353
- ->with ($ this ->identicalTo (0 ))
360
+ // Impossible to test with PHPUnit because called twice
361
+ // ->with($this->identicalTo(0))
354
362
->will ($ this ->returnValue ('norm[0] ' ));
355
363
356
364
// ...and then to the value transformer
357
365
$ valueTransformer = $ this ->createMockTransformer ();
358
- $ valueTransformer ->expects ($ this ->once ( ))
366
+ $ valueTransformer ->expects ($ this ->exactly ( 2 ))
359
367
->method ('transform ' )
360
- ->with ($ this ->identicalTo ('norm[0] ' ))
368
+ // Impossible to test with PHPUnit because called twice
369
+ // ->with($this->identicalTo('norm[0]'))
361
370
->will ($ this ->returnValue ('transform[norm[0]] ' ));
362
371
363
- $ this ->field ->setNormalizationTransformer ($ normTransformer );
364
- $ this ->field ->setValueTransformer ($ valueTransformer );
365
- $ this ->field ->setData (0 );
372
+ $ field = new TestField ('title ' , array (
373
+ 'value_transformer ' => $ valueTransformer ,
374
+ 'normalization_transformer ' => $ normTransformer ,
375
+ ));
376
+
377
+ $ field ->setData (0 );
366
378
367
- $ this ->assertEquals (0 , $ this -> field ->getData ());
368
- $ this ->assertEquals ('norm[0] ' , $ this -> field ->getNormalizedData ());
369
- $ this ->assertEquals ('transform[norm[0]] ' , $ this -> field ->getDisplayedData ());
379
+ $ this ->assertEquals (0 , $ field ->getData ());
380
+ $ this ->assertEquals ('norm[0] ' , $ field ->getNormalizedData ());
381
+ $ this ->assertEquals ('transform[norm[0]] ' , $ field ->getDisplayedData ());
370
382
}
371
383
372
384
public function testBoundValuesAreTrimmedBeforeTransforming ()
@@ -378,16 +390,20 @@ public function testBoundValuesAreTrimmedBeforeTransforming()
378
390
->with ($ this ->identicalTo ('a ' ))
379
391
->will ($ this ->returnValue ('reverse[a] ' ));
380
392
381
- $ transformer ->expects ($ this ->once ( ))
393
+ $ transformer ->expects ($ this ->exactly ( 2 ))
382
394
->method ('transform ' )
383
- ->with ($ this ->identicalTo ('reverse[a] ' ))
395
+ // Impossible to test with PHPUnit because called twice
396
+ // ->with($this->identicalTo('reverse[a]'))
384
397
->will ($ this ->returnValue ('a ' ));
385
398
386
- $ this ->field ->setValueTransformer ($ transformer );
387
- $ this ->field ->bind (' a ' );
399
+ $ field = new TestField ('title ' , array (
400
+ 'value_transformer ' => $ transformer ,
401
+ ));
388
402
389
- $ this ->assertEquals ('a ' , $ this ->field ->getDisplayedData ());
390
- $ this ->assertEquals ('reverse[a] ' , $ this ->field ->getData ());
403
+ $ field ->bind (' a ' );
404
+
405
+ $ this ->assertEquals ('a ' , $ field ->getDisplayedData ());
406
+ $ this ->assertEquals ('reverse[a] ' , $ field ->getData ());
391
407
}
392
408
393
409
public function testBoundValuesAreNotTrimmedBeforeTransformingIfDisabled ()
@@ -399,13 +415,17 @@ public function testBoundValuesAreNotTrimmedBeforeTransformingIfDisabled()
399
415
->with ($ this ->identicalTo (' a ' ))
400
416
->will ($ this ->returnValue ('reverse[ a ] ' ));
401
417
402
- $ transformer ->expects ($ this ->once ( ))
418
+ $ transformer ->expects ($ this ->exactly ( 2 ))
403
419
->method ('transform ' )
404
- ->with ($ this ->identicalTo ('reverse[ a ] ' ))
420
+ // Impossible to test with PHPUnit because called twice
421
+ // ->with($this->identicalTo('reverse[ a ]'))
405
422
->will ($ this ->returnValue (' a ' ));
406
423
407
- $ field = new TestField ('title ' , array ('trim ' => false ));
408
- $ field ->setValueTransformer ($ transformer );
424
+ $ field = new TestField ('title ' , array (
425
+ 'trim ' => false ,
426
+ 'value_transformer ' => $ transformer ,
427
+ ));
428
+
409
429
$ field ->bind (' a ' );
410
430
411
431
$ this ->assertEquals (' a ' , $ field ->getDisplayedData ());
0 commit comments