Lines 4107-4116
subtest 'CanBookBeIssued | is_overdue' => sub {
Link Here
|
4107 |
is( $needsconfirmation->{TOO_MANY}, undef, "Not too many, is a renewal"); |
4107 |
is( $needsconfirmation->{TOO_MANY}, undef, "Not too many, is a renewal"); |
4108 |
}; |
4108 |
}; |
4109 |
|
4109 |
|
4110 |
subtest 'ItemsDeniedRenewal preference' => sub { |
4110 |
subtest 'ItemsDeniedRenewal rules are checked' => sub { |
4111 |
plan tests => 18; |
4111 |
plan tests => 4; |
4112 |
|
|
|
4113 |
C4::Context->set_preference('ItemsDeniedRenewal',''); |
4114 |
|
4112 |
|
4115 |
my $idr_lib = $builder->build_object({ class => 'Koha::Libraries'}); |
4113 |
my $idr_lib = $builder->build_object({ class => 'Koha::Libraries'}); |
4116 |
Koha::CirculationRules->set_rules( |
4114 |
Koha::CirculationRules->set_rules( |
Lines 4132-4146
subtest 'ItemsDeniedRenewal preference' => sub {
Link Here
|
4132 |
} |
4130 |
} |
4133 |
); |
4131 |
); |
4134 |
|
4132 |
|
4135 |
my $deny_book = $builder->build_object({ class => 'Koha::Items', value => { |
|
|
4136 |
homebranch => $idr_lib->branchcode, |
4137 |
withdrawn => 1, |
4138 |
itype => 'HIDE', |
4139 |
location => 'PROC', |
4140 |
itemcallnumber => undef, |
4141 |
itemnotes => "", |
4142 |
} |
4143 |
}); |
4144 |
my $allow_book = $builder->build_object({ class => 'Koha::Items', value => { |
4133 |
my $allow_book = $builder->build_object({ class => 'Koha::Items', value => { |
4145 |
homebranch => $idr_lib->branchcode, |
4134 |
homebranch => $idr_lib->branchcode, |
4146 |
withdrawn => 0, |
4135 |
withdrawn => 0, |
Lines 4154-4174
subtest 'ItemsDeniedRenewal preference' => sub {
Link Here
|
4154 |
} |
4143 |
} |
4155 |
}); |
4144 |
}); |
4156 |
my $future = dt_from_string->add( days => 1 ); |
4145 |
my $future = dt_from_string->add( days => 1 ); |
4157 |
my $deny_issue = $builder->build_object( |
4146 |
my $issue = $builder->build_object( |
4158 |
{ |
|
|
4159 |
class => 'Koha::Checkouts', |
4160 |
value => { |
4161 |
returndate => undef, |
4162 |
renewals_count => 0, |
4163 |
auto_renew => 0, |
4164 |
borrowernumber => $idr_borrower->borrowernumber, |
4165 |
itemnumber => $deny_book->itemnumber, |
4166 |
onsite_checkout => 0, |
4167 |
date_due => $future, |
4168 |
} |
4169 |
} |
4170 |
); |
4171 |
my $allow_issue = $builder->build_object( |
4172 |
{ |
4147 |
{ |
4173 |
class => 'Koha::Checkouts', |
4148 |
class => 'Koha::Checkouts', |
4174 |
value => { |
4149 |
value => { |
Lines 4183-4252
subtest 'ItemsDeniedRenewal preference' => sub {
Link Here
|
4183 |
} |
4158 |
} |
4184 |
); |
4159 |
); |
4185 |
|
4160 |
|
4186 |
my $idr_rules; |
4161 |
my $mock_item_class = Test::MockModule->new("Koha::Item"); |
4187 |
|
4162 |
$mock_item_class->mock( 'is_denied_renewal', sub { return 1; } ); |
4188 |
my ( $idr_mayrenew, $idr_error ) = |
4163 |
|
4189 |
CanBookBeRenewed( $idr_borrower->borrowernumber, $deny_issue->itemnumber ); |
4164 |
my ( $mayrenew, $error ) = CanBookBeRenewed( $idr_borrower->borrowernumber, $issue->itemnumber ); |
4190 |
is( $idr_mayrenew, 1, 'Renewal allowed when no rules' ); |
4165 |
is( $mayrenew, 0, 'Renewal blocked when $item->is_denied_renewal returns true' ); |
4191 |
is( $idr_error, undef, 'Renewal allowed when no rules' ); |
4166 |
is( $error, 'item_denied_renewal', 'Renewal blocked when $item->is_denied_renewal returns true' ); |
4192 |
|
4167 |
|
4193 |
$idr_rules="withdrawn: [1]"; |
4168 |
$mock_item_class->unmock( 'is_denied_renewal' ); |
4194 |
|
4169 |
$mock_item_class->mock( 'is_denied_renewal', sub { return 0; } ); |
4195 |
C4::Context->set_preference('ItemsDeniedRenewal',$idr_rules); |
4170 |
|
4196 |
( $idr_mayrenew, $idr_error ) = |
4171 |
( $mayrenew, $error ) = CanBookBeRenewed( $idr_borrower->borrowernumber, $issue->itemnumber ); |
4197 |
CanBookBeRenewed( $idr_borrower->borrowernumber, $deny_issue->itemnumber ); |
4172 |
is( $mayrenew, 1, 'Renewal allowed when $item->is_denied_renewal returns false' ); |
4198 |
is( $idr_mayrenew, 0, 'Renewal blocked when 1 rules (withdrawn)' ); |
4173 |
is( $error, undef, 'Renewal allowed when $item->is_denied_renewal returns false' ); |
4199 |
is( $idr_error, 'item_denied_renewal', 'Renewal blocked when 1 rule (withdrawn)' ); |
4174 |
|
4200 |
( $idr_mayrenew, $idr_error ) = |
4175 |
$mock_item_class->unmock( 'is_denied_renewal' ); |
4201 |
CanBookBeRenewed( $idr_borrower->borrowernumber, $allow_issue->itemnumber ); |
|
|
4202 |
is( $idr_mayrenew, 1, 'Renewal allowed when 1 rules not matched (withdrawn)' ); |
4203 |
is( $idr_error, undef, 'Renewal allowed when 1 rules not matched (withdrawn)' ); |
4204 |
|
4205 |
$idr_rules="withdrawn: [1]\nitype: [HIDE,INVISIBLE]"; |
4206 |
|
4207 |
C4::Context->set_preference('ItemsDeniedRenewal',$idr_rules); |
4208 |
( $idr_mayrenew, $idr_error ) = |
4209 |
CanBookBeRenewed( $idr_borrower->borrowernumber, $deny_issue->itemnumber ); |
4210 |
is( $idr_mayrenew, 0, 'Renewal blocked when 2 rules matched (withdrawn, itype)' ); |
4211 |
is( $idr_error, 'item_denied_renewal', 'Renewal blocked when 2 rules matched (withdrawn,itype)' ); |
4212 |
( $idr_mayrenew, $idr_error ) = |
4213 |
CanBookBeRenewed( $idr_borrower->borrowernumber, $allow_issue->itemnumber ); |
4214 |
is( $idr_mayrenew, 1, 'Renewal allowed when 2 rules not matched (withdrawn, itype)' ); |
4215 |
is( $idr_error, undef, 'Renewal allowed when 2 rules not matched (withdrawn, itype)' ); |
4216 |
|
4217 |
$idr_rules="withdrawn: [1]\nitype: [HIDE,INVISIBLE]\nlocation: [PROC]"; |
4218 |
|
4219 |
C4::Context->set_preference('ItemsDeniedRenewal',$idr_rules); |
4220 |
( $idr_mayrenew, $idr_error ) = |
4221 |
CanBookBeRenewed( $idr_borrower->borrowernumber, $deny_issue->itemnumber ); |
4222 |
is( $idr_mayrenew, 0, 'Renewal blocked when 3 rules matched (withdrawn, itype, location)' ); |
4223 |
is( $idr_error, 'item_denied_renewal', 'Renewal blocked when 3 rules matched (withdrawn,itype, location)' ); |
4224 |
( $idr_mayrenew, $idr_error ) = |
4225 |
CanBookBeRenewed( $idr_borrower->borrowernumber, $allow_issue->itemnumber ); |
4226 |
is( $idr_mayrenew, 1, 'Renewal allowed when 3 rules not matched (withdrawn, itype, location)' ); |
4227 |
is( $idr_error, undef, 'Renewal allowed when 3 rules not matched (withdrawn, itype, location)' ); |
4228 |
|
4229 |
$idr_rules="itemcallnumber: [NULL]"; |
4230 |
C4::Context->set_preference('ItemsDeniedRenewal',$idr_rules); |
4231 |
( $idr_mayrenew, $idr_error ) = |
4232 |
CanBookBeRenewed( $idr_borrower->borrowernumber, $deny_issue->itemnumber ); |
4233 |
is( $idr_mayrenew, 0, 'Renewal blocked for undef when NULL in pref' ); |
4234 |
$idr_rules="itemcallnumber: ['']"; |
4235 |
C4::Context->set_preference('ItemsDeniedRenewal',$idr_rules); |
4236 |
( $idr_mayrenew, $idr_error ) = |
4237 |
CanBookBeRenewed( $idr_borrower->borrowernumber, $deny_issue->itemnumber ); |
4238 |
is( $idr_mayrenew, 1, 'Renewal not blocked for undef when "" in pref' ); |
4239 |
|
4240 |
$idr_rules="itemnotes: [NULL]"; |
4241 |
C4::Context->set_preference('ItemsDeniedRenewal',$idr_rules); |
4242 |
( $idr_mayrenew, $idr_error ) = |
4243 |
CanBookBeRenewed( $idr_borrower->borrowernumber, $deny_issue->itemnumber ); |
4244 |
is( $idr_mayrenew, 1, 'Renewal not blocked for "" when NULL in pref' ); |
4245 |
$idr_rules="itemnotes: ['']"; |
4246 |
C4::Context->set_preference('ItemsDeniedRenewal',$idr_rules); |
4247 |
( $idr_mayrenew, $idr_error ) = |
4248 |
CanBookBeRenewed( $idr_borrower->borrowernumber, $deny_issue->itemnumber ); |
4249 |
is( $idr_mayrenew, 0, 'Renewal blocked for empty string when "" in pref' ); |
4250 |
}; |
4176 |
}; |
4251 |
|
4177 |
|
4252 |
subtest 'CanBookBeIssued | item-level_itypes=biblio' => sub { |
4178 |
subtest 'CanBookBeIssued | item-level_itypes=biblio' => sub { |