ParentNamePluginTest.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien.potencier@symfony-project.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\Renderer\Plugin;
  11. use Symfony\Component\Form\Renderer\Plugin\ParentNamePlugin;
  12. class ParentNamePluginTest extends \PHPUnit_Framework_TestCase
  13. {
  14. public function testSetUpHasParent()
  15. {
  16. $parentRenderer = $this->getMock('Symfony\Component\Form\Renderer\FormRendererInterface');
  17. $parentRenderer->expects($this->once())
  18. ->method('getVar')
  19. ->will($this->returnValue("parentName"));
  20. $parentField = $this->getMock('Symfony\Tests\Component\Form\FormInterface');
  21. $parentField->expects($this->once())
  22. ->method('getRenderer')
  23. ->will($this->returnValue($parentRenderer));
  24. $form = $this->getMock('Symfony\Tests\Component\Form\FormInterface');
  25. $form->expects($this->once())
  26. ->method('getParent')
  27. ->will($this->returnValue($parentField));
  28. $form->expects($this->once())
  29. ->method('hasParent')
  30. ->will($this->returnValue(true));
  31. $renderer = $this->getMock('Symfony\Component\Form\Renderer\FormRendererInterface');
  32. $renderer->expects($this->once())
  33. ->method('setVar')
  34. ->with($this->equalTo('name'), $this->equalTo('parentName'));
  35. $plugin = new ParentNamePlugin();
  36. $plugin->setUp($form, $renderer);
  37. }
  38. public function testSetUpNoParent()
  39. {
  40. $form = $this->getMock('Symfony\Tests\Component\Form\FormInterface');
  41. $form->expects($this->never())
  42. ->method('getParent');
  43. $form->expects($this->once())
  44. ->method('hasParent')
  45. ->will($this->returnValue(false));
  46. $renderer = $this->getMock('Symfony\Component\Form\Renderer\FormRendererInterface');
  47. $renderer->expects($this->never())
  48. ->method('setVar');
  49. $plugin = new ParentNamePlugin();
  50. $plugin->setUp($form, $renderer);
  51. }
  52. }