Koha/t/db_dependent/Koha_template_plugin_KohaDates.t
Marc Véron 4307591f22 Bug 14977: Remove C4::Dates from files t/db_dependent/*.t
This patch removes C4::Dates from following files:

-  t/db_dependent/Budgets.t
-  t/db_dependent/Holds.t
-  t/db_dependent/Koha_template_plugin_KohaDates.t
-  t/db_dependent/Log.t
-  t/db_dependent/NewsChannels.t

To test:
- First run all tests above
- Apply patch
- Then run tests again. The results should be the same.
  (Note: I get 2 fails with NewsChannels.t, they are the same with
   and without patch).

Signed-off-by: Bernardo Gonzalez Kriegel <bgkriegel@gmail.com>

NewsChanell pass for me before patch, no after.
Followup follows :)
Rest of tests pass

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
2015-10-29 11:58:44 -03:00

58 lines
1.6 KiB
Perl

#!/usr/bin/perl
use Modern::Perl;
use C4::Context;
use Koha::DateUtils;
use Test::More tests => 7;
use Test::MockModule;
BEGIN {
use_ok('Koha::Template::Plugin::KohaDates');
}
my $module_context = new Test::MockModule('C4::Context');
my $date = "1973-05-21";
my $context = C4::Context->new();
my $filter = Koha::Template::Plugin::KohaDates->new();
ok ($filter, "new()");
$context->set_preference( "dateformat", 'iso' );
$context->clear_syspref_cache();
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();
$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();
$filtered_date = $filter->filter($date);
is ($filtered_date,'21/05/1973', "metric conversion") or diag ("metric conversion fails $filtered_date");
$module_context->mock(
'tz',
sub {
return DateTime::TimeZone->new( name => 'Europe/Lisbon' );
}
);
$filtered_date = $filter->filter('1979-04-01');
is( $filtered_date, '01/04/1979', 'us: dt_from_string should return the valid date if a DST is given' );
$module_context->mock(
'tz',
sub {
return DateTime::TimeZone->new( name => 'Europe/Paris' );
}
);
$filtered_date = $filter->filter('2014-03-30 02:00:00');
is( $filtered_date, '30/03/2014', 'us: dt_from_string should return a DateTime object if a DST is given' );