21
21
use Symfony \Component \Form \Form ;
22
22
use Symfony \Component \Form \FormBuilderInterface ;
23
23
use Symfony \Component \Form \FormConfigInterface ;
24
+ use Symfony \Component \Form \FormError ;
24
25
use Symfony \Component \Form \FormFactoryInterface ;
25
26
use Symfony \Component \Form \FormInterface ;
26
27
use Symfony \Component \HttpFoundation \BinaryFileResponse ;
@@ -411,6 +412,44 @@ public function testRenderTwig()
411
412
$ this ->assertEquals ('bar ' , $ controller ->render ('foo ' )->getContent ());
412
413
}
413
414
415
+ public function testRenderFormNew ()
416
+ {
417
+ $ twig = $ this ->createMock (Environment::class);
418
+ $ twig ->expects ($ this ->once ())->method ('render ' )->willReturn ('bar ' );
419
+
420
+ $ container = new Container ();
421
+ $ container ->set ('twig ' , $ twig );
422
+
423
+ $ controller = $ this ->createController ();
424
+ $ controller ->setContainer ($ container );
425
+ $ form = new Form ($ this ->createMock (FormConfigInterface::class));
426
+
427
+ $ response = $ controller ->renderForm ('foo ' , $ form );
428
+ $ this ->assertEquals (200 , $ response ->getStatusCode ());
429
+ $ this ->assertEquals ('bar ' , $ response ->getContent ());
430
+ }
431
+
432
+ public function testRenderFormSubmittedAndInvalid ()
433
+ {
434
+ $ twig = $ this ->createMock (Environment::class);
435
+ $ twig ->expects ($ this ->once ())->method ('render ' )->willReturn ('bar ' );
436
+
437
+ $ container = new Container ();
438
+ $ container ->set ('twig ' , $ twig );
439
+
440
+ $ controller = $ this ->createController ();
441
+ $ controller ->setContainer ($ container );
442
+ $ form = new Form ($ this ->createMock (FormConfigInterface::class));
443
+ $ formReflection = new \ReflectionProperty ($ form , 'submitted ' );
444
+ $ formReflection ->setAccessible (true );
445
+ $ formReflection ->setValue ($ form , true );
446
+ $ form ->addError (new FormError ('message ' ));
447
+
448
+ $ response = $ controller ->renderForm ('foo ' , $ form );
449
+ $ this ->assertEquals (422 , $ response ->getStatusCode ());
450
+ $ this ->assertEquals ('bar ' , $ response ->getContent ());
451
+ }
452
+
414
453
public function testStreamTwig ()
415
454
{
416
455
$ twig = $ this ->createMock (Environment::class);
@@ -424,6 +463,9 @@ public function testStreamTwig()
424
463
$ this ->assertInstanceOf (StreamedResponse::class, $ controller ->stream ('foo ' ));
425
464
}
426
465
466
+ /**
467
+ * @group legacy
468
+ */
427
469
public function testHandleFormNotSubmitted ()
428
470
{
429
471
$ form = $ this ->createMock (FormInterface::class);
@@ -445,6 +487,9 @@ function (FormInterface $form, $data): Response {
445
487
$ this ->assertSame ('rendered ' , $ response ->getContent ());
446
488
}
447
489
490
+ /**
491
+ * @group legacy
492
+ */
448
493
public function testHandleFormInvalid ()
449
494
{
450
495
$ form = $ this ->createMock (FormInterface::class);
@@ -467,6 +512,9 @@ function (FormInterface $form): Response {
467
512
$ this ->assertSame ('rendered ' , $ response ->getContent ());
468
513
}
469
514
515
+ /**
516
+ * @group legacy
517
+ */
470
518
public function testHandleFormValid ()
471
519
{
472
520
$ form = $ this ->createMock (FormInterface::class);
0 commit comments