‪TYPO3CMS  9.5
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 
17 use Prophecy\Argument;
26 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
27 
31 class ‪InputDateTimeElementTest extends UnitTestCase
32 {
36  protected ‪$timezoneBackup = '';
37 
44  protected function ‪setUp()
45  {
46  $this->timezoneBackup = date_default_timezone_get();
47  }
48 
52  protected function ‪tearDown()
53  {
54  date_default_timezone_set($this->timezoneBackup);
55  parent::tearDown();
56  }
57 
64  {
65  // Three elements: input (UTC), timezone of output, expected output
66  return [
67  // German standard time (without DST) is one hour ahead of UTC
68  'date in 2016 in German timezone' => [
69  1457103519, 'Europe/Berlin', '2016-03-04T15:58:39+00:00'
70  ],
71  'date in 1969 in German timezone' => [
72  -7200, 'Europe/Berlin', '1969-12-31T23:00:00+00:00'
73  ],
74  // Los Angeles is 8 hours behind UTC
75  'date in 2016 in Los Angeles timezone' => [
76  1457103519, 'America/Los_Angeles', '2016-03-04T06:58:39+00:00'
77  ],
78  'date in UTC' => [
79  1457103519, 'UTC', '2016-03-04T14:58:39+00:00'
80  ]
81  ];
82  }
83 
91  public function ‪renderAppliesCorrectTimestampConversion($input, $serverTimezone, $expectedOutput)
92  {
93  date_default_timezone_set($serverTimezone);
94  $data = [
95  'tableName' => 'table_foo',
96  'fieldName' => 'field_bar',
97  'databaseRow' => [
98  'uid' => 5,
99  ],
100  'parameterArray' => [
101  'tableName' => 'table_foo',
102  'fieldName' => 'field_bar',
103  'fieldConf' => [
104  'config' => [
105  'type' => 'input',
106  'dbType' => 'datetime',
107  'eval' => 'datetime',
108  'default' => '0000-00-00 00:00:00'
109  ]
110  ],
111  'itemFormElName' => 'myItemFormElName',
112  'itemFormElValue' => $input
113  ]
114  ];
115  $abstractNode = $this->prophesize(AbstractNode::class);
116  $abstractNode->render(Argument::cetera())->willReturn([
117  'additionalJavaScriptPost' => [],
118  'additionalJavaScriptSubmit' => [],
119  'additionalHiddenFields' => [],
120  'stylesheetFiles' => [],
121  ]);
122  $iconFactoryProphecy = $this->prophesize(IconFactory::class);
123  GeneralUtility::addInstance(IconFactory::class, $iconFactoryProphecy->reveal());
124  $iconProphecy = $this->prophesize(Icon::class);
125  $iconProphecy->render()->willReturn('');
126  $iconFactoryProphecy->getIcon(Argument::cetera())->willReturn($iconProphecy->reveal());
127  $nodeFactoryProphecy = $this->prophesize(NodeFactory::class);
128  $nodeFactoryProphecy->create(Argument::cetera())->willReturn($abstractNode->reveal());
129  $fieldInformationProphecy = $this->prophesize(FieldInformation::class);
130  $fieldInformationProphecy->render(Argument::cetera())->willReturn(['html' => '']);
131  $nodeFactoryProphecy->create(Argument::cetera())->willReturn($fieldInformationProphecy->reveal());
132  $languageService = $this->prophesize(LanguageService::class);
133  ‪$GLOBALS['LANG'] = $languageService->reveal();
134  $subject = new ‪InputDateTimeElement($nodeFactoryProphecy->reveal(), $data);
135  $result = $subject->render();
136  $this->assertContains('<input type="hidden" name="myItemFormElName" value="' . $expectedOutput . '" />', $result['html']);
137  }
138 }
‪TYPO3\CMS\Backend\Form\NodeExpansion\FieldInformation
Definition: FieldInformation.php:31
‪TYPO3\CMS\Core\Imaging\Icon
Definition: Icon.php:25
‪TYPO3\CMS\Backend\Tests\Unit\Form\Element\InputDateTimeElementTest\tearDown
‪tearDown()
Definition: InputDateTimeElementTest.php:51
‪TYPO3\CMS\Backend\Tests\Unit\Form\Element\InputDateTimeElementTest\setUp
‪setUp()
Definition: InputDateTimeElementTest.php:43
‪TYPO3\CMS\Core\Imaging\IconFactory
Definition: IconFactory.php:31
‪TYPO3\CMS\Backend\Form\Element\InputDateTimeElement
Definition: InputDateTimeElement.php:27
‪TYPO3\CMS\Backend\Tests\Unit\Form\Element\InputDateTimeElementTest\$timezoneBackup
‪string $timezoneBackup
Definition: InputDateTimeElementTest.php:35
‪TYPO3\CMS\Backend\Tests\Unit\Form\Element\InputDateTimeElementTest
Definition: InputDateTimeElementTest.php:32
‪TYPO3\CMS\Backend\Tests\Unit\Form\Element\InputDateTimeElementTest\renderAppliesCorrectTimestampConversionDataProvider
‪array renderAppliesCorrectTimestampConversionDataProvider()
Definition: InputDateTimeElementTest.php:62
‪TYPO3\CMS\Backend\Tests\Unit\Form\Element\InputDateTimeElementTest\renderAppliesCorrectTimestampConversion
‪renderAppliesCorrectTimestampConversion($input, $serverTimezone, $expectedOutput)
Definition: InputDateTimeElementTest.php:90
‪TYPO3\CMS\Backend\Tests\Unit\Form\Element
Definition: AbstractFormElementTest.php:2
‪TYPO3\CMS\Backend\Form\NodeFactory
Definition: NodeFactory.php:36
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:29
‪TYPO3\CMS\Backend\Form\AbstractNode
Definition: AbstractNode.php:27
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45