ThemeRendererTest.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. return $this->getMock('Symfony\Component\Form\Renderer\Theme\FormThemeFactoryInterface');
  17. }
  18. public function testArrayAccess()
  19. {
  20. $fields = array(
  21. 'foo' => $this->getMock('Symfony\Tests\Component\Form\FormInterface'),
  22. 'bar' => $this->getMock('Symfony\Tests\Component\Form\FormInterface'),
  23. );
  24. $themeFactory = $this->createThemeFactory();
  25. $renderer = new ThemeRenderer($themeFactory);
  26. $renderer->setChildren($fields);
  27. $this->assertTrue(isset($renderer['foo']));
  28. $this->assertTrue(isset($renderer['bar']));
  29. $this->assertSame($fields['bar'], $renderer['bar']);
  30. }
  31. public function testIterator()
  32. {
  33. $fields = array(
  34. 'foo' => $this->getMock('Symfony\Tests\Component\Form\FormInterface'),
  35. 'bar' => $this->getMock('Symfony\Tests\Component\Form\FormInterface'),
  36. );
  37. $themeFactory = $this->createThemeFactory();
  38. $renderer = new ThemeRenderer($themeFactory);
  39. $renderer->setChildren($fields);
  40. $this->assertFalse($renderer->isRendered());
  41. $this->assertEquals($fields, iterator_to_array($renderer));
  42. $this->assertTrue($renderer->isRendered());
  43. }
  44. }