123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- <?php
- /*
- * This file is part of the Symfony package.
- *
- * (c) Fabien Potencier <fabien@symfony.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
- namespace Symfony\Tests\Component\Form\Renderer;
- use Symfony\Component\Form\Renderer\ThemeRenderer;
- class ThemeRendererTest extends \PHPUnit_Framework_TestCase
- {
- private $themeFactory;
- private $renderer;
- protected function setUp()
- {
- $this->themeFactory = $this->getMock('Symfony\Component\Form\Renderer\Theme\ThemeFactoryInterface');
- $this->renderer = new ThemeRenderer($this->themeFactory);
- }
- public function testArrayAccess()
- {
- $fields = array(
- 'foo' => $this->getMock('Symfony\Tests\Component\Form\FormInterface'),
- 'bar' => $this->getMock('Symfony\Tests\Component\Form\FormInterface'),
- );
- $this->renderer->setChildren($fields);
- $this->assertTrue(isset($this->renderer['foo']));
- $this->assertTrue(isset($this->renderer['bar']));
- $this->assertSame($fields['bar'], $this->renderer['bar']);
- }
- public function testIterator()
- {
- $fields = array(
- 'foo' => $this->getMock('Symfony\Tests\Component\Form\FormInterface'),
- 'bar' => $this->getMock('Symfony\Tests\Component\Form\FormInterface'),
- );
- $this->renderer->setChildren($fields);
- $this->assertFalse($this->renderer->isRendered());
- $this->assertEquals($fields, iterator_to_array($this->renderer));
- $this->assertTrue($this->renderer->isRendered());
- }
- public function considersEqualProvider()
- {
- return array(
- // the first argument given here must be a valid array key
- // = integers and non-integer strings
- array(0, '0'),
- array(0, false),
- array(1, true),
- );
- }
- public function considersUnequalProvider()
- {
- return array(
- // the first argument given here must be a valid array key
- // = integers and non-integer strings
- array(0, ''),
- array('', 0),
- array('', false),
- array('', '0'),
- );
- }
- /**
- * @dataProvider considersEqualProvider
- */
- public function testIsChoiceConsidersEqual($choice, $otherChoice)
- {
- $this->renderer->setVar('choices', array(
- $choice => 'foo',
- ));
- $this->renderer->setVar('value', $choice);
- $this->assertTrue($this->renderer->isChoiceSelected($choice));
- $this->assertTrue($this->renderer->isChoiceSelected($otherChoice));
- }
- /**
- * @dataProvider considersUnequalProvider
- */
- public function testIsChoiceConsidersUnequal($choice, $otherChoice)
- {
- $this->renderer->setVar('choices', array(
- $choice => 'foo',
- ));
- $this->renderer->setVar('value', $choice);
- $this->assertTrue($this->renderer->isChoiceSelected($choice));
- $this->assertFalse($this->renderer->isChoiceSelected($otherChoice));
- }
- }
|