From a1d4cb859d30f2a2aed5ee0518eb101fcd66156b Mon Sep 17 00:00:00 2001 From: Baptiste Wojtkowski Date: Thu, 23 Feb 2017 16:21:05 +0000 Subject: [PATCH] BUG 11580 : Added unit test Added one unit test when the syspref useDaysMode is active. This does not move code anymore Signed-off-by: Katrin Fischer Signed-off-by: Kyle M Hall --- t/db_dependent/Circulation/dateexpiry.t | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Circulation/dateexpiry.t b/t/db_dependent/Circulation/dateexpiry.t index dbb7e0b..cf88536 100644 --- a/t/db_dependent/Circulation/dateexpiry.t +++ b/t/db_dependent/Circulation/dateexpiry.t @@ -23,6 +23,7 @@ use Test::More tests => 2; use C4::Members; use Koha::DateUtils; use Koha::Database; +use C4::Calendar; use t::lib::TestBuilder; use t::lib::Mocks qw( mock_preference ); @@ -39,7 +40,7 @@ subtest 'Tests for CanBookBeIssued related to dateexpiry' => sub { can_book_be_issued(); }; subtest 'Tests for CalcDateDue related to dateexpiry' => sub { - plan tests => 4; + plan tests => 5; calc_date_due(); }; @@ -82,6 +83,7 @@ sub can_book_be_issued { sub calc_date_due { t::lib::Mocks::mock_preference( 'ReturnBeforeExpiry', 1 ); + t::lib::Mocks::mock_preference( 'useDaysMode', 'Days' ); # this triggers the compare between expiry and due date @@ -116,6 +118,26 @@ sub calc_date_due { $d = C4::Circulation::CalcDateDue( $today, $item->{itype}, $branch->{branchcode}, $patron ); my $t2 = time; is( ref $d eq "DateTime" && $t2 - $t1 < 1, 1, "CalcDateDue with expiry in year 9876 in " . sprintf( "%6.4f", $t2 - $t1 ) . " seconds." ); + + # fifth test takes account of closed days + $d = C4::Circulation::CalcDateDue( $today, $item->{itype}, $branch->{branchcode}, $patron ); + t::lib::Mocks::mock_preference( 'useDaysMode', 'Datedue' ); + my $calendar = C4::Calendar->new(branchcode => $branch->{branchcode}); + $calendar->insert_single_holiday( + day => $d->day(), + month => $d->month(), + year => $d->year(), + title =>'holidayTest', + description => 'holidayDesc' + ); + $calendar->delete_holiday(weekday => $d->day_of_week() - 1, day => $d->day()-1, month =>$d->month(), year=>$d->year() ); + $d2 = C4::Circulation::CalcDateDue( $today, $item->{itype}, $branch->{branchcode}, $patron ); + $d2->add(days => 1); + $d->truncate( to => 'day' ); + $d2->truncate( to => 'day' ); + warn Data::Dumper::Dumper($d->datetime()); + warn Data::Dumper::Dumper($d2->datetime()); + is ( DateTime->compare( $d, $d2) == 0, 1, "no problem with closed days"); } $schema->storage->txn_rollback; -- 2.10.2