[TASK] Functional test for VariableFrontend cache type
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Tests / Unit / Form / Element / InputTextElementTest.php
1 <?php
2 namespace typo3\sysext\backend\Tests\Unit\Form\Element;
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 TYPO3\CMS\Backend\Form\Element\InputTextElement;
18 use TYPO3\CMS\Backend\Form\NodeFactory;
19
20 /**
21 * Test case
22 */
23 class InputTextElementTest extends \TYPO3\CMS\Components\TestingFramework\Core\UnitTestCase
24 {
25 /**
26 * @var string Selected timezone backup
27 */
28 protected $timezoneBackup = '';
29
30 /**
31 * We're fiddling with hard timestamps in the tests, but time methods in
32 * the system under test do use timezone settings. Therefore we backup the
33 * current timezone setting, set it to UTC explicitly and reconstitute it
34 * again in tearDown()
35 */
36 protected function setUp()
37 {
38 $this->timezoneBackup = date_default_timezone_get();
39 }
40
41 /**
42 * Tear down
43 */
44 protected function tearDown()
45 {
46 date_default_timezone_set($this->timezoneBackup);
47 parent::tearDown();
48 }
49
50 /**
51 * Data provider for renderAppliesCorrectTimestampConversion
52 *
53 * @return array
54 */
55 public function renderAppliesCorrectTimestampConversionDataProvider()
56 {
57 // Three elements: input (UTC), timezone of output, expected output
58 return [
59 // German standard time (without DST) is one hour ahead of UTC
60 'date in 2016 in German timezone' => [
61 1457103519, 'Europe/Berlin', '2016-03-04T15:58:39+00:00'
62 ],
63 'date in 1969 in German timezone' => [
64 -7200, 'Europe/Berlin', '1969-12-31T23:00:00+00:00'
65 ],
66 // Los Angeles is 8 hours behind UTC
67 'date in 2016 in Los Angeles timezone' => [
68 1457103519, 'America/Los_Angeles', '2016-03-04T06:58:39+00:00'
69 ],
70 'date in UTC' => [
71 1457103519, 'UTC', '2016-03-04T14:58:39+00:00'
72 ]
73 ];
74 }
75
76 /**
77 * @test
78 * @dataProvider renderAppliesCorrectTimestampConversionDataProvider
79 * @param int $input
80 * @param string $serverTimezone
81 * @param int $expectedOutput
82 */
83 public function renderAppliesCorrectTimestampConversion($input, $serverTimezone, $expectedOutput)
84 {
85 date_default_timezone_set($serverTimezone);
86 $data = [
87 'parameterArray' => [
88 'tableName' => 'table_foo',
89 'fieldName' => 'field_bar',
90 'fieldConf' => [
91 'config' => [
92 'type' => 'input',
93 'dbType' => 'datetime',
94 'eval' => 'datetime',
95 'default' => '0000-00-00 00:00:00'
96 ]
97 ],
98 'itemFormElValue' => $input
99 ]
100 ];
101 /** @var NodeFactory $nodeFactoryProphecy */
102 $nodeFactoryProphecy = $this->prophesize(NodeFactory::class)->reveal();
103 $subject = new InputTextElement($nodeFactoryProphecy, $data);
104 $result = $subject->render();
105 $this->assertContains('<input type="hidden" name="" value="' . $expectedOutput . '" />', $result['html']);
106 }
107 }