[FEATURE] Add Contexts for storing data access modes
[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 $dateObject = new \DateTimeImmutable('2018-07-15', new \DateTimeZone('Europe/Moscow'));
42 $subject = new DateTimeAspect($dateObject);
43 $subject->get('football');
44 }
45
46 /**
47 * @return array
48 */
49 public function dateFormatValuesDataProvider()
50 {
51 return [
52 'timestamp' => [
53 'timestamp',
54 '1531648805'
55 ],
56 'iso' => [
57 'iso',
58 '2018-07-15T13:00:05+03:00'
59 ],
60 'timezone' => [
61 'timezone',
62 'Europe/Moscow'
63 ],
64 'full' => [
65 'full',
66 new \DateTimeImmutable('2018-07-15T13:00:05', new \DateTimeZone('Europe/Moscow'))
67 ],
68 ];
69 }
70
71 /**
72 * @test
73 * @dataProvider dateFormatValuesDataProvider
74 * @param string $key
75 * @param string $expectedResult
76 */
77 public function getReturnsValidInformationFromProperty($key, $expectedResult)
78 {
79 $dateObject = new \DateTimeImmutable('2018-07-15T13:00:05', new \DateTimeZone('Europe/Moscow'));
80 $subject = new DateTimeAspect($dateObject);
81 $this->assertEquals($expectedResult, $subject->get($key));
82 }
83 }