Koha/t/timezones.t
Tomas Cohen Arazi b068259521 Bug 18674: TZ error handling
This patch adds C4::Context->timezone bad timezone handling.
The calculated 'effective' timezone is tested with the right tool and a
fallback to 'local' is added. A warning is printed in the logs.

A test for this is added to about.pl too, along with the right warning
messages in case of problems.

Tests are added for both invalid TZ and to make sure the warning is
raised.

To test:
- Apply the patch
- Run:
  $ kshell
 k$ prove t/timezones.t
=> SUCCESS: All tests pass

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
2018-04-11 16:45:08 -03:00

34 lines
885 B
Raku

use Modern::Perl;
use C4::Context;
use Test::More tests => 5;
use Test::Warn;
use t::lib::Mocks;
use DateTime::TimeZone;
$ENV{TZ} = q{};
t::lib::Mocks::mock_config( 'timezone', q{} );
is( C4::Context->timezone, 'local',
'Got local timezone with no env or config timezone set' );
$ENV{TZ} = 'Antarctica/Macquarie';
is(
C4::Context->timezone,
'Antarctica/Macquarie',
'Got correct timezone using ENV, overrides local time'
);
t::lib::Mocks::mock_config( 'timezone', 'Antarctica/South_Pole' );
is(
C4::Context->timezone,
'Antarctica/South_Pole',
'Got correct timezone using config, overrides env'
);
t::lib::Mocks::mock_config( 'timezone', 'Your/Timezone' );
warning_is {
is( C4::Context->timezone, 'local', 'Invalid timezone falls back to local' ); }
'Invalid timezone in koha-conf.xml (Your/Timezone)',
'Invalid timezone raises a warning';