ThemeRendererTest.php 1.8 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\Renderer;
  11. use Symfony\Component\Form\Renderer\ThemeRenderer;
  12. class ThemeRendererTest extends \PHPUnit_Framework_TestCase
  13. {
  14. protected function createThemeFactory()
  15. {
  16. $themeFactory = $this->getMock('Symfony\Component\Form\Renderer\Theme\FormThemeFactoryInterface');
  17. $themeFactory->expects($this->once())
  18. ->method('create')
  19. ->will($this->returnValue($this->getMock('Symfony\Component\Form\Renderer\Theme\FormThemeInterface')));
  20. return $themeFactory;
  21. }
  22. public function testArrayAccess()
  23. {
  24. $fields = array(
  25. 'foo' => $this->getMock('Symfony\Tests\Component\Form\FormInterface'),
  26. 'bar' => $this->getMock('Symfony\Tests\Component\Form\FormInterface'),
  27. );
  28. $themeFactory = $this->createThemeFactory();
  29. $renderer = new ThemeRenderer($themeFactory);
  30. $renderer->setChildren($fields);
  31. $this->assertTrue(isset($renderer['foo']));
  32. $this->assertTrue(isset($renderer['bar']));
  33. $this->assertSame($fields['bar'], $renderer['bar']);
  34. }
  35. public function testIterator()
  36. {
  37. $themeFactory = $this->createThemeFactory();
  38. $renderer = new ThemeRenderer($themeFactory);
  39. $renderer->setVar('fields', array('foo' => 'baz', 'bar' => 'baz'));
  40. $this->assertFalse($renderer->isRendered());
  41. foreach ($renderer AS $child) {
  42. $this->assertEquals('baz', $child);
  43. }
  44. $this->assertTrue($renderer->isRendered());
  45. }
  46. }