|
Lines 8-14
Link Here
|
| 8 |
|
8 |
|
| 9 |
use Modern::Perl; |
9 |
use Modern::Perl; |
| 10 |
|
10 |
|
| 11 |
use Test::More tests => 58; |
11 |
use Test::More tests => 59; |
| 12 |
use Data::Dumper; |
12 |
use Data::Dumper; |
| 13 |
|
13 |
|
| 14 |
use C4::Calendar qw( new insert_single_holiday ); |
14 |
use C4::Calendar qw( new insert_single_holiday ); |
|
Lines 43-54
t::lib::Mocks::mock_preference( 'BranchTransferLimitsType', 'itemtype' );
Link Here
|
| 43 |
|
43 |
|
| 44 |
my $library1 = $builder->build({ |
44 |
my $library1 = $builder->build({ |
| 45 |
source => 'Branch', |
45 |
source => 'Branch', |
|
|
46 |
value => { pickup_location => 1 } |
| 46 |
}); |
47 |
}); |
| 47 |
my $library2 = $builder->build({ |
48 |
my $library2 = $builder->build({ |
| 48 |
source => 'Branch', |
49 |
source => 'Branch', |
|
|
50 |
value => { pickup_location => 1 } |
| 49 |
}); |
51 |
}); |
| 50 |
my $library3 = $builder->build({ |
52 |
my $library3 = $builder->build({ |
| 51 |
source => 'Branch', |
53 |
source => 'Branch', |
|
|
54 |
value => { pickup_location => 1 } |
| 52 |
}); |
55 |
}); |
| 53 |
|
56 |
|
| 54 |
my $TITLE = "Test Holds Queue XXX"; |
57 |
my $TITLE = "Test Holds Queue XXX"; |
|
Lines 114-119
foreach ( $borrower_branchcode, $least_cost_branch_code, @other_branches ) {
Link Here
|
| 114 |
$dbh->do("DELETE FROM reserves"); |
117 |
$dbh->do("DELETE FROM reserves"); |
| 115 |
my $bibitems = undef; |
118 |
my $bibitems = undef; |
| 116 |
my $priority = 1; |
119 |
my $priority = 1; |
|
|
120 |
|
| 121 |
# Set circulation rule |
| 122 |
Koha::CirculationRules->set_rules( |
| 123 |
{ |
| 124 |
categorycode => undef, |
| 125 |
branchcode => undef, |
| 126 |
itemtype => undef, |
| 127 |
rules => { |
| 128 |
reservesallowed => 25, |
| 129 |
holds_per_record => 99, |
| 130 |
} |
| 131 |
} |
| 132 |
); |
| 133 |
|
| 134 |
|
| 117 |
# Make a reserve |
135 |
# Make a reserve |
| 118 |
AddReserve( |
136 |
AddReserve( |
| 119 |
{ |
137 |
{ |
|
Lines 193-204
$itemtype = $builder->build({ source => 'Itemtype', value => { notforloan => 0 }
Link Here
|
| 193 |
|
211 |
|
| 194 |
$library1 = $builder->build({ |
212 |
$library1 = $builder->build({ |
| 195 |
source => 'Branch', |
213 |
source => 'Branch', |
|
|
214 |
value => { pickup_location => 1 } |
| 196 |
}); |
215 |
}); |
| 197 |
$library2 = $builder->build({ |
216 |
$library2 = $builder->build({ |
| 198 |
source => 'Branch', |
217 |
source => 'Branch', |
|
|
218 |
value => { pickup_location => 1 } |
| 199 |
}); |
219 |
}); |
| 200 |
$library3 = $builder->build({ |
220 |
$library3 = $builder->build({ |
| 201 |
source => 'Branch', |
221 |
source => 'Branch', |
|
|
222 |
value => { pickup_location => 1 } |
| 202 |
}); |
223 |
}); |
| 203 |
@branchcodes = ( $library1->{branchcode}, $library2->{branchcode}, $library3->{branchcode} ); |
224 |
@branchcodes = ( $library1->{branchcode}, $library2->{branchcode}, $library3->{branchcode} ); |
| 204 |
|
225 |
|
|
Lines 314-319
Koha::CirculationRules->set_rule(
Link Here
|
| 314 |
itemtype => undef, |
335 |
itemtype => undef, |
| 315 |
} |
336 |
} |
| 316 |
); |
337 |
); |
|
|
338 |
Koha::CirculationRules->set_rules( |
| 339 |
{ |
| 340 |
branchcode => undef, |
| 341 |
itemtype => undef, |
| 342 |
categorycode => undef, |
| 343 |
rules => { |
| 344 |
reservesallowed => 25, |
| 345 |
holds_per_record => 99 |
| 346 |
|
| 347 |
} |
| 348 |
} |
| 349 |
); |
| 317 |
C4::HoldsQueue::CreateQueue(); |
350 |
C4::HoldsQueue::CreateQueue(); |
| 318 |
$holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice => {} }); |
351 |
$holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice => {} }); |
| 319 |
is( @$holds_queue, 2, "Holds queue filling correct number for default holds policy 'from home library'" ); |
352 |
is( @$holds_queue, 2, "Holds queue filling correct number for default holds policy 'from home library'" ); |
|
Lines 351-356
Koha::CirculationRules->set_rule(
Link Here
|
| 351 |
itemtype => undef, |
384 |
itemtype => undef, |
| 352 |
} |
385 |
} |
| 353 |
); |
386 |
); |
|
|
387 |
Koha::CirculationRules->set_rules( |
| 388 |
{ |
| 389 |
categorycode => undef, |
| 390 |
branchcode => undef, |
| 391 |
itemtype => undef, |
| 392 |
rules => { |
| 393 |
reservesallowed => 25, |
| 394 |
holds_per_record => 99, |
| 395 |
} |
| 396 |
} |
| 397 |
); |
| 398 |
|
| 354 |
C4::HoldsQueue::CreateQueue(); |
399 |
C4::HoldsQueue::CreateQueue(); |
| 355 |
$holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice => {} }); |
400 |
$holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice => {} }); |
| 356 |
is( @$holds_queue, 3, "Holds queue filling correct number for holds for default holds policy 'from any library'" ); |
401 |
is( @$holds_queue, 3, "Holds queue filling correct number for holds for default holds policy 'from any library'" ); |
|
Lines 370-376
t::lib::Mocks::mock_preference( 'HoldsQueueSkipClosed', 0 );
Link Here
|
| 370 |
t::lib::Mocks::mock_preference('LocalHoldsPriority', 1); |
415 |
t::lib::Mocks::mock_preference('LocalHoldsPriority', 1); |
| 371 |
|
416 |
|
| 372 |
$dbh->do("DELETE FROM circulation_rules"); |
417 |
$dbh->do("DELETE FROM circulation_rules"); |
| 373 |
Koha::CirculationRules->set_rule( |
418 |
Koha::CirculationRules->set_rules( |
| 374 |
{ |
419 |
{ |
| 375 |
rule_name => 'holdallowed', |
420 |
rule_name => 'holdallowed', |
| 376 |
rule_value => 'from_any_library', |
421 |
rule_value => 'from_any_library', |
|
Lines 378-383
Koha::CirculationRules->set_rule(
Link Here
|
| 378 |
itemtype => undef, |
423 |
itemtype => undef, |
| 379 |
} |
424 |
} |
| 380 |
); |
425 |
); |
|
|
426 |
Koha::CirculationRules->set_rules( |
| 427 |
{ |
| 428 |
categorycode => undef, |
| 429 |
branchcode => undef, |
| 430 |
itemtype => undef, |
| 431 |
rules => { |
| 432 |
reservesallowed => 25, |
| 433 |
holds_per_record => 99, |
| 434 |
} |
| 435 |
} |
| 436 |
); |
| 437 |
|
| 381 |
$dbh->do("DELETE FROM issues"); |
438 |
$dbh->do("DELETE FROM issues"); |
| 382 |
|
439 |
|
| 383 |
# Test homebranch = patron branch |
440 |
# Test homebranch = patron branch |
|
Lines 656-661
Koha::CirculationRules->set_rules(
Link Here
|
| 656 |
} |
713 |
} |
| 657 |
} |
714 |
} |
| 658 |
); |
715 |
); |
|
|
716 |
Koha::CirculationRules->set_rules( |
| 717 |
{ |
| 718 |
branchcode => undef, |
| 719 |
itemtype => undef, |
| 720 |
categorycode => undef, |
| 721 |
rules => { |
| 722 |
reservesallowed => 25, |
| 723 |
holds_per_record => 99 |
| 724 |
|
| 725 |
} |
| 726 |
} |
| 727 |
); |
| 659 |
|
728 |
|
| 660 |
# Home branch matches pickup branch |
729 |
# Home branch matches pickup branch |
| 661 |
$reserve_id = AddReserve( |
730 |
$reserve_id = AddReserve( |
|
Lines 717-722
Koha::CirculationRules->set_rules(
Link Here
|
| 717 |
} |
786 |
} |
| 718 |
} |
787 |
} |
| 719 |
); |
788 |
); |
|
|
789 |
Koha::CirculationRules->set_rules( |
| 790 |
{ |
| 791 |
categorycode => undef, |
| 792 |
branchcode => undef, |
| 793 |
itemtype => undef, |
| 794 |
rules => { |
| 795 |
reservesallowed => 25, |
| 796 |
holds_per_record => 99, |
| 797 |
} |
| 798 |
} |
| 799 |
); |
| 720 |
|
800 |
|
| 721 |
# Home branch matches pickup branch |
801 |
# Home branch matches pickup branch |
| 722 |
$reserve_id = AddReserve( |
802 |
$reserve_id = AddReserve( |
|
Lines 775-780
Koha::CirculationRules->set_rules(
Link Here
|
| 775 |
} |
855 |
} |
| 776 |
} |
856 |
} |
| 777 |
); |
857 |
); |
|
|
858 |
Koha::CirculationRules->set_rules( |
| 859 |
{ |
| 860 |
categorycode => undef, |
| 861 |
branchcode => undef, |
| 862 |
itemtype => undef, |
| 863 |
rules => { |
| 864 |
reservesallowed => 25, |
| 865 |
holds_per_record => 99, |
| 866 |
} |
| 867 |
} |
| 868 |
); |
| 778 |
|
869 |
|
| 779 |
# Home branch matches pickup branch |
870 |
# Home branch matches pickup branch |
| 780 |
$reserve_id = AddReserve( |
871 |
$reserve_id = AddReserve( |
|
Lines 866-871
Koha::CirculationRules->set_rules(
Link Here
|
| 866 |
} |
957 |
} |
| 867 |
} |
958 |
} |
| 868 |
); |
959 |
); |
|
|
960 |
Koha::CirculationRules->set_rules( |
| 961 |
{ |
| 962 |
categorycode => undef, |
| 963 |
branchcode => undef, |
| 964 |
itemtype => undef, |
| 965 |
rules => { |
| 966 |
reservesallowed => 25, |
| 967 |
holds_per_record => 99, |
| 968 |
} |
| 969 |
} |
| 970 |
); |
| 869 |
|
971 |
|
| 870 |
# Home branch matches pickup branch |
972 |
# Home branch matches pickup branch |
| 871 |
$reserve_id = AddReserve( |
973 |
$reserve_id = AddReserve( |
|
Lines 924-931
subtest "Test Local Holds Priority - Bib level" => sub {
Link Here
|
| 924 |
t::lib::Mocks::mock_preference( 'LocalHoldsPriority', 1 ); |
1026 |
t::lib::Mocks::mock_preference( 'LocalHoldsPriority', 1 ); |
| 925 |
t::lib::Mocks::mock_preference( 'LocalHoldsPriorityPatronControl', 'PickupLibrary' ); |
1027 |
t::lib::Mocks::mock_preference( 'LocalHoldsPriorityPatronControl', 'PickupLibrary' ); |
| 926 |
t::lib::Mocks::mock_preference( 'LocalHoldsPriorityItemControl', 'homebranch' ); |
1028 |
t::lib::Mocks::mock_preference( 'LocalHoldsPriorityItemControl', 'homebranch' ); |
| 927 |
my $branch = $builder->build_object( { class => 'Koha::Libraries' } ); |
1029 |
my $branch = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } ); |
| 928 |
my $branch2 = $builder->build_object( { class => 'Koha::Libraries' } ); |
1030 |
my $branch2 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } ); |
| 929 |
my $category = $builder->build_object( { class => 'Koha::Patron::Categories', value => {exclude_from_local_holds_priority => 0} }); |
1031 |
my $category = $builder->build_object( { class => 'Koha::Patron::Categories', value => {exclude_from_local_holds_priority => 0} }); |
| 930 |
my $local_patron = $builder->build_object( |
1032 |
my $local_patron = $builder->build_object( |
| 931 |
{ |
1033 |
{ |
|
Lines 992-999
subtest "Test Local Holds Priority - Item level" => sub {
Link Here
|
| 992 |
t::lib::Mocks::mock_preference( 'LocalHoldsPriority', 1 ); |
1094 |
t::lib::Mocks::mock_preference( 'LocalHoldsPriority', 1 ); |
| 993 |
t::lib::Mocks::mock_preference( 'LocalHoldsPriorityPatronControl', 'PickupLibrary' ); |
1095 |
t::lib::Mocks::mock_preference( 'LocalHoldsPriorityPatronControl', 'PickupLibrary' ); |
| 994 |
t::lib::Mocks::mock_preference( 'LocalHoldsPriorityItemControl', 'homebranch' ); |
1096 |
t::lib::Mocks::mock_preference( 'LocalHoldsPriorityItemControl', 'homebranch' ); |
| 995 |
my $branch = $builder->build_object( { class => 'Koha::Libraries' } ); |
1097 |
my $branch = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } ); |
| 996 |
my $branch2 = $builder->build_object( { class => 'Koha::Libraries' } ); |
1098 |
my $branch2 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } ); |
| 997 |
my $category = $builder->build_object( { class => 'Koha::Patron::Categories', value => {exclude_from_local_holds_priority => 0} }); |
1099 |
my $category = $builder->build_object( { class => 'Koha::Patron::Categories', value => {exclude_from_local_holds_priority => 0} }); |
| 998 |
my $local_patron = $builder->build_object( |
1100 |
my $local_patron = $builder->build_object( |
| 999 |
{ |
1101 |
{ |
|
Lines 1061-1068
subtest "Test Local Holds Priority - Item level hold over Record level hold (Bug
Link Here
|
| 1061 |
t::lib::Mocks::mock_preference( 'LocalHoldsPriority', 1 ); |
1163 |
t::lib::Mocks::mock_preference( 'LocalHoldsPriority', 1 ); |
| 1062 |
t::lib::Mocks::mock_preference( 'LocalHoldsPriorityPatronControl', 'PickupLibrary' ); |
1164 |
t::lib::Mocks::mock_preference( 'LocalHoldsPriorityPatronControl', 'PickupLibrary' ); |
| 1063 |
t::lib::Mocks::mock_preference( 'LocalHoldsPriorityItemControl', 'homebranch' ); |
1165 |
t::lib::Mocks::mock_preference( 'LocalHoldsPriorityItemControl', 'homebranch' ); |
| 1064 |
my $branch = $builder->build_object( { class => 'Koha::Libraries' } ); |
1166 |
my $branch = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } ); |
| 1065 |
my $branch2 = $builder->build_object( { class => 'Koha::Libraries' } ); |
1167 |
my $branch2 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } ); |
| 1066 |
my $category = $builder->build_object( { class => 'Koha::Patron::Categories', value => {exclude_from_local_holds_priority => 0} }); |
1168 |
my $category = $builder->build_object( { class => 'Koha::Patron::Categories', value => {exclude_from_local_holds_priority => 0} }); |
| 1067 |
my $local_patron = $builder->build_object( |
1169 |
my $local_patron = $builder->build_object( |
| 1068 |
{ |
1170 |
{ |
|
Lines 1129-1136
subtest "Test Local Holds Priority - Get correct item for item level hold" => su
Link Here
|
| 1129 |
t::lib::Mocks::mock_preference( 'LocalHoldsPriority', 1 ); |
1231 |
t::lib::Mocks::mock_preference( 'LocalHoldsPriority', 1 ); |
| 1130 |
t::lib::Mocks::mock_preference( 'LocalHoldsPriorityPatronControl', 'PickupLibrary' ); |
1232 |
t::lib::Mocks::mock_preference( 'LocalHoldsPriorityPatronControl', 'PickupLibrary' ); |
| 1131 |
t::lib::Mocks::mock_preference( 'LocalHoldsPriorityItemControl', 'homebranch' ); |
1233 |
t::lib::Mocks::mock_preference( 'LocalHoldsPriorityItemControl', 'homebranch' ); |
| 1132 |
my $branch = $builder->build_object( { class => 'Koha::Libraries' } ); |
1234 |
my $branch = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } ); |
| 1133 |
my $branch2 = $builder->build_object( { class => 'Koha::Libraries' } ); |
1235 |
my $branch2 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } ); |
| 1134 |
my $category = $builder->build_object( { class => 'Koha::Patron::Categories', value => {exclude_from_local_holds_priority => 0} }); |
1236 |
my $category = $builder->build_object( { class => 'Koha::Patron::Categories', value => {exclude_from_local_holds_priority => 0} }); |
| 1135 |
my $local_patron = $builder->build_object( |
1237 |
my $local_patron = $builder->build_object( |
| 1136 |
{ |
1238 |
{ |
|
Lines 1209-1219
subtest "Test Local Holds Priority - Ensure no duplicate requests in holds queue
Link Here
|
| 1209 |
$dbh->do("DELETE FROM circulation_rules"); |
1311 |
$dbh->do("DELETE FROM circulation_rules"); |
| 1210 |
Koha::Biblios->delete(); |
1312 |
Koha::Biblios->delete(); |
| 1211 |
|
1313 |
|
|
|
1314 |
Koha::CirculationRules->set_rules( |
| 1315 |
{ |
| 1316 |
categorycode => undef, |
| 1317 |
branchcode => undef, |
| 1318 |
itemtype => undef, |
| 1319 |
rules => { |
| 1320 |
reservesallowed => 25, |
| 1321 |
holds_per_record => 99, |
| 1322 |
} |
| 1323 |
} |
| 1324 |
); |
| 1325 |
|
| 1212 |
t::lib::Mocks::mock_preference( 'LocalHoldsPriority', 1 ); |
1326 |
t::lib::Mocks::mock_preference( 'LocalHoldsPriority', 1 ); |
| 1213 |
t::lib::Mocks::mock_preference( 'LocalHoldsPriorityPatronControl', 'PickupLibrary' ); |
1327 |
t::lib::Mocks::mock_preference( 'LocalHoldsPriorityPatronControl', 'PickupLibrary' ); |
| 1214 |
t::lib::Mocks::mock_preference( 'LocalHoldsPriorityItemControl', 'homebranch' ); |
1328 |
t::lib::Mocks::mock_preference( 'LocalHoldsPriorityItemControl', 'homebranch' ); |
| 1215 |
my $branch = $builder->build_object( { class => 'Koha::Libraries' } ); |
1329 |
my $branch = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } ); |
| 1216 |
my $branch2 = $builder->build_object( { class => 'Koha::Libraries' } ); |
1330 |
my $branch2 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } ); |
| 1217 |
my $category = $builder->build_object( { class => 'Koha::Patron::Categories', value => {exclude_from_local_holds_priority => 0} }); |
1331 |
my $category = $builder->build_object( { class => 'Koha::Patron::Categories', value => {exclude_from_local_holds_priority => 0} }); |
| 1218 |
my $patron = $builder->build_object( |
1332 |
my $patron = $builder->build_object( |
| 1219 |
{ |
1333 |
{ |
|
Lines 1275-1281
subtest "Item level holds info is preserved (Bug 25738)" => sub {
Link Here
|
| 1275 |
$dbh->do("DELETE FROM reserves"); |
1389 |
$dbh->do("DELETE FROM reserves"); |
| 1276 |
$dbh->do("DELETE FROM circulation_rules"); |
1390 |
$dbh->do("DELETE FROM circulation_rules"); |
| 1277 |
|
1391 |
|
| 1278 |
my $library = $builder->build_object({ class => 'Koha::Libraries' }); |
1392 |
Koha::CirculationRules->set_rules( |
|
|
1393 |
{ |
| 1394 |
categorycode => undef, |
| 1395 |
branchcode => undef, |
| 1396 |
itemtype => undef, |
| 1397 |
rules => { |
| 1398 |
reservesallowed => 25, |
| 1399 |
holds_per_record => 99, |
| 1400 |
} |
| 1401 |
} |
| 1402 |
); |
| 1403 |
|
| 1404 |
|
| 1405 |
|
| 1406 |
my $library = $builder->build_object({ class => 'Koha::Libraries', value => { pickup_location => 1 } }); |
| 1279 |
my $category = $builder->build_object( { class => 'Koha::Patron::Categories', value => {exclude_from_local_holds_priority => 0} }); |
1407 |
my $category = $builder->build_object( { class => 'Koha::Patron::Categories', value => {exclude_from_local_holds_priority => 0} }); |
| 1280 |
my $patron_1 = $builder->build_object( |
1408 |
my $patron_1 = $builder->build_object( |
| 1281 |
{ |
1409 |
{ |
|
Lines 1368-1375
subtest 'Excludes from local holds priority' => sub {
Link Here
|
| 1368 |
t::lib::Mocks::mock_preference( 'LocalHoldsPriorityPatronControl', 'PickupLibrary' ); |
1496 |
t::lib::Mocks::mock_preference( 'LocalHoldsPriorityPatronControl', 'PickupLibrary' ); |
| 1369 |
t::lib::Mocks::mock_preference( 'LocalHoldsPriorityItemControl', 'homebranch' ); |
1497 |
t::lib::Mocks::mock_preference( 'LocalHoldsPriorityItemControl', 'homebranch' ); |
| 1370 |
|
1498 |
|
| 1371 |
my $branch = $builder->build_object( { class => 'Koha::Libraries' } ); |
1499 |
my $branch = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } ); |
| 1372 |
my $branch2 = $builder->build_object( { class => 'Koha::Libraries' } ); |
1500 |
my $branch2 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } ); |
| 1373 |
my $category = $builder->build_object( { class => 'Koha::Patron::Categories', value => {exclude_from_local_holds_priority => 0} }); |
1501 |
my $category = $builder->build_object( { class => 'Koha::Patron::Categories', value => {exclude_from_local_holds_priority => 0} }); |
| 1374 |
my $excluded_category = $builder->build_object( { class => 'Koha::Patron::Categories', value => {exclude_from_local_holds_priority => 1} }); |
1502 |
my $excluded_category = $builder->build_object( { class => 'Koha::Patron::Categories', value => {exclude_from_local_holds_priority => 1} }); |
| 1375 |
my $local_patron_excluded = $builder->build_object( |
1503 |
my $local_patron_excluded = $builder->build_object( |
|
Lines 1659-1664
subtest "Test _checkHoldPolicy" => sub {
Link Here
|
| 1659 |
$schema->storage->txn_rollback; |
1787 |
$schema->storage->txn_rollback; |
| 1660 |
}; |
1788 |
}; |
| 1661 |
|
1789 |
|
|
|
1790 |
subtest "Test _checkCirculationRules" => sub { |
| 1791 |
|
| 1792 |
plan tests => 7; |
| 1793 |
|
| 1794 |
$schema->storage->txn_begin; |
| 1795 |
|
| 1796 |
# Create objects |
| 1797 |
my $library = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } ); |
| 1798 |
my $category_1 = $builder->build_object( { class => 'Koha::Patron::Categories' }); |
| 1799 |
my $category_2 = $builder->build_object( { class => 'Koha::Patron::Categories' }); |
| 1800 |
my $itype_1 = $builder->build_object( { class => 'Koha::ItemTypes' }); |
| 1801 |
my $itype_2 = $builder->build_object( { class => 'Koha::ItemTypes' }); |
| 1802 |
my $patron_1 = $builder->build_object( |
| 1803 |
{ |
| 1804 |
class => "Koha::Patrons", |
| 1805 |
value => { |
| 1806 |
branchcode => $library->branchcode, |
| 1807 |
categorycode => $category_1->categorycode, |
| 1808 |
} |
| 1809 |
} |
| 1810 |
); |
| 1811 |
my $patron_2 = $builder->build_object( |
| 1812 |
{ |
| 1813 |
class => "Koha::Patrons", |
| 1814 |
value => { |
| 1815 |
branchcode => $library->branchcode, |
| 1816 |
categorycode => $category_2->categorycode, |
| 1817 |
} |
| 1818 |
} |
| 1819 |
); |
| 1820 |
my $biblio = $builder->build_sample_biblio(); |
| 1821 |
my $item_1 = $builder->build_sample_item( |
| 1822 |
{ |
| 1823 |
biblionumber => $biblio->biblionumber, |
| 1824 |
library => $library->branchcode, |
| 1825 |
itype => $itype_1->itemtype |
| 1826 |
} |
| 1827 |
); |
| 1828 |
my $item_2 = $builder->build_sample_item( |
| 1829 |
{ |
| 1830 |
biblionumber => $biblio->biblionumber, |
| 1831 |
library => $library->branchcode, |
| 1832 |
itype => $itype_2->itemtype |
| 1833 |
} |
| 1834 |
); |
| 1835 |
|
| 1836 |
# Add reserves |
| 1837 |
# Title-level reserve for patron_1 |
| 1838 |
my $reserve_id_1 = AddReserve( |
| 1839 |
{ |
| 1840 |
branchcode => $item_1->homebranch, |
| 1841 |
borrowernumber => $patron_1->borrowernumber, |
| 1842 |
biblionumber => $biblio->id, |
| 1843 |
priority => 1 |
| 1844 |
} |
| 1845 |
); |
| 1846 |
# Title-level reserve for patron_2 |
| 1847 |
my $reserve_id_2 = AddReserve( |
| 1848 |
{ |
| 1849 |
branchcode => $item_2->homebranch, |
| 1850 |
borrowernumber => $patron_2->borrowernumber, |
| 1851 |
biblionumber => $biblio->id, |
| 1852 |
priority => 2 |
| 1853 |
} |
| 1854 |
); |
| 1855 |
|
| 1856 |
# Set 3 circulation rules |
| 1857 |
# The category for patron_1 cannot reserve item type 1 |
| 1858 |
Koha::CirculationRules->set_rules( |
| 1859 |
{ |
| 1860 |
categorycode => $category_1->categorycode, |
| 1861 |
branchcode => undef, |
| 1862 |
itemtype => $itype_1->itemtype, |
| 1863 |
rules => { |
| 1864 |
reservesallowed => 0, |
| 1865 |
holds_per_record => 0, |
| 1866 |
} |
| 1867 |
} |
| 1868 |
); |
| 1869 |
# The category for patron_2 can reserve item type 1 |
| 1870 |
Koha::CirculationRules->set_rules( |
| 1871 |
{ |
| 1872 |
categorycode => $category_2->categorycode, |
| 1873 |
branchcode => undef, |
| 1874 |
itemtype => $itype_1->itemtype, |
| 1875 |
rules => { |
| 1876 |
reservesallowed => 25, |
| 1877 |
holds_per_record => 99, |
| 1878 |
} |
| 1879 |
} |
| 1880 |
); |
| 1881 |
# All patron categories can reserve item type 2 |
| 1882 |
Koha::CirculationRules->set_rules( |
| 1883 |
{ |
| 1884 |
categorycode => undef, |
| 1885 |
branchcode => undef, |
| 1886 |
itemtype => $itype_2->itemtype, |
| 1887 |
rules => { |
| 1888 |
reservesallowed => 25, |
| 1889 |
holds_per_record => 99, |
| 1890 |
} |
| 1891 |
} |
| 1892 |
); |
| 1893 |
|
| 1894 |
# Get pending holds |
| 1895 |
my $requests = C4::HoldsQueue::GetPendingHoldRequestsForBib($biblio->biblionumber); |
| 1896 |
is( @$requests, 2, "Got correct number of holds"); |
| 1897 |
is( $requests->[0]->{borrowernumber}, $patron_1->id, "First hold has correct borrower"); |
| 1898 |
is( $requests->[1]->{borrowernumber}, $patron_2->id, "Second hold has correct borrower"); |
| 1899 |
|
| 1900 |
# Loop through the available items |
| 1901 |
# Check the circulation rules for each pending title-level reserve against the available |
| 1902 |
# item type. To determine if the reserving patron category is allowed to reserve the item |
| 1903 |
my $available_items = C4::HoldsQueue::GetItemsAvailableToFillHoldRequestsForBib($biblio->id); |
| 1904 |
foreach my $item ( @$available_items ) { |
| 1905 |
if ( $item->{itemnumber} == $item_1->itemnumber ) { |
| 1906 |
# Check item_1 against both title-level reserves |
| 1907 |
is( C4::HoldsQueue::_checkCirculationRules( $item, $requests->[0] ), 0, "_checkCirculationRule returns false - item_1 should not be mapped to patron_1 title-level reserve" ); |
| 1908 |
is( C4::HoldsQueue::_checkCirculationRules( $item, $requests->[1] ), 1, "_checkCirculationRule returns true - item_1 should be mapped to patron_2 title-level reserve" ); |
| 1909 |
} elsif ( $item->{itemnumber} == $item_2->itemnumber ) { |
| 1910 |
# Check item_2 against both title-level reserves |
| 1911 |
is( C4::HoldsQueue::_checkCirculationRules( $item, $requests->[0] ), 1, "_checkCirculationRule returns true - item_2 should be mapped to patron_1 title level reserve" ); |
| 1912 |
is( C4::HoldsQueue::_checkCirculationRules( $item, $requests->[1] ), 1, "_checkCirculationRule returns true - item_2 should be mapped to patron_2 title-level reserve" ); |
| 1913 |
} |
| 1914 |
} |
| 1915 |
$schema->storage->txn_rollback; |
| 1916 |
}; |
| 1917 |
|
| 1662 |
sub dump_records { |
1918 |
sub dump_records { |
| 1663 |
my ($tablename) = @_; |
1919 |
my ($tablename) = @_; |
| 1664 |
return $dbh->selectall_arrayref("SELECT * from $tablename where borrowernumber = ?", { Slice => {} }, $borrowernumber); |
1920 |
return $dbh->selectall_arrayref("SELECT * from $tablename where borrowernumber = ?", { Slice => {} }, $borrowernumber); |
|
Lines 1670-1676
subtest 'Remove holds on check-in match' => sub {
Link Here
|
| 1670 |
|
1926 |
|
| 1671 |
$schema->storage->txn_begin; |
1927 |
$schema->storage->txn_begin; |
| 1672 |
|
1928 |
|
| 1673 |
my $lib = $builder->build_object( { class => 'Koha::Libraries' } ); |
1929 |
my $lib = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } ); |
| 1674 |
|
1930 |
|
| 1675 |
my $patron1 = $builder->build_object( |
1931 |
my $patron1 = $builder->build_object( |
| 1676 |
{ |
1932 |
{ |
|
Lines 1685-1690
subtest 'Remove holds on check-in match' => sub {
Link Here
|
| 1685 |
} |
1941 |
} |
| 1686 |
); |
1942 |
); |
| 1687 |
|
1943 |
|
|
|
1944 |
Koha::CirculationRules->set_rules( |
| 1945 |
{ |
| 1946 |
categorycode => undef, |
| 1947 |
branchcode => undef, |
| 1948 |
itemtype => undef, |
| 1949 |
rules => { |
| 1950 |
reservesallowed => 25, |
| 1951 |
holds_per_record => 99, |
| 1952 |
} |
| 1953 |
} |
| 1954 |
); |
| 1955 |
|
| 1688 |
my $item = $builder->build_sample_item( |
1956 |
my $item = $builder->build_sample_item( |
| 1689 |
{ homebranch => $lib->branchcode, holdingbranch => $lib->branchcode } ); |
1957 |
{ homebranch => $lib->branchcode, holdingbranch => $lib->branchcode } ); |
| 1690 |
|
1958 |
|
| 1691 |
- |
|
|