Bug 13933: Fix t/DateUtils.t without DB
authorJonathan Druart <jonathan.druart@biblibre.com>
Tue, 31 Mar 2015 07:56:56 +0000 (09:56 +0200)
committerTomas Cohen Arazi <tomascohen@gmail.com>
Wed, 1 Apr 2015 16:10:16 +0000 (13:10 -0300)
If the mysql server is not running, the DateUtils.t tests failed.
This is caused by

commit dd9f456ab7c2f0e66173a6feb7df2a38604c82cd
    Bug 13601: Add tests to highlight the problems with
    DateTime::Format::DateParse

The pref dateformat and TimeFormat were retrieved before the mock.
Before bug 13601, the complete preference method was mocked, that's why
the error did not appear.

Test plan:
  sudo service mysql stop
  prove t/DateUtils.t
should be happy

Signed-off-by: Nicolas Legrand <nicolas.legrand@bulac.fr>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
t/DateUtils.t

index 1af4268..4f7c773 100755 (executable)
@@ -10,6 +10,9 @@ use t::lib::Mocks;
 
 BEGIN { use_ok('Koha::DateUtils'); }
 
+t::lib::Mocks::mock_preference('dateformat', 'us');
+t::lib::Mocks::mock_preference('TimeFormat', 'This_is_not_used_but_called');
+
 my $tz = C4::Context->tz;
 
 isa_ok( $tz, 'DateTime::TimeZone', 'Context returns timezone object' );
@@ -26,10 +29,6 @@ $dt->set_minute(0);
 
 my $date_string;
 
-my $module_context = new Test::MockModule('C4::Context');
-
-t::lib::Mocks::mock_preference('dateformat', 'us');
-
 my $dateformat = C4::Context->preference('dateformat');
 cmp_ok  output_pref({ dt => $dt, dateformat => $dateformat }),
         'eq',
@@ -160,6 +159,7 @@ cmp_ok $date_string, 'eq', '12/11/2013 06:35 PM', 'as_due_date with hours and ti
 my $now = DateTime->now;
 is( dt_from_string, $now, "Without parameter, dt_from_string should return today" );
 
+my $module_context = new Test::MockModule('C4::Context');
 $module_context->mock(
     'tz',
     sub {