Bug 929 : Follow up adding unit tests, discovered C4::Dates cached the syspref with no way to clear it, fixed also.
This commit is contained in:
parent
e6bbb97942
commit
55d0b65522
2 changed files with 48 additions and 0 deletions
|
@ -41,6 +41,12 @@ sub _prefformat {
|
|||
return $prefformat;
|
||||
}
|
||||
|
||||
sub reset_prefformat { # subroutine to clear the prefformat, called when we change it
|
||||
if (defined $prefformat){
|
||||
$prefformat = C4::Context->preference('dateformat');
|
||||
}
|
||||
}
|
||||
|
||||
our %format_map = (
|
||||
iso => 'yyyy-mm-dd', # plus " HH:MM:SS"
|
||||
metric => 'dd/mm/yyyy', # plus " HH:MM:SS"
|
||||
|
|
42
t/Koha_template_plugin_KohaDates.t
Normal file
42
t/Koha_template_plugin_KohaDates.t
Normal file
|
@ -0,0 +1,42 @@
|
|||
#!/usr/bin/perl
|
||||
#
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use C4::Context;
|
||||
use C4::Dates;
|
||||
use Test::More tests => 5;
|
||||
|
||||
BEGIN {
|
||||
use_ok('Koha::Template::Plugin::KohaDates');
|
||||
}
|
||||
|
||||
my $date = "1973-05-21";
|
||||
my $context = C4::Context->new();
|
||||
my $dateobj = C4::Dates->new();
|
||||
|
||||
my $filter = Koha::Template::Plugin::KohaDates->new();
|
||||
ok ($filter, "new()");
|
||||
|
||||
|
||||
$context->set_preference( "dateformat", 'iso' );
|
||||
$context->clear_syspref_cache();
|
||||
$dateobj->reset_prefformat;
|
||||
|
||||
my $filtered_date = $filter->filter($date);
|
||||
is ($filtered_date,$date, "iso conversion") or diag ("iso conversion fails");
|
||||
|
||||
#$filter = Koha::Template::Plugin::KohaDates->new();
|
||||
$context->set_preference( "dateformat", 'us' );
|
||||
$context->clear_syspref_cache();
|
||||
$dateobj->reset_prefformat;
|
||||
|
||||
$filtered_date = $filter->filter($date);
|
||||
is ($filtered_date,'05/21/1973', "us conversion") or diag ("us conversion fails $filtered_date");
|
||||
|
||||
$context->set_preference( "dateformat", 'metric' );
|
||||
$context->clear_syspref_cache();
|
||||
$dateobj->reset_prefformat;
|
||||
|
||||
$filtered_date = $filter->filter($date);
|
||||
is ($filtered_date,'21/05/1973', "metric conversion") or diag ("metric conversion fails $filtered_date");
|
Loading…
Reference in a new issue