diff options
author | Nicolas LÅ“uillet <nicolas.loeuillet@gmail.com> | 2013-08-04 17:50:34 +0200 |
---|---|---|
committer | Nicolas LÅ“uillet <nicolas.loeuillet@gmail.com> | 2013-08-04 17:50:34 +0200 |
commit | 46b77928f746a4231d064774b5b67fd892c7ce86 (patch) | |
tree | e3ea690b3f0def1744ddae758923cf92171ef985 /vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/EventListener | |
parent | 68abd9c71b1d2f7bb2e9d21819584d1d15005b25 (diff) | |
download | wallabag-46b77928f746a4231d064774b5b67fd892c7ce86.tar.gz wallabag-46b77928f746a4231d064774b5b67fd892c7ce86.tar.zst wallabag-46b77928f746a4231d064774b5b67fd892c7ce86.zip |
rm vendor
Diffstat (limited to 'vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/EventListener')
9 files changed, 0 insertions, 842 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 deleted file mode 100644 index a5d5c78a..00000000 --- a/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/EventListener/FixRadioInputListenerTest.php +++ /dev/null | |||
@@ -1,106 +0,0 @@ | |||
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 | } | ||
diff --git a/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/EventListener/FixUrlProtocolListenerTest.php b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/EventListener/FixUrlProtocolListenerTest.php deleted file mode 100644 index 2b84e4fd..00000000 --- a/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/EventListener/FixUrlProtocolListenerTest.php +++ /dev/null | |||
@@ -1,61 +0,0 @@ | |||
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\FixUrlProtocolListener; | ||
16 | |||
17 | class FixUrlProtocolListenerTest extends \PHPUnit_Framework_TestCase | ||
18 | { | ||
19 | protected function setUp() | ||
20 | { | ||
21 | if (!class_exists('Symfony\Component\EventDispatcher\EventDispatcher')) { | ||
22 | $this->markTestSkipped('The "EventDispatcher" component is not available'); | ||
23 | } | ||
24 | } | ||
25 | |||
26 | public function testFixHttpUrl() | ||
27 | { | ||
28 | $data = "www.symfony.com"; | ||
29 | $form = $this->getMock('Symfony\Component\Form\Test\FormInterface'); | ||
30 | $event = new FormEvent($form, $data); | ||
31 | |||
32 | $filter = new FixUrlProtocolListener('http'); | ||
33 | $filter->onSubmit($event); | ||
34 | |||
35 | $this->assertEquals('http://www.symfony.com', $event->getData()); | ||
36 | } | ||
37 | |||
38 | public function testSkipKnownUrl() | ||
39 | { | ||
40 | $data = "http://www.symfony.com"; | ||
41 | $form = $this->getMock('Symfony\Component\Form\Test\FormInterface'); | ||
42 | $event = new FormEvent($form, $data); | ||
43 | |||
44 | $filter = new FixUrlProtocolListener('http'); | ||
45 | $filter->onSubmit($event); | ||
46 | |||
47 | $this->assertEquals('http://www.symfony.com', $event->getData()); | ||
48 | } | ||
49 | |||
50 | public function testSkipOtherProtocol() | ||
51 | { | ||
52 | $data = "ftp://www.symfony.com"; | ||
53 | $form = $this->getMock('Symfony\Component\Form\Test\FormInterface'); | ||
54 | $event = new FormEvent($form, $data); | ||
55 | |||
56 | $filter = new FixUrlProtocolListener('http'); | ||
57 | $filter->onSubmit($event); | ||
58 | |||
59 | $this->assertEquals('ftp://www.symfony.com', $event->getData()); | ||
60 | } | ||
61 | } | ||
diff --git a/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/EventListener/Fixtures/randomhash b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/EventListener/Fixtures/randomhash deleted file mode 100644 index b636f4b8..00000000 --- a/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/EventListener/Fixtures/randomhash +++ /dev/null | |||
Binary files differ | |||
diff --git a/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/EventListener/MergeCollectionListenerArrayObjectTest.php b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/EventListener/MergeCollectionListenerArrayObjectTest.php deleted file mode 100644 index 6f46c9d7..00000000 --- a/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/EventListener/MergeCollectionListenerArrayObjectTest.php +++ /dev/null | |||
@@ -1,27 +0,0 @@ | |||
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\FormBuilder; | ||
15 | |||
16 | class MergeCollectionListenerArrayObjectTest extends MergeCollectionListenerTest | ||
17 | { | ||
18 | protected function getData(array $data) | ||
19 | { | ||
20 | return new \ArrayObject($data); | ||
21 | } | ||
22 | |||
23 | protected function getBuilder($name = 'name') | ||
24 | { | ||
25 | return new FormBuilder($name, '\ArrayObject', $this->dispatcher, $this->factory); | ||
26 | } | ||
27 | } | ||
diff --git a/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/EventListener/MergeCollectionListenerArrayTest.php b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/EventListener/MergeCollectionListenerArrayTest.php deleted file mode 100644 index c0f3d597..00000000 --- a/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/EventListener/MergeCollectionListenerArrayTest.php +++ /dev/null | |||
@@ -1,27 +0,0 @@ | |||
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\FormBuilder; | ||
15 | |||
16 | class MergeCollectionListenerArrayTest extends MergeCollectionListenerTest | ||
17 | { | ||
18 | protected function getData(array $data) | ||
19 | { | ||
20 | return $data; | ||
21 | } | ||
22 | |||
23 | protected function getBuilder($name = 'name') | ||
24 | { | ||
25 | return new FormBuilder($name, null, $this->dispatcher, $this->factory); | ||
26 | } | ||
27 | } | ||
diff --git a/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/EventListener/MergeCollectionListenerCustomArrayObjectTest.php b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/EventListener/MergeCollectionListenerCustomArrayObjectTest.php deleted file mode 100644 index 5eb6c7b9..00000000 --- a/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/EventListener/MergeCollectionListenerCustomArrayObjectTest.php +++ /dev/null | |||
@@ -1,28 +0,0 @@ | |||
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\Tests\Fixtures\CustomArrayObject; | ||
15 | use Symfony\Component\Form\FormBuilder; | ||
16 | |||
17 | class MergeCollectionListenerCustomArrayObjectTest extends MergeCollectionListenerTest | ||
18 | { | ||
19 | protected function getData(array $data) | ||
20 | { | ||
21 | return new CustomArrayObject($data); | ||
22 | } | ||
23 | |||
24 | protected function getBuilder($name = 'name') | ||
25 | { | ||
26 | return new FormBuilder($name, 'Symfony\Component\Form\Tests\Fixtures\CustomArrayObject', $this->dispatcher, $this->factory); | ||
27 | } | ||
28 | } | ||
diff --git a/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/EventListener/MergeCollectionListenerTest.php b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/EventListener/MergeCollectionListenerTest.php deleted file mode 100644 index dbd28c6b..00000000 --- a/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/EventListener/MergeCollectionListenerTest.php +++ /dev/null | |||
@@ -1,259 +0,0 @@ | |||
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\MergeCollectionListener; | ||
16 | |||
17 | abstract class MergeCollectionListenerTest extends \PHPUnit_Framework_TestCase | ||
18 | { | ||
19 | protected $dispatcher; | ||
20 | protected $factory; | ||
21 | protected $form; | ||
22 | |||
23 | protected function setUp() | ||
24 | { | ||
25 | if (!class_exists('Symfony\Component\EventDispatcher\EventDispatcher')) { | ||
26 | $this->markTestSkipped('The "EventDispatcher" component is not available'); | ||
27 | } | ||
28 | |||
29 | $this->dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface'); | ||
30 | $this->factory = $this->getMock('Symfony\Component\Form\FormFactoryInterface'); | ||
31 | $this->form = $this->getForm('axes'); | ||
32 | } | ||
33 | |||
34 | protected function tearDown() | ||
35 | { | ||
36 | $this->dispatcher = null; | ||
37 | $this->factory = null; | ||
38 | $this->form = null; | ||
39 | } | ||
40 | |||
41 | abstract protected function getBuilder($name = 'name'); | ||
42 | |||
43 | protected function getForm($name = 'name', $propertyPath = null) | ||
44 | { | ||
45 | $propertyPath = $propertyPath ?: $name; | ||
46 | |||
47 | return $this->getBuilder($name)->setAttribute('property_path', $propertyPath)->getForm(); | ||
48 | } | ||
49 | |||
50 | protected function getMockForm() | ||
51 | { | ||
52 | return $this->getMock('Symfony\Component\Form\Test\FormInterface'); | ||
53 | } | ||
54 | |||
55 | public function getBooleanMatrix1() | ||
56 | { | ||
57 | return array( | ||
58 | array(true), | ||
59 | array(false), | ||
60 | ); | ||
61 | } | ||
62 | |||
63 | public function getBooleanMatrix2() | ||
64 | { | ||
65 | return array( | ||
66 | array(true, true), | ||
67 | array(true, false), | ||
68 | array(false, true), | ||
69 | array(false, false), | ||
70 | ); | ||
71 | } | ||
72 | |||
73 | abstract protected function getData(array $data); | ||
74 | |||
75 | /** | ||
76 | * @dataProvider getBooleanMatrix1 | ||
77 | */ | ||
78 | public function testAddExtraEntriesIfAllowAdd($allowDelete) | ||
79 | { | ||
80 | $originalData = $this->getData(array(1 => 'second')); | ||
81 | $newData = $this->getData(array(0 => 'first', 1 => 'second', 2 => 'third')); | ||
82 | |||
83 | $listener = new MergeCollectionListener(true, $allowDelete); | ||
84 | |||
85 | $this->form->setData($originalData); | ||
86 | |||
87 | $event = new FormEvent($this->form, $newData); | ||
88 | $listener->onSubmit($event); | ||
89 | |||
90 | // The original object was modified | ||
91 | if (is_object($originalData)) { | ||
92 | $this->assertSame($originalData, $event->getData()); | ||
93 | } | ||
94 | |||
95 | // The original object matches the new object | ||
96 | $this->assertEquals($newData, $event->getData()); | ||
97 | } | ||
98 | |||
99 | /** | ||
100 | * @dataProvider getBooleanMatrix1 | ||
101 | */ | ||
102 | public function testAddExtraEntriesIfAllowAddDontOverwriteExistingIndices($allowDelete) | ||
103 | { | ||
104 | $originalData = $this->getData(array(1 => 'first')); | ||
105 | $newData = $this->getData(array(0 => 'first', 1 => 'second')); | ||
106 | |||
107 | $listener = new MergeCollectionListener(true, $allowDelete); | ||
108 | |||
109 | $this->form->setData($originalData); | ||
110 | |||
111 | $event = new FormEvent($this->form, $newData); | ||
112 | $listener->onSubmit($event); | ||
113 | |||
114 | // The original object was modified | ||
115 | if (is_object($originalData)) { | ||
116 | $this->assertSame($originalData, $event->getData()); | ||
117 | } | ||
118 | |||
119 | // The original object matches the new object | ||
120 | $this->assertEquals($this->getData(array(1 => 'first', 2 => 'second')), $event->getData()); | ||
121 | } | ||
122 | |||
123 | /** | ||
124 | * @dataProvider getBooleanMatrix1 | ||
125 | */ | ||
126 | public function testDoNothingIfNotAllowAdd($allowDelete) | ||
127 | { | ||
128 | $originalDataArray = array(1 => 'second'); | ||
129 | $originalData = $this->getData($originalDataArray); | ||
130 | $newData = $this->getData(array(0 => 'first', 1 => 'second', 2 => 'third')); | ||
131 | |||
132 | $listener = new MergeCollectionListener(false, $allowDelete); | ||
133 | |||
134 | $this->form->setData($originalData); | ||
135 | |||
136 | $event = new FormEvent($this->form, $newData); | ||
137 | $listener->onSubmit($event); | ||
138 | |||
139 | // We still have the original object | ||
140 | if (is_object($originalData)) { | ||
141 | $this->assertSame($originalData, $event->getData()); | ||
142 | } | ||
143 | |||
144 | // Nothing was removed | ||
145 | $this->assertEquals($this->getData($originalDataArray), $event->getData()); | ||
146 | } | ||
147 | |||
148 | /** | ||
149 | * @dataProvider getBooleanMatrix1 | ||
150 | */ | ||
151 | public function testRemoveMissingEntriesIfAllowDelete($allowAdd) | ||
152 | { | ||
153 | $originalData = $this->getData(array(0 => 'first', 1 => 'second', 2 => 'third')); | ||
154 | $newData = $this->getData(array(1 => 'second')); | ||
155 | |||
156 | $listener = new MergeCollectionListener($allowAdd, true); | ||
157 | |||
158 | $this->form->setData($originalData); | ||
159 | |||
160 | $event = new FormEvent($this->form, $newData); | ||
161 | $listener->onSubmit($event); | ||
162 | |||
163 | // The original object was modified | ||
164 | if (is_object($originalData)) { | ||
165 | $this->assertSame($originalData, $event->getData()); | ||
166 | } | ||
167 | |||
168 | // The original object matches the new object | ||
169 | $this->assertEquals($newData, $event->getData()); | ||
170 | } | ||
171 | |||
172 | /** | ||
173 | * @dataProvider getBooleanMatrix1 | ||
174 | */ | ||
175 | public function testDoNothingIfNotAllowDelete($allowAdd) | ||
176 | { | ||
177 | $originalDataArray = array(0 => 'first', 1 => 'second', 2 => 'third'); | ||
178 | $originalData = $this->getData($originalDataArray); | ||
179 | $newData = $this->getData(array(1 => 'second')); | ||
180 | |||
181 | $listener = new MergeCollectionListener($allowAdd, false); | ||
182 | |||
183 | $this->form->setData($originalData); | ||
184 | |||
185 | $event = new FormEvent($this->form, $newData); | ||
186 | $listener->onSubmit($event); | ||
187 | |||
188 | // We still have the original object | ||
189 | if (is_object($originalData)) { | ||
190 | $this->assertSame($originalData, $event->getData()); | ||
191 | } | ||
192 | |||
193 | // Nothing was removed | ||
194 | $this->assertEquals($this->getData($originalDataArray), $event->getData()); | ||
195 | } | ||
196 | |||
197 | /** | ||
198 | * @dataProvider getBooleanMatrix2 | ||
199 | * @expectedException \Symfony\Component\Form\Exception\UnexpectedTypeException | ||
200 | */ | ||
201 | public function testRequireArrayOrTraversable($allowAdd, $allowDelete) | ||
202 | { | ||
203 | $newData = 'no array or traversable'; | ||
204 | $event = new FormEvent($this->form, $newData); | ||
205 | $listener = new MergeCollectionListener($allowAdd, $allowDelete); | ||
206 | $listener->onSubmit($event); | ||
207 | } | ||
208 | |||
209 | public function testDealWithNullData() | ||
210 | { | ||
211 | $originalData = $this->getData(array(0 => 'first', 1 => 'second', 2 => 'third')); | ||
212 | $newData = null; | ||
213 | |||
214 | $listener = new MergeCollectionListener(false, false); | ||
215 | |||
216 | $this->form->setData($originalData); | ||
217 | |||
218 | $event = new FormEvent($this->form, $newData); | ||
219 | $listener->onSubmit($event); | ||
220 | |||
221 | $this->assertSame($originalData, $event->getData()); | ||
222 | } | ||
223 | |||
224 | /** | ||
225 | * @dataProvider getBooleanMatrix1 | ||
226 | */ | ||
227 | public function testDealWithNullOriginalDataIfAllowAdd($allowDelete) | ||
228 | { | ||
229 | $originalData = null; | ||
230 | $newData = $this->getData(array(0 => 'first', 1 => 'second', 2 => 'third')); | ||
231 | |||
232 | $listener = new MergeCollectionListener(true, $allowDelete); | ||
233 | |||
234 | $this->form->setData($originalData); | ||
235 | |||
236 | $event = new FormEvent($this->form, $newData); | ||
237 | $listener->onSubmit($event); | ||
238 | |||
239 | $this->assertSame($newData, $event->getData()); | ||
240 | } | ||
241 | |||
242 | /** | ||
243 | * @dataProvider getBooleanMatrix1 | ||
244 | */ | ||
245 | public function testDontDealWithNullOriginalDataIfNotAllowAdd($allowDelete) | ||
246 | { | ||
247 | $originalData = null; | ||
248 | $newData = $this->getData(array(0 => 'first', 1 => 'second', 2 => 'third')); | ||
249 | |||
250 | $listener = new MergeCollectionListener(false, $allowDelete); | ||
251 | |||
252 | $this->form->setData($originalData); | ||
253 | |||
254 | $event = new FormEvent($this->form, $newData); | ||
255 | $listener->onSubmit($event); | ||
256 | |||
257 | $this->assertNull($event->getData()); | ||
258 | } | ||
259 | } | ||
diff --git a/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/EventListener/ResizeFormListenerTest.php b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/EventListener/ResizeFormListenerTest.php deleted file mode 100644 index 1367b3ef..00000000 --- a/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/EventListener/ResizeFormListenerTest.php +++ /dev/null | |||
@@ -1,255 +0,0 @@ | |||
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\Extension\Core\EventListener\ResizeFormListener; | ||
15 | use Symfony\Component\Form\FormBuilder; | ||
16 | use Symfony\Component\Form\FormEvent; | ||
17 | |||
18 | class ResizeFormListenerTest extends \PHPUnit_Framework_TestCase | ||
19 | { | ||
20 | private $dispatcher; | ||
21 | private $factory; | ||
22 | private $form; | ||
23 | |||
24 | protected function setUp() | ||
25 | { | ||
26 | if (!class_exists('Symfony\Component\EventDispatcher\EventDispatcher')) { | ||
27 | $this->markTestSkipped('The "EventDispatcher" component is not available'); | ||
28 | } | ||
29 | |||
30 | $this->dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface'); | ||
31 | $this->factory = $this->getMock('Symfony\Component\Form\FormFactoryInterface'); | ||
32 | $this->form = $this->getBuilder() | ||
33 | ->setCompound(true) | ||
34 | ->setDataMapper($this->getDataMapper()) | ||
35 | ->getForm(); | ||
36 | } | ||
37 | |||
38 | protected function tearDown() | ||
39 | { | ||
40 | $this->dispatcher = null; | ||
41 | $this->factory = null; | ||
42 | $this->form = null; | ||
43 | } | ||
44 | |||
45 | protected function getBuilder($name = 'name') | ||
46 | { | ||
47 | return new FormBuilder($name, null, $this->dispatcher, $this->factory); | ||
48 | } | ||
49 | |||
50 | protected function getForm($name = 'name') | ||
51 | { | ||
52 | return $this->getBuilder($name)->getForm(); | ||
53 | } | ||
54 | |||
55 | /** | ||
56 | * @return \PHPUnit_Framework_MockObject_MockObject | ||
57 | */ | ||
58 | private function getDataMapper() | ||
59 | { | ||
60 | return $this->getMock('Symfony\Component\Form\DataMapperInterface'); | ||
61 | } | ||
62 | |||
63 | protected function getMockForm() | ||
64 | { | ||
65 | return $this->getMock('Symfony\Component\Form\Test\FormInterface'); | ||
66 | } | ||
67 | |||
68 | public function testPreSetDataResizesForm() | ||
69 | { | ||
70 | $this->form->add($this->getForm('0')); | ||
71 | $this->form->add($this->getForm('1')); | ||
72 | |||
73 | $this->factory->expects($this->at(0)) | ||
74 | ->method('createNamed') | ||
75 | ->with(1, 'text', null, array('property_path' => '[1]', 'max_length' => 10, 'auto_initialize' => false)) | ||
76 | ->will($this->returnValue($this->getForm('1'))); | ||
77 | $this->factory->expects($this->at(1)) | ||
78 | ->method('createNamed') | ||
79 | ->with(2, 'text', null, array('property_path' => '[2]', 'max_length' => 10, 'auto_initialize' => false)) | ||
80 | ->will($this->returnValue($this->getForm('2'))); | ||
81 | |||
82 | $data = array(1 => 'string', 2 => 'string'); | ||
83 | $event = new FormEvent($this->form, $data); | ||
84 | $listener = new ResizeFormListener('text', array('max_length' => '10'), false, false); | ||
85 | $listener->preSetData($event); | ||
86 | |||
87 | $this->assertFalse($this->form->has('0')); | ||
88 | $this->assertTrue($this->form->has('1')); | ||
89 | $this->assertTrue($this->form->has('2')); | ||
90 | } | ||
91 | |||
92 | /** | ||
93 | * @expectedException \Symfony\Component\Form\Exception\UnexpectedTypeException | ||
94 | */ | ||
95 | public function testPreSetDataRequiresArrayOrTraversable() | ||
96 | { | ||
97 | $data = 'no array or traversable'; | ||
98 | $event = new FormEvent($this->form, $data); | ||
99 | $listener = new ResizeFormListener('text', array(), false, false); | ||
100 | $listener->preSetData($event); | ||
101 | } | ||
102 | |||
103 | public function testPreSetDataDealsWithNullData() | ||
104 | { | ||
105 | $this->factory->expects($this->never())->method('createNamed'); | ||
106 | |||
107 | $data = null; | ||
108 | $event = new FormEvent($this->form, $data); | ||
109 | $listener = new ResizeFormListener('text', array(), false, false); | ||
110 | $listener->preSetData($event); | ||
111 | } | ||
112 | |||
113 | public function testPreSubmitResizesUpIfAllowAdd() | ||
114 | { | ||
115 | $this->form->add($this->getForm('0')); | ||
116 | |||
117 | $this->factory->expects($this->once()) | ||
118 | ->method('createNamed') | ||
119 | ->with(1, 'text', null, array('property_path' => '[1]', 'max_length' => 10, 'auto_initialize' => false)) | ||
120 | ->will($this->returnValue($this->getForm('1'))); | ||
121 | |||
122 | $data = array(0 => 'string', 1 => 'string'); | ||
123 | $event = new FormEvent($this->form, $data); | ||
124 | $listener = new ResizeFormListener('text', array('max_length' => 10), true, false); | ||
125 | $listener->preSubmit($event); | ||
126 | |||
127 | $this->assertTrue($this->form->has('0')); | ||
128 | $this->assertTrue($this->form->has('1')); | ||
129 | } | ||
130 | |||
131 | public function testPreSubmitResizesDownIfAllowDelete() | ||
132 | { | ||
133 | $this->form->add($this->getForm('0')); | ||
134 | $this->form->add($this->getForm('1')); | ||
135 | |||
136 | $data = array(0 => 'string'); | ||
137 | $event = new FormEvent($this->form, $data); | ||
138 | $listener = new ResizeFormListener('text', array(), false, true); | ||
139 | $listener->preSubmit($event); | ||
140 | |||
141 | $this->assertTrue($this->form->has('0')); | ||
142 | $this->assertFalse($this->form->has('1')); | ||
143 | } | ||
144 | |||
145 | // fix for https://github.com/symfony/symfony/pull/493 | ||
146 | public function testPreSubmitRemovesZeroKeys() | ||
147 | { | ||
148 | $this->form->add($this->getForm('0')); | ||
149 | |||
150 | $data = array(); | ||
151 | $event = new FormEvent($this->form, $data); | ||
152 | $listener = new ResizeFormListener('text', array(), false, true); | ||
153 | $listener->preSubmit($event); | ||
154 | |||
155 | $this->assertFalse($this->form->has('0')); | ||
156 | } | ||
157 | |||
158 | public function testPreSubmitDoesNothingIfNotAllowAddNorAllowDelete() | ||
159 | { | ||
160 | $this->form->add($this->getForm('0')); | ||
161 | $this->form->add($this->getForm('1')); | ||
162 | |||
163 | $data = array(0 => 'string', 2 => 'string'); | ||
164 | $event = new FormEvent($this->form, $data); | ||
165 | $listener = new ResizeFormListener('text', array(), false, false); | ||
166 | $listener->preSubmit($event); | ||
167 | |||
168 | $this->assertTrue($this->form->has('0')); | ||
169 | $this->assertTrue($this->form->has('1')); | ||
170 | $this->assertFalse($this->form->has('2')); | ||
171 | } | ||
172 | |||
173 | /** | ||
174 | * @expectedException \Symfony\Component\Form\Exception\UnexpectedTypeException | ||
175 | */ | ||
176 | public function testPreSubmitRequiresArrayOrTraversable() | ||
177 | { | ||
178 | $data = 'no array or traversable'; | ||
179 | $event = new FormEvent($this->form, $data); | ||
180 | $listener = new ResizeFormListener('text', array(), false, false); | ||
181 | $listener->preSubmit($event); | ||
182 | } | ||
183 | |||
184 | public function testPreSubmitDealsWithNullData() | ||
185 | { | ||
186 | $this->form->add($this->getForm('1')); | ||
187 | |||
188 | $data = null; | ||
189 | $event = new FormEvent($this->form, $data); | ||
190 | $listener = new ResizeFormListener('text', array(), false, true); | ||
191 | $listener->preSubmit($event); | ||
192 | |||
193 | $this->assertFalse($this->form->has('1')); | ||
194 | } | ||
195 | |||
196 | // fixes https://github.com/symfony/symfony/pull/40 | ||
197 | public function testPreSubmitDealsWithEmptyData() | ||
198 | { | ||
199 | $this->form->add($this->getForm('1')); | ||
200 | |||
201 | $data = ''; | ||
202 | $event = new FormEvent($this->form, $data); | ||
203 | $listener = new ResizeFormListener('text', array(), false, true); | ||
204 | $listener->preSubmit($event); | ||
205 | |||
206 | $this->assertFalse($this->form->has('1')); | ||
207 | } | ||
208 | |||
209 | public function testOnSubmitNormDataRemovesEntriesMissingInTheFormIfAllowDelete() | ||
210 | { | ||
211 | $this->form->add($this->getForm('1')); | ||
212 | |||
213 | $data = array(0 => 'first', 1 => 'second', 2 => 'third'); | ||
214 | $event = new FormEvent($this->form, $data); | ||
215 | $listener = new ResizeFormListener('text', array(), false, true); | ||
216 | $listener->onSubmit($event); | ||
217 | |||
218 | $this->assertEquals(array(1 => 'second'), $event->getData()); | ||
219 | } | ||
220 | |||
221 | public function testOnSubmitNormDataDoesNothingIfNotAllowDelete() | ||
222 | { | ||
223 | $this->form->add($this->getForm('1')); | ||
224 | |||
225 | $data = array(0 => 'first', 1 => 'second', 2 => 'third'); | ||
226 | $event = new FormEvent($this->form, $data); | ||
227 | $listener = new ResizeFormListener('text', array(), false, false); | ||
228 | $listener->onSubmit($event); | ||
229 | |||
230 | $this->assertEquals($data, $event->getData()); | ||
231 | } | ||
232 | |||
233 | /** | ||
234 | * @expectedException \Symfony\Component\Form\Exception\UnexpectedTypeException | ||
235 | */ | ||
236 | public function testOnSubmitNormDataRequiresArrayOrTraversable() | ||
237 | { | ||
238 | $data = 'no array or traversable'; | ||
239 | $event = new FormEvent($this->form, $data); | ||
240 | $listener = new ResizeFormListener('text', array(), false, false); | ||
241 | $listener->onSubmit($event); | ||
242 | } | ||
243 | |||
244 | public function testOnSubmitNormDataDealsWithNullData() | ||
245 | { | ||
246 | $this->form->add($this->getForm('1')); | ||
247 | |||
248 | $data = null; | ||
249 | $event = new FormEvent($this->form, $data); | ||
250 | $listener = new ResizeFormListener('text', array(), false, true); | ||
251 | $listener->onSubmit($event); | ||
252 | |||
253 | $this->assertEquals(array(), $event->getData()); | ||
254 | } | ||
255 | } | ||
diff --git a/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/EventListener/TrimListenerTest.php b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/EventListener/TrimListenerTest.php deleted file mode 100644 index 4e368933..00000000 --- a/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/EventListener/TrimListenerTest.php +++ /dev/null | |||
@@ -1,79 +0,0 @@ | |||
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\TrimListener; | ||
16 | |||
17 | class TrimListenerTest extends \PHPUnit_Framework_TestCase | ||
18 | { | ||
19 | protected function setUp() | ||
20 | { | ||
21 | if (!class_exists('Symfony\Component\EventDispatcher\EventDispatcher')) { | ||
22 | $this->markTestSkipped('The "EventDispatcher" component is not available'); | ||
23 | } | ||
24 | } | ||
25 | |||
26 | public function testTrim() | ||
27 | { | ||
28 | $data = " Foo! "; | ||
29 | $form = $this->getMock('Symfony\Component\Form\Test\FormInterface'); | ||
30 | $event = new FormEvent($form, $data); | ||
31 | |||
32 | $filter = new TrimListener(); | ||
33 | $filter->preSubmit($event); | ||
34 | |||
35 | $this->assertEquals('Foo!', $event->getData()); | ||
36 | } | ||
37 | |||
38 | public function testTrimSkipNonStrings() | ||
39 | { | ||
40 | $data = 1234; | ||
41 | $form = $this->getMock('Symfony\Component\Form\Test\FormInterface'); | ||
42 | $event = new FormEvent($form, $data); | ||
43 | |||
44 | $filter = new TrimListener(); | ||
45 | $filter->preSubmit($event); | ||
46 | |||
47 | $this->assertSame(1234, $event->getData()); | ||
48 | } | ||
49 | |||
50 | /** | ||
51 | * @dataProvider codePointProvider | ||
52 | */ | ||
53 | public function testTrimUtf8($chars) | ||
54 | { | ||
55 | if (!function_exists('mb_check_encoding')) { | ||
56 | $this->markTestSkipped('The "mb_check_encoding" function is not available'); | ||
57 | } | ||
58 | |||
59 | $data = mb_convert_encoding(pack('H*', implode('', $chars)), 'UTF-8', 'UCS-2BE'); | ||
60 | $data = $data."ab\ncd".$data; | ||
61 | |||
62 | $form = $this->getMock('Symfony\Component\Form\Test\FormInterface'); | ||
63 | $event = new FormEvent($form, $data); | ||
64 | |||
65 | $filter = new TrimListener(); | ||
66 | $filter->preSubmit($event); | ||
67 | |||
68 | $this->assertSame("ab\ncd", $event->getData(), 'TrimListener should trim character(s): '.implode(', ', $chars)); | ||
69 | } | ||
70 | |||
71 | public function codePointProvider() | ||
72 | { | ||
73 | return array( | ||
74 | 'General category: Separator' => array(array('0020', '00A0', '1680', '180E', '2000', '2001', '2002', '2003', '2004', '2005', '2006', '2007', '2008', '2009', '200A', '2028', '2029', '202F', '205F', '3000')), | ||
75 | 'General category: Other, control' => array(array('0009', '000A', '000B', '000C', '000D', '0085')), | ||
76 | //'General category: Other, format. ZERO WIDTH SPACE' => array(array('200B')), | ||
77 | ); | ||
78 | } | ||
79 | } | ||