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/Type/CollectionTypeTest.php | |
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/Type/CollectionTypeTest.php')
-rw-r--r-- | vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/Type/CollectionTypeTest.php | 200 |
1 files changed, 0 insertions, 200 deletions
diff --git a/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/Type/CollectionTypeTest.php b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/Type/CollectionTypeTest.php deleted file mode 100644 index be3ad9db..00000000 --- a/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/Type/CollectionTypeTest.php +++ /dev/null | |||
@@ -1,200 +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\Type; | ||
13 | |||
14 | use Symfony\Component\Form\Form; | ||
15 | |||
16 | class CollectionTypeTest extends \Symfony\Component\Form\Test\TypeTestCase | ||
17 | { | ||
18 | public function testContainsNoChildByDefault() | ||
19 | { | ||
20 | $form = $this->factory->create('collection', null, array( | ||
21 | 'type' => 'text', | ||
22 | )); | ||
23 | |||
24 | $this->assertCount(0, $form); | ||
25 | } | ||
26 | |||
27 | public function testSetDataAdjustsSize() | ||
28 | { | ||
29 | $form = $this->factory->create('collection', null, array( | ||
30 | 'type' => 'text', | ||
31 | 'options' => array( | ||
32 | 'max_length' => 20, | ||
33 | ), | ||
34 | )); | ||
35 | $form->setData(array('foo@foo.com', 'foo@bar.com')); | ||
36 | |||
37 | $this->assertInstanceOf('Symfony\Component\Form\Form', $form[0]); | ||
38 | $this->assertInstanceOf('Symfony\Component\Form\Form', $form[1]); | ||
39 | $this->assertCount(2, $form); | ||
40 | $this->assertEquals('foo@foo.com', $form[0]->getData()); | ||
41 | $this->assertEquals('foo@bar.com', $form[1]->getData()); | ||
42 | $this->assertEquals(20, $form[0]->getConfig()->getOption('max_length')); | ||
43 | $this->assertEquals(20, $form[1]->getConfig()->getOption('max_length')); | ||
44 | |||
45 | $form->setData(array('foo@baz.com')); | ||
46 | $this->assertInstanceOf('Symfony\Component\Form\Form', $form[0]); | ||
47 | $this->assertFalse(isset($form[1])); | ||
48 | $this->assertCount(1, $form); | ||
49 | $this->assertEquals('foo@baz.com', $form[0]->getData()); | ||
50 | $this->assertEquals(20, $form[0]->getConfig()->getOption('max_length')); | ||
51 | } | ||
52 | |||
53 | public function testThrowsExceptionIfObjectIsNotTraversable() | ||
54 | { | ||
55 | $form = $this->factory->create('collection', null, array( | ||
56 | 'type' => 'text', | ||
57 | )); | ||
58 | $this->setExpectedException('Symfony\Component\Form\Exception\UnexpectedTypeException'); | ||
59 | $form->setData(new \stdClass()); | ||
60 | } | ||
61 | |||
62 | public function testNotResizedIfSubmittedWithMissingData() | ||
63 | { | ||
64 | $form = $this->factory->create('collection', null, array( | ||
65 | 'type' => 'text', | ||
66 | )); | ||
67 | $form->setData(array('foo@foo.com', 'bar@bar.com')); | ||
68 | $form->submit(array('foo@bar.com')); | ||
69 | |||
70 | $this->assertTrue($form->has('0')); | ||
71 | $this->assertTrue($form->has('1')); | ||
72 | $this->assertEquals('foo@bar.com', $form[0]->getData()); | ||
73 | $this->assertEquals('', $form[1]->getData()); | ||
74 | } | ||
75 | |||
76 | public function testResizedDownIfSubmittedWithMissingDataAndAllowDelete() | ||
77 | { | ||
78 | $form = $this->factory->create('collection', null, array( | ||
79 | 'type' => 'text', | ||
80 | 'allow_delete' => true, | ||
81 | )); | ||
82 | $form->setData(array('foo@foo.com', 'bar@bar.com')); | ||
83 | $form->submit(array('foo@foo.com')); | ||
84 | |||
85 | $this->assertTrue($form->has('0')); | ||
86 | $this->assertFalse($form->has('1')); | ||
87 | $this->assertEquals('foo@foo.com', $form[0]->getData()); | ||
88 | $this->assertEquals(array('foo@foo.com'), $form->getData()); | ||
89 | } | ||
90 | |||
91 | public function testNotResizedIfSubmittedWithExtraData() | ||
92 | { | ||
93 | $form = $this->factory->create('collection', null, array( | ||
94 | 'type' => 'text', | ||
95 | )); | ||
96 | $form->setData(array('foo@bar.com')); | ||
97 | $form->submit(array('foo@foo.com', 'bar@bar.com')); | ||
98 | |||
99 | $this->assertTrue($form->has('0')); | ||
100 | $this->assertFalse($form->has('1')); | ||
101 | $this->assertEquals('foo@foo.com', $form[0]->getData()); | ||
102 | } | ||
103 | |||
104 | public function testResizedUpIfSubmittedWithExtraDataAndAllowAdd() | ||
105 | { | ||
106 | $form = $this->factory->create('collection', null, array( | ||
107 | 'type' => 'text', | ||
108 | 'allow_add' => true, | ||
109 | )); | ||
110 | $form->setData(array('foo@bar.com')); | ||
111 | $form->submit(array('foo@bar.com', 'bar@bar.com')); | ||
112 | |||
113 | $this->assertTrue($form->has('0')); | ||
114 | $this->assertTrue($form->has('1')); | ||
115 | $this->assertEquals('foo@bar.com', $form[0]->getData()); | ||
116 | $this->assertEquals('bar@bar.com', $form[1]->getData()); | ||
117 | $this->assertEquals(array('foo@bar.com', 'bar@bar.com'), $form->getData()); | ||
118 | } | ||
119 | |||
120 | public function testAllowAddButNoPrototype() | ||
121 | { | ||
122 | $form = $this->factory->create('collection', null, array( | ||
123 | 'type' => 'form', | ||
124 | 'allow_add' => true, | ||
125 | 'prototype' => false, | ||
126 | )); | ||
127 | |||
128 | $this->assertFalse($form->has('__name__')); | ||
129 | } | ||
130 | |||
131 | public function testPrototypeMultipartPropagation() | ||
132 | { | ||
133 | $form = $this->factory | ||
134 | ->create('collection', null, array( | ||
135 | 'type' => 'file', | ||
136 | 'allow_add' => true, | ||
137 | 'prototype' => true, | ||
138 | )) | ||
139 | ; | ||
140 | |||
141 | $this->assertTrue($form->createView()->vars['multipart']); | ||
142 | } | ||
143 | |||
144 | public function testGetDataDoesNotContainsPrototypeNameBeforeDataAreSet() | ||
145 | { | ||
146 | $form = $this->factory->create('collection', array(), array( | ||
147 | 'type' => 'file', | ||
148 | 'prototype' => true, | ||
149 | 'allow_add' => true, | ||
150 | )); | ||
151 | |||
152 | $data = $form->getData(); | ||
153 | $this->assertFalse(isset($data['__name__'])); | ||
154 | } | ||
155 | |||
156 | public function testGetDataDoesNotContainsPrototypeNameAfterDataAreSet() | ||
157 | { | ||
158 | $form = $this->factory->create('collection', array(), array( | ||
159 | 'type' => 'file', | ||
160 | 'allow_add' => true, | ||
161 | 'prototype' => true, | ||
162 | )); | ||
163 | |||
164 | $form->setData(array('foobar.png')); | ||
165 | $data = $form->getData(); | ||
166 | $this->assertFalse(isset($data['__name__'])); | ||
167 | } | ||
168 | |||
169 | public function testPrototypeNameOption() | ||
170 | { | ||
171 | $form = $this->factory->create('collection', null, array( | ||
172 | 'type' => 'form', | ||
173 | 'prototype' => true, | ||
174 | 'allow_add' => true, | ||
175 | )); | ||
176 | |||
177 | $this->assertSame('__name__', $form->getConfig()->getAttribute('prototype')->getName(), '__name__ is the default'); | ||
178 | |||
179 | $form = $this->factory->create('collection', null, array( | ||
180 | 'type' => 'form', | ||
181 | 'prototype' => true, | ||
182 | 'allow_add' => true, | ||
183 | 'prototype_name' => '__test__', | ||
184 | )); | ||
185 | |||
186 | $this->assertSame('__test__', $form->getConfig()->getAttribute('prototype')->getName()); | ||
187 | } | ||
188 | |||
189 | public function testPrototypeDefaultLabel() | ||
190 | { | ||
191 | $form = $this->factory->create('collection', array(), array( | ||
192 | 'type' => 'file', | ||
193 | 'allow_add' => true, | ||
194 | 'prototype' => true, | ||
195 | 'prototype_name' => '__test__', | ||
196 | )); | ||
197 | |||
198 | $this->assertSame('__test__label__', $form->createView()->vars['prototype']->vars['label']); | ||
199 | } | ||
200 | } | ||