From 1b363360f66f23bbdd2318ea776a20d684f0a84a Mon Sep 17 00:00:00 2001 From: raviks789 Date: Mon, 28 Apr 2025 15:40:10 +0200 Subject: [PATCH] Add tests for detecting browser timezone name --- .../Icinga/Util/TimezoneDetectTest.php | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 test/php/library/Icinga/Util/TimezoneDetectTest.php diff --git a/test/php/library/Icinga/Util/TimezoneDetectTest.php b/test/php/library/Icinga/Util/TimezoneDetectTest.php new file mode 100644 index 000000000..7548d4a22 --- /dev/null +++ b/test/php/library/Icinga/Util/TimezoneDetectTest.php @@ -0,0 +1,49 @@ +reset(); + + $_COOKIE[TimezoneDetect::$cookieName] = 'ABC'; + $tzDetect = new TimezoneDetect(); + $this->assertFalse( + $tzDetect->success(), + false, + 'Failed to assert invalid timezone name is detected' + ); + + $this->assertNull( + $tzDetect->getTimezoneName(), + 'Failed to assert that the timezone name will not be set for invalid timezone' + ); + } + + public function testValidTimezoneNameInCookie(): void + { + $tzDetect = new TimezoneDetect(); + $tzDetect->reset(); + + $_COOKIE[TimezoneDetect::$cookieName] = "Europe/Berlin"; + $tzDetect = new TimezoneDetect(); + $this->assertTrue( + $tzDetect->success(), + true, + 'Failed to assert that the valid timezone name is detected' + ); + + $this->assertSame( + $tzDetect->getTimezoneName(), + "Europe/Berlin", + 'Failed to assert that the valid timezone name was correctly set' + ); + } +}