TYPO3 CMS  TYPO3_7-6
DatabaseRowDateTimeFieldsTest.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 
22 
27 {
31  protected $subject;
32 
36  protected $dbProphecy;
37 
41  protected $dateFormats = [
42  'date' => [
43  'empty' => '0000-00-00',
44  'format' => 'Y-m-d'
45  ],
46  'datetime' => [
47  'empty' => '0000-00-00 00:00:00',
48  'format' => 'Y-m-d H:i:s'
49  ],
50  ];
51 
52  protected function setUp()
53  {
54  $this->subject = new DatabaseRowDateTimeFields();
55  $this->dbProphecy = $this->prophesize(DatabaseConnection::class);
56  $GLOBALS['TYPO3_DB'] = $this->dbProphecy->reveal();
57  }
58 
63  {
64  $tableName = 'aTable';
65  $input = [
66  'tableName' => $tableName,
67  'processedTca' => [
68  'columns' => [],
69  ],
70  ];
71  $this->dbProphecy->getDateTimeFormats($tableName)->shouldBeCalled();
72  $this->subject->addData($input);
73  }
74 
79  {
80  $input = [
81  'tableName' => 'aTable',
82  'processedTca' => [
83  'columns' => [
84  'aField' => [
85  'config' => [
86  'dbType' => 'date',
87  ],
88  ],
89  ],
90  ],
91  ];
92  $expected = $input;
93  $expected['databaseRow']['aField'] = 0;
94  $this->dbProphecy->getDateTimeFormats(Argument::cetera())->willReturn($this->dateFormats);
95  $this->assertEquals($expected, $this->subject->addData($input));
96  }
97 
102  {
103  $input = [
104  'tableName' => 'aTable',
105  'processedTca' => [
106  'columns' => [
107  'aField' => [
108  'config' => [
109  'dbType' => 'datetime',
110  ],
111  ],
112  ],
113  ],
114  ];
115  $expected = $input;
116  $expected['databaseRow']['aField'] = 0;
117  $this->dbProphecy->getDateTimeFormats(Argument::cetera())->willReturn($this->dateFormats);
118  $this->assertEquals($expected, $this->subject->addData($input));
119  }
120 
125  {
126  $oldTimezone = date_default_timezone_get();
127  date_default_timezone_set('UTC');
128  $input = [
129  'tableName' => 'aTable',
130  'processedTca' => [
131  'columns' => [
132  'aField' => [
133  'config' => [
134  'dbType' => 'date',
135  ],
136  ],
137  ],
138  ],
139  'databaseRow' => [
140  'aField' => '2015-07-27',
141  ],
142  ];
143  $expected = $input;
144  $expected['databaseRow']['aField'] = 1437955200; // 27.07.2015 0:00 UTC
145  $this->dbProphecy->getDateTimeFormats(Argument::cetera())->willReturn($this->dateFormats);
146  $this->assertEquals($expected, $this->subject->addData($input));
147  date_default_timezone_set($oldTimezone);
148  }
149 
154  {
155  $oldTimezone = date_default_timezone_get();
156  date_default_timezone_set('UTC');
157  $input = [
158  'tableName' => 'aTable',
159  'processedTca' => [
160  'columns' => [
161  'aField' => [
162  'config' => [
163  'dbType' => 'datetime',
164  ],
165  ],
166  ],
167  ],
168  'databaseRow' => [
169  'aField' => '2015-07-27 15:25:32',
170  ],
171  ];
172  $expected = $input;
173  $expected['databaseRow']['aField'] = 1438010732; // 27.07.2015 15:25:32 UTC
174  $this->dbProphecy->getDateTimeFormats(Argument::cetera())->willReturn($this->dateFormats);
175  $this->assertEquals($expected, $this->subject->addData($input));
176  date_default_timezone_set($oldTimezone);
177  }
178 }
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']