ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ChangeTimezoneTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
24 
25 class ChangeTimezoneTest extends TestCase
26 {
28 
29  protected function setUp(): void
30  {
31  $this->dt = new DateTime\Group();
32  }
33 
34  public function testTransform(): void
35  {
36  $dat = '2019-05-26 13:15:01';
37  $origin_tz = 'Europe/Berlin';
38  $target_tz = 'Europe/London';
39  $origin = new DateTimeImmutable($dat, new DateTimeZone($origin_tz));
40  $expected = new DateTimeImmutable($dat, new DateTimeZone($target_tz));
41  $trans = $this->dt->changeTimezone($target_tz);
42 
43  $this->assertEquals(
44  $expected,
45  $trans->transform($origin)
46  );
47  }
48 
49  public function testTransformValues(): void
50  {
51  $dat = '2019-05-26 13:15:01';
52  $origin_tz = 'Europe/Berlin';
53  $target_tz = 'America/El_Salvador';
54  $origin = new DateTimeImmutable($dat, new DateTimeZone($origin_tz));
55  $trans = $this->dt->changeTimezone($target_tz);
56  $this->assertEquals(
57  $dat,
58  date_format($trans->transform($origin), 'Y-m-d H:i:s')
59  );
60  }
61 
62  public function testNullTransform(): void
63  {
64  $trans = $this->dt->changeTimezone('Europe/Berlin');
65  $this->expectException(InvalidArgumentException::class);
66  $trans->transform(null);
67  }
68 
69  public function testInvalidTransform(): void
70  {
71  $this->expectException(InvalidArgumentException::class);
72  $trans = $this->dt->changeTimezone('Europe/Berlin');
73  $trans->transform('erroneous');
74  }
75 
76  public function testInvoke(): void
77  {
78  $dat = '2019/05/26 16:05:22';
79  $origin_tz = 'Europe/Berlin';
80  $target_tz = 'Europe/London';
81  $origin = new DateTimeImmutable($dat, new DateTimeZone($origin_tz));
82  $expected = new DateTimeImmutable($dat, new DateTimeZone($target_tz));
83  $trans = $this->dt->changeTimezone($target_tz);
84  $this->assertEquals($expected, $trans($origin));
85  }
86 
87  public function testApplyToOK(): void
88  {
89  $trans = $this->dt->changeTimezone('Europe/London');
90  $value = '2019/05/26';
91  $origin = new DateTimeImmutable($value);
92  $expected = new DateTimeImmutable($value, new DateTimeZone('Europe/London'));
93 
94  $df = new DataFactory();
95  $ok = $df->ok($origin);
96 
97  $result = $trans->applyTo($ok);
98  $this->assertEquals($expected, $result->value());
99  $this->assertFalse($result->isError());
100  }
101 
102  public function testApplyToFail(): void
103  {
104  $trans = $this->dt->changeTimezone('Europe/London');
105  $df = new DataFactory();
106  $ok = $df->ok('not_a_date');
107 
108  $result = $trans->applyTo($ok);
109  $this->assertTrue($result->isError());
110  }
111 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...