4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Form\Tests\Extension\Core\ChoiceList
;
14 use Symfony\Component\Form\Extension\Core\ChoiceList\SimpleChoiceList
;
15 use Symfony\Component\Form\Extension\Core\ChoiceList\LazyChoiceList
;
16 use Symfony\Component\Form\Extension\Core\View\ChoiceView
;
18 class LazyChoiceListTest
extends \PHPUnit_Framework_TestCase
22 protected function setUp()
26 $this->list = new LazyChoiceListTest_Impl(new SimpleChoiceList(array(
33 protected function tearDown()
40 public function testGetChoices()
42 $this->assertSame(array(0 => 'a', 1 => 'b', 2 => 'c'), $this->list->getChoices());
45 public function testGetValues()
47 $this->assertSame(array(0 => 'a', 1 => 'b', 2 => 'c'), $this->list->getValues());
50 public function testGetPreferredViews()
52 $this->assertEquals(array(1 => new ChoiceView('b', 'b', 'B')), $this->list->getPreferredViews());
55 public function testGetRemainingViews()
57 $this->assertEquals(array(0 => new ChoiceView('a', 'a', 'A'), 2 => new ChoiceView('c', 'c', 'C')), $this->list->getRemainingViews());
60 public function testGetIndicesForChoices()
62 $choices = array('b', 'c');
63 $this->assertSame(array(1, 2), $this->list->getIndicesForChoices($choices));
66 public function testGetIndicesForValues()
68 $values = array('b', 'c');
69 $this->assertSame(array(1, 2), $this->list->getIndicesForValues($values));
72 public function testGetChoicesForValues()
74 $values = array('b', 'c');
75 $this->assertSame(array('b', 'c'), $this->list->getChoicesForValues($values));
78 public function testGetValuesForChoices()
80 $choices = array('b', 'c');
81 $this->assertSame(array('b', 'c'), $this->list->getValuesForChoices($choices));
85 * @expectedException \Symfony\Component\Form\Exception\InvalidArgumentException
87 public function testLoadChoiceListShouldReturnChoiceList()
89 $list = new LazyChoiceListTest_InvalidImpl();
95 class LazyChoiceListTest_Impl
extends LazyChoiceList
99 public function __construct($choiceList)
101 $this->choiceList
= $choiceList;
104 protected function loadChoiceList()
106 return $this->choiceList
;
110 class LazyChoiceListTest_InvalidImpl
extends LazyChoiceList
112 protected function loadChoiceList()
114 return new \
stdClass();