5 use Test
::More tests
=> 7;
10 my $contextmodule = new Test
::MockModule
('C4::Context');
11 $contextmodule->mock('_new_dbh', sub {
12 my $dbh = DBI
->connect( 'DBI:Mock:', '', '' )
13 || die "Cannot create handle: $DBI::errstr\n";
17 use_ok
('C4::Circulation');
19 my $dbh = C4
::Context
->dbh();
22 my $renewalperiod = 5;
23 my $lengthunit = 'days';
26 issuelength
=> $issuelength,
27 renewalperiod
=> $renewalperiod,
28 lengthunit
=> $lengthunit
42 my $mock_loan_length = [
43 ['issuelength', 'renewalperiod', 'lengthunit'],
44 [$issuelength, $renewalperiod, $lengthunit]
47 my $categorycode = 'B';
49 my $branchcode = 'FPL';
52 $dbh->{mock_add_resultset
} = $mock_loan_length;
53 $loanlength = C4
::Circulation
::GetLoanLength
($categorycode, $itemtype, $branchcode);
54 is_deeply
($loanlength, $expected, 'first matches');
56 $dbh->{mock_add_resultset
} = $mock_undef;
57 $loanlength = C4
::Circulation
::GetLoanLength
($categorycode, $itemtype, $branchcode);
58 is_deeply
($loanlength, $default, 'none matches');
62 #Set syspref ReturnBeforeExpiry = 1 and useDaysMode = 'Days'
63 $contextmodule->mock('preference', sub {
64 my ($self, $syspref) = @_;
65 if ( $syspref eq "ReturnBeforeExpiry" ) {
67 } elsif ( $syspref eq "useDaysMode" ) {
74 my $dateexpiry = '2013-01-01';
76 my $borrower = {categorycode
=> 'B', dateexpiry
=> $dateexpiry};
77 my $start_date = DateTime
->new({year
=> 2013, month
=> 2, day
=> 9});
78 $dbh->{mock_add_resultset
} = $mock_loan_length;
79 my $date = C4
::Circulation
::CalcDateDue
( $start_date, $itemtype, $branchcode, $borrower );
80 is
($date, $dateexpiry . 'T23:59:00', 'date expiry');
81 $dbh->{mock_add_resultset
} = $mock_loan_length;
82 $date = C4
::Circulation
::CalcDateDue
( $start_date, $itemtype, $branchcode, $borrower, 1 );
85 #Set syspref ReturnBeforeExpiry = 1 and useDaysMode != 'Days'
86 $contextmodule->mock('preference', sub {
87 my ($self, $syspref) = @_;
88 if ( $syspref eq "ReturnBeforeExpiry" ) {
90 } elsif ( $syspref eq "useDaysMode" ) {
97 $borrower = {categorycode
=> 'B', dateexpiry
=> $dateexpiry};
98 $start_date = DateTime
->new({year
=> 2013, month
=> 2, day
=> 9});
99 $dbh->{mock_add_resultset
} = $mock_loan_length;
100 $date = C4
::Circulation
::CalcDateDue
( $start_date, $itemtype, $branchcode, $borrower );
101 is
($date, $dateexpiry . 'T23:59:00', 'date expiry');
103 $dbh->{mock_add_resultset
} = $mock_loan_length;
104 $date = C4
::Circulation
::CalcDateDue
( $start_date, $itemtype, $branchcode, $borrower, 1 );
107 #Set syspref ReturnBeforeExpiry = 0 and useDaysMode = 'Days'
108 $contextmodule->mock('preference', sub {
109 my ($self, $syspref) = @_;
110 if ( $syspref eq "ReturnBeforeExpiry" ) {
112 } elsif ( $syspref eq "useDaysMode" ) {
119 $borrower = {categorycode
=> 'B', dateexpiry
=> $dateexpiry};
120 $start_date = DateTime
->new({year
=> 2013, month
=> 2, day
=> 9});
121 $dbh->{mock_add_resultset
} = $mock_loan_length;
122 $date = C4
::Circulation
::CalcDateDue
( $start_date, $itemtype, $branchcode, $borrower );
123 is
($date, '2013-02-' . (9 + $issuelength) . 'T23:59:00', "date expiry ( 9 + $issuelength )");
125 $dbh->{mock_add_resultset
} = $mock_loan_length;
126 $date = C4
::Circulation
::CalcDateDue
( $start_date, $itemtype, $branchcode, $borrower, 1 );
127 is
($date, '2013-02-' . (9 + $renewalperiod) . 'T23:59:00', "date expiry ( 9 + $renewalperiod )");