[TASK] Doctrine: Migrate DatabaseConnection::getDateTimeFormats()
[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\CMS\Core\Tests\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 addDataConvertsDateStringToTimestamp()
73 {
74 $oldTimezone = date_default_timezone_get();
75 date_default_timezone_set('UTC');
76 $input = [
77 'tableName' => 'aTable',
78 'processedTca' => [
79 'columns' => [
80 'aField' => [
81 'config' => [
82 'dbType' => 'date',
83 ],
84 ],
85 ],
86 ],
87 'databaseRow' => [
88 'aField' => '2015-07-27',
89 ],
90 ];
91 $expected = $input;
92 $expected['databaseRow']['aField'] = 1437955200; // 27.07.2015 0:00 UTC
93 $this->assertEquals($expected, (new DatabaseRowDateTimeFields())->addData($input));
94 date_default_timezone_set($oldTimezone);
95 }
96
97 /**
98 * @test
99 */
100 public function addDataConvertsDateTimeStringToTimestamp()
101 {
102 $oldTimezone = date_default_timezone_get();
103 date_default_timezone_set('UTC');
104 $input = [
105 'tableName' => 'aTable',
106 'processedTca' => [
107 'columns' => [
108 'aField' => [
109 'config' => [
110 'dbType' => 'datetime',
111 ],
112 ],
113 ],
114 ],
115 'databaseRow' => [
116 'aField' => '2015-07-27 15:25:32',
117 ],
118 ];
119 $expected = $input;
120 $expected['databaseRow']['aField'] = 1438010732; // 27.07.2015 15:25:32 UTC
121 $this->assertEquals($expected, (new DatabaseRowDateTimeFields())->addData($input));
122 date_default_timezone_set($oldTimezone);
123 }
124 }