Bug 26384: Fix executable flags
[koha.git] / t / db_dependent / Template / Plugin / KohaDates.t
1 #!/usr/bin/perl
2
3 use Modern::Perl;
4
5 use C4::Context;
6 use Koha::DateUtils;
7
8 use Test::MockModule;
9 use Test::More tests => 9;
10 use t::lib::Mocks;
11
12 BEGIN {
13         use_ok('Koha::Template::Plugin::KohaDates');
14 }
15
16 my $module_context = new Test::MockModule('C4::Context');
17
18 my $date = "1973-05-21";
19 my $context = C4::Context->new();
20
21 my $filter = Koha::Template::Plugin::KohaDates->new();
22 ok ($filter, "new()");
23
24 t::lib::Mocks::mock_preference( "dateformat", 'iso' );
25 $context->clear_syspref_cache();
26
27 my $filtered_date = $filter->filter($date);
28 is ($filtered_date,$date, "iso conversion") or diag ("iso conversion fails");
29
30 #$filter = Koha::Template::Plugin::KohaDates->new();
31 t::lib::Mocks::mock_preference( "dateformat", 'us' );
32 $context->clear_syspref_cache();
33
34 $filtered_date = $filter->filter($date);
35 is ($filtered_date,'05/21/1973', "us conversion") or diag ("us conversion fails $filtered_date");
36
37 t::lib::Mocks::mock_preference( "dateformat", 'metric' );
38 $context->clear_syspref_cache();
39
40 $filtered_date = $filter->filter($date);
41 is ($filtered_date,'21/05/1973', "metric conversion") or diag ("metric conversion fails $filtered_date");
42
43 $module_context->mock(
44     'tz',
45     sub {
46         return DateTime::TimeZone->new( name => 'Europe/Lisbon' );
47     }
48 );
49
50 $filtered_date = $filter->filter('1979-04-01');
51 is( $filtered_date, '01/04/1979', 'us: dt_from_string should return the valid date if a dst is given' );
52
53 $filtered_date = $filter->filter('1979-04-01', undef, { dateformat => 'iso' } );
54 is( $filtered_date, '1979-04-01', 'date should be returned in ISO if dateformat is passed with a value of iso' );
55
56 is( Koha::DateUtils::output_pref( dt_from_string ), $filter->output_preference( dt_from_string ), 'Filter output_preference method output matches output_pref' );
57
58 $module_context->mock(
59     'tz',
60     sub {
61         return DateTime::TimeZone->new( name => 'Europe/Paris' );
62     }
63 );
64
65 $filtered_date = $filter->filter('2014-03-30 02:00:00');
66 is( $filtered_date, '30/03/2014', 'us: dt_from_string should return a DateTime object if a DST is given' );