|
13 | 13 |
|
14 | 14 | use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
|
15 | 15 | use Symfony\Component\DependencyInjection\Container;
|
| 16 | +use Symfony\Component\Form\FormInterface; |
16 | 17 | use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
17 | 18 | use Symfony\Component\HttpFoundation\File\File;
|
18 | 19 | use Symfony\Component\HttpFoundation\JsonResponse;
|
@@ -517,6 +518,77 @@ public function testCreateFormBuilder()
|
517 | 518 | $this->assertEquals($formBuilder, $controller->createFormBuilder('foo'));
|
518 | 519 | }
|
519 | 520 |
|
| 521 | + public function testIsFormValidWhenInvalid() |
| 522 | + { |
| 523 | + $requestStack = new RequestStack(); |
| 524 | + $requestStack->push($request = new Request()); |
| 525 | + |
| 526 | + $container = new Container(); |
| 527 | + $container->set('request_stack', $requestStack); |
| 528 | + |
| 529 | + $controller = $this->createController(); |
| 530 | + $controller->setContainer($container); |
| 531 | + |
| 532 | + $form = $this->getMockBuilder('Symfony\Component\Form\FormInterface')->getMock(); |
| 533 | + $form |
| 534 | + ->expects($this->once()) |
| 535 | + ->method('handleRequest') |
| 536 | + ->with($request) |
| 537 | + ->willReturn($form) |
| 538 | + ; |
| 539 | + |
| 540 | + $this->assertFalse($controller->isFormValid($form)); |
| 541 | + } |
| 542 | + |
| 543 | + public function testIsFormValidWhenValid() |
| 544 | + { |
| 545 | + $requestStack = new RequestStack(); |
| 546 | + $requestStack->push($request = new Request()); |
| 547 | + |
| 548 | + $container = new Container(); |
| 549 | + $container->set('request_stack', $requestStack); |
| 550 | + |
| 551 | + $controller = $this->createController(); |
| 552 | + $controller->setContainer($container); |
| 553 | + |
| 554 | + $form = $this->getMockBuilder('Symfony\Component\Form\FormInterface')->getMock(); |
| 555 | + $form |
| 556 | + ->expects($this->once()) |
| 557 | + ->method('handleRequest') |
| 558 | + ->with($request) |
| 559 | + ->willReturn($form) |
| 560 | + ; |
| 561 | + $form |
| 562 | + ->expects($this->once()) |
| 563 | + ->method('isSubmitted') |
| 564 | + ->willReturn(true) |
| 565 | + ; |
| 566 | + $form |
| 567 | + ->expects($this->once()) |
| 568 | + ->method('isValid') |
| 569 | + ->willReturn(true) |
| 570 | + ; |
| 571 | + |
| 572 | + $this->assertTrue($controller->isFormValid($form)); |
| 573 | + } |
| 574 | + |
| 575 | + /** |
| 576 | + * @expectedException \LogicException |
| 577 | + * @expectedExceptionMessage You must pass a request as second argument because the request stack was empty. |
| 578 | + */ |
| 579 | + public function testIsFormValidWhenRequestStackIsEmpty() |
| 580 | + { |
| 581 | + $container = new Container(); |
| 582 | + $container->set('request_stack', new RequestStack()); |
| 583 | + |
| 584 | + $controller = $this->createController(); |
| 585 | + $controller->setContainer($container); |
| 586 | + |
| 587 | + $form = $this->getMockBuilder('Symfony\Component\Form\FormInterface')->getMock(); |
| 588 | + |
| 589 | + $this->assertTrue($controller->isFormValid($form)); |
| 590 | + } |
| 591 | + |
520 | 592 | public function testGetDoctrine()
|
521 | 593 | {
|
522 | 594 | $doctrine = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry')->getMock();
|
@@ -623,6 +695,11 @@ public function createFormBuilder($data = null, array $options = array())
|
623 | 695 | return parent::createFormBuilder($data, $options);
|
624 | 696 | }
|
625 | 697 |
|
| 698 | + public function isFormValid(FormInterface $form, Request $request = null) |
| 699 | + { |
| 700 | + return parent::isFormValid($form, $request); |
| 701 | + } |
| 702 | + |
626 | 703 | public function getDoctrine()
|
627 | 704 | {
|
628 | 705 | return parent::getDoctrine();
|
|
0 commit comments