]>
Commit | Line | Data |
---|---|---|
4f5b44bd NL |
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 | } |