|
Line 0
Link Here
|
| 0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
| 3 |
use Modern::Perl; |
| 4 |
|
| 5 |
use C4::Context; |
| 6 |
|
| 7 |
use Test::MockModule; |
| 8 |
use Test::More tests => 5; |
| 9 |
use t::lib::Mocks; |
| 10 |
|
| 11 |
BEGIN { |
| 12 |
use_ok('Koha::Template::Plugin::KohaTimes'); |
| 13 |
} |
| 14 |
|
| 15 |
my $module_context = Test::MockModule->new('C4::Context'); |
| 16 |
|
| 17 |
my $test_time = "21:45:32"; |
| 18 |
my $test_midnight = "00:00:00"; |
| 19 |
|
| 20 |
my $context = C4::Context->new(); |
| 21 |
|
| 22 |
my $filter = Koha::Template::Plugin::KohaTimes->new(); |
| 23 |
ok( $filter, "new()" ); |
| 24 |
|
| 25 |
t::lib::Mocks::mock_preference( "TimeFormat", '24hr' ); |
| 26 |
$context->clear_syspref_cache(); |
| 27 |
|
| 28 |
my $filtered_time = $filter->filter($test_time); |
| 29 |
is( $filtered_time, "21:45", "24-hour conversion" ) or diag("24-hour conversion failed"); |
| 30 |
|
| 31 |
t::lib::Mocks::mock_preference( "TimeFormat", '12hr' ); |
| 32 |
$context->clear_syspref_cache(); |
| 33 |
|
| 34 |
$filtered_time = $filter->filter($test_time); |
| 35 |
is( $filtered_time, "09:45 pm", "12-hour conversion" ) or diag("12-hour conversion failed"); |
| 36 |
|
| 37 |
$filtered_time = $filter->filter($test_midnight); |
| 38 |
is( $filtered_time, "12:00 am", "12-hour midnight/AM conversion" ) or diag("12-hour midnight/AM conversion failed"); |