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