‪TYPO3CMS  11.5
InputDateTimeElementTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Prophecy\Argument;
21 use Prophecy\PhpUnit\ProphecyTrait;
30 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
31 
35 class ‪InputDateTimeElementTest extends UnitTestCase
36 {
37  use ProphecyTrait;
38 
42  protected string ‪$timezoneBackup = '';
43 
50  protected function ‪setUp(): void
51  {
52  parent::setUp();
53  $this->timezoneBackup = date_default_timezone_get();
54  }
55 
56  protected function ‪tearDown(): void
57  {
58  date_default_timezone_set($this->timezoneBackup);
59  parent::tearDown();
60  }
61 
66  {
67  // Three elements: input (UTC), timezone of output, expected output
68  return [
69  // German standard time (without DST) is one hour ahead of UTC
70  'date in 2016 in German timezone' => [
71  1457103519, 'Europe/Berlin', '2016-03-04T15:58:39+00:00',
72  ],
73  'date in 1969 in German timezone' => [
74  -7200, 'Europe/Berlin', '1969-12-31T23:00:00+00:00',
75  ],
76  // Los Angeles is 8 hours behind UTC
77  'date in 2016 in Los Angeles timezone' => [
78  1457103519, 'America/Los_Angeles', '2016-03-04T06:58:39+00:00',
79  ],
80  'date in UTC' => [
81  1457103519, 'UTC', '2016-03-04T14:58:39+00:00',
82  ],
83  ];
84  }
85 
90  public function ‪renderAppliesCorrectTimestampConversion(int $input, string $serverTimezone, string $expectedOutput): void
91  {
92  date_default_timezone_set($serverTimezone);
93  $data = [
94  'tableName' => 'table_foo',
95  'fieldName' => 'field_bar',
96  'databaseRow' => [
97  'uid' => 5,
98  ],
99  'parameterArray' => [
100  'tableName' => 'table_foo',
101  'fieldName' => 'field_bar',
102  'fieldConf' => [
103  'config' => [
104  'type' => 'input',
105  'dbType' => 'datetime',
106  'eval' => 'datetime',
107  'default' => '0000-00-00 00:00:00',
108  ],
109  ],
110  'itemFormElName' => 'myItemFormElName',
111  'itemFormElValue' => $input,
112  ],
113  ];
114  $abstractNode = $this->prophesize(AbstractNode::class);
115  $abstractNode->render(Argument::cetera())->willReturn([
116  'additionalJavaScriptPost' => [],
117  'additionalHiddenFields' => [],
118  'stylesheetFiles' => [],
119  ]);
120  $iconFactoryProphecy = $this->prophesize(IconFactory::class);
121  GeneralUtility::addInstance(IconFactory::class, $iconFactoryProphecy->reveal());
122  $iconProphecy = $this->prophesize(Icon::class);
123  $iconProphecy->render()->willReturn('');
124  $iconFactoryProphecy->getIcon(Argument::cetera())->willReturn($iconProphecy->reveal());
125  $nodeFactoryProphecy = $this->prophesize(NodeFactory::class);
126  $nodeFactoryProphecy->create(Argument::cetera())->willReturn($abstractNode->reveal());
127  $fieldInformationProphecy = $this->prophesize(FieldInformation::class);
128  $fieldInformationProphecy->render(Argument::cetera())->willReturn(['html' => '']);
129  $nodeFactoryProphecy->create(Argument::cetera())->willReturn($fieldInformationProphecy->reveal());
130  $languageService = $this->prophesize(LanguageService::class);
131  ‪$GLOBALS['LANG'] = $languageService->reveal();
132  $subject = new InputDateTimeElement($nodeFactoryProphecy->reveal(), $data);
133  $result = $subject->render();
134  self::assertStringContainsString('<input type="hidden" name="myItemFormElName" value="' . $expectedOutput . '" />', $result['html']);
135  }
136 }
‪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\renderAppliesCorrectTimestampConversion
‪renderAppliesCorrectTimestampConversion(int $input, string $serverTimezone, string $expectedOutput)
Definition: InputDateTimeElementTest.php:89
‪TYPO3\CMS\Backend\Tests\Unit\Form\Element\InputDateTimeElementTest\tearDown
‪tearDown()
Definition: InputDateTimeElementTest.php:55
‪TYPO3\CMS\Backend\Tests\Unit\Form\Element\InputDateTimeElementTest\setUp
‪setUp()
Definition: InputDateTimeElementTest.php:49
‪TYPO3\CMS\Core\Imaging\IconFactory
Definition: IconFactory.php:34
‪TYPO3\CMS\Backend\Tests\Unit\Form\Element\InputDateTimeElementTest\renderAppliesCorrectTimestampConversionDataProvider
‪renderAppliesCorrectTimestampConversionDataProvider()
Definition: InputDateTimeElementTest.php:64
‪TYPO3\CMS\Backend\Form\Element\InputDateTimeElement
Definition: InputDateTimeElement.php:29
‪TYPO3\CMS\Backend\Tests\Unit\Form\Element\InputDateTimeElementTest\$timezoneBackup
‪string $timezoneBackup
Definition: InputDateTimeElementTest.php:41
‪TYPO3\CMS\Backend\Tests\Unit\Form\Element\InputDateTimeElementTest
Definition: InputDateTimeElementTest.php:36
‪TYPO3\CMS\Backend\Tests\Unit\Form\Element
Definition: AbstractFormElementTest.php:18
‪TYPO3\CMS\Backend\Form\NodeFactory
Definition: NodeFactory.php:37
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪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:50