Skip to content

Commit 6fce234

Browse files
committed
Add tests for detecting browser timezone name
1 parent 380b368 commit 6fce234

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
/* Icinga Web 2 | (c) 2017 Icinga Development Team | GPLv2+ */
3+
4+
namespace Tests\Icinga\Util;
5+
6+
use Icinga\Test\BaseTestCase;
7+
use Icinga\Util\TimezoneDetect;
8+
9+
class TimezoneDetectTest extends BaseTestCase
10+
{
11+
public function testInvalidTimezoneNameInCookie(): void
12+
{
13+
$_COOKIE[TimezoneDetect::$cookieName] = 'ABC';
14+
$tzDetect = new TimezoneDetect();
15+
$this->assertFalse(
16+
$tzDetect->success(),
17+
false,
18+
'Failed to assert invalid timezone name detected'
19+
);
20+
21+
$this->assertNull(
22+
$tzDetect->getTimezoneName(),
23+
'Failed to assert that the timezone name returns null for invalid timezone'
24+
);
25+
}
26+
27+
public function testValidTimezoneNameInCookie(): void
28+
{
29+
$_COOKIE[TimezoneDetect::$cookieName] = "Europe/Berlin";
30+
$tzDetect = new TimezoneDetect();
31+
$this->assertTrue(
32+
$tzDetect->success(),
33+
true,
34+
'Failed to assert that the valid timezone name detected'
35+
);
36+
37+
$this->assertSame(
38+
$tzDetect->getTimezoneName(),
39+
"Europe/Berlin",
40+
'Failed to assert that the valid timezone name was correctly set'
41+
);
42+
}
43+
}

0 commit comments

Comments
 (0)