TYPO3 CMS  TYPO3_8-7
DatabaseRowDefaultValuesTest.php
Go to the documentation of this file.
1 <?php
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 
18 
22 class DatabaseRowDefaultValuesTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
23 {
27  protected $subject;
28 
29  protected function setUp()
30  {
31  $this->subject = new DatabaseRowDefaultValues();
32  }
33 
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 
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 
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 
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 
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 }