[BUGFIX] Adapt glitches of context patch
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / Context / DateTimeAspectTest.php
1 <?php
2 declare(strict_types = 1);
3 namespace TYPO3\CMS\Core\Tests\Unit\Context;
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
18 use TYPO3\CMS\Core\Context\DateTimeAspect;
19 use TYPO3\CMS\Core\Context\Exception\AspectPropertyNotFoundException;
20 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
21
22 class DateTimeAspectTest extends UnitTestCase
23 {
24 /**
25 * @test
26 */
27 public function getDateTimeReturnsSameObject()
28 {
29 $dateObject = new \DateTimeImmutable('2018-07-15', new \DateTimeZone('Europe/Moscow'));
30 $subject = new DateTimeAspect($dateObject);
31 $result = $subject->getDateTime();
32 $this->assertSame($dateObject, $result);
33 }
34
35 /**
36 * @test
37 */
38 public function getThrowsExceptionOnInvalidArgument()
39 {
40 $this->expectException(AspectPropertyNotFoundException::class);
41 $this->expectExceptionCode(1527778767);
42 $dateObject = new \DateTimeImmutable('2018-07-15', new \DateTimeZone('Europe/Moscow'));
43 $subject = new DateTimeAspect($dateObject);
44 $subject->get('football');
45 }
46
47 /**
48 * @return array
49 */
50 public function dateFormatValuesDataProvider()
51 {
52 return [
53 'timestamp' => [
54 'timestamp',
55 '1531648805'
56 ],
57 'iso' => [
58 'iso',
59 '2018-07-15T13:00:05+03:00'
60 ],
61 'timezone' => [
62 'timezone',
63 'Europe/Moscow'
64 ],
65 'full' => [
66 'full',
67 new \DateTimeImmutable('2018-07-15T13:00:05', new \DateTimeZone('Europe/Moscow'))
68 ],
69 ];
70 }
71
72 /**
73 * @test
74 * @dataProvider dateFormatValuesDataProvider
75 * @param string $key
76 * @param string $expectedResult
77 */
78 public function getReturnsValidInformationFromProperty($key, $expectedResult)
79 {
80 $dateObject = new \DateTimeImmutable('2018-07-15T13:00:05', new \DateTimeZone('Europe/Moscow'));
81 $subject = new DateTimeAspect($dateObject);
82 $this->assertEquals($expectedResult, $subject->get($key));
83 }
84 }