]> git.immae.eu Git - github/wallabag/wallabag.git/blob - vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/ChoiceList/LazyChoiceListTest.php
twig implementation
[github/wallabag/wallabag.git] / vendor / symfony / form / Symfony / Component / Form / Tests / Extension / Core / ChoiceList / LazyChoiceListTest.php
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace Symfony\Component\Form\Tests\Extension\Core\ChoiceList;
13
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;
17
18 class LazyChoiceListTest extends \PHPUnit_Framework_TestCase
19 {
20 private $list;
21
22 protected function setUp()
23 {
24 parent::setUp();
25
26 $this->list = new LazyChoiceListTest_Impl(new SimpleChoiceList(array(
27 'a' => 'A',
28 'b' => 'B',
29 'c' => 'C',
30 ), array('b')));
31 }
32
33 protected function tearDown()
34 {
35 parent::tearDown();
36
37 $this->list = null;
38 }
39
40 public function testGetChoices()
41 {
42 $this->assertSame(array(0 => 'a', 1 => 'b', 2 => 'c'), $this->list->getChoices());
43 }
44
45 public function testGetValues()
46 {
47 $this->assertSame(array(0 => 'a', 1 => 'b', 2 => 'c'), $this->list->getValues());
48 }
49
50 public function testGetPreferredViews()
51 {
52 $this->assertEquals(array(1 => new ChoiceView('b', 'b', 'B')), $this->list->getPreferredViews());
53 }
54
55 public function testGetRemainingViews()
56 {
57 $this->assertEquals(array(0 => new ChoiceView('a', 'a', 'A'), 2 => new ChoiceView('c', 'c', 'C')), $this->list->getRemainingViews());
58 }
59
60 public function testGetIndicesForChoices()
61 {
62 $choices = array('b', 'c');
63 $this->assertSame(array(1, 2), $this->list->getIndicesForChoices($choices));
64 }
65
66 public function testGetIndicesForValues()
67 {
68 $values = array('b', 'c');
69 $this->assertSame(array(1, 2), $this->list->getIndicesForValues($values));
70 }
71
72 public function testGetChoicesForValues()
73 {
74 $values = array('b', 'c');
75 $this->assertSame(array('b', 'c'), $this->list->getChoicesForValues($values));
76 }
77
78 public function testGetValuesForChoices()
79 {
80 $choices = array('b', 'c');
81 $this->assertSame(array('b', 'c'), $this->list->getValuesForChoices($choices));
82 }
83
84 /**
85 * @expectedException \Symfony\Component\Form\Exception\InvalidArgumentException
86 */
87 public function testLoadChoiceListShouldReturnChoiceList()
88 {
89 $list = new LazyChoiceListTest_InvalidImpl();
90
91 $list->getChoices();
92 }
93 }
94
95 class LazyChoiceListTest_Impl extends LazyChoiceList
96 {
97 private $choiceList;
98
99 public function __construct($choiceList)
100 {
101 $this->choiceList = $choiceList;
102 }
103
104 protected function loadChoiceList()
105 {
106 return $this->choiceList;
107 }
108 }
109
110 class LazyChoiceListTest_InvalidImpl extends LazyChoiceList
111 {
112 protected function loadChoiceList()
113 {
114 return new \stdClass();
115 }
116 }