]> git.immae.eu Git - github/wallabag/wallabag.git/blob - vendor/symfony/form/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/ArrayToPartsTransformerTest.php
twig implementation
[github/wallabag/wallabag.git] / vendor / symfony / form / Symfony / Component / Form / Tests / Extension / Core / DataTransformer / ArrayToPartsTransformerTest.php
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 }