[BUGFIX] Show correct label for IRRE records
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Tests / Unit / Form / FormDataProvider / DatabaseRowDefaultValuesTest.php
1 <?php
2 namespace TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Backend\Form\FormDataProvider\DatabaseRowDefaultValues;
18 use TYPO3\CMS\Core\Tests\UnitTestCase;
19
20 /**
21 * Test case
22 */
23 class DatabaseRowDefaultValuesTest extends UnitTestCase
24 {
25 /**
26 * @var DatabaseRowDefaultValues
27 */
28 protected $subject;
29
30 protected function setUp()
31 {
32 $this->subject = new DatabaseRowDefaultValues();
33 }
34
35 /**
36 * @test
37 */
38 public function addDataKeepsExistingValue()
39 {
40 $input = [
41 'databaseRow' => [
42 'aDefinedField' => 'aValue',
43 ],
44 'processedTca' => [
45 'columns' => [
46 'aDefinedField' => [],
47 ],
48 ],
49 ];
50 $expected = $input;
51 $this->assertSame($expected, $this->subject->addData($input));
52 }
53
54 /**
55 * @test
56 */
57 public function addDataKeepsExistingNullValueWithEvalNull()
58 {
59 $input = [
60 'databaseRow' => [
61 'aField' => null,
62 ],
63 'processedTca' => [
64 'columns' => [
65 'aField' => [
66 'config' => [
67 'eval' => 'null',
68 ],
69 ],
70 ],
71 ],
72 ];
73 $expected = $input;
74 $this->assertSame($expected, $this->subject->addData($input));
75 }
76
77 /**
78 * @test
79 */
80 public function addDataSetsNullValueWithDefaultNullForNewRecord()
81 {
82 $input = [
83 'databaseRow' => [],
84 'processedTca' => [
85 'columns' => [
86 'aField' => [
87 'config' => [
88 'eval' => 'null',
89 'default' => null,
90 ],
91 ],
92 ],
93 ],
94 ];
95 $expected = $input;
96 $expected['databaseRow']['aField'] = null;
97 $this->assertSame($expected, $this->subject->addData($input));
98 }
99
100 /**
101 * @test
102 */
103 public function addDataSetsDefaultValueIfEvalNullIsSet()
104 {
105 $input = [
106 'databaseRow' => [],
107 'processedTca' => [
108 'columns' => [
109 'aField' => [
110 'config' => [
111 'eval' => 'null',
112 'default' => 'foo',
113 ],
114 ],
115 ],
116 ],
117 ];
118 $expected = $input;
119 $expected['databaseRow']['aField'] = 'foo';
120 $this->assertSame($expected, $this->subject->addData($input));
121 }
122
123 /**
124 * @test
125 */
126 public function addDataSetsDefaultValueIsSet()
127 {
128 $input = [
129 'databaseRow' => [],
130 'processedTca' => [
131 'columns' => [
132 'aField' => [
133 'config' => [
134 'default' => 'foo',
135 ],
136 ],
137 ],
138 ],
139 ];
140 $expected = $input;
141 $expected['databaseRow']['aField'] = 'foo';
142 $this->assertSame($expected, $this->subject->addData($input));
143 }
144 }