FormTest.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Tests\Component\Form;
  11. use Symfony\Component\Form\Form;
  12. use Symfony\Component\Form\FormBuilder;
  13. use Symfony\Component\Form\FormError;
  14. class FormTest extends \PHPUnit_Framework_TestCase
  15. {
  16. private $dispatcher;
  17. private $builder;
  18. private $form;
  19. protected function setUp()
  20. {
  21. $this->dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
  22. $this->builder = new FormBuilder($this->dispatcher);
  23. $this->form = $this->builder->getForm();
  24. }
  25. public function testErrorsBubbleUpIfEnabled()
  26. {
  27. $error = new FormError('Error!');
  28. $parent = $this->form;
  29. $form = $this->builder->setErrorBubbling(true)->getForm();
  30. $form->setParent($parent);
  31. $form->addError($error);
  32. $this->assertEquals(array(), $form->getErrors());
  33. $this->assertEquals(array($error), $parent->getErrors());
  34. }
  35. public function testErrorsDontBubbleUpIfDisabled()
  36. {
  37. $error = new FormError('Error!');
  38. $parent = $this->form;
  39. $form = $this->builder->setErrorBubbling(false)->getForm();
  40. $form->setParent($parent);
  41. $form->addError($error);
  42. $this->assertEquals(array($error), $form->getErrors());
  43. $this->assertEquals(array(), $parent->getErrors());
  44. }
  45. }