‪TYPO3CMS  11.5
DateTimeAspectTest.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 
22 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
23 
24 class ‪DateTimeAspectTest extends UnitTestCase
25 {
29  public function ‪getDateTimeReturnsSameObject(): void
30  {
31  $dateObject = new \DateTimeImmutable('2018-07-15', new \DateTimeZone('Europe/Moscow'));
32  $subject = new ‪DateTimeAspect($dateObject);
33  $result = $subject->getDateTime();
34  self::assertSame($dateObject, $result);
35  }
36 
41  {
42  $this->expectException(AspectPropertyNotFoundException::class);
43  $this->expectExceptionCode(1527778767);
44  $dateObject = new \DateTimeImmutable('2018-07-15', new \DateTimeZone('Europe/Moscow'));
45  $subject = new ‪DateTimeAspect($dateObject);
46  $subject->get('football');
47  }
48 
52  public function ‪getTimestampReturnsInteger(): void
53  {
54  $dateObject = new \DateTimeImmutable('2018-07-15', new \DateTimeZone('Europe/Moscow'));
55  $subject = new ‪DateTimeAspect($dateObject);
56  $timestamp = $subject->get('timestamp');
57  self::assertIsInt($timestamp);
58  }
59 
64  {
65  $dateObject = new \DateTimeImmutable('@12345');
66  $subject = new ‪DateTimeAspect($dateObject);
67  self::assertSame('+00:00', $subject->get('timezone'));
68  }
69 
74  {
75  $dateObject = new \DateTimeImmutable('2004-02-12T15:19:21+05:00');
76  $subject = new ‪DateTimeAspect($dateObject);
77  self::assertSame('+05:00', $subject->get('timezone'));
78  }
79 
83  public function ‪dateFormatValuesDataProvider(): array
84  {
85  return [
86  'timestamp' => [
87  'timestamp',
88  1531648805,
89  ],
90  'iso' => [
91  'iso',
92  '2018-07-15T13:00:05+03:00',
93  ],
94  'timezone' => [
95  'timezone',
96  'Europe/Moscow',
97  ],
98  'full' => [
99  'full',
100  new \DateTimeImmutable('2018-07-15T13:00:05', new \DateTimeZone('Europe/Moscow')),
101  ],
102  'accessTime' => [
103  'accessTime',
104  1531648800,
105  ],
106  ];
107  }
108 
115  public function ‪getReturnsValidInformationFromProperty($key, $expectedResult): void
116  {
117  $dateObject = new \DateTimeImmutable('2018-07-15T13:00:05', new \DateTimeZone('Europe/Moscow'));
118  $subject = new ‪DateTimeAspect($dateObject);
119  self::assertEquals($expectedResult, $subject->get($key));
120  }
121 }
‪TYPO3\CMS\Core\Tests\Unit\Context\DateTimeAspectTest\getThrowsExceptionOnInvalidArgument
‪getThrowsExceptionOnInvalidArgument()
Definition: DateTimeAspectTest.php:40
‪TYPO3\CMS\Core\Tests\Unit\Context\DateTimeAspectTest\getTimestampReturnsInteger
‪getTimestampReturnsInteger()
Definition: DateTimeAspectTest.php:52
‪TYPO3\CMS\Core\Tests\Unit\Context\DateTimeAspectTest\getTimezoneReturnsUtcTimezoneOffsetWhenDateTimeIsInitializedFromUnixTimestamp
‪getTimezoneReturnsUtcTimezoneOffsetWhenDateTimeIsInitializedFromUnixTimestamp()
Definition: DateTimeAspectTest.php:63
‪TYPO3\CMS\Core\Tests\Unit\Context\DateTimeAspectTest
Definition: DateTimeAspectTest.php:25
‪TYPO3\CMS\Core\Tests\Unit\Context\DateTimeAspectTest\getReturnsValidInformationFromProperty
‪getReturnsValidInformationFromProperty($key, $expectedResult)
Definition: DateTimeAspectTest.php:115
‪TYPO3\CMS\Core\Tests\Unit\Context\DateTimeAspectTest\getDateTimeReturnsSameObject
‪getDateTimeReturnsSameObject()
Definition: DateTimeAspectTest.php:29
‪TYPO3\CMS\Core\Tests\Unit\Context\DateTimeAspectTest\getTimezoneReturnsGivenTimezoneOffsetWhenDateTimeIsInitializedFromIso8601Date
‪getTimezoneReturnsGivenTimezoneOffsetWhenDateTimeIsInitializedFromIso8601Date()
Definition: DateTimeAspectTest.php:73
‪TYPO3\CMS\Core\Tests\Unit\Context\DateTimeAspectTest\dateFormatValuesDataProvider
‪array dateFormatValuesDataProvider()
Definition: DateTimeAspectTest.php:83
‪TYPO3\CMS\Core\Context\DateTimeAspect
Definition: DateTimeAspect.php:35
‪TYPO3\CMS\Core\Context\Exception\AspectPropertyNotFoundException
Definition: AspectPropertyNotFoundException.php:25
‪TYPO3\CMS\Core\Tests\Unit\Context
Definition: ContextTest.php:18