@ -20,6 +20,7 @@ use utf8;
use Test::More tests = > 46 ;
use Test::MockModule ;
use Test::Deep qw( cmp_deeply ) ;
use Data::Dumper ;
use DateTime ;
@ -254,9 +255,9 @@ is(
$ dbh - > do ( 'DELETE FROM circulation_rules' ) ;
Koha::CirculationRules - > set_rules (
{
categorycode = > '*' ,
branchcode = > '*' ,
itemtype = > '*' ,
categorycode = > undef ,
branchcode = > undef ,
itemtype = > undef ,
rules = > {
reservesallowed = > 25 ,
issuelength = > 14 ,
@ -392,9 +393,9 @@ subtest "CanBookBeRenewed tests" => sub {
# Testing of feature to allow the renewal of reserved items if other items on the record can fill all needed holds
Koha::CirculationRules - > set_rule (
{
categorycode = > '*' ,
branchcode = > '*' ,
itemtype = > '*' ,
categorycode = > undef ,
branchcode = > undef ,
itemtype = > undef ,
rule_name = > 'onshelfholds' ,
rule_value = > '1' ,
}
@ -615,9 +616,9 @@ subtest "CanBookBeRenewed tests" => sub {
# Test premature manual renewal
Koha::CirculationRules - > set_rule (
{
categorycode = > '*' ,
branchcode = > '*' ,
itemtype = > '*' ,
categorycode = > undef ,
branchcode = > undef ,
itemtype = > undef ,
rule_name = > 'norenewalbefore' ,
rule_value = > '7' ,
}
@ -692,9 +693,9 @@ subtest "CanBookBeRenewed tests" => sub {
Koha::CirculationRules - > set_rules (
{
categorycode = > '*' ,
branchcode = > '*' ,
itemtype = > '*' ,
categorycode = > undef ,
branchcode = > undef ,
itemtype = > undef ,
rules = > {
norenewalbefore = > '7' ,
no_auto_renewal_after = > '9' ,
@ -708,9 +709,9 @@ subtest "CanBookBeRenewed tests" => sub {
Koha::CirculationRules - > set_rules (
{
categorycode = > '*' ,
branchcode = > '*' ,
itemtype = > '*' ,
categorycode = > undef ,
branchcode = > undef ,
itemtype = > undef ,
rules = > {
norenewalbefore = > '7' ,
no_auto_renewal_after = > '10' ,
@ -724,9 +725,9 @@ subtest "CanBookBeRenewed tests" => sub {
Koha::CirculationRules - > set_rules (
{
categorycode = > '*' ,
branchcode = > '*' ,
itemtype = > '*' ,
categorycode = > undef ,
branchcode = > undef ,
itemtype = > undef ,
rules = > {
norenewalbefore = > '7' ,
no_auto_renewal_after = > '11' ,
@ -740,9 +741,9 @@ subtest "CanBookBeRenewed tests" => sub {
Koha::CirculationRules - > set_rules (
{
categorycode = > '*' ,
branchcode = > '*' ,
itemtype = > '*' ,
categorycode = > undef ,
branchcode = > undef ,
itemtype = > undef ,
rules = > {
norenewalbefore = > '10' ,
no_auto_renewal_after = > '11' ,
@ -756,9 +757,9 @@ subtest "CanBookBeRenewed tests" => sub {
Koha::CirculationRules - > set_rules (
{
categorycode = > '*' ,
branchcode = > '*' ,
itemtype = > '*' ,
categorycode = > undef ,
branchcode = > undef ,
itemtype = > undef ,
rules = > {
norenewalbefore = > '10' ,
no_auto_renewal_after = > undef ,
@ -773,9 +774,9 @@ subtest "CanBookBeRenewed tests" => sub {
Koha::CirculationRules - > set_rules (
{
categorycode = > '*' ,
branchcode = > '*' ,
itemtype = > '*' ,
categorycode = > undef ,
branchcode = > undef ,
itemtype = > undef ,
rules = > {
norenewalbefore = > '7' ,
no_auto_renewal_after = > '15' ,
@ -790,9 +791,9 @@ subtest "CanBookBeRenewed tests" => sub {
Koha::CirculationRules - > set_rules (
{
categorycode = > '*' ,
branchcode = > '*' ,
itemtype = > '*' ,
categorycode = > undef ,
branchcode = > undef ,
itemtype = > undef ,
rules = > {
norenewalbefore = > '10' ,
no_auto_renewal_after = > undef ,
@ -823,9 +824,9 @@ subtest "CanBookBeRenewed tests" => sub {
Koha::CirculationRules - > set_rules (
{
categorycode = > '*' ,
branchcode = > '*' ,
itemtype = > '*' ,
categorycode = > undef ,
branchcode = > undef ,
itemtype = > undef ,
rules = > {
norenewalbefore = > '10' ,
no_auto_renewal_after = > '11' ,
@ -971,9 +972,9 @@ subtest "CanBookBeRenewed tests" => sub {
AddIssue ( $ renewing_borrower , $ item_to_auto_renew - > { barcode } , $ ten_days_ahead , undef , $ ten_days_before , undef , { auto_renew = > 1 } ) ;
Koha::CirculationRules - > set_rules (
{
categorycode = > '*' ,
branchcode = > '*' ,
itemtype = > '*' ,
categorycode = > undef ,
branchcode = > undef ,
itemtype = > undef ,
rules = > {
norenewalbefore = > '7' ,
no_auto_renewal_after = > '' ,
@ -986,9 +987,9 @@ subtest "CanBookBeRenewed tests" => sub {
my $ five_days_before = dt_from_string - > add ( days = > - 5 ) ;
Koha::CirculationRules - > set_rules (
{
categorycode = > '*' ,
branchcode = > '*' ,
itemtype = > '*' ,
categorycode = > undef ,
branchcode = > undef ,
itemtype = > undef ,
rules = > {
norenewalbefore = > '10' ,
no_auto_renewal_after = > '5' ,
@ -1007,9 +1008,9 @@ subtest "CanBookBeRenewed tests" => sub {
$ dbh - > do ( q{ UPDATE circulation_rules SET rule_value = NULL WHERE rule_name = 'no_auto_renewal_after_hard_limit' } ) ;
Koha::CirculationRules - > set_rules (
{
categorycode = > '*' ,
branchcode = > '*' ,
itemtype = > '*' ,
categorycode = > undef ,
branchcode = > undef ,
itemtype = > undef ,
rules = > {
norenewalbefore = > '10' ,
no_auto_renewal_after = > '15' ,
@ -1025,9 +1026,9 @@ subtest "CanBookBeRenewed tests" => sub {
my $ two_days_ahead = dt_from_string - > add ( days = > 2 ) ;
Koha::CirculationRules - > set_rules (
{
categorycode = > '*' ,
branchcode = > '*' ,
itemtype = > '*' ,
categorycode = > undef ,
branchcode = > undef ,
itemtype = > undef ,
rules = > {
norenewalbefore = > '10' ,
no_auto_renewal_after = > '' ,
@ -1042,9 +1043,9 @@ subtest "CanBookBeRenewed tests" => sub {
) ;
Koha::CirculationRules - > set_rules (
{
categorycode = > '*' ,
branchcode = > '*' ,
itemtype = > '*' ,
categorycode = > undef ,
branchcode = > undef ,
itemtype = > undef ,
rules = > {
norenewalbefore = > '10' ,
no_auto_renewal_after = > '15' ,
@ -1064,9 +1065,9 @@ subtest "CanBookBeRenewed tests" => sub {
# set policy to forbid renewals
Koha::CirculationRules - > set_rules (
{
categorycode = > '*' ,
branchcode = > '*' ,
itemtype = > '*' ,
categorycode = > undef ,
branchcode = > undef ,
itemtype = > undef ,
rules = > {
norenewalbefore = > undef ,
renewalsallowed = > 0 ,
@ -1310,9 +1311,9 @@ subtest "AllowRenewalIfOtherItemsAvailable tests" => sub {
$ dbh - > do ( 'DELETE FROM circulation_rules' ) ;
Koha::CirculationRules - > set_rules (
{
categorycode = > '*' ,
itemtype = > '*' ,
branchcode = > '*' ,
categorycode = > undef ,
itemtype = > undef ,
branchcode = > undef ,
rules = > {
reservesallowed = > 25 ,
issuelength = > 14 ,
@ -1374,9 +1375,9 @@ subtest "AllowRenewalIfOtherItemsAvailable tests" => sub {
Koha::CirculationRules - > set_rules (
{
categorycode = > '*' ,
itemtype = > '*' ,
branchcode = > '*' ,
categorycode = > undef ,
itemtype = > undef ,
branchcode = > undef ,
rules = > {
onshelfholds = > 0 ,
}
@ -1388,9 +1389,9 @@ subtest "AllowRenewalIfOtherItemsAvailable tests" => sub {
Koha::CirculationRules - > set_rules (
{
categorycode = > '*' ,
itemtype = > '*' ,
branchcode = > '*' ,
categorycode = > undef ,
itemtype = > undef ,
branchcode = > undef ,
rules = > {
onshelfholds = > 0 ,
}
@ -1402,9 +1403,9 @@ subtest "AllowRenewalIfOtherItemsAvailable tests" => sub {
Koha::CirculationRules - > set_rules (
{
categorycode = > '*' ,
itemtype = > '*' ,
branchcode = > '*' ,
categorycode = > undef ,
itemtype = > undef ,
branchcode = > undef ,
rules = > {
onshelfholds = > 1 ,
}
@ -1416,9 +1417,9 @@ subtest "AllowRenewalIfOtherItemsAvailable tests" => sub {
Koha::CirculationRules - > set_rules (
{
categorycode = > '*' ,
itemtype = > '*' ,
branchcode = > '*' ,
categorycode = > undef ,
itemtype = > undef ,
branchcode = > undef ,
rules = > {
onshelfholds = > 1 ,
}
@ -1856,23 +1857,39 @@ subtest 'CanBookBeIssued + AllowMultipleIssuesOnABiblio' => sub {
t::lib::Mocks:: mock_preference ( 'AllowMultipleIssuesOnABiblio' , 0 ) ;
( $ error , $ question , $ alerts ) = CanBookBeIssued ( $ patron , $ item_2 - > { barcode } ) ;
is ( keys ( %$ error ) + keys ( %$ alerts ) , 0 , 'No error or alert should be raised' . str ( $ error , $ question , $ alerts ) ) ;
is ( $ question - > { BIBLIO_ALREADY_ISSUED } , 1 , 'BIBLIO_ALREADY_ISSUED question flag should be set if AllowMultipleIssuesOnABiblio=0 and issue already exists' . str ( $ error , $ question , $ alerts ) ) ;
cmp_deeply (
{ error = > $ error , alerts = > $ alerts } ,
{ error = > { } , alerts = > { } } ,
'No error or alert should be raised'
) ;
is ( $ question - > { BIBLIO_ALREADY_ISSUED } , 1 , 'BIBLIO_ALREADY_ISSUED question flag should be set if AllowMultipleIssuesOnABiblio=0 and issue already exists' ) ;
t::lib::Mocks:: mock_preference ( 'AllowMultipleIssuesOnABiblio' , 1 ) ;
( $ error , $ question , $ alerts ) = CanBookBeIssued ( $ patron , $ item_2 - > { barcode } ) ;
is ( keys ( %$ error ) + keys ( %$ question ) + keys ( %$ alerts ) , 0 , 'No BIBLIO_ALREADY_ISSUED flag should be set if AllowMultipleIssuesOnABiblio=1' . str ( $ error , $ question , $ alerts ) ) ;
cmp_deeply (
{ error = > $ error , question = > $ question , alerts = > $ alerts } ,
{ error = > { } , question = > { } , alerts = > { } } ,
'No BIBLIO_ALREADY_ISSUED flag should be set if AllowMultipleIssuesOnABiblio=1'
) ;
# Add a subscription
Koha::Subscription - > new ( { biblionumber = > $ biblionumber } ) - > store ;
t::lib::Mocks:: mock_preference ( 'AllowMultipleIssuesOnABiblio' , 0 ) ;
( $ error , $ question , $ alerts ) = CanBookBeIssued ( $ patron , $ item_2 - > { barcode } ) ;
is ( keys ( %$ error ) + keys ( %$ question ) + keys ( %$ alerts ) , 0 , 'No BIBLIO_ALREADY_ISSUED flag should be set if it is a subscription' . str ( $ error , $ question , $ alerts ) ) ;
cmp_deeply (
{ error = > $ error , question = > $ question , alerts = > $ alerts } ,
{ error = > { } , question = > { } , alerts = > { } } ,
'No BIBLIO_ALREADY_ISSUED flag should be set if it is a subscription'
) ;
t::lib::Mocks:: mock_preference ( 'AllowMultipleIssuesOnABiblio' , 1 ) ;
( $ error , $ question , $ alerts ) = CanBookBeIssued ( $ patron , $ item_2 - > { barcode } ) ;
is ( keys ( %$ error ) + keys ( %$ question ) + keys ( %$ alerts ) , 0 , 'No BIBLIO_ALREADY_ISSUED flag should be set if it is a subscription' . str ( $ error , $ question , $ alerts ) ) ;
cmp_deeply (
{ error = > $ error , question = > $ question , alerts = > $ alerts } ,
{ error = > { } , question = > { } , alerts = > { } } ,
'No BIBLIO_ALREADY_ISSUED flag should be set if it is a subscription'
) ;
} ;
subtest 'AddReturn + CumulativeRestrictionPeriods' = > sub {
@ -1904,9 +1921,9 @@ subtest 'AddReturn + CumulativeRestrictionPeriods' => sub {
Koha::CirculationRules - > search - > delete ;
Koha::CirculationRules - > set_rules (
{
categorycode = > '*' ,
itemtype = > '*' ,
branchcode = > '*' ,
categorycode = > undef ,
itemtype = > undef ,
branchcode = > undef ,
rules = > {
issuelength = > 1 ,
firstremind = > 1 , # 1 day of grace
@ -2215,9 +2232,9 @@ subtest 'AddReturn | is_overdue' => sub {
Koha::CirculationRules - > search - > delete ;
my $ rule = Koha::CirculationRules - > set_rules (
{
categorycode = > '*' ,
itemtype = > '*' ,
branchcode = > '*' ,
categorycode = > undef ,
itemtype = > undef ,
branchcode = > undef ,
rules = > {
issuelength = > 6 ,
lengthunit = > 'days' ,