5 use Test
::More tests
=> 7;
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 $cache = Koha
::Caches
->get_instance();
40 $cache->clear_from_cache('single_holidays');
42 my $dateexpiry = '2013-01-01';
44 my $borrower = {categorycode
=> 'B', dateexpiry
=> $dateexpiry};
45 my $start_date = DateTime
->new({year
=> 2013, month
=> 2, day
=> 9});
46 my $date = C4
::Circulation
::CalcDateDue
( $start_date, $itemtype, $branchcode, $borrower );
47 is
($date, $dateexpiry . 'T23:59:00', 'date expiry');
48 $date = C4
::Circulation
::CalcDateDue
( $start_date, $itemtype, $branchcode, $borrower, 1 );
51 #Set syspref ReturnBeforeExpiry = 1 and useDaysMode != 'Days'
52 t
::lib
::Mocks
::mock_preference
('ReturnBeforeExpiry', 1);
53 t
::lib
::Mocks
::mock_preference
('useDaysMode', 'noDays');
55 $borrower = {categorycode
=> 'B', dateexpiry
=> $dateexpiry};
56 $start_date = DateTime
->new({year
=> 2013, month
=> 2, day
=> 9});
57 $date = C4
::Circulation
::CalcDateDue
( $start_date, $itemtype, $branchcode, $borrower );
58 is
($date, $dateexpiry . 'T23:59:00', 'date expiry with useDaysMode to noDays');
60 # Let's add a special holiday on 2013-01-01. With ReturnBeforeExpiry and
61 # useDaysMode different from 'Days', return should forward the dateexpiry.
62 my $calendar = C4
::Calendar
->new(branchcode
=> $branchcode);
63 $calendar->insert_single_holiday(
67 title
=>'holidayTest',
68 description
=> 'holidayDesc'
70 $date = C4
::Circulation
::CalcDateDue
( $start_date, $itemtype, $branchcode, $borrower );
71 is
($date, '2012-12-31T23:59:00', 'date expiry should be 2013-01-01 -1 day');
72 $calendar->insert_single_holiday(
76 title
=>'holidayTest',
77 description
=> 'holidayDesc'
79 $date = C4
::Circulation
::CalcDateDue
( $start_date, $itemtype, $branchcode, $borrower );
80 is
($date, '2012-12-30T23:59:00', 'date expiry should be 2013-01-01 -2 day');
83 $date = C4
::Circulation
::CalcDateDue
( $start_date, $itemtype, $branchcode, $borrower, 1 );
86 #Set syspref ReturnBeforeExpiry = 0 and useDaysMode = 'Days'
87 t
::lib
::Mocks
::mock_preference
('ReturnBeforeExpiry', 0);
88 t
::lib
::Mocks
::mock_preference
('useDaysMode', 'Days');
90 $borrower = {categorycode
=> 'B', dateexpiry
=> $dateexpiry};
91 $start_date = DateTime
->new({year
=> 2013, month
=> 2, day
=> 9});
92 $date = C4
::Circulation
::CalcDateDue
( $start_date, $itemtype, $branchcode, $borrower );
93 is
($date, '2013-02-' . (9 + $issuelength) . 'T23:59:00', "date expiry ( 9 + $issuelength )");
95 $date = C4
::Circulation
::CalcDateDue
( $start_date, $itemtype, $branchcode, $borrower, 1 );
96 is
($date, '2013-02-' . (9 + $renewalperiod) . 'T23:59:00', "date expiry ( 9 + $renewalperiod )");
98 $cache->clear_from_cache('single_holidays');
99 $schema->storage->txn_rollback;