‪TYPO3CMS  10.4
InputDateTimeElementTest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
18 use Prophecy\Argument;
27 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
28 
32 class ‪InputDateTimeElementTest extends UnitTestCase
33 {
37  protected ‪$timezoneBackup = '';
38 
45  protected function ‪setUp(): void
46  {
47  $this->timezoneBackup = date_default_timezone_get();
48  }
49 
53  protected function ‪tearDown(): void
54  {
55  date_default_timezone_set($this->timezoneBackup);
56  parent::tearDown();
57  }
58 
65  {
66  // Three elements: input (UTC), timezone of output, expected output
67  return [
68  // German standard time (without DST) is one hour ahead of UTC
69  'date in 2016 in German timezone' => [
70  1457103519, 'Europe/Berlin', '2016-03-04T15:58:39+00:00'
71  ],
72  'date in 1969 in German timezone' => [
73  -7200, 'Europe/Berlin', '1969-12-31T23:00:00+00:00'
74  ],
75  // Los Angeles is 8 hours behind UTC
76  'date in 2016 in Los Angeles timezone' => [
77  1457103519, 'America/Los_Angeles', '2016-03-04T06:58:39+00:00'
78  ],
79  'date in UTC' => [
80  1457103519, 'UTC', '2016-03-04T14:58:39+00:00'
81  ]
82  ];
83  }
84 
92  public function ‪renderAppliesCorrectTimestampConversion($input, $serverTimezone, $expectedOutput)
93  {
94  date_default_timezone_set($serverTimezone);
95  $data = [
96  'tableName' => 'table_foo',
97  'fieldName' => 'field_bar',
98  'databaseRow' => [
99  'uid' => 5,
100  ],
101  'parameterArray' => [
102  'tableName' => 'table_foo',
103  'fieldName' => 'field_bar',
104  'fieldConf' => [
105  'config' => [
106  'type' => 'input',
107  'dbType' => 'datetime',
108  'eval' => 'datetime',
109  'default' => '0000-00-00 00:00:00'
110  ]
111  ],
112  'itemFormElName' => 'myItemFormElName',
113  'itemFormElValue' => $input
114  ]
115  ];
116  $abstractNode = $this->prophesize(AbstractNode::class);
117  $abstractNode->render(Argument::cetera())->willReturn([
118  'additionalJavaScriptPost' => [],
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  self::assertStringContainsString('<input type="hidden" name="myItemFormElName" value="' . $expectedOutput . '" />', $result['html']);
137  }
138 }
‪TYPO3\CMS\Backend\Form\NodeExpansion\FieldInformation
Definition: FieldInformation.php:33
‪TYPO3\CMS\Core\Imaging\Icon
Definition: Icon.php:26
‪TYPO3\CMS\Backend\Tests\Unit\Form\Element\InputDateTimeElementTest\tearDown
‪tearDown()
Definition: InputDateTimeElementTest.php:52
‪TYPO3\CMS\Backend\Tests\Unit\Form\Element\InputDateTimeElementTest\setUp
‪setUp()
Definition: InputDateTimeElementTest.php:44
‪TYPO3\CMS\Core\Imaging\IconFactory
Definition: IconFactory.php:33
‪TYPO3\CMS\Backend\Form\Element\InputDateTimeElement
Definition: InputDateTimeElement.php:28
‪TYPO3\CMS\Backend\Tests\Unit\Form\Element\InputDateTimeElementTest\$timezoneBackup
‪string $timezoneBackup
Definition: InputDateTimeElementTest.php:36
‪TYPO3\CMS\Backend\Tests\Unit\Form\Element\InputDateTimeElementTest
Definition: InputDateTimeElementTest.php:33
‪TYPO3\CMS\Backend\Tests\Unit\Form\Element\InputDateTimeElementTest\renderAppliesCorrectTimestampConversionDataProvider
‪array renderAppliesCorrectTimestampConversionDataProvider()
Definition: InputDateTimeElementTest.php:63
‪TYPO3\CMS\Backend\Tests\Unit\Form\Element\InputDateTimeElementTest\renderAppliesCorrectTimestampConversion
‪renderAppliesCorrectTimestampConversion($input, $serverTimezone, $expectedOutput)
Definition: InputDateTimeElementTest.php:91
‪TYPO3\CMS\Backend\Tests\Unit\Form\Element
Definition: AbstractFormElementTest.php:16
‪TYPO3\CMS\Backend\Form\NodeFactory
Definition: NodeFactory.php:37
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:42
‪TYPO3\CMS\Backend\Form\AbstractNode
Definition: AbstractNode.php:29
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46