ParentNamePluginTest.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. protected function setUp()
  15. {
  16. $this->markTestSkipped('Move me to Type tests');
  17. }
  18. public function testSetUpHasParent()
  19. {
  20. $parentRenderer = $this->getMock('Symfony\Component\Form\Renderer\FormRendererInterface');
  21. $parentRenderer->expects($this->once())
  22. ->method('getVar')
  23. ->will($this->returnValue("parentName"));
  24. $parentField = $this->getMock('Symfony\Tests\Component\Form\FormInterface');
  25. $parentField->expects($this->once())
  26. ->method('getRenderer')
  27. ->will($this->returnValue($parentRenderer));
  28. $form = $this->getMock('Symfony\Tests\Component\Form\FormInterface');
  29. $form->expects($this->once())
  30. ->method('getParent')
  31. ->will($this->returnValue($parentField));
  32. $form->expects($this->once())
  33. ->method('hasParent')
  34. ->will($this->returnValue(true));
  35. $renderer = $this->getMock('Symfony\Component\Form\Renderer\FormRendererInterface');
  36. $renderer->expects($this->once())
  37. ->method('setVar')
  38. ->with($this->equalTo('name'), $this->equalTo('parentName'));
  39. $plugin = new ParentNamePlugin();
  40. $plugin->setUp($form, $renderer);
  41. }
  42. public function testSetUpNoParent()
  43. {
  44. $form = $this->getMock('Symfony\Tests\Component\Form\FormInterface');
  45. $form->expects($this->never())
  46. ->method('getParent');
  47. $form->expects($this->once())
  48. ->method('hasParent')
  49. ->will($this->returnValue(false));
  50. $renderer = $this->getMock('Symfony\Component\Form\Renderer\FormRendererInterface');
  51. $renderer->expects($this->never())
  52. ->method('setVar');
  53. $plugin = new ParentNamePlugin();
  54. $plugin->setUp($form, $renderer);
  55. }
  56. }