diff options
Diffstat (limited to 'vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core')
54 files changed, 9105 insertions, 0 deletions
diff --git a/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/ChoiceList/ChoiceListTest.php b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/ChoiceList/ChoiceListTest.php new file mode 100644 index 00000000..63eae9bf --- /dev/null +++ b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/ChoiceList/ChoiceListTest.php | |||
@@ -0,0 +1,200 @@ | |||
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\ChoiceList; | ||
15 | use Symfony\Component\Form\Extension\Core\View\ChoiceView; | ||
16 | |||
17 | class ChoiceListTest extends \PHPUnit_Framework_TestCase | ||
18 | { | ||
19 | private $obj1; | ||
20 | |||
21 | private $obj2; | ||
22 | |||
23 | private $obj3; | ||
24 | |||
25 | private $obj4; | ||
26 | |||
27 | private $list; | ||
28 | |||
29 | protected function setUp() | ||
30 | { | ||
31 | parent::setUp(); | ||
32 | |||
33 | $this->obj1 = new \stdClass(); | ||
34 | $this->obj2 = new \stdClass(); | ||
35 | $this->obj3 = new \stdClass(); | ||
36 | $this->obj4 = new \stdClass(); | ||
37 | |||
38 | $this->list = new ChoiceList( | ||
39 | array( | ||
40 | 'Group 1' => array($this->obj1, $this->obj2), | ||
41 | 'Group 2' => array($this->obj3, $this->obj4), | ||
42 | ), | ||
43 | array( | ||
44 | 'Group 1' => array('A', 'B'), | ||
45 | 'Group 2' => array('C', 'D'), | ||
46 | ), | ||
47 | array($this->obj2, $this->obj3) | ||
48 | ); | ||
49 | } | ||
50 | |||
51 | protected function tearDown() | ||
52 | { | ||
53 | parent::tearDown(); | ||
54 | |||
55 | $this->obj1 = null; | ||
56 | $this->obj2 = null; | ||
57 | $this->obj3 = null; | ||
58 | $this->obj4 = null; | ||
59 | $this->list = null; | ||
60 | } | ||
61 | |||
62 | public function testInitArray() | ||
63 | { | ||
64 | $this->list = new ChoiceList( | ||
65 | array($this->obj1, $this->obj2, $this->obj3, $this->obj4), | ||
66 | array('A', 'B', 'C', 'D'), | ||
67 | array($this->obj2) | ||
68 | ); | ||
69 | |||
70 | $this->assertSame(array($this->obj1, $this->obj2, $this->obj3, $this->obj4), $this->list->getChoices()); | ||
71 | $this->assertSame(array('0', '1', '2', '3'), $this->list->getValues()); | ||
72 | $this->assertEquals(array(1 => new ChoiceView($this->obj2, '1', 'B')), $this->list->getPreferredViews()); | ||
73 | $this->assertEquals(array(0 => new ChoiceView($this->obj1, '0', 'A'), 2 => new ChoiceView($this->obj3, '2', 'C'), 3 => new ChoiceView($this->obj4, '3', 'D')), $this->list->getRemainingViews()); | ||
74 | } | ||
75 | |||
76 | /** | ||
77 | * Necessary for interoperability with MongoDB cursors or ORM relations as | ||
78 | * choices parameter. A choice itself that is an object implementing \Traversable | ||
79 | * is not treated as hierarchical structure, but as-is. | ||
80 | */ | ||
81 | public function testInitNestedTraversable() | ||
82 | { | ||
83 | $traversableChoice = new \ArrayIterator(array($this->obj3, $this->obj4)); | ||
84 | |||
85 | $this->list = new ChoiceList( | ||
86 | new \ArrayIterator(array( | ||
87 | 'Group' => array($this->obj1, $this->obj2), | ||
88 | 'Not a Group' => $traversableChoice | ||
89 | )), | ||
90 | array( | ||
91 | 'Group' => array('A', 'B'), | ||
92 | 'Not a Group' => 'C', | ||
93 | ), | ||
94 | array($this->obj2) | ||
95 | ); | ||
96 | |||
97 | $this->assertSame(array($this->obj1, $this->obj2, $traversableChoice), $this->list->getChoices()); | ||
98 | $this->assertSame(array('0', '1', '2'), $this->list->getValues()); | ||
99 | $this->assertEquals(array( | ||
100 | 'Group' => array(1 => new ChoiceView($this->obj2, '1', 'B')) | ||
101 | ), $this->list->getPreferredViews()); | ||
102 | $this->assertEquals(array( | ||
103 | 'Group' => array(0 => new ChoiceView($this->obj1, '0', 'A')), | ||
104 | 2 => new ChoiceView($traversableChoice, '2', 'C') | ||
105 | ), $this->list->getRemainingViews()); | ||
106 | } | ||
107 | |||
108 | public function testInitNestedArray() | ||
109 | { | ||
110 | $this->assertSame(array($this->obj1, $this->obj2, $this->obj3, $this->obj4), $this->list->getChoices()); | ||
111 | $this->assertSame(array('0', '1', '2', '3'), $this->list->getValues()); | ||
112 | $this->assertEquals(array( | ||
113 | 'Group 1' => array(1 => new ChoiceView($this->obj2, '1', 'B')), | ||
114 | 'Group 2' => array(2 => new ChoiceView($this->obj3, '2', 'C')) | ||
115 | ), $this->list->getPreferredViews()); | ||
116 | $this->assertEquals(array( | ||
117 | 'Group 1' => array(0 => new ChoiceView($this->obj1, '0', 'A')), | ||
118 | 'Group 2' => array(3 => new ChoiceView($this->obj4, '3', 'D')) | ||
119 | ), $this->list->getRemainingViews()); | ||
120 | } | ||
121 | |||
122 | public function testGetIndicesForChoices() | ||
123 | { | ||
124 | $choices = array($this->obj2, $this->obj3); | ||
125 | $this->assertSame(array(1, 2), $this->list->getIndicesForChoices($choices)); | ||
126 | } | ||
127 | |||
128 | public function testGetIndicesForChoicesIgnoresNonExistingChoices() | ||
129 | { | ||
130 | $choices = array($this->obj2, $this->obj3, 'foobar'); | ||
131 | $this->assertSame(array(1, 2), $this->list->getIndicesForChoices($choices)); | ||
132 | } | ||
133 | |||
134 | public function testGetIndicesForValues() | ||
135 | { | ||
136 | // values and indices are always the same | ||
137 | $values = array('1', '2'); | ||
138 | $this->assertSame(array(1, 2), $this->list->getIndicesForValues($values)); | ||
139 | } | ||
140 | |||
141 | public function testGetIndicesForValuesIgnoresNonExistingValues() | ||
142 | { | ||
143 | $values = array('1', '2', '5'); | ||
144 | $this->assertSame(array(1, 2), $this->list->getIndicesForValues($values)); | ||
145 | } | ||
146 | |||
147 | public function testGetChoicesForValues() | ||
148 | { | ||
149 | $values = array('1', '2'); | ||
150 | $this->assertSame(array($this->obj2, $this->obj3), $this->list->getChoicesForValues($values)); | ||
151 | } | ||
152 | |||
153 | public function testGetChoicesForValuesCorrectOrderingOfResult() | ||
154 | { | ||
155 | $values = array('2', '1'); | ||
156 | $this->assertSame(array($this->obj3, $this->obj2), $this->list->getChoicesForValues($values)); | ||
157 | } | ||
158 | |||
159 | public function testGetChoicesForValuesIgnoresNonExistingValues() | ||
160 | { | ||
161 | $values = array('1', '2', '5'); | ||
162 | $this->assertSame(array($this->obj2, $this->obj3), $this->list->getChoicesForValues($values)); | ||
163 | } | ||
164 | |||
165 | public function testGetValuesForChoices() | ||
166 | { | ||
167 | $choices = array($this->obj2, $this->obj3); | ||
168 | $this->assertSame(array('1', '2'), $this->list->getValuesForChoices($choices)); | ||
169 | } | ||
170 | |||
171 | public function testGetValuesForChoicesIgnoresNonExistingChoices() | ||
172 | { | ||
173 | $choices = array($this->obj2, $this->obj3, 'foobar'); | ||
174 | $this->assertSame(array('1', '2'), $this->list->getValuesForChoices($choices)); | ||
175 | } | ||
176 | |||
177 | /** | ||
178 | * @expectedException \InvalidArgumentException | ||
179 | */ | ||
180 | public function testNonMatchingLabels() | ||
181 | { | ||
182 | $this->list = new ChoiceList( | ||
183 | array($this->obj1, $this->obj2), | ||
184 | array('A') | ||
185 | ); | ||
186 | } | ||
187 | |||
188 | public function testLabelsContainingNull() | ||
189 | { | ||
190 | $this->list = new ChoiceList( | ||
191 | array($this->obj1, $this->obj2), | ||
192 | array('A', null) | ||
193 | ); | ||
194 | |||
195 | $this->assertEquals( | ||
196 | array(0 => new ChoiceView($this->obj1, '0', 'A'), 1 => new ChoiceView($this->obj2, '1', null)), | ||
197 | $this->list->getRemainingViews() | ||
198 | ); | ||
199 | } | ||
200 | } | ||
diff --git a/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/ChoiceList/LazyChoiceListTest.php b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/ChoiceList/LazyChoiceListTest.php new file mode 100644 index 00000000..bcd309e0 --- /dev/null +++ b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/ChoiceList/LazyChoiceListTest.php | |||
@@ -0,0 +1,116 @@ | |||
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 | } | ||
diff --git a/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/ChoiceList/ObjectChoiceListTest.php b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/ChoiceList/ObjectChoiceListTest.php new file mode 100644 index 00000000..69c5aa0f --- /dev/null +++ b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/ChoiceList/ObjectChoiceListTest.php | |||
@@ -0,0 +1,212 @@ | |||
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\ObjectChoiceList; | ||
15 | use Symfony\Component\Form\Extension\Core\View\ChoiceView; | ||
16 | |||
17 | class ObjectChoiceListTest_EntityWithToString | ||
18 | { | ||
19 | private $property; | ||
20 | |||
21 | public function __construct($property) | ||
22 | { | ||
23 | $this->property = $property; | ||
24 | } | ||
25 | |||
26 | public function __toString() | ||
27 | { | ||
28 | return $this->property; | ||
29 | } | ||
30 | } | ||
31 | |||
32 | class ObjectChoiceListTest extends \PHPUnit_Framework_TestCase | ||
33 | { | ||
34 | private $obj1; | ||
35 | |||
36 | private $obj2; | ||
37 | |||
38 | private $obj3; | ||
39 | |||
40 | private $obj4; | ||
41 | |||
42 | /** | ||
43 | * @var ObjectChoiceList | ||
44 | */ | ||
45 | private $list; | ||
46 | |||
47 | protected function setUp() | ||
48 | { | ||
49 | parent::setUp(); | ||
50 | |||
51 | $this->obj1 = (object) array('name' => 'A'); | ||
52 | $this->obj2 = (object) array('name' => 'B'); | ||
53 | $this->obj3 = (object) array('name' => 'C'); | ||
54 | $this->obj4 = (object) array('name' => 'D'); | ||
55 | |||
56 | $this->list = new ObjectChoiceList( | ||
57 | array( | ||
58 | 'Group 1' => array($this->obj1, $this->obj2), | ||
59 | 'Group 2' => array($this->obj3, $this->obj4), | ||
60 | ), | ||
61 | 'name', | ||
62 | array($this->obj2, $this->obj3) | ||
63 | ); | ||
64 | } | ||
65 | |||
66 | protected function tearDown() | ||
67 | { | ||
68 | parent::tearDown(); | ||
69 | |||
70 | $this->obj1 = null; | ||
71 | $this->obj2 = null; | ||
72 | $this->obj3 = null; | ||
73 | $this->obj4 = null; | ||
74 | $this->list = null; | ||
75 | } | ||
76 | |||
77 | public function testInitArray() | ||
78 | { | ||
79 | $this->list = new ObjectChoiceList( | ||
80 | array($this->obj1, $this->obj2, $this->obj3, $this->obj4), | ||
81 | 'name', | ||
82 | array($this->obj2) | ||
83 | ); | ||
84 | |||
85 | $this->assertSame(array($this->obj1, $this->obj2, $this->obj3, $this->obj4), $this->list->getChoices()); | ||
86 | $this->assertSame(array('0', '1', '2', '3'), $this->list->getValues()); | ||
87 | $this->assertEquals(array(1 => new ChoiceView($this->obj2, '1', 'B')), $this->list->getPreferredViews()); | ||
88 | $this->assertEquals(array(0 => new ChoiceView($this->obj1, '0', 'A'), 2 => new ChoiceView($this->obj3, '2', 'C'), 3 => new ChoiceView($this->obj4, '3', 'D')), $this->list->getRemainingViews()); | ||
89 | } | ||
90 | |||
91 | public function testInitNestedArray() | ||
92 | { | ||
93 | $this->assertSame(array($this->obj1, $this->obj2, $this->obj3, $this->obj4), $this->list->getChoices()); | ||
94 | $this->assertSame(array('0', '1', '2', '3'), $this->list->getValues()); | ||
95 | $this->assertEquals(array( | ||
96 | 'Group 1' => array(1 => new ChoiceView($this->obj2, '1', 'B')), | ||
97 | 'Group 2' => array(2 => new ChoiceView($this->obj3, '2', 'C')) | ||
98 | ), $this->list->getPreferredViews()); | ||
99 | $this->assertEquals(array( | ||
100 | 'Group 1' => array(0 => new ChoiceView($this->obj1, '0', 'A')), | ||
101 | 'Group 2' => array(3 => new ChoiceView($this->obj4, '3', 'D')) | ||
102 | ), $this->list->getRemainingViews()); | ||
103 | } | ||
104 | |||
105 | public function testInitArrayWithGroupPath() | ||
106 | { | ||
107 | $this->obj1 = (object) array('name' => 'A', 'category' => 'Group 1'); | ||
108 | $this->obj2 = (object) array('name' => 'B', 'category' => 'Group 1'); | ||
109 | $this->obj3 = (object) array('name' => 'C', 'category' => 'Group 2'); | ||
110 | $this->obj4 = (object) array('name' => 'D', 'category' => 'Group 2'); | ||
111 | |||
112 | // Objects with NULL groups are not grouped | ||
113 | $obj5 = (object) array('name' => 'E', 'category' => null); | ||
114 | |||
115 | // Objects without the group property are not grouped either | ||
116 | // see https://github.com/symfony/symfony/commit/d9b7abb7c7a0f28e0ce970afc5e305dce5dccddf | ||
117 | $obj6 = (object) array('name' => 'F'); | ||
118 | |||
119 | $this->list = new ObjectChoiceList( | ||
120 | array($this->obj1, $this->obj2, $this->obj3, $this->obj4, $obj5, $obj6), | ||
121 | 'name', | ||
122 | array($this->obj2, $this->obj3), | ||
123 | 'category' | ||
124 | ); | ||
125 | |||
126 | $this->assertSame(array($this->obj1, $this->obj2, $this->obj3, $this->obj4, $obj5, $obj6), $this->list->getChoices()); | ||
127 | $this->assertSame(array('0', '1', '2', '3', '4', '5'), $this->list->getValues()); | ||
128 | $this->assertEquals(array( | ||
129 | 'Group 1' => array(1 => new ChoiceView($this->obj2, '1', 'B')), | ||
130 | 'Group 2' => array(2 => new ChoiceView($this->obj3, '2', 'C')) | ||
131 | ), $this->list->getPreferredViews()); | ||
132 | $this->assertEquals(array( | ||
133 | 'Group 1' => array(0 => new ChoiceView($this->obj1, '0', 'A')), | ||
134 | 'Group 2' => array(3 => new ChoiceView($this->obj4, '3', 'D')), | ||
135 | 4 => new ChoiceView($obj5, '4', 'E'), | ||
136 | 5 => new ChoiceView($obj6, '5', 'F'), | ||
137 | ), $this->list->getRemainingViews()); | ||
138 | } | ||
139 | |||
140 | /** | ||
141 | * @expectedException \InvalidArgumentException | ||
142 | */ | ||
143 | public function testInitArrayWithGroupPathThrowsExceptionIfNestedArray() | ||
144 | { | ||
145 | $this->obj1 = (object) array('name' => 'A', 'category' => 'Group 1'); | ||
146 | $this->obj2 = (object) array('name' => 'B', 'category' => 'Group 1'); | ||
147 | $this->obj3 = (object) array('name' => 'C', 'category' => 'Group 2'); | ||
148 | $this->obj4 = (object) array('name' => 'D', 'category' => 'Group 2'); | ||
149 | |||
150 | new ObjectChoiceList( | ||
151 | array( | ||
152 | 'Group 1' => array($this->obj1, $this->obj2), | ||
153 | 'Group 2' => array($this->obj3, $this->obj4), | ||
154 | ), | ||
155 | 'name', | ||
156 | array($this->obj2, $this->obj3), | ||
157 | 'category' | ||
158 | ); | ||
159 | } | ||
160 | |||
161 | public function testInitArrayWithValuePath() | ||
162 | { | ||
163 | $this->obj1 = (object) array('name' => 'A', 'id' => 10); | ||
164 | $this->obj2 = (object) array('name' => 'B', 'id' => 20); | ||
165 | $this->obj3 = (object) array('name' => 'C', 'id' => 30); | ||
166 | $this->obj4 = (object) array('name' => 'D', 'id' => 40); | ||
167 | |||
168 | $this->list = new ObjectChoiceList( | ||
169 | array($this->obj1, $this->obj2, $this->obj3, $this->obj4), | ||
170 | 'name', | ||
171 | array($this->obj2, $this->obj3), | ||
172 | null, | ||
173 | 'id' | ||
174 | ); | ||
175 | |||
176 | $this->assertSame(array($this->obj1, $this->obj2, $this->obj3, $this->obj4), $this->list->getChoices()); | ||
177 | $this->assertSame(array('10', '20', '30', '40'), $this->list->getValues()); | ||
178 | $this->assertEquals(array(1 => new ChoiceView($this->obj2, '20', 'B'), 2 => new ChoiceView($this->obj3, '30', 'C')), $this->list->getPreferredViews()); | ||
179 | $this->assertEquals(array(0 => new ChoiceView($this->obj1, '10', 'A'), 3 => new ChoiceView($this->obj4, '40', 'D')), $this->list->getRemainingViews()); | ||
180 | } | ||
181 | |||
182 | public function testInitArrayUsesToString() | ||
183 | { | ||
184 | $this->obj1 = new ObjectChoiceListTest_EntityWithToString('A'); | ||
185 | $this->obj2 = new ObjectChoiceListTest_EntityWithToString('B'); | ||
186 | $this->obj3 = new ObjectChoiceListTest_EntityWithToString('C'); | ||
187 | $this->obj4 = new ObjectChoiceListTest_EntityWithToString('D'); | ||
188 | |||
189 | $this->list = new ObjectChoiceList( | ||
190 | array($this->obj1, $this->obj2, $this->obj3, $this->obj4) | ||
191 | ); | ||
192 | |||
193 | $this->assertSame(array($this->obj1, $this->obj2, $this->obj3, $this->obj4), $this->list->getChoices()); | ||
194 | $this->assertSame(array('0', '1', '2', '3'), $this->list->getValues()); | ||
195 | $this->assertEquals(array(0 => new ChoiceView($this->obj1, '0', 'A'), 1 => new ChoiceView($this->obj2, '1', 'B'), 2 => new ChoiceView($this->obj3, '2', 'C'), 3 => new ChoiceView($this->obj4, '3', 'D')), $this->list->getRemainingViews()); | ||
196 | } | ||
197 | |||
198 | /** | ||
199 | * @expectedException \Symfony\Component\Form\Exception\StringCastException | ||
200 | */ | ||
201 | public function testInitArrayThrowsExceptionIfToStringNotFound() | ||
202 | { | ||
203 | $this->obj1 = new ObjectChoiceListTest_EntityWithToString('A'); | ||
204 | $this->obj2 = new ObjectChoiceListTest_EntityWithToString('B'); | ||
205 | $this->obj3 = (object) array('name' => 'C'); | ||
206 | $this->obj4 = new ObjectChoiceListTest_EntityWithToString('D'); | ||
207 | |||
208 | new ObjectChoiceList( | ||
209 | array($this->obj1, $this->obj2, $this->obj3, $this->obj4) | ||
210 | ); | ||
211 | } | ||
212 | } | ||
diff --git a/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/ChoiceList/SimpleChoiceListTest.php b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/ChoiceList/SimpleChoiceListTest.php new file mode 100644 index 00000000..69d27a18 --- /dev/null +++ b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/ChoiceList/SimpleChoiceListTest.php | |||
@@ -0,0 +1,188 @@ | |||
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\ChoiceList; | ||
15 | use Symfony\Component\Form\Extension\Core\ChoiceList\SimpleChoiceList; | ||
16 | use Symfony\Component\Form\Extension\Core\View\ChoiceView; | ||
17 | |||
18 | class SimpleChoiceListTest extends \PHPUnit_Framework_TestCase | ||
19 | { | ||
20 | private $list; | ||
21 | |||
22 | private $numericList; | ||
23 | |||
24 | protected function setUp() | ||
25 | { | ||
26 | parent::setUp(); | ||
27 | |||
28 | $choices = array( | ||
29 | 'Group 1' => array('a' => 'A', 'b' => 'B'), | ||
30 | 'Group 2' => array('c' => 'C', 'd' => 'D'), | ||
31 | ); | ||
32 | $numericChoices = array( | ||
33 | 'Group 1' => array(0 => 'A', 1 => 'B'), | ||
34 | 'Group 2' => array(2 => 'C', 3 => 'D'), | ||
35 | ); | ||
36 | |||
37 | $this->list = new SimpleChoiceList($choices, array('b', 'c')); | ||
38 | |||
39 | // Use COPY_CHOICE strategy to test for the various associated problems | ||
40 | $this->numericList = new SimpleChoiceList($numericChoices, array(1, 2)); | ||
41 | } | ||
42 | |||
43 | protected function tearDown() | ||
44 | { | ||
45 | parent::tearDown(); | ||
46 | |||
47 | $this->list = null; | ||
48 | $this->numericList = null; | ||
49 | } | ||
50 | |||
51 | public function testInitArray() | ||
52 | { | ||
53 | $choices = array('a' => 'A', 'b' => 'B', 'c' => 'C'); | ||
54 | $this->list = new SimpleChoiceList($choices, array('b')); | ||
55 | |||
56 | $this->assertSame(array(0 => 'a', 1 => 'b', 2 => 'c'), $this->list->getChoices()); | ||
57 | $this->assertSame(array(0 => 'a', 1 => 'b', 2 => 'c'), $this->list->getValues()); | ||
58 | $this->assertEquals(array(1 => new ChoiceView('b', 'b', 'B')), $this->list->getPreferredViews()); | ||
59 | $this->assertEquals(array(0 => new ChoiceView('a', 'a', 'A'), 2 => new ChoiceView('c', 'c', 'C')), $this->list->getRemainingViews()); | ||
60 | } | ||
61 | |||
62 | public function testInitNestedArray() | ||
63 | { | ||
64 | $this->assertSame(array(0 => 'a', 1 => 'b', 2 => 'c', 3 => 'd'), $this->list->getChoices()); | ||
65 | $this->assertSame(array(0 => 'a', 1 => 'b', 2 => 'c', 3 => 'd'), $this->list->getValues()); | ||
66 | $this->assertEquals(array( | ||
67 | 'Group 1' => array(1 => new ChoiceView('b', 'b', 'B')), | ||
68 | 'Group 2' => array(2 => new ChoiceView('c', 'c', 'C')) | ||
69 | ), $this->list->getPreferredViews()); | ||
70 | $this->assertEquals(array( | ||
71 | 'Group 1' => array(0 => new ChoiceView('a', 'a', 'A')), | ||
72 | 'Group 2' => array(3 => new ChoiceView('d', 'd', 'D')) | ||
73 | ), $this->list->getRemainingViews()); | ||
74 | } | ||
75 | |||
76 | public function testGetIndicesForChoices() | ||
77 | { | ||
78 | $choices = array('b', 'c'); | ||
79 | $this->assertSame(array(1, 2), $this->list->getIndicesForChoices($choices)); | ||
80 | } | ||
81 | |||
82 | public function testGetIndicesForChoicesIgnoresNonExistingChoices() | ||
83 | { | ||
84 | $choices = array('b', 'c', 'foobar'); | ||
85 | $this->assertSame(array(1, 2), $this->list->getIndicesForChoices($choices)); | ||
86 | } | ||
87 | |||
88 | public function testGetIndicesForChoicesDealsWithNumericChoices() | ||
89 | { | ||
90 | // Pass choices as strings although they are integers | ||
91 | $choices = array('0', '1'); | ||
92 | $this->assertSame(array(0, 1), $this->numericList->getIndicesForChoices($choices)); | ||
93 | } | ||
94 | |||
95 | public function testGetIndicesForValues() | ||
96 | { | ||
97 | $values = array('b', 'c'); | ||
98 | $this->assertSame(array(1, 2), $this->list->getIndicesForValues($values)); | ||
99 | } | ||
100 | |||
101 | public function testGetIndicesForValuesIgnoresNonExistingValues() | ||
102 | { | ||
103 | $values = array('b', 'c', '100'); | ||
104 | $this->assertSame(array(1, 2), $this->list->getIndicesForValues($values)); | ||
105 | } | ||
106 | |||
107 | public function testGetIndicesForValuesDealsWithNumericValues() | ||
108 | { | ||
109 | // Pass values as strings although they are integers | ||
110 | $values = array('0', '1'); | ||
111 | $this->assertSame(array(0, 1), $this->numericList->getIndicesForValues($values)); | ||
112 | } | ||
113 | |||
114 | public function testGetChoicesForValues() | ||
115 | { | ||
116 | $values = array('b', 'c'); | ||
117 | $this->assertSame(array('b', 'c'), $this->list->getChoicesForValues($values)); | ||
118 | } | ||
119 | |||
120 | public function testGetChoicesForValuesIgnoresNonExistingValues() | ||
121 | { | ||
122 | $values = array('b', 'c', '100'); | ||
123 | $this->assertSame(array('b', 'c'), $this->list->getChoicesForValues($values)); | ||
124 | } | ||
125 | |||
126 | public function testGetChoicesForValuesDealsWithNumericValues() | ||
127 | { | ||
128 | // Pass values as strings although they are integers | ||
129 | $values = array('0', '1'); | ||
130 | $this->assertSame(array(0, 1), $this->numericList->getChoicesForValues($values)); | ||
131 | } | ||
132 | |||
133 | public function testGetValuesForChoices() | ||
134 | { | ||
135 | $choices = array('b', 'c'); | ||
136 | $this->assertSame(array('b', 'c'), $this->list->getValuesForChoices($choices)); | ||
137 | } | ||
138 | |||
139 | public function testGetValuesForChoicesIgnoresNonExistingValues() | ||
140 | { | ||
141 | $choices = array('b', 'c', 'foobar'); | ||
142 | $this->assertSame(array('b', 'c'), $this->list->getValuesForChoices($choices)); | ||
143 | } | ||
144 | |||
145 | public function testGetValuesForChoicesDealsWithNumericValues() | ||
146 | { | ||
147 | // Pass values as strings although they are integers | ||
148 | $values = array('0', '1'); | ||
149 | |||
150 | $this->assertSame(array('0', '1'), $this->numericList->getValuesForChoices($values)); | ||
151 | } | ||
152 | |||
153 | /** | ||
154 | * @dataProvider dirtyValuesProvider | ||
155 | */ | ||
156 | public function testGetValuesForChoicesDealsWithDirtyValues($choice, $value) | ||
157 | { | ||
158 | $choices = array( | ||
159 | '0' => 'Zero', | ||
160 | '1' => 'One', | ||
161 | '' => 'Empty', | ||
162 | '1.23' => 'Float', | ||
163 | 'foo' => 'Foo', | ||
164 | 'foo10' => 'Foo 10', | ||
165 | ); | ||
166 | |||
167 | // use COPY_CHOICE strategy to test the problems | ||
168 | $this->list = new SimpleChoiceList($choices, array()); | ||
169 | |||
170 | $this->assertSame(array($value), $this->list->getValuesForChoices(array($choice))); | ||
171 | } | ||
172 | |||
173 | public function dirtyValuesProvider() | ||
174 | { | ||
175 | return array( | ||
176 | array(0, '0'), | ||
177 | array('0', '0'), | ||
178 | array('1', '1'), | ||
179 | array(false, '0'), | ||
180 | array(true, '1'), | ||
181 | array('', ''), | ||
182 | array(null, ''), | ||
183 | array('1.23', '1.23'), | ||
184 | array('foo', 'foo'), | ||
185 | array('foo10', 'foo10'), | ||
186 | ); | ||
187 | } | ||
188 | } | ||
diff --git a/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/DataMapper/PropertyPathMapperTest.php b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/DataMapper/PropertyPathMapperTest.php new file mode 100644 index 00000000..ee2e3351 --- /dev/null +++ b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/DataMapper/PropertyPathMapperTest.php | |||
@@ -0,0 +1,319 @@ | |||
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\DataMapper; | ||
13 | |||
14 | use Symfony\Component\Form\FormConfigBuilder; | ||
15 | use Symfony\Component\Form\FormConfigInterface; | ||
16 | use Symfony\Component\Form\Extension\Core\DataMapper\PropertyPathMapper; | ||
17 | |||
18 | class PropertyPathMapperTest extends \PHPUnit_Framework_TestCase | ||
19 | { | ||
20 | /** | ||
21 | * @var PropertyPathMapper | ||
22 | */ | ||
23 | private $mapper; | ||
24 | |||
25 | /** | ||
26 | * @var \PHPUnit_Framework_MockObject_MockObject | ||
27 | */ | ||
28 | private $dispatcher; | ||
29 | |||
30 | /** | ||
31 | * @var \PHPUnit_Framework_MockObject_MockObject | ||
32 | */ | ||
33 | private $propertyAccessor; | ||
34 | |||
35 | protected function setUp() | ||
36 | { | ||
37 | if (!class_exists('Symfony\Component\EventDispatcher\Event')) { | ||
38 | $this->markTestSkipped('The "EventDispatcher" component is not available'); | ||
39 | } | ||
40 | |||
41 | if (!class_exists('Symfony\Component\PropertyAccess\PropertyAccess')) { | ||
42 | $this->markTestSkipped('The "PropertyAccess" component is not available'); | ||
43 | } | ||
44 | |||
45 | $this->dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface'); | ||
46 | $this->propertyAccessor = $this->getMock('Symfony\Component\PropertyAccess\PropertyAccessorInterface'); | ||
47 | $this->mapper = new PropertyPathMapper($this->propertyAccessor); | ||
48 | } | ||
49 | |||
50 | /** | ||
51 | * @param $path | ||
52 | * @return \PHPUnit_Framework_MockObject_MockObject | ||
53 | */ | ||
54 | private function getPropertyPath($path) | ||
55 | { | ||
56 | return $this->getMockBuilder('Symfony\Component\PropertyAccess\PropertyPath') | ||
57 | ->setConstructorArgs(array($path)) | ||
58 | ->setMethods(array('getValue', 'setValue')) | ||
59 | ->getMock(); | ||
60 | } | ||
61 | |||
62 | /** | ||
63 | * @param FormConfigInterface $config | ||
64 | * @param Boolean $synchronized | ||
65 | * @return \PHPUnit_Framework_MockObject_MockObject | ||
66 | */ | ||
67 | private function getForm(FormConfigInterface $config, $synchronized = true) | ||
68 | { | ||
69 | $form = $this->getMockBuilder('Symfony\Component\Form\Form') | ||
70 | ->setConstructorArgs(array($config)) | ||
71 | ->setMethods(array('isSynchronized')) | ||
72 | ->getMock(); | ||
73 | |||
74 | $form->expects($this->any()) | ||
75 | ->method('isSynchronized') | ||
76 | ->will($this->returnValue($synchronized)); | ||
77 | |||
78 | return $form; | ||
79 | } | ||
80 | |||
81 | /** | ||
82 | * @return \PHPUnit_Framework_MockObject_MockObject | ||
83 | */ | ||
84 | private function getDataMapper() | ||
85 | { | ||
86 | return $this->getMock('Symfony\Component\Form\DataMapperInterface'); | ||
87 | } | ||
88 | |||
89 | public function testMapDataToFormsPassesObjectRefIfByReference() | ||
90 | { | ||
91 | $car = new \stdClass(); | ||
92 | $engine = new \stdClass(); | ||
93 | $propertyPath = $this->getPropertyPath('engine'); | ||
94 | |||
95 | $this->propertyAccessor->expects($this->once()) | ||
96 | ->method('getValue') | ||
97 | ->with($car, $propertyPath) | ||
98 | ->will($this->returnValue($engine)); | ||
99 | |||
100 | $config = new FormConfigBuilder('name', '\stdClass', $this->dispatcher); | ||
101 | $config->setByReference(true); | ||
102 | $config->setPropertyPath($propertyPath); | ||
103 | $form = $this->getForm($config); | ||
104 | |||
105 | $this->mapper->mapDataToForms($car, array($form)); | ||
106 | |||
107 | // Can't use isIdentical() above because mocks always clone their | ||
108 | // arguments which can't be disabled in PHPUnit 3.6 | ||
109 | $this->assertSame($engine, $form->getData()); | ||
110 | } | ||
111 | |||
112 | public function testMapDataToFormsPassesObjectCloneIfNotByReference() | ||
113 | { | ||
114 | $car = new \stdClass(); | ||
115 | $engine = new \stdClass(); | ||
116 | $propertyPath = $this->getPropertyPath('engine'); | ||
117 | |||
118 | $this->propertyAccessor->expects($this->once()) | ||
119 | ->method('getValue') | ||
120 | ->with($car, $propertyPath) | ||
121 | ->will($this->returnValue($engine)); | ||
122 | |||
123 | $config = new FormConfigBuilder('name', '\stdClass', $this->dispatcher); | ||
124 | $config->setByReference(false); | ||
125 | $config->setPropertyPath($propertyPath); | ||
126 | $form = $this->getForm($config); | ||
127 | |||
128 | $this->mapper->mapDataToForms($car, array($form)); | ||
129 | |||
130 | $this->assertNotSame($engine, $form->getData()); | ||
131 | $this->assertEquals($engine, $form->getData()); | ||
132 | } | ||
133 | |||
134 | public function testMapDataToFormsIgnoresEmptyPropertyPath() | ||
135 | { | ||
136 | $car = new \stdClass(); | ||
137 | |||
138 | $config = new FormConfigBuilder(null, '\stdClass', $this->dispatcher); | ||
139 | $config->setByReference(true); | ||
140 | $form = $this->getForm($config); | ||
141 | |||
142 | $this->assertNull($form->getPropertyPath()); | ||
143 | |||
144 | $this->mapper->mapDataToForms($car, array($form)); | ||
145 | |||
146 | $this->assertNull($form->getData()); | ||
147 | } | ||
148 | |||
149 | public function testMapDataToFormsIgnoresUnmapped() | ||
150 | { | ||
151 | $car = new \stdClass(); | ||
152 | $propertyPath = $this->getPropertyPath('engine'); | ||
153 | |||
154 | $this->propertyAccessor->expects($this->never()) | ||
155 | ->method('getValue'); | ||
156 | |||
157 | $config = new FormConfigBuilder('name', '\stdClass', $this->dispatcher); | ||
158 | $config->setByReference(true); | ||
159 | $config->setMapped(false); | ||
160 | $config->setPropertyPath($propertyPath); | ||
161 | $form = $this->getForm($config); | ||
162 | |||
163 | $this->mapper->mapDataToForms($car, array($form)); | ||
164 | |||
165 | $this->assertNull($form->getData()); | ||
166 | } | ||
167 | |||
168 | public function testMapDataToFormsIgnoresEmptyData() | ||
169 | { | ||
170 | $propertyPath = $this->getPropertyPath('engine'); | ||
171 | |||
172 | $this->propertyAccessor->expects($this->never()) | ||
173 | ->method('getValue'); | ||
174 | |||
175 | $config = new FormConfigBuilder('name', '\stdClass', $this->dispatcher); | ||
176 | $config->setByReference(true); | ||
177 | $config->setPropertyPath($propertyPath); | ||
178 | $form = $this->getForm($config); | ||
179 | |||
180 | $this->mapper->mapDataToForms(null, array($form)); | ||
181 | |||
182 | $this->assertNull($form->getData()); | ||
183 | } | ||
184 | |||
185 | public function testMapFormsToDataWritesBackIfNotByReference() | ||
186 | { | ||
187 | $car = new \stdClass(); | ||
188 | $engine = new \stdClass(); | ||
189 | $propertyPath = $this->getPropertyPath('engine'); | ||
190 | |||
191 | $this->propertyAccessor->expects($this->once()) | ||
192 | ->method('setValue') | ||
193 | ->with($car, $propertyPath, $engine); | ||
194 | |||
195 | $config = new FormConfigBuilder('name', '\stdClass', $this->dispatcher); | ||
196 | $config->setByReference(false); | ||
197 | $config->setPropertyPath($propertyPath); | ||
198 | $config->setData($engine); | ||
199 | $form = $this->getForm($config); | ||
200 | |||
201 | $this->mapper->mapFormsToData(array($form), $car); | ||
202 | } | ||
203 | |||
204 | public function testMapFormsToDataWritesBackIfByReferenceButNoReference() | ||
205 | { | ||
206 | $car = new \stdClass(); | ||
207 | $engine = new \stdClass(); | ||
208 | $propertyPath = $this->getPropertyPath('engine'); | ||
209 | |||
210 | $this->propertyAccessor->expects($this->once()) | ||
211 | ->method('setValue') | ||
212 | ->with($car, $propertyPath, $engine); | ||
213 | |||
214 | $config = new FormConfigBuilder('name', '\stdClass', $this->dispatcher); | ||
215 | $config->setByReference(true); | ||
216 | $config->setPropertyPath($propertyPath); | ||
217 | $config->setData($engine); | ||
218 | $form = $this->getForm($config); | ||
219 | |||
220 | $this->mapper->mapFormsToData(array($form), $car); | ||
221 | } | ||
222 | |||
223 | public function testMapFormsToDataWritesBackIfByReferenceAndReference() | ||
224 | { | ||
225 | $car = new \stdClass(); | ||
226 | $engine = new \stdClass(); | ||
227 | $propertyPath = $this->getPropertyPath('engine'); | ||
228 | |||
229 | // $car already contains the reference of $engine | ||
230 | $this->propertyAccessor->expects($this->once()) | ||
231 | ->method('getValue') | ||
232 | ->with($car, $propertyPath) | ||
233 | ->will($this->returnValue($engine)); | ||
234 | |||
235 | $this->propertyAccessor->expects($this->never()) | ||
236 | ->method('setValue'); | ||
237 | |||
238 | $config = new FormConfigBuilder('name', '\stdClass', $this->dispatcher); | ||
239 | $config->setByReference(true); | ||
240 | $config->setPropertyPath($propertyPath); | ||
241 | $config->setData($engine); | ||
242 | $form = $this->getForm($config); | ||
243 | |||
244 | $this->mapper->mapFormsToData(array($form), $car); | ||
245 | } | ||
246 | |||
247 | public function testMapFormsToDataIgnoresUnmapped() | ||
248 | { | ||
249 | $car = new \stdClass(); | ||
250 | $engine = new \stdClass(); | ||
251 | $propertyPath = $this->getPropertyPath('engine'); | ||
252 | |||
253 | $this->propertyAccessor->expects($this->never()) | ||
254 | ->method('setValue'); | ||
255 | |||
256 | $config = new FormConfigBuilder('name', '\stdClass', $this->dispatcher); | ||
257 | $config->setByReference(true); | ||
258 | $config->setPropertyPath($propertyPath); | ||
259 | $config->setData($engine); | ||
260 | $config->setMapped(false); | ||
261 | $form = $this->getForm($config); | ||
262 | |||
263 | $this->mapper->mapFormsToData(array($form), $car); | ||
264 | } | ||
265 | |||
266 | public function testMapFormsToDataIgnoresEmptyData() | ||
267 | { | ||
268 | $car = new \stdClass(); | ||
269 | $propertyPath = $this->getPropertyPath('engine'); | ||
270 | |||
271 | $this->propertyAccessor->expects($this->never()) | ||
272 | ->method('setValue'); | ||
273 | |||
274 | $config = new FormConfigBuilder('name', '\stdClass', $this->dispatcher); | ||
275 | $config->setByReference(true); | ||
276 | $config->setPropertyPath($propertyPath); | ||
277 | $config->setData(null); | ||
278 | $form = $this->getForm($config); | ||
279 | |||
280 | $this->mapper->mapFormsToData(array($form), $car); | ||
281 | } | ||
282 | |||
283 | public function testMapFormsToDataIgnoresUnsynchronized() | ||
284 | { | ||
285 | $car = new \stdClass(); | ||
286 | $engine = new \stdClass(); | ||
287 | $propertyPath = $this->getPropertyPath('engine'); | ||
288 | |||
289 | $this->propertyAccessor->expects($this->never()) | ||
290 | ->method('setValue'); | ||
291 | |||
292 | $config = new FormConfigBuilder('name', '\stdClass', $this->dispatcher); | ||
293 | $config->setByReference(true); | ||
294 | $config->setPropertyPath($propertyPath); | ||
295 | $config->setData($engine); | ||
296 | $form = $this->getForm($config, false); | ||
297 | |||
298 | $this->mapper->mapFormsToData(array($form), $car); | ||
299 | } | ||
300 | |||
301 | public function testMapFormsToDataIgnoresDisabled() | ||
302 | { | ||
303 | $car = new \stdClass(); | ||
304 | $engine = new \stdClass(); | ||
305 | $propertyPath = $this->getPropertyPath('engine'); | ||
306 | |||
307 | $this->propertyAccessor->expects($this->never()) | ||
308 | ->method('setValue'); | ||
309 | |||
310 | $config = new FormConfigBuilder('name', '\stdClass', $this->dispatcher); | ||
311 | $config->setByReference(true); | ||
312 | $config->setPropertyPath($propertyPath); | ||
313 | $config->setData($engine); | ||
314 | $config->setDisabled(true); | ||
315 | $form = $this->getForm($config); | ||
316 | |||
317 | $this->mapper->mapFormsToData(array($form), $car); | ||
318 | } | ||
319 | } | ||
diff --git a/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/ArrayToPartsTransformerTest.php b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/ArrayToPartsTransformerTest.php new file mode 100644 index 00000000..bafe5c09 --- /dev/null +++ b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/ArrayToPartsTransformerTest.php | |||
@@ -0,0 +1,149 @@ | |||
1 | <?php | ||
2 | |||
3 | /* | ||
4 | * This file is part of the Symfony package. | ||
5 | * | ||
6 | * (c) Fabien Potencier <fabien.potencier@symfony-project.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\DataTransformer; | ||
13 | |||
14 | use Symfony\Component\Form\Extension\Core\DataTransformer\ArrayToPartsTransformer; | ||
15 | |||
16 | class ArrayToPartsTransformerTest extends \PHPUnit_Framework_TestCase | ||
17 | { | ||
18 | private $transformer; | ||
19 | |||
20 | protected function setUp() | ||
21 | { | ||
22 | $this->transformer = new ArrayToPartsTransformer(array( | ||
23 | 'first' => array('a', 'b', 'c'), | ||
24 | 'second' => array('d', 'e', 'f'), | ||
25 | )); | ||
26 | } | ||
27 | |||
28 | protected function tearDown() | ||
29 | { | ||
30 | $this->transformer = null; | ||
31 | } | ||
32 | |||
33 | public function testTransform() | ||
34 | { | ||
35 | $input = array( | ||
36 | 'a' => '1', | ||
37 | 'b' => '2', | ||
38 | 'c' => '3', | ||
39 | 'd' => '4', | ||
40 | 'e' => '5', | ||
41 | 'f' => '6', | ||
42 | ); | ||
43 | |||
44 | $output = array( | ||
45 | 'first' => array( | ||
46 | 'a' => '1', | ||
47 | 'b' => '2', | ||
48 | 'c' => '3', | ||
49 | ), | ||
50 | 'second' => array( | ||
51 | 'd' => '4', | ||
52 | 'e' => '5', | ||
53 | 'f' => '6', | ||
54 | ), | ||
55 | ); | ||
56 | |||
57 | $this->assertSame($output, $this->transformer->transform($input)); | ||
58 | } | ||
59 | |||
60 | public function testTransformEmpty() | ||
61 | { | ||
62 | $output = array( | ||
63 | 'first' => null, | ||
64 | 'second' => null, | ||
65 | ); | ||
66 | |||
67 | $this->assertSame($output, $this->transformer->transform(null)); | ||
68 | } | ||
69 | |||
70 | /** | ||
71 | * @expectedException \Symfony\Component\Form\Exception\TransformationFailedException | ||
72 | */ | ||
73 | public function testTransformRequiresArray() | ||
74 | { | ||
75 | $this->transformer->transform('12345'); | ||
76 | } | ||
77 | |||
78 | public function testReverseTransform() | ||
79 | { | ||
80 | $input = array( | ||
81 | 'first' => array( | ||
82 | 'a' => '1', | ||
83 | 'b' => '2', | ||
84 | 'c' => '3', | ||
85 | ), | ||
86 | 'second' => array( | ||
87 | 'd' => '4', | ||
88 | 'e' => '5', | ||
89 | 'f' => '6', | ||
90 | ), | ||
91 | ); | ||
92 | |||
93 | $output = array( | ||
94 | 'a' => '1', | ||
95 | 'b' => '2', | ||
96 | 'c' => '3', | ||
97 | 'd' => '4', | ||
98 | 'e' => '5', | ||
99 | 'f' => '6', | ||
100 | ); | ||
101 | |||
102 | $this->assertSame($output, $this->transformer->reverseTransform($input)); | ||
103 | } | ||
104 | |||
105 | public function testReverseTransformCompletelyEmpty() | ||
106 | { | ||
107 | $input = array( | ||
108 | 'first' => '', | ||
109 | 'second' => '', | ||
110 | ); | ||
111 | |||
112 | $this->assertNull($this->transformer->reverseTransform($input)); | ||
113 | } | ||
114 | |||
115 | public function testReverseTransformCompletelyNull() | ||
116 | { | ||
117 | $input = array( | ||
118 | 'first' => null, | ||
119 | 'second' => null, | ||
120 | ); | ||
121 | |||
122 | $this->assertNull($this->transformer->reverseTransform($input)); | ||
123 | } | ||
124 | |||
125 | /** | ||
126 | * @expectedException \Symfony\Component\Form\Exception\TransformationFailedException | ||
127 | */ | ||
128 | public function testReverseTransformPartiallyNull() | ||
129 | { | ||
130 | $input = array( | ||
131 | 'first' => array( | ||
132 | 'a' => '1', | ||
133 | 'b' => '2', | ||
134 | 'c' => '3', | ||
135 | ), | ||
136 | 'second' => null, | ||
137 | ); | ||
138 | |||
139 | $this->transformer->reverseTransform($input); | ||
140 | } | ||
141 | |||
142 | /** | ||
143 | * @expectedException \Symfony\Component\Form\Exception\TransformationFailedException | ||
144 | */ | ||
145 | public function testReverseTransformRequiresArray() | ||
146 | { | ||
147 | $this->transformer->reverseTransform('12345'); | ||
148 | } | ||
149 | } | ||
diff --git a/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/BooleanToStringTransformerTest.php b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/BooleanToStringTransformerTest.php new file mode 100644 index 00000000..41f8f956 --- /dev/null +++ b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/BooleanToStringTransformerTest.php | |||
@@ -0,0 +1,60 @@ | |||
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\DataTransformer; | ||
13 | |||
14 | use Symfony\Component\Form\Extension\Core\DataTransformer\BooleanToStringTransformer; | ||
15 | |||
16 | class BooleanToStringTransformerTest extends \PHPUnit_Framework_TestCase | ||
17 | { | ||
18 | const TRUE_VALUE = '1'; | ||
19 | |||
20 | protected $transformer; | ||
21 | |||
22 | protected function setUp() | ||
23 | { | ||
24 | $this->transformer = new BooleanToStringTransformer(self::TRUE_VALUE); | ||
25 | } | ||
26 | |||
27 | protected function tearDown() | ||
28 | { | ||
29 | $this->transformer = null; | ||
30 | } | ||
31 | |||
32 | public function testTransform() | ||
33 | { | ||
34 | $this->assertEquals(self::TRUE_VALUE, $this->transformer->transform(true)); | ||
35 | $this->assertNull($this->transformer->transform(false)); | ||
36 | $this->assertNull($this->transformer->transform(null)); | ||
37 | } | ||
38 | |||
39 | public function testTransformExpectsBoolean() | ||
40 | { | ||
41 | $this->setExpectedException('Symfony\Component\Form\Exception\TransformationFailedException'); | ||
42 | |||
43 | $this->transformer->transform('1'); | ||
44 | } | ||
45 | |||
46 | public function testReverseTransformExpectsString() | ||
47 | { | ||
48 | $this->setExpectedException('Symfony\Component\Form\Exception\TransformationFailedException'); | ||
49 | |||
50 | $this->transformer->reverseTransform(1); | ||
51 | } | ||
52 | |||
53 | public function testReverseTransform() | ||
54 | { | ||
55 | $this->assertTrue($this->transformer->reverseTransform(self::TRUE_VALUE)); | ||
56 | $this->assertTrue($this->transformer->reverseTransform('foobar')); | ||
57 | $this->assertTrue($this->transformer->reverseTransform('')); | ||
58 | $this->assertFalse($this->transformer->reverseTransform(null)); | ||
59 | } | ||
60 | } | ||
diff --git a/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/ChoiceToValueTransformerTest.php b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/ChoiceToValueTransformerTest.php new file mode 100644 index 00000000..bbae0621 --- /dev/null +++ b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/ChoiceToValueTransformerTest.php | |||
@@ -0,0 +1,76 @@ | |||
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\DataTransformer; | ||
13 | |||
14 | use Symfony\Component\Form\Extension\Core\ChoiceList\SimpleChoiceList; | ||
15 | use Symfony\Component\Form\Extension\Core\DataTransformer\ChoiceToValueTransformer; | ||
16 | |||
17 | class ChoiceToValueTransformerTest extends \PHPUnit_Framework_TestCase | ||
18 | { | ||
19 | protected $transformer; | ||
20 | |||
21 | protected function setUp() | ||
22 | { | ||
23 | $list = new SimpleChoiceList(array('' => 'A', 0 => 'B', 1 => 'C')); | ||
24 | $this->transformer = new ChoiceToValueTransformer($list); | ||
25 | } | ||
26 | |||
27 | protected function tearDown() | ||
28 | { | ||
29 | $this->transformer = null; | ||
30 | } | ||
31 | |||
32 | public function transformProvider() | ||
33 | { | ||
34 | return array( | ||
35 | // more extensive test set can be found in FormUtilTest | ||
36 | array(0, '0'), | ||
37 | array(false, '0'), | ||
38 | array('', ''), | ||
39 | ); | ||
40 | } | ||
41 | |||
42 | /** | ||
43 | * @dataProvider transformProvider | ||
44 | */ | ||
45 | public function testTransform($in, $out) | ||
46 | { | ||
47 | $this->assertSame($out, $this->transformer->transform($in)); | ||
48 | } | ||
49 | |||
50 | public function reverseTransformProvider() | ||
51 | { | ||
52 | return array( | ||
53 | // values are expected to be valid choice keys already and stay | ||
54 | // the same | ||
55 | array('0', 0), | ||
56 | array('', null), | ||
57 | array(null, null), | ||
58 | ); | ||
59 | } | ||
60 | |||
61 | /** | ||
62 | * @dataProvider reverseTransformProvider | ||
63 | */ | ||
64 | public function testReverseTransform($in, $out) | ||
65 | { | ||
66 | $this->assertSame($out, $this->transformer->reverseTransform($in)); | ||
67 | } | ||
68 | |||
69 | /** | ||
70 | * @expectedException \Symfony\Component\Form\Exception\TransformationFailedException | ||
71 | */ | ||
72 | public function testReverseTransformExpectsScalar() | ||
73 | { | ||
74 | $this->transformer->reverseTransform(array()); | ||
75 | } | ||
76 | } | ||
diff --git a/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/ChoicesToValuesTransformerTest.php b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/ChoicesToValuesTransformerTest.php new file mode 100644 index 00000000..57297193 --- /dev/null +++ b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/ChoicesToValuesTransformerTest.php | |||
@@ -0,0 +1,76 @@ | |||
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\DataTransformer; | ||
13 | |||
14 | use Symfony\Component\Form\Extension\Core\ChoiceList\SimpleChoiceList; | ||
15 | |||
16 | use Symfony\Component\Form\Extension\Core\DataTransformer\ChoicesToValuesTransformer; | ||
17 | |||
18 | class ChoicesToValuesTransformerTest extends \PHPUnit_Framework_TestCase | ||
19 | { | ||
20 | protected $transformer; | ||
21 | |||
22 | protected function setUp() | ||
23 | { | ||
24 | $list = new SimpleChoiceList(array(0 => 'A', 1 => 'B', 2 => 'C')); | ||
25 | $this->transformer = new ChoicesToValuesTransformer($list); | ||
26 | } | ||
27 | |||
28 | protected function tearDown() | ||
29 | { | ||
30 | $this->transformer = null; | ||
31 | } | ||
32 | |||
33 | public function testTransform() | ||
34 | { | ||
35 | // Value strategy in SimpleChoiceList is to copy and convert to string | ||
36 | $in = array(0, 1, 2); | ||
37 | $out = array('0', '1', '2'); | ||
38 | |||
39 | $this->assertSame($out, $this->transformer->transform($in)); | ||
40 | } | ||
41 | |||
42 | public function testTransformNull() | ||
43 | { | ||
44 | $this->assertSame(array(), $this->transformer->transform(null)); | ||
45 | } | ||
46 | |||
47 | /** | ||
48 | * @expectedException \Symfony\Component\Form\Exception\TransformationFailedException | ||
49 | */ | ||
50 | public function testTransformExpectsArray() | ||
51 | { | ||
52 | $this->transformer->transform('foobar'); | ||
53 | } | ||
54 | |||
55 | public function testReverseTransform() | ||
56 | { | ||
57 | // values are expected to be valid choices and stay the same | ||
58 | $in = array('0', '1', '2'); | ||
59 | $out = array(0, 1, 2); | ||
60 | |||
61 | $this->assertSame($out, $this->transformer->reverseTransform($in)); | ||
62 | } | ||
63 | |||
64 | public function testReverseTransformNull() | ||
65 | { | ||
66 | $this->assertSame(array(), $this->transformer->reverseTransform(null)); | ||
67 | } | ||
68 | |||
69 | /** | ||
70 | * @expectedException \Symfony\Component\Form\Exception\TransformationFailedException | ||
71 | */ | ||
72 | public function testReverseTransformExpectsArray() | ||
73 | { | ||
74 | $this->transformer->reverseTransform('foobar'); | ||
75 | } | ||
76 | } | ||
diff --git a/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DataTransformerChainTest.php b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DataTransformerChainTest.php new file mode 100644 index 00000000..2ee2f22d --- /dev/null +++ b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DataTransformerChainTest.php | |||
@@ -0,0 +1,53 @@ | |||
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\DataTransformer; | ||
13 | |||
14 | use Symfony\Component\Form\Extension\Core\DataTransformer\DataTransformerChain; | ||
15 | |||
16 | class DataTransformerChainTest extends \PHPUnit_Framework_TestCase | ||
17 | { | ||
18 | public function testTransform() | ||
19 | { | ||
20 | $transformer1 = $this->getMock('Symfony\Component\Form\DataTransformerInterface'); | ||
21 | $transformer1->expects($this->once()) | ||
22 | ->method('transform') | ||
23 | ->with($this->identicalTo('foo')) | ||
24 | ->will($this->returnValue('bar')); | ||
25 | $transformer2 = $this->getMock('Symfony\Component\Form\DataTransformerInterface'); | ||
26 | $transformer2->expects($this->once()) | ||
27 | ->method('transform') | ||
28 | ->with($this->identicalTo('bar')) | ||
29 | ->will($this->returnValue('baz')); | ||
30 | |||
31 | $chain = new DataTransformerChain(array($transformer1, $transformer2)); | ||
32 | |||
33 | $this->assertEquals('baz', $chain->transform('foo')); | ||
34 | } | ||
35 | |||
36 | public function testReverseTransform() | ||
37 | { | ||
38 | $transformer2 = $this->getMock('Symfony\Component\Form\DataTransformerInterface'); | ||
39 | $transformer2->expects($this->once()) | ||
40 | ->method('reverseTransform') | ||
41 | ->with($this->identicalTo('foo')) | ||
42 | ->will($this->returnValue('bar')); | ||
43 | $transformer1 = $this->getMock('Symfony\Component\Form\DataTransformerInterface'); | ||
44 | $transformer1->expects($this->once()) | ||
45 | ->method('reverseTransform') | ||
46 | ->with($this->identicalTo('bar')) | ||
47 | ->will($this->returnValue('baz')); | ||
48 | |||
49 | $chain = new DataTransformerChain(array($transformer1, $transformer2)); | ||
50 | |||
51 | $this->assertEquals('baz', $chain->reverseTransform('foo')); | ||
52 | } | ||
53 | } | ||
diff --git a/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeTestCase.php b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeTestCase.php new file mode 100644 index 00000000..f7722c49 --- /dev/null +++ b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeTestCase.php | |||
@@ -0,0 +1,20 @@ | |||
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\DataTransformer; | ||
13 | |||
14 | abstract class DateTimeTestCase extends \PHPUnit_Framework_TestCase | ||
15 | { | ||
16 | public static function assertDateTimeEquals(\DateTime $expected, \DateTime $actual) | ||
17 | { | ||
18 | self::assertEquals($expected->format('c'), $actual->format('c')); | ||
19 | } | ||
20 | } | ||
diff --git a/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToArrayTransformerTest.php b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToArrayTransformerTest.php new file mode 100644 index 00000000..4898b88d --- /dev/null +++ b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToArrayTransformerTest.php | |||
@@ -0,0 +1,512 @@ | |||
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\DataTransformer; | ||
13 | |||
14 | use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToArrayTransformer; | ||
15 | |||
16 | class DateTimeToArrayTransformerTest extends DateTimeTestCase | ||
17 | { | ||
18 | public function testTransform() | ||
19 | { | ||
20 | $transformer = new DateTimeToArrayTransformer('UTC', 'UTC'); | ||
21 | |||
22 | $input = new \DateTime('2010-02-03 04:05:06 UTC'); | ||
23 | |||
24 | $output = array( | ||
25 | 'year' => '2010', | ||
26 | 'month' => '2', | ||
27 | 'day' => '3', | ||
28 | 'hour' => '4', | ||
29 | 'minute' => '5', | ||
30 | 'second' => '6', | ||
31 | ); | ||
32 | |||
33 | $this->assertSame($output, $transformer->transform($input)); | ||
34 | } | ||
35 | |||
36 | public function testTransformEmpty() | ||
37 | { | ||
38 | $transformer = new DateTimeToArrayTransformer(); | ||
39 | |||
40 | $output = array( | ||
41 | 'year' => '', | ||
42 | 'month' => '', | ||
43 | 'day' => '', | ||
44 | 'hour' => '', | ||
45 | 'minute' => '', | ||
46 | 'second' => '', | ||
47 | ); | ||
48 | |||
49 | $this->assertSame($output, $transformer->transform(null)); | ||
50 | } | ||
51 | |||
52 | public function testTransformEmptyWithFields() | ||
53 | { | ||
54 | $transformer = new DateTimeToArrayTransformer(null, null, array('year', 'minute', 'second')); | ||
55 | |||
56 | $output = array( | ||
57 | 'year' => '', | ||
58 | 'minute' => '', | ||
59 | 'second' => '', | ||
60 | ); | ||
61 | |||
62 | $this->assertSame($output, $transformer->transform(null)); | ||
63 | } | ||
64 | |||
65 | public function testTransformWithFields() | ||
66 | { | ||
67 | $transformer = new DateTimeToArrayTransformer('UTC', 'UTC', array('year', 'month', 'minute', 'second')); | ||
68 | |||
69 | $input = new \DateTime('2010-02-03 04:05:06 UTC'); | ||
70 | |||
71 | $output = array( | ||
72 | 'year' => '2010', | ||
73 | 'month' => '2', | ||
74 | 'minute' => '5', | ||
75 | 'second' => '6', | ||
76 | ); | ||
77 | |||
78 | $this->assertSame($output, $transformer->transform($input)); | ||
79 | } | ||
80 | |||
81 | public function testTransformWithPadding() | ||
82 | { | ||
83 | $transformer = new DateTimeToArrayTransformer('UTC', 'UTC', null, true); | ||
84 | |||
85 | $input = new \DateTime('2010-02-03 04:05:06 UTC'); | ||
86 | |||
87 | $output = array( | ||
88 | 'year' => '2010', | ||
89 | 'month' => '02', | ||
90 | 'day' => '03', | ||
91 | 'hour' => '04', | ||
92 | 'minute' => '05', | ||
93 | 'second' => '06', | ||
94 | ); | ||
95 | |||
96 | $this->assertSame($output, $transformer->transform($input)); | ||
97 | } | ||
98 | |||
99 | public function testTransformDifferentTimezones() | ||
100 | { | ||
101 | $transformer = new DateTimeToArrayTransformer('America/New_York', 'Asia/Hong_Kong'); | ||
102 | |||
103 | $input = new \DateTime('2010-02-03 04:05:06 America/New_York'); | ||
104 | |||
105 | $dateTime = new \DateTime('2010-02-03 04:05:06 America/New_York'); | ||
106 | $dateTime->setTimezone(new \DateTimeZone('Asia/Hong_Kong')); | ||
107 | $output = array( | ||
108 | 'year' => (string) (int) $dateTime->format('Y'), | ||
109 | 'month' => (string) (int) $dateTime->format('m'), | ||
110 | 'day' => (string) (int) $dateTime->format('d'), | ||
111 | 'hour' => (string) (int) $dateTime->format('H'), | ||
112 | 'minute' => (string) (int) $dateTime->format('i'), | ||
113 | 'second' => (string) (int) $dateTime->format('s'), | ||
114 | ); | ||
115 | |||
116 | $this->assertSame($output, $transformer->transform($input)); | ||
117 | } | ||
118 | |||
119 | /** | ||
120 | * @expectedException \Symfony\Component\Form\Exception\TransformationFailedException | ||
121 | */ | ||
122 | public function testTransformRequiresDateTime() | ||
123 | { | ||
124 | $transformer = new DateTimeToArrayTransformer(); | ||
125 | $transformer->reverseTransform('12345'); | ||
126 | } | ||
127 | |||
128 | public function testReverseTransform() | ||
129 | { | ||
130 | $transformer = new DateTimeToArrayTransformer('UTC', 'UTC'); | ||
131 | |||
132 | $input = array( | ||
133 | 'year' => '2010', | ||
134 | 'month' => '2', | ||
135 | 'day' => '3', | ||
136 | 'hour' => '4', | ||
137 | 'minute' => '5', | ||
138 | 'second' => '6', | ||
139 | ); | ||
140 | |||
141 | $output = new \DateTime('2010-02-03 04:05:06 UTC'); | ||
142 | |||
143 | $this->assertDateTimeEquals($output, $transformer->reverseTransform($input)); | ||
144 | } | ||
145 | |||
146 | public function testReverseTransformWithSomeZero() | ||
147 | { | ||
148 | $transformer = new DateTimeToArrayTransformer('UTC', 'UTC'); | ||
149 | |||
150 | $input = array( | ||
151 | 'year' => '2010', | ||
152 | 'month' => '2', | ||
153 | 'day' => '3', | ||
154 | 'hour' => '4', | ||
155 | 'minute' => '0', | ||
156 | 'second' => '0', | ||
157 | ); | ||
158 | |||
159 | $output = new \DateTime('2010-02-03 04:00:00 UTC'); | ||
160 | |||
161 | $this->assertDateTimeEquals($output, $transformer->reverseTransform($input)); | ||
162 | } | ||
163 | |||
164 | public function testReverseTransformCompletelyEmpty() | ||
165 | { | ||
166 | $transformer = new DateTimeToArrayTransformer(); | ||
167 | |||
168 | $input = array( | ||
169 | 'year' => '', | ||
170 | 'month' => '', | ||
171 | 'day' => '', | ||
172 | 'hour' => '', | ||
173 | 'minute' => '', | ||
174 | 'second' => '', | ||
175 | ); | ||
176 | |||
177 | $this->assertNull($transformer->reverseTransform($input)); | ||
178 | } | ||
179 | |||
180 | public function testReverseTransformCompletelyEmptySubsetOfFields() | ||
181 | { | ||
182 | $transformer = new DateTimeToArrayTransformer(null, null, array('year', 'month', 'day')); | ||
183 | |||
184 | $input = array( | ||
185 | 'year' => '', | ||
186 | 'month' => '', | ||
187 | 'day' => '', | ||
188 | ); | ||
189 | |||
190 | $this->assertNull($transformer->reverseTransform($input)); | ||
191 | } | ||
192 | |||
193 | /** | ||
194 | * @expectedException \Symfony\Component\Form\Exception\TransformationFailedException | ||
195 | */ | ||
196 | public function testReverseTransformPartiallyEmptyYear() | ||
197 | { | ||
198 | $transformer = new DateTimeToArrayTransformer(); | ||
199 | $transformer->reverseTransform(array( | ||
200 | 'month' => '2', | ||
201 | 'day' => '3', | ||
202 | 'hour' => '4', | ||
203 | 'minute' => '5', | ||
204 | 'second' => '6', | ||
205 | )); | ||
206 | } | ||
207 | |||
208 | /** | ||
209 | * @expectedException \Symfony\Component\Form\Exception\TransformationFailedException | ||
210 | */ | ||
211 | public function testReverseTransformPartiallyEmptyMonth() | ||
212 | { | ||
213 | $transformer = new DateTimeToArrayTransformer(); | ||
214 | $transformer->reverseTransform(array( | ||
215 | 'year' => '2010', | ||
216 | 'day' => '3', | ||
217 | 'hour' => '4', | ||
218 | 'minute' => '5', | ||
219 | 'second' => '6', | ||
220 | )); | ||
221 | } | ||
222 | |||
223 | /** | ||
224 | * @expectedException \Symfony\Component\Form\Exception\TransformationFailedException | ||
225 | */ | ||
226 | public function testReverseTransformPartiallyEmptyDay() | ||
227 | { | ||
228 | $transformer = new DateTimeToArrayTransformer(); | ||
229 | $transformer->reverseTransform(array( | ||
230 | 'year' => '2010', | ||
231 | 'month' => '2', | ||
232 | 'hour' => '4', | ||
233 | 'minute' => '5', | ||
234 | 'second' => '6', | ||
235 | )); | ||
236 | } | ||
237 | |||
238 | /** | ||
239 | * @expectedException \Symfony\Component\Form\Exception\TransformationFailedException | ||
240 | */ | ||
241 | public function testReverseTransformPartiallyEmptyHour() | ||
242 | { | ||
243 | $transformer = new DateTimeToArrayTransformer(); | ||
244 | $transformer->reverseTransform(array( | ||
245 | 'year' => '2010', | ||
246 | 'month' => '2', | ||
247 | 'day' => '3', | ||
248 | 'minute' => '5', | ||
249 | 'second' => '6', | ||
250 | )); | ||
251 | } | ||
252 | |||
253 | /** | ||
254 | * @expectedException \Symfony\Component\Form\Exception\TransformationFailedException | ||
255 | */ | ||
256 | public function testReverseTransformPartiallyEmptyMinute() | ||
257 | { | ||
258 | $transformer = new DateTimeToArrayTransformer(); | ||
259 | $transformer->reverseTransform(array( | ||
260 | 'year' => '2010', | ||
261 | 'month' => '2', | ||
262 | 'day' => '3', | ||
263 | 'hour' => '4', | ||
264 | 'second' => '6', | ||
265 | )); | ||
266 | } | ||
267 | |||
268 | /** | ||
269 | * @expectedException \Symfony\Component\Form\Exception\TransformationFailedException | ||
270 | */ | ||
271 | public function testReverseTransformPartiallyEmptySecond() | ||
272 | { | ||
273 | $transformer = new DateTimeToArrayTransformer(); | ||
274 | $transformer->reverseTransform(array( | ||
275 | 'year' => '2010', | ||
276 | 'month' => '2', | ||
277 | 'day' => '3', | ||
278 | 'hour' => '4', | ||
279 | 'minute' => '5', | ||
280 | )); | ||
281 | } | ||
282 | |||
283 | public function testReverseTransformNull() | ||
284 | { | ||
285 | $transformer = new DateTimeToArrayTransformer(); | ||
286 | |||
287 | $this->assertNull($transformer->reverseTransform(null)); | ||
288 | } | ||
289 | |||
290 | public function testReverseTransformDifferentTimezones() | ||
291 | { | ||
292 | $transformer = new DateTimeToArrayTransformer('America/New_York', 'Asia/Hong_Kong'); | ||
293 | |||
294 | $input = array( | ||
295 | 'year' => '2010', | ||
296 | 'month' => '2', | ||
297 | 'day' => '3', | ||
298 | 'hour' => '4', | ||
299 | 'minute' => '5', | ||
300 | 'second' => '6', | ||
301 | ); | ||
302 | |||
303 | $output = new \DateTime('2010-02-03 04:05:06 Asia/Hong_Kong'); | ||
304 | $output->setTimezone(new \DateTimeZone('America/New_York')); | ||
305 | |||
306 | $this->assertDateTimeEquals($output, $transformer->reverseTransform($input)); | ||
307 | } | ||
308 | |||
309 | public function testReverseTransformToDifferentTimezone() | ||
310 | { | ||
311 | $transformer = new DateTimeToArrayTransformer('Asia/Hong_Kong', 'UTC'); | ||
312 | |||
313 | $input = array( | ||
314 | 'year' => '2010', | ||
315 | 'month' => '2', | ||
316 | 'day' => '3', | ||
317 | 'hour' => '4', | ||
318 | 'minute' => '5', | ||
319 | 'second' => '6', | ||
320 | ); | ||
321 | |||
322 | $output = new \DateTime('2010-02-03 04:05:06 UTC'); | ||
323 | $output->setTimezone(new \DateTimeZone('Asia/Hong_Kong')); | ||
324 | |||
325 | $this->assertDateTimeEquals($output, $transformer->reverseTransform($input)); | ||
326 | } | ||
327 | |||
328 | /** | ||
329 | * @expectedException \Symfony\Component\Form\Exception\TransformationFailedException | ||
330 | */ | ||
331 | public function testReverseTransformRequiresArray() | ||
332 | { | ||
333 | $transformer = new DateTimeToArrayTransformer(); | ||
334 | $transformer->reverseTransform('12345'); | ||
335 | } | ||
336 | |||
337 | /** | ||
338 | * @expectedException \Symfony\Component\Form\Exception\TransformationFailedException | ||
339 | */ | ||
340 | public function testReverseTransformWithNegativeYear() | ||
341 | { | ||
342 | $transformer = new DateTimeToArrayTransformer(); | ||
343 | $transformer->reverseTransform(array( | ||
344 | 'year' => '-1', | ||
345 | 'month' => '2', | ||
346 | 'day' => '3', | ||
347 | 'hour' => '4', | ||
348 | 'minute' => '5', | ||
349 | 'second' => '6', | ||
350 | )); | ||
351 | } | ||
352 | |||
353 | /** | ||
354 | * @expectedException \Symfony\Component\Form\Exception\TransformationFailedException | ||
355 | */ | ||
356 | public function testReverseTransformWithNegativeMonth() | ||
357 | { | ||
358 | $transformer = new DateTimeToArrayTransformer(); | ||
359 | $transformer->reverseTransform(array( | ||
360 | 'year' => '2010', | ||
361 | 'month' => '-1', | ||
362 | 'day' => '3', | ||
363 | 'hour' => '4', | ||
364 | 'minute' => '5', | ||
365 | 'second' => '6', | ||
366 | )); | ||
367 | } | ||
368 | |||
369 | /** | ||
370 | * @expectedException \Symfony\Component\Form\Exception\TransformationFailedException | ||
371 | */ | ||
372 | public function testReverseTransformWithNegativeDay() | ||
373 | { | ||
374 | $transformer = new DateTimeToArrayTransformer(); | ||
375 | $transformer->reverseTransform(array( | ||
376 | 'year' => '2010', | ||
377 | 'month' => '2', | ||
378 | 'day' => '-1', | ||
379 | 'hour' => '4', | ||
380 | 'minute' => '5', | ||
381 | 'second' => '6', | ||
382 | )); | ||
383 | } | ||
384 | |||
385 | /** | ||
386 | * @expectedException \Symfony\Component\Form\Exception\TransformationFailedException | ||
387 | */ | ||
388 | public function testReverseTransformWithNegativeHour() | ||
389 | { | ||
390 | $transformer = new DateTimeToArrayTransformer(); | ||
391 | $transformer->reverseTransform(array( | ||
392 | 'year' => '2010', | ||
393 | 'month' => '2', | ||
394 | 'day' => '3', | ||
395 | 'hour' => '-1', | ||
396 | 'minute' => '5', | ||
397 | 'second' => '6', | ||
398 | )); | ||
399 | } | ||
400 | |||
401 | /** | ||
402 | * @expectedException \Symfony\Component\Form\Exception\TransformationFailedException | ||
403 | */ | ||
404 | public function testReverseTransformWithNegativeMinute() | ||
405 | { | ||
406 | $transformer = new DateTimeToArrayTransformer(); | ||
407 | $transformer->reverseTransform(array( | ||
408 | 'year' => '2010', | ||
409 | 'month' => '2', | ||
410 | 'day' => '3', | ||
411 | 'hour' => '4', | ||
412 | 'minute' => '-1', | ||
413 | 'second' => '6', | ||
414 | )); | ||
415 | } | ||
416 | |||
417 | /** | ||
418 | * @expectedException \Symfony\Component\Form\Exception\TransformationFailedException | ||
419 | */ | ||
420 | public function testReverseTransformWithNegativeSecond() | ||
421 | { | ||
422 | $transformer = new DateTimeToArrayTransformer(); | ||
423 | $transformer->reverseTransform(array( | ||
424 | 'year' => '2010', | ||
425 | 'month' => '2', | ||
426 | 'day' => '3', | ||
427 | 'hour' => '4', | ||
428 | 'minute' => '5', | ||
429 | 'second' => '-1', | ||
430 | )); | ||
431 | } | ||
432 | |||
433 | /** | ||
434 | * @expectedException \Symfony\Component\Form\Exception\TransformationFailedException | ||
435 | */ | ||
436 | public function testReverseTransformWithInvalidMonth() | ||
437 | { | ||
438 | $transformer = new DateTimeToArrayTransformer(); | ||
439 | $transformer->reverseTransform(array( | ||
440 | 'year' => '2010', | ||
441 | 'month' => '13', | ||
442 | 'day' => '3', | ||
443 | 'hour' => '4', | ||
444 | 'minute' => '5', | ||
445 | 'second' => '6', | ||
446 | )); | ||
447 | } | ||
448 | |||
449 | /** | ||
450 | * @expectedException \Symfony\Component\Form\Exception\TransformationFailedException | ||
451 | */ | ||
452 | public function testReverseTransformWithInvalidDay() | ||
453 | { | ||
454 | $transformer = new DateTimeToArrayTransformer(); | ||
455 | $transformer->reverseTransform(array( | ||
456 | 'year' => '2010', | ||
457 | 'month' => '2', | ||
458 | 'day' => '31', | ||
459 | 'hour' => '4', | ||
460 | 'minute' => '5', | ||
461 | 'second' => '6', | ||
462 | )); | ||
463 | } | ||
464 | |||
465 | /** | ||
466 | * @expectedException \Symfony\Component\Form\Exception\TransformationFailedException | ||
467 | */ | ||
468 | public function testReverseTransformWithStringDay() | ||
469 | { | ||
470 | $transformer = new DateTimeToArrayTransformer(); | ||
471 | $transformer->reverseTransform(array( | ||
472 | 'year' => '2010', | ||
473 | 'month' => '2', | ||
474 | 'day' => 'bazinga', | ||
475 | 'hour' => '4', | ||
476 | 'minute' => '5', | ||
477 | 'second' => '6', | ||
478 | )); | ||
479 | } | ||
480 | |||
481 | /** | ||
482 | * @expectedException \Symfony\Component\Form\Exception\TransformationFailedException | ||
483 | */ | ||
484 | public function testReverseTransformWithStringMonth() | ||
485 | { | ||
486 | $transformer = new DateTimeToArrayTransformer(); | ||
487 | $transformer->reverseTransform(array( | ||
488 | 'year' => '2010', | ||
489 | 'month' => 'bazinga', | ||
490 | 'day' => '31', | ||
491 | 'hour' => '4', | ||
492 | 'minute' => '5', | ||
493 | 'second' => '6', | ||
494 | )); | ||
495 | } | ||
496 | |||
497 | /** | ||
498 | * @expectedException \Symfony\Component\Form\Exception\TransformationFailedException | ||
499 | */ | ||
500 | public function testReverseTransformWithStringYear() | ||
501 | { | ||
502 | $transformer = new DateTimeToArrayTransformer(); | ||
503 | $transformer->reverseTransform(array( | ||
504 | 'year' => 'bazinga', | ||
505 | 'month' => '2', | ||
506 | 'day' => '31', | ||
507 | 'hour' => '4', | ||
508 | 'minute' => '5', | ||
509 | 'second' => '6', | ||
510 | )); | ||
511 | } | ||
512 | } | ||
diff --git a/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToLocalizedStringTransformerTest.php b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToLocalizedStringTransformerTest.php new file mode 100644 index 00000000..cb50fc36 --- /dev/null +++ b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToLocalizedStringTransformerTest.php | |||
@@ -0,0 +1,275 @@ | |||
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\DataTransformer; | ||
13 | |||
14 | use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToLocalizedStringTransformer; | ||
15 | use Symfony\Component\Intl\Util\IntlTestHelper; | ||
16 | |||
17 | class DateTimeToLocalizedStringTransformerTest extends DateTimeTestCase | ||
18 | { | ||
19 | protected $dateTime; | ||
20 | protected $dateTimeWithoutSeconds; | ||
21 | |||
22 | protected function setUp() | ||
23 | { | ||
24 | parent::setUp(); | ||
25 | |||
26 | // Since we test against "de_AT", we need the full implementation | ||
27 | IntlTestHelper::requireFullIntl($this); | ||
28 | |||
29 | \Locale::setDefault('de_AT'); | ||
30 | |||
31 | $this->dateTime = new \DateTime('2010-02-03 04:05:06 UTC'); | ||
32 | $this->dateTimeWithoutSeconds = new \DateTime('2010-02-03 04:05:00 UTC'); | ||
33 | } | ||
34 | |||
35 | protected function tearDown() | ||
36 | { | ||
37 | $this->dateTime = null; | ||
38 | $this->dateTimeWithoutSeconds = null; | ||
39 | } | ||
40 | |||
41 | public static function assertEquals($expected, $actual, $message = '', $delta = 0, $maxDepth = 10, $canonicalize = false, $ignoreCase = false) | ||
42 | { | ||
43 | if ($expected instanceof \DateTime && $actual instanceof \DateTime) { | ||
44 | $expected = $expected->format('c'); | ||
45 | $actual = $actual->format('c'); | ||
46 | } | ||
47 | |||
48 | parent::assertEquals($expected, $actual, $message, $delta, $maxDepth, $canonicalize, $ignoreCase); | ||
49 | } | ||
50 | |||
51 | public function dataProvider() | ||
52 | { | ||
53 | return array( | ||
54 | array(\IntlDateFormatter::SHORT, null, null, '03.02.10 04:05', '2010-02-03 04:05:00 UTC'), | ||
55 | array(\IntlDateFormatter::MEDIUM, null, null, '03.02.2010 04:05', '2010-02-03 04:05:00 UTC'), | ||
56 | array(\IntlDateFormatter::LONG, null, null, '03. Februar 2010 04:05', '2010-02-03 04:05:00 UTC'), | ||
57 | array(\IntlDateFormatter::FULL, null, null, 'Mittwoch, 03. Februar 2010 04:05', '2010-02-03 04:05:00 UTC'), | ||
58 | array(\IntlDateFormatter::SHORT, \IntlDateFormatter::NONE, null, '03.02.10', '2010-02-03 00:00:00 UTC'), | ||
59 | array(\IntlDateFormatter::MEDIUM, \IntlDateFormatter::NONE, null, '03.02.2010', '2010-02-03 00:00:00 UTC'), | ||
60 | array(\IntlDateFormatter::LONG, \IntlDateFormatter::NONE, null, '03. Februar 2010', '2010-02-03 00:00:00 UTC'), | ||
61 | array(\IntlDateFormatter::FULL, \IntlDateFormatter::NONE, null, 'Mittwoch, 03. Februar 2010', '2010-02-03 00:00:00 UTC'), | ||
62 | array(null, \IntlDateFormatter::SHORT, null, '03.02.2010 04:05', '2010-02-03 04:05:00 UTC'), | ||
63 | array(null, \IntlDateFormatter::MEDIUM, null, '03.02.2010 04:05:06', '2010-02-03 04:05:06 UTC'), | ||
64 | array(null, \IntlDateFormatter::LONG, null, '03.02.2010 04:05:06 GMT', '2010-02-03 04:05:06 UTC'), | ||
65 | // see below for extra test case for time format FULL | ||
66 | array(\IntlDateFormatter::NONE, \IntlDateFormatter::SHORT, null, '04:05', '1970-01-01 04:05:00 UTC'), | ||
67 | array(\IntlDateFormatter::NONE, \IntlDateFormatter::MEDIUM, null, '04:05:06', '1970-01-01 04:05:06 UTC'), | ||
68 | array(\IntlDateFormatter::NONE, \IntlDateFormatter::LONG, null, '04:05:06 GMT', '1970-01-01 04:05:06 UTC'), | ||
69 | array(null, null, 'yyyy-MM-dd HH:mm:00', '2010-02-03 04:05:00', '2010-02-03 04:05:00 UTC'), | ||
70 | array(null, null, 'yyyy-MM-dd HH:mm', '2010-02-03 04:05', '2010-02-03 04:05:00 UTC'), | ||
71 | array(null, null, 'yyyy-MM-dd HH', '2010-02-03 04', '2010-02-03 04:00:00 UTC'), | ||
72 | array(null, null, 'yyyy-MM-dd', '2010-02-03', '2010-02-03 00:00:00 UTC'), | ||
73 | array(null, null, 'yyyy-MM', '2010-02', '2010-02-01 00:00:00 UTC'), | ||
74 | array(null, null, 'yyyy', '2010', '2010-01-01 00:00:00 UTC'), | ||
75 | array(null, null, 'dd-MM-yyyy', '03-02-2010', '2010-02-03 00:00:00 UTC'), | ||
76 | array(null, null, 'HH:mm:ss', '04:05:06', '1970-01-01 04:05:06 UTC'), | ||
77 | array(null, null, 'HH:mm:00', '04:05:00', '1970-01-01 04:05:00 UTC'), | ||
78 | array(null, null, 'HH:mm', '04:05', '1970-01-01 04:05:00 UTC'), | ||
79 | array(null, null, 'HH', '04', '1970-01-01 04:00:00 UTC'), | ||
80 | ); | ||
81 | } | ||
82 | |||
83 | /** | ||
84 | * @dataProvider dataProvider | ||
85 | */ | ||
86 | public function testTransform($dateFormat, $timeFormat, $pattern, $output, $input) | ||
87 | { | ||
88 | $transformer = new DateTimeToLocalizedStringTransformer( | ||
89 | 'UTC', | ||
90 | 'UTC', | ||
91 | $dateFormat, | ||
92 | $timeFormat, | ||
93 | \IntlDateFormatter::GREGORIAN, | ||
94 | $pattern | ||
95 | ); | ||
96 | |||
97 | $input = new \DateTime($input); | ||
98 | |||
99 | $this->assertEquals($output, $transformer->transform($input)); | ||
100 | } | ||
101 | |||
102 | public function testTransformFullTime() | ||
103 | { | ||
104 | $transformer = new DateTimeToLocalizedStringTransformer('UTC', 'UTC', null, \IntlDateFormatter::FULL); | ||
105 | |||
106 | $this->assertEquals('03.02.2010 04:05:06 GMT', $transformer->transform($this->dateTime)); | ||
107 | } | ||
108 | |||
109 | public function testTransformToDifferentLocale() | ||
110 | { | ||
111 | \Locale::setDefault('en_US'); | ||
112 | |||
113 | $transformer = new DateTimeToLocalizedStringTransformer('UTC', 'UTC'); | ||
114 | |||
115 | $this->assertEquals('Feb 3, 2010, 4:05 AM', $transformer->transform($this->dateTime)); | ||
116 | } | ||
117 | |||
118 | public function testTransformEmpty() | ||
119 | { | ||
120 | $transformer = new DateTimeToLocalizedStringTransformer(); | ||
121 | |||
122 | $this->assertSame('', $transformer->transform(null)); | ||
123 | } | ||
124 | |||
125 | public function testTransformWithDifferentTimezones() | ||
126 | { | ||
127 | $transformer = new DateTimeToLocalizedStringTransformer('America/New_York', 'Asia/Hong_Kong'); | ||
128 | |||
129 | $input = new \DateTime('2010-02-03 04:05:06 America/New_York'); | ||
130 | |||
131 | $dateTime = clone $input; | ||
132 | $dateTime->setTimezone(new \DateTimeZone('Asia/Hong_Kong')); | ||
133 | |||
134 | $this->assertEquals($dateTime->format('d.m.Y H:i'), $transformer->transform($input)); | ||
135 | } | ||
136 | |||
137 | public function testTransformWithDifferentPatterns() | ||
138 | { | ||
139 | $transformer = new DateTimeToLocalizedStringTransformer('UTC', 'UTC', \IntlDateFormatter::FULL, \IntlDateFormatter::FULL, \IntlDateFormatter::GREGORIAN, 'MM*yyyy*dd HH|mm|ss'); | ||
140 | |||
141 | $this->assertEquals('02*2010*03 04|05|06', $transformer->transform($this->dateTime)); | ||
142 | } | ||
143 | |||
144 | /** | ||
145 | * @expectedException \Symfony\Component\Form\Exception\TransformationFailedException | ||
146 | */ | ||
147 | public function testTransformRequiresValidDateTime() | ||
148 | { | ||
149 | $transformer = new DateTimeToLocalizedStringTransformer(); | ||
150 | $transformer->transform('2010-01-01'); | ||
151 | } | ||
152 | |||
153 | public function testTransformWrapsIntlErrors() | ||
154 | { | ||
155 | $transformer = new DateTimeToLocalizedStringTransformer(); | ||
156 | |||
157 | // HOW TO REPRODUCE? | ||
158 | |||
159 | //$this->setExpectedException('Symfony\Component\Form\Extension\Core\DataTransformer\Transdate_formationFailedException'); | ||
160 | |||
161 | //$transformer->transform(1.5); | ||
162 | } | ||
163 | |||
164 | /** | ||
165 | * @dataProvider dataProvider | ||
166 | */ | ||
167 | public function testReverseTransform($dateFormat, $timeFormat, $pattern, $input, $output) | ||
168 | { | ||
169 | $transformer = new DateTimeToLocalizedStringTransformer( | ||
170 | 'UTC', | ||
171 | 'UTC', | ||
172 | $dateFormat, | ||
173 | $timeFormat, | ||
174 | \IntlDateFormatter::GREGORIAN, | ||
175 | $pattern | ||
176 | ); | ||
177 | |||
178 | $output = new \DateTime($output); | ||
179 | |||
180 | $this->assertEquals($output, $transformer->reverseTransform($input)); | ||
181 | } | ||
182 | |||
183 | public function testReverseTransformFullTime() | ||
184 | { | ||
185 | $transformer = new DateTimeToLocalizedStringTransformer('UTC', 'UTC', null, \IntlDateFormatter::FULL); | ||
186 | |||
187 | $this->assertDateTimeEquals($this->dateTime, $transformer->reverseTransform('03.02.2010 04:05:06 GMT+00:00')); | ||
188 | } | ||
189 | |||
190 | public function testReverseTransformFromDifferentLocale() | ||
191 | { | ||
192 | \Locale::setDefault('en_US'); | ||
193 | |||
194 | $transformer = new DateTimeToLocalizedStringTransformer('UTC', 'UTC'); | ||
195 | |||
196 | $this->assertDateTimeEquals($this->dateTimeWithoutSeconds, $transformer->reverseTransform('Feb 3, 2010, 04:05 AM')); | ||
197 | } | ||
198 | |||
199 | public function testReverseTransformWithDifferentTimezones() | ||
200 | { | ||
201 | $transformer = new DateTimeToLocalizedStringTransformer('America/New_York', 'Asia/Hong_Kong'); | ||
202 | |||
203 | $dateTime = new \DateTime('2010-02-03 04:05:00 Asia/Hong_Kong'); | ||
204 | $dateTime->setTimezone(new \DateTimeZone('America/New_York')); | ||
205 | |||
206 | $this->assertDateTimeEquals($dateTime, $transformer->reverseTransform('03.02.2010 04:05')); | ||
207 | } | ||
208 | |||
209 | public function testReverseTransformWithDifferentPatterns() | ||
210 | { | ||
211 | $transformer = new DateTimeToLocalizedStringTransformer('UTC', 'UTC', \IntlDateFormatter::FULL, \IntlDateFormatter::FULL, \IntlDateFormatter::GREGORIAN, 'MM*yyyy*dd HH|mm|ss'); | ||
212 | |||
213 | $this->assertDateTimeEquals($this->dateTime, $transformer->reverseTransform('02*2010*03 04|05|06')); | ||
214 | } | ||
215 | |||
216 | public function testReverseTransformEmpty() | ||
217 | { | ||
218 | $transformer = new DateTimeToLocalizedStringTransformer(); | ||
219 | |||
220 | $this->assertNull($transformer->reverseTransform('')); | ||
221 | } | ||
222 | |||
223 | /** | ||
224 | * @expectedException \Symfony\Component\Form\Exception\TransformationFailedException | ||
225 | */ | ||
226 | public function testReverseTransformRequiresString() | ||
227 | { | ||
228 | $transformer = new DateTimeToLocalizedStringTransformer(); | ||
229 | $transformer->reverseTransform(12345); | ||
230 | } | ||
231 | |||
232 | /** | ||
233 | * @expectedException \Symfony\Component\Form\Exception\TransformationFailedException | ||
234 | */ | ||
235 | public function testReverseTransformWrapsIntlErrors() | ||
236 | { | ||
237 | $transformer = new DateTimeToLocalizedStringTransformer(); | ||
238 | $transformer->reverseTransform('12345'); | ||
239 | } | ||
240 | |||
241 | /** | ||
242 | * @expectedException \Symfony\Component\Form\Exception\UnexpectedTypeException | ||
243 | */ | ||
244 | public function testValidateDateFormatOption() | ||
245 | { | ||
246 | new DateTimeToLocalizedStringTransformer(null, null, 'foobar'); | ||
247 | } | ||
248 | |||
249 | /** | ||
250 | * @expectedException \Symfony\Component\Form\Exception\UnexpectedTypeException | ||
251 | */ | ||
252 | public function testValidateTimeFormatOption() | ||
253 | { | ||
254 | new DateTimeToLocalizedStringTransformer(null, null, null, 'foobar'); | ||
255 | } | ||
256 | |||
257 | /** | ||
258 | * @expectedException \Symfony\Component\Form\Exception\TransformationFailedException | ||
259 | */ | ||
260 | public function testReverseTransformWithNonExistingDate() | ||
261 | { | ||
262 | $transformer = new DateTimeToLocalizedStringTransformer('UTC', 'UTC', \IntlDateFormatter::SHORT); | ||
263 | |||
264 | $this->assertDateTimeEquals($this->dateTimeWithoutSeconds, $transformer->reverseTransform('31.04.10 04:05')); | ||
265 | } | ||
266 | |||
267 | /** | ||
268 | * @expectedException \Symfony\Component\Form\Exception\TransformationFailedException | ||
269 | */ | ||
270 | public function testReverseTransformOutOfTimestampRange() | ||
271 | { | ||
272 | $transformer = new DateTimeToLocalizedStringTransformer('UTC', 'UTC'); | ||
273 | $transformer->reverseTransform('1789-07-14'); | ||
274 | } | ||
275 | } | ||
diff --git a/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToRfc3339TransformerTest.php b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToRfc3339TransformerTest.php new file mode 100644 index 00000000..98aeb772 --- /dev/null +++ b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToRfc3339TransformerTest.php | |||
@@ -0,0 +1,132 @@ | |||
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\DataTransformer; | ||
13 | |||
14 | use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToRfc3339Transformer; | ||
15 | |||
16 | class DateTimeToRfc3339TransformerTest extends DateTimeTestCase | ||
17 | { | ||
18 | protected $dateTime; | ||
19 | protected $dateTimeWithoutSeconds; | ||
20 | |||
21 | protected function setUp() | ||
22 | { | ||
23 | parent::setUp(); | ||
24 | |||
25 | $this->dateTime = new \DateTime('2010-02-03 04:05:06 UTC'); | ||
26 | $this->dateTimeWithoutSeconds = new \DateTime('2010-02-03 04:05:00 UTC'); | ||
27 | } | ||
28 | |||
29 | protected function tearDown() | ||
30 | { | ||
31 | $this->dateTime = null; | ||
32 | $this->dateTimeWithoutSeconds = null; | ||
33 | } | ||
34 | |||
35 | public static function assertEquals($expected, $actual, $message = '', $delta = 0, $maxDepth = 10, $canonicalize = FALSE, $ignoreCase = FALSE) | ||
36 | { | ||
37 | if ($expected instanceof \DateTime && $actual instanceof \DateTime) { | ||
38 | $expected = $expected->format('c'); | ||
39 | $actual = $actual->format('c'); | ||
40 | } | ||
41 | |||
42 | parent::assertEquals($expected, $actual, $message, $delta, $maxDepth, $canonicalize, $ignoreCase); | ||
43 | } | ||
44 | |||
45 | public function allProvider() | ||
46 | { | ||
47 | return array( | ||
48 | array('UTC', 'UTC', '2010-02-03 04:05:06 UTC', '2010-02-03T04:05:06Z'), | ||
49 | array('UTC', 'UTC', null, ''), | ||
50 | array('America/New_York', 'Asia/Hong_Kong', '2010-02-03 04:05:06 America/New_York', '2010-02-03T17:05:06+08:00'), | ||
51 | array('America/New_York', 'Asia/Hong_Kong', null, ''), | ||
52 | array('UTC', 'Asia/Hong_Kong', '2010-02-03 04:05:06 UTC', '2010-02-03T12:05:06+08:00'), | ||
53 | array('America/New_York', 'UTC', '2010-02-03 04:05:06 America/New_York', '2010-02-03T09:05:06Z'), | ||
54 | ); | ||
55 | } | ||
56 | |||
57 | public function transformProvider() | ||
58 | { | ||
59 | return $this->allProvider(); | ||
60 | } | ||
61 | |||
62 | public function reverseTransformProvider() | ||
63 | { | ||
64 | return array_merge($this->allProvider(), array( | ||
65 | // format without seconds, as appears in some browsers | ||
66 | array('UTC', 'UTC', '2010-02-03 04:05:00 UTC', '2010-02-03T04:05Z'), | ||
67 | array('America/New_York', 'Asia/Hong_Kong', '2010-02-03 04:05:00 America/New_York', '2010-02-03T17:05+08:00'), | ||
68 | )); | ||
69 | } | ||
70 | |||
71 | /** | ||
72 | * @dataProvider transformProvider | ||
73 | */ | ||
74 | public function testTransform($fromTz, $toTz, $from, $to) | ||
75 | { | ||
76 | $transformer = new DateTimeToRfc3339Transformer($fromTz, $toTz); | ||
77 | |||
78 | $this->assertSame($to, $transformer->transform(null !== $from ? new \DateTime($from) : null)); | ||
79 | } | ||
80 | |||
81 | /** | ||
82 | * @expectedException \Symfony\Component\Form\Exception\TransformationFailedException | ||
83 | */ | ||
84 | public function testTransformRequiresValidDateTime() | ||
85 | { | ||
86 | $transformer = new DateTimeToRfc3339Transformer(); | ||
87 | $transformer->transform('2010-01-01'); | ||
88 | } | ||
89 | |||
90 | /** | ||
91 | * @dataProvider reverseTransformProvider | ||
92 | */ | ||
93 | public function testReverseTransform($toTz, $fromTz, $to, $from) | ||
94 | { | ||
95 | $transformer = new DateTimeToRfc3339Transformer($toTz, $fromTz); | ||
96 | |||
97 | if (null !== $to) { | ||
98 | $this->assertDateTimeEquals(new \DateTime($to), $transformer->reverseTransform($from)); | ||
99 | } else { | ||
100 | $this->assertSame($to, $transformer->reverseTransform($from)); | ||
101 | } | ||
102 | } | ||
103 | |||
104 | /** | ||
105 | * @expectedException \Symfony\Component\Form\Exception\TransformationFailedException | ||
106 | */ | ||
107 | public function testReverseTransformRequiresString() | ||
108 | { | ||
109 | $transformer = new DateTimeToRfc3339Transformer(); | ||
110 | $transformer->reverseTransform(12345); | ||
111 | } | ||
112 | |||
113 | /** | ||
114 | * @expectedException \Symfony\Component\Form\Exception\TransformationFailedException | ||
115 | */ | ||
116 | public function testReverseTransformWithNonExistingDate() | ||
117 | { | ||
118 | $transformer = new DateTimeToRfc3339Transformer('UTC', 'UTC'); | ||
119 | |||
120 | $transformer->reverseTransform('2010-04-31T04:05Z'); | ||
121 | } | ||
122 | |||
123 | /** | ||
124 | * @expectedException \Symfony\Component\Form\Exception\TransformationFailedException | ||
125 | */ | ||
126 | public function testReverseTransformExpectsValidDateString() | ||
127 | { | ||
128 | $transformer = new DateTimeToRfc3339Transformer('UTC', 'UTC'); | ||
129 | |||
130 | $transformer->reverseTransform('2010-2010-2010'); | ||
131 | } | ||
132 | } | ||
diff --git a/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToStringTransformerTest.php b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToStringTransformerTest.php new file mode 100644 index 00000000..987df1d8 --- /dev/null +++ b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToStringTransformerTest.php | |||
@@ -0,0 +1,181 @@ | |||
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\DataTransformer; | ||
13 | |||
14 | use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToStringTransformer; | ||
15 | |||
16 | class DateTimeToStringTransformerTest extends DateTimeTestCase | ||
17 | { | ||
18 | public function dataProvider() | ||
19 | { | ||
20 | $data = array( | ||
21 | array('Y-m-d H:i:s', '2010-02-03 16:05:06', '2010-02-03 16:05:06 UTC'), | ||
22 | array('Y-m-d H:i:00', '2010-02-03 16:05:00', '2010-02-03 16:05:00 UTC'), | ||
23 | array('Y-m-d H:i', '2010-02-03 16:05', '2010-02-03 16:05:00 UTC'), | ||
24 | array('Y-m-d H', '2010-02-03 16', '2010-02-03 16:00:00 UTC'), | ||
25 | array('Y-m-d', '2010-02-03', '2010-02-03 00:00:00 UTC'), | ||
26 | array('Y-m', '2010-12', '2010-12-01 00:00:00 UTC'), | ||
27 | array('Y', '2010', '2010-01-01 00:00:00 UTC'), | ||
28 | array('d-m-Y', '03-02-2010', '2010-02-03 00:00:00 UTC'), | ||
29 | array('H:i:s', '16:05:06', '1970-01-01 16:05:06 UTC'), | ||
30 | array('H:i:00', '16:05:00', '1970-01-01 16:05:00 UTC'), | ||
31 | array('H:i', '16:05', '1970-01-01 16:05:00 UTC'), | ||
32 | array('H', '16', '1970-01-01 16:00:00 UTC'), | ||
33 | |||
34 | // different day representations | ||
35 | array('Y-m-j', '2010-02-3', '2010-02-03 00:00:00 UTC'), | ||
36 | array('z', '33', '1970-02-03 00:00:00 UTC'), | ||
37 | |||
38 | // not bijective | ||
39 | // this will not work as php will use actual date to replace missing info | ||
40 | // and after change of date will lookup for closest Wednesday | ||
41 | // i.e. value: 2010-02, php value: 2010-02-(today i.e. 20), parsed date: 2010-02-24 | ||
42 | //array('Y-m-D', '2010-02-Wed', '2010-02-03 00:00:00 UTC'), | ||
43 | //array('Y-m-l', '2010-02-Wednesday', '2010-02-03 00:00:00 UTC'), | ||
44 | |||
45 | // different month representations | ||
46 | array('Y-n-d', '2010-2-03', '2010-02-03 00:00:00 UTC'), | ||
47 | array('Y-M-d', '2010-Feb-03', '2010-02-03 00:00:00 UTC'), | ||
48 | array('Y-F-d', '2010-February-03', '2010-02-03 00:00:00 UTC'), | ||
49 | |||
50 | // different year representations | ||
51 | array('y-m-d', '10-02-03', '2010-02-03 00:00:00 UTC'), | ||
52 | |||
53 | // different time representations | ||
54 | array('G:i:s', '16:05:06', '1970-01-01 16:05:06 UTC'), | ||
55 | array('g:i:s a', '4:05:06 pm', '1970-01-01 16:05:06 UTC'), | ||
56 | array('h:i:s a', '04:05:06 pm', '1970-01-01 16:05:06 UTC'), | ||
57 | |||
58 | // seconds since unix | ||
59 | array('U', '1265213106', '2010-02-03 16:05:06 UTC'), | ||
60 | ); | ||
61 | |||
62 | // This test will fail < 5.3.9 - see https://bugs.php.net/51994 | ||
63 | if (version_compare(phpversion(), '5.3.9', '>=')) { | ||
64 | $data[] = array('Y-z', '2010-33', '2010-02-03 00:00:00 UTC'); | ||
65 | } | ||
66 | |||
67 | return $data; | ||
68 | } | ||
69 | |||
70 | /** | ||
71 | * @dataProvider dataProvider | ||
72 | */ | ||
73 | public function testTransform($format, $output, $input) | ||
74 | { | ||
75 | $transformer = new DateTimeToStringTransformer('UTC', 'UTC', $format); | ||
76 | |||
77 | $input = new \DateTime($input); | ||
78 | |||
79 | $this->assertEquals($output, $transformer->transform($input)); | ||
80 | } | ||
81 | |||
82 | public function testTransformEmpty() | ||
83 | { | ||
84 | $transformer = new DateTimeToStringTransformer(); | ||
85 | |||
86 | $this->assertSame('', $transformer->transform(null)); | ||
87 | } | ||
88 | |||
89 | public function testTransformWithDifferentTimezones() | ||
90 | { | ||
91 | $transformer = new DateTimeToStringTransformer('Asia/Hong_Kong', 'America/New_York', 'Y-m-d H:i:s'); | ||
92 | |||
93 | $input = new \DateTime('2010-02-03 12:05:06 America/New_York'); | ||
94 | $output = $input->format('Y-m-d H:i:s'); | ||
95 | $input->setTimezone(new \DateTimeZone('Asia/Hong_Kong')); | ||
96 | |||
97 | $this->assertEquals($output, $transformer->transform($input)); | ||
98 | } | ||
99 | |||
100 | public function testTransformExpectsDateTime() | ||
101 | { | ||
102 | $transformer = new DateTimeToStringTransformer(); | ||
103 | |||
104 | $this->setExpectedException('Symfony\Component\Form\Exception\TransformationFailedException'); | ||
105 | |||
106 | $transformer->transform('1234'); | ||
107 | } | ||
108 | |||
109 | /** | ||
110 | * @dataProvider dataProvider | ||
111 | */ | ||
112 | public function testReverseTransformUsingPipe($format, $input, $output) | ||
113 | { | ||
114 | if (version_compare(phpversion(), '5.3.7', '<')) { | ||
115 | $this->markTestSkipped('Pipe usage requires PHP 5.3.7 or newer.'); | ||
116 | } | ||
117 | |||
118 | $reverseTransformer = new DateTimeToStringTransformer('UTC', 'UTC', $format, true); | ||
119 | |||
120 | $output = new \DateTime($output); | ||
121 | |||
122 | $this->assertDateTimeEquals($output, $reverseTransformer->reverseTransform($input)); | ||
123 | } | ||
124 | |||
125 | /** | ||
126 | * @dataProvider dataProvider | ||
127 | */ | ||
128 | public function testReverseTransformWithoutUsingPipe($format, $input, $output) | ||
129 | { | ||
130 | $reverseTransformer = new DateTimeToStringTransformer('UTC', 'UTC', $format, false); | ||
131 | |||
132 | $output = new \DateTime($output); | ||
133 | |||
134 | $this->assertDateTimeEquals($output, $reverseTransformer->reverseTransform($input)); | ||
135 | } | ||
136 | |||
137 | public function testReverseTransformEmpty() | ||
138 | { | ||
139 | $reverseTransformer = new DateTimeToStringTransformer(); | ||
140 | |||
141 | $this->assertNull($reverseTransformer->reverseTransform('')); | ||
142 | } | ||
143 | |||
144 | public function testReverseTransformWithDifferentTimezones() | ||
145 | { | ||
146 | $reverseTransformer = new DateTimeToStringTransformer('America/New_York', 'Asia/Hong_Kong', 'Y-m-d H:i:s'); | ||
147 | |||
148 | $output = new \DateTime('2010-02-03 16:05:06 Asia/Hong_Kong'); | ||
149 | $input = $output->format('Y-m-d H:i:s'); | ||
150 | $output->setTimeZone(new \DateTimeZone('America/New_York')); | ||
151 | |||
152 | $this->assertDateTimeEquals($output, $reverseTransformer->reverseTransform($input)); | ||
153 | } | ||
154 | |||
155 | public function testReverseTransformExpectsString() | ||
156 | { | ||
157 | $reverseTransformer = new DateTimeToStringTransformer(); | ||
158 | |||
159 | $this->setExpectedException('Symfony\Component\Form\Exception\TransformationFailedException'); | ||
160 | |||
161 | $reverseTransformer->reverseTransform(1234); | ||
162 | } | ||
163 | |||
164 | public function testReverseTransformExpectsValidDateString() | ||
165 | { | ||
166 | $reverseTransformer = new DateTimeToStringTransformer(); | ||
167 | |||
168 | $this->setExpectedException('Symfony\Component\Form\Exception\TransformationFailedException'); | ||
169 | |||
170 | $reverseTransformer->reverseTransform('2010-2010-2010'); | ||
171 | } | ||
172 | |||
173 | public function testReverseTransformWithNonExistingDate() | ||
174 | { | ||
175 | $reverseTransformer = new DateTimeToStringTransformer(); | ||
176 | |||
177 | $this->setExpectedException('Symfony\Component\Form\Exception\TransformationFailedException'); | ||
178 | |||
179 | $reverseTransformer->reverseTransform('2010-04-31'); | ||
180 | } | ||
181 | } | ||
diff --git a/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToTimestampTransformerTest.php b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToTimestampTransformerTest.php new file mode 100644 index 00000000..b54f0c4c --- /dev/null +++ b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToTimestampTransformerTest.php | |||
@@ -0,0 +1,104 @@ | |||
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\DataTransformer; | ||
13 | |||
14 | use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToTimestampTransformer; | ||
15 | |||
16 | class DateTimeToTimestampTransformerTest extends DateTimeTestCase | ||
17 | { | ||
18 | public function testTransform() | ||
19 | { | ||
20 | $transformer = new DateTimeToTimestampTransformer('UTC', 'UTC'); | ||
21 | |||
22 | $input = new \DateTime('2010-02-03 04:05:06 UTC'); | ||
23 | $output = $input->format('U'); | ||
24 | |||
25 | $this->assertEquals($output, $transformer->transform($input)); | ||
26 | } | ||
27 | |||
28 | public function testTransformEmpty() | ||
29 | { | ||
30 | $transformer = new DateTimeToTimestampTransformer(); | ||
31 | |||
32 | $this->assertNull($transformer->transform(null)); | ||
33 | } | ||
34 | |||
35 | public function testTransformWithDifferentTimezones() | ||
36 | { | ||
37 | $transformer = new DateTimeToTimestampTransformer('Asia/Hong_Kong', 'America/New_York'); | ||
38 | |||
39 | $input = new \DateTime('2010-02-03 04:05:06 America/New_York'); | ||
40 | $output = $input->format('U'); | ||
41 | $input->setTimezone(new \DateTimeZone('Asia/Hong_Kong')); | ||
42 | |||
43 | $this->assertEquals($output, $transformer->transform($input)); | ||
44 | } | ||
45 | |||
46 | public function testTransformFromDifferentTimezone() | ||
47 | { | ||
48 | $transformer = new DateTimeToTimestampTransformer('Asia/Hong_Kong', 'UTC'); | ||
49 | |||
50 | $input = new \DateTime('2010-02-03 04:05:06 Asia/Hong_Kong'); | ||
51 | |||
52 | $dateTime = clone $input; | ||
53 | $dateTime->setTimezone(new \DateTimeZone('UTC')); | ||
54 | $output = $dateTime->format('U'); | ||
55 | |||
56 | $this->assertEquals($output, $transformer->transform($input)); | ||
57 | } | ||
58 | |||
59 | public function testTransformExpectsDateTime() | ||
60 | { | ||
61 | $transformer = new DateTimeToTimestampTransformer(); | ||
62 | |||
63 | $this->setExpectedException('Symfony\Component\Form\Exception\TransformationFailedException'); | ||
64 | |||
65 | $transformer->transform('1234'); | ||
66 | } | ||
67 | |||
68 | public function testReverseTransform() | ||
69 | { | ||
70 | $reverseTransformer = new DateTimeToTimestampTransformer('UTC', 'UTC'); | ||
71 | |||
72 | $output = new \DateTime('2010-02-03 04:05:06 UTC'); | ||
73 | $input = $output->format('U'); | ||
74 | |||
75 | $this->assertDateTimeEquals($output, $reverseTransformer->reverseTransform($input)); | ||
76 | } | ||
77 | |||
78 | public function testReverseTransformEmpty() | ||
79 | { | ||
80 | $reverseTransformer = new DateTimeToTimestampTransformer(); | ||
81 | |||
82 | $this->assertNull($reverseTransformer->reverseTransform(null)); | ||
83 | } | ||
84 | |||
85 | public function testReverseTransformWithDifferentTimezones() | ||
86 | { | ||
87 | $reverseTransformer = new DateTimeToTimestampTransformer('Asia/Hong_Kong', 'America/New_York'); | ||
88 | |||
89 | $output = new \DateTime('2010-02-03 04:05:06 America/New_York'); | ||
90 | $input = $output->format('U'); | ||
91 | $output->setTimezone(new \DateTimeZone('Asia/Hong_Kong')); | ||
92 | |||
93 | $this->assertDateTimeEquals($output, $reverseTransformer->reverseTransform($input)); | ||
94 | } | ||
95 | |||
96 | public function testReverseTransformExpectsValidTimestamp() | ||
97 | { | ||
98 | $reverseTransformer = new DateTimeToTimestampTransformer(); | ||
99 | |||
100 | $this->setExpectedException('Symfony\Component\Form\Exception\TransformationFailedException'); | ||
101 | |||
102 | $reverseTransformer->reverseTransform('2010-2010-2010'); | ||
103 | } | ||
104 | } | ||
diff --git a/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/IntegerToLocalizedStringTransformerTest.php b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/IntegerToLocalizedStringTransformerTest.php new file mode 100644 index 00000000..a90fa91b --- /dev/null +++ b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/IntegerToLocalizedStringTransformerTest.php | |||
@@ -0,0 +1,115 @@ | |||
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\DataTransformer; | ||
13 | |||
14 | use Symfony\Component\Form\Extension\Core\DataTransformer\IntegerToLocalizedStringTransformer; | ||
15 | use Symfony\Component\Intl\Util\IntlTestHelper; | ||
16 | |||
17 | class IntegerToLocalizedStringTransformerTest extends \PHPUnit_Framework_TestCase | ||
18 | { | ||
19 | protected function setUp() | ||
20 | { | ||
21 | parent::setUp(); | ||
22 | |||
23 | // Since we test against "de_AT", we need the full implementation | ||
24 | IntlTestHelper::requireFullIntl($this); | ||
25 | |||
26 | \Locale::setDefault('de_AT'); | ||
27 | } | ||
28 | |||
29 | public function testReverseTransform() | ||
30 | { | ||
31 | $transformer = new IntegerToLocalizedStringTransformer(); | ||
32 | |||
33 | $this->assertEquals(1, $transformer->reverseTransform('1')); | ||
34 | $this->assertEquals(1, $transformer->reverseTransform('1,5')); | ||
35 | $this->assertEquals(1234, $transformer->reverseTransform('1234,5')); | ||
36 | $this->assertEquals(12345, $transformer->reverseTransform('12345,912')); | ||
37 | } | ||
38 | |||
39 | public function testReverseTransformEmpty() | ||
40 | { | ||
41 | $transformer = new IntegerToLocalizedStringTransformer(); | ||
42 | |||
43 | $this->assertNull($transformer->reverseTransform('')); | ||
44 | } | ||
45 | |||
46 | public function testReverseTransformWithGrouping() | ||
47 | { | ||
48 | $transformer = new IntegerToLocalizedStringTransformer(null, true); | ||
49 | |||
50 | $this->assertEquals(1234, $transformer->reverseTransform('1.234,5')); | ||
51 | $this->assertEquals(12345, $transformer->reverseTransform('12.345,912')); | ||
52 | $this->assertEquals(1234, $transformer->reverseTransform('1234,5')); | ||
53 | $this->assertEquals(12345, $transformer->reverseTransform('12345,912')); | ||
54 | } | ||
55 | |||
56 | /** | ||
57 | * @expectedException \Symfony\Component\Form\Exception\TransformationFailedException | ||
58 | */ | ||
59 | public function testReverseTransformExpectsString() | ||
60 | { | ||
61 | $transformer = new IntegerToLocalizedStringTransformer(); | ||
62 | |||
63 | $transformer->reverseTransform(1); | ||
64 | } | ||
65 | |||
66 | /** | ||
67 | * @expectedException \Symfony\Component\Form\Exception\TransformationFailedException | ||
68 | */ | ||
69 | public function testReverseTransformExpectsValidNumber() | ||
70 | { | ||
71 | $transformer = new IntegerToLocalizedStringTransformer(); | ||
72 | |||
73 | $transformer->reverseTransform('foo'); | ||
74 | } | ||
75 | |||
76 | /** | ||
77 | * @expectedException \Symfony\Component\Form\Exception\TransformationFailedException | ||
78 | */ | ||
79 | public function testReverseTransformDisallowsNaN() | ||
80 | { | ||
81 | $transformer = new IntegerToLocalizedStringTransformer(); | ||
82 | |||
83 | $transformer->reverseTransform('NaN'); | ||
84 | } | ||
85 | |||
86 | /** | ||
87 | * @expectedException \Symfony\Component\Form\Exception\TransformationFailedException | ||
88 | */ | ||
89 | public function testReverseTransformDisallowsNaN2() | ||
90 | { | ||
91 | $transformer = new IntegerToLocalizedStringTransformer(); | ||
92 | |||
93 | $transformer->reverseTransform('nan'); | ||
94 | } | ||
95 | |||
96 | /** | ||
97 | * @expectedException \Symfony\Component\Form\Exception\TransformationFailedException | ||
98 | */ | ||
99 | public function testReverseTransformDisallowsInfinity() | ||
100 | { | ||
101 | $transformer = new IntegerToLocalizedStringTransformer(); | ||
102 | |||
103 | $transformer->reverseTransform('∞'); | ||
104 | } | ||
105 | |||
106 | /** | ||
107 | * @expectedException \Symfony\Component\Form\Exception\TransformationFailedException | ||
108 | */ | ||
109 | public function testReverseTransformDisallowsNegativeInfinity() | ||
110 | { | ||
111 | $transformer = new IntegerToLocalizedStringTransformer(); | ||
112 | |||
113 | $transformer->reverseTransform('-∞'); | ||
114 | } | ||
115 | } | ||
diff --git a/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/MoneyToLocalizedStringTransformerTest.php b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/MoneyToLocalizedStringTransformerTest.php new file mode 100644 index 00000000..8b91fe10 --- /dev/null +++ b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/MoneyToLocalizedStringTransformerTest.php | |||
@@ -0,0 +1,74 @@ | |||
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\DataTransformer; | ||
13 | |||
14 | use Symfony\Component\Form\Extension\Core\DataTransformer\MoneyToLocalizedStringTransformer; | ||
15 | use Symfony\Component\Intl\Util\IntlTestHelper; | ||
16 | |||
17 | class MoneyToLocalizedStringTransformerTest extends \PHPUnit_Framework_TestCase | ||
18 | { | ||
19 | protected function setUp() | ||
20 | { | ||
21 | parent::setUp(); | ||
22 | |||
23 | // Since we test against "de_AT", we need the full implementation | ||
24 | IntlTestHelper::requireFullIntl($this); | ||
25 | |||
26 | \Locale::setDefault('de_AT'); | ||
27 | } | ||
28 | |||
29 | public function testTransform() | ||
30 | { | ||
31 | $transformer = new MoneyToLocalizedStringTransformer(null, null, null, 100); | ||
32 | |||
33 | $this->assertEquals('1,23', $transformer->transform(123)); | ||
34 | } | ||
35 | |||
36 | public function testTransformExpectsNumeric() | ||
37 | { | ||
38 | $transformer = new MoneyToLocalizedStringTransformer(null, null, null, 100); | ||
39 | |||
40 | $this->setExpectedException('Symfony\Component\Form\Exception\TransformationFailedException'); | ||
41 | |||
42 | $transformer->transform('abcd'); | ||
43 | } | ||
44 | |||
45 | public function testTransformEmpty() | ||
46 | { | ||
47 | $transformer = new MoneyToLocalizedStringTransformer(); | ||
48 | |||
49 | $this->assertSame('', $transformer->transform(null)); | ||
50 | } | ||
51 | |||
52 | public function testReverseTransform() | ||
53 | { | ||
54 | $transformer = new MoneyToLocalizedStringTransformer(null, null, null, 100); | ||
55 | |||
56 | $this->assertEquals(123, $transformer->reverseTransform('1,23')); | ||
57 | } | ||
58 | |||
59 | public function testReverseTransformExpectsString() | ||
60 | { | ||
61 | $transformer = new MoneyToLocalizedStringTransformer(null, null, null, 100); | ||
62 | |||
63 | $this->setExpectedException('Symfony\Component\Form\Exception\TransformationFailedException'); | ||
64 | |||
65 | $transformer->reverseTransform(12345); | ||
66 | } | ||
67 | |||
68 | public function testReverseTransformEmpty() | ||
69 | { | ||
70 | $transformer = new MoneyToLocalizedStringTransformer(); | ||
71 | |||
72 | $this->assertNull($transformer->reverseTransform('')); | ||
73 | } | ||
74 | } | ||
diff --git a/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/NumberToLocalizedStringTransformerTest.php b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/NumberToLocalizedStringTransformerTest.php new file mode 100644 index 00000000..c58e3f60 --- /dev/null +++ b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/NumberToLocalizedStringTransformerTest.php | |||
@@ -0,0 +1,393 @@ | |||
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\DataTransformer; | ||
13 | |||
14 | use Symfony\Component\Form\Extension\Core\DataTransformer\NumberToLocalizedStringTransformer; | ||
15 | use Symfony\Component\Intl\Util\IntlTestHelper; | ||
16 | |||
17 | class NumberToLocalizedStringTransformerTest extends \PHPUnit_Framework_TestCase | ||
18 | { | ||
19 | protected function setUp() | ||
20 | { | ||
21 | parent::setUp(); | ||
22 | |||
23 | // Since we test against "de_AT", we need the full implementation | ||
24 | IntlTestHelper::requireFullIntl($this); | ||
25 | |||
26 | \Locale::setDefault('de_AT'); | ||
27 | } | ||
28 | |||
29 | public function provideTransformations() | ||
30 | { | ||
31 | return array( | ||
32 | array(null, '', 'de_AT'), | ||
33 | array(1, '1', 'de_AT'), | ||
34 | array(1.5, '1,5', 'de_AT'), | ||
35 | array(1234.5, '1234,5', 'de_AT'), | ||
36 | array(12345.912, '12345,912', 'de_AT'), | ||
37 | array(1234.5, '1234,5', 'ru'), | ||
38 | array(1234.5, '1234,5', 'fi'), | ||
39 | ); | ||
40 | } | ||
41 | |||
42 | /** | ||
43 | * @dataProvider provideTransformations | ||
44 | */ | ||
45 | public function testTransform($from, $to, $locale) | ||
46 | { | ||
47 | \Locale::setDefault($locale); | ||
48 | |||
49 | $transformer = new NumberToLocalizedStringTransformer(); | ||
50 | |||
51 | $this->assertSame($to, $transformer->transform($from)); | ||
52 | } | ||
53 | |||
54 | public function provideTransformationsWithGrouping() | ||
55 | { | ||
56 | return array( | ||
57 | array(1234.5, '1.234,5', 'de_AT'), | ||
58 | array(12345.912, '12.345,912', 'de_AT'), | ||
59 | array(1234.5, '1 234,5', 'fr'), | ||
60 | array(1234.5, '1 234,5', 'ru'), | ||
61 | array(1234.5, '1 234,5', 'fi'), | ||
62 | ); | ||
63 | } | ||
64 | |||
65 | /** | ||
66 | * @dataProvider provideTransformationsWithGrouping | ||
67 | */ | ||
68 | public function testTransformWithGrouping($from, $to, $locale) | ||
69 | { | ||
70 | \Locale::setDefault($locale); | ||
71 | |||
72 | $transformer = new NumberToLocalizedStringTransformer(null, true); | ||
73 | |||
74 | $this->assertSame($to, $transformer->transform($from)); | ||
75 | } | ||
76 | |||
77 | public function testTransformWithPrecision() | ||
78 | { | ||
79 | $transformer = new NumberToLocalizedStringTransformer(2); | ||
80 | |||
81 | $this->assertEquals('1234,50', $transformer->transform(1234.5)); | ||
82 | $this->assertEquals('678,92', $transformer->transform(678.916)); | ||
83 | } | ||
84 | |||
85 | public function testTransformWithRoundingMode() | ||
86 | { | ||
87 | $transformer = new NumberToLocalizedStringTransformer(null, null, NumberToLocalizedStringTransformer::ROUND_DOWN); | ||
88 | $this->assertEquals('1234,547', $transformer->transform(1234.547), '->transform() only applies rounding mode if precision set'); | ||
89 | |||
90 | $transformer = new NumberToLocalizedStringTransformer(2, null, NumberToLocalizedStringTransformer::ROUND_DOWN); | ||
91 | $this->assertEquals('1234,54', $transformer->transform(1234.547), '->transform() rounding-mode works'); | ||
92 | |||
93 | } | ||
94 | |||
95 | /** | ||
96 | * @dataProvider provideTransformations | ||
97 | */ | ||
98 | public function testReverseTransform($to, $from, $locale) | ||
99 | { | ||
100 | \Locale::setDefault($locale); | ||
101 | |||
102 | $transformer = new NumberToLocalizedStringTransformer(); | ||
103 | |||
104 | $this->assertEquals($to, $transformer->reverseTransform($from)); | ||
105 | } | ||
106 | |||
107 | /** | ||
108 | * @dataProvider provideTransformationsWithGrouping | ||
109 | */ | ||
110 | public function testReverseTransformWithGrouping($to, $from, $locale) | ||
111 | { | ||
112 | \Locale::setDefault($locale); | ||
113 | |||
114 | $transformer = new NumberToLocalizedStringTransformer(null, true); | ||
115 | |||
116 | $this->assertEquals($to, $transformer->reverseTransform($from)); | ||
117 | } | ||
118 | |||
119 | // https://github.com/symfony/symfony/issues/7609 | ||
120 | public function testReverseTransformWithGroupingAndFixedSpaces() | ||
121 | { | ||
122 | if (!extension_loaded('mbstring')) { | ||
123 | $this->markTestSkipped('The "mbstring" extension is required for this test.'); | ||
124 | } | ||
125 | |||
126 | \Locale::setDefault('ru'); | ||
127 | |||
128 | $transformer = new NumberToLocalizedStringTransformer(null, true); | ||
129 | |||
130 | $this->assertEquals(1234.5, $transformer->reverseTransform("1\xc2\xa0234,5")); | ||
131 | } | ||
132 | |||
133 | public function testReverseTransformWithGroupingButWithoutGroupSeparator() | ||
134 | { | ||
135 | $transformer = new NumberToLocalizedStringTransformer(null, true); | ||
136 | |||
137 | // omit group separator | ||
138 | $this->assertEquals(1234.5, $transformer->reverseTransform('1234,5')); | ||
139 | $this->assertEquals(12345.912, $transformer->reverseTransform('12345,912')); | ||
140 | } | ||
141 | |||
142 | public function testDecimalSeparatorMayBeDotIfGroupingSeparatorIsNotDot() | ||
143 | { | ||
144 | \Locale::setDefault('fr'); | ||
145 | $transformer = new NumberToLocalizedStringTransformer(null, true); | ||
146 | |||
147 | // completely valid format | ||
148 | $this->assertEquals(1234.5, $transformer->reverseTransform('1 234,5')); | ||
149 | // accept dots | ||
150 | $this->assertEquals(1234.5, $transformer->reverseTransform('1 234.5')); | ||
151 | // omit group separator | ||
152 | $this->assertEquals(1234.5, $transformer->reverseTransform('1234,5')); | ||
153 | $this->assertEquals(1234.5, $transformer->reverseTransform('1234.5')); | ||
154 | } | ||
155 | |||
156 | /** | ||
157 | * @expectedException \Symfony\Component\Form\Exception\TransformationFailedException | ||
158 | */ | ||
159 | public function testDecimalSeparatorMayNotBeDotIfGroupingSeparatorIsDot() | ||
160 | { | ||
161 | $transformer = new NumberToLocalizedStringTransformer(null, true); | ||
162 | |||
163 | $transformer->reverseTransform('1.234.5'); | ||
164 | } | ||
165 | |||
166 | /** | ||
167 | * @expectedException \Symfony\Component\Form\Exception\TransformationFailedException | ||
168 | */ | ||
169 | public function testDecimalSeparatorMayNotBeDotIfGroupingSeparatorIsDotWithNoGroupSep() | ||
170 | { | ||
171 | $transformer = new NumberToLocalizedStringTransformer(null, true); | ||
172 | |||
173 | $transformer->reverseTransform('1234.5'); | ||
174 | } | ||
175 | |||
176 | public function testDecimalSeparatorMayBeDotIfGroupingSeparatorIsDotButNoGroupingUsed() | ||
177 | { | ||
178 | \Locale::setDefault('fr'); | ||
179 | $transformer = new NumberToLocalizedStringTransformer(); | ||
180 | |||
181 | $this->assertEquals(1234.5, $transformer->reverseTransform('1234,5')); | ||
182 | $this->assertEquals(1234.5, $transformer->reverseTransform('1234.5')); | ||
183 | } | ||
184 | |||
185 | public function testDecimalSeparatorMayBeCommaIfGroupingSeparatorIsNotComma() | ||
186 | { | ||
187 | \Locale::setDefault('bg'); | ||
188 | $transformer = new NumberToLocalizedStringTransformer(null, true); | ||
189 | |||
190 | // completely valid format | ||
191 | $this->assertEquals(1234.5, $transformer->reverseTransform('1 234.5')); | ||
192 | // accept commas | ||
193 | $this->assertEquals(1234.5, $transformer->reverseTransform('1 234,5')); | ||
194 | // omit group separator | ||
195 | $this->assertEquals(1234.5, $transformer->reverseTransform('1234.5')); | ||
196 | $this->assertEquals(1234.5, $transformer->reverseTransform('1234,5')); | ||
197 | } | ||
198 | |||
199 | /** | ||
200 | * @expectedException \Symfony\Component\Form\Exception\TransformationFailedException | ||
201 | */ | ||
202 | public function testDecimalSeparatorMayNotBeCommaIfGroupingSeparatorIsComma() | ||
203 | { | ||
204 | \Locale::setDefault('en'); | ||
205 | $transformer = new NumberToLocalizedStringTransformer(null, true); | ||
206 | |||
207 | $transformer->reverseTransform('1,234,5'); | ||
208 | } | ||
209 | |||
210 | /** | ||
211 | * @expectedException \Symfony\Component\Form\Exception\TransformationFailedException | ||
212 | */ | ||
213 | public function testDecimalSeparatorMayNotBeCommaIfGroupingSeparatorIsCommaWithNoGroupSep() | ||
214 | { | ||
215 | \Locale::setDefault('en'); | ||
216 | $transformer = new NumberToLocalizedStringTransformer(null, true); | ||
217 | |||
218 | $transformer->reverseTransform('1234,5'); | ||
219 | } | ||
220 | |||
221 | public function testDecimalSeparatorMayBeCommaIfGroupingSeparatorIsCommaButNoGroupingUsed() | ||
222 | { | ||
223 | \Locale::setDefault('en'); | ||
224 | $transformer = new NumberToLocalizedStringTransformer(); | ||
225 | |||
226 | $this->assertEquals(1234.5, $transformer->reverseTransform('1234,5')); | ||
227 | $this->assertEquals(1234.5, $transformer->reverseTransform('1234.5')); | ||
228 | } | ||
229 | |||
230 | /** | ||
231 | * @expectedException \Symfony\Component\Form\Exception\TransformationFailedException | ||
232 | */ | ||
233 | public function testTransformExpectsNumeric() | ||
234 | { | ||
235 | $transformer = new NumberToLocalizedStringTransformer(); | ||
236 | |||
237 | $transformer->transform('foo'); | ||
238 | } | ||
239 | |||
240 | /** | ||
241 | * @expectedException \Symfony\Component\Form\Exception\TransformationFailedException | ||
242 | */ | ||
243 | public function testReverseTransformExpectsString() | ||
244 | { | ||
245 | $transformer = new NumberToLocalizedStringTransformer(); | ||
246 | |||
247 | $transformer->reverseTransform(1); | ||
248 | } | ||
249 | |||
250 | /** | ||
251 | * @expectedException \Symfony\Component\Form\Exception\TransformationFailedException | ||
252 | */ | ||
253 | public function testReverseTransformExpectsValidNumber() | ||
254 | { | ||
255 | $transformer = new NumberToLocalizedStringTransformer(); | ||
256 | |||
257 | $transformer->reverseTransform('foo'); | ||
258 | } | ||
259 | |||
260 | /** | ||
261 | * @expectedException \Symfony\Component\Form\Exception\TransformationFailedException | ||
262 | * @link https://github.com/symfony/symfony/issues/3161 | ||
263 | */ | ||
264 | public function testReverseTransformDisallowsNaN() | ||
265 | { | ||
266 | $transformer = new NumberToLocalizedStringTransformer(); | ||
267 | |||
268 | $transformer->reverseTransform('NaN'); | ||
269 | } | ||
270 | |||
271 | /** | ||
272 | * @expectedException \Symfony\Component\Form\Exception\TransformationFailedException | ||
273 | */ | ||
274 | public function testReverseTransformDisallowsNaN2() | ||
275 | { | ||
276 | $transformer = new NumberToLocalizedStringTransformer(); | ||
277 | |||
278 | $transformer->reverseTransform('nan'); | ||
279 | } | ||
280 | |||
281 | /** | ||
282 | * @expectedException \Symfony\Component\Form\Exception\TransformationFailedException | ||
283 | */ | ||
284 | public function testReverseTransformDisallowsInfinity() | ||
285 | { | ||
286 | $transformer = new NumberToLocalizedStringTransformer(); | ||
287 | |||
288 | $transformer->reverseTransform('∞'); | ||
289 | } | ||
290 | |||
291 | /** | ||
292 | * @expectedException \Symfony\Component\Form\Exception\TransformationFailedException | ||
293 | */ | ||
294 | public function testReverseTransformDisallowsInfinity2() | ||
295 | { | ||
296 | $transformer = new NumberToLocalizedStringTransformer(); | ||
297 | |||
298 | $transformer->reverseTransform('∞,123'); | ||
299 | } | ||
300 | |||
301 | /** | ||
302 | * @expectedException \Symfony\Component\Form\Exception\TransformationFailedException | ||
303 | */ | ||
304 | public function testReverseTransformDisallowsNegativeInfinity() | ||
305 | { | ||
306 | $transformer = new NumberToLocalizedStringTransformer(); | ||
307 | |||
308 | $transformer->reverseTransform('-∞'); | ||
309 | } | ||
310 | |||
311 | /** | ||
312 | * @expectedException \Symfony\Component\Form\Exception\TransformationFailedException | ||
313 | */ | ||
314 | public function testReverseTransformDisallowsLeadingExtraCharacters() | ||
315 | { | ||
316 | $transformer = new NumberToLocalizedStringTransformer(); | ||
317 | |||
318 | $transformer->reverseTransform('foo123'); | ||
319 | } | ||
320 | |||
321 | /** | ||
322 | * @expectedException \Symfony\Component\Form\Exception\TransformationFailedException | ||
323 | * @expectedExceptionMessage The number contains unrecognized characters: "foo3" | ||
324 | */ | ||
325 | public function testReverseTransformDisallowsCenteredExtraCharacters() | ||
326 | { | ||
327 | $transformer = new NumberToLocalizedStringTransformer(); | ||
328 | |||
329 | $transformer->reverseTransform('12foo3'); | ||
330 | } | ||
331 | |||
332 | /** | ||
333 | * @expectedException \Symfony\Component\Form\Exception\TransformationFailedException | ||
334 | * @expectedExceptionMessage The number contains unrecognized characters: "foo8" | ||
335 | */ | ||
336 | public function testReverseTransformDisallowsCenteredExtraCharactersMultibyte() | ||
337 | { | ||
338 | if (!extension_loaded('mbstring')) { | ||
339 | $this->markTestSkipped('The "mbstring" extension is required for this test.'); | ||
340 | } | ||
341 | |||
342 | \Locale::setDefault('ru'); | ||
343 | |||
344 | $transformer = new NumberToLocalizedStringTransformer(null, true); | ||
345 | |||
346 | $transformer->reverseTransform("12\xc2\xa0345,67foo8"); | ||
347 | } | ||
348 | |||
349 | /** | ||
350 | * @expectedException \Symfony\Component\Form\Exception\TransformationFailedException | ||
351 | * @expectedExceptionMessage The number contains unrecognized characters: "foo8" | ||
352 | */ | ||
353 | public function testReverseTransformIgnoresTrailingSpacesInExceptionMessage() | ||
354 | { | ||
355 | if (!extension_loaded('mbstring')) { | ||
356 | $this->markTestSkipped('The "mbstring" extension is required for this test.'); | ||
357 | } | ||
358 | |||
359 | \Locale::setDefault('ru'); | ||
360 | |||
361 | $transformer = new NumberToLocalizedStringTransformer(null, true); | ||
362 | |||
363 | $transformer->reverseTransform("12\xc2\xa0345,67foo8 \xc2\xa0\t"); | ||
364 | } | ||
365 | |||
366 | /** | ||
367 | * @expectedException \Symfony\Component\Form\Exception\TransformationFailedException | ||
368 | * @expectedExceptionMessage The number contains unrecognized characters: "foo" | ||
369 | */ | ||
370 | public function testReverseTransformDisallowsTrailingExtraCharacters() | ||
371 | { | ||
372 | $transformer = new NumberToLocalizedStringTransformer(); | ||
373 | |||
374 | $transformer->reverseTransform('123foo'); | ||
375 | } | ||
376 | |||
377 | /** | ||
378 | * @expectedException \Symfony\Component\Form\Exception\TransformationFailedException | ||
379 | * @expectedExceptionMessage The number contains unrecognized characters: "foo" | ||
380 | */ | ||
381 | public function testReverseTransformDisallowsTrailingExtraCharactersMultibyte() | ||
382 | { | ||
383 | if (!extension_loaded('mbstring')) { | ||
384 | $this->markTestSkipped('The "mbstring" extension is required for this test.'); | ||
385 | } | ||
386 | |||
387 | \Locale::setDefault('ru'); | ||
388 | |||
389 | $transformer = new NumberToLocalizedStringTransformer(null, true); | ||
390 | |||
391 | $transformer->reverseTransform("12\xc2\xa0345,678foo"); | ||
392 | } | ||
393 | } | ||
diff --git a/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/PercentToLocalizedStringTransformerTest.php b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/PercentToLocalizedStringTransformerTest.php new file mode 100644 index 00000000..104941c9 --- /dev/null +++ b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/PercentToLocalizedStringTransformerTest.php | |||
@@ -0,0 +1,114 @@ | |||
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\DataTransformer; | ||
13 | |||
14 | use Symfony\Component\Form\Extension\Core\DataTransformer\PercentToLocalizedStringTransformer; | ||
15 | use Symfony\Component\Intl\Util\IntlTestHelper; | ||
16 | |||
17 | class PercentToLocalizedStringTransformerTest extends \PHPUnit_Framework_TestCase | ||
18 | { | ||
19 | protected function setUp() | ||
20 | { | ||
21 | parent::setUp(); | ||
22 | |||
23 | // Since we test against "de_AT", we need the full implementation | ||
24 | IntlTestHelper::requireFullIntl($this); | ||
25 | |||
26 | \Locale::setDefault('de_AT'); | ||
27 | } | ||
28 | |||
29 | public function testTransform() | ||
30 | { | ||
31 | $transformer = new PercentToLocalizedStringTransformer(); | ||
32 | |||
33 | $this->assertEquals('10', $transformer->transform(0.1)); | ||
34 | $this->assertEquals('15', $transformer->transform(0.15)); | ||
35 | $this->assertEquals('12', $transformer->transform(0.1234)); | ||
36 | $this->assertEquals('200', $transformer->transform(2)); | ||
37 | } | ||
38 | |||
39 | public function testTransformEmpty() | ||
40 | { | ||
41 | $transformer = new PercentToLocalizedStringTransformer(); | ||
42 | |||
43 | $this->assertEquals('', $transformer->transform(null)); | ||
44 | } | ||
45 | |||
46 | public function testTransformWithInteger() | ||
47 | { | ||
48 | $transformer = new PercentToLocalizedStringTransformer(null, 'integer'); | ||
49 | |||
50 | $this->assertEquals('0', $transformer->transform(0.1)); | ||
51 | $this->assertEquals('1', $transformer->transform(1)); | ||
52 | $this->assertEquals('15', $transformer->transform(15)); | ||
53 | $this->assertEquals('16', $transformer->transform(15.9)); | ||
54 | } | ||
55 | |||
56 | public function testTransformWithPrecision() | ||
57 | { | ||
58 | $transformer = new PercentToLocalizedStringTransformer(2); | ||
59 | |||
60 | $this->assertEquals('12,34', $transformer->transform(0.1234)); | ||
61 | } | ||
62 | |||
63 | public function testReverseTransform() | ||
64 | { | ||
65 | $transformer = new PercentToLocalizedStringTransformer(); | ||
66 | |||
67 | $this->assertEquals(0.1, $transformer->reverseTransform('10')); | ||
68 | $this->assertEquals(0.15, $transformer->reverseTransform('15')); | ||
69 | $this->assertEquals(0.12, $transformer->reverseTransform('12')); | ||
70 | $this->assertEquals(2, $transformer->reverseTransform('200')); | ||
71 | } | ||
72 | |||
73 | public function testReverseTransformEmpty() | ||
74 | { | ||
75 | $transformer = new PercentToLocalizedStringTransformer(); | ||
76 | |||
77 | $this->assertNull($transformer->reverseTransform('')); | ||
78 | } | ||
79 | |||
80 | public function testReverseTransformWithInteger() | ||
81 | { | ||
82 | $transformer = new PercentToLocalizedStringTransformer(null, 'integer'); | ||
83 | |||
84 | $this->assertEquals(10, $transformer->reverseTransform('10')); | ||
85 | $this->assertEquals(15, $transformer->reverseTransform('15')); | ||
86 | $this->assertEquals(12, $transformer->reverseTransform('12')); | ||
87 | $this->assertEquals(200, $transformer->reverseTransform('200')); | ||
88 | } | ||
89 | |||
90 | public function testReverseTransformWithPrecision() | ||
91 | { | ||
92 | $transformer = new PercentToLocalizedStringTransformer(2); | ||
93 | |||
94 | $this->assertEquals(0.1234, $transformer->reverseTransform('12,34')); | ||
95 | } | ||
96 | |||
97 | public function testTransformExpectsNumeric() | ||
98 | { | ||
99 | $transformer = new PercentToLocalizedStringTransformer(); | ||
100 | |||
101 | $this->setExpectedException('Symfony\Component\Form\Exception\TransformationFailedException'); | ||
102 | |||
103 | $transformer->transform('foo'); | ||
104 | } | ||
105 | |||
106 | public function testReverseTransformExpectsString() | ||
107 | { | ||
108 | $transformer = new PercentToLocalizedStringTransformer(); | ||
109 | |||
110 | $this->setExpectedException('Symfony\Component\Form\Exception\TransformationFailedException'); | ||
111 | |||
112 | $transformer->reverseTransform(1); | ||
113 | } | ||
114 | } | ||
diff --git a/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/ValueToDuplicatesTransformerTest.php b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/ValueToDuplicatesTransformerTest.php new file mode 100644 index 00000000..2c5298da --- /dev/null +++ b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/ValueToDuplicatesTransformerTest.php | |||
@@ -0,0 +1,120 @@ | |||
1 | <?php | ||
2 | |||
3 | /* | ||
4 | * This file is part of the Symfony package. | ||
5 | * | ||
6 | * (c) Fabien Potencier <fabien.potencier@symfony-project.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\DataTransformer; | ||
13 | |||
14 | use Symfony\Component\Form\Extension\Core\DataTransformer\ValueToDuplicatesTransformer; | ||
15 | |||
16 | class ValueToDuplicatesTransformerTest extends \PHPUnit_Framework_TestCase | ||
17 | { | ||
18 | private $transformer; | ||
19 | |||
20 | protected function setUp() | ||
21 | { | ||
22 | $this->transformer = new ValueToDuplicatesTransformer(array('a', 'b', 'c')); | ||
23 | } | ||
24 | |||
25 | protected function tearDown() | ||
26 | { | ||
27 | $this->transformer = null; | ||
28 | } | ||
29 | |||
30 | public function testTransform() | ||
31 | { | ||
32 | $output = array( | ||
33 | 'a' => 'Foo', | ||
34 | 'b' => 'Foo', | ||
35 | 'c' => 'Foo', | ||
36 | ); | ||
37 | |||
38 | $this->assertSame($output, $this->transformer->transform('Foo')); | ||
39 | } | ||
40 | |||
41 | public function testTransformEmpty() | ||
42 | { | ||
43 | $output = array( | ||
44 | 'a' => null, | ||
45 | 'b' => null, | ||
46 | 'c' => null, | ||
47 | ); | ||
48 | |||
49 | $this->assertSame($output, $this->transformer->transform(null)); | ||
50 | } | ||
51 | |||
52 | public function testReverseTransform() | ||
53 | { | ||
54 | $input = array( | ||
55 | 'a' => 'Foo', | ||
56 | 'b' => 'Foo', | ||
57 | 'c' => 'Foo', | ||
58 | ); | ||
59 | |||
60 | $this->assertSame('Foo', $this->transformer->reverseTransform($input)); | ||
61 | } | ||
62 | |||
63 | public function testReverseTransformCompletelyEmpty() | ||
64 | { | ||
65 | $input = array( | ||
66 | 'a' => '', | ||
67 | 'b' => '', | ||
68 | 'c' => '', | ||
69 | ); | ||
70 | |||
71 | $this->assertNull($this->transformer->reverseTransform($input)); | ||
72 | } | ||
73 | |||
74 | public function testReverseTransformCompletelyNull() | ||
75 | { | ||
76 | $input = array( | ||
77 | 'a' => null, | ||
78 | 'b' => null, | ||
79 | 'c' => null, | ||
80 | ); | ||
81 | |||
82 | $this->assertNull($this->transformer->reverseTransform($input)); | ||
83 | } | ||
84 | |||
85 | /** | ||
86 | * @expectedException \Symfony\Component\Form\Exception\TransformationFailedException | ||
87 | */ | ||
88 | public function testReverseTransformPartiallyNull() | ||
89 | { | ||
90 | $input = array( | ||
91 | 'a' => 'Foo', | ||
92 | 'b' => 'Foo', | ||
93 | 'c' => null, | ||
94 | ); | ||
95 | |||
96 | $this->transformer->reverseTransform($input); | ||
97 | } | ||
98 | |||
99 | /** | ||
100 | * @expectedException \Symfony\Component\Form\Exception\TransformationFailedException | ||
101 | */ | ||
102 | public function testReverseTransformDifferences() | ||
103 | { | ||
104 | $input = array( | ||
105 | 'a' => 'Foo', | ||
106 | 'b' => 'Bar', | ||
107 | 'c' => 'Foo', | ||
108 | ); | ||
109 | |||
110 | $this->transformer->reverseTransform($input); | ||
111 | } | ||
112 | |||
113 | /** | ||
114 | * @expectedException \Symfony\Component\Form\Exception\TransformationFailedException | ||
115 | */ | ||
116 | public function testReverseTransformRequiresArray() | ||
117 | { | ||
118 | $this->transformer->reverseTransform('12345'); | ||
119 | } | ||
120 | } | ||
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 | } | ||
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 new file mode 100644 index 00000000..2b84e4fd --- /dev/null +++ b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/EventListener/FixUrlProtocolListenerTest.php | |||
@@ -0,0 +1,61 @@ | |||
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 new file mode 100644 index 00000000..b636f4b8 --- /dev/null +++ b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/EventListener/Fixtures/randomhash | |||
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 new file mode 100644 index 00000000..6f46c9d7 --- /dev/null +++ b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/EventListener/MergeCollectionListenerArrayObjectTest.php | |||
@@ -0,0 +1,27 @@ | |||
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 new file mode 100644 index 00000000..c0f3d597 --- /dev/null +++ b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/EventListener/MergeCollectionListenerArrayTest.php | |||
@@ -0,0 +1,27 @@ | |||
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 new file mode 100644 index 00000000..5eb6c7b9 --- /dev/null +++ b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/EventListener/MergeCollectionListenerCustomArrayObjectTest.php | |||
@@ -0,0 +1,28 @@ | |||
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 new file mode 100644 index 00000000..dbd28c6b --- /dev/null +++ b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/EventListener/MergeCollectionListenerTest.php | |||
@@ -0,0 +1,259 @@ | |||
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 new file mode 100644 index 00000000..1367b3ef --- /dev/null +++ b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/EventListener/ResizeFormListenerTest.php | |||
@@ -0,0 +1,255 @@ | |||
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 new file mode 100644 index 00000000..4e368933 --- /dev/null +++ b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/EventListener/TrimListenerTest.php | |||
@@ -0,0 +1,79 @@ | |||
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 | } | ||
diff --git a/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/Type/BaseTypeTest.php b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/Type/BaseTypeTest.php new file mode 100644 index 00000000..bfa1e218 --- /dev/null +++ b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/Type/BaseTypeTest.php | |||
@@ -0,0 +1,135 @@ | |||
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 | /** | ||
15 | * @author Bernhard Schussek <bschussek@gmail.com> | ||
16 | */ | ||
17 | abstract class BaseTypeTest extends \Symfony\Component\Form\Test\TypeTestCase | ||
18 | { | ||
19 | public function testPassDisabledAsOption() | ||
20 | { | ||
21 | $form = $this->factory->create($this->getTestedType(), null, array('disabled' => true)); | ||
22 | |||
23 | $this->assertTrue($form->isDisabled()); | ||
24 | } | ||
25 | |||
26 | public function testPassIdAndNameToView() | ||
27 | { | ||
28 | $view = $this->factory->createNamed('name', $this->getTestedType()) | ||
29 | ->createView(); | ||
30 | |||
31 | $this->assertEquals('name', $view->vars['id']); | ||
32 | $this->assertEquals('name', $view->vars['name']); | ||
33 | $this->assertEquals('name', $view->vars['full_name']); | ||
34 | } | ||
35 | |||
36 | public function testStripLeadingUnderscoresAndDigitsFromId() | ||
37 | { | ||
38 | $view = $this->factory->createNamed('_09name', $this->getTestedType()) | ||
39 | ->createView(); | ||
40 | |||
41 | $this->assertEquals('name', $view->vars['id']); | ||
42 | $this->assertEquals('_09name', $view->vars['name']); | ||
43 | $this->assertEquals('_09name', $view->vars['full_name']); | ||
44 | } | ||
45 | |||
46 | public function testPassIdAndNameToViewWithParent() | ||
47 | { | ||
48 | $view = $this->factory->createNamedBuilder('parent', 'form') | ||
49 | ->add('child', $this->getTestedType()) | ||
50 | ->getForm() | ||
51 | ->createView(); | ||
52 | |||
53 | $this->assertEquals('parent_child', $view['child']->vars['id']); | ||
54 | $this->assertEquals('child', $view['child']->vars['name']); | ||
55 | $this->assertEquals('parent[child]', $view['child']->vars['full_name']); | ||
56 | } | ||
57 | |||
58 | public function testPassIdAndNameToViewWithGrandParent() | ||
59 | { | ||
60 | $builder = $this->factory->createNamedBuilder('parent', 'form') | ||
61 | ->add('child', 'form'); | ||
62 | $builder->get('child')->add('grand_child', $this->getTestedType()); | ||
63 | $view = $builder->getForm()->createView(); | ||
64 | |||
65 | $this->assertEquals('parent_child_grand_child', $view['child']['grand_child']->vars['id']); | ||
66 | $this->assertEquals('grand_child', $view['child']['grand_child']->vars['name']); | ||
67 | $this->assertEquals('parent[child][grand_child]', $view['child']['grand_child']->vars['full_name']); | ||
68 | } | ||
69 | |||
70 | public function testPassTranslationDomainToView() | ||
71 | { | ||
72 | $form = $this->factory->create($this->getTestedType(), null, array( | ||
73 | 'translation_domain' => 'domain', | ||
74 | )); | ||
75 | $view = $form->createView(); | ||
76 | |||
77 | $this->assertSame('domain', $view->vars['translation_domain']); | ||
78 | } | ||
79 | |||
80 | public function testInheritTranslationDomainFromParent() | ||
81 | { | ||
82 | $view = $this->factory | ||
83 | ->createNamedBuilder('parent', 'form', null, array( | ||
84 | 'translation_domain' => 'domain', | ||
85 | )) | ||
86 | ->add('child', $this->getTestedType()) | ||
87 | ->getForm() | ||
88 | ->createView(); | ||
89 | |||
90 | $this->assertEquals('domain', $view['child']->vars['translation_domain']); | ||
91 | } | ||
92 | |||
93 | public function testPreferOwnTranslationDomain() | ||
94 | { | ||
95 | $view = $this->factory | ||
96 | ->createNamedBuilder('parent', 'form', null, array( | ||
97 | 'translation_domain' => 'parent_domain', | ||
98 | )) | ||
99 | ->add('child', $this->getTestedType(), array( | ||
100 | 'translation_domain' => 'domain', | ||
101 | )) | ||
102 | ->getForm() | ||
103 | ->createView(); | ||
104 | |||
105 | $this->assertEquals('domain', $view['child']->vars['translation_domain']); | ||
106 | } | ||
107 | |||
108 | public function testDefaultTranslationDomain() | ||
109 | { | ||
110 | $view = $this->factory->createNamedBuilder('parent', 'form') | ||
111 | ->add('child', $this->getTestedType()) | ||
112 | ->getForm() | ||
113 | ->createView(); | ||
114 | |||
115 | $this->assertEquals('messages', $view['child']->vars['translation_domain']); | ||
116 | } | ||
117 | |||
118 | public function testPassLabelToView() | ||
119 | { | ||
120 | $form = $this->factory->createNamed('__test___field', $this->getTestedType(), null, array('label' => 'My label')); | ||
121 | $view = $form->createView(); | ||
122 | |||
123 | $this->assertSame('My label', $view->vars['label']); | ||
124 | } | ||
125 | |||
126 | public function testPassMultipartFalseToView() | ||
127 | { | ||
128 | $form = $this->factory->create($this->getTestedType()); | ||
129 | $view = $form->createView(); | ||
130 | |||
131 | $this->assertFalse($view->vars['multipart']); | ||
132 | } | ||
133 | |||
134 | abstract protected function getTestedType(); | ||
135 | } | ||
diff --git a/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/Type/ButtonTypeTest.php b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/Type/ButtonTypeTest.php new file mode 100644 index 00000000..55835e77 --- /dev/null +++ b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/Type/ButtonTypeTest.php | |||
@@ -0,0 +1,28 @@ | |||
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 | /** | ||
15 | * @author Bernhard Schussek <bschussek@gmail.com> | ||
16 | */ | ||
17 | class ButtonTypeTest extends BaseTypeTest | ||
18 | { | ||
19 | public function testCreateButtonInstances() | ||
20 | { | ||
21 | $this->assertInstanceOf('Symfony\Component\Form\Button', $this->factory->create('button')); | ||
22 | } | ||
23 | |||
24 | protected function getTestedType() | ||
25 | { | ||
26 | return 'button'; | ||
27 | } | ||
28 | } | ||
diff --git a/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/Type/CheckboxTypeTest.php b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/Type/CheckboxTypeTest.php new file mode 100644 index 00000000..c782adab --- /dev/null +++ b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/Type/CheckboxTypeTest.php | |||
@@ -0,0 +1,162 @@ | |||
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\CallbackTransformer; | ||
15 | |||
16 | class CheckboxTypeTest extends \Symfony\Component\Form\Test\TypeTestCase | ||
17 | { | ||
18 | public function testPassValueToView() | ||
19 | { | ||
20 | $form = $this->factory->create('checkbox', null, array('value' => 'foobar')); | ||
21 | $view = $form->createView(); | ||
22 | |||
23 | $this->assertEquals('foobar', $view->vars['value']); | ||
24 | } | ||
25 | |||
26 | public function testCheckedIfDataTrue() | ||
27 | { | ||
28 | $form = $this->factory->create('checkbox'); | ||
29 | $form->setData(true); | ||
30 | $view = $form->createView(); | ||
31 | |||
32 | $this->assertTrue($view->vars['checked']); | ||
33 | } | ||
34 | |||
35 | public function testCheckedIfDataTrueWithEmptyValue() | ||
36 | { | ||
37 | $form = $this->factory->create('checkbox', null, array('value' => '')); | ||
38 | $form->setData(true); | ||
39 | $view = $form->createView(); | ||
40 | |||
41 | $this->assertTrue($view->vars['checked']); | ||
42 | } | ||
43 | |||
44 | public function testNotCheckedIfDataFalse() | ||
45 | { | ||
46 | $form = $this->factory->create('checkbox'); | ||
47 | $form->setData(false); | ||
48 | $view = $form->createView(); | ||
49 | |||
50 | $this->assertFalse($view->vars['checked']); | ||
51 | } | ||
52 | |||
53 | public function testSubmitWithValueChecked() | ||
54 | { | ||
55 | $form = $this->factory->create('checkbox', null, array( | ||
56 | 'value' => 'foobar', | ||
57 | )); | ||
58 | $form->submit('foobar'); | ||
59 | |||
60 | $this->assertTrue($form->getData()); | ||
61 | $this->assertEquals('foobar', $form->getViewData()); | ||
62 | } | ||
63 | |||
64 | public function testSubmitWithRandomValueChecked() | ||
65 | { | ||
66 | $form = $this->factory->create('checkbox', null, array( | ||
67 | 'value' => 'foobar', | ||
68 | )); | ||
69 | $form->submit('krixikraxi'); | ||
70 | |||
71 | $this->assertTrue($form->getData()); | ||
72 | $this->assertEquals('foobar', $form->getViewData()); | ||
73 | } | ||
74 | |||
75 | public function testSubmitWithValueUnchecked() | ||
76 | { | ||
77 | $form = $this->factory->create('checkbox', null, array( | ||
78 | 'value' => 'foobar', | ||
79 | )); | ||
80 | $form->submit(null); | ||
81 | |||
82 | $this->assertFalse($form->getData()); | ||
83 | $this->assertNull($form->getViewData()); | ||
84 | } | ||
85 | |||
86 | public function testSubmitWithEmptyValueChecked() | ||
87 | { | ||
88 | $form = $this->factory->create('checkbox', null, array( | ||
89 | 'value' => '', | ||
90 | )); | ||
91 | $form->submit(''); | ||
92 | |||
93 | $this->assertTrue($form->getData()); | ||
94 | $this->assertSame('', $form->getViewData()); | ||
95 | } | ||
96 | |||
97 | public function testSubmitWithEmptyValueUnchecked() | ||
98 | { | ||
99 | $form = $this->factory->create('checkbox', null, array( | ||
100 | 'value' => '', | ||
101 | )); | ||
102 | $form->submit(null); | ||
103 | |||
104 | $this->assertFalse($form->getData()); | ||
105 | $this->assertNull($form->getViewData()); | ||
106 | } | ||
107 | |||
108 | public function testBindWithEmptyValueAndFalseUnchecked() | ||
109 | { | ||
110 | $form = $this->factory->create('checkbox', null, array( | ||
111 | 'value' => '', | ||
112 | )); | ||
113 | $form->bind(false); | ||
114 | |||
115 | $this->assertFalse($form->getData()); | ||
116 | $this->assertNull($form->getViewData()); | ||
117 | } | ||
118 | |||
119 | public function testBindWithEmptyValueAndTrueChecked() | ||
120 | { | ||
121 | $form = $this->factory->create('checkbox', null, array( | ||
122 | 'value' => '', | ||
123 | )); | ||
124 | $form->bind(true); | ||
125 | |||
126 | $this->assertTrue($form->getData()); | ||
127 | $this->assertSame('', $form->getViewData()); | ||
128 | } | ||
129 | |||
130 | /** | ||
131 | * @dataProvider provideTransformedData | ||
132 | */ | ||
133 | public function testTransformedData($data, $expected) | ||
134 | { | ||
135 | // present a binary status field as a checkbox | ||
136 | $transformer = new CallbackTransformer( | ||
137 | function ($value) { | ||
138 | return 'expedited' == $value; | ||
139 | }, | ||
140 | function ($value) { | ||
141 | return $value ? 'expedited' : 'standard'; | ||
142 | } | ||
143 | ); | ||
144 | |||
145 | $form = $this->builder | ||
146 | ->create('expedited_shipping', 'checkbox') | ||
147 | ->addModelTransformer($transformer) | ||
148 | ->getForm(); | ||
149 | $form->setData($data); | ||
150 | $view = $form->createView(); | ||
151 | |||
152 | $this->assertEquals($expected, $view->vars['checked']); | ||
153 | } | ||
154 | |||
155 | public function provideTransformedData() | ||
156 | { | ||
157 | return array( | ||
158 | array('expedited', true), | ||
159 | array('standard', false), | ||
160 | ); | ||
161 | } | ||
162 | } | ||
diff --git a/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypePerformanceTest.php b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypePerformanceTest.php new file mode 100644 index 00000000..0685946f --- /dev/null +++ b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypePerformanceTest.php | |||
@@ -0,0 +1,38 @@ | |||
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\Test\FormPerformanceTestCase; | ||
15 | |||
16 | /** | ||
17 | * @author Bernhard Schussek <bschussek@gmail.com> | ||
18 | */ | ||
19 | class ChoiceTypePerformanceTest extends FormPerformanceTestCase | ||
20 | { | ||
21 | /** | ||
22 | * This test case is realistic in collection forms where each | ||
23 | * row contains the same choice field. | ||
24 | * | ||
25 | * @group benchmark | ||
26 | */ | ||
27 | public function testSameChoiceFieldCreatedMultipleTimes() | ||
28 | { | ||
29 | $this->setMaxRunningTime(1); | ||
30 | $choices = range(1, 300); | ||
31 | |||
32 | for ($i = 0; $i < 100; ++$i) { | ||
33 | $this->factory->create('choice', rand(1, 400), array( | ||
34 | 'choices' => $choices, | ||
35 | )); | ||
36 | } | ||
37 | } | ||
38 | } | ||
diff --git a/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php new file mode 100644 index 00000000..219e8181 --- /dev/null +++ b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php | |||
@@ -0,0 +1,949 @@ | |||
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\Extension\Core\ChoiceList\ObjectChoiceList; | ||
15 | use Symfony\Component\Form\Extension\Core\View\ChoiceView; | ||
16 | |||
17 | class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase | ||
18 | { | ||
19 | private $choices = array( | ||
20 | 'a' => 'Bernhard', | ||
21 | 'b' => 'Fabien', | ||
22 | 'c' => 'Kris', | ||
23 | 'd' => 'Jon', | ||
24 | 'e' => 'Roman', | ||
25 | ); | ||
26 | |||
27 | private $numericChoices = array( | ||
28 | 0 => 'Bernhard', | ||
29 | 1 => 'Fabien', | ||
30 | 2 => 'Kris', | ||
31 | 3 => 'Jon', | ||
32 | 4 => 'Roman', | ||
33 | ); | ||
34 | |||
35 | private $objectChoices; | ||
36 | |||
37 | protected $groupedChoices = array( | ||
38 | 'Symfony' => array( | ||
39 | 'a' => 'Bernhard', | ||
40 | 'b' => 'Fabien', | ||
41 | 'c' => 'Kris', | ||
42 | ), | ||
43 | 'Doctrine' => array( | ||
44 | 'd' => 'Jon', | ||
45 | 'e' => 'Roman', | ||
46 | ) | ||
47 | ); | ||
48 | |||
49 | protected function setUp() | ||
50 | { | ||
51 | parent::setUp(); | ||
52 | |||
53 | $this->objectChoices = array( | ||
54 | (object) array('id' => 1, 'name' => 'Bernhard'), | ||
55 | (object) array('id' => 2, 'name' => 'Fabien'), | ||
56 | (object) array('id' => 3, 'name' => 'Kris'), | ||
57 | (object) array('id' => 4, 'name' => 'Jon'), | ||
58 | (object) array('id' => 5, 'name' => 'Roman'), | ||
59 | ); | ||
60 | } | ||
61 | |||
62 | protected function tearDown() | ||
63 | { | ||
64 | parent::tearDown(); | ||
65 | |||
66 | $this->objectChoices = null; | ||
67 | } | ||
68 | |||
69 | /** | ||
70 | * @expectedException \PHPUnit_Framework_Error | ||
71 | */ | ||
72 | public function testChoicesOptionExpectsArray() | ||
73 | { | ||
74 | $this->factory->create('choice', null, array( | ||
75 | 'choices' => new \ArrayObject(), | ||
76 | )); | ||
77 | } | ||
78 | |||
79 | /** | ||
80 | * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException | ||
81 | */ | ||
82 | public function testChoiceListOptionExpectsChoiceListInterface() | ||
83 | { | ||
84 | $this->factory->create('choice', null, array( | ||
85 | 'choice_list' => array('foo' => 'foo'), | ||
86 | )); | ||
87 | } | ||
88 | |||
89 | public function testChoiceListAndChoicesCanBeEmpty() | ||
90 | { | ||
91 | $this->factory->create('choice'); | ||
92 | } | ||
93 | |||
94 | public function testExpandedChoicesOptionsTurnIntoChildren() | ||
95 | { | ||
96 | $form = $this->factory->create('choice', null, array( | ||
97 | 'expanded' => true, | ||
98 | 'choices' => $this->choices, | ||
99 | )); | ||
100 | |||
101 | $this->assertCount(count($this->choices), $form, 'Each choice should become a new field'); | ||
102 | } | ||
103 | |||
104 | public function testPlaceholderPresentOnNonRequiredExpandedSingleChoice() | ||
105 | { | ||
106 | $form = $this->factory->create('choice', null, array( | ||
107 | 'multiple' => false, | ||
108 | 'expanded' => true, | ||
109 | 'required' => false, | ||
110 | 'choices' => $this->choices, | ||
111 | )); | ||
112 | |||
113 | $this->assertTrue(isset($form['placeholder'])); | ||
114 | $this->assertCount(count($this->choices) + 1, $form, 'Each choice should become a new field'); | ||
115 | } | ||
116 | |||
117 | public function testPlaceholderNotPresentIfRequired() | ||
118 | { | ||
119 | $form = $this->factory->create('choice', null, array( | ||
120 | 'multiple' => false, | ||
121 | 'expanded' => true, | ||
122 | 'required' => true, | ||
123 | 'choices' => $this->choices, | ||
124 | )); | ||
125 | |||
126 | $this->assertFalse(isset($form['placeholder'])); | ||
127 | $this->assertCount(count($this->choices), $form, 'Each choice should become a new field'); | ||
128 | } | ||
129 | |||
130 | public function testPlaceholderNotPresentIfMultiple() | ||
131 | { | ||
132 | $form = $this->factory->create('choice', null, array( | ||
133 | 'multiple' => true, | ||
134 | 'expanded' => true, | ||
135 | 'required' => false, | ||
136 | 'choices' => $this->choices, | ||
137 | )); | ||
138 | |||
139 | $this->assertFalse(isset($form['placeholder'])); | ||
140 | $this->assertCount(count($this->choices), $form, 'Each choice should become a new field'); | ||
141 | } | ||
142 | |||
143 | public function testPlaceholderNotPresentIfEmptyChoice() | ||
144 | { | ||
145 | $form = $this->factory->create('choice', null, array( | ||
146 | 'multiple' => false, | ||
147 | 'expanded' => true, | ||
148 | 'required' => false, | ||
149 | 'choices' => array( | ||
150 | '' => 'Empty', | ||
151 | 1 => 'Not empty', | ||
152 | ), | ||
153 | )); | ||
154 | |||
155 | $this->assertFalse(isset($form['placeholder'])); | ||
156 | $this->assertCount(2, $form, 'Each choice should become a new field'); | ||
157 | } | ||
158 | |||
159 | public function testExpandedChoicesOptionsAreFlattened() | ||
160 | { | ||
161 | $form = $this->factory->create('choice', null, array( | ||
162 | 'expanded' => true, | ||
163 | 'choices' => $this->groupedChoices, | ||
164 | )); | ||
165 | |||
166 | $flattened = array(); | ||
167 | foreach ($this->groupedChoices as $choices) { | ||
168 | $flattened = array_merge($flattened, array_keys($choices)); | ||
169 | } | ||
170 | |||
171 | $this->assertCount($form->count(), $flattened, 'Each nested choice should become a new field, not the groups'); | ||
172 | |||
173 | foreach ($flattened as $value => $choice) { | ||
174 | $this->assertTrue($form->has($value), 'Flattened choice is named after it\'s value'); | ||
175 | } | ||
176 | } | ||
177 | |||
178 | public function testExpandedCheckboxesAreNeverRequired() | ||
179 | { | ||
180 | $form = $this->factory->create('choice', null, array( | ||
181 | 'multiple' => true, | ||
182 | 'expanded' => true, | ||
183 | 'required' => true, | ||
184 | 'choices' => $this->choices, | ||
185 | )); | ||
186 | |||
187 | foreach ($form as $child) { | ||
188 | $this->assertFalse($child->isRequired()); | ||
189 | } | ||
190 | } | ||
191 | |||
192 | public function testExpandedRadiosAreRequiredIfChoiceChildIsRequired() | ||
193 | { | ||
194 | $form = $this->factory->create('choice', null, array( | ||
195 | 'multiple' => false, | ||
196 | 'expanded' => true, | ||
197 | 'required' => true, | ||
198 | 'choices' => $this->choices, | ||
199 | )); | ||
200 | |||
201 | foreach ($form as $child) { | ||
202 | $this->assertTrue($child->isRequired()); | ||
203 | } | ||
204 | } | ||
205 | |||
206 | public function testExpandedRadiosAreNotRequiredIfChoiceChildIsNotRequired() | ||
207 | { | ||
208 | $form = $this->factory->create('choice', null, array( | ||
209 | 'multiple' => false, | ||
210 | 'expanded' => true, | ||
211 | 'required' => false, | ||
212 | 'choices' => $this->choices, | ||
213 | )); | ||
214 | |||
215 | foreach ($form as $child) { | ||
216 | $this->assertFalse($child->isRequired()); | ||
217 | } | ||
218 | } | ||
219 | |||
220 | public function testSubmitSingleNonExpanded() | ||
221 | { | ||
222 | $form = $this->factory->create('choice', null, array( | ||
223 | 'multiple' => false, | ||
224 | 'expanded' => false, | ||
225 | 'choices' => $this->choices, | ||
226 | )); | ||
227 | |||
228 | $form->submit('b'); | ||
229 | |||
230 | $this->assertEquals('b', $form->getData()); | ||
231 | $this->assertEquals('b', $form->getViewData()); | ||
232 | } | ||
233 | |||
234 | public function testSubmitSingleNonExpandedObjectChoices() | ||
235 | { | ||
236 | $form = $this->factory->create('choice', null, array( | ||
237 | 'multiple' => false, | ||
238 | 'expanded' => false, | ||
239 | 'choice_list' => new ObjectChoiceList( | ||
240 | $this->objectChoices, | ||
241 | // label path | ||
242 | 'name', | ||
243 | array(), | ||
244 | null, | ||
245 | // value path | ||
246 | 'id' | ||
247 | ), | ||
248 | )); | ||
249 | |||
250 | // "id" value of the second entry | ||
251 | $form->submit('2'); | ||
252 | |||
253 | $this->assertEquals($this->objectChoices[1], $form->getData()); | ||
254 | $this->assertEquals('2', $form->getViewData()); | ||
255 | } | ||
256 | |||
257 | public function testSubmitMultipleNonExpanded() | ||
258 | { | ||
259 | $form = $this->factory->create('choice', null, array( | ||
260 | 'multiple' => true, | ||
261 | 'expanded' => false, | ||
262 | 'choices' => $this->choices, | ||
263 | )); | ||
264 | |||
265 | $form->submit(array('a', 'b')); | ||
266 | |||
267 | $this->assertEquals(array('a', 'b'), $form->getData()); | ||
268 | $this->assertEquals(array('a', 'b'), $form->getViewData()); | ||
269 | } | ||
270 | |||
271 | public function testSubmitMultipleNonExpandedObjectChoices() | ||
272 | { | ||
273 | $form = $this->factory->create('choice', null, array( | ||
274 | 'multiple' => true, | ||
275 | 'expanded' => false, | ||
276 | 'choice_list' => new ObjectChoiceList( | ||
277 | $this->objectChoices, | ||
278 | // label path | ||
279 | 'name', | ||
280 | array(), | ||
281 | null, | ||
282 | // value path | ||
283 | 'id' | ||
284 | ), | ||
285 | )); | ||
286 | |||
287 | $form->submit(array('2', '3')); | ||
288 | |||
289 | $this->assertEquals(array($this->objectChoices[1], $this->objectChoices[2]), $form->getData()); | ||
290 | $this->assertEquals(array('2', '3'), $form->getViewData()); | ||
291 | } | ||
292 | |||
293 | public function testSubmitSingleExpandedRequired() | ||
294 | { | ||
295 | $form = $this->factory->create('choice', null, array( | ||
296 | 'multiple' => false, | ||
297 | 'expanded' => true, | ||
298 | 'required' => true, | ||
299 | 'choices' => $this->choices, | ||
300 | )); | ||
301 | |||
302 | $form->submit('b'); | ||
303 | |||
304 | $this->assertSame('b', $form->getData()); | ||
305 | $this->assertSame(array( | ||
306 | 0 => false, | ||
307 | 1 => true, | ||
308 | 2 => false, | ||
309 | 3 => false, | ||
310 | 4 => false, | ||
311 | ), $form->getViewData()); | ||
312 | |||
313 | $this->assertFalse($form[0]->getData()); | ||
314 | $this->assertTrue($form[1]->getData()); | ||
315 | $this->assertFalse($form[2]->getData()); | ||
316 | $this->assertFalse($form[3]->getData()); | ||
317 | $this->assertFalse($form[4]->getData()); | ||
318 | $this->assertNull($form[0]->getViewData()); | ||
319 | $this->assertSame('b', $form[1]->getViewData()); | ||
320 | $this->assertNull($form[2]->getViewData()); | ||
321 | $this->assertNull($form[3]->getViewData()); | ||
322 | $this->assertNull($form[4]->getViewData()); | ||
323 | } | ||
324 | |||
325 | public function testSubmitSingleExpandedNonRequired() | ||
326 | { | ||
327 | $form = $this->factory->create('choice', null, array( | ||
328 | 'multiple' => false, | ||
329 | 'expanded' => true, | ||
330 | 'required' => false, | ||
331 | 'choices' => $this->choices, | ||
332 | )); | ||
333 | |||
334 | $form->submit('b'); | ||
335 | |||
336 | $this->assertSame('b', $form->getData()); | ||
337 | $this->assertSame(array( | ||
338 | 0 => false, | ||
339 | 1 => true, | ||
340 | 2 => false, | ||
341 | 3 => false, | ||
342 | 4 => false, | ||
343 | 'placeholder' => false, | ||
344 | ), $form->getViewData()); | ||
345 | |||
346 | $this->assertFalse($form['placeholder']->getData()); | ||
347 | $this->assertFalse($form[0]->getData()); | ||
348 | $this->assertTrue($form[1]->getData()); | ||
349 | $this->assertFalse($form[2]->getData()); | ||
350 | $this->assertFalse($form[3]->getData()); | ||
351 | $this->assertFalse($form[4]->getData()); | ||
352 | $this->assertNull($form['placeholder']->getViewData()); | ||
353 | $this->assertNull($form[0]->getViewData()); | ||
354 | $this->assertSame('b', $form[1]->getViewData()); | ||
355 | $this->assertNull($form[2]->getViewData()); | ||
356 | $this->assertNull($form[3]->getViewData()); | ||
357 | $this->assertNull($form[4]->getViewData()); | ||
358 | } | ||
359 | |||
360 | public function testSubmitSingleExpandedRequiredNothingChecked() | ||
361 | { | ||
362 | $form = $this->factory->create('choice', null, array( | ||
363 | 'multiple' => false, | ||
364 | 'expanded' => true, | ||
365 | 'required' => true, | ||
366 | 'choices' => $this->choices, | ||
367 | )); | ||
368 | |||
369 | $form->submit(null); | ||
370 | |||
371 | $this->assertNull($form->getData()); | ||
372 | $this->assertSame(array( | ||
373 | 0 => false, | ||
374 | 1 => false, | ||
375 | 2 => false, | ||
376 | 3 => false, | ||
377 | 4 => false, | ||
378 | ), $form->getViewData()); | ||
379 | |||
380 | $this->assertFalse($form[0]->getData()); | ||
381 | $this->assertFalse($form[1]->getData()); | ||
382 | $this->assertFalse($form[2]->getData()); | ||
383 | $this->assertFalse($form[3]->getData()); | ||
384 | $this->assertFalse($form[4]->getData()); | ||
385 | $this->assertNull($form[0]->getViewData()); | ||
386 | $this->assertNull($form[1]->getViewData()); | ||
387 | $this->assertNull($form[2]->getViewData()); | ||
388 | $this->assertNull($form[3]->getViewData()); | ||
389 | $this->assertNull($form[4]->getViewData()); | ||
390 | } | ||
391 | |||
392 | public function testSubmitSingleExpandedNonRequiredNothingChecked() | ||
393 | { | ||
394 | $form = $this->factory->create('choice', null, array( | ||
395 | 'multiple' => false, | ||
396 | 'expanded' => true, | ||
397 | 'required' => false, | ||
398 | 'choices' => $this->choices, | ||
399 | )); | ||
400 | |||
401 | $form->submit(null); | ||
402 | |||
403 | $this->assertNull($form->getData()); | ||
404 | $this->assertSame(array( | ||
405 | 0 => false, | ||
406 | 1 => false, | ||
407 | 2 => false, | ||
408 | 3 => false, | ||
409 | 4 => false, | ||
410 | 'placeholder' => true, | ||
411 | ), $form->getViewData()); | ||
412 | |||
413 | $this->assertTrue($form['placeholder']->getData()); | ||
414 | $this->assertFalse($form[0]->getData()); | ||
415 | $this->assertFalse($form[1]->getData()); | ||
416 | $this->assertFalse($form[2]->getData()); | ||
417 | $this->assertFalse($form[3]->getData()); | ||
418 | $this->assertFalse($form[4]->getData()); | ||
419 | $this->assertSame('', $form['placeholder']->getViewData()); | ||
420 | $this->assertNull($form[0]->getViewData()); | ||
421 | $this->assertNull($form[1]->getViewData()); | ||
422 | $this->assertNull($form[2]->getViewData()); | ||
423 | $this->assertNull($form[3]->getViewData()); | ||
424 | $this->assertNull($form[4]->getViewData()); | ||
425 | } | ||
426 | |||
427 | public function testSubmitFalseToSingleExpandedRequiredDoesNotProduceExtraChildrenError() | ||
428 | { | ||
429 | $form = $this->factory->create('choice', null, array( | ||
430 | 'multiple' => false, | ||
431 | 'expanded' => true, | ||
432 | 'required' => true, | ||
433 | 'choices' => $this->choices, | ||
434 | )); | ||
435 | |||
436 | $form->submit(false); | ||
437 | |||
438 | $this->assertEmpty($form->getExtraData()); | ||
439 | $this->assertNull($form->getData()); | ||
440 | } | ||
441 | |||
442 | public function testSubmitFalseToSingleExpandedNonRequiredDoesNotProduceExtraChildrenError() | ||
443 | { | ||
444 | $form = $this->factory->create('choice', null, array( | ||
445 | 'multiple' => false, | ||
446 | 'expanded' => true, | ||
447 | 'required' => false, | ||
448 | 'choices' => $this->choices, | ||
449 | )); | ||
450 | |||
451 | $form->submit(false); | ||
452 | |||
453 | $this->assertEmpty($form->getExtraData()); | ||
454 | $this->assertNull($form->getData()); | ||
455 | } | ||
456 | |||
457 | public function testSubmitSingleExpandedWithEmptyChild() | ||
458 | { | ||
459 | $form = $this->factory->create('choice', null, array( | ||
460 | 'multiple' => false, | ||
461 | 'expanded' => true, | ||
462 | 'choices' => array( | ||
463 | '' => 'Empty', | ||
464 | 1 => 'Not empty', | ||
465 | ), | ||
466 | )); | ||
467 | |||
468 | $form->submit(''); | ||
469 | |||
470 | $this->assertNull($form->getData()); | ||
471 | $this->assertTrue($form[0]->getData()); | ||
472 | $this->assertFalse($form[1]->getData()); | ||
473 | $this->assertSame('', $form[0]->getViewData()); | ||
474 | $this->assertNull($form[1]->getViewData()); | ||
475 | } | ||
476 | |||
477 | public function testSubmitSingleExpandedObjectChoices() | ||
478 | { | ||
479 | $form = $this->factory->create('choice', null, array( | ||
480 | 'multiple' => false, | ||
481 | 'expanded' => true, | ||
482 | 'choice_list' => new ObjectChoiceList( | ||
483 | $this->objectChoices, | ||
484 | // label path | ||
485 | 'name', | ||
486 | array(), | ||
487 | null, | ||
488 | // value path | ||
489 | 'id' | ||
490 | ), | ||
491 | )); | ||
492 | |||
493 | $form->submit('2'); | ||
494 | |||
495 | $this->assertSame($this->objectChoices[1], $form->getData()); | ||
496 | $this->assertFalse($form[0]->getData()); | ||
497 | $this->assertTrue($form[1]->getData()); | ||
498 | $this->assertFalse($form[2]->getData()); | ||
499 | $this->assertFalse($form[3]->getData()); | ||
500 | $this->assertFalse($form[4]->getData()); | ||
501 | $this->assertNull($form[0]->getViewData()); | ||
502 | $this->assertSame('2', $form[1]->getViewData()); | ||
503 | $this->assertNull($form[2]->getViewData()); | ||
504 | $this->assertNull($form[3]->getViewData()); | ||
505 | $this->assertNull($form[4]->getViewData()); | ||
506 | } | ||
507 | |||
508 | public function testSubmitSingleExpandedNumericChoices() | ||
509 | { | ||
510 | $form = $this->factory->create('choice', null, array( | ||
511 | 'multiple' => false, | ||
512 | 'expanded' => true, | ||
513 | 'choices' => $this->numericChoices, | ||
514 | )); | ||
515 | |||
516 | $form->submit('1'); | ||
517 | |||
518 | $this->assertSame(1, $form->getData()); | ||
519 | $this->assertFalse($form[0]->getData()); | ||
520 | $this->assertTrue($form[1]->getData()); | ||
521 | $this->assertFalse($form[2]->getData()); | ||
522 | $this->assertFalse($form[3]->getData()); | ||
523 | $this->assertFalse($form[4]->getData()); | ||
524 | $this->assertNull($form[0]->getViewData()); | ||
525 | $this->assertSame('1', $form[1]->getViewData()); | ||
526 | $this->assertNull($form[2]->getViewData()); | ||
527 | $this->assertNull($form[3]->getViewData()); | ||
528 | $this->assertNull($form[4]->getViewData()); | ||
529 | } | ||
530 | |||
531 | public function testSubmitMultipleExpanded() | ||
532 | { | ||
533 | $form = $this->factory->create('choice', null, array( | ||
534 | 'multiple' => true, | ||
535 | 'expanded' => true, | ||
536 | 'choices' => $this->choices, | ||
537 | )); | ||
538 | |||
539 | $form->submit(array('a', 'c')); | ||
540 | |||
541 | $this->assertSame(array('a', 'c'), $form->getData()); | ||
542 | $this->assertTrue($form[0]->getData()); | ||
543 | $this->assertFalse($form[1]->getData()); | ||
544 | $this->assertTrue($form[2]->getData()); | ||
545 | $this->assertFalse($form[3]->getData()); | ||
546 | $this->assertFalse($form[4]->getData()); | ||
547 | $this->assertSame('a', $form[0]->getViewData()); | ||
548 | $this->assertNull($form[1]->getViewData()); | ||
549 | $this->assertSame('c', $form[2]->getViewData()); | ||
550 | $this->assertNull($form[3]->getViewData()); | ||
551 | $this->assertNull($form[4]->getViewData()); | ||
552 | } | ||
553 | |||
554 | public function testSubmitMultipleExpandedEmpty() | ||
555 | { | ||
556 | $form = $this->factory->create('choice', null, array( | ||
557 | 'multiple' => true, | ||
558 | 'expanded' => true, | ||
559 | 'choices' => $this->choices, | ||
560 | )); | ||
561 | |||
562 | $form->submit(array()); | ||
563 | |||
564 | $this->assertSame(array(), $form->getData()); | ||
565 | $this->assertFalse($form[0]->getData()); | ||
566 | $this->assertFalse($form[1]->getData()); | ||
567 | $this->assertFalse($form[2]->getData()); | ||
568 | $this->assertFalse($form[3]->getData()); | ||
569 | $this->assertFalse($form[4]->getData()); | ||
570 | $this->assertNull($form[0]->getViewData()); | ||
571 | $this->assertNull($form[1]->getViewData()); | ||
572 | $this->assertNull($form[2]->getViewData()); | ||
573 | $this->assertNull($form[3]->getViewData()); | ||
574 | $this->assertNull($form[4]->getViewData()); | ||
575 | } | ||
576 | |||
577 | public function testSubmitMultipleExpandedWithEmptyChild() | ||
578 | { | ||
579 | $form = $this->factory->create('choice', null, array( | ||
580 | 'multiple' => true, | ||
581 | 'expanded' => true, | ||
582 | 'choices' => array( | ||
583 | '' => 'Empty', | ||
584 | 1 => 'Not Empty', | ||
585 | 2 => 'Not Empty 2', | ||
586 | ) | ||
587 | )); | ||
588 | |||
589 | $form->submit(array('', '2')); | ||
590 | |||
591 | $this->assertSame(array('', 2), $form->getData()); | ||
592 | $this->assertTrue($form[0]->getData()); | ||
593 | $this->assertFalse($form[1]->getData()); | ||
594 | $this->assertTrue($form[2]->getData()); | ||
595 | $this->assertSame('', $form[0]->getViewData()); | ||
596 | $this->assertNull($form[1]->getViewData()); | ||
597 | $this->assertSame('2', $form[2]->getViewData()); | ||
598 | } | ||
599 | |||
600 | public function testSubmitMultipleExpandedObjectChoices() | ||
601 | { | ||
602 | $form = $this->factory->create('choice', null, array( | ||
603 | 'multiple' => true, | ||
604 | 'expanded' => true, | ||
605 | 'choice_list' => new ObjectChoiceList( | ||
606 | $this->objectChoices, | ||
607 | // label path | ||
608 | 'name', | ||
609 | array(), | ||
610 | null, | ||
611 | // value path | ||
612 | 'id' | ||
613 | ), | ||
614 | )); | ||
615 | |||
616 | $form->submit(array('1', '2')); | ||
617 | |||
618 | $this->assertSame(array($this->objectChoices[0], $this->objectChoices[1]), $form->getData()); | ||
619 | $this->assertTrue($form[0]->getData()); | ||
620 | $this->assertTrue($form[1]->getData()); | ||
621 | $this->assertFalse($form[2]->getData()); | ||
622 | $this->assertFalse($form[3]->getData()); | ||
623 | $this->assertFalse($form[4]->getData()); | ||
624 | $this->assertSame('1', $form[0]->getViewData()); | ||
625 | $this->assertSame('2', $form[1]->getViewData()); | ||
626 | $this->assertNull($form[2]->getViewData()); | ||
627 | $this->assertNull($form[3]->getViewData()); | ||
628 | $this->assertNull($form[4]->getViewData()); | ||
629 | } | ||
630 | |||
631 | public function testSubmitMultipleExpandedNumericChoices() | ||
632 | { | ||
633 | $form = $this->factory->create('choice', null, array( | ||
634 | 'multiple' => true, | ||
635 | 'expanded' => true, | ||
636 | 'choices' => $this->numericChoices, | ||
637 | )); | ||
638 | |||
639 | $form->submit(array('1', '2')); | ||
640 | |||
641 | $this->assertSame(array(1, 2), $form->getData()); | ||
642 | $this->assertFalse($form[0]->getData()); | ||
643 | $this->assertTrue($form[1]->getData()); | ||
644 | $this->assertTrue($form[2]->getData()); | ||
645 | $this->assertFalse($form[3]->getData()); | ||
646 | $this->assertFalse($form[4]->getData()); | ||
647 | $this->assertNull($form[0]->getViewData()); | ||
648 | $this->assertSame('1', $form[1]->getViewData()); | ||
649 | $this->assertSame('2', $form[2]->getViewData()); | ||
650 | $this->assertNull($form[3]->getViewData()); | ||
651 | $this->assertNull($form[4]->getViewData()); | ||
652 | } | ||
653 | |||
654 | /* | ||
655 | * We need this functionality to create choice fields for Boolean types, | ||
656 | * e.g. false => 'No', true => 'Yes' | ||
657 | */ | ||
658 | public function testSetDataSingleNonExpandedAcceptsBoolean() | ||
659 | { | ||
660 | $form = $this->factory->create('choice', null, array( | ||
661 | 'multiple' => false, | ||
662 | 'expanded' => false, | ||
663 | 'choices' => $this->numericChoices, | ||
664 | )); | ||
665 | |||
666 | $form->setData(false); | ||
667 | |||
668 | $this->assertFalse($form->getData()); | ||
669 | $this->assertEquals('0', $form->getViewData()); | ||
670 | } | ||
671 | |||
672 | public function testSetDataMultipleNonExpandedAcceptsBoolean() | ||
673 | { | ||
674 | $form = $this->factory->create('choice', null, array( | ||
675 | 'multiple' => true, | ||
676 | 'expanded' => false, | ||
677 | 'choices' => $this->numericChoices, | ||
678 | )); | ||
679 | |||
680 | $form->setData(array(false, true)); | ||
681 | |||
682 | $this->assertEquals(array(false, true), $form->getData()); | ||
683 | $this->assertEquals(array('0', '1'), $form->getViewData()); | ||
684 | } | ||
685 | |||
686 | public function testPassRequiredToView() | ||
687 | { | ||
688 | $form = $this->factory->create('choice', null, array( | ||
689 | 'choices' => $this->choices, | ||
690 | )); | ||
691 | $view = $form->createView(); | ||
692 | |||
693 | $this->assertTrue($view->vars['required']); | ||
694 | } | ||
695 | |||
696 | public function testPassNonRequiredToView() | ||
697 | { | ||
698 | $form = $this->factory->create('choice', null, array( | ||
699 | 'required' => false, | ||
700 | 'choices' => $this->choices, | ||
701 | )); | ||
702 | $view = $form->createView(); | ||
703 | |||
704 | $this->assertFalse($view->vars['required']); | ||
705 | } | ||
706 | |||
707 | public function testPassMultipleToView() | ||
708 | { | ||
709 | $form = $this->factory->create('choice', null, array( | ||
710 | 'multiple' => true, | ||
711 | 'choices' => $this->choices, | ||
712 | )); | ||
713 | $view = $form->createView(); | ||
714 | |||
715 | $this->assertTrue($view->vars['multiple']); | ||
716 | } | ||
717 | |||
718 | public function testPassExpandedToView() | ||
719 | { | ||
720 | $form = $this->factory->create('choice', null, array( | ||
721 | 'expanded' => true, | ||
722 | 'choices' => $this->choices, | ||
723 | )); | ||
724 | $view = $form->createView(); | ||
725 | |||
726 | $this->assertTrue($view->vars['expanded']); | ||
727 | } | ||
728 | |||
729 | public function testEmptyValueIsNullByDefaultIfRequired() | ||
730 | { | ||
731 | $form = $this->factory->create('choice', null, array( | ||
732 | 'multiple' => false, | ||
733 | 'required' => true, | ||
734 | 'choices' => $this->choices, | ||
735 | )); | ||
736 | $view = $form->createView(); | ||
737 | |||
738 | $this->assertNull($view->vars['empty_value']); | ||
739 | } | ||
740 | |||
741 | public function testEmptyValueIsEmptyStringByDefaultIfNotRequired() | ||
742 | { | ||
743 | $form = $this->factory->create('choice', null, array( | ||
744 | 'multiple' => false, | ||
745 | 'required' => false, | ||
746 | 'choices' => $this->choices, | ||
747 | )); | ||
748 | $view = $form->createView(); | ||
749 | |||
750 | $this->assertSame('', $view->vars['empty_value']); | ||
751 | } | ||
752 | |||
753 | /** | ||
754 | * @dataProvider getOptionsWithEmptyValue | ||
755 | */ | ||
756 | public function testPassEmptyValueToView($multiple, $expanded, $required, $emptyValue, $viewValue) | ||
757 | { | ||
758 | $form = $this->factory->create('choice', null, array( | ||
759 | 'multiple' => $multiple, | ||
760 | 'expanded' => $expanded, | ||
761 | 'required' => $required, | ||
762 | 'empty_value' => $emptyValue, | ||
763 | 'choices' => $this->choices, | ||
764 | )); | ||
765 | $view = $form->createView(); | ||
766 | |||
767 | $this->assertEquals($viewValue, $view->vars['empty_value']); | ||
768 | } | ||
769 | |||
770 | /** | ||
771 | * @dataProvider getOptionsWithEmptyValue | ||
772 | */ | ||
773 | public function testDontPassEmptyValueIfContainedInChoices($multiple, $expanded, $required, $emptyValue, $viewValue) | ||
774 | { | ||
775 | $form = $this->factory->create('choice', null, array( | ||
776 | 'multiple' => $multiple, | ||
777 | 'expanded' => $expanded, | ||
778 | 'required' => $required, | ||
779 | 'empty_value' => $emptyValue, | ||
780 | 'choices' => array('a' => 'A', '' => 'Empty'), | ||
781 | )); | ||
782 | $view = $form->createView(); | ||
783 | |||
784 | $this->assertNull($view->vars['empty_value']); | ||
785 | } | ||
786 | |||
787 | public function getOptionsWithEmptyValue() | ||
788 | { | ||
789 | return array( | ||
790 | // single non-expanded | ||
791 | array(false, false, false, 'foobar', 'foobar'), | ||
792 | array(false, false, false, '', ''), | ||
793 | array(false, false, false, null, null), | ||
794 | array(false, false, false, false, null), | ||
795 | array(false, false, true, 'foobar', 'foobar'), | ||
796 | array(false, false, true, '', ''), | ||
797 | array(false, false, true, null, null), | ||
798 | array(false, false, true, false, null), | ||
799 | // single expanded | ||
800 | array(false, true, false, 'foobar', 'foobar'), | ||
801 | // radios should never have an empty label | ||
802 | array(false, true, false, '', 'None'), | ||
803 | array(false, true, false, null, null), | ||
804 | array(false, true, false, false, null), | ||
805 | array(false, true, true, 'foobar', 'foobar'), | ||
806 | // radios should never have an empty label | ||
807 | array(false, true, true, '', 'None'), | ||
808 | array(false, true, true, null, null), | ||
809 | array(false, true, true, false, null), | ||
810 | // multiple non-expanded | ||
811 | array(true, false, false, 'foobar', null), | ||
812 | array(true, false, false, '', null), | ||
813 | array(true, false, false, null, null), | ||
814 | array(true, false, false, false, null), | ||
815 | array(true, false, true, 'foobar', null), | ||
816 | array(true, false, true, '', null), | ||
817 | array(true, false, true, null, null), | ||
818 | array(true, false, true, false, null), | ||
819 | // multiple expanded | ||
820 | array(true, true, false, 'foobar', null), | ||
821 | array(true, true, false, '', null), | ||
822 | array(true, true, false, null, null), | ||
823 | array(true, true, false, false, null), | ||
824 | array(true, true, true, 'foobar', null), | ||
825 | array(true, true, true, '', null), | ||
826 | array(true, true, true, null, null), | ||
827 | array(true, true, true, false, null), | ||
828 | ); | ||
829 | } | ||
830 | |||
831 | public function testPassChoicesToView() | ||
832 | { | ||
833 | $choices = array('a' => 'A', 'b' => 'B', 'c' => 'C', 'd' => 'D'); | ||
834 | $form = $this->factory->create('choice', null, array( | ||
835 | 'choices' => $choices, | ||
836 | )); | ||
837 | $view = $form->createView(); | ||
838 | |||
839 | $this->assertEquals(array( | ||
840 | new ChoiceView('a', 'a', 'A'), | ||
841 | new ChoiceView('b', 'b', 'B'), | ||
842 | new ChoiceView('c', 'c', 'C'), | ||
843 | new ChoiceView('d', 'd', 'D'), | ||
844 | ), $view->vars['choices']); | ||
845 | } | ||
846 | |||
847 | public function testPassPreferredChoicesToView() | ||
848 | { | ||
849 | $choices = array('a' => 'A', 'b' => 'B', 'c' => 'C', 'd' => 'D'); | ||
850 | $form = $this->factory->create('choice', null, array( | ||
851 | 'choices' => $choices, | ||
852 | 'preferred_choices' => array('b', 'd'), | ||
853 | )); | ||
854 | $view = $form->createView(); | ||
855 | |||
856 | $this->assertEquals(array( | ||
857 | 0 => new ChoiceView('a', 'a', 'A'), | ||
858 | 2 => new ChoiceView('c', 'c', 'C'), | ||
859 | ), $view->vars['choices']); | ||
860 | $this->assertEquals(array( | ||
861 | 1 => new ChoiceView('b', 'b', 'B'), | ||
862 | 3 => new ChoiceView('d', 'd', 'D'), | ||
863 | ), $view->vars['preferred_choices']); | ||
864 | } | ||
865 | |||
866 | public function testPassHierarchicalChoicesToView() | ||
867 | { | ||
868 | $form = $this->factory->create('choice', null, array( | ||
869 | 'choices' => $this->groupedChoices, | ||
870 | 'preferred_choices' => array('b', 'd'), | ||
871 | )); | ||
872 | $view = $form->createView(); | ||
873 | |||
874 | $this->assertEquals(array( | ||
875 | 'Symfony' => array( | ||
876 | 0 => new ChoiceView('a', 'a', 'Bernhard'), | ||
877 | 2 => new ChoiceView('c', 'c', 'Kris'), | ||
878 | ), | ||
879 | 'Doctrine' => array( | ||
880 | 4 => new ChoiceView('e', 'e', 'Roman'), | ||
881 | ), | ||
882 | ), $view->vars['choices']); | ||
883 | $this->assertEquals(array( | ||
884 | 'Symfony' => array( | ||
885 | 1 => new ChoiceView('b', 'b', 'Fabien'), | ||
886 | ), | ||
887 | 'Doctrine' => array( | ||
888 | 3 => new ChoiceView('d', 'd', 'Jon'), | ||
889 | ), | ||
890 | ), $view->vars['preferred_choices']); | ||
891 | } | ||
892 | |||
893 | public function testPassChoiceDataToView() | ||
894 | { | ||
895 | $obj1 = (object) array('value' => 'a', 'label' => 'A'); | ||
896 | $obj2 = (object) array('value' => 'b', 'label' => 'B'); | ||
897 | $obj3 = (object) array('value' => 'c', 'label' => 'C'); | ||
898 | $obj4 = (object) array('value' => 'd', 'label' => 'D'); | ||
899 | $form = $this->factory->create('choice', null, array( | ||
900 | 'choice_list' => new ObjectChoiceList(array($obj1, $obj2, $obj3, $obj4), 'label', array(), null, 'value'), | ||
901 | )); | ||
902 | $view = $form->createView(); | ||
903 | |||
904 | $this->assertEquals(array( | ||
905 | new ChoiceView($obj1, 'a', 'A'), | ||
906 | new ChoiceView($obj2, 'b', 'B'), | ||
907 | new ChoiceView($obj3, 'c', 'C'), | ||
908 | new ChoiceView($obj4, 'd', 'D'), | ||
909 | ), $view->vars['choices']); | ||
910 | } | ||
911 | |||
912 | public function testAdjustFullNameForMultipleNonExpanded() | ||
913 | { | ||
914 | $form = $this->factory->createNamed('name', 'choice', null, array( | ||
915 | 'multiple' => true, | ||
916 | 'expanded' => false, | ||
917 | 'choices' => $this->choices, | ||
918 | )); | ||
919 | $view = $form->createView(); | ||
920 | |||
921 | $this->assertSame('name[]', $view->vars['full_name']); | ||
922 | } | ||
923 | |||
924 | // https://github.com/symfony/symfony/issues/3298 | ||
925 | public function testInitializeWithEmptyChoices() | ||
926 | { | ||
927 | $this->factory->createNamed('name', 'choice', null, array( | ||
928 | 'choices' => array(), | ||
929 | )); | ||
930 | } | ||
931 | |||
932 | public function testInitializeWithDefaultObjectChoice() | ||
933 | { | ||
934 | $obj1 = (object) array('value' => 'a', 'label' => 'A'); | ||
935 | $obj2 = (object) array('value' => 'b', 'label' => 'B'); | ||
936 | $obj3 = (object) array('value' => 'c', 'label' => 'C'); | ||
937 | $obj4 = (object) array('value' => 'd', 'label' => 'D'); | ||
938 | |||
939 | $form = $this->factory->create('choice', null, array( | ||
940 | 'choice_list' => new ObjectChoiceList(array($obj1, $obj2, $obj3, $obj4), 'label', array(), null, 'value'), | ||
941 | // Used to break because "data_class" was inferred, which needs to | ||
942 | // remain null in every case (because it refers to the view format) | ||
943 | 'data' => $obj3, | ||
944 | )); | ||
945 | |||
946 | // Trigger data initialization | ||
947 | $form->getViewData(); | ||
948 | } | ||
949 | } | ||
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 new file mode 100644 index 00000000..be3ad9db --- /dev/null +++ b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/Type/CollectionTypeTest.php | |||
@@ -0,0 +1,200 @@ | |||
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 | } | ||
diff --git a/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/Type/CountryTypeTest.php b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/Type/CountryTypeTest.php new file mode 100644 index 00000000..1d56e2a0 --- /dev/null +++ b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/Type/CountryTypeTest.php | |||
@@ -0,0 +1,52 @@ | |||
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\Extension\Core\View\ChoiceView; | ||
15 | use Symfony\Component\Intl\Util\IntlTestHelper; | ||
16 | |||
17 | class CountryTypeTest extends TypeTestCase | ||
18 | { | ||
19 | protected function setUp() | ||
20 | { | ||
21 | IntlTestHelper::requireIntl($this); | ||
22 | |||
23 | parent::setUp(); | ||
24 | } | ||
25 | |||
26 | public function testCountriesAreSelectable() | ||
27 | { | ||
28 | $form = $this->factory->create('country'); | ||
29 | $view = $form->createView(); | ||
30 | $choices = $view->vars['choices']; | ||
31 | |||
32 | // Don't check objects for identity | ||
33 | $this->assertContains(new ChoiceView('DE', 'DE', 'Germany'), $choices, '', false, false); | ||
34 | $this->assertContains(new ChoiceView('GB', 'GB', 'United Kingdom'), $choices, '', false, false); | ||
35 | $this->assertContains(new ChoiceView('US', 'US', 'United States'), $choices, '', false, false); | ||
36 | $this->assertContains(new ChoiceView('FR', 'FR', 'France'), $choices, '', false, false); | ||
37 | $this->assertContains(new ChoiceView('MY', 'MY', 'Malaysia'), $choices, '', false, false); | ||
38 | } | ||
39 | |||
40 | public function testUnknownCountryIsNotIncluded() | ||
41 | { | ||
42 | $form = $this->factory->create('country', 'country'); | ||
43 | $view = $form->createView(); | ||
44 | $choices = $view->vars['choices']; | ||
45 | |||
46 | foreach ($choices as $choice) { | ||
47 | if ('ZZ' === $choice->value) { | ||
48 | $this->fail('Should not contain choice "ZZ"'); | ||
49 | } | ||
50 | } | ||
51 | } | ||
52 | } | ||
diff --git a/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/Type/CurrencyTypeTest.php b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/Type/CurrencyTypeTest.php new file mode 100644 index 00000000..b0eb6dc0 --- /dev/null +++ b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/Type/CurrencyTypeTest.php | |||
@@ -0,0 +1,37 @@ | |||
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\Extension\Core\View\ChoiceView; | ||
15 | use Symfony\Component\Intl\Util\IntlTestHelper; | ||
16 | |||
17 | class CurrencyTypeTest extends TypeTestCase | ||
18 | { | ||
19 | protected function setUp() | ||
20 | { | ||
21 | IntlTestHelper::requireIntl($this); | ||
22 | |||
23 | parent::setUp(); | ||
24 | } | ||
25 | |||
26 | public function testCurrenciesAreSelectable() | ||
27 | { | ||
28 | $form = $this->factory->create('currency'); | ||
29 | $view = $form->createView(); | ||
30 | $choices = $view->vars['choices']; | ||
31 | |||
32 | $this->assertContains(new ChoiceView('EUR', 'EUR', 'Euro'), $choices, '', false, false); | ||
33 | $this->assertContains(new ChoiceView('USD', 'USD', 'US Dollar'), $choices, '', false, false); | ||
34 | $this->assertContains(new ChoiceView('SIT', 'SIT', 'Slovenian Tolar'), $choices, '', false, false); | ||
35 | } | ||
36 | |||
37 | } | ||
diff --git a/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/Type/DateTimeTypeTest.php b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/Type/DateTimeTypeTest.php new file mode 100644 index 00000000..b9c1ebad --- /dev/null +++ b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/Type/DateTimeTypeTest.php | |||
@@ -0,0 +1,477 @@ | |||
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\FormError; | ||
15 | use Symfony\Component\Intl\Util\IntlTestHelper; | ||
16 | |||
17 | class DateTimeTypeTest extends TypeTestCase | ||
18 | { | ||
19 | protected function setUp() | ||
20 | { | ||
21 | IntlTestHelper::requireIntl($this); | ||
22 | |||
23 | parent::setUp(); | ||
24 | } | ||
25 | |||
26 | public function testSubmitDateTime() | ||
27 | { | ||
28 | $form = $this->factory->create('datetime', null, array( | ||
29 | 'model_timezone' => 'UTC', | ||
30 | 'view_timezone' => 'UTC', | ||
31 | 'date_widget' => 'choice', | ||
32 | 'time_widget' => 'choice', | ||
33 | 'input' => 'datetime', | ||
34 | )); | ||
35 | |||
36 | $form->submit(array( | ||
37 | 'date' => array( | ||
38 | 'day' => '2', | ||
39 | 'month' => '6', | ||
40 | 'year' => '2010', | ||
41 | ), | ||
42 | 'time' => array( | ||
43 | 'hour' => '3', | ||
44 | 'minute' => '4', | ||
45 | ), | ||
46 | )); | ||
47 | |||
48 | $dateTime = new \DateTime('2010-06-02 03:04:00 UTC'); | ||
49 | |||
50 | $this->assertDateTimeEquals($dateTime, $form->getData()); | ||
51 | } | ||
52 | |||
53 | public function testSubmitString() | ||
54 | { | ||
55 | $form = $this->factory->create('datetime', null, array( | ||
56 | 'model_timezone' => 'UTC', | ||
57 | 'view_timezone' => 'UTC', | ||
58 | 'input' => 'string', | ||
59 | 'date_widget' => 'choice', | ||
60 | 'time_widget' => 'choice', | ||
61 | )); | ||
62 | |||
63 | $form->submit(array( | ||
64 | 'date' => array( | ||
65 | 'day' => '2', | ||
66 | 'month' => '6', | ||
67 | 'year' => '2010', | ||
68 | ), | ||
69 | 'time' => array( | ||
70 | 'hour' => '3', | ||
71 | 'minute' => '4', | ||
72 | ), | ||
73 | )); | ||
74 | |||
75 | $this->assertEquals('2010-06-02 03:04:00', $form->getData()); | ||
76 | } | ||
77 | |||
78 | public function testSubmitTimestamp() | ||
79 | { | ||
80 | $form = $this->factory->create('datetime', null, array( | ||
81 | 'model_timezone' => 'UTC', | ||
82 | 'view_timezone' => 'UTC', | ||
83 | 'input' => 'timestamp', | ||
84 | 'date_widget' => 'choice', | ||
85 | 'time_widget' => 'choice', | ||
86 | )); | ||
87 | |||
88 | $form->submit(array( | ||
89 | 'date' => array( | ||
90 | 'day' => '2', | ||
91 | 'month' => '6', | ||
92 | 'year' => '2010', | ||
93 | ), | ||
94 | 'time' => array( | ||
95 | 'hour' => '3', | ||
96 | 'minute' => '4', | ||
97 | ), | ||
98 | )); | ||
99 | |||
100 | $dateTime = new \DateTime('2010-06-02 03:04:00 UTC'); | ||
101 | |||
102 | $this->assertEquals($dateTime->format('U'), $form->getData()); | ||
103 | } | ||
104 | |||
105 | public function testSubmitWithoutMinutes() | ||
106 | { | ||
107 | $form = $this->factory->create('datetime', null, array( | ||
108 | 'model_timezone' => 'UTC', | ||
109 | 'view_timezone' => 'UTC', | ||
110 | 'date_widget' => 'choice', | ||
111 | 'time_widget' => 'choice', | ||
112 | 'input' => 'datetime', | ||
113 | 'with_minutes' => false, | ||
114 | )); | ||
115 | |||
116 | $form->setData(new \DateTime('2010-06-02 03:04:05 UTC')); | ||
117 | |||
118 | $input = array( | ||
119 | 'date' => array( | ||
120 | 'day' => '2', | ||
121 | 'month' => '6', | ||
122 | 'year' => '2010', | ||
123 | ), | ||
124 | 'time' => array( | ||
125 | 'hour' => '3', | ||
126 | ), | ||
127 | ); | ||
128 | |||
129 | $form->submit($input); | ||
130 | |||
131 | $this->assertDateTimeEquals(new \DateTime('2010-06-02 03:00:00 UTC'), $form->getData()); | ||
132 | } | ||
133 | |||
134 | public function testSubmitWithSeconds() | ||
135 | { | ||
136 | $form = $this->factory->create('datetime', null, array( | ||
137 | 'model_timezone' => 'UTC', | ||
138 | 'view_timezone' => 'UTC', | ||
139 | 'date_widget' => 'choice', | ||
140 | 'time_widget' => 'choice', | ||
141 | 'input' => 'datetime', | ||
142 | 'with_seconds' => true, | ||
143 | )); | ||
144 | |||
145 | $form->setData(new \DateTime('2010-06-02 03:04:05 UTC')); | ||
146 | |||
147 | $input = array( | ||
148 | 'date' => array( | ||
149 | 'day' => '2', | ||
150 | 'month' => '6', | ||
151 | 'year' => '2010', | ||
152 | ), | ||
153 | 'time' => array( | ||
154 | 'hour' => '3', | ||
155 | 'minute' => '4', | ||
156 | 'second' => '5', | ||
157 | ), | ||
158 | ); | ||
159 | |||
160 | $form->submit($input); | ||
161 | |||
162 | $this->assertDateTimeEquals(new \DateTime('2010-06-02 03:04:05 UTC'), $form->getData()); | ||
163 | } | ||
164 | |||
165 | public function testSubmitDifferentTimezones() | ||
166 | { | ||
167 | $form = $this->factory->create('datetime', null, array( | ||
168 | 'model_timezone' => 'America/New_York', | ||
169 | 'view_timezone' => 'Pacific/Tahiti', | ||
170 | 'date_widget' => 'choice', | ||
171 | 'time_widget' => 'choice', | ||
172 | 'input' => 'string', | ||
173 | 'with_seconds' => true, | ||
174 | )); | ||
175 | |||
176 | $dateTime = new \DateTime('2010-06-02 03:04:05 Pacific/Tahiti'); | ||
177 | |||
178 | $form->submit(array( | ||
179 | 'date' => array( | ||
180 | 'day' => (int) $dateTime->format('d'), | ||
181 | 'month' => (int) $dateTime->format('m'), | ||
182 | 'year' => (int) $dateTime->format('Y'), | ||
183 | ), | ||
184 | 'time' => array( | ||
185 | 'hour' => (int) $dateTime->format('H'), | ||
186 | 'minute' => (int) $dateTime->format('i'), | ||
187 | 'second' => (int) $dateTime->format('s'), | ||
188 | ), | ||
189 | )); | ||
190 | |||
191 | $dateTime->setTimezone(new \DateTimeZone('America/New_York')); | ||
192 | |||
193 | $this->assertEquals($dateTime->format('Y-m-d H:i:s'), $form->getData()); | ||
194 | } | ||
195 | |||
196 | public function testSubmitDifferentTimezonesDateTime() | ||
197 | { | ||
198 | $form = $this->factory->create('datetime', null, array( | ||
199 | 'model_timezone' => 'America/New_York', | ||
200 | 'view_timezone' => 'Pacific/Tahiti', | ||
201 | 'widget' => 'single_text', | ||
202 | 'input' => 'datetime', | ||
203 | )); | ||
204 | |||
205 | $outputTime = new \DateTime('2010-06-02 03:04:00 Pacific/Tahiti'); | ||
206 | |||
207 | $form->submit('2010-06-02T03:04:00-10:00'); | ||
208 | |||
209 | $outputTime->setTimezone(new \DateTimeZone('America/New_York')); | ||
210 | |||
211 | $this->assertDateTimeEquals($outputTime, $form->getData()); | ||
212 | $this->assertEquals('2010-06-02T03:04:00-10:00', $form->getViewData()); | ||
213 | } | ||
214 | |||
215 | public function testSubmitStringSingleText() | ||
216 | { | ||
217 | $form = $this->factory->create('datetime', null, array( | ||
218 | 'model_timezone' => 'UTC', | ||
219 | 'view_timezone' => 'UTC', | ||
220 | 'input' => 'string', | ||
221 | 'widget' => 'single_text', | ||
222 | )); | ||
223 | |||
224 | $form->submit('2010-06-02T03:04:00Z'); | ||
225 | |||
226 | $this->assertEquals('2010-06-02 03:04:00', $form->getData()); | ||
227 | $this->assertEquals('2010-06-02T03:04:00Z', $form->getViewData()); | ||
228 | } | ||
229 | |||
230 | public function testSubmitStringSingleTextWithSeconds() | ||
231 | { | ||
232 | $form = $this->factory->create('datetime', null, array( | ||
233 | 'model_timezone' => 'UTC', | ||
234 | 'view_timezone' => 'UTC', | ||
235 | 'input' => 'string', | ||
236 | 'widget' => 'single_text', | ||
237 | 'with_seconds' => true, | ||
238 | )); | ||
239 | |||
240 | $form->submit('2010-06-02T03:04:05Z'); | ||
241 | |||
242 | $this->assertEquals('2010-06-02 03:04:05', $form->getData()); | ||
243 | $this->assertEquals('2010-06-02T03:04:05Z', $form->getViewData()); | ||
244 | } | ||
245 | |||
246 | public function testSubmitDifferentPattern() | ||
247 | { | ||
248 | $form = $this->factory->create('datetime', null, array( | ||
249 | 'date_format' => 'MM*yyyy*dd', | ||
250 | 'date_widget' => 'single_text', | ||
251 | 'time_widget' => 'single_text', | ||
252 | 'input' => 'datetime', | ||
253 | )); | ||
254 | |||
255 | $dateTime = new \DateTime('2010-06-02 03:04'); | ||
256 | |||
257 | $form->submit(array( | ||
258 | 'date' => '06*2010*02', | ||
259 | 'time' => '03:04', | ||
260 | )); | ||
261 | |||
262 | $this->assertDateTimeEquals($dateTime, $form->getData()); | ||
263 | } | ||
264 | |||
265 | // Bug fix | ||
266 | public function testInitializeWithDateTime() | ||
267 | { | ||
268 | // Throws an exception if "data_class" option is not explicitly set | ||
269 | // to null in the type | ||
270 | $this->factory->create('datetime', new \DateTime()); | ||
271 | } | ||
272 | |||
273 | public function testSingleTextWidgetShouldUseTheRightInputType() | ||
274 | { | ||
275 | $form = $this->factory->create('datetime', null, array( | ||
276 | 'widget' => 'single_text', | ||
277 | )); | ||
278 | |||
279 | $view = $form->createView(); | ||
280 | $this->assertEquals('datetime', $view->vars['type']); | ||
281 | } | ||
282 | |||
283 | public function testPassDefaultEmptyValueToViewIfNotRequired() | ||
284 | { | ||
285 | $form = $this->factory->create('datetime', null, array( | ||
286 | 'required' => false, | ||
287 | 'with_seconds' => true, | ||
288 | )); | ||
289 | |||
290 | $view = $form->createView(); | ||
291 | $this->assertSame('', $view['date']['year']->vars['empty_value']); | ||
292 | $this->assertSame('', $view['date']['month']->vars['empty_value']); | ||
293 | $this->assertSame('', $view['date']['day']->vars['empty_value']); | ||
294 | $this->assertSame('', $view['time']['hour']->vars['empty_value']); | ||
295 | $this->assertSame('', $view['time']['minute']->vars['empty_value']); | ||
296 | $this->assertSame('', $view['time']['second']->vars['empty_value']); | ||
297 | } | ||
298 | |||
299 | public function testPassNoEmptyValueToViewIfRequired() | ||
300 | { | ||
301 | $form = $this->factory->create('datetime', null, array( | ||
302 | 'required' => true, | ||
303 | 'with_seconds' => true, | ||
304 | )); | ||
305 | |||
306 | $view = $form->createView(); | ||
307 | $this->assertNull($view['date']['year']->vars['empty_value']); | ||
308 | $this->assertNull($view['date']['month']->vars['empty_value']); | ||
309 | $this->assertNull($view['date']['day']->vars['empty_value']); | ||
310 | $this->assertNull($view['time']['hour']->vars['empty_value']); | ||
311 | $this->assertNull($view['time']['minute']->vars['empty_value']); | ||
312 | $this->assertNull($view['time']['second']->vars['empty_value']); | ||
313 | } | ||
314 | |||
315 | public function testPassEmptyValueAsString() | ||
316 | { | ||
317 | $form = $this->factory->create('datetime', null, array( | ||
318 | 'empty_value' => 'Empty', | ||
319 | 'with_seconds' => true, | ||
320 | )); | ||
321 | |||
322 | $view = $form->createView(); | ||
323 | $this->assertSame('Empty', $view['date']['year']->vars['empty_value']); | ||
324 | $this->assertSame('Empty', $view['date']['month']->vars['empty_value']); | ||
325 | $this->assertSame('Empty', $view['date']['day']->vars['empty_value']); | ||
326 | $this->assertSame('Empty', $view['time']['hour']->vars['empty_value']); | ||
327 | $this->assertSame('Empty', $view['time']['minute']->vars['empty_value']); | ||
328 | $this->assertSame('Empty', $view['time']['second']->vars['empty_value']); | ||
329 | } | ||
330 | |||
331 | public function testPassEmptyValueAsArray() | ||
332 | { | ||
333 | $form = $this->factory->create('datetime', null, array( | ||
334 | 'empty_value' => array( | ||
335 | 'year' => 'Empty year', | ||
336 | 'month' => 'Empty month', | ||
337 | 'day' => 'Empty day', | ||
338 | 'hour' => 'Empty hour', | ||
339 | 'minute' => 'Empty minute', | ||
340 | 'second' => 'Empty second', | ||
341 | ), | ||
342 | 'with_seconds' => true, | ||
343 | )); | ||
344 | |||
345 | $view = $form->createView(); | ||
346 | $this->assertSame('Empty year', $view['date']['year']->vars['empty_value']); | ||
347 | $this->assertSame('Empty month', $view['date']['month']->vars['empty_value']); | ||
348 | $this->assertSame('Empty day', $view['date']['day']->vars['empty_value']); | ||
349 | $this->assertSame('Empty hour', $view['time']['hour']->vars['empty_value']); | ||
350 | $this->assertSame('Empty minute', $view['time']['minute']->vars['empty_value']); | ||
351 | $this->assertSame('Empty second', $view['time']['second']->vars['empty_value']); | ||
352 | } | ||
353 | |||
354 | public function testPassEmptyValueAsPartialArrayAddEmptyIfNotRequired() | ||
355 | { | ||
356 | $form = $this->factory->create('datetime', null, array( | ||
357 | 'required' => false, | ||
358 | 'empty_value' => array( | ||
359 | 'year' => 'Empty year', | ||
360 | 'day' => 'Empty day', | ||
361 | 'hour' => 'Empty hour', | ||
362 | 'second' => 'Empty second', | ||
363 | ), | ||
364 | 'with_seconds' => true, | ||
365 | )); | ||
366 | |||
367 | $view = $form->createView(); | ||
368 | $this->assertSame('Empty year', $view['date']['year']->vars['empty_value']); | ||
369 | $this->assertSame('', $view['date']['month']->vars['empty_value']); | ||
370 | $this->assertSame('Empty day', $view['date']['day']->vars['empty_value']); | ||
371 | $this->assertSame('Empty hour', $view['time']['hour']->vars['empty_value']); | ||
372 | $this->assertSame('', $view['time']['minute']->vars['empty_value']); | ||
373 | $this->assertSame('Empty second', $view['time']['second']->vars['empty_value']); | ||
374 | } | ||
375 | |||
376 | public function testPassEmptyValueAsPartialArrayAddNullIfRequired() | ||
377 | { | ||
378 | $form = $this->factory->create('datetime', null, array( | ||
379 | 'required' => true, | ||
380 | 'empty_value' => array( | ||
381 | 'year' => 'Empty year', | ||
382 | 'day' => 'Empty day', | ||
383 | 'hour' => 'Empty hour', | ||
384 | 'second' => 'Empty second', | ||
385 | ), | ||
386 | 'with_seconds' => true, | ||
387 | )); | ||
388 | |||
389 | $view = $form->createView(); | ||
390 | $this->assertSame('Empty year', $view['date']['year']->vars['empty_value']); | ||
391 | $this->assertNull($view['date']['month']->vars['empty_value']); | ||
392 | $this->assertSame('Empty day', $view['date']['day']->vars['empty_value']); | ||
393 | $this->assertSame('Empty hour', $view['time']['hour']->vars['empty_value']); | ||
394 | $this->assertNull($view['time']['minute']->vars['empty_value']); | ||
395 | $this->assertSame('Empty second', $view['time']['second']->vars['empty_value']); | ||
396 | } | ||
397 | |||
398 | public function testPassHtml5TypeIfSingleTextAndHtml5Format() | ||
399 | { | ||
400 | $form = $this->factory->create('datetime', null, array( | ||
401 | 'widget' => 'single_text', | ||
402 | )); | ||
403 | |||
404 | $view = $form->createView(); | ||
405 | $this->assertSame('datetime', $view->vars['type']); | ||
406 | } | ||
407 | |||
408 | public function testDontPassHtml5TypeIfNotHtml5Format() | ||
409 | { | ||
410 | $form = $this->factory->create('datetime', null, array( | ||
411 | 'widget' => 'single_text', | ||
412 | 'format' => 'yyyy-MM-dd HH:mm', | ||
413 | )); | ||
414 | |||
415 | $view = $form->createView(); | ||
416 | $this->assertFalse(isset($view->vars['type'])); | ||
417 | } | ||
418 | |||
419 | public function testDontPassHtml5TypeIfNotSingleText() | ||
420 | { | ||
421 | $form = $this->factory->create('datetime', null, array( | ||
422 | 'widget' => 'text', | ||
423 | )); | ||
424 | |||
425 | $view = $form->createView(); | ||
426 | $this->assertFalse(isset($view->vars['type'])); | ||
427 | } | ||
428 | |||
429 | public function testDateTypeChoiceErrorsBubbleUp() | ||
430 | { | ||
431 | $error = new FormError('Invalid!'); | ||
432 | $form = $this->factory->create('datetime', null); | ||
433 | |||
434 | $form['date']->addError($error); | ||
435 | |||
436 | $this->assertSame(array(), $form['date']->getErrors()); | ||
437 | $this->assertSame(array($error), $form->getErrors()); | ||
438 | } | ||
439 | |||
440 | public function testDateTypeSingleTextErrorsBubbleUp() | ||
441 | { | ||
442 | $error = new FormError('Invalid!'); | ||
443 | $form = $this->factory->create('datetime', null, array( | ||
444 | 'date_widget' => 'single_text' | ||
445 | )); | ||
446 | |||
447 | $form['date']->addError($error); | ||
448 | |||
449 | $this->assertSame(array(), $form['date']->getErrors()); | ||
450 | $this->assertSame(array($error), $form->getErrors()); | ||
451 | } | ||
452 | |||
453 | public function testTimeTypeChoiceErrorsBubbleUp() | ||
454 | { | ||
455 | $error = new FormError('Invalid!'); | ||
456 | $form = $this->factory->create('datetime', null); | ||
457 | |||
458 | $form['time']->addError($error); | ||
459 | |||
460 | $this->assertSame(array(), $form['time']->getErrors()); | ||
461 | $this->assertSame(array($error), $form->getErrors()); | ||
462 | } | ||
463 | |||
464 | public function testTimeTypeSingleTextErrorsBubbleUp() | ||
465 | { | ||
466 | $error = new FormError('Invalid!'); | ||
467 | $form = $this->factory->create('datetime', null, array( | ||
468 | 'time_widget' => 'single_text' | ||
469 | )); | ||
470 | |||
471 | $form['time']->addError($error); | ||
472 | |||
473 | $this->assertSame(array(), $form['time']->getErrors()); | ||
474 | $this->assertSame(array($error), $form->getErrors()); | ||
475 | } | ||
476 | |||
477 | } | ||
diff --git a/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php new file mode 100644 index 00000000..2aa155e7 --- /dev/null +++ b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php | |||
@@ -0,0 +1,781 @@ | |||
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\Extension\Core\View\ChoiceView; | ||
15 | use Symfony\Component\Form\FormError; | ||
16 | use Symfony\Component\Intl\Util\IntlTestHelper; | ||
17 | |||
18 | class DateTypeTest extends TypeTestCase | ||
19 | { | ||
20 | protected function setUp() | ||
21 | { | ||
22 | parent::setUp(); | ||
23 | |||
24 | // we test against "de_AT", so we need the full implementation | ||
25 | IntlTestHelper::requireFullIntl($this); | ||
26 | |||
27 | \Locale::setDefault('de_AT'); | ||
28 | } | ||
29 | |||
30 | /** | ||
31 | * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException | ||
32 | */ | ||
33 | public function testInvalidWidgetOption() | ||
34 | { | ||
35 | $this->factory->create('date', null, array( | ||
36 | 'widget' => 'fake_widget', | ||
37 | )); | ||
38 | } | ||
39 | |||
40 | /** | ||
41 | * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException | ||
42 | */ | ||
43 | public function testInvalidInputOption() | ||
44 | { | ||
45 | $this->factory->create('date', null, array( | ||
46 | 'input' => 'fake_input', | ||
47 | )); | ||
48 | } | ||
49 | |||
50 | public function testSubmitFromSingleTextDateTimeWithDefaultFormat() | ||
51 | { | ||
52 | $form = $this->factory->create('date', null, array( | ||
53 | 'model_timezone' => 'UTC', | ||
54 | 'view_timezone' => 'UTC', | ||
55 | 'widget' => 'single_text', | ||
56 | 'input' => 'datetime', | ||
57 | )); | ||
58 | |||
59 | $form->submit('2010-06-02'); | ||
60 | |||
61 | $this->assertDateTimeEquals(new \DateTime('2010-06-02 UTC'), $form->getData()); | ||
62 | $this->assertEquals('2010-06-02', $form->getViewData()); | ||
63 | } | ||
64 | |||
65 | public function testSubmitFromSingleTextDateTime() | ||
66 | { | ||
67 | $form = $this->factory->create('date', null, array( | ||
68 | 'format' => \IntlDateFormatter::MEDIUM, | ||
69 | 'model_timezone' => 'UTC', | ||
70 | 'view_timezone' => 'UTC', | ||
71 | 'widget' => 'single_text', | ||
72 | 'input' => 'datetime', | ||
73 | )); | ||
74 | |||
75 | $form->submit('2.6.2010'); | ||
76 | |||
77 | $this->assertDateTimeEquals(new \DateTime('2010-06-02 UTC'), $form->getData()); | ||
78 | $this->assertEquals('02.06.2010', $form->getViewData()); | ||
79 | } | ||
80 | |||
81 | public function testSubmitFromSingleTextString() | ||
82 | { | ||
83 | $form = $this->factory->create('date', null, array( | ||
84 | 'format' => \IntlDateFormatter::MEDIUM, | ||
85 | 'model_timezone' => 'UTC', | ||
86 | 'view_timezone' => 'UTC', | ||
87 | 'widget' => 'single_text', | ||
88 | 'input' => 'string', | ||
89 | )); | ||
90 | |||
91 | $form->submit('2.6.2010'); | ||
92 | |||
93 | $this->assertEquals('2010-06-02', $form->getData()); | ||
94 | $this->assertEquals('02.06.2010', $form->getViewData()); | ||
95 | } | ||
96 | |||
97 | public function testSubmitFromSingleTextTimestamp() | ||
98 | { | ||
99 | $form = $this->factory->create('date', null, array( | ||
100 | 'format' => \IntlDateFormatter::MEDIUM, | ||
101 | 'model_timezone' => 'UTC', | ||
102 | 'view_timezone' => 'UTC', | ||
103 | 'widget' => 'single_text', | ||
104 | 'input' => 'timestamp', | ||
105 | )); | ||
106 | |||
107 | $form->submit('2.6.2010'); | ||
108 | |||
109 | $dateTime = new \DateTime('2010-06-02 UTC'); | ||
110 | |||
111 | $this->assertEquals($dateTime->format('U'), $form->getData()); | ||
112 | $this->assertEquals('02.06.2010', $form->getViewData()); | ||
113 | } | ||
114 | |||
115 | public function testSubmitFromSingleTextRaw() | ||
116 | { | ||
117 | $form = $this->factory->create('date', null, array( | ||
118 | 'format' => \IntlDateFormatter::MEDIUM, | ||
119 | 'model_timezone' => 'UTC', | ||
120 | 'view_timezone' => 'UTC', | ||
121 | 'widget' => 'single_text', | ||
122 | 'input' => 'array', | ||
123 | )); | ||
124 | |||
125 | $form->submit('2.6.2010'); | ||
126 | |||
127 | $output = array( | ||
128 | 'day' => '2', | ||
129 | 'month' => '6', | ||
130 | 'year' => '2010', | ||
131 | ); | ||
132 | |||
133 | $this->assertEquals($output, $form->getData()); | ||
134 | $this->assertEquals('02.06.2010', $form->getViewData()); | ||
135 | } | ||
136 | |||
137 | public function testSubmitFromText() | ||
138 | { | ||
139 | $form = $this->factory->create('date', null, array( | ||
140 | 'model_timezone' => 'UTC', | ||
141 | 'view_timezone' => 'UTC', | ||
142 | 'widget' => 'text', | ||
143 | )); | ||
144 | |||
145 | $text = array( | ||
146 | 'day' => '2', | ||
147 | 'month' => '6', | ||
148 | 'year' => '2010', | ||
149 | ); | ||
150 | |||
151 | $form->submit($text); | ||
152 | |||
153 | $dateTime = new \DateTime('2010-06-02 UTC'); | ||
154 | |||
155 | $this->assertDateTimeEquals($dateTime, $form->getData()); | ||
156 | $this->assertEquals($text, $form->getViewData()); | ||
157 | } | ||
158 | |||
159 | public function testSubmitFromChoice() | ||
160 | { | ||
161 | $form = $this->factory->create('date', null, array( | ||
162 | 'model_timezone' => 'UTC', | ||
163 | 'view_timezone' => 'UTC', | ||
164 | 'widget' => 'choice', | ||
165 | )); | ||
166 | |||
167 | $text = array( | ||
168 | 'day' => '2', | ||
169 | 'month' => '6', | ||
170 | 'year' => '2010', | ||
171 | ); | ||
172 | |||
173 | $form->submit($text); | ||
174 | |||
175 | $dateTime = new \DateTime('2010-06-02 UTC'); | ||
176 | |||
177 | $this->assertDateTimeEquals($dateTime, $form->getData()); | ||
178 | $this->assertEquals($text, $form->getViewData()); | ||
179 | } | ||
180 | |||
181 | public function testSubmitFromChoiceEmpty() | ||
182 | { | ||
183 | $form = $this->factory->create('date', null, array( | ||
184 | 'model_timezone' => 'UTC', | ||
185 | 'view_timezone' => 'UTC', | ||
186 | 'widget' => 'choice', | ||
187 | 'required' => false, | ||
188 | )); | ||
189 | |||
190 | $text = array( | ||
191 | 'day' => '', | ||
192 | 'month' => '', | ||
193 | 'year' => '', | ||
194 | ); | ||
195 | |||
196 | $form->submit($text); | ||
197 | |||
198 | $this->assertNull($form->getData()); | ||
199 | $this->assertEquals($text, $form->getViewData()); | ||
200 | } | ||
201 | |||
202 | public function testSubmitFromInputDateTimeDifferentPattern() | ||
203 | { | ||
204 | $form = $this->factory->create('date', null, array( | ||
205 | 'model_timezone' => 'UTC', | ||
206 | 'view_timezone' => 'UTC', | ||
207 | 'format' => 'MM*yyyy*dd', | ||
208 | 'widget' => 'single_text', | ||
209 | 'input' => 'datetime', | ||
210 | )); | ||
211 | |||
212 | $form->submit('06*2010*02'); | ||
213 | |||
214 | $this->assertDateTimeEquals(new \DateTime('2010-06-02 UTC'), $form->getData()); | ||
215 | $this->assertEquals('06*2010*02', $form->getViewData()); | ||
216 | } | ||
217 | |||
218 | public function testSubmitFromInputStringDifferentPattern() | ||
219 | { | ||
220 | $form = $this->factory->create('date', null, array( | ||
221 | 'model_timezone' => 'UTC', | ||
222 | 'view_timezone' => 'UTC', | ||
223 | 'format' => 'MM*yyyy*dd', | ||
224 | 'widget' => 'single_text', | ||
225 | 'input' => 'string', | ||
226 | )); | ||
227 | |||
228 | $form->submit('06*2010*02'); | ||
229 | |||
230 | $this->assertEquals('2010-06-02', $form->getData()); | ||
231 | $this->assertEquals('06*2010*02', $form->getViewData()); | ||
232 | } | ||
233 | |||
234 | public function testSubmitFromInputTimestampDifferentPattern() | ||
235 | { | ||
236 | $form = $this->factory->create('date', null, array( | ||
237 | 'model_timezone' => 'UTC', | ||
238 | 'view_timezone' => 'UTC', | ||
239 | 'format' => 'MM*yyyy*dd', | ||
240 | 'widget' => 'single_text', | ||
241 | 'input' => 'timestamp', | ||
242 | )); | ||
243 | |||
244 | $form->submit('06*2010*02'); | ||
245 | |||
246 | $dateTime = new \DateTime('2010-06-02 UTC'); | ||
247 | |||
248 | $this->assertEquals($dateTime->format('U'), $form->getData()); | ||
249 | $this->assertEquals('06*2010*02', $form->getViewData()); | ||
250 | } | ||
251 | |||
252 | public function testSubmitFromInputRawDifferentPattern() | ||
253 | { | ||
254 | $form = $this->factory->create('date', null, array( | ||
255 | 'model_timezone' => 'UTC', | ||
256 | 'view_timezone' => 'UTC', | ||
257 | 'format' => 'MM*yyyy*dd', | ||
258 | 'widget' => 'single_text', | ||
259 | 'input' => 'array', | ||
260 | )); | ||
261 | |||
262 | $form->submit('06*2010*02'); | ||
263 | |||
264 | $output = array( | ||
265 | 'day' => '2', | ||
266 | 'month' => '6', | ||
267 | 'year' => '2010', | ||
268 | ); | ||
269 | |||
270 | $this->assertEquals($output, $form->getData()); | ||
271 | $this->assertEquals('06*2010*02', $form->getViewData()); | ||
272 | } | ||
273 | |||
274 | /** | ||
275 | * @dataProvider provideDateFormats | ||
276 | */ | ||
277 | public function testDatePatternWithFormatOption($format, $pattern) | ||
278 | { | ||
279 | $form = $this->factory->create('date', null, array( | ||
280 | 'format' => $format, | ||
281 | )); | ||
282 | |||
283 | $view = $form->createView(); | ||
284 | |||
285 | $this->assertEquals($pattern, $view->vars['date_pattern']); | ||
286 | } | ||
287 | |||
288 | public function provideDateFormats() | ||
289 | { | ||
290 | return array( | ||
291 | array('dMy', '{{ day }}{{ month }}{{ year }}'), | ||
292 | array('d-M-yyyy', '{{ day }}-{{ month }}-{{ year }}'), | ||
293 | array('M d y', '{{ month }} {{ day }} {{ year }}'), | ||
294 | ); | ||
295 | } | ||
296 | |||
297 | /** | ||
298 | * This test is to check that the strings '0', '1', '2', '3' are no accepted | ||
299 | * as valid IntlDateFormatter constants for FULL, LONG, MEDIUM or SHORT respectively. | ||
300 | * | ||
301 | * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException | ||
302 | */ | ||
303 | public function testThrowExceptionIfFormatIsNoPattern() | ||
304 | { | ||
305 | $this->factory->create('date', null, array( | ||
306 | 'format' => '0', | ||
307 | 'widget' => 'single_text', | ||
308 | 'input' => 'string', | ||
309 | )); | ||
310 | } | ||
311 | |||
312 | /** | ||
313 | * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException | ||
314 | */ | ||
315 | public function testThrowExceptionIfFormatDoesNotContainYearMonthAndDay() | ||
316 | { | ||
317 | $this->factory->create('date', null, array( | ||
318 | 'months' => array(6, 7), | ||
319 | 'format' => 'yy', | ||
320 | )); | ||
321 | } | ||
322 | |||
323 | /** | ||
324 | * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException | ||
325 | */ | ||
326 | public function testThrowExceptionIfFormatIsNoConstant() | ||
327 | { | ||
328 | $this->factory->create('date', null, array( | ||
329 | 'format' => 105, | ||
330 | )); | ||
331 | } | ||
332 | |||
333 | /** | ||
334 | * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException | ||
335 | */ | ||
336 | public function testThrowExceptionIfFormatIsInvalid() | ||
337 | { | ||
338 | $this->factory->create('date', null, array( | ||
339 | 'format' => array(), | ||
340 | )); | ||
341 | } | ||
342 | |||
343 | public function testSetDataWithDifferentTimezones() | ||
344 | { | ||
345 | $form = $this->factory->create('date', null, array( | ||
346 | 'format' => \IntlDateFormatter::MEDIUM, | ||
347 | 'model_timezone' => 'America/New_York', | ||
348 | 'view_timezone' => 'Pacific/Tahiti', | ||
349 | 'input' => 'string', | ||
350 | 'widget' => 'single_text', | ||
351 | )); | ||
352 | |||
353 | $form->setData('2010-06-02'); | ||
354 | |||
355 | $this->assertEquals('01.06.2010', $form->getViewData()); | ||
356 | } | ||
357 | |||
358 | public function testSetDataWithDifferentTimezonesDateTime() | ||
359 | { | ||
360 | $form = $this->factory->create('date', null, array( | ||
361 | 'format' => \IntlDateFormatter::MEDIUM, | ||
362 | 'model_timezone' => 'America/New_York', | ||
363 | 'view_timezone' => 'Pacific/Tahiti', | ||
364 | 'input' => 'datetime', | ||
365 | 'widget' => 'single_text', | ||
366 | )); | ||
367 | |||
368 | $dateTime = new \DateTime('2010-06-02 America/New_York'); | ||
369 | |||
370 | $form->setData($dateTime); | ||
371 | |||
372 | $this->assertDateTimeEquals($dateTime, $form->getData()); | ||
373 | $this->assertEquals('01.06.2010', $form->getViewData()); | ||
374 | } | ||
375 | |||
376 | public function testYearsOption() | ||
377 | { | ||
378 | $form = $this->factory->create('date', null, array( | ||
379 | 'years' => array(2010, 2011), | ||
380 | )); | ||
381 | |||
382 | $view = $form->createView(); | ||
383 | |||
384 | $this->assertEquals(array( | ||
385 | new ChoiceView('2010', '2010', '2010'), | ||
386 | new ChoiceView('2011', '2011', '2011'), | ||
387 | ), $view['year']->vars['choices']); | ||
388 | } | ||
389 | |||
390 | public function testMonthsOption() | ||
391 | { | ||
392 | $form = $this->factory->create('date', null, array( | ||
393 | 'months' => array(6, 7), | ||
394 | )); | ||
395 | |||
396 | $view = $form->createView(); | ||
397 | |||
398 | $this->assertEquals(array( | ||
399 | new ChoiceView('6', '6', '06'), | ||
400 | new ChoiceView('7', '7', '07'), | ||
401 | ), $view['month']->vars['choices']); | ||
402 | } | ||
403 | |||
404 | public function testMonthsOptionShortFormat() | ||
405 | { | ||
406 | $form = $this->factory->create('date', null, array( | ||
407 | 'months' => array(1, 4), | ||
408 | 'format' => 'dd.MMM.yy', | ||
409 | )); | ||
410 | |||
411 | $view = $form->createView(); | ||
412 | |||
413 | $this->assertEquals(array( | ||
414 | new ChoiceView('1', '1', 'Jän'), | ||
415 | new ChoiceView('4', '4', 'Apr.') | ||
416 | ), $view['month']->vars['choices']); | ||
417 | } | ||
418 | |||
419 | public function testMonthsOptionLongFormat() | ||
420 | { | ||
421 | $form = $this->factory->create('date', null, array( | ||
422 | 'months' => array(1, 4), | ||
423 | 'format' => 'dd.MMMM.yy', | ||
424 | )); | ||
425 | |||
426 | $view = $form->createView(); | ||
427 | |||
428 | $this->assertEquals(array( | ||
429 | new ChoiceView('1', '1', 'Jänner'), | ||
430 | new ChoiceView('4', '4', 'April'), | ||
431 | ), $view['month']->vars['choices']); | ||
432 | } | ||
433 | |||
434 | public function testMonthsOptionLongFormatWithDifferentTimezone() | ||
435 | { | ||
436 | $form = $this->factory->create('date', null, array( | ||
437 | 'months' => array(1, 4), | ||
438 | 'format' => 'dd.MMMM.yy', | ||
439 | )); | ||
440 | |||
441 | $view = $form->createView(); | ||
442 | |||
443 | $this->assertEquals(array( | ||
444 | new ChoiceView('1', '1', 'Jänner'), | ||
445 | new ChoiceView('4', '4', 'April'), | ||
446 | ), $view['month']->vars['choices']); | ||
447 | } | ||
448 | |||
449 | public function testIsDayWithinRangeReturnsTrueIfWithin() | ||
450 | { | ||
451 | $form = $this->factory->create('date', null, array( | ||
452 | 'days' => array(6, 7), | ||
453 | )); | ||
454 | |||
455 | $view = $form->createView(); | ||
456 | |||
457 | $this->assertEquals(array( | ||
458 | new ChoiceView('6', '6', '06'), | ||
459 | new ChoiceView('7', '7', '07'), | ||
460 | ), $view['day']->vars['choices']); | ||
461 | } | ||
462 | |||
463 | public function testIsPartiallyFilledReturnsFalseIfSingleText() | ||
464 | { | ||
465 | $this->markTestIncomplete('Needs to be reimplemented using validators'); | ||
466 | |||
467 | $form = $this->factory->create('date', null, array( | ||
468 | 'model_timezone' => 'UTC', | ||
469 | 'view_timezone' => 'UTC', | ||
470 | 'widget' => 'single_text', | ||
471 | )); | ||
472 | |||
473 | $form->submit('7.6.2010'); | ||
474 | |||
475 | $this->assertFalse($form->isPartiallyFilled()); | ||
476 | } | ||
477 | |||
478 | public function testIsPartiallyFilledReturnsFalseIfChoiceAndCompletelyEmpty() | ||
479 | { | ||
480 | $this->markTestIncomplete('Needs to be reimplemented using validators'); | ||
481 | |||
482 | $form = $this->factory->create('date', null, array( | ||
483 | 'model_timezone' => 'UTC', | ||
484 | 'view_timezone' => 'UTC', | ||
485 | 'widget' => 'choice', | ||
486 | )); | ||
487 | |||
488 | $form->submit(array( | ||
489 | 'day' => '', | ||
490 | 'month' => '', | ||
491 | 'year' => '', | ||
492 | )); | ||
493 | |||
494 | $this->assertFalse($form->isPartiallyFilled()); | ||
495 | } | ||
496 | |||
497 | public function testIsPartiallyFilledReturnsFalseIfChoiceAndCompletelyFilled() | ||
498 | { | ||
499 | $this->markTestIncomplete('Needs to be reimplemented using validators'); | ||
500 | |||
501 | $form = $this->factory->create('date', null, array( | ||
502 | 'model_timezone' => 'UTC', | ||
503 | 'view_timezone' => 'UTC', | ||
504 | 'widget' => 'choice', | ||
505 | )); | ||
506 | |||
507 | $form->submit(array( | ||
508 | 'day' => '2', | ||
509 | 'month' => '6', | ||
510 | 'year' => '2010', | ||
511 | )); | ||
512 | |||
513 | $this->assertFalse($form->isPartiallyFilled()); | ||
514 | } | ||
515 | |||
516 | public function testIsPartiallyFilledReturnsTrueIfChoiceAndDayEmpty() | ||
517 | { | ||
518 | $this->markTestIncomplete('Needs to be reimplemented using validators'); | ||
519 | |||
520 | $form = $this->factory->create('date', null, array( | ||
521 | 'model_timezone' => 'UTC', | ||
522 | 'view_timezone' => 'UTC', | ||
523 | 'widget' => 'choice', | ||
524 | )); | ||
525 | |||
526 | $form->submit(array( | ||
527 | 'day' => '', | ||
528 | 'month' => '6', | ||
529 | 'year' => '2010', | ||
530 | )); | ||
531 | |||
532 | $this->assertTrue($form->isPartiallyFilled()); | ||
533 | } | ||
534 | |||
535 | public function testPassDatePatternToView() | ||
536 | { | ||
537 | $form = $this->factory->create('date'); | ||
538 | $view = $form->createView(); | ||
539 | |||
540 | $this->assertSame('{{ day }}{{ month }}{{ year }}', $view->vars['date_pattern']); | ||
541 | } | ||
542 | |||
543 | public function testPassDatePatternToViewDifferentFormat() | ||
544 | { | ||
545 | $form = $this->factory->create('date', null, array( | ||
546 | 'format' => \IntlDateFormatter::LONG, | ||
547 | )); | ||
548 | |||
549 | $view = $form->createView(); | ||
550 | |||
551 | $this->assertSame('{{ day }}{{ month }}{{ year }}', $view->vars['date_pattern']); | ||
552 | } | ||
553 | |||
554 | public function testPassDatePatternToViewDifferentPattern() | ||
555 | { | ||
556 | $form = $this->factory->create('date', null, array( | ||
557 | 'format' => 'MMyyyydd' | ||
558 | )); | ||
559 | |||
560 | $view = $form->createView(); | ||
561 | |||
562 | $this->assertSame('{{ month }}{{ year }}{{ day }}', $view->vars['date_pattern']); | ||
563 | } | ||
564 | |||
565 | public function testPassDatePatternToViewDifferentPatternWithSeparators() | ||
566 | { | ||
567 | $form = $this->factory->create('date', null, array( | ||
568 | 'format' => 'MM*yyyy*dd' | ||
569 | )); | ||
570 | |||
571 | $view = $form->createView(); | ||
572 | |||
573 | $this->assertSame('{{ month }}*{{ year }}*{{ day }}', $view->vars['date_pattern']); | ||
574 | } | ||
575 | |||
576 | public function testDontPassDatePatternIfText() | ||
577 | { | ||
578 | $form = $this->factory->create('date', null, array( | ||
579 | 'widget' => 'single_text', | ||
580 | )); | ||
581 | $view = $form->createView(); | ||
582 | |||
583 | $this->assertFalse(isset($view->vars['date_pattern'])); | ||
584 | } | ||
585 | |||
586 | public function testPassWidgetToView() | ||
587 | { | ||
588 | $form = $this->factory->create('date', null, array( | ||
589 | 'widget' => 'single_text', | ||
590 | )); | ||
591 | $view = $form->createView(); | ||
592 | |||
593 | $this->assertSame('single_text', $view->vars['widget']); | ||
594 | } | ||
595 | |||
596 | // Bug fix | ||
597 | public function testInitializeWithDateTime() | ||
598 | { | ||
599 | // Throws an exception if "data_class" option is not explicitly set | ||
600 | // to null in the type | ||
601 | $this->factory->create('date', new \DateTime()); | ||
602 | } | ||
603 | |||
604 | public function testSingleTextWidgetShouldUseTheRightInputType() | ||
605 | { | ||
606 | $form = $this->factory->create('date', null, array( | ||
607 | 'widget' => 'single_text', | ||
608 | )); | ||
609 | |||
610 | $view = $form->createView(); | ||
611 | $this->assertEquals('date', $view->vars['type']); | ||
612 | } | ||
613 | |||
614 | public function testPassDefaultEmptyValueToViewIfNotRequired() | ||
615 | { | ||
616 | $form = $this->factory->create('date', null, array( | ||
617 | 'required' => false, | ||
618 | )); | ||
619 | |||
620 | $view = $form->createView(); | ||
621 | $this->assertSame('', $view['year']->vars['empty_value']); | ||
622 | $this->assertSame('', $view['month']->vars['empty_value']); | ||
623 | $this->assertSame('', $view['day']->vars['empty_value']); | ||
624 | } | ||
625 | |||
626 | public function testPassNoEmptyValueToViewIfRequired() | ||
627 | { | ||
628 | $form = $this->factory->create('date', null, array( | ||
629 | 'required' => true, | ||
630 | )); | ||
631 | |||
632 | $view = $form->createView(); | ||
633 | $this->assertNull($view['year']->vars['empty_value']); | ||
634 | $this->assertNull($view['month']->vars['empty_value']); | ||
635 | $this->assertNull($view['day']->vars['empty_value']); | ||
636 | } | ||
637 | |||
638 | public function testPassEmptyValueAsString() | ||
639 | { | ||
640 | $form = $this->factory->create('date', null, array( | ||
641 | 'empty_value' => 'Empty', | ||
642 | )); | ||
643 | |||
644 | $view = $form->createView(); | ||
645 | $this->assertSame('Empty', $view['year']->vars['empty_value']); | ||
646 | $this->assertSame('Empty', $view['month']->vars['empty_value']); | ||
647 | $this->assertSame('Empty', $view['day']->vars['empty_value']); | ||
648 | } | ||
649 | |||
650 | public function testPassEmptyValueAsArray() | ||
651 | { | ||
652 | $form = $this->factory->create('date', null, array( | ||
653 | 'empty_value' => array( | ||
654 | 'year' => 'Empty year', | ||
655 | 'month' => 'Empty month', | ||
656 | 'day' => 'Empty day', | ||
657 | ), | ||
658 | )); | ||
659 | |||
660 | $view = $form->createView(); | ||
661 | $this->assertSame('Empty year', $view['year']->vars['empty_value']); | ||
662 | $this->assertSame('Empty month', $view['month']->vars['empty_value']); | ||
663 | $this->assertSame('Empty day', $view['day']->vars['empty_value']); | ||
664 | } | ||
665 | |||
666 | public function testPassEmptyValueAsPartialArrayAddEmptyIfNotRequired() | ||
667 | { | ||
668 | $form = $this->factory->create('date', null, array( | ||
669 | 'required' => false, | ||
670 | 'empty_value' => array( | ||
671 | 'year' => 'Empty year', | ||
672 | 'day' => 'Empty day', | ||
673 | ), | ||
674 | )); | ||
675 | |||
676 | $view = $form->createView(); | ||
677 | $this->assertSame('Empty year', $view['year']->vars['empty_value']); | ||
678 | $this->assertSame('', $view['month']->vars['empty_value']); | ||
679 | $this->assertSame('Empty day', $view['day']->vars['empty_value']); | ||
680 | } | ||
681 | |||
682 | public function testPassEmptyValueAsPartialArrayAddNullIfRequired() | ||
683 | { | ||
684 | $form = $this->factory->create('date', null, array( | ||
685 | 'required' => true, | ||
686 | 'empty_value' => array( | ||
687 | 'year' => 'Empty year', | ||
688 | 'day' => 'Empty day', | ||
689 | ), | ||
690 | )); | ||
691 | |||
692 | $view = $form->createView(); | ||
693 | $this->assertSame('Empty year', $view['year']->vars['empty_value']); | ||
694 | $this->assertNull($view['month']->vars['empty_value']); | ||
695 | $this->assertSame('Empty day', $view['day']->vars['empty_value']); | ||
696 | } | ||
697 | |||
698 | public function testPassHtml5TypeIfSingleTextAndHtml5Format() | ||
699 | { | ||
700 | $form = $this->factory->create('date', null, array( | ||
701 | 'widget' => 'single_text', | ||
702 | )); | ||
703 | |||
704 | $view = $form->createView(); | ||
705 | $this->assertSame('date', $view->vars['type']); | ||
706 | } | ||
707 | |||
708 | public function testDontPassHtml5TypeIfNotHtml5Format() | ||
709 | { | ||
710 | $form = $this->factory->create('date', null, array( | ||
711 | 'widget' => 'single_text', | ||
712 | 'format' => \IntlDateFormatter::MEDIUM, | ||
713 | )); | ||
714 | |||
715 | $view = $form->createView(); | ||
716 | $this->assertFalse(isset($view->vars['type'])); | ||
717 | } | ||
718 | |||
719 | public function testDontPassHtml5TypeIfNotSingleText() | ||
720 | { | ||
721 | $form = $this->factory->create('date', null, array( | ||
722 | 'widget' => 'text', | ||
723 | )); | ||
724 | |||
725 | $view = $form->createView(); | ||
726 | $this->assertFalse(isset($view->vars['type'])); | ||
727 | } | ||
728 | |||
729 | public function provideCompoundWidgets() | ||
730 | { | ||
731 | return array( | ||
732 | array('text'), | ||
733 | array('choice'), | ||
734 | ); | ||
735 | } | ||
736 | |||
737 | /** | ||
738 | * @dataProvider provideCompoundWidgets | ||
739 | */ | ||
740 | public function testYearErrorsBubbleUp($widget) | ||
741 | { | ||
742 | $error = new FormError('Invalid!'); | ||
743 | $form = $this->factory->create('date', null, array( | ||
744 | 'widget' => $widget, | ||
745 | )); | ||
746 | $form['year']->addError($error); | ||
747 | |||
748 | $this->assertSame(array(), $form['year']->getErrors()); | ||
749 | $this->assertSame(array($error), $form->getErrors()); | ||
750 | } | ||
751 | |||
752 | /** | ||
753 | * @dataProvider provideCompoundWidgets | ||
754 | */ | ||
755 | public function testMonthErrorsBubbleUp($widget) | ||
756 | { | ||
757 | $error = new FormError('Invalid!'); | ||
758 | $form = $this->factory->create('date', null, array( | ||
759 | 'widget' => $widget, | ||
760 | )); | ||
761 | $form['month']->addError($error); | ||
762 | |||
763 | $this->assertSame(array(), $form['month']->getErrors()); | ||
764 | $this->assertSame(array($error), $form->getErrors()); | ||
765 | } | ||
766 | |||
767 | /** | ||
768 | * @dataProvider provideCompoundWidgets | ||
769 | */ | ||
770 | public function testDayErrorsBubbleUp($widget) | ||
771 | { | ||
772 | $error = new FormError('Invalid!'); | ||
773 | $form = $this->factory->create('date', null, array( | ||
774 | 'widget' => $widget, | ||
775 | )); | ||
776 | $form['day']->addError($error); | ||
777 | |||
778 | $this->assertSame(array(), $form['day']->getErrors()); | ||
779 | $this->assertSame(array($error), $form->getErrors()); | ||
780 | } | ||
781 | } | ||
diff --git a/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/Type/FileTypeTest.php b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/Type/FileTypeTest.php new file mode 100644 index 00000000..63556eb5 --- /dev/null +++ b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/Type/FileTypeTest.php | |||
@@ -0,0 +1,83 @@ | |||
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 | class FileTypeTest extends \Symfony\Component\Form\Test\TypeTestCase | ||
15 | { | ||
16 | // https://github.com/symfony/symfony/pull/5028 | ||
17 | public function testSetData() | ||
18 | { | ||
19 | $form = $this->factory->createBuilder('file')->getForm(); | ||
20 | $data = $this->createUploadedFileMock('abcdef', 'original.jpg', true); | ||
21 | |||
22 | $form->setData($data); | ||
23 | |||
24 | $this->assertSame($data, $form->getData()); | ||
25 | } | ||
26 | |||
27 | public function testSubmit() | ||
28 | { | ||
29 | $form = $this->factory->createBuilder('file')->getForm(); | ||
30 | $data = $this->createUploadedFileMock('abcdef', 'original.jpg', true); | ||
31 | |||
32 | $form->submit($data); | ||
33 | |||
34 | $this->assertSame($data, $form->getData()); | ||
35 | } | ||
36 | |||
37 | // https://github.com/symfony/symfony/issues/6134 | ||
38 | public function testSubmitEmpty() | ||
39 | { | ||
40 | $form = $this->factory->createBuilder('file')->getForm(); | ||
41 | |||
42 | $form->submit(null); | ||
43 | |||
44 | $this->assertNull($form->getData()); | ||
45 | } | ||
46 | |||
47 | public function testDontPassValueToView() | ||
48 | { | ||
49 | $form = $this->factory->create('file'); | ||
50 | $form->submit(array( | ||
51 | 'file' => $this->createUploadedFileMock('abcdef', 'original.jpg', true), | ||
52 | )); | ||
53 | $view = $form->createView(); | ||
54 | |||
55 | $this->assertEquals('', $view->vars['value']); | ||
56 | } | ||
57 | |||
58 | private function createUploadedFileMock($name, $originalName, $valid) | ||
59 | { | ||
60 | $file = $this | ||
61 | ->getMockBuilder('Symfony\Component\HttpFoundation\File\UploadedFile') | ||
62 | ->disableOriginalConstructor() | ||
63 | ->getMock() | ||
64 | ; | ||
65 | $file | ||
66 | ->expects($this->any()) | ||
67 | ->method('getBasename') | ||
68 | ->will($this->returnValue($name)) | ||
69 | ; | ||
70 | $file | ||
71 | ->expects($this->any()) | ||
72 | ->method('getClientOriginalName') | ||
73 | ->will($this->returnValue($originalName)) | ||
74 | ; | ||
75 | $file | ||
76 | ->expects($this->any()) | ||
77 | ->method('isValid') | ||
78 | ->will($this->returnValue($valid)) | ||
79 | ; | ||
80 | |||
81 | return $file; | ||
82 | } | ||
83 | } | ||
diff --git a/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/Type/FormTypeTest.php b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/Type/FormTypeTest.php new file mode 100644 index 00000000..cced82f4 --- /dev/null +++ b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/Type/FormTypeTest.php | |||
@@ -0,0 +1,578 @@ | |||
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\PropertyAccess\PropertyPath; | ||
15 | use Symfony\Component\Form\Form; | ||
16 | use Symfony\Component\Form\CallbackTransformer; | ||
17 | use Symfony\Component\Form\Tests\Fixtures\Author; | ||
18 | use Symfony\Component\Form\Tests\Fixtures\FixedDataTransformer; | ||
19 | use Symfony\Component\Form\FormError; | ||
20 | |||
21 | class FormTest_AuthorWithoutRefSetter | ||
22 | { | ||
23 | protected $reference; | ||
24 | |||
25 | protected $referenceCopy; | ||
26 | |||
27 | public function __construct($reference) | ||
28 | { | ||
29 | $this->reference = $reference; | ||
30 | $this->referenceCopy = $reference; | ||
31 | } | ||
32 | |||
33 | // The returned object should be modified by reference without having | ||
34 | // to provide a setReference() method | ||
35 | public function getReference() | ||
36 | { | ||
37 | return $this->reference; | ||
38 | } | ||
39 | |||
40 | // The returned object is a copy, so setReferenceCopy() must be used | ||
41 | // to update it | ||
42 | public function getReferenceCopy() | ||
43 | { | ||
44 | return is_object($this->referenceCopy) ? clone $this->referenceCopy : $this->referenceCopy; | ||
45 | } | ||
46 | |||
47 | public function setReferenceCopy($reference) | ||
48 | { | ||
49 | $this->referenceCopy = $reference; | ||
50 | } | ||
51 | } | ||
52 | |||
53 | class FormTypeTest extends BaseTypeTest | ||
54 | { | ||
55 | public function testCreateFormInstances() | ||
56 | { | ||
57 | $this->assertInstanceOf('Symfony\Component\Form\Form', $this->factory->create('form')); | ||
58 | } | ||
59 | |||
60 | public function testPassRequiredAsOption() | ||
61 | { | ||
62 | $form = $this->factory->create('form', null, array('required' => false)); | ||
63 | |||
64 | $this->assertFalse($form->isRequired()); | ||
65 | |||
66 | $form = $this->factory->create('form', null, array('required' => true)); | ||
67 | |||
68 | $this->assertTrue($form->isRequired()); | ||
69 | } | ||
70 | |||
71 | public function testSubmittedDataIsTrimmedBeforeTransforming() | ||
72 | { | ||
73 | $form = $this->factory->createBuilder('form') | ||
74 | ->addViewTransformer(new FixedDataTransformer(array( | ||
75 | null => '', | ||
76 | 'reverse[a]' => 'a', | ||
77 | ))) | ||
78 | ->setCompound(false) | ||
79 | ->getForm(); | ||
80 | |||
81 | $form->submit(' a '); | ||
82 | |||
83 | $this->assertEquals('a', $form->getViewData()); | ||
84 | $this->assertEquals('reverse[a]', $form->getData()); | ||
85 | } | ||
86 | |||
87 | public function testSubmittedDataIsNotTrimmedBeforeTransformingIfNoTrimming() | ||
88 | { | ||
89 | $form = $this->factory->createBuilder('form', null, array('trim' => false)) | ||
90 | ->addViewTransformer(new FixedDataTransformer(array( | ||
91 | null => '', | ||
92 | 'reverse[ a ]' => ' a ', | ||
93 | ))) | ||
94 | ->setCompound(false) | ||
95 | ->getForm(); | ||
96 | |||
97 | $form->submit(' a '); | ||
98 | |||
99 | $this->assertEquals(' a ', $form->getViewData()); | ||
100 | $this->assertEquals('reverse[ a ]', $form->getData()); | ||
101 | } | ||
102 | |||
103 | public function testNonReadOnlyFormWithReadOnlyParentIsReadOnly() | ||
104 | { | ||
105 | $view = $this->factory->createNamedBuilder('parent', 'form', null, array('read_only' => true)) | ||
106 | ->add('child', 'form') | ||
107 | ->getForm() | ||
108 | ->createView(); | ||
109 | |||
110 | $this->assertTrue($view['child']->vars['read_only']); | ||
111 | } | ||
112 | |||
113 | public function testReadOnlyFormWithNonReadOnlyParentIsReadOnly() | ||
114 | { | ||
115 | $view = $this->factory->createNamedBuilder('parent', 'form') | ||
116 | ->add('child', 'form', array('read_only' => true)) | ||
117 | ->getForm() | ||
118 | ->createView(); | ||
119 | |||
120 | $this->assertTrue($view['child']->vars['read_only']); | ||
121 | } | ||
122 | |||
123 | public function testNonReadOnlyFormWithNonReadOnlyParentIsNotReadOnly() | ||
124 | { | ||
125 | $view = $this->factory->createNamedBuilder('parent', 'form') | ||
126 | ->add('child', 'form') | ||
127 | ->getForm() | ||
128 | ->createView(); | ||
129 | |||
130 | $this->assertFalse($view['child']->vars['read_only']); | ||
131 | } | ||
132 | |||
133 | public function testPassMaxLengthToView() | ||
134 | { | ||
135 | $form = $this->factory->create('form', null, array('max_length' => 10)); | ||
136 | $view = $form->createView(); | ||
137 | |||
138 | $this->assertSame(10, $view->vars['max_length']); | ||
139 | } | ||
140 | |||
141 | public function testSubmitWithEmptyDataCreatesObjectIfClassAvailable() | ||
142 | { | ||
143 | $builder = $this->factory->createBuilder('form', null, array( | ||
144 | 'data_class' => 'Symfony\Component\Form\Tests\Fixtures\Author', | ||
145 | 'required' => false, | ||
146 | )); | ||
147 | $builder->add('firstName', 'text'); | ||
148 | $builder->add('lastName', 'text'); | ||
149 | $form = $builder->getForm(); | ||
150 | |||
151 | $form->setData(null); | ||
152 | // partially empty, still an object is created | ||
153 | $form->submit(array('firstName' => 'Bernhard', 'lastName' => '')); | ||
154 | |||
155 | $author = new Author(); | ||
156 | $author->firstName = 'Bernhard'; | ||
157 | $author->setLastName(''); | ||
158 | |||
159 | $this->assertEquals($author, $form->getData()); | ||
160 | } | ||
161 | |||
162 | public function testSubmitWithEmptyDataCreatesObjectIfInitiallySubmittedWithObject() | ||
163 | { | ||
164 | $builder = $this->factory->createBuilder('form', null, array( | ||
165 | // data class is inferred from the passed object | ||
166 | 'data' => new Author(), | ||
167 | 'required' => false, | ||
168 | )); | ||
169 | $builder->add('firstName', 'text'); | ||
170 | $builder->add('lastName', 'text'); | ||
171 | $form = $builder->getForm(); | ||
172 | |||
173 | $form->setData(null); | ||
174 | // partially empty, still an object is created | ||
175 | $form->submit(array('firstName' => 'Bernhard', 'lastName' => '')); | ||
176 | |||
177 | $author = new Author(); | ||
178 | $author->firstName = 'Bernhard'; | ||
179 | $author->setLastName(''); | ||
180 | |||
181 | $this->assertEquals($author, $form->getData()); | ||
182 | } | ||
183 | |||
184 | public function testSubmitWithEmptyDataCreatesArrayIfDataClassIsNull() | ||
185 | { | ||
186 | $builder = $this->factory->createBuilder('form', null, array( | ||
187 | 'data_class' => null, | ||
188 | 'required' => false, | ||
189 | )); | ||
190 | $builder->add('firstName', 'text'); | ||
191 | $form = $builder->getForm(); | ||
192 | |||
193 | $form->setData(null); | ||
194 | $form->submit(array('firstName' => 'Bernhard')); | ||
195 | |||
196 | $this->assertSame(array('firstName' => 'Bernhard'), $form->getData()); | ||
197 | } | ||
198 | |||
199 | public function testSubmitEmptyWithEmptyDataCreatesNoObjectIfNotRequired() | ||
200 | { | ||
201 | $builder = $this->factory->createBuilder('form', null, array( | ||
202 | 'data_class' => 'Symfony\Component\Form\Tests\Fixtures\Author', | ||
203 | 'required' => false, | ||
204 | )); | ||
205 | $builder->add('firstName', 'text'); | ||
206 | $builder->add('lastName', 'text'); | ||
207 | $form = $builder->getForm(); | ||
208 | |||
209 | $form->setData(null); | ||
210 | $form->submit(array('firstName' => '', 'lastName' => '')); | ||
211 | |||
212 | $this->assertNull($form->getData()); | ||
213 | } | ||
214 | |||
215 | public function testSubmitEmptyWithEmptyDataCreatesObjectIfRequired() | ||
216 | { | ||
217 | $builder = $this->factory->createBuilder('form', null, array( | ||
218 | 'data_class' => 'Symfony\Component\Form\Tests\Fixtures\Author', | ||
219 | 'required' => true, | ||
220 | )); | ||
221 | $builder->add('firstName', 'text'); | ||
222 | $builder->add('lastName', 'text'); | ||
223 | $form = $builder->getForm(); | ||
224 | |||
225 | $form->setData(null); | ||
226 | $form->submit(array('firstName' => '', 'lastName' => '')); | ||
227 | |||
228 | $this->assertEquals(new Author(), $form->getData()); | ||
229 | } | ||
230 | |||
231 | /* | ||
232 | * We need something to write the field values into | ||
233 | */ | ||
234 | public function testSubmitWithEmptyDataStoresArrayIfNoClassAvailable() | ||
235 | { | ||
236 | $form = $this->factory->createBuilder('form') | ||
237 | ->add('firstName', 'text') | ||
238 | ->getForm(); | ||
239 | |||
240 | $form->setData(null); | ||
241 | $form->submit(array('firstName' => 'Bernhard')); | ||
242 | |||
243 | $this->assertSame(array('firstName' => 'Bernhard'), $form->getData()); | ||
244 | } | ||
245 | |||
246 | public function testSubmitWithEmptyDataPassesEmptyStringToTransformerIfNotCompound() | ||
247 | { | ||
248 | $form = $this->factory->createBuilder('form') | ||
249 | ->addViewTransformer(new FixedDataTransformer(array( | ||
250 | // required for the initial, internal setData(null) | ||
251 | null => 'null', | ||
252 | // required to test that submit(null) is converted to '' | ||
253 | 'empty' => '', | ||
254 | ))) | ||
255 | ->setCompound(false) | ||
256 | ->getForm(); | ||
257 | |||
258 | $form->submit(null); | ||
259 | |||
260 | $this->assertSame('empty', $form->getData()); | ||
261 | } | ||
262 | |||
263 | public function testSubmitWithEmptyDataUsesEmptyDataOption() | ||
264 | { | ||
265 | $author = new Author(); | ||
266 | |||
267 | $builder = $this->factory->createBuilder('form', null, array( | ||
268 | 'data_class' => 'Symfony\Component\Form\Tests\Fixtures\Author', | ||
269 | 'empty_data' => $author, | ||
270 | )); | ||
271 | $builder->add('firstName', 'text'); | ||
272 | $form = $builder->getForm(); | ||
273 | |||
274 | $form->submit(array('firstName' => 'Bernhard')); | ||
275 | |||
276 | $this->assertSame($author, $form->getData()); | ||
277 | $this->assertEquals('Bernhard', $author->firstName); | ||
278 | } | ||
279 | |||
280 | public function provideZeros() | ||
281 | { | ||
282 | return array( | ||
283 | array(0, '0'), | ||
284 | array('0', '0'), | ||
285 | array('00000', '00000'), | ||
286 | ); | ||
287 | } | ||
288 | |||
289 | /** | ||
290 | * @dataProvider provideZeros | ||
291 | * @see https://github.com/symfony/symfony/issues/1986 | ||
292 | */ | ||
293 | public function testSetDataThroughParamsWithZero($data, $dataAsString) | ||
294 | { | ||
295 | $form = $this->factory->create('form', null, array( | ||
296 | 'data' => $data, | ||
297 | 'compound' => false, | ||
298 | )); | ||
299 | $view = $form->createView(); | ||
300 | |||
301 | $this->assertFalse($form->isEmpty()); | ||
302 | |||
303 | $this->assertSame($dataAsString, $view->vars['value']); | ||
304 | $this->assertSame($dataAsString, $form->getData()); | ||
305 | } | ||
306 | |||
307 | /** | ||
308 | * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException | ||
309 | */ | ||
310 | public function testAttributesException() | ||
311 | { | ||
312 | $this->factory->create('form', null, array('attr' => '')); | ||
313 | } | ||
314 | |||
315 | public function testNameCanBeEmptyString() | ||
316 | { | ||
317 | $form = $this->factory->createNamed('', 'form'); | ||
318 | |||
319 | $this->assertEquals('', $form->getName()); | ||
320 | } | ||
321 | |||
322 | public function testSubformDoesntCallSetters() | ||
323 | { | ||
324 | $author = new FormTest_AuthorWithoutRefSetter(new Author()); | ||
325 | |||
326 | $builder = $this->factory->createBuilder('form', $author); | ||
327 | $builder->add('reference', 'form', array( | ||
328 | 'data_class' => 'Symfony\Component\Form\Tests\Fixtures\Author', | ||
329 | )); | ||
330 | $builder->get('reference')->add('firstName', 'text'); | ||
331 | $form = $builder->getForm(); | ||
332 | |||
333 | $form->submit(array( | ||
334 | // reference has a getter, but not setter | ||
335 | 'reference' => array( | ||
336 | 'firstName' => 'Foo', | ||
337 | ) | ||
338 | )); | ||
339 | |||
340 | $this->assertEquals('Foo', $author->getReference()->firstName); | ||
341 | } | ||
342 | |||
343 | public function testSubformCallsSettersIfTheObjectChanged() | ||
344 | { | ||
345 | // no reference | ||
346 | $author = new FormTest_AuthorWithoutRefSetter(null); | ||
347 | $newReference = new Author(); | ||
348 | |||
349 | $builder = $this->factory->createBuilder('form', $author); | ||
350 | $builder->add('referenceCopy', 'form', array( | ||
351 | 'data_class' => 'Symfony\Component\Form\Tests\Fixtures\Author', | ||
352 | )); | ||
353 | $builder->get('referenceCopy')->add('firstName', 'text'); | ||
354 | $form = $builder->getForm(); | ||
355 | |||
356 | $form['referenceCopy']->setData($newReference); // new author object | ||
357 | |||
358 | $form->submit(array( | ||
359 | // referenceCopy has a getter that returns a copy | ||
360 | 'referenceCopy' => array( | ||
361 | 'firstName' => 'Foo', | ||
362 | ) | ||
363 | )); | ||
364 | |||
365 | $this->assertEquals('Foo', $author->getReferenceCopy()->firstName); | ||
366 | } | ||
367 | |||
368 | public function testSubformCallsSettersIfByReferenceIsFalse() | ||
369 | { | ||
370 | $author = new FormTest_AuthorWithoutRefSetter(new Author()); | ||
371 | |||
372 | $builder = $this->factory->createBuilder('form', $author); | ||
373 | $builder->add('referenceCopy', 'form', array( | ||
374 | 'data_class' => 'Symfony\Component\Form\Tests\Fixtures\Author', | ||
375 | 'by_reference' => false | ||
376 | )); | ||
377 | $builder->get('referenceCopy')->add('firstName', 'text'); | ||
378 | $form = $builder->getForm(); | ||
379 | |||
380 | $form->submit(array( | ||
381 | // referenceCopy has a getter that returns a copy | ||
382 | 'referenceCopy' => array( | ||
383 | 'firstName' => 'Foo', | ||
384 | ) | ||
385 | )); | ||
386 | |||
387 | // firstName can only be updated if setReferenceCopy() was called | ||
388 | $this->assertEquals('Foo', $author->getReferenceCopy()->firstName); | ||
389 | } | ||
390 | |||
391 | public function testSubformCallsSettersIfReferenceIsScalar() | ||
392 | { | ||
393 | $author = new FormTest_AuthorWithoutRefSetter('scalar'); | ||
394 | |||
395 | $builder = $this->factory->createBuilder('form', $author); | ||
396 | $builder->add('referenceCopy', 'form'); | ||
397 | $builder->get('referenceCopy')->addViewTransformer(new CallbackTransformer( | ||
398 | function () {}, | ||
399 | function ($value) { // reverseTransform | ||
400 | |||
401 | return 'foobar'; | ||
402 | } | ||
403 | )); | ||
404 | $form = $builder->getForm(); | ||
405 | |||
406 | $form->submit(array( | ||
407 | 'referenceCopy' => array(), // doesn't matter actually | ||
408 | )); | ||
409 | |||
410 | // firstName can only be updated if setReferenceCopy() was called | ||
411 | $this->assertEquals('foobar', $author->getReferenceCopy()); | ||
412 | } | ||
413 | |||
414 | public function testSubformAlwaysInsertsIntoArrays() | ||
415 | { | ||
416 | $ref1 = new Author(); | ||
417 | $ref2 = new Author(); | ||
418 | $author = array('referenceCopy' => $ref1); | ||
419 | |||
420 | $builder = $this->factory->createBuilder('form'); | ||
421 | $builder->setData($author); | ||
422 | $builder->add('referenceCopy', 'form'); | ||
423 | $builder->get('referenceCopy')->addViewTransformer(new CallbackTransformer( | ||
424 | function () {}, | ||
425 | function ($value) use ($ref2) { // reverseTransform | ||
426 | |||
427 | return $ref2; | ||
428 | } | ||
429 | )); | ||
430 | $form = $builder->getForm(); | ||
431 | |||
432 | $form->submit(array( | ||
433 | 'referenceCopy' => array('a' => 'b'), // doesn't matter actually | ||
434 | )); | ||
435 | |||
436 | // the new reference was inserted into the array | ||
437 | $author = $form->getData(); | ||
438 | $this->assertSame($ref2, $author['referenceCopy']); | ||
439 | } | ||
440 | |||
441 | public function testPassMultipartTrueIfAnyChildIsMultipartToView() | ||
442 | { | ||
443 | $view = $this->factory->createBuilder('form') | ||
444 | ->add('foo', 'text') | ||
445 | ->add('bar', 'file') | ||
446 | ->getForm() | ||
447 | ->createView(); | ||
448 | |||
449 | $this->assertTrue($view->vars['multipart']); | ||
450 | } | ||
451 | |||
452 | public function testViewIsNotRenderedByDefault() | ||
453 | { | ||
454 | $view = $this->factory->createBuilder('form') | ||
455 | ->add('foo', 'form') | ||
456 | ->getForm() | ||
457 | ->createView(); | ||
458 | |||
459 | $this->assertFalse($view->isRendered()); | ||
460 | } | ||
461 | |||
462 | public function testErrorBubblingIfCompound() | ||
463 | { | ||
464 | $form = $this->factory->create('form', null, array( | ||
465 | 'compound' => true, | ||
466 | )); | ||
467 | |||
468 | $this->assertTrue($form->getConfig()->getErrorBubbling()); | ||
469 | } | ||
470 | |||
471 | public function testNoErrorBubblingIfNotCompound() | ||
472 | { | ||
473 | $form = $this->factory->create('form', null, array( | ||
474 | 'compound' => false, | ||
475 | )); | ||
476 | |||
477 | $this->assertFalse($form->getConfig()->getErrorBubbling()); | ||
478 | } | ||
479 | |||
480 | public function testOverrideErrorBubbling() | ||
481 | { | ||
482 | $form = $this->factory->create('form', null, array( | ||
483 | 'compound' => false, | ||
484 | 'error_bubbling' => true, | ||
485 | )); | ||
486 | |||
487 | $this->assertTrue($form->getConfig()->getErrorBubbling()); | ||
488 | } | ||
489 | |||
490 | public function testPropertyPath() | ||
491 | { | ||
492 | $form = $this->factory->create('form', null, array( | ||
493 | 'property_path' => 'foo', | ||
494 | )); | ||
495 | |||
496 | $this->assertEquals(new PropertyPath('foo'), $form->getPropertyPath()); | ||
497 | $this->assertTrue($form->getConfig()->getMapped()); | ||
498 | } | ||
499 | |||
500 | public function testPropertyPathNullImpliesDefault() | ||
501 | { | ||
502 | $form = $this->factory->createNamed('name', 'form', null, array( | ||
503 | 'property_path' => null, | ||
504 | )); | ||
505 | |||
506 | $this->assertEquals(new PropertyPath('name'), $form->getPropertyPath()); | ||
507 | $this->assertTrue($form->getConfig()->getMapped()); | ||
508 | } | ||
509 | |||
510 | public function testNotMapped() | ||
511 | { | ||
512 | $form = $this->factory->create('form', null, array( | ||
513 | 'property_path' => 'foo', | ||
514 | 'mapped' => false, | ||
515 | )); | ||
516 | |||
517 | $this->assertEquals(new PropertyPath('foo'), $form->getPropertyPath()); | ||
518 | $this->assertFalse($form->getConfig()->getMapped()); | ||
519 | } | ||
520 | |||
521 | public function testViewValidNotSubmitted() | ||
522 | { | ||
523 | $form = $this->factory->create('form'); | ||
524 | $view = $form->createView(); | ||
525 | $this->assertTrue($view->vars['valid']); | ||
526 | } | ||
527 | |||
528 | public function testViewNotValidSubmitted() | ||
529 | { | ||
530 | $form = $this->factory->create('form'); | ||
531 | $form->submit(array()); | ||
532 | $form->addError(new FormError('An error')); | ||
533 | $view = $form->createView(); | ||
534 | $this->assertFalse($view->vars['valid']); | ||
535 | } | ||
536 | |||
537 | public function testDataOptionSupersedesSetDataCalls() | ||
538 | { | ||
539 | $form = $this->factory->create('form', null, array( | ||
540 | 'data' => 'default', | ||
541 | 'compound' => false, | ||
542 | )); | ||
543 | |||
544 | $form->setData('foobar'); | ||
545 | |||
546 | $this->assertSame('default', $form->getData()); | ||
547 | } | ||
548 | |||
549 | public function testNormDataIsPassedToView() | ||
550 | { | ||
551 | $view = $this->factory->createBuilder('form') | ||
552 | ->addViewTransformer(new FixedDataTransformer(array( | ||
553 | 'foo' => 'bar', | ||
554 | ))) | ||
555 | ->setData('foo') | ||
556 | ->getForm() | ||
557 | ->createView(); | ||
558 | |||
559 | $this->assertSame('foo', $view->vars['data']); | ||
560 | $this->assertSame('bar', $view->vars['value']); | ||
561 | } | ||
562 | |||
563 | // https://github.com/symfony/symfony/issues/6862 | ||
564 | public function testPassZeroLabelToView() | ||
565 | { | ||
566 | $view = $this->factory->create('form', null, array( | ||
567 | 'label' => '0' | ||
568 | )) | ||
569 | ->createView(); | ||
570 | |||
571 | $this->assertSame('0', $view->vars['label']); | ||
572 | } | ||
573 | |||
574 | protected function getTestedType() | ||
575 | { | ||
576 | return 'form'; | ||
577 | } | ||
578 | } | ||
diff --git a/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/Type/IntegerTypeTest.php b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/Type/IntegerTypeTest.php new file mode 100644 index 00000000..998bbe01 --- /dev/null +++ b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/Type/IntegerTypeTest.php | |||
@@ -0,0 +1,34 @@ | |||
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\Intl\Util\IntlTestHelper; | ||
15 | |||
16 | class IntegerTypeTest extends TypeTestCase | ||
17 | { | ||
18 | protected function setUp() | ||
19 | { | ||
20 | IntlTestHelper::requireIntl($this); | ||
21 | |||
22 | parent::setUp(); | ||
23 | } | ||
24 | |||
25 | public function testSubmitCastsToInteger() | ||
26 | { | ||
27 | $form = $this->factory->create('integer'); | ||
28 | |||
29 | $form->submit('1.678'); | ||
30 | |||
31 | $this->assertSame(1, $form->getData()); | ||
32 | $this->assertSame('1', $form->getViewData()); | ||
33 | } | ||
34 | } | ||
diff --git a/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/Type/LanguageTypeTest.php b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/Type/LanguageTypeTest.php new file mode 100644 index 00000000..24434b21 --- /dev/null +++ b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/Type/LanguageTypeTest.php | |||
@@ -0,0 +1,47 @@ | |||
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\Extension\Core\View\ChoiceView; | ||
15 | use Symfony\Component\Intl\Util\IntlTestHelper; | ||
16 | |||
17 | class LanguageTypeTest extends TypeTestCase | ||
18 | { | ||
19 | protected function setUp() | ||
20 | { | ||
21 | IntlTestHelper::requireIntl($this); | ||
22 | |||
23 | parent::setUp(); | ||
24 | } | ||
25 | |||
26 | public function testCountriesAreSelectable() | ||
27 | { | ||
28 | $form = $this->factory->create('language'); | ||
29 | $view = $form->createView(); | ||
30 | $choices = $view->vars['choices']; | ||
31 | |||
32 | $this->assertContains(new ChoiceView('en', 'en', 'English'), $choices, '', false, false); | ||
33 | $this->assertContains(new ChoiceView('en_GB', 'en_GB', 'British English'), $choices, '', false, false); | ||
34 | $this->assertContains(new ChoiceView('en_US', 'en_US', 'U.S. English'), $choices, '', false, false); | ||
35 | $this->assertContains(new ChoiceView('fr', 'fr', 'French'), $choices, '', false, false); | ||
36 | $this->assertContains(new ChoiceView('my', 'my', 'Burmese'), $choices, '', false, false); | ||
37 | } | ||
38 | |||
39 | public function testMultipleLanguagesIsNotIncluded() | ||
40 | { | ||
41 | $form = $this->factory->create('language', 'language'); | ||
42 | $view = $form->createView(); | ||
43 | $choices = $view->vars['choices']; | ||
44 | |||
45 | $this->assertNotContains(new ChoiceView('mul', 'mul', 'Mehrsprachig'), $choices, '', false, false); | ||
46 | } | ||
47 | } | ||
diff --git a/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/Type/LocaleTypeTest.php b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/Type/LocaleTypeTest.php new file mode 100644 index 00000000..e402cb4b --- /dev/null +++ b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/Type/LocaleTypeTest.php | |||
@@ -0,0 +1,36 @@ | |||
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\Extension\Core\View\ChoiceView; | ||
15 | use Symfony\Component\Intl\Util\IntlTestHelper; | ||
16 | |||
17 | class LocaleTypeTest extends TypeTestCase | ||
18 | { | ||
19 | protected function setUp() | ||
20 | { | ||
21 | IntlTestHelper::requireIntl($this); | ||
22 | |||
23 | parent::setUp(); | ||
24 | } | ||
25 | |||
26 | public function testLocalesAreSelectable() | ||
27 | { | ||
28 | $form = $this->factory->create('locale'); | ||
29 | $view = $form->createView(); | ||
30 | $choices = $view->vars['choices']; | ||
31 | |||
32 | $this->assertContains(new ChoiceView('en', 'en', 'English'), $choices, '', false, false); | ||
33 | $this->assertContains(new ChoiceView('en_GB', 'en_GB', 'English (United Kingdom)'), $choices, '', false, false); | ||
34 | $this->assertContains(new ChoiceView('zh_Hant_MO', 'zh_Hant_MO', 'Chinese (Traditional, Macau SAR China)'), $choices, '', false, false); | ||
35 | } | ||
36 | } | ||
diff --git a/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/Type/MoneyTypeTest.php b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/Type/MoneyTypeTest.php new file mode 100644 index 00000000..97fc37fa --- /dev/null +++ b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/Type/MoneyTypeTest.php | |||
@@ -0,0 +1,59 @@ | |||
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\Intl\Util\IntlTestHelper; | ||
15 | |||
16 | class MoneyTypeTest extends TypeTestCase | ||
17 | { | ||
18 | protected function setUp() | ||
19 | { | ||
20 | // we test against different locales, so we need the full | ||
21 | // implementation | ||
22 | IntlTestHelper::requireFullIntl($this); | ||
23 | |||
24 | parent::setUp(); | ||
25 | } | ||
26 | |||
27 | public function testPassMoneyPatternToView() | ||
28 | { | ||
29 | \Locale::setDefault('de_DE'); | ||
30 | |||
31 | $form = $this->factory->create('money'); | ||
32 | $view = $form->createView(); | ||
33 | |||
34 | $this->assertSame('{{ widget }} €', $view->vars['money_pattern']); | ||
35 | } | ||
36 | |||
37 | public function testMoneyPatternWorksForYen() | ||
38 | { | ||
39 | \Locale::setDefault('en_US'); | ||
40 | |||
41 | $form = $this->factory->create('money', null, array('currency' => 'JPY')); | ||
42 | $view = $form->createView(); | ||
43 | $this->assertTrue((Boolean) strstr($view->vars['money_pattern'], 'Â¥')); | ||
44 | } | ||
45 | |||
46 | // https://github.com/symfony/symfony/issues/5458 | ||
47 | public function testPassDifferentPatternsForDifferentCurrencies() | ||
48 | { | ||
49 | \Locale::setDefault('de_DE'); | ||
50 | |||
51 | $form1 = $this->factory->create('money', null, array('currency' => 'GBP')); | ||
52 | $form2 = $this->factory->create('money', null, array('currency' => 'EUR')); | ||
53 | $view1 = $form1->createView(); | ||
54 | $view2 = $form2->createView(); | ||
55 | |||
56 | $this->assertSame('{{ widget }} £', $view1->vars['money_pattern']); | ||
57 | $this->assertSame('{{ widget }} €', $view2->vars['money_pattern']); | ||
58 | } | ||
59 | } | ||
diff --git a/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/Type/NumberTypeTest.php b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/Type/NumberTypeTest.php new file mode 100644 index 00000000..e5b3dd74 --- /dev/null +++ b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/Type/NumberTypeTest.php | |||
@@ -0,0 +1,63 @@ | |||
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\Intl\Util\IntlTestHelper; | ||
15 | |||
16 | class NumberTypeTest extends TypeTestCase | ||
17 | { | ||
18 | protected function setUp() | ||
19 | { | ||
20 | parent::setUp(); | ||
21 | |||
22 | // we test against "de_DE", so we need the full implementation | ||
23 | IntlTestHelper::requireFullIntl($this); | ||
24 | |||
25 | \Locale::setDefault('de_DE'); | ||
26 | } | ||
27 | |||
28 | public function testDefaultFormatting() | ||
29 | { | ||
30 | $form = $this->factory->create('number'); | ||
31 | $form->setData('12345.67890'); | ||
32 | $view = $form->createView(); | ||
33 | |||
34 | $this->assertSame('12345,679', $view->vars['value']); | ||
35 | } | ||
36 | |||
37 | public function testDefaultFormattingWithGrouping() | ||
38 | { | ||
39 | $form = $this->factory->create('number', null, array('grouping' => true)); | ||
40 | $form->setData('12345.67890'); | ||
41 | $view = $form->createView(); | ||
42 | |||
43 | $this->assertSame('12.345,679', $view->vars['value']); | ||
44 | } | ||
45 | |||
46 | public function testDefaultFormattingWithPrecision() | ||
47 | { | ||
48 | $form = $this->factory->create('number', null, array('precision' => 2)); | ||
49 | $form->setData('12345.67890'); | ||
50 | $view = $form->createView(); | ||
51 | |||
52 | $this->assertSame('12345,68', $view->vars['value']); | ||
53 | } | ||
54 | |||
55 | public function testDefaultFormattingWithRounding() | ||
56 | { | ||
57 | $form = $this->factory->create('number', null, array('precision' => 0, 'rounding_mode' => \NumberFormatter::ROUND_UP)); | ||
58 | $form->setData('12345.54321'); | ||
59 | $view = $form->createView(); | ||
60 | |||
61 | $this->assertSame('12346', $view->vars['value']); | ||
62 | } | ||
63 | } | ||
diff --git a/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/Type/PasswordTypeTest.php b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/Type/PasswordTypeTest.php new file mode 100644 index 00000000..bccb6f7b --- /dev/null +++ b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/Type/PasswordTypeTest.php | |||
@@ -0,0 +1,51 @@ | |||
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 | class PasswordTypeTest extends \Symfony\Component\Form\Test\TypeTestCase | ||
15 | { | ||
16 | public function testEmptyIfNotSubmitted() | ||
17 | { | ||
18 | $form = $this->factory->create('password'); | ||
19 | $form->setData('pAs5w0rd'); | ||
20 | $view = $form->createView(); | ||
21 | |||
22 | $this->assertSame('', $view->vars['value']); | ||
23 | } | ||
24 | |||
25 | public function testEmptyIfSubmitted() | ||
26 | { | ||
27 | $form = $this->factory->create('password'); | ||
28 | $form->submit('pAs5w0rd'); | ||
29 | $view = $form->createView(); | ||
30 | |||
31 | $this->assertSame('', $view->vars['value']); | ||
32 | } | ||
33 | |||
34 | public function testNotEmptyIfSubmittedAndNotAlwaysEmpty() | ||
35 | { | ||
36 | $form = $this->factory->create('password', null, array('always_empty' => false)); | ||
37 | $form->submit('pAs5w0rd'); | ||
38 | $view = $form->createView(); | ||
39 | |||
40 | $this->assertSame('pAs5w0rd', $view->vars['value']); | ||
41 | } | ||
42 | |||
43 | public function testNotTrimmed() | ||
44 | { | ||
45 | $form = $this->factory->create('password', null); | ||
46 | $form->submit(' pAs5w0rd '); | ||
47 | $data = $form->getData(); | ||
48 | |||
49 | $this->assertSame(' pAs5w0rd ', $data); | ||
50 | } | ||
51 | } | ||
diff --git a/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/Type/RepeatedTypeTest.php b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/Type/RepeatedTypeTest.php new file mode 100644 index 00000000..9e125d78 --- /dev/null +++ b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/Type/RepeatedTypeTest.php | |||
@@ -0,0 +1,149 @@ | |||
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 | class RepeatedTypeTest extends \Symfony\Component\Form\Test\TypeTestCase | ||
15 | { | ||
16 | protected $form; | ||
17 | |||
18 | protected function setUp() | ||
19 | { | ||
20 | parent::setUp(); | ||
21 | |||
22 | $this->form = $this->factory->create('repeated', null, array( | ||
23 | 'type' => 'text', | ||
24 | )); | ||
25 | $this->form->setData(null); | ||
26 | } | ||
27 | |||
28 | public function testSetData() | ||
29 | { | ||
30 | $this->form->setData('foobar'); | ||
31 | |||
32 | $this->assertEquals('foobar', $this->form['first']->getData()); | ||
33 | $this->assertEquals('foobar', $this->form['second']->getData()); | ||
34 | } | ||
35 | |||
36 | public function testSetOptions() | ||
37 | { | ||
38 | $form = $this->factory->create('repeated', null, array( | ||
39 | 'type' => 'text', | ||
40 | 'options' => array('label' => 'Global'), | ||
41 | )); | ||
42 | |||
43 | $this->assertEquals('Global', $form['first']->getConfig()->getOption('label')); | ||
44 | $this->assertEquals('Global', $form['second']->getConfig()->getOption('label')); | ||
45 | $this->assertTrue($form['first']->isRequired()); | ||
46 | $this->assertTrue($form['second']->isRequired()); | ||
47 | } | ||
48 | |||
49 | public function testSetOptionsPerChild() | ||
50 | { | ||
51 | $form = $this->factory->create('repeated', null, array( | ||
52 | // the global required value cannot be overridden | ||
53 | 'type' => 'text', | ||
54 | 'first_options' => array('label' => 'Test', 'required' => false), | ||
55 | 'second_options' => array('label' => 'Test2') | ||
56 | )); | ||
57 | |||
58 | $this->assertEquals('Test', $form['first']->getConfig()->getOption('label')); | ||
59 | $this->assertEquals('Test2', $form['second']->getConfig()->getOption('label')); | ||
60 | $this->assertTrue($form['first']->isRequired()); | ||
61 | $this->assertTrue($form['second']->isRequired()); | ||
62 | } | ||
63 | |||
64 | public function testSetRequired() | ||
65 | { | ||
66 | $form = $this->factory->create('repeated', null, array( | ||
67 | 'required' => false, | ||
68 | 'type' => 'text', | ||
69 | )); | ||
70 | |||
71 | $this->assertFalse($form['first']->isRequired()); | ||
72 | $this->assertFalse($form['second']->isRequired()); | ||
73 | } | ||
74 | |||
75 | public function testSetErrorBubblingToTrue() | ||
76 | { | ||
77 | $form = $this->factory->create('repeated', null, array( | ||
78 | 'error_bubbling' => true, | ||
79 | )); | ||
80 | |||
81 | $this->assertTrue($form->getConfig()->getOption('error_bubbling')); | ||
82 | $this->assertTrue($form['first']->getConfig()->getOption('error_bubbling')); | ||
83 | $this->assertTrue($form['second']->getConfig()->getOption('error_bubbling')); | ||
84 | } | ||
85 | |||
86 | public function testSetErrorBubblingToFalse() | ||
87 | { | ||
88 | $form = $this->factory->create('repeated', null, array( | ||
89 | 'error_bubbling' => false, | ||
90 | )); | ||
91 | |||
92 | $this->assertFalse($form->getConfig()->getOption('error_bubbling')); | ||
93 | $this->assertFalse($form['first']->getConfig()->getOption('error_bubbling')); | ||
94 | $this->assertFalse($form['second']->getConfig()->getOption('error_bubbling')); | ||
95 | } | ||
96 | |||
97 | public function testSetErrorBubblingIndividually() | ||
98 | { | ||
99 | $form = $this->factory->create('repeated', null, array( | ||
100 | 'error_bubbling' => true, | ||
101 | 'options' => array('error_bubbling' => false), | ||
102 | 'second_options' => array('error_bubbling' => true), | ||
103 | )); | ||
104 | |||
105 | $this->assertTrue($form->getConfig()->getOption('error_bubbling')); | ||
106 | $this->assertFalse($form['first']->getConfig()->getOption('error_bubbling')); | ||
107 | $this->assertTrue($form['second']->getConfig()->getOption('error_bubbling')); | ||
108 | } | ||
109 | |||
110 | public function testSetOptionsPerChildAndOverwrite() | ||
111 | { | ||
112 | $form = $this->factory->create('repeated', null, array( | ||
113 | 'type' => 'text', | ||
114 | 'options' => array('label' => 'Label'), | ||
115 | 'second_options' => array('label' => 'Second label') | ||
116 | )); | ||
117 | |||
118 | $this->assertEquals('Label', $form['first']->getConfig()->getOption('label')); | ||
119 | $this->assertEquals('Second label', $form['second']->getConfig()->getOption('label')); | ||
120 | $this->assertTrue($form['first']->isRequired()); | ||
121 | $this->assertTrue($form['second']->isRequired()); | ||
122 | } | ||
123 | |||
124 | public function testSubmitUnequal() | ||
125 | { | ||
126 | $input = array('first' => 'foo', 'second' => 'bar'); | ||
127 | |||
128 | $this->form->submit($input); | ||
129 | |||
130 | $this->assertEquals('foo', $this->form['first']->getViewData()); | ||
131 | $this->assertEquals('bar', $this->form['second']->getViewData()); | ||
132 | $this->assertFalse($this->form->isSynchronized()); | ||
133 | $this->assertEquals($input, $this->form->getViewData()); | ||
134 | $this->assertNull($this->form->getData()); | ||
135 | } | ||
136 | |||
137 | public function testSubmitEqual() | ||
138 | { | ||
139 | $input = array('first' => 'foo', 'second' => 'foo'); | ||
140 | |||
141 | $this->form->submit($input); | ||
142 | |||
143 | $this->assertEquals('foo', $this->form['first']->getViewData()); | ||
144 | $this->assertEquals('foo', $this->form['second']->getViewData()); | ||
145 | $this->assertTrue($this->form->isSynchronized()); | ||
146 | $this->assertEquals($input, $this->form->getViewData()); | ||
147 | $this->assertEquals('foo', $this->form->getData()); | ||
148 | } | ||
149 | } | ||
diff --git a/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/Type/SubmitTypeTest.php b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/Type/SubmitTypeTest.php new file mode 100644 index 00000000..8cc72281 --- /dev/null +++ b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/Type/SubmitTypeTest.php | |||
@@ -0,0 +1,54 @@ | |||
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 | /** | ||
15 | * @author Bernhard Schussek <bschussek@gmail.com> | ||
16 | */ | ||
17 | class SubmitTypeTest extends TypeTestCase | ||
18 | { | ||
19 | public function testCreateSubmitButtonInstances() | ||
20 | { | ||
21 | $this->assertInstanceOf('Symfony\Component\Form\SubmitButton', $this->factory->create('submit')); | ||
22 | } | ||
23 | |||
24 | public function testNotClickedByDefault() | ||
25 | { | ||
26 | $button = $this->factory->create('submit'); | ||
27 | |||
28 | $this->assertFalse($button->isClicked()); | ||
29 | } | ||
30 | |||
31 | public function testNotClickedIfSubmittedWithNull() | ||
32 | { | ||
33 | $button = $this->factory->create('submit'); | ||
34 | $button->submit(null); | ||
35 | |||
36 | $this->assertFalse($button->isClicked()); | ||
37 | } | ||
38 | |||
39 | public function testClickedIfSubmittedWithEmptyString() | ||
40 | { | ||
41 | $button = $this->factory->create('submit'); | ||
42 | $button->submit(''); | ||
43 | |||
44 | $this->assertTrue($button->isClicked()); | ||
45 | } | ||
46 | |||
47 | public function testClickedIfSubmittedWithUnemptyString() | ||
48 | { | ||
49 | $button = $this->factory->create('submit'); | ||
50 | $button->submit('foo'); | ||
51 | |||
52 | $this->assertTrue($button->isClicked()); | ||
53 | } | ||
54 | } | ||
diff --git a/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/Type/TimeTypeTest.php b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/Type/TimeTypeTest.php new file mode 100644 index 00000000..9bdfe156 --- /dev/null +++ b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/Type/TimeTypeTest.php | |||
@@ -0,0 +1,649 @@ | |||
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\Extension\Core\View\ChoiceView; | ||
15 | use Symfony\Component\Form\FormError; | ||
16 | use Symfony\Component\Intl\Util\IntlTestHelper; | ||
17 | |||
18 | class TimeTypeTest extends TypeTestCase | ||
19 | { | ||
20 | protected function setUp() | ||
21 | { | ||
22 | IntlTestHelper::requireIntl($this); | ||
23 | |||
24 | parent::setUp(); | ||
25 | } | ||
26 | |||
27 | public function testSubmitDateTime() | ||
28 | { | ||
29 | $form = $this->factory->create('time', null, array( | ||
30 | 'model_timezone' => 'UTC', | ||
31 | 'view_timezone' => 'UTC', | ||
32 | 'input' => 'datetime', | ||
33 | )); | ||
34 | |||
35 | $input = array( | ||
36 | 'hour' => '3', | ||
37 | 'minute' => '4', | ||
38 | ); | ||
39 | |||
40 | $form->submit($input); | ||
41 | |||
42 | $dateTime = new \DateTime('1970-01-01 03:04:00 UTC'); | ||
43 | |||
44 | $this->assertEquals($dateTime, $form->getData()); | ||
45 | $this->assertEquals($input, $form->getViewData()); | ||
46 | } | ||
47 | |||
48 | public function testSubmitString() | ||
49 | { | ||
50 | $form = $this->factory->create('time', null, array( | ||
51 | 'model_timezone' => 'UTC', | ||
52 | 'view_timezone' => 'UTC', | ||
53 | 'input' => 'string', | ||
54 | )); | ||
55 | |||
56 | $input = array( | ||
57 | 'hour' => '3', | ||
58 | 'minute' => '4', | ||
59 | ); | ||
60 | |||
61 | $form->submit($input); | ||
62 | |||
63 | $this->assertEquals('03:04:00', $form->getData()); | ||
64 | $this->assertEquals($input, $form->getViewData()); | ||
65 | } | ||
66 | |||
67 | public function testSubmitTimestamp() | ||
68 | { | ||
69 | $form = $this->factory->create('time', null, array( | ||
70 | 'model_timezone' => 'UTC', | ||
71 | 'view_timezone' => 'UTC', | ||
72 | 'input' => 'timestamp', | ||
73 | )); | ||
74 | |||
75 | $input = array( | ||
76 | 'hour' => '3', | ||
77 | 'minute' => '4', | ||
78 | ); | ||
79 | |||
80 | $form->submit($input); | ||
81 | |||
82 | $dateTime = new \DateTime('1970-01-01 03:04:00 UTC'); | ||
83 | |||
84 | $this->assertEquals($dateTime->format('U'), $form->getData()); | ||
85 | $this->assertEquals($input, $form->getViewData()); | ||
86 | } | ||
87 | |||
88 | public function testSubmitArray() | ||
89 | { | ||
90 | $form = $this->factory->create('time', null, array( | ||
91 | 'model_timezone' => 'UTC', | ||
92 | 'view_timezone' => 'UTC', | ||
93 | 'input' => 'array', | ||
94 | )); | ||
95 | |||
96 | $input = array( | ||
97 | 'hour' => '3', | ||
98 | 'minute' => '4', | ||
99 | ); | ||
100 | |||
101 | $form->submit($input); | ||
102 | |||
103 | $this->assertEquals($input, $form->getData()); | ||
104 | $this->assertEquals($input, $form->getViewData()); | ||
105 | } | ||
106 | |||
107 | public function testSubmitDatetimeSingleText() | ||
108 | { | ||
109 | $form = $this->factory->create('time', null, array( | ||
110 | 'model_timezone' => 'UTC', | ||
111 | 'view_timezone' => 'UTC', | ||
112 | 'input' => 'datetime', | ||
113 | 'widget' => 'single_text', | ||
114 | )); | ||
115 | |||
116 | $form->submit('03:04'); | ||
117 | |||
118 | $this->assertEquals(new \DateTime('1970-01-01 03:04:00 UTC'), $form->getData()); | ||
119 | $this->assertEquals('03:04', $form->getViewData()); | ||
120 | } | ||
121 | |||
122 | public function testSubmitDatetimeSingleTextWithoutMinutes() | ||
123 | { | ||
124 | $form = $this->factory->create('time', null, array( | ||
125 | 'model_timezone' => 'UTC', | ||
126 | 'view_timezone' => 'UTC', | ||
127 | 'input' => 'datetime', | ||
128 | 'widget' => 'single_text', | ||
129 | 'with_minutes' => false, | ||
130 | )); | ||
131 | |||
132 | $form->submit('03'); | ||
133 | |||
134 | $this->assertEquals(new \DateTime('1970-01-01 03:00:00 UTC'), $form->getData()); | ||
135 | $this->assertEquals('03', $form->getViewData()); | ||
136 | } | ||
137 | |||
138 | public function testSubmitArraySingleText() | ||
139 | { | ||
140 | $form = $this->factory->create('time', null, array( | ||
141 | 'model_timezone' => 'UTC', | ||
142 | 'view_timezone' => 'UTC', | ||
143 | 'input' => 'array', | ||
144 | 'widget' => 'single_text', | ||
145 | )); | ||
146 | |||
147 | $data = array( | ||
148 | 'hour' => '3', | ||
149 | 'minute' => '4', | ||
150 | ); | ||
151 | |||
152 | $form->submit('03:04'); | ||
153 | |||
154 | $this->assertEquals($data, $form->getData()); | ||
155 | $this->assertEquals('03:04', $form->getViewData()); | ||
156 | } | ||
157 | |||
158 | public function testSubmitArraySingleTextWithoutMinutes() | ||
159 | { | ||
160 | $form = $this->factory->create('time', null, array( | ||
161 | 'model_timezone' => 'UTC', | ||
162 | 'view_timezone' => 'UTC', | ||
163 | 'input' => 'array', | ||
164 | 'widget' => 'single_text', | ||
165 | 'with_minutes' => false, | ||
166 | )); | ||
167 | |||
168 | $data = array( | ||
169 | 'hour' => '3', | ||
170 | ); | ||
171 | |||
172 | $form->submit('03'); | ||
173 | |||
174 | $this->assertEquals($data, $form->getData()); | ||
175 | $this->assertEquals('03', $form->getViewData()); | ||
176 | } | ||
177 | |||
178 | public function testSubmitArraySingleTextWithSeconds() | ||
179 | { | ||
180 | $form = $this->factory->create('time', null, array( | ||
181 | 'model_timezone' => 'UTC', | ||
182 | 'view_timezone' => 'UTC', | ||
183 | 'input' => 'array', | ||
184 | 'widget' => 'single_text', | ||
185 | 'with_seconds' => true, | ||
186 | )); | ||
187 | |||
188 | $data = array( | ||
189 | 'hour' => '3', | ||
190 | 'minute' => '4', | ||
191 | 'second' => '5', | ||
192 | ); | ||
193 | |||
194 | $form->submit('03:04:05'); | ||
195 | |||
196 | $this->assertEquals($data, $form->getData()); | ||
197 | $this->assertEquals('03:04:05', $form->getViewData()); | ||
198 | } | ||
199 | |||
200 | public function testSubmitStringSingleText() | ||
201 | { | ||
202 | $form = $this->factory->create('time', null, array( | ||
203 | 'model_timezone' => 'UTC', | ||
204 | 'view_timezone' => 'UTC', | ||
205 | 'input' => 'string', | ||
206 | 'widget' => 'single_text', | ||
207 | )); | ||
208 | |||
209 | $form->submit('03:04'); | ||
210 | |||
211 | $this->assertEquals('03:04:00', $form->getData()); | ||
212 | $this->assertEquals('03:04', $form->getViewData()); | ||
213 | } | ||
214 | |||
215 | public function testSubmitStringSingleTextWithoutMinutes() | ||
216 | { | ||
217 | $form = $this->factory->create('time', null, array( | ||
218 | 'model_timezone' => 'UTC', | ||
219 | 'view_timezone' => 'UTC', | ||
220 | 'input' => 'string', | ||
221 | 'widget' => 'single_text', | ||
222 | 'with_minutes' => false, | ||
223 | )); | ||
224 | |||
225 | $form->submit('03'); | ||
226 | |||
227 | $this->assertEquals('03:00:00', $form->getData()); | ||
228 | $this->assertEquals('03', $form->getViewData()); | ||
229 | } | ||
230 | |||
231 | public function testSetDataWithoutMinutes() | ||
232 | { | ||
233 | $form = $this->factory->create('time', null, array( | ||
234 | 'model_timezone' => 'UTC', | ||
235 | 'view_timezone' => 'UTC', | ||
236 | 'input' => 'datetime', | ||
237 | 'with_minutes' => false, | ||
238 | )); | ||
239 | |||
240 | $form->setData(new \DateTime('03:04:05 UTC')); | ||
241 | |||
242 | $this->assertEquals(array('hour' => 3), $form->getViewData()); | ||
243 | } | ||
244 | |||
245 | public function testSetDataWithSeconds() | ||
246 | { | ||
247 | $form = $this->factory->create('time', null, array( | ||
248 | 'model_timezone' => 'UTC', | ||
249 | 'view_timezone' => 'UTC', | ||
250 | 'input' => 'datetime', | ||
251 | 'with_seconds' => true, | ||
252 | )); | ||
253 | |||
254 | $form->setData(new \DateTime('03:04:05 UTC')); | ||
255 | |||
256 | $this->assertEquals(array('hour' => 3, 'minute' => 4, 'second' => 5), $form->getViewData()); | ||
257 | } | ||
258 | |||
259 | public function testSetDataDifferentTimezones() | ||
260 | { | ||
261 | $form = $this->factory->create('time', null, array( | ||
262 | 'model_timezone' => 'America/New_York', | ||
263 | 'view_timezone' => 'Asia/Hong_Kong', | ||
264 | 'input' => 'string', | ||
265 | 'with_seconds' => true, | ||
266 | )); | ||
267 | |||
268 | $dateTime = new \DateTime('2013-01-01 12:04:05'); | ||
269 | $dateTime->setTimezone(new \DateTimeZone('America/New_York')); | ||
270 | |||
271 | $form->setData($dateTime->format('H:i:s')); | ||
272 | |||
273 | $outputTime = clone $dateTime; | ||
274 | $outputTime->setTimezone(new \DateTimeZone('Asia/Hong_Kong')); | ||
275 | |||
276 | $displayedData = array( | ||
277 | 'hour' => (int) $outputTime->format('H'), | ||
278 | 'minute' => (int) $outputTime->format('i'), | ||
279 | 'second' => (int) $outputTime->format('s') | ||
280 | ); | ||
281 | |||
282 | $this->assertEquals($displayedData, $form->getViewData()); | ||
283 | } | ||
284 | |||
285 | public function testSetDataDifferentTimezonesDateTime() | ||
286 | { | ||
287 | $form = $this->factory->create('time', null, array( | ||
288 | 'model_timezone' => 'America/New_York', | ||
289 | 'view_timezone' => 'Asia/Hong_Kong', | ||
290 | 'input' => 'datetime', | ||
291 | 'with_seconds' => true, | ||
292 | )); | ||
293 | |||
294 | $dateTime = new \DateTime('12:04:05'); | ||
295 | $dateTime->setTimezone(new \DateTimeZone('America/New_York')); | ||
296 | |||
297 | $form->setData($dateTime); | ||
298 | |||
299 | $outputTime = clone $dateTime; | ||
300 | $outputTime->setTimezone(new \DateTimeZone('Asia/Hong_Kong')); | ||
301 | |||
302 | $displayedData = array( | ||
303 | 'hour' => (int) $outputTime->format('H'), | ||
304 | 'minute' => (int) $outputTime->format('i'), | ||
305 | 'second' => (int) $outputTime->format('s') | ||
306 | ); | ||
307 | |||
308 | $this->assertDateTimeEquals($dateTime, $form->getData()); | ||
309 | $this->assertEquals($displayedData, $form->getViewData()); | ||
310 | } | ||
311 | |||
312 | public function testHoursOption() | ||
313 | { | ||
314 | $form = $this->factory->create('time', null, array( | ||
315 | 'hours' => array(6, 7), | ||
316 | )); | ||
317 | |||
318 | $view = $form->createView(); | ||
319 | |||
320 | $this->assertEquals(array( | ||
321 | new ChoiceView('6', '6', '06'), | ||
322 | new ChoiceView('7', '7', '07'), | ||
323 | ), $view['hour']->vars['choices']); | ||
324 | } | ||
325 | |||
326 | public function testIsMinuteWithinRangeReturnsTrueIfWithin() | ||
327 | { | ||
328 | $form = $this->factory->create('time', null, array( | ||
329 | 'minutes' => array(6, 7), | ||
330 | )); | ||
331 | |||
332 | $view = $form->createView(); | ||
333 | |||
334 | $this->assertEquals(array( | ||
335 | new ChoiceView('6', '6', '06'), | ||
336 | new ChoiceView('7', '7', '07'), | ||
337 | ), $view['minute']->vars['choices']); | ||
338 | } | ||
339 | |||
340 | public function testIsSecondWithinRangeReturnsTrueIfWithin() | ||
341 | { | ||
342 | $form = $this->factory->create('time', null, array( | ||
343 | 'seconds' => array(6, 7), | ||
344 | 'with_seconds' => true, | ||
345 | )); | ||
346 | |||
347 | $view = $form->createView(); | ||
348 | |||
349 | $this->assertEquals(array( | ||
350 | new ChoiceView('6', '6', '06'), | ||
351 | new ChoiceView('7', '7', '07'), | ||
352 | ), $view['second']->vars['choices']); | ||
353 | } | ||
354 | |||
355 | public function testIsPartiallyFilledReturnsFalseIfCompletelyEmpty() | ||
356 | { | ||
357 | $this->markTestIncomplete('Needs to be reimplemented using validators'); | ||
358 | |||
359 | $form = $this->factory->create('time', null, array( | ||
360 | 'widget' => 'choice', | ||
361 | )); | ||
362 | |||
363 | $form->submit(array( | ||
364 | 'hour' => '', | ||
365 | 'minute' => '', | ||
366 | )); | ||
367 | |||
368 | $this->assertFalse($form->isPartiallyFilled()); | ||
369 | } | ||
370 | |||
371 | public function testIsPartiallyFilledReturnsFalseIfCompletelyEmptyWithSeconds() | ||
372 | { | ||
373 | $this->markTestIncomplete('Needs to be reimplemented using validators'); | ||
374 | |||
375 | $form = $this->factory->create('time', null, array( | ||
376 | 'widget' => 'choice', | ||
377 | 'with_seconds' => true, | ||
378 | )); | ||
379 | |||
380 | $form->submit(array( | ||
381 | 'hour' => '', | ||
382 | 'minute' => '', | ||
383 | 'second' => '', | ||
384 | )); | ||
385 | |||
386 | $this->assertFalse($form->isPartiallyFilled()); | ||
387 | } | ||
388 | |||
389 | public function testIsPartiallyFilledReturnsFalseIfCompletelyFilled() | ||
390 | { | ||
391 | $this->markTestIncomplete('Needs to be reimplemented using validators'); | ||
392 | |||
393 | $form = $this->factory->create('time', null, array( | ||
394 | 'widget' => 'choice', | ||
395 | )); | ||
396 | |||
397 | $form->submit(array( | ||
398 | 'hour' => '0', | ||
399 | 'minute' => '0', | ||
400 | )); | ||
401 | |||
402 | $this->assertFalse($form->isPartiallyFilled()); | ||
403 | } | ||
404 | |||
405 | public function testIsPartiallyFilledReturnsFalseIfCompletelyFilledWithSeconds() | ||
406 | { | ||
407 | $this->markTestIncomplete('Needs to be reimplemented using validators'); | ||
408 | |||
409 | $form = $this->factory->create('time', null, array( | ||
410 | 'widget' => 'choice', | ||
411 | 'with_seconds' => true, | ||
412 | )); | ||
413 | |||
414 | $form->submit(array( | ||
415 | 'hour' => '0', | ||
416 | 'minute' => '0', | ||
417 | 'second' => '0', | ||
418 | )); | ||
419 | |||
420 | $this->assertFalse($form->isPartiallyFilled()); | ||
421 | } | ||
422 | |||
423 | public function testIsPartiallyFilledReturnsTrueIfChoiceAndHourEmpty() | ||
424 | { | ||
425 | $this->markTestIncomplete('Needs to be reimplemented using validators'); | ||
426 | |||
427 | $form = $this->factory->create('time', null, array( | ||
428 | 'widget' => 'choice', | ||
429 | 'with_seconds' => true, | ||
430 | )); | ||
431 | |||
432 | $form->submit(array( | ||
433 | 'hour' => '', | ||
434 | 'minute' => '0', | ||
435 | 'second' => '0', | ||
436 | )); | ||
437 | |||
438 | $this->assertTrue($form->isPartiallyFilled()); | ||
439 | } | ||
440 | |||
441 | public function testIsPartiallyFilledReturnsTrueIfChoiceAndMinuteEmpty() | ||
442 | { | ||
443 | $this->markTestIncomplete('Needs to be reimplemented using validators'); | ||
444 | |||
445 | $form = $this->factory->create('time', null, array( | ||
446 | 'widget' => 'choice', | ||
447 | 'with_seconds' => true, | ||
448 | )); | ||
449 | |||
450 | $form->submit(array( | ||
451 | 'hour' => '0', | ||
452 | 'minute' => '', | ||
453 | 'second' => '0', | ||
454 | )); | ||
455 | |||
456 | $this->assertTrue($form->isPartiallyFilled()); | ||
457 | } | ||
458 | |||
459 | public function testIsPartiallyFilledReturnsTrueIfChoiceAndSecondsEmpty() | ||
460 | { | ||
461 | $this->markTestIncomplete('Needs to be reimplemented using validators'); | ||
462 | |||
463 | $form = $this->factory->create('time', null, array( | ||
464 | 'widget' => 'choice', | ||
465 | 'with_seconds' => true, | ||
466 | )); | ||
467 | |||
468 | $form->submit(array( | ||
469 | 'hour' => '0', | ||
470 | 'minute' => '0', | ||
471 | 'second' => '', | ||
472 | )); | ||
473 | |||
474 | $this->assertTrue($form->isPartiallyFilled()); | ||
475 | } | ||
476 | |||
477 | // Bug fix | ||
478 | public function testInitializeWithDateTime() | ||
479 | { | ||
480 | // Throws an exception if "data_class" option is not explicitly set | ||
481 | // to null in the type | ||
482 | $this->factory->create('time', new \DateTime()); | ||
483 | } | ||
484 | |||
485 | public function testSingleTextWidgetShouldUseTheRightInputType() | ||
486 | { | ||
487 | $form = $this->factory->create('time', null, array( | ||
488 | 'widget' => 'single_text', | ||
489 | )); | ||
490 | |||
491 | $view = $form->createView(); | ||
492 | $this->assertEquals('time', $view->vars['type']); | ||
493 | } | ||
494 | |||
495 | public function testPassDefaultEmptyValueToViewIfNotRequired() | ||
496 | { | ||
497 | $form = $this->factory->create('time', null, array( | ||
498 | 'required' => false, | ||
499 | 'with_seconds' => true, | ||
500 | )); | ||
501 | |||
502 | $view = $form->createView(); | ||
503 | $this->assertSame('', $view['hour']->vars['empty_value']); | ||
504 | $this->assertSame('', $view['minute']->vars['empty_value']); | ||
505 | $this->assertSame('', $view['second']->vars['empty_value']); | ||
506 | } | ||
507 | |||
508 | public function testPassNoEmptyValueToViewIfRequired() | ||
509 | { | ||
510 | $form = $this->factory->create('time', null, array( | ||
511 | 'required' => true, | ||
512 | 'with_seconds' => true, | ||
513 | )); | ||
514 | |||
515 | $view = $form->createView(); | ||
516 | $this->assertNull($view['hour']->vars['empty_value']); | ||
517 | $this->assertNull($view['minute']->vars['empty_value']); | ||
518 | $this->assertNull($view['second']->vars['empty_value']); | ||
519 | } | ||
520 | |||
521 | public function testPassEmptyValueAsString() | ||
522 | { | ||
523 | $form = $this->factory->create('time', null, array( | ||
524 | 'empty_value' => 'Empty', | ||
525 | 'with_seconds' => true, | ||
526 | )); | ||
527 | |||
528 | $view = $form->createView(); | ||
529 | $this->assertSame('Empty', $view['hour']->vars['empty_value']); | ||
530 | $this->assertSame('Empty', $view['minute']->vars['empty_value']); | ||
531 | $this->assertSame('Empty', $view['second']->vars['empty_value']); | ||
532 | } | ||
533 | |||
534 | public function testPassEmptyValueAsArray() | ||
535 | { | ||
536 | $form = $this->factory->create('time', null, array( | ||
537 | 'empty_value' => array( | ||
538 | 'hour' => 'Empty hour', | ||
539 | 'minute' => 'Empty minute', | ||
540 | 'second' => 'Empty second', | ||
541 | ), | ||
542 | 'with_seconds' => true, | ||
543 | )); | ||
544 | |||
545 | $view = $form->createView(); | ||
546 | $this->assertSame('Empty hour', $view['hour']->vars['empty_value']); | ||
547 | $this->assertSame('Empty minute', $view['minute']->vars['empty_value']); | ||
548 | $this->assertSame('Empty second', $view['second']->vars['empty_value']); | ||
549 | } | ||
550 | |||
551 | public function testPassEmptyValueAsPartialArrayAddEmptyIfNotRequired() | ||
552 | { | ||
553 | $form = $this->factory->create('time', null, array( | ||
554 | 'required' => false, | ||
555 | 'empty_value' => array( | ||
556 | 'hour' => 'Empty hour', | ||
557 | 'second' => 'Empty second', | ||
558 | ), | ||
559 | 'with_seconds' => true, | ||
560 | )); | ||
561 | |||
562 | $view = $form->createView(); | ||
563 | $this->assertSame('Empty hour', $view['hour']->vars['empty_value']); | ||
564 | $this->assertSame('', $view['minute']->vars['empty_value']); | ||
565 | $this->assertSame('Empty second', $view['second']->vars['empty_value']); | ||
566 | } | ||
567 | |||
568 | public function testPassEmptyValueAsPartialArrayAddNullIfRequired() | ||
569 | { | ||
570 | $form = $this->factory->create('time', null, array( | ||
571 | 'required' => true, | ||
572 | 'empty_value' => array( | ||
573 | 'hour' => 'Empty hour', | ||
574 | 'second' => 'Empty second', | ||
575 | ), | ||
576 | 'with_seconds' => true, | ||
577 | )); | ||
578 | |||
579 | $view = $form->createView(); | ||
580 | $this->assertSame('Empty hour', $view['hour']->vars['empty_value']); | ||
581 | $this->assertNull($view['minute']->vars['empty_value']); | ||
582 | $this->assertSame('Empty second', $view['second']->vars['empty_value']); | ||
583 | } | ||
584 | |||
585 | public function provideCompoundWidgets() | ||
586 | { | ||
587 | return array( | ||
588 | array('text'), | ||
589 | array('choice'), | ||
590 | ); | ||
591 | } | ||
592 | |||
593 | /** | ||
594 | * @dataProvider provideCompoundWidgets | ||
595 | */ | ||
596 | public function testHourErrorsBubbleUp($widget) | ||
597 | { | ||
598 | $error = new FormError('Invalid!'); | ||
599 | $form = $this->factory->create('time', null, array( | ||
600 | 'widget' => $widget, | ||
601 | )); | ||
602 | $form['hour']->addError($error); | ||
603 | |||
604 | $this->assertSame(array(), $form['hour']->getErrors()); | ||
605 | $this->assertSame(array($error), $form->getErrors()); | ||
606 | } | ||
607 | |||
608 | /** | ||
609 | * @dataProvider provideCompoundWidgets | ||
610 | */ | ||
611 | public function testMinuteErrorsBubbleUp($widget) | ||
612 | { | ||
613 | $error = new FormError('Invalid!'); | ||
614 | $form = $this->factory->create('time', null, array( | ||
615 | 'widget' => $widget, | ||
616 | )); | ||
617 | $form['minute']->addError($error); | ||
618 | |||
619 | $this->assertSame(array(), $form['minute']->getErrors()); | ||
620 | $this->assertSame(array($error), $form->getErrors()); | ||
621 | } | ||
622 | |||
623 | /** | ||
624 | * @dataProvider provideCompoundWidgets | ||
625 | */ | ||
626 | public function testSecondErrorsBubbleUp($widget) | ||
627 | { | ||
628 | $error = new FormError('Invalid!'); | ||
629 | $form = $this->factory->create('time', null, array( | ||
630 | 'widget' => $widget, | ||
631 | 'with_seconds' => true, | ||
632 | )); | ||
633 | $form['second']->addError($error); | ||
634 | |||
635 | $this->assertSame(array(), $form['second']->getErrors()); | ||
636 | $this->assertSame(array($error), $form->getErrors()); | ||
637 | } | ||
638 | |||
639 | /** | ||
640 | * @expectedException \Symfony\Component\Form\Exception\InvalidConfigurationException | ||
641 | */ | ||
642 | public function testInitializeWithSecondsAndWithoutMinutes() | ||
643 | { | ||
644 | $this->factory->create('time', null, array( | ||
645 | 'with_minutes' => false, | ||
646 | 'with_seconds' => true, | ||
647 | )); | ||
648 | } | ||
649 | } | ||
diff --git a/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/Type/TimezoneTypeTest.php b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/Type/TimezoneTypeTest.php new file mode 100644 index 00000000..81df20cb --- /dev/null +++ b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/Type/TimezoneTypeTest.php | |||
@@ -0,0 +1,30 @@ | |||
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\Extension\Core\View\ChoiceView; | ||
15 | |||
16 | class TimezoneTypeTest extends \Symfony\Component\Form\Test\TypeTestCase | ||
17 | { | ||
18 | public function testTimezonesAreSelectable() | ||
19 | { | ||
20 | $form = $this->factory->create('timezone'); | ||
21 | $view = $form->createView(); | ||
22 | $choices = $view->vars['choices']; | ||
23 | |||
24 | $this->assertArrayHasKey('Africa', $choices); | ||
25 | $this->assertContains(new ChoiceView('Africa/Kinshasa', 'Africa/Kinshasa', 'Kinshasa'), $choices['Africa'], '', false, false); | ||
26 | |||
27 | $this->assertArrayHasKey('America', $choices); | ||
28 | $this->assertContains(new ChoiceView('America/New_York', 'America/New_York', 'New York'), $choices['America'], '', false, false); | ||
29 | } | ||
30 | } | ||
diff --git a/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/Type/TypeTestCase.php b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/Type/TypeTestCase.php new file mode 100644 index 00000000..733546e3 --- /dev/null +++ b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/Type/TypeTestCase.php | |||
@@ -0,0 +1,21 @@ | |||
1 | <?php | ||
2 | |||
3 | /* | ||
4 | * This file is part of the Symfony package. | ||
5 | * | ||
6 | * (c) Fabien Potencier <fabien.potencier@symfony-project.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\Test\TypeTestCase as BaseTypeTestCase; | ||
15 | |||
16 | /** | ||
17 | * @deprecated Deprecated since version 2.3, to be removed in 3.0. Use Symfony\Component\Form\Test\TypeTestCase instead. | ||
18 | */ | ||
19 | abstract class TypeTestCase extends BaseTypeTestCase | ||
20 | { | ||
21 | } | ||
diff --git a/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/Type/UrlTypeTest.php b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/Type/UrlTypeTest.php new file mode 100644 index 00000000..254b2a8e --- /dev/null +++ b/vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/Type/UrlTypeTest.php | |||
@@ -0,0 +1,61 @@ | |||
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 | class UrlTypeTest extends TypeTestCase | ||
15 | { | ||
16 | public function testSubmitAddsDefaultProtocolIfNoneIsIncluded() | ||
17 | { | ||
18 | $form = $this->factory->create('url', 'name'); | ||
19 | |||
20 | $form->submit('www.domain.com'); | ||
21 | |||
22 | $this->assertSame('http://www.domain.com', $form->getData()); | ||
23 | $this->assertSame('http://www.domain.com', $form->getViewData()); | ||
24 | } | ||
25 | |||
26 | public function testSubmitAddsNoDefaultProtocolIfAlreadyIncluded() | ||
27 | { | ||
28 | $form = $this->factory->create('url', null, array( | ||
29 | 'default_protocol' => 'http', | ||
30 | )); | ||
31 | |||
32 | $form->submit('ftp://www.domain.com'); | ||
33 | |||
34 | $this->assertSame('ftp://www.domain.com', $form->getData()); | ||
35 | $this->assertSame('ftp://www.domain.com', $form->getViewData()); | ||
36 | } | ||
37 | |||
38 | public function testSubmitAddsNoDefaultProtocolIfEmpty() | ||
39 | { | ||
40 | $form = $this->factory->create('url', null, array( | ||
41 | 'default_protocol' => 'http', | ||
42 | )); | ||
43 | |||
44 | $form->submit(''); | ||
45 | |||
46 | $this->assertNull($form->getData()); | ||
47 | $this->assertSame('', $form->getViewData()); | ||
48 | } | ||
49 | |||
50 | public function testSubmitAddsNoDefaultProtocolIfSetToNull() | ||
51 | { | ||
52 | $form = $this->factory->create('url', null, array( | ||
53 | 'default_protocol' => null, | ||
54 | )); | ||
55 | |||
56 | $form->submit('www.domain.com'); | ||
57 | |||
58 | $this->assertSame('www.domain.com', $form->getData()); | ||
59 | $this->assertSame('www.domain.com', $form->getViewData()); | ||
60 | } | ||
61 | } | ||