ThemeRendererTest.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. private $themeFactory;
  15. private $renderer;
  16. protected function setUp()
  17. {
  18. $this->themeFactory = $this->getMock('Symfony\Component\Form\Renderer\Theme\ThemeFactoryInterface');
  19. $this->renderer = new ThemeRenderer($this->themeFactory);
  20. }
  21. public function testArrayAccess()
  22. {
  23. $fields = array(
  24. 'foo' => $this->getMock('Symfony\Tests\Component\Form\FormInterface'),
  25. 'bar' => $this->getMock('Symfony\Tests\Component\Form\FormInterface'),
  26. );
  27. $this->renderer->setChildren($fields);
  28. $this->assertTrue(isset($this->renderer['foo']));
  29. $this->assertTrue(isset($this->renderer['bar']));
  30. $this->assertSame($fields['bar'], $this->renderer['bar']);
  31. }
  32. public function testIterator()
  33. {
  34. $fields = array(
  35. 'foo' => $this->getMock('Symfony\Tests\Component\Form\FormInterface'),
  36. 'bar' => $this->getMock('Symfony\Tests\Component\Form\FormInterface'),
  37. );
  38. $this->renderer->setChildren($fields);
  39. $this->assertFalse($this->renderer->isRendered());
  40. $this->assertEquals($fields, iterator_to_array($this->renderer));
  41. $this->assertTrue($this->renderer->isRendered());
  42. }
  43. public function considersEqualProvider()
  44. {
  45. return array(
  46. // the first argument given here must be a valid array key
  47. // = integers and non-integer strings
  48. array(0, '0'),
  49. array(0, false),
  50. array(1, true),
  51. );
  52. }
  53. public function considersUnequalProvider()
  54. {
  55. return array(
  56. // the first argument given here must be a valid array key
  57. // = integers and non-integer strings
  58. array(0, ''),
  59. array('', 0),
  60. array('', false),
  61. array('', '0'),
  62. );
  63. }
  64. /**
  65. * @dataProvider considersEqualProvider
  66. */
  67. public function testIsChoiceConsidersEqual($choice, $otherChoice)
  68. {
  69. $this->renderer->setVar('choices', array(
  70. $choice => 'foo',
  71. ));
  72. $this->renderer->setVar('value', $choice);
  73. $this->assertTrue($this->renderer->isChoiceSelected($choice));
  74. $this->assertTrue($this->renderer->isChoiceSelected($otherChoice));
  75. }
  76. /**
  77. * @dataProvider considersUnequalProvider
  78. */
  79. public function testIsChoiceConsidersUnequal($choice, $otherChoice)
  80. {
  81. $this->renderer->setVar('choices', array(
  82. $choice => 'foo',
  83. ));
  84. $this->renderer->setVar('value', $choice);
  85. $this->assertTrue($this->renderer->isChoiceSelected($choice));
  86. $this->assertFalse($this->renderer->isChoiceSelected($otherChoice));
  87. }
  88. }