|
Lines 21-42
use Test::More tests => 72;
Link Here
|
| 21 |
use Test::MockModule; |
21 |
use Test::MockModule; |
| 22 |
use Test::Warn; |
22 |
use Test::Warn; |
| 23 |
|
23 |
|
|
|
24 |
use t::lib::Mocks; |
| 25 |
use t::lib::TestBuilder; |
| 26 |
|
| 24 |
use MARC::Record; |
27 |
use MARC::Record; |
| 25 |
use DateTime::Duration; |
28 |
use DateTime::Duration; |
| 26 |
|
29 |
|
| 27 |
use C4::Biblio; |
30 |
use C4::Biblio; |
| 28 |
use C4::Reserves; |
31 |
use C4::Circulation; |
| 29 |
use C4::Items; |
32 |
use C4::Items; |
| 30 |
use C4::Members; |
33 |
use C4::Members; |
| 31 |
use C4::Circulation; |
34 |
use C4::Reserves; |
| 32 |
use Koha::Holds; |
|
|
| 33 |
use t::lib::Mocks; |
| 34 |
|
| 35 |
use Koha::DateUtils; |
35 |
use Koha::DateUtils; |
|
|
36 |
use Koha::Holds; |
| 36 |
use Koha::Libraries; |
37 |
use Koha::Libraries; |
| 37 |
use Koha::Patron::Categories; |
38 |
use Koha::Patron::Categories; |
| 38 |
|
39 |
|
| 39 |
use Data::Dumper; |
|
|
| 40 |
BEGIN { |
40 |
BEGIN { |
| 41 |
require_ok('C4::Reserves'); |
41 |
require_ok('C4::Reserves'); |
| 42 |
} |
42 |
} |
|
Lines 54-73
my $database = Koha::Database->new();
Link Here
|
| 54 |
my $schema = $database->schema(); |
54 |
my $schema = $database->schema(); |
| 55 |
$schema->storage->txn_begin(); |
55 |
$schema->storage->txn_begin(); |
| 56 |
|
56 |
|
|
|
57 |
my $builder = t::lib::TestBuilder->new; |
| 58 |
|
| 57 |
# Somewhat arbitrary field chosen for age restriction unit tests. Must be added to db before the framework is cached |
59 |
# Somewhat arbitrary field chosen for age restriction unit tests. Must be added to db before the framework is cached |
| 58 |
$dbh->do("update marc_subfield_structure set kohafield='biblioitems.agerestriction' where tagfield='521' and tagsubfield='a'"); |
60 |
$dbh->do("update marc_subfield_structure set kohafield='biblioitems.agerestriction' where tagfield='521' and tagsubfield='a'"); |
| 59 |
|
61 |
|
| 60 |
# Setup Test------------------------ |
62 |
## Setup Test |
|
|
63 |
# Add branches |
| 64 |
my $branch_1 = $builder->build({ source => 'Branch' })->{ branchcode }; |
| 65 |
my $branch_2 = $builder->build({ source => 'Branch' })->{ branchcode }; |
| 66 |
my $branch_3 = $builder->build({ source => 'Branch' })->{ branchcode }; |
| 67 |
# Add categories |
| 68 |
my $category_1 = $builder->build({ source => 'Category' })->{ categorycode }; |
| 69 |
my $category_2 = $builder->build({ source => 'Category' })->{ categorycode }; |
| 70 |
# Add an item type |
| 71 |
my $itemtype = $builder->build( |
| 72 |
{ source => 'Itemtype', value => { notforloan => undef } } )->{itemtype}; |
| 61 |
|
73 |
|
| 62 |
# Add branches if not existing |
|
|
| 63 |
foreach my $addbra ('CPL', 'FPL', 'RPL') { |
| 64 |
$dbh->do("INSERT INTO branches (branchcode,branchname) VALUES (?,?)", undef, ($addbra,"$addbra branch")) unless Koha::Libraries->find($addbra); |
| 65 |
} |
| 66 |
|
| 67 |
# Add categories if not existing |
| 68 |
foreach my $addcat ('S', 'PT') { |
| 69 |
$dbh->do("INSERT INTO categories (categorycode,hidelostitems,category_type) VALUES (?,?,?)",undef,($addcat, 0, $addcat eq 'S'? 'S': 'A')) unless Koha::Patron::Categories->find($addcat); |
| 70 |
} |
| 71 |
|
74 |
|
| 72 |
# Create a helper biblio |
75 |
# Create a helper biblio |
| 73 |
my $bib = MARC::Record->new(); |
76 |
my $bib = MARC::Record->new(); |
|
Lines 88-94
my ($bibnum, $bibitemnum);
Link Here
|
| 88 |
($bibnum, $title, $bibitemnum) = AddBiblio($bib, ''); |
91 |
($bibnum, $title, $bibitemnum) = AddBiblio($bib, ''); |
| 89 |
|
92 |
|
| 90 |
# Create a helper item instance for testing |
93 |
# Create a helper item instance for testing |
| 91 |
my ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => 'CPL', holdingbranch => 'CPL' } , $bibnum); |
94 |
my ( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem( |
|
|
95 |
{ homebranch => $branch_1, |
| 96 |
holdingbranch => $branch_1, |
| 97 |
itype => $itemtype |
| 98 |
}, |
| 99 |
$bibnum |
| 100 |
); |
| 101 |
|
| 92 |
|
102 |
|
| 93 |
# Modify item; setting barcode. |
103 |
# Modify item; setting barcode. |
| 94 |
my $testbarcode = '97531'; |
104 |
my $testbarcode = '97531'; |
|
Lines 98-107
ModItem({ barcode => $testbarcode }, $bibnum, $itemnumber);
Link Here
|
| 98 |
my %data = ( |
108 |
my %data = ( |
| 99 |
firstname => 'my firstname', |
109 |
firstname => 'my firstname', |
| 100 |
surname => 'my surname', |
110 |
surname => 'my surname', |
| 101 |
categorycode => 'S', |
111 |
categorycode => $category_1, |
| 102 |
branchcode => 'CPL', |
112 |
branchcode => $branch_1, |
| 103 |
); |
113 |
); |
| 104 |
Koha::Patron::Categories->find('S')->set({ enrolmentfee => 0})->store; |
114 |
Koha::Patron::Categories->find($category_1)->set({ enrolmentfee => 0})->store; |
| 105 |
my $borrowernumber = AddMember(%data); |
115 |
my $borrowernumber = AddMember(%data); |
| 106 |
my $borrower = GetMember( borrowernumber => $borrowernumber ); |
116 |
my $borrower = GetMember( borrowernumber => $borrowernumber ); |
| 107 |
my $biblionumber = $bibnum; |
117 |
my $biblionumber = $bibnum; |
|
Lines 154-184
t::lib::Mocks::mock_preference( 'ReservesControlBranch', $ReservesControlBranch
Link Here
|
| 154 |
### Regression test for bug 10272 |
164 |
### Regression test for bug 10272 |
| 155 |
### |
165 |
### |
| 156 |
my %requesters = (); |
166 |
my %requesters = (); |
| 157 |
$requesters{'CPL'} = AddMember( |
167 |
$requesters{$branch_1} = AddMember( |
| 158 |
branchcode => 'CPL', |
168 |
branchcode => $branch_1, |
| 159 |
categorycode => 'PT', |
169 |
categorycode => $category_2, |
| 160 |
surname => 'borrower from CPL', |
170 |
surname => "borrower from $branch_1", |
| 161 |
); |
171 |
); |
| 162 |
for my $i ( 2 .. 5 ) { |
172 |
for my $i ( 2 .. 5 ) { |
| 163 |
$requesters{"CPL$i"} = AddMember( |
173 |
$requesters{"CPL$i"} = AddMember( |
| 164 |
branchcode => 'CPL', |
174 |
branchcode => $branch_1, |
| 165 |
categorycode => 'PT', |
175 |
categorycode => $category_2, |
| 166 |
surname => 'borrower $i from CPL', |
176 |
surname => "borrower $i from $branch_1", |
| 167 |
); |
177 |
); |
| 168 |
} |
178 |
} |
| 169 |
$requesters{'FPL'} = AddMember( |
179 |
$requesters{$branch_2} = AddMember( |
| 170 |
branchcode => 'FPL', |
180 |
branchcode => $branch_2, |
| 171 |
categorycode => 'PT', |
181 |
categorycode => $category_2, |
| 172 |
surname => 'borrower from FPL', |
182 |
surname => "borrower from $branch_2", |
| 173 |
); |
183 |
); |
| 174 |
$requesters{'RPL'} = AddMember( |
184 |
$requesters{$branch_3} = AddMember( |
| 175 |
branchcode => 'RPL', |
185 |
branchcode => $branch_3, |
| 176 |
categorycode => 'PT', |
186 |
categorycode => $category_2, |
| 177 |
surname => 'borrower from RPL', |
187 |
surname => "borrower from $branch_3", |
| 178 |
); |
188 |
); |
| 179 |
|
189 |
|
| 180 |
# Configure rules so that CPL allows only CPL patrons |
190 |
# Configure rules so that $branch_1 allows only $branch_1 patrons |
| 181 |
# to request its items, while FPL will allow its items |
191 |
# to request its items, while $branch_2 will allow its items |
| 182 |
# to fill holds from anywhere. |
192 |
# to fill holds from anywhere. |
| 183 |
|
193 |
|
| 184 |
$dbh->do('DELETE FROM issuingrules'); |
194 |
$dbh->do('DELETE FROM issuingrules'); |
|
Lines 200-206
$dbh->do(
Link Here
|
| 200 |
q{INSERT INTO default_branch_circ_rules (branchcode, maxissueqty, holdallowed, returnbranch) |
210 |
q{INSERT INTO default_branch_circ_rules (branchcode, maxissueqty, holdallowed, returnbranch) |
| 201 |
VALUES (?, ?, ?, ?)}, |
211 |
VALUES (?, ?, ?, ?)}, |
| 202 |
{}, |
212 |
{}, |
| 203 |
'CPL', 10, 1, 'homebranch', |
213 |
$branch_1, 10, 1, 'homebranch', |
| 204 |
); |
214 |
); |
| 205 |
|
215 |
|
| 206 |
# ... while FPL allows anybody to request its items |
216 |
# ... while FPL allows anybody to request its items |
|
Lines 208-214
$dbh->do(
Link Here
|
| 208 |
q{INSERT INTO default_branch_circ_rules (branchcode, maxissueqty, holdallowed, returnbranch) |
218 |
q{INSERT INTO default_branch_circ_rules (branchcode, maxissueqty, holdallowed, returnbranch) |
| 209 |
VALUES (?, ?, ?, ?)}, |
219 |
VALUES (?, ?, ?, ?)}, |
| 210 |
{}, |
220 |
{}, |
| 211 |
'FPL', 10, 2, 'homebranch', |
221 |
$branch_2, 10, 2, 'homebranch', |
| 212 |
); |
222 |
); |
| 213 |
|
223 |
|
| 214 |
# helper biblio for the bug 10272 regression test |
224 |
# helper biblio for the bug 10272 regression test |
|
Lines 221-250
$bib2->append_fields(
Link Here
|
| 221 |
# create one item belonging to FPL and one belonging to CPL |
231 |
# create one item belonging to FPL and one belonging to CPL |
| 222 |
my ($bibnum2, $bibitemnum2) = AddBiblio($bib, ''); |
232 |
my ($bibnum2, $bibitemnum2) = AddBiblio($bib, ''); |
| 223 |
my ($itemnum_cpl, $itemnum_fpl); |
233 |
my ($itemnum_cpl, $itemnum_fpl); |
| 224 |
(undef, undef, $itemnum_cpl) = AddItem({ |
234 |
( undef, undef, $itemnum_cpl ) = AddItem( |
| 225 |
homebranch => 'CPL', |
235 |
{ homebranch => $branch_1, |
| 226 |
holdingbranch => 'CPL', |
236 |
holdingbranch => $branch_1, |
| 227 |
barcode => 'bug10272_CPL' |
237 |
barcode => 'bug10272_CPL', |
| 228 |
} , $bibnum2); |
238 |
itype => $itemtype |
| 229 |
(undef, undef, $itemnum_fpl) = AddItem({ |
239 |
}, |
| 230 |
homebranch => 'FPL', |
240 |
$bibnum2 |
| 231 |
holdingbranch => 'FPL', |
241 |
); |
| 232 |
barcode => 'bug10272_FPL' |
242 |
( undef, undef, $itemnum_fpl ) = AddItem( |
| 233 |
} , $bibnum2); |
243 |
{ homebranch => $branch_2, |
|
|
244 |
holdingbranch => $branch_2, |
| 245 |
barcode => 'bug10272_FPL', |
| 246 |
itype => $itemtype |
| 247 |
}, |
| 248 |
$bibnum2 |
| 249 |
); |
| 250 |
|
| 234 |
|
251 |
|
| 235 |
# Ensure that priorities are numbered correcly when a hold is moved to waiting |
252 |
# Ensure that priorities are numbered correcly when a hold is moved to waiting |
| 236 |
# (bug 11947) |
253 |
# (bug 11947) |
| 237 |
$dbh->do("DELETE FROM reserves WHERE biblionumber=?",undef,($bibnum2)); |
254 |
$dbh->do("DELETE FROM reserves WHERE biblionumber=?",undef,($bibnum2)); |
| 238 |
AddReserve('RPL', $requesters{'RPL'}, $bibnum2, |
255 |
AddReserve($branch_3, $requesters{$branch_3}, $bibnum2, |
| 239 |
$bibitems, 1, $resdate, $expdate, $notes, |
256 |
$bibitems, 1, $resdate, $expdate, $notes, |
| 240 |
$title, $checkitem, $found); |
257 |
$title, $checkitem, $found); |
| 241 |
AddReserve('FPL', $requesters{'FPL'}, $bibnum2, |
258 |
AddReserve($branch_2, $requesters{$branch_2}, $bibnum2, |
| 242 |
$bibitems, 2, $resdate, $expdate, $notes, |
259 |
$bibitems, 2, $resdate, $expdate, $notes, |
| 243 |
$title, $checkitem, $found); |
260 |
$title, $checkitem, $found); |
| 244 |
AddReserve('CPL', $requesters{'CPL'}, $bibnum2, |
261 |
AddReserve($branch_1, $requesters{$branch_1}, $bibnum2, |
| 245 |
$bibitems, 3, $resdate, $expdate, $notes, |
262 |
$bibitems, 3, $resdate, $expdate, $notes, |
| 246 |
$title, $checkitem, $found); |
263 |
$title, $checkitem, $found); |
| 247 |
ModReserveAffect($itemnum_cpl, $requesters{'RPL'}, 0); |
264 |
ModReserveAffect($itemnum_cpl, $requesters{$branch_3}, 0); |
| 248 |
|
265 |
|
| 249 |
# Now it should have different priorities. |
266 |
# Now it should have different priorities. |
| 250 |
my $title_reserves = GetReservesFromBiblionumber({biblionumber => $bibnum2}); |
267 |
my $title_reserves = GetReservesFromBiblionumber({biblionumber => $bibnum2}); |
|
Lines 254-272
is($reserves[0]{priority}, 0, 'Item is correctly waiting');
Link Here
|
| 254 |
is($reserves[1]{priority}, 1, 'Item is correctly priority 1'); |
271 |
is($reserves[1]{priority}, 1, 'Item is correctly priority 1'); |
| 255 |
is($reserves[2]{priority}, 2, 'Item is correctly priority 2'); |
272 |
is($reserves[2]{priority}, 2, 'Item is correctly priority 2'); |
| 256 |
|
273 |
|
| 257 |
@reserves = Koha::Holds->search({ borrowernumber => $requesters{'RPL'} })->waiting(); |
274 |
@reserves = Koha::Holds->search({ borrowernumber => $requesters{$branch_3} })->waiting(); |
| 258 |
is( @reserves, 1, 'GetWaiting got only the waiting reserve' ); |
275 |
is( @reserves, 1, 'GetWaiting got only the waiting reserve' ); |
| 259 |
is( $reserves[0]->borrowernumber(), $requesters{'RPL'}, 'GetWaiting got the reserve for the correct borrower' ); |
276 |
is( $reserves[0]->borrowernumber(), $requesters{$branch_3}, 'GetWaiting got the reserve for the correct borrower' ); |
| 260 |
|
277 |
|
| 261 |
|
278 |
|
| 262 |
$dbh->do("DELETE FROM reserves WHERE biblionumber=?",undef,($bibnum2)); |
279 |
$dbh->do("DELETE FROM reserves WHERE biblionumber=?",undef,($bibnum2)); |
| 263 |
AddReserve('RPL', $requesters{'RPL'}, $bibnum2, |
280 |
AddReserve($branch_3, $requesters{$branch_3}, $bibnum2, |
| 264 |
$bibitems, 1, $resdate, $expdate, $notes, |
281 |
$bibitems, 1, $resdate, $expdate, $notes, |
| 265 |
$title, $checkitem, $found); |
282 |
$title, $checkitem, $found); |
| 266 |
AddReserve('FPL', $requesters{'FPL'}, $bibnum2, |
283 |
AddReserve($branch_2, $requesters{$branch_2}, $bibnum2, |
| 267 |
$bibitems, 2, $resdate, $expdate, $notes, |
284 |
$bibitems, 2, $resdate, $expdate, $notes, |
| 268 |
$title, $checkitem, $found); |
285 |
$title, $checkitem, $found); |
| 269 |
AddReserve('CPL', $requesters{'CPL'}, $bibnum2, |
286 |
AddReserve($branch_1, $requesters{$branch_1}, $bibnum2, |
| 270 |
$bibitems, 3, $resdate, $expdate, $notes, |
287 |
$bibitems, 3, $resdate, $expdate, $notes, |
| 271 |
$title, $checkitem, $found); |
288 |
$title, $checkitem, $found); |
| 272 |
|
289 |
|
|
Lines 277-285
my $messages;
Link Here
|
| 277 |
# Return the CPL item at FPL. The hold that should be triggered is |
294 |
# Return the CPL item at FPL. The hold that should be triggered is |
| 278 |
# the one placed by the CPL patron, as the other two patron's hold |
295 |
# the one placed by the CPL patron, as the other two patron's hold |
| 279 |
# requests cannot be filled by that item per policy. |
296 |
# requests cannot be filled by that item per policy. |
| 280 |
(undef, $messages, undef, undef) = AddReturn('bug10272_CPL', 'FPL'); |
297 |
(undef, $messages, undef, undef) = AddReturn('bug10272_CPL', $branch_2); |
| 281 |
is( $messages->{ResFound}->{borrowernumber}, |
298 |
is( $messages->{ResFound}->{borrowernumber}, |
| 282 |
$requesters{'CPL'}, |
299 |
$requesters{$branch_1}, |
| 283 |
'restrictive library\'s items only fill requests by own patrons (bug 10272)'); |
300 |
'restrictive library\'s items only fill requests by own patrons (bug 10272)'); |
| 284 |
|
301 |
|
| 285 |
# Return the FPL item at FPL. The hold that should be triggered is |
302 |
# Return the FPL item at FPL. The hold that should be triggered is |
|
Lines 289-297
is( $messages->{ResFound}->{borrowernumber},
Link Here
|
| 289 |
# Ensure that the preference 'LocalHoldsPriority' is not set (Bug 15244): |
306 |
# Ensure that the preference 'LocalHoldsPriority' is not set (Bug 15244): |
| 290 |
t::lib::Mocks::mock_preference( 'LocalHoldsPriority', '' ); |
307 |
t::lib::Mocks::mock_preference( 'LocalHoldsPriority', '' ); |
| 291 |
|
308 |
|
| 292 |
(undef, $messages, undef, undef) = AddReturn('bug10272_FPL', 'FPL'); |
309 |
(undef, $messages, undef, undef) = AddReturn('bug10272_FPL', $branch_2); |
| 293 |
is( $messages->{ResFound}->{borrowernumber}, |
310 |
is( $messages->{ResFound}->{borrowernumber}, |
| 294 |
$requesters{'RPL'}, |
311 |
$requesters{$branch_3}, |
| 295 |
'for generous library, its items fill first hold request in line (bug 10272)'); |
312 |
'for generous library, its items fill first hold request in line (bug 10272)'); |
| 296 |
|
313 |
|
| 297 |
my $reserves = GetReservesFromBiblionumber({biblionumber => $biblionumber}); |
314 |
my $reserves = GetReservesFromBiblionumber({biblionumber => $biblionumber}); |
|
Lines 320-326
is($reserve, undef, "CancelReserve return undef if reserve does not exist");
Link Here
|
| 320 |
$resdate= undef; #defaults to today in AddReserve |
337 |
$resdate= undef; #defaults to today in AddReserve |
| 321 |
$expdate= undef; #no expdate |
338 |
$expdate= undef; #no expdate |
| 322 |
$dbh->do("DELETE FROM reserves WHERE biblionumber=?",undef,($bibnum)); |
339 |
$dbh->do("DELETE FROM reserves WHERE biblionumber=?",undef,($bibnum)); |
| 323 |
AddReserve('CPL', $requesters{'CPL'}, $bibnum, |
340 |
AddReserve($branch_1, $requesters{$branch_1}, $bibnum, |
| 324 |
$bibitems, 1, $resdate, $expdate, $notes, |
341 |
$bibitems, 1, $resdate, $expdate, $notes, |
| 325 |
$title, $checkitem, $found); |
342 |
$title, $checkitem, $found); |
| 326 |
($status)=CheckReserves($itemnumber,undef,undef); |
343 |
($status)=CheckReserves($itemnumber,undef,undef); |
|
Lines 335-341
$resdate= dt_from_string();
Link Here
|
| 335 |
$resdate->add_duration(DateTime::Duration->new(days => 4)); |
352 |
$resdate->add_duration(DateTime::Duration->new(days => 4)); |
| 336 |
$resdate=output_pref($resdate); |
353 |
$resdate=output_pref($resdate); |
| 337 |
$expdate= undef; #no expdate |
354 |
$expdate= undef; #no expdate |
| 338 |
AddReserve('CPL', $requesters{'CPL'}, $bibnum, |
355 |
AddReserve($branch_1, $requesters{$branch_1}, $bibnum, |
| 339 |
$bibitems, 1, $resdate, $expdate, $notes, |
356 |
$bibitems, 1, $resdate, $expdate, $notes, |
| 340 |
$title, $checkitem, $found); |
357 |
$title, $checkitem, $found); |
| 341 |
($status)=CheckReserves($itemnumber,undef,undef); |
358 |
($status)=CheckReserves($itemnumber,undef,undef); |
|
Lines 351-375
is( $status, 'Reserved', 'CheckReserves returns future reserve with sufficient l
Link Here
|
| 351 |
# Note that AddReturn is in Circulation.pm, but this test really pertains to reserves; AddReturn uses the ConfirmFutureHolds pref when calling CheckReserves |
368 |
# Note that AddReturn is in Circulation.pm, but this test really pertains to reserves; AddReturn uses the ConfirmFutureHolds pref when calling CheckReserves |
| 352 |
# In this test we do not need an issued item; it is just a 'checkin' |
369 |
# In this test we do not need an issued item; it is just a 'checkin' |
| 353 |
t::lib::Mocks::mock_preference('ConfirmFutureHolds', 0); |
370 |
t::lib::Mocks::mock_preference('ConfirmFutureHolds', 0); |
| 354 |
(my $doreturn, $messages)= AddReturn('97531','CPL'); |
371 |
(my $doreturn, $messages)= AddReturn('97531',$branch_1); |
| 355 |
is($messages->{ResFound}//'', '', 'AddReturn does not care about future reserve when ConfirmFutureHolds is off'); |
372 |
is($messages->{ResFound}//'', '', 'AddReturn does not care about future reserve when ConfirmFutureHolds is off'); |
| 356 |
t::lib::Mocks::mock_preference('ConfirmFutureHolds', 3); |
373 |
t::lib::Mocks::mock_preference('ConfirmFutureHolds', 3); |
| 357 |
($doreturn, $messages)= AddReturn('97531','CPL'); |
374 |
($doreturn, $messages)= AddReturn('97531',$branch_1); |
| 358 |
is(exists $messages->{ResFound}?1:0, 0, 'AddReturn ignores future reserve beyond ConfirmFutureHolds days'); |
375 |
is(exists $messages->{ResFound}?1:0, 0, 'AddReturn ignores future reserve beyond ConfirmFutureHolds days'); |
| 359 |
t::lib::Mocks::mock_preference('ConfirmFutureHolds', 7); |
376 |
t::lib::Mocks::mock_preference('ConfirmFutureHolds', 7); |
| 360 |
($doreturn, $messages)= AddReturn('97531','CPL'); |
377 |
($doreturn, $messages)= AddReturn('97531',$branch_1); |
| 361 |
is(exists $messages->{ResFound}?1:0, 1, 'AddReturn considers future reserve within ConfirmFutureHolds days'); |
378 |
is(exists $messages->{ResFound}?1:0, 1, 'AddReturn considers future reserve within ConfirmFutureHolds days'); |
| 362 |
|
379 |
|
| 363 |
# End of tests for bug 9761 (ConfirmFutureHolds) |
380 |
# End of tests for bug 9761 (ConfirmFutureHolds) |
| 364 |
|
381 |
|
| 365 |
# test marking a hold as captured |
382 |
# test marking a hold as captured |
| 366 |
my $hold_notice_count = count_hold_print_messages(); |
383 |
my $hold_notice_count = count_hold_print_messages(); |
| 367 |
ModReserveAffect($itemnumber, $requesters{'CPL'}, 0); |
384 |
ModReserveAffect($itemnumber, $requesters{$branch_1}, 0); |
| 368 |
my $new_count = count_hold_print_messages(); |
385 |
my $new_count = count_hold_print_messages(); |
| 369 |
is($new_count, $hold_notice_count + 1, 'patron notified when item set to waiting'); |
386 |
is($new_count, $hold_notice_count + 1, 'patron notified when item set to waiting'); |
| 370 |
|
387 |
|
| 371 |
# test that duplicate notices aren't generated |
388 |
# test that duplicate notices aren't generated |
| 372 |
ModReserveAffect($itemnumber, $requesters{'CPL'}, 0); |
389 |
ModReserveAffect($itemnumber, $requesters{$branch_1}, 0); |
| 373 |
$new_count = count_hold_print_messages(); |
390 |
$new_count = count_hold_print_messages(); |
| 374 |
is($new_count, $hold_notice_count + 1, 'patron not notified a second time (bug 11445)'); |
391 |
is($new_count, $hold_notice_count + 1, 'patron not notified a second time (bug 11445)'); |
| 375 |
|
392 |
|
|
Lines 381-387
is(
Link Here
|
| 381 |
'item that is captured to fill a hold cannot be deleted', |
398 |
'item that is captured to fill a hold cannot be deleted', |
| 382 |
); |
399 |
); |
| 383 |
|
400 |
|
| 384 |
my $letter = ReserveSlip('CPL', $requesters{'CPL'}, $bibnum); |
401 |
my $letter = ReserveSlip($branch_1, $requesters{$branch_1}, $bibnum); |
| 385 |
ok(defined($letter), 'can successfully generate hold slip (bug 10949)'); |
402 |
ok(defined($letter), 'can successfully generate hold slip (bug 10949)'); |
| 386 |
|
403 |
|
| 387 |
# Tests for bug 9788: Does GetReservesFromItemnumber return a future wait? |
404 |
# Tests for bug 9788: Does GetReservesFromItemnumber return a future wait? |
|
Lines 392-411
t::lib::Mocks::mock_preference('AllowHoldDateInFuture', 1);
Link Here
|
| 392 |
$resdate= dt_from_string(); |
409 |
$resdate= dt_from_string(); |
| 393 |
$resdate->add_duration(DateTime::Duration->new(days => 2)); |
410 |
$resdate->add_duration(DateTime::Duration->new(days => 2)); |
| 394 |
$resdate=output_pref($resdate); |
411 |
$resdate=output_pref($resdate); |
| 395 |
AddReserve('CPL', $requesters{'CPL'}, $bibnum, |
412 |
AddReserve($branch_1, $requesters{$branch_1}, $bibnum, |
| 396 |
$bibitems, 1, $resdate, $expdate, $notes, |
413 |
$bibitems, 1, $resdate, $expdate, $notes, |
| 397 |
$title, $checkitem, $found); |
414 |
$title, $checkitem, $found); |
| 398 |
my @results= GetReservesFromItemnumber($itemnumber); |
415 |
my @results= GetReservesFromItemnumber($itemnumber); |
| 399 |
is(defined $results[3]?1:0, 0, 'GetReservesFromItemnumber does not return a future next available hold'); |
416 |
is(defined $results[3]?1:0, 0, 'GetReservesFromItemnumber does not return a future next available hold'); |
| 400 |
# 9788b: GetReservesFromItemnumber does not return future item level hold |
417 |
# 9788b: GetReservesFromItemnumber does not return future item level hold |
| 401 |
$dbh->do("DELETE FROM reserves WHERE biblionumber=?",undef,($bibnum)); |
418 |
$dbh->do("DELETE FROM reserves WHERE biblionumber=?",undef,($bibnum)); |
| 402 |
AddReserve('CPL', $requesters{'CPL'}, $bibnum, |
419 |
AddReserve($branch_1, $requesters{$branch_1}, $bibnum, |
| 403 |
$bibitems, 1, $resdate, $expdate, $notes, |
420 |
$bibitems, 1, $resdate, $expdate, $notes, |
| 404 |
$title, $itemnumber, $found); #item level hold |
421 |
$title, $itemnumber, $found); #item level hold |
| 405 |
@results= GetReservesFromItemnumber($itemnumber); |
422 |
@results= GetReservesFromItemnumber($itemnumber); |
| 406 |
is(defined $results[3]?1:0, 0, 'GetReservesFromItemnumber does not return a future item level hold'); |
423 |
is(defined $results[3]?1:0, 0, 'GetReservesFromItemnumber does not return a future item level hold'); |
| 407 |
# 9788c: GetReservesFromItemnumber returns future wait (confirmed future hold) |
424 |
# 9788c: GetReservesFromItemnumber returns future wait (confirmed future hold) |
| 408 |
ModReserveAffect( $itemnumber, $requesters{'CPL'} , 0); #confirm hold |
425 |
ModReserveAffect( $itemnumber, $requesters{$branch_1} , 0); #confirm hold |
| 409 |
@results= GetReservesFromItemnumber($itemnumber); |
426 |
@results= GetReservesFromItemnumber($itemnumber); |
| 410 |
is(defined $results[3]?1:0, 1, 'GetReservesFromItemnumber returns a future wait (confirmed future hold)'); |
427 |
is(defined $results[3]?1:0, 1, 'GetReservesFromItemnumber returns a future wait (confirmed future hold)'); |
| 411 |
# End of tests for bug 9788 |
428 |
# End of tests for bug 9788 |
|
Lines 415-421
$dbh->do("DELETE FROM reserves WHERE biblionumber=?",undef,($bibnum));
Link Here
|
| 415 |
my $p = C4::Reserves::CalculatePriority($bibnum2); |
432 |
my $p = C4::Reserves::CalculatePriority($bibnum2); |
| 416 |
is($p, 4, 'CalculatePriority should now return priority 4'); |
433 |
is($p, 4, 'CalculatePriority should now return priority 4'); |
| 417 |
$resdate=undef; |
434 |
$resdate=undef; |
| 418 |
AddReserve('CPL', $requesters{'CPL2'}, $bibnum2, |
435 |
AddReserve($branch_1, $requesters{'CPL2'}, $bibnum2, |
| 419 |
$bibitems, $p, $resdate, $expdate, $notes, |
436 |
$bibitems, $p, $resdate, $expdate, $notes, |
| 420 |
$title, $checkitem, $found); |
437 |
$title, $checkitem, $found); |
| 421 |
$p = C4::Reserves::CalculatePriority($bibnum2); |
438 |
$p = C4::Reserves::CalculatePriority($bibnum2); |
|
Lines 425-440
$dbh->do("DELETE FROM reserves WHERE biblionumber=?",undef,($bibnum));
Link Here
|
| 425 |
$p = C4::Reserves::CalculatePriority($bibnum); |
442 |
$p = C4::Reserves::CalculatePriority($bibnum); |
| 426 |
is($p, 1, 'CalculatePriority should now return priority 1'); |
443 |
is($p, 1, 'CalculatePriority should now return priority 1'); |
| 427 |
#add a new reserve and confirm it to waiting |
444 |
#add a new reserve and confirm it to waiting |
| 428 |
AddReserve('CPL', $requesters{'CPL'}, $bibnum, |
445 |
AddReserve($branch_1, $requesters{$branch_1}, $bibnum, |
| 429 |
$bibitems, $p, $resdate, $expdate, $notes, |
446 |
$bibitems, $p, $resdate, $expdate, $notes, |
| 430 |
$title, $itemnumber, $found); |
447 |
$title, $itemnumber, $found); |
| 431 |
$p = C4::Reserves::CalculatePriority($bibnum); |
448 |
$p = C4::Reserves::CalculatePriority($bibnum); |
| 432 |
is($p, 2, 'CalculatePriority should now return priority 2'); |
449 |
is($p, 2, 'CalculatePriority should now return priority 2'); |
| 433 |
ModReserveAffect( $itemnumber, $requesters{'CPL'} , 0); |
450 |
ModReserveAffect( $itemnumber, $requesters{$branch_1} , 0); |
| 434 |
$p = C4::Reserves::CalculatePriority($bibnum); |
451 |
$p = C4::Reserves::CalculatePriority($bibnum); |
| 435 |
is($p, 1, 'CalculatePriority should now return priority 1'); |
452 |
is($p, 1, 'CalculatePriority should now return priority 1'); |
| 436 |
#add another biblio hold, no resdate |
453 |
#add another biblio hold, no resdate |
| 437 |
AddReserve('CPL', $requesters{'CPL2'}, $bibnum, |
454 |
AddReserve($branch_1, $requesters{'CPL2'}, $bibnum, |
| 438 |
$bibitems, $p, $resdate, $expdate, $notes, |
455 |
$bibitems, $p, $resdate, $expdate, $notes, |
| 439 |
$title, $checkitem, $found); |
456 |
$title, $checkitem, $found); |
| 440 |
$p = C4::Reserves::CalculatePriority($bibnum); |
457 |
$p = C4::Reserves::CalculatePriority($bibnum); |
|
Lines 443-449
is($p, 2, 'CalculatePriority should now return priority 2');
Link Here
|
| 443 |
t::lib::Mocks::mock_preference('AllowHoldDateInFuture', 1); |
460 |
t::lib::Mocks::mock_preference('AllowHoldDateInFuture', 1); |
| 444 |
$resdate= dt_from_string(); |
461 |
$resdate= dt_from_string(); |
| 445 |
$resdate->add_duration(DateTime::Duration->new(days => 1)); |
462 |
$resdate->add_duration(DateTime::Duration->new(days => 1)); |
| 446 |
AddReserve('CPL', $requesters{'CPL3'}, $bibnum, |
463 |
AddReserve($branch_1, $requesters{'CPL3'}, $bibnum, |
| 447 |
$bibitems, $p, output_pref($resdate), $expdate, $notes, |
464 |
$bibitems, $p, output_pref($resdate), $expdate, $notes, |
| 448 |
$title, $checkitem, $found); |
465 |
$title, $checkitem, $found); |
| 449 |
$p = C4::Reserves::CalculatePriority($bibnum); |
466 |
$p = C4::Reserves::CalculatePriority($bibnum); |
|
Lines 455-461
is($p, 3, 'CalculatePriority should now return priority 3');
Link Here
|
| 455 |
|
472 |
|
| 456 |
# Tests for cancel reserves by users from OPAC. |
473 |
# Tests for cancel reserves by users from OPAC. |
| 457 |
$dbh->do('DELETE FROM reserves', undef, ($bibnum)); |
474 |
$dbh->do('DELETE FROM reserves', undef, ($bibnum)); |
| 458 |
AddReserve('CPL', $requesters{'CPL'}, $item_bibnum, |
475 |
AddReserve($branch_1, $requesters{$branch_1}, $item_bibnum, |
| 459 |
$bibitems, 1, undef, $expdate, $notes, |
476 |
$bibitems, 1, undef, $expdate, $notes, |
| 460 |
$title, $checkitem, ''); |
477 |
$title, $checkitem, ''); |
| 461 |
my (undef, $canres, undef) = CheckReserves($itemnumber); |
478 |
my (undef, $canres, undef) = CheckReserves($itemnumber); |
|
Lines 474-497
is(
Link Here
|
| 474 |
'CanReserveBeCanceledFromOpac should return undef if called without borrowernumber' |
491 |
'CanReserveBeCanceledFromOpac should return undef if called without borrowernumber' |
| 475 |
); |
492 |
); |
| 476 |
|
493 |
|
| 477 |
my $cancancel = CanReserveBeCanceledFromOpac($canres->{reserve_id}, $requesters{'CPL'}); |
494 |
my $cancancel = CanReserveBeCanceledFromOpac($canres->{reserve_id}, $requesters{$branch_1}); |
| 478 |
is($cancancel, 1, 'Can user cancel its own reserve'); |
495 |
is($cancancel, 1, 'Can user cancel its own reserve'); |
| 479 |
|
496 |
|
| 480 |
$cancancel = CanReserveBeCanceledFromOpac($canres->{reserve_id}, $requesters{'FPL'}); |
497 |
$cancancel = CanReserveBeCanceledFromOpac($canres->{reserve_id}, $requesters{$branch_2}); |
| 481 |
is($cancancel, 0, 'Other user cant cancel reserve'); |
498 |
is($cancancel, 0, 'Other user cant cancel reserve'); |
| 482 |
|
499 |
|
| 483 |
ModReserveAffect($itemnumber, $requesters{'CPL'}, 1); |
500 |
ModReserveAffect($itemnumber, $requesters{$branch_1}, 1); |
| 484 |
$cancancel = CanReserveBeCanceledFromOpac($canres->{reserve_id}, $requesters{'CPL'}); |
501 |
$cancancel = CanReserveBeCanceledFromOpac($canres->{reserve_id}, $requesters{$branch_1}); |
| 485 |
is($cancancel, 0, 'Reserve in transfer status cant be canceled'); |
502 |
is($cancancel, 0, 'Reserve in transfer status cant be canceled'); |
| 486 |
|
503 |
|
| 487 |
$dbh->do('DELETE FROM reserves', undef, ($bibnum)); |
504 |
$dbh->do('DELETE FROM reserves', undef, ($bibnum)); |
| 488 |
AddReserve('CPL', $requesters{'CPL'}, $item_bibnum, |
505 |
AddReserve($branch_1, $requesters{$branch_1}, $item_bibnum, |
| 489 |
$bibitems, 1, undef, $expdate, $notes, |
506 |
$bibitems, 1, undef, $expdate, $notes, |
| 490 |
$title, $checkitem, ''); |
507 |
$title, $checkitem, ''); |
| 491 |
(undef, $canres, undef) = CheckReserves($itemnumber); |
508 |
(undef, $canres, undef) = CheckReserves($itemnumber); |
| 492 |
|
509 |
|
| 493 |
ModReserveAffect($itemnumber, $requesters{'CPL'}, 0); |
510 |
ModReserveAffect($itemnumber, $requesters{$branch_1}, 0); |
| 494 |
$cancancel = CanReserveBeCanceledFromOpac($canres->{reserve_id}, $requesters{'CPL'}); |
511 |
$cancancel = CanReserveBeCanceledFromOpac($canres->{reserve_id}, $requesters{$branch_1}); |
| 495 |
is($cancancel, 0, 'Reserve in waiting status cant be canceled'); |
512 |
is($cancancel, 0, 'Reserve in waiting status cant be canceled'); |
| 496 |
|
513 |
|
| 497 |
# End of tests for bug 12876 |
514 |
# End of tests for bug 12876 |
|
Lines 560-566
is( !$bz14464_fines || $bz14464_fines==0, 1, 'Bug 14464 - No fines at beginning'
Link Here
|
| 560 |
t::lib::Mocks::mock_preference('ExpireReservesMaxPickUpDelayCharge', 0); |
577 |
t::lib::Mocks::mock_preference('ExpireReservesMaxPickUpDelayCharge', 0); |
| 561 |
|
578 |
|
| 562 |
my $bz14464_reserve = AddReserve( |
579 |
my $bz14464_reserve = AddReserve( |
| 563 |
'CPL', |
580 |
$branch_1, |
| 564 |
$borrowernumber, |
581 |
$borrowernumber, |
| 565 |
$bibnum, |
582 |
$bibnum, |
| 566 |
undef, |
583 |
undef, |
|
Lines 587-593
is( !$bz14464_fines || $bz14464_fines==0, 1, 'Bug 14464 - No fines after cancell
Link Here
|
| 587 |
t::lib::Mocks::mock_preference('ExpireReservesMaxPickUpDelayCharge', 42); |
604 |
t::lib::Mocks::mock_preference('ExpireReservesMaxPickUpDelayCharge', 42); |
| 588 |
|
605 |
|
| 589 |
$bz14464_reserve = AddReserve( |
606 |
$bz14464_reserve = AddReserve( |
| 590 |
'CPL', |
607 |
$branch_1, |
| 591 |
$borrowernumber, |
608 |
$borrowernumber, |
| 592 |
$bibnum, |
609 |
$bibnum, |
| 593 |
undef, |
610 |
undef, |
|
Lines 609-615
is( !$bz14464_fines || $bz14464_fines==0, 1, 'Bug 14464 - No fines after cancell
Link Here
|
| 609 |
|
626 |
|
| 610 |
# Finally, test cancelling a reserve when there's a charge desired and configured. |
627 |
# Finally, test cancelling a reserve when there's a charge desired and configured. |
| 611 |
$bz14464_reserve = AddReserve( |
628 |
$bz14464_reserve = AddReserve( |
| 612 |
'CPL', |
629 |
$branch_1, |
| 613 |
$borrowernumber, |
630 |
$borrowernumber, |
| 614 |
$bibnum, |
631 |
$bibnum, |
| 615 |
undef, |
632 |
undef, |
|
Lines 634-646
is( int( $bz14464_fines ), 42, 'Bug 14464 - Fine applied after cancelling reserv
Link Here
|
| 634 |
$dbh->do('DELETE FROM reserves', undef, ($bibnum)); |
651 |
$dbh->do('DELETE FROM reserves', undef, ($bibnum)); |
| 635 |
t::lib::Mocks::mock_preference('ConfirmFutureHolds', 0); |
652 |
t::lib::Mocks::mock_preference('ConfirmFutureHolds', 0); |
| 636 |
t::lib::Mocks::mock_preference('AllowHoldDateInFuture', 1); |
653 |
t::lib::Mocks::mock_preference('AllowHoldDateInFuture', 1); |
| 637 |
AddReserve('CPL', $borrowernumber, $item_bibnum, |
654 |
AddReserve($branch_1, $borrowernumber, $item_bibnum, |
| 638 |
$bibitems, 1, undef, $expdate, $notes, $title, $checkitem, ''); |
655 |
$bibitems, 1, undef, $expdate, $notes, $title, $checkitem, ''); |
| 639 |
MoveReserve( $itemnumber, $borrowernumber ); |
656 |
MoveReserve( $itemnumber, $borrowernumber ); |
| 640 |
($status)=CheckReserves( $itemnumber ); |
657 |
($status)=CheckReserves( $itemnumber ); |
| 641 |
is( $status, '', 'MoveReserve filled hold'); |
658 |
is( $status, '', 'MoveReserve filled hold'); |
| 642 |
# hold from A waiting, today, no fut holds: MoveReserve should fill it |
659 |
# hold from A waiting, today, no fut holds: MoveReserve should fill it |
| 643 |
AddReserve('CPL', $borrowernumber, $item_bibnum, |
660 |
AddReserve($branch_1, $borrowernumber, $item_bibnum, |
| 644 |
$bibitems, 1, undef, $expdate, $notes, $title, $checkitem, 'W'); |
661 |
$bibitems, 1, undef, $expdate, $notes, $title, $checkitem, 'W'); |
| 645 |
MoveReserve( $itemnumber, $borrowernumber ); |
662 |
MoveReserve( $itemnumber, $borrowernumber ); |
| 646 |
($status)=CheckReserves( $itemnumber ); |
663 |
($status)=CheckReserves( $itemnumber ); |
|
Lines 649-655
is( $status, '', 'MoveReserve filled waiting hold');
Link Here
|
| 649 |
$resdate= dt_from_string(); |
666 |
$resdate= dt_from_string(); |
| 650 |
$resdate->add_duration(DateTime::Duration->new(days => 1)); |
667 |
$resdate->add_duration(DateTime::Duration->new(days => 1)); |
| 651 |
$resdate=output_pref($resdate); |
668 |
$resdate=output_pref($resdate); |
| 652 |
AddReserve('CPL', $borrowernumber, $item_bibnum, |
669 |
AddReserve($branch_1, $borrowernumber, $item_bibnum, |
| 653 |
$bibitems, 1, $resdate, $expdate, $notes, $title, $checkitem, ''); |
670 |
$bibitems, 1, $resdate, $expdate, $notes, $title, $checkitem, ''); |
| 654 |
MoveReserve( $itemnumber, $borrowernumber ); |
671 |
MoveReserve( $itemnumber, $borrowernumber ); |
| 655 |
($status)=CheckReserves( $itemnumber, undef, 1 ); |
672 |
($status)=CheckReserves( $itemnumber, undef, 1 ); |
|
Lines 657-669
is( $status, 'Reserved', 'MoveReserve did not fill future hold');
Link Here
|
| 657 |
$dbh->do('DELETE FROM reserves', undef, ($bibnum)); |
674 |
$dbh->do('DELETE FROM reserves', undef, ($bibnum)); |
| 658 |
# hold from A pos 1, tomorrow, fut holds=2: MoveReserve should fill it |
675 |
# hold from A pos 1, tomorrow, fut holds=2: MoveReserve should fill it |
| 659 |
t::lib::Mocks::mock_preference('ConfirmFutureHolds', 2); |
676 |
t::lib::Mocks::mock_preference('ConfirmFutureHolds', 2); |
| 660 |
AddReserve('CPL', $borrowernumber, $item_bibnum, |
677 |
AddReserve($branch_1, $borrowernumber, $item_bibnum, |
| 661 |
$bibitems, 1, $resdate, $expdate, $notes, $title, $checkitem, ''); |
678 |
$bibitems, 1, $resdate, $expdate, $notes, $title, $checkitem, ''); |
| 662 |
MoveReserve( $itemnumber, $borrowernumber ); |
679 |
MoveReserve( $itemnumber, $borrowernumber ); |
| 663 |
($status)=CheckReserves( $itemnumber, undef, 2 ); |
680 |
($status)=CheckReserves( $itemnumber, undef, 2 ); |
| 664 |
is( $status, '', 'MoveReserve filled future hold now'); |
681 |
is( $status, '', 'MoveReserve filled future hold now'); |
| 665 |
# hold from A waiting, tomorrow, fut holds=2: MoveReserve should fill it |
682 |
# hold from A waiting, tomorrow, fut holds=2: MoveReserve should fill it |
| 666 |
AddReserve('CPL', $borrowernumber, $item_bibnum, |
683 |
AddReserve($branch_1, $borrowernumber, $item_bibnum, |
| 667 |
$bibitems, 1, $resdate, $expdate, $notes, $title, $checkitem, 'W'); |
684 |
$bibitems, 1, $resdate, $expdate, $notes, $title, $checkitem, 'W'); |
| 668 |
MoveReserve( $itemnumber, $borrowernumber ); |
685 |
MoveReserve( $itemnumber, $borrowernumber ); |
| 669 |
($status)=CheckReserves( $itemnumber, undef, 2 ); |
686 |
($status)=CheckReserves( $itemnumber, undef, 2 ); |
|
Lines 672-678
is( $status, '', 'MoveReserve filled future waiting hold now');
Link Here
|
| 672 |
$resdate= dt_from_string(); |
689 |
$resdate= dt_from_string(); |
| 673 |
$resdate->add_duration(DateTime::Duration->new(days => 3)); |
690 |
$resdate->add_duration(DateTime::Duration->new(days => 3)); |
| 674 |
$resdate=output_pref($resdate); |
691 |
$resdate=output_pref($resdate); |
| 675 |
AddReserve('CPL', $borrowernumber, $item_bibnum, |
692 |
AddReserve($branch_1, $borrowernumber, $item_bibnum, |
| 676 |
$bibitems, 1, $resdate, $expdate, $notes, $title, $checkitem, ''); |
693 |
$bibitems, 1, $resdate, $expdate, $notes, $title, $checkitem, ''); |
| 677 |
MoveReserve( $itemnumber, $borrowernumber ); |
694 |
MoveReserve( $itemnumber, $borrowernumber ); |
| 678 |
($status)=CheckReserves( $itemnumber, undef, 3 ); |
695 |
($status)=CheckReserves( $itemnumber, undef, 3 ); |
| 679 |
- |
|
|