Lines 16-22
use t::lib::TestBuilder;
Link Here
|
16 |
use t::lib::Mocks; |
16 |
use t::lib::Mocks; |
17 |
|
17 |
|
18 |
BEGIN { |
18 |
BEGIN { |
19 |
use_ok( 'C4::Reserves', qw( ItemsAnyAvailableAndNotRestricted IsAvailableForItemLevelRequest ) ); |
19 |
use_ok( 'C4::Reserves', qw( ItemsAnyAvailableAndNotRestricted CanItemBeReserved ) ); |
20 |
} |
20 |
} |
21 |
|
21 |
|
22 |
my $schema = Koha::Database->schema; |
22 |
my $schema = Koha::Database->schema; |
Lines 35-47
my $itemtype = $builder->build(
Link Here
|
35 |
} |
35 |
} |
36 |
)->{itemtype}; |
36 |
)->{itemtype}; |
37 |
|
37 |
|
38 |
t::lib::Mocks::mock_userenv( { branchcode => $library1->{branchcode} } ); |
38 |
my $library_A = $library1->{branchcode}; |
|
|
39 |
my $library_B = $library2->{branchcode}; |
40 |
|
41 |
t::lib::Mocks::mock_userenv( { branchcode => $library_A } ); |
39 |
|
42 |
|
40 |
my $patron1 = $builder->build_object( |
43 |
my $patron1 = $builder->build_object( |
41 |
{ |
44 |
{ |
42 |
class => 'Koha::Patrons', |
45 |
class => 'Koha::Patrons', |
43 |
value => { |
46 |
value => { |
44 |
branchcode => $library1->{branchcode}, |
47 |
branchcode => $library_A, |
45 |
dateexpiry => '3000-01-01', |
48 |
dateexpiry => '3000-01-01', |
46 |
} |
49 |
} |
47 |
} |
50 |
} |
Lines 52-58
my $patron2 = $builder->build_object(
Link Here
|
52 |
{ |
55 |
{ |
53 |
class => 'Koha::Patrons', |
56 |
class => 'Koha::Patrons', |
54 |
value => { |
57 |
value => { |
55 |
branchcode => $library1->{branchcode}, |
58 |
branchcode => $library_A, |
56 |
dateexpiry => '3000-01-01', |
59 |
dateexpiry => '3000-01-01', |
57 |
} |
60 |
} |
58 |
} |
61 |
} |
Lines 62-76
my $patron3 = $builder->build_object(
Link Here
|
62 |
{ |
65 |
{ |
63 |
class => 'Koha::Patrons', |
66 |
class => 'Koha::Patrons', |
64 |
value => { |
67 |
value => { |
65 |
branchcode => $library2->{branchcode}, |
68 |
branchcode => $library_B, |
66 |
dateexpiry => '3000-01-01', |
69 |
dateexpiry => '3000-01-01', |
67 |
} |
70 |
} |
68 |
} |
71 |
} |
69 |
); |
72 |
); |
70 |
|
73 |
|
71 |
my $library_A = $library1->{branchcode}; |
|
|
72 |
my $library_B = $library2->{branchcode}; |
73 |
|
74 |
my $biblio = $builder->build_sample_biblio( { itemtype => $itemtype } ); |
74 |
my $biblio = $builder->build_sample_biblio( { itemtype => $itemtype } ); |
75 |
my $biblionumber = $biblio->biblionumber; |
75 |
my $biblionumber = $biblio->biblionumber; |
76 |
my $item1 = $builder->build_sample_item( |
76 |
my $item1 = $builder->build_sample_item( |
Lines 111-126
my $is;
Link Here
|
111 |
$is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 } ); |
111 |
$is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 } ); |
112 |
is( $is, 1, "Items availability: both of 2 items are available" ); |
112 |
is( $is, 1, "Items availability: both of 2 items are available" ); |
113 |
|
113 |
|
114 |
$is = IsAvailableForItemLevelRequest( $item1, $patron1 ); |
114 |
$is = CanItemBeReserved( $patron1, $item1 ); |
115 |
is( $is, 0, "Item cannot be held, 2 items available" ); |
115 |
is( $is->{status}, "onShelfHoldsNotAllowed", "Item cannot be held, 2 items available" ); |
116 |
|
116 |
|
117 |
my $issue1 = AddIssue( $patron2, $item1->barcode ); |
117 |
my $issue1 = AddIssue( $patron2, $item1->barcode ); |
118 |
|
118 |
|
119 |
$is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 } ); |
119 |
$is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 } ); |
120 |
is( $is, 1, "Items availability: one item is available" ); |
120 |
is( $is, 1, "Items availability: one item is available" ); |
121 |
|
121 |
|
122 |
$is = IsAvailableForItemLevelRequest( $item1, $patron1 ); |
122 |
$is = CanItemBeReserved( $patron1, $item1 ); |
123 |
is( $is, 0, "Item cannot be held, 1 item available" ); |
123 |
is( $is->{status}, "onShelfHoldsNotAllowed", "Item cannot be held, 1 item available" ); |
124 |
|
124 |
|
125 |
AddIssue( $patron2, $item2->barcode ); |
125 |
AddIssue( $patron2, $item2->barcode ); |
126 |
$cache->flush(); |
126 |
$cache->flush(); |
Lines 128-140
$cache->flush();
Link Here
|
128 |
$is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 } ); |
128 |
$is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron => $patron1 } ); |
129 |
is( $is, 0, "Items availability: none of items are available" ); |
129 |
is( $is, 0, "Items availability: none of items are available" ); |
130 |
|
130 |
|
131 |
$is = IsAvailableForItemLevelRequest( $item1, $patron1 ); |
131 |
$is = CanItemBeReserved( $patron1, $item1 ); |
132 |
is( $is, 1, "Item can be held, no items available" ); |
132 |
is( $is->{status}, "OK", "Item can be held, no items available" ); |
133 |
|
133 |
|
134 |
AddReturn( $item1->barcode ); |
134 |
AddReturn( $item1->barcode ); |
135 |
|
135 |
|
136 |
{ # Remove the issue for the first patron, and modify the branch for item1 |
136 |
{ # Remove the issue for the first patron, and modify the branch for item1 |
137 |
subtest 'IsAvailableForItemLevelRequest behaviours depending on ReservesControlBranch + holdallowed' => sub { |
137 |
subtest 'CanItemBeReserved behaviours depending on ReservesControlBranch + holdallowed' => sub { |
138 |
plan tests => 2; |
138 |
plan tests => 2; |
139 |
|
139 |
|
140 |
my $hold_allowed_from_home_library = 'from_home_library'; |
140 |
my $hold_allowed_from_home_library = 'from_home_library'; |
Lines 163-177
AddReturn( $item1->barcode );
Link Here
|
163 |
"Items availability: hold allowed from home + ReservesControlBranch=ItemHomeLibrary + one item is available at different library" |
163 |
"Items availability: hold allowed from home + ReservesControlBranch=ItemHomeLibrary + one item is available at different library" |
164 |
); |
164 |
); |
165 |
|
165 |
|
166 |
$is = IsAvailableForItemLevelRequest( $item1, $patron1 ); |
166 |
$is = CanItemBeReserved( $patron1, $item1 ); |
167 |
is( |
167 |
is( |
168 |
$is, 1, |
168 |
$is->{status}, "cannotReserveFromOtherBranches", |
169 |
"Hold allowed from home library + ReservesControlBranch=ItemHomeLibrary, " |
169 |
"Hold allowed from home library + ReservesControlBranch=ItemHomeLibrary, " |
170 |
. "One item is available at different library, not holdable = none available => the hold is allowed at item level" |
170 |
. "One item is available at different library, not holdable = none available => the hold is not allowed at item level" |
171 |
); |
171 |
); |
172 |
$is = IsAvailableForItemLevelRequest( $item1, $patron2 ); |
172 |
$is = CanItemBeReserved( $patron2, $item1 ); |
173 |
is( |
173 |
is( |
174 |
$is, 1, |
174 |
$is->{status}, "cannotReserveFromOtherBranches", |
175 |
"Hold allowed from home library + ReservesControlBranch=ItemHomeLibrary, " |
175 |
"Hold allowed from home library + ReservesControlBranch=ItemHomeLibrary, " |
176 |
. "One item is available at home library, holdable = one available => the hold is not allowed at item level" |
176 |
. "One item is available at home library, holdable = one available => the hold is not allowed at item level" |
177 |
); |
177 |
); |
Lines 187-195
AddReturn( $item1->barcode );
Link Here
|
187 |
"Items availability: hold allowed from any library for library B + ReservesControlBranch=ItemHomeLibrary + one item is available at different library" |
187 |
"Items availability: hold allowed from any library for library B + ReservesControlBranch=ItemHomeLibrary + one item is available at different library" |
188 |
); |
188 |
); |
189 |
|
189 |
|
190 |
$is = IsAvailableForItemLevelRequest( $item1, $patron1 ); |
190 |
$is = CanItemBeReserved( $patron1, $item1 ); |
191 |
is( |
191 |
is( |
192 |
$is, 0, |
192 |
$is->{status}, "onShelfHoldsNotAllowed", |
193 |
"Hold allowed from home library + ReservesControlBranch=ItemHomeLibrary, " |
193 |
"Hold allowed from home library + ReservesControlBranch=ItemHomeLibrary, " |
194 |
. "One item is available at different library, holdable = one available => the hold is not allowed at item level" |
194 |
. "One item is available at different library, holdable = one available => the hold is not allowed at item level" |
195 |
); |
195 |
); |
Lines 204-214
AddReturn( $item1->barcode );
Link Here
|
204 |
"Items availability: hold allowed from any library for library B + ReservesControlBranch=PatronLibrary + one item is available at different library" |
204 |
"Items availability: hold allowed from any library for library B + ReservesControlBranch=PatronLibrary + one item is available at different library" |
205 |
); |
205 |
); |
206 |
|
206 |
|
207 |
$is = IsAvailableForItemLevelRequest( $item1, $patron1 ); |
207 |
$is = CanItemBeReserved( $patron1, $item1 ); |
208 |
is( |
208 |
is( |
209 |
$is, 1, |
209 |
$is->{status}, "cannotReserveFromOtherBranches", |
210 |
"Hold allowed from home library + ReservesControlBranch=PatronLibrary, " |
210 |
"Hold allowed from home library + ReservesControlBranch=PatronLibrary, " |
211 |
. "One item is available at different library, not holdable = none available => the hold is allowed at item level" |
211 |
. "One item is available at different library, not holdable = none available => the hold is not allowed at item level" |
212 |
); |
212 |
); |
213 |
|
213 |
|
214 |
#Adding a rule for the patron's home library affects the availability for an item from another library because ReservesControlBranch is set to PatronLibrary |
214 |
#Adding a rule for the patron's home library affects the availability for an item from another library because ReservesControlBranch is set to PatronLibrary |
Lines 222-230
AddReturn( $item1->barcode );
Link Here
|
222 |
"Items availability: hold allowed from any library for library A + ReservesControlBranch=PatronLibrary + one item is available at different library" |
222 |
"Items availability: hold allowed from any library for library A + ReservesControlBranch=PatronLibrary + one item is available at different library" |
223 |
); |
223 |
); |
224 |
|
224 |
|
225 |
$is = IsAvailableForItemLevelRequest( $item1, $patron1 ); |
225 |
$is = CanItemBeReserved( $patron1, $item1 ); |
226 |
is( |
226 |
is( |
227 |
$is, 0, |
227 |
$is->{status}, "onShelfHoldsNotAllowed", |
228 |
"Hold allowed from home library + ReservesControlBranch=PatronLibrary, " |
228 |
"Hold allowed from home library + ReservesControlBranch=PatronLibrary, " |
229 |
. "One item is available at different library, holdable = one available => the hold is not allowed at item level" |
229 |
. "One item is available at different library, holdable = one available => the hold is not allowed at item level" |
230 |
); |
230 |
); |
Lines 243-251
AddReturn( $item1->barcode );
Link Here
|
243 |
"Items availability: hold allowed from any library + ReservesControlBranch=ItemHomeLibrary + one item is available at different library" |
243 |
"Items availability: hold allowed from any library + ReservesControlBranch=ItemHomeLibrary + one item is available at different library" |
244 |
); |
244 |
); |
245 |
|
245 |
|
246 |
$is = IsAvailableForItemLevelRequest( $item1, $patron1 ); |
246 |
$is = CanItemBeReserved( $patron1, $item1 ); |
247 |
is( |
247 |
is( |
248 |
$is, 0, |
248 |
$is->{status}, "onShelfHoldsNotAllowed", |
249 |
"Hold allowed from any library + ReservesControlBranch=ItemHomeLibrary, " |
249 |
"Hold allowed from any library + ReservesControlBranch=ItemHomeLibrary, " |
250 |
. "One item is available at the diff library, holdable = 1 available => the hold is not allowed at item level" |
250 |
. "One item is available at the diff library, holdable = 1 available => the hold is not allowed at item level" |
251 |
); |
251 |
); |
Lines 260-268
AddReturn( $item1->barcode );
Link Here
|
260 |
"Items availability: hold allowed from any library + ReservesControlBranch=PatronLibrary + one item is available at different library" |
260 |
"Items availability: hold allowed from any library + ReservesControlBranch=PatronLibrary + one item is available at different library" |
261 |
); |
261 |
); |
262 |
|
262 |
|
263 |
$is = IsAvailableForItemLevelRequest( $item1, $patron1 ); |
263 |
$is = CanItemBeReserved( $patron1, $item1 ); |
264 |
is( |
264 |
is( |
265 |
$is, 0, |
265 |
$is->{status}, "onShelfHoldsNotAllowed", |
266 |
"Hold allowed from any library + ReservesControlBranch=PatronLibrary, " |
266 |
"Hold allowed from any library + ReservesControlBranch=PatronLibrary, " |
267 |
. "One item is available at the diff library, holdable = 1 available => the hold is not allowed at item level" |
267 |
. "One item is available at the diff library, holdable = 1 available => the hold is not allowed at item level" |
268 |
); |
268 |
); |
Lines 294-302
AddReturn( $item1->barcode );
Link Here
|
294 |
"Items availability: hold allowed from home library + ReservesControlBranch=ItemHomeLibrary + one item is available at home library" |
294 |
"Items availability: hold allowed from home library + ReservesControlBranch=ItemHomeLibrary + one item is available at home library" |
295 |
); |
295 |
); |
296 |
|
296 |
|
297 |
$is = IsAvailableForItemLevelRequest( $item1, $patron1 ); |
297 |
$is = CanItemBeReserved( $patron1, $item1 ); |
298 |
is( |
298 |
is( |
299 |
$is, 0, |
299 |
$is->{status}, "onShelfHoldsNotAllowed", |
300 |
"Hold allowed from home library + ReservesControlBranch=ItemHomeLibrary, " |
300 |
"Hold allowed from home library + ReservesControlBranch=ItemHomeLibrary, " |
301 |
. "One item is available at the same library, holdable = 1 available => the hold is not allowed at item level" |
301 |
. "One item is available at the same library, holdable = 1 available => the hold is not allowed at item level" |
302 |
); |
302 |
); |
Lines 310-318
AddReturn( $item1->barcode );
Link Here
|
310 |
"Items availability: hold allowed from home library + ReservesControlBranch=PatronLibrary + one item is available at home library" |
310 |
"Items availability: hold allowed from home library + ReservesControlBranch=PatronLibrary + one item is available at home library" |
311 |
); |
311 |
); |
312 |
|
312 |
|
313 |
$is = IsAvailableForItemLevelRequest( $item1, $patron1 ); |
313 |
$is = CanItemBeReserved( $patron1, $item1 ); |
314 |
is( |
314 |
is( |
315 |
$is, 0, |
315 |
$is->{status}, "onShelfHoldsNotAllowed", |
316 |
"Hold allowed from home library + ReservesControlBranch=PatronLibrary, " |
316 |
"Hold allowed from home library + ReservesControlBranch=PatronLibrary, " |
317 |
. "One item is available at the same library, holdable = 1 available => the hold is not allowed at item level" |
317 |
. "One item is available at the same library, holdable = 1 available => the hold is not allowed at item level" |
318 |
); |
318 |
); |
Lines 330-338
AddReturn( $item1->barcode );
Link Here
|
330 |
"Items availability: hold allowed from any library + ReservesControlBranch=ItemHomeLibrary + one item is available at home library" |
330 |
"Items availability: hold allowed from any library + ReservesControlBranch=ItemHomeLibrary + one item is available at home library" |
331 |
); |
331 |
); |
332 |
|
332 |
|
333 |
$is = IsAvailableForItemLevelRequest( $item1, $patron1 ); |
333 |
$is = CanItemBeReserved( $patron1, $item1 ); |
334 |
is( |
334 |
is( |
335 |
$is, 0, |
335 |
$is->{status}, "onShelfHoldsNotAllowed", |
336 |
"Hold allowed from any library + ReservesControlBranch=ItemHomeLibrary, " |
336 |
"Hold allowed from any library + ReservesControlBranch=ItemHomeLibrary, " |
337 |
. "One item is available at the same library, holdable = 1 available => the hold is not allowed at item level" |
337 |
. "One item is available at the same library, holdable = 1 available => the hold is not allowed at item level" |
338 |
); |
338 |
); |
Lines 346-354
AddReturn( $item1->barcode );
Link Here
|
346 |
"Items availability: hold allowed from any library + ReservesControlBranch=PatronLibrary + one item is available at home library" |
346 |
"Items availability: hold allowed from any library + ReservesControlBranch=PatronLibrary + one item is available at home library" |
347 |
); |
347 |
); |
348 |
|
348 |
|
349 |
$is = IsAvailableForItemLevelRequest( $item1, $patron1 ); |
349 |
$is = CanItemBeReserved( $patron1, $item1 ); |
350 |
is( |
350 |
is( |
351 |
$is, 0, |
351 |
$is->{status}, "onShelfHoldsNotAllowed", |
352 |
"Hold allowed from any library + ReservesControlBranch=PatronLibrary, " |
352 |
"Hold allowed from any library + ReservesControlBranch=PatronLibrary, " |
353 |
. "One item is available at the same library, holdable = 1 available => the hold is not allowed at item level" |
353 |
. "One item is available at the same library, holdable = 1 available => the hold is not allowed at item level" |
354 |
); |
354 |
); |
Lines 381-388
Koha::CirculationRules->set_rules(
Link Here
|
381 |
itemtype => $itemtype2, |
381 |
itemtype => $itemtype2, |
382 |
branchcode => undef, |
382 |
branchcode => undef, |
383 |
rules => { |
383 |
rules => { |
384 |
maxissueqty => 99, |
384 |
reservesallowed => 99, |
385 |
onshelfholds => 0, |
385 |
maxissueqty => 99, |
|
|
386 |
onshelfholds => 0, |
386 |
} |
387 |
} |
387 |
} |
388 |
} |
388 |
); |
389 |
); |
Lines 391-398
$is = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblionumber, patron
Link Here
|
391 |
; # patron1 in library A, library A 1 item |
392 |
; # patron1 in library A, library A 1 item |
392 |
is( $is, 1, "Items availability: 1 item is available, 1 item held in T" ); |
393 |
is( $is, 1, "Items availability: 1 item is available, 1 item held in T" ); |
393 |
|
394 |
|
394 |
$is = IsAvailableForItemLevelRequest( $item3, $patron1 ); |
395 |
$is = CanItemBeReserved( $patron1, $item3 ); |
395 |
is( $is, 1, "Item can be held, items in transit are not available" ); |
396 |
is( $is->{status}, "OK", "Item can be held, items in transit are not available" ); |
396 |
|
397 |
|
397 |
subtest 'Check holds availability with different item types' => sub { |
398 |
subtest 'Check holds availability with different item types' => sub { |
398 |
plan tests => 6; |
399 |
plan tests => 6; |
Lines 459-469
subtest 'Check holds availability with different item types' => sub {
Link Here
|
459 |
"Items availability: 2 items, one allowed by smart rule but not checked out, another one not allowed to be held by smart rule" |
460 |
"Items availability: 2 items, one allowed by smart rule but not checked out, another one not allowed to be held by smart rule" |
460 |
); |
461 |
); |
461 |
|
462 |
|
462 |
$is = IsAvailableForItemLevelRequest( $item4, $patron1 ); |
463 |
$is = CanItemBeReserved( $patron1, $item4 ); |
463 |
is( $is, 0, "Item4 cannot be requested to hold: 2 items, Item4 available, Item5 restricted" ); |
464 |
is( |
|
|
465 |
$is->{status}, "onShelfHoldsNotAllowed", |
466 |
"Item4 cannot be requested to hold: 2 items, Item4 available, Item5 restricted" |
467 |
); |
464 |
|
468 |
|
465 |
$is = IsAvailableForItemLevelRequest( $item5, $patron1 ); |
469 |
$is = CanItemBeReserved( $patron1, $item5 ); |
466 |
is( $is, 0, "Item5 cannot be requested to hold: 2 items, Item4 available, Item5 restricted" ); |
470 |
is( |
|
|
471 |
$is->{status}, "noReservesAllowed", |
472 |
"Item5 cannot be requested to hold: 2 items, Item4 available, Item5 restricted" |
473 |
); |
467 |
|
474 |
|
468 |
AddIssue( $patron2, $item4->barcode ); |
475 |
AddIssue( $patron2, $item4->barcode ); |
469 |
$cache->flush(); |
476 |
$cache->flush(); |
Lines 474-486
subtest 'Check holds availability with different item types' => sub {
Link Here
|
474 |
"Items availability: 2 items, one allowed by smart rule and checked out, another one not allowed to be held by smart rule" |
481 |
"Items availability: 2 items, one allowed by smart rule and checked out, another one not allowed to be held by smart rule" |
475 |
); |
482 |
); |
476 |
|
483 |
|
477 |
$is = IsAvailableForItemLevelRequest( $item4, $patron1 ); |
484 |
$is = CanItemBeReserved( $patron1, $item4 ); |
478 |
is( $is, 1, "Item4 can be requested to hold, 2 items, Item4 checked out, Item5 restricted" ); |
485 |
is( $is->{status}, "OK", "Item4 can be requested to hold, 2 items, Item4 checked out, Item5 restricted" ); |
479 |
|
486 |
|
480 |
$is = IsAvailableForItemLevelRequest( $item5, $patron1 ); |
487 |
$is = CanItemBeReserved( $patron1, $item5 ); |
481 |
|
488 |
is( |
482 |
# Note: read IsAvailableForItemLevelRequest sub description about CanItemBeReserved/CanBookBeReserved: |
489 |
$is->{status}, "noReservesAllowed", |
483 |
is( $is, 1, "Item5 can be requested to hold, 2 items, Item4 checked out, Item5 restricted" ); |
490 |
"Item5 can be requested to hold, 2 items, Item4 checked out, Item5 restricted" |
|
|
491 |
); |
484 |
}; |
492 |
}; |
485 |
|
493 |
|
486 |
subtest 'Check item checkout availability with ordered item' => sub { |
494 |
subtest 'Check item checkout availability with ordered item' => sub { |
Lines 549-556
subtest 'Check item availability for hold with ordered item' => sub {
Link Here
|
549 |
); |
557 |
); |
550 |
|
558 |
|
551 |
$cache->flush(); |
559 |
$cache->flush(); |
552 |
$is = IsAvailableForItemLevelRequest( $item1, $patron1 ); |
560 |
$is = CanItemBeReserved( $patron1, $item1 ); |
553 |
is( $is, 1, "Ordered items are available for hold" ); |
561 |
is( $is->{status}, "OK", "Ordered items are available for hold" ); |
554 |
}; |
562 |
}; |
555 |
|
563 |
|
556 |
# Cleanup |
564 |
# Cleanup |