diff options
Diffstat (limited to 'vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/EventListener/FixRadioInputListenerTest.php')
-rw-r--r-- | vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/EventListener/FixRadioInputListenerTest.php | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/EventListener/FixRadioInputListenerTest.php b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/EventListener/FixRadioInputListenerTest.php new file mode 100644 index 00000000..a5d5c78a --- /dev/null +++ b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/EventListener/FixRadioInputListenerTest.php | |||
@@ -0,0 +1,106 @@ | |||
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\EventListener; | ||
13 | |||
14 | use Symfony\Component\Form\FormEvent; | ||
15 | use Symfony\Component\Form\Extension\Core\EventListener\FixRadioInputListener; | ||
16 | use Symfony\Component\Form\Extension\Core\ChoiceList\SimpleChoiceList; | ||
17 | |||
18 | class FixRadioInputListenerTest extends \PHPUnit_Framework_TestCase | ||
19 | { | ||
20 | private $choiceList; | ||
21 | |||
22 | protected function setUp() | ||
23 | { | ||
24 | if (!class_exists('Symfony\Component\EventDispatcher\EventDispatcher')) { | ||
25 | $this->markTestSkipped('The "EventDispatcher" component is not available'); | ||
26 | } | ||
27 | |||
28 | parent::setUp(); | ||
29 | |||
30 | $this->choiceList = new SimpleChoiceList(array('' => 'Empty', 0 => 'A', 1 => 'B')); | ||
31 | } | ||
32 | |||
33 | protected function tearDown() | ||
34 | { | ||
35 | parent::tearDown(); | ||
36 | |||
37 | $listener = null; | ||
38 | } | ||
39 | |||
40 | public function testFixRadio() | ||
41 | { | ||
42 | $data = '1'; | ||
43 | $form = $this->getMock('Symfony\Component\Form\Test\FormInterface'); | ||
44 | $event = new FormEvent($form, $data); | ||
45 | |||
46 | $listener = new FixRadioInputListener($this->choiceList, true); | ||
47 | $listener->preSubmit($event); | ||
48 | |||
49 | // Indices in SimpleChoiceList are zero-based generated integers | ||
50 | $this->assertEquals(array(2 => '1'), $event->getData()); | ||
51 | } | ||
52 | |||
53 | public function testFixZero() | ||
54 | { | ||
55 | $data = '0'; | ||
56 | $form = $this->getMock('Symfony\Component\Form\Test\FormInterface'); | ||
57 | $event = new FormEvent($form, $data); | ||
58 | |||
59 | $listener = new FixRadioInputListener($this->choiceList, true); | ||
60 | $listener->preSubmit($event); | ||
61 | |||
62 | // Indices in SimpleChoiceList are zero-based generated integers | ||
63 | $this->assertEquals(array(1 => '0'), $event->getData()); | ||
64 | } | ||
65 | |||
66 | public function testFixEmptyString() | ||
67 | { | ||
68 | $data = ''; | ||
69 | $form = $this->getMock('Symfony\Component\Form\Test\FormInterface'); | ||
70 | $event = new FormEvent($form, $data); | ||
71 | |||
72 | $listener = new FixRadioInputListener($this->choiceList, true); | ||
73 | $listener->preSubmit($event); | ||
74 | |||
75 | // Indices in SimpleChoiceList are zero-based generated integers | ||
76 | $this->assertEquals(array(0 => ''), $event->getData()); | ||
77 | } | ||
78 | |||
79 | public function testConvertEmptyStringToPlaceholderIfNotFound() | ||
80 | { | ||
81 | $list = new SimpleChoiceList(array(0 => 'A', 1 => 'B')); | ||
82 | |||
83 | $data = ''; | ||
84 | $form = $this->getMock('Symfony\Component\Form\Test\FormInterface'); | ||
85 | $event = new FormEvent($form, $data); | ||
86 | |||
87 | $listener = new FixRadioInputListener($list, true); | ||
88 | $listener->preSubmit($event); | ||
89 | |||
90 | $this->assertEquals(array('placeholder' => ''), $event->getData()); | ||
91 | } | ||
92 | |||
93 | public function testDontConvertEmptyStringToPlaceholderIfNoPlaceholderUsed() | ||
94 | { | ||
95 | $list = new SimpleChoiceList(array(0 => 'A', 1 => 'B')); | ||
96 | |||
97 | $data = ''; | ||
98 | $form = $this->getMock('Symfony\Component\Form\Test\FormInterface'); | ||
99 | $event = new FormEvent($form, $data); | ||
100 | |||
101 | $listener = new FixRadioInputListener($list, false); | ||
102 | $listener->preSubmit($event); | ||
103 | |||
104 | $this->assertEquals(array(), $event->getData()); | ||
105 | } | ||
106 | } | ||