ed4843d76d21c56167202c0987c3e1de0d9c9a6b
[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
19 /**
20 * Test case
21 */
22 class DatabaseRowDefaultValuesTest extends \TYPO3\Components\TestingFramework\Core\UnitTestCase
23 {
24 /**
25 * @var DatabaseRowDefaultValues
26 */
27 protected $subject;
28
29 protected function setUp()
30 {
31 $this->subject = new DatabaseRowDefaultValues();
32 }
33
34 /**
35 * @test
36 */
37 public function addDataKeepsExistingValue()
38 {
39 $input = [
40 'databaseRow' => [
41 'aDefinedField' => 'aValue',
42 ],
43 'processedTca' => [
44 'columns' => [
45 'aDefinedField' => [],
46 ],
47 ],
48 ];
49 $expected = $input;
50 $this->assertSame($expected, $this->subject->addData($input));
51 }
52
53 /**
54 * @test
55 */
56 public function addDataKeepsExistingNullValueWithEvalNull()
57 {
58 $input = [
59 'databaseRow' => [
60 'aField' => null,
61 ],
62 'processedTca' => [
63 'columns' => [
64 'aField' => [
65 'config' => [
66 'eval' => 'null',
67 ],
68 ],
69 ],
70 ],
71 ];
72 $expected = $input;
73 $this->assertSame($expected, $this->subject->addData($input));
74 }
75
76 /**
77 * @test
78 */
79 public function addDataSetsNullValueWithDefaultNullForNewRecord()
80 {
81 $input = [
82 'databaseRow' => [],
83 'processedTca' => [
84 'columns' => [
85 'aField' => [
86 'config' => [
87 'eval' => 'null',
88 'default' => null,
89 ],
90 ],
91 ],
92 ],
93 ];
94 $expected = $input;
95 $expected['databaseRow']['aField'] = null;
96 $this->assertSame($expected, $this->subject->addData($input));
97 }
98
99 /**
100 * @test
101 */
102 public function addDataSetsDefaultValueIfEvalNullIsSet()
103 {
104 $input = [
105 'databaseRow' => [],
106 'processedTca' => [
107 'columns' => [
108 'aField' => [
109 'config' => [
110 'eval' => 'null',
111 'default' => 'foo',
112 ],
113 ],
114 ],
115 ],
116 ];
117 $expected = $input;
118 $expected['databaseRow']['aField'] = 'foo';
119 $this->assertSame($expected, $this->subject->addData($input));
120 }
121
122 /**
123 * @test
124 */
125 public function addDataSetsDefaultValueIsSet()
126 {
127 $input = [
128 'databaseRow' => [],
129 'processedTca' => [
130 'columns' => [
131 'aField' => [
132 'config' => [
133 'default' => 'foo',
134 ],
135 ],
136 ],
137 ],
138 ];
139 $expected = $input;
140 $expected['databaseRow']['aField'] = 'foo';
141 $this->assertSame($expected, $this->subject->addData($input));
142 }
143 }