From 1be5a8e72d515b671cb1d12060aad81e27ba293c Mon Sep 17 00:00:00 2001 From: Adam Daley Date: Tue, 7 Jul 2026 01:58:59 +0100 Subject: [PATCH] Fixes for 2 code quality findings in i18n tests (#3923) * Apply suggested fix to tests/Unit/FOSSBilling/i18nTest.php from Copilot Autofix Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com> * Apply suggested fix to tests/Unit/FOSSBilling/i18nTest.php from Copilot Autofix Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com> * Fix failing timezone alias test to match actual validateTimezone behavior US/Eastern is a legacy tzdata backward-compatibility alias excluded from DateTimeZone::listIdentifiers(), so validateTimezone() correctly rejects it. The test asserted the opposite and failed CI. --------- Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com> --- tests/Unit/FOSSBilling/i18nTest.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/Unit/FOSSBilling/i18nTest.php b/tests/Unit/FOSSBilling/i18nTest.php index 53bcc5ac8..11897235a 100644 --- a/tests/Unit/FOSSBilling/i18nTest.php +++ b/tests/Unit/FOSSBilling/i18nTest.php @@ -99,6 +99,14 @@ test('getActiveTimezone ignores an invalid fb_timezone cookie', function (): voi expect(i18n::getActiveTimezone())->toBe('UTC'); }); +test('getActiveTimezone ignores an invalid fb_timezone cookie when explicit arguments are valid', function (): void { + $_COOKIE['fb_timezone'] = 'Definitely/Not_Real'; + + expect(i18n::getActiveTimezone('America/New_York', 'Asia/Tokyo'))->toBe('America/New_York'); + expect(i18n::getActiveTimezone('America/New_York', null))->toBe('America/New_York'); + expect(i18n::getActiveTimezone(null, 'Asia/Tokyo'))->toBe('Asia/Tokyo'); +}); + test('getActiveTimezone falls back to valid fb_timezone cookie when client timezone is invalid', function (): void { $_COOKIE['fb_timezone'] = 'Europe/Berlin'; @@ -138,6 +146,10 @@ test('validateTimezone returns the value when it is a known IANA identifier', fu expect(i18n::validateTimezone('UTC'))->toBe('UTC'); }); +test('validateTimezone rejects deprecated/alias timezone identifiers not in the canonical IANA list', function (): void { + expect(fn (): ?string => i18n::validateTimezone('US/Eastern'))->toThrow(FOSSBilling\InformationException::class); +}); + test('validateTimezone throws InformationException for an unknown identifier', function (): void { expect(fn (): ?string => i18n::validateTimezone('Mars/Olympus_Mons'))->toThrow(FOSSBilling\InformationException::class); });