Koha/t/db_dependent/Circulation_issuingrules.t
Jonathan Druart 769728015c Bug 15757: Make GetLoanLength defaults to 0 instead of 21
GetLoanLength arbitrary defaulted to 21. The expected behavior seems to
be to default on 0 (loan will be dued today).

IMPORTANT NOTE: This patch will introduce a change in the behaviors for
configuration with a 0 in issuelength. Before this patch, the rule with
a issuelength==0 was skipped, now it's used!

Test plan:
1/ Do not define any rule: the due date will be today (before this patch
was +21 days)
2/ Define some rules which does not match the patron category, itemtype
or branchcode: the due date will be today (before this patch was +21
days).
3/ Modify a rule to match the checkout and set issuelength=0: the due
date will be today (before this patch, the rule was skipped)
4/ Modify this rule and set the issuelength to something > 0: the due
date will be adjusted (same behavior as before this patch)

Signed-off-by: Bernardo Gonzalez Kriegel <bgkriegel@gmail.com>
Works ok, checked 1-4
All test pass
No koha-qa errors

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
2016-04-22 00:24:06 +00:00

101 lines
3.2 KiB
Perl

#!/usr/bin/perl
use Modern::Perl;
use Test::More tests => 7;
use Test::MockModule;
use DBI;
use DateTime;
use t::lib::Mocks;
BEGIN {
t::lib::Mocks::mock_dbh;
}
use_ok('C4::Circulation');
my $dbh = C4::Context->dbh();
my $issuelength = 10;
my $renewalperiod = 5;
my $lengthunit = 'days';
my $expected = {
issuelength => $issuelength,
renewalperiod => $renewalperiod,
lengthunit => $lengthunit
};
my $default = {
issuelength => 0,
renewalperiod => 0,
lengthunit => 'days'
};
my $loanlength;
my $mock_undef = [
[]
];
my $mock_loan_length = [
['issuelength', 'renewalperiod', 'lengthunit'],
[$issuelength, $renewalperiod, $lengthunit]
];
my $categorycode = 'B';
my $itemtype = 'MX';
my $branchcode = 'FPL';
#=== GetLoanLength
$dbh->{mock_add_resultset} = $mock_loan_length;
$loanlength = C4::Circulation::GetLoanLength($categorycode, $itemtype, $branchcode);
is_deeply($loanlength, $expected, 'first matches');
$dbh->{mock_add_resultset} = $mock_undef;
$loanlength = C4::Circulation::GetLoanLength($categorycode, $itemtype, $branchcode);
is_deeply($loanlength, $default, 'none matches');
#=== CalcDateDue
#Set syspref ReturnBeforeExpiry = 1 and useDaysMode = 'Days'
t::lib::Mocks::mock_preference('ReturnBeforeExpiry', 1);
t::lib::Mocks::mock_preference('useDaysMode', 'Days');
my $dateexpiry = '2013-01-01';
my $borrower = {categorycode => 'B', dateexpiry => $dateexpiry};
my $start_date = DateTime->new({year => 2013, month => 2, day => 9});
$dbh->{mock_add_resultset} = $mock_loan_length;
my $date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower );
is($date, $dateexpiry . 'T23:59:00', 'date expiry');
$dbh->{mock_add_resultset} = $mock_loan_length;
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower, 1 );
#Set syspref ReturnBeforeExpiry = 1 and useDaysMode != 'Days'
t::lib::Mocks::mock_preference('ReturnBeforeExpiry', 1);
t::lib::Mocks::mock_preference('useDaysMode', 'noDays');
$borrower = {categorycode => 'B', dateexpiry => $dateexpiry};
$start_date = DateTime->new({year => 2013, month => 2, day => 9});
$dbh->{mock_add_resultset} = $mock_loan_length;
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower );
is($date, $dateexpiry . 'T23:59:00', 'date expiry');
$dbh->{mock_add_resultset} = $mock_loan_length;
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower, 1 );
#Set syspref ReturnBeforeExpiry = 0 and useDaysMode = 'Days'
t::lib::Mocks::mock_preference('ReturnBeforeExpiry', 0);
t::lib::Mocks::mock_preference('useDaysMode', 'Days');
$borrower = {categorycode => 'B', dateexpiry => $dateexpiry};
$start_date = DateTime->new({year => 2013, month => 2, day => 9});
$dbh->{mock_add_resultset} = $mock_loan_length;
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower );
is($date, '2013-02-' . (9 + $issuelength) . 'T23:59:00', "date expiry ( 9 + $issuelength )");
$dbh->{mock_add_resultset} = $mock_loan_length;
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower, 1 );
is($date, '2013-02-' . (9 + $renewalperiod) . 'T23:59:00', "date expiry ( 9 + $renewalperiod )");