[TASK] Shorten the extend class in all unit tests
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Tests / Unit / Form / FormDataProvider / DatabaseRowDateTimeFieldsTest.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\DatabaseRowDateTimeFields;
18 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
19
20 /**
21 * Test case
22 */
23 class DatabaseRowDateTimeFieldsTest extends UnitTestCase
24 {
25 /**
26 * @test
27 */
28 public function addDataSetsTimestampZeroForDefaultDateField()
29 {
30 $input = [
31 'tableName' => 'aTable',
32 'processedTca' => [
33 'columns' => [
34 'aField' => [
35 'config' => [
36 'dbType' => 'date',
37 ],
38 ],
39 ],
40 ],
41 ];
42 $expected = $input;
43 $expected['databaseRow']['aField'] = 0;
44 $this->assertEquals($expected, (new DatabaseRowDateTimeFields())->addData($input));
45 }
46
47 /**
48 * @test
49 */
50 public function addDataSetsTimestampZeroForDefaultDateTimeField()
51 {
52 $input = [
53 'tableName' => 'aTable',
54 'processedTca' => [
55 'columns' => [
56 'aField' => [
57 'config' => [
58 'dbType' => 'datetime',
59 ],
60 ],
61 ],
62 ],
63 ];
64 $expected = $input;
65 $expected['databaseRow']['aField'] = 0;
66 $this->assertEquals($expected, (new DatabaseRowDateTimeFields())->addData($input));
67 }
68
69 /**
70 * @test
71 */
72 public function addDataSetsTimestampZeroForDefaultTimeField()
73 {
74 $input = [
75 'tableName' => 'aTable',
76 'processedTca' => [
77 'columns' => [
78 'aField' => [
79 'config' => [
80 'dbType' => 'time',
81 ],
82 ],
83 ],
84 ],
85 ];
86 $expected = $input;
87 $expected['databaseRow']['aField'] = 0;
88 $this->assertEquals($expected, (new DatabaseRowDateTimeFields())->addData($input));
89 }
90
91 /**
92 * @test
93 */
94 public function addDataConvertsDateStringToTimestamp()
95 {
96 $oldTimezone = date_default_timezone_get();
97 date_default_timezone_set('UTC');
98 $input = [
99 'tableName' => 'aTable',
100 'processedTca' => [
101 'columns' => [
102 'aField' => [
103 'config' => [
104 'dbType' => 'date',
105 ],
106 ],
107 ],
108 ],
109 'databaseRow' => [
110 'aField' => '2015-07-27',
111 ],
112 ];
113 $expected = $input;
114 $expected['databaseRow']['aField'] = '2015-07-27T00:00:00+00:00';
115 $this->assertEquals($expected, (new DatabaseRowDateTimeFields())->addData($input));
116 date_default_timezone_set($oldTimezone);
117 }
118
119 /**
120 * @test
121 */
122 public function addDataConvertsDateTimeStringToTimestamp()
123 {
124 $oldTimezone = date_default_timezone_get();
125 date_default_timezone_set('UTC');
126 $input = [
127 'tableName' => 'aTable',
128 'processedTca' => [
129 'columns' => [
130 'aField' => [
131 'config' => [
132 'dbType' => 'datetime',
133 ],
134 ],
135 ],
136 ],
137 'databaseRow' => [
138 'aField' => '2015-07-27 15:25:32',
139 ],
140 ];
141 $expected = $input;
142 $expected['databaseRow']['aField'] = '2015-07-27T15:25:32+00:00';
143 $this->assertEquals($expected, (new DatabaseRowDateTimeFields())->addData($input));
144 date_default_timezone_set($oldTimezone);
145 }
146
147 /**
148 * @test
149 */
150 public function addDataConvertsTimeStringToTimestamp()
151 {
152 $oldTimezone = date_default_timezone_get();
153 date_default_timezone_set('UTC');
154 $input = [
155 'tableName' => 'aTable',
156 'processedTca' => [
157 'columns' => [
158 'aField' => [
159 'config' => [
160 'dbType' => 'time',
161 ],
162 ],
163 ],
164 ],
165 'databaseRow' => [
166 'aField' => '15:25:32',
167 ],
168 ];
169 $expected = $input;
170 $expected['databaseRow']['aField'] = date('Y-m-d') . 'T15:25:32+00:00';
171 $this->assertEquals($expected, (new DatabaseRowDateTimeFields())->addData($input));
172 date_default_timezone_set($oldTimezone);
173 }
174 }