TYPO3 CMS  TYPO3_8-7
InputDateTimeElementTest.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 
26 class InputDateTimeElementTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
27 {
31  protected $timezoneBackup = '';
32 
39  protected function setUp()
40  {
41  $this->timezoneBackup = date_default_timezone_get();
42  }
43 
47  protected function tearDown()
48  {
49  date_default_timezone_set($this->timezoneBackup);
50  parent::tearDown();
51  }
52 
59  {
60  // Three elements: input (UTC), timezone of output, expected output
61  return [
62  // German standard time (without DST) is one hour ahead of UTC
63  'date in 2016 in German timezone' => [
64  1457103519, 'Europe/Berlin', '2016-03-04T15:58:39+00:00'
65  ],
66  'date in 1969 in German timezone' => [
67  -7200, 'Europe/Berlin', '1969-12-31T23:00:00+00:00'
68  ],
69  // Los Angeles is 8 hours behind UTC
70  'date in 2016 in Los Angeles timezone' => [
71  1457103519, 'America/Los_Angeles', '2016-03-04T06:58:39+00:00'
72  ],
73  'date in UTC' => [
74  1457103519, 'UTC', '2016-03-04T14:58:39+00:00'
75  ]
76  ];
77  }
78 
86  public function renderAppliesCorrectTimestampConversion($input, $serverTimezone, $expectedOutput)
87  {
88  date_default_timezone_set($serverTimezone);
89  $data = [
90  'parameterArray' => [
91  'tableName' => 'table_foo',
92  'fieldName' => 'field_bar',
93  'fieldConf' => [
94  'config' => [
95  'type' => 'input',
96  'dbType' => 'datetime',
97  'eval' => 'datetime',
98  'default' => '0000-00-00 00:00:00'
99  ]
100  ],
101  'itemFormElValue' => $input
102  ]
103  ];
104  $abstractNode = $this->prophesize(AbstractNode::class);
105  $abstractNode->render(Argument::cetera())->willReturn([
106  'additionalJavaScriptPost' => [],
107  'additionalJavaScriptSubmit' => [],
108  'additionalHiddenFields' => [],
109  'stylesheetFiles' => [],
110  ]);
111  $nodeFactoryProphecy = $this->prophesize(NodeFactory::class);
112  $nodeFactoryProphecy->create(Argument::cetera())->willReturn($abstractNode->reveal());
113  $languageService = $this->prophesize(LanguageService::class);
114  $GLOBALS['LANG'] = $languageService->reveal();
115  $subject = new InputDateTimeElement($nodeFactoryProphecy->reveal(), $data);
116  $result = $subject->render();
117  $this->assertContains('<input type="hidden" name="" value="' . $expectedOutput . '" />', $result['html']);
118  }
119 }
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']