5 use Test::More tests => 6;
10 use t::lib::TestBuilder;
13 use_ok('C4::Circulation');
15 my $schema = Koha::Database->new->schema;
16 $schema->storage->txn_begin;
17 my $builder = t::lib::TestBuilder->new;
19 my $categorycode = 'B';
21 my $branchcode = 'FPL';
23 my $renewalperiod = 5;
24 my $lengthunit = 'days';
26 Koha::Database->schema->resultset('Issuingrule')->create({
27 categorycode => $categorycode,
28 itemtype => $itemtype,
29 branchcode => $branchcode,
30 issuelength => $issuelength,
31 renewalperiod => $renewalperiod,
32 lengthunit => $lengthunit,
35 #Set syspref ReturnBeforeExpiry = 1 and useDaysMode = 'Days'
36 t::lib::Mocks::mock_preference('ReturnBeforeExpiry', 1);
37 t::lib::Mocks::mock_preference('useDaysMode', 'Days');
39 my $dateexpiry = '2013-01-01';
41 my $borrower = {categorycode => 'B', dateexpiry => $dateexpiry};
42 my $start_date = DateTime->new({year => 2013, month => 2, day => 9});
43 my $date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower );
44 is($date, $dateexpiry . 'T23:59:00', 'date expiry');
45 $date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower, 1 );
48 #Set syspref ReturnBeforeExpiry = 1 and useDaysMode != 'Days'
49 t::lib::Mocks::mock_preference('ReturnBeforeExpiry', 1);
50 t::lib::Mocks::mock_preference('useDaysMode', 'noDays');
52 $borrower = {categorycode => 'B', dateexpiry => $dateexpiry};
53 $start_date = DateTime->new({year => 2013, month => 2, day => 9});
54 $date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower );
55 is($date, $dateexpiry . 'T23:59:00', 'date expiry with useDaysMode to noDays');
57 # Let's add a special holiday on 2013-01-01. With ReturnBeforeExpiry and
58 # useDaysMode different from 'Days', return should forward the dateexpiry.
59 my $calendar = C4::Calendar->new(branchcode => $branchcode);
60 $calendar->insert_single_holiday(
64 title =>'holidayTest',
65 description => 'holidayDesc'
67 $date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower );
68 is($date, '2012-12-31T23:59:00', 'date expiry should be 2013-01-01 -1 day');
71 $date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower, 1 );
74 #Set syspref ReturnBeforeExpiry = 0 and useDaysMode = 'Days'
75 t::lib::Mocks::mock_preference('ReturnBeforeExpiry', 0);
76 t::lib::Mocks::mock_preference('useDaysMode', 'Days');
78 $borrower = {categorycode => 'B', dateexpiry => $dateexpiry};
79 $start_date = DateTime->new({year => 2013, month => 2, day => 9});
80 $date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower );
81 is($date, '2013-02-' . (9 + $issuelength) . 'T23:59:00', "date expiry ( 9 + $issuelength )");
83 $date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower, 1 );
84 is($date, '2013-02-' . (9 + $renewalperiod) . 'T23:59:00', "date expiry ( 9 + $renewalperiod )");
86 $schema->storage->txn_rollback;