|
Lines 156-185
subtest "as_marc_field() tests" => sub {
Link Here
|
| 156 |
}; |
156 |
}; |
| 157 |
|
157 |
|
| 158 |
subtest 'pickup_locations' => sub { |
158 |
subtest 'pickup_locations' => sub { |
| 159 |
plan tests => 114; |
159 |
plan tests => 66; |
| 160 |
|
160 |
|
| 161 |
$schema->storage->txn_begin; |
161 |
$schema->storage->txn_begin; |
| 162 |
|
162 |
|
| 163 |
my $dbh = C4::Context->dbh; |
163 |
my $dbh = C4::Context->dbh; |
| 164 |
|
164 |
|
| 165 |
# Cleanup database |
|
|
| 166 |
Koha::Holds->search->delete; |
| 167 |
$dbh->do('DELETE FROM issues'); |
| 168 |
Koha::Patrons->search->delete; |
| 169 |
Koha::Items->search->delete; |
| 170 |
Koha::Libraries->search->delete; |
| 171 |
Koha::CirculationRules->search->delete; |
| 172 |
Koha::CirculationRules->set_rules( |
| 173 |
{ |
| 174 |
categorycode => undef, |
| 175 |
itemtype => undef, |
| 176 |
branchcode => undef, |
| 177 |
rules => { |
| 178 |
reservesallowed => 25, |
| 179 |
} |
| 180 |
} |
| 181 |
); |
| 182 |
|
| 183 |
my $root1 = $builder->build_object( { class => 'Koha::Library::Groups', value => { ft_local_hold_group => 1, branchcode => undef } } ); |
165 |
my $root1 = $builder->build_object( { class => 'Koha::Library::Groups', value => { ft_local_hold_group => 1, branchcode => undef } } ); |
| 184 |
my $root2 = $builder->build_object( { class => 'Koha::Library::Groups', value => { ft_local_hold_group => 1, branchcode => undef } } ); |
166 |
my $root2 = $builder->build_object( { class => 'Koha::Library::Groups', value => { ft_local_hold_group => 1, branchcode => undef } } ); |
| 185 |
my $library1 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1, } } ); |
167 |
my $library1 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1, } } ); |
|
Lines 192-280
subtest 'pickup_locations' => sub {
Link Here
|
| 192 |
my $group2_1 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root2->id, branchcode => $library3->branchcode } } ); |
174 |
my $group2_1 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root2->id, branchcode => $library3->branchcode } } ); |
| 193 |
my $group2_2 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root2->id, branchcode => $library4->branchcode } } ); |
175 |
my $group2_2 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root2->id, branchcode => $library4->branchcode } } ); |
| 194 |
|
176 |
|
| 195 |
my $biblioitem = $builder->build( { source => 'Biblioitem' } ); |
177 |
our @branchcodes = ( |
| 196 |
|
178 |
$library1->branchcode, $library2->branchcode, |
| 197 |
my $item1 = Koha::Item->new({ |
179 |
$library3->branchcode, $library4->branchcode |
| 198 |
biblionumber => $biblioitem->{biblionumber}, |
180 |
); |
| 199 |
biblioitemnumber => $biblioitem->{biblioitemnumber}, |
181 |
|
| 200 |
homebranch => $library1->branchcode, |
182 |
my $item1 = $builder->build_sample_item( |
| 201 |
holdingbranch => $library2->branchcode, |
183 |
{ |
| 202 |
barcode => '1', |
184 |
homebranch => $library1->branchcode, |
| 203 |
itype => 'test', |
185 |
holdingbranch => $library2->branchcode, |
| 204 |
})->store; |
186 |
copynumber => 1, |
| 205 |
|
187 |
ccode => 'Gollum' |
| 206 |
my $item3 = Koha::Item->new({ |
188 |
} |
| 207 |
biblionumber => $biblioitem->{biblionumber}, |
189 |
)->store; |
| 208 |
biblioitemnumber => $biblioitem->{biblioitemnumber}, |
190 |
|
| 209 |
homebranch => $library3->branchcode, |
191 |
my $item3 = $builder->build_sample_item( |
| 210 |
holdingbranch => $library4->branchcode, |
192 |
{ |
| 211 |
barcode => '3', |
193 |
homebranch => $library3->branchcode, |
| 212 |
itype => 'test', |
194 |
holdingbranch => $library4->branchcode, |
| 213 |
})->store; |
195 |
copynumber => 3, |
|
|
196 |
itype => $item1->itype, |
| 197 |
} |
| 198 |
)->store; |
| 199 |
|
| 200 |
Koha::CirculationRules->set_rules( |
| 201 |
{ |
| 202 |
categorycode => undef, |
| 203 |
itemtype => $item1->itype, |
| 204 |
branchcode => undef, |
| 205 |
rules => { |
| 206 |
reservesallowed => 25, |
| 207 |
} |
| 208 |
} |
| 209 |
); |
| 210 |
|
| 214 |
|
211 |
|
| 215 |
my $patron1 = $builder->build_object( { class => 'Koha::Patrons', value => { branchcode => $library1->branchcode, firstname => '1' } } ); |
212 |
my $patron1 = $builder->build_object( { class => 'Koha::Patrons', value => { branchcode => $library1->branchcode, firstname => '1' } } ); |
| 216 |
my $patron4 = $builder->build_object( { class => 'Koha::Patrons', value => { branchcode => $library4->branchcode, firstname => '4' } } ); |
213 |
my $patron4 = $builder->build_object( { class => 'Koha::Patrons', value => { branchcode => $library4->branchcode, firstname => '4' } } ); |
| 217 |
|
214 |
|
|
|
215 |
my $all_count = Koha::Libraries->search({ pickup_location => 1})->count(); |
| 216 |
|
| 218 |
my $results = { |
217 |
my $results = { |
| 219 |
"1-1-1-any" => 3, |
218 |
"1-1-1-any" => $all_count, |
| 220 |
"1-1-1-holdgroup" => 2, |
219 |
"1-1-1-holdgroup" => 2, |
| 221 |
"1-1-1-patrongroup" => 2, |
220 |
"1-1-1-patrongroup" => 2, |
| 222 |
"1-1-1-homebranch" => 1, |
221 |
"1-1-1-homebranch" => 1, |
| 223 |
"1-1-1-holdingbranch" => 1, |
222 |
"1-1-1-holdingbranch" => 1, |
| 224 |
"1-1-2-any" => 3, |
223 |
"1-1-2-any" => $all_count, |
| 225 |
"1-1-2-holdgroup" => 2, |
224 |
"1-1-2-holdgroup" => 2, |
| 226 |
"1-1-2-patrongroup" => 2, |
225 |
"1-1-2-patrongroup" => 2, |
| 227 |
"1-1-2-homebranch" => 1, |
226 |
"1-1-2-homebranch" => 1, |
| 228 |
"1-1-2-holdingbranch" => 1, |
227 |
"1-1-2-holdingbranch" => 1, |
| 229 |
"1-1-3-any" => 3, |
228 |
"1-1-3-any" => $all_count, |
| 230 |
"1-1-3-holdgroup" => 2, |
229 |
"1-1-3-holdgroup" => 2, |
| 231 |
"1-1-3-patrongroup" => 2, |
230 |
"1-1-3-patrongroup" => 2, |
| 232 |
"1-1-3-homebranch" => 1, |
231 |
"1-1-3-homebranch" => 1, |
| 233 |
"1-1-3-holdingbranch" => 1, |
232 |
"1-1-3-holdingbranch" => 1, |
| 234 |
"1-4-1-any" => 0, |
233 |
"1-4-1-any" => 0, |
| 235 |
"1-4-1-holdgroup" => 0, |
234 |
"1-4-1-holdgroup" => 0, |
| 236 |
"1-4-1-patrongroup" => 0, |
235 |
"1-4-1-patrongroup" => 0, |
| 237 |
"1-4-1-homebranch" => 0, |
236 |
"1-4-1-homebranch" => 0, |
| 238 |
"1-4-1-holdingbranch" => 0, |
237 |
"1-4-1-holdingbranch" => 0, |
| 239 |
"1-4-2-any" => 3, |
238 |
"1-4-2-any" => $all_count, |
| 240 |
"1-4-2-holdgroup" => 2, |
239 |
"1-4-2-holdgroup" => 2, |
| 241 |
"1-4-2-patrongroup" => 1, |
240 |
"1-4-2-patrongroup" => 1, |
| 242 |
"1-4-2-homebranch" => 1, |
241 |
"1-4-2-homebranch" => 1, |
| 243 |
"1-4-2-holdingbranch" => 1, |
242 |
"1-4-2-holdingbranch" => 1, |
| 244 |
"1-4-3-any" => 0, |
243 |
"1-4-3-any" => 0, |
| 245 |
"1-4-3-holdgroup" => 0, |
244 |
"1-4-3-holdgroup" => 0, |
| 246 |
"1-4-3-patrongroup" => 0, |
245 |
"1-4-3-patrongroup" => 0, |
| 247 |
"1-4-3-homebranch" => 0, |
246 |
"1-4-3-homebranch" => 0, |
| 248 |
"1-4-3-holdingbranch" => 0, |
247 |
"1-4-3-holdingbranch" => 0, |
| 249 |
"3-1-1-any" => 0, |
248 |
"3-1-1-any" => 0, |
| 250 |
"3-1-1-holdgroup" => 0, |
249 |
"3-1-1-holdgroup" => 0, |
| 251 |
"3-1-1-patrongroup" => 0, |
250 |
"3-1-1-patrongroup" => 0, |
| 252 |
"3-1-1-homebranch" => 0, |
251 |
"3-1-1-homebranch" => 0, |
| 253 |
"3-1-1-holdingbranch" => 0, |
252 |
"3-1-1-holdingbranch" => 0, |
| 254 |
"3-1-2-any" => 3, |
253 |
"3-1-2-any" => $all_count, |
| 255 |
"3-1-2-holdgroup" => 1, |
254 |
"3-1-2-holdgroup" => 1, |
| 256 |
"3-1-2-patrongroup" => 2, |
255 |
"3-1-2-patrongroup" => 2, |
| 257 |
"3-1-2-homebranch" => 0, |
256 |
"3-1-2-homebranch" => 0, |
| 258 |
"3-1-2-holdingbranch" => 1, |
257 |
"3-1-2-holdingbranch" => 1, |
| 259 |
"3-1-3-any" => 0, |
258 |
"3-1-3-any" => 0, |
| 260 |
"3-1-3-holdgroup" => 0, |
259 |
"3-1-3-holdgroup" => 0, |
| 261 |
"3-1-3-patrongroup" => 0, |
260 |
"3-1-3-patrongroup" => 0, |
| 262 |
"3-1-3-homebranch" => 0, |
261 |
"3-1-3-homebranch" => 0, |
| 263 |
"3-1-3-holdingbranch" => 0, |
262 |
"3-1-3-holdingbranch" => 0, |
| 264 |
"3-4-1-any" => 0, |
263 |
"3-4-1-any" => 0, |
| 265 |
"3-4-1-holdgroup" => 0, |
264 |
"3-4-1-holdgroup" => 0, |
| 266 |
"3-4-1-patrongroup" => 0, |
265 |
"3-4-1-patrongroup" => 0, |
| 267 |
"3-4-1-homebranch" => 0, |
266 |
"3-4-1-homebranch" => 0, |
| 268 |
"3-4-1-holdingbranch" => 0, |
267 |
"3-4-1-holdingbranch" => 0, |
| 269 |
"3-4-2-any" => 3, |
268 |
"3-4-2-any" => $all_count, |
| 270 |
"3-4-2-holdgroup" => 1, |
269 |
"3-4-2-holdgroup" => 1, |
| 271 |
"3-4-2-patrongroup" => 1, |
270 |
"3-4-2-patrongroup" => 1, |
| 272 |
"3-4-2-homebranch" => 0, |
271 |
"3-4-2-homebranch" => 0, |
| 273 |
"3-4-2-holdingbranch" => 1, |
272 |
"3-4-2-holdingbranch" => 1, |
| 274 |
"3-4-3-any" => 3, |
273 |
"3-4-3-any" => $all_count, |
| 275 |
"3-4-3-holdgroup" => 1, |
274 |
"3-4-3-holdgroup" => 1, |
| 276 |
"3-4-3-patrongroup" => 1, |
275 |
"3-4-3-patrongroup" => 1, |
| 277 |
"3-4-3-homebranch" => 0, |
276 |
"3-4-3-homebranch" => 0, |
| 278 |
"3-4-3-holdingbranch" => 1 |
277 |
"3-4-3-holdingbranch" => 1 |
| 279 |
}; |
278 |
}; |
| 280 |
|
279 |
|
|
Lines 292-312
subtest 'pickup_locations' => sub {
Link Here
|
| 292 |
} |
291 |
} |
| 293 |
} |
292 |
} |
| 294 |
); |
293 |
); |
| 295 |
my @pl = @{ $item->pickup_locations( { patron => $patron} ) }; |
294 |
my @pl = $item->pickup_locations( { patron => $patron} )->as_list; |
| 296 |
my $ha_value=$ha==3?'holdgroup':($ha==2?'any':'homebranch'); |
295 |
my $ha_value=$ha==3?'holdgroup':($ha==2?'any':'homebranch'); |
| 297 |
|
296 |
|
| 298 |
foreach my $pickup_location (@pl) { |
297 |
foreach my $pickup_location (@pl) { |
|
|
298 |
next |
| 299 |
unless grep { $pickup_location eq $_ } @branchcodes; |
| 299 |
is( ref($pickup_location), 'Koha::Library', 'Object type is correct' ); |
300 |
is( ref($pickup_location), 'Koha::Library', 'Object type is correct' ); |
| 300 |
} |
301 |
} |
| 301 |
ok( |
302 |
ok( |
| 302 |
scalar(@pl) == $results->{ |
303 |
scalar(@pl) == $results->{ |
| 303 |
$item->barcode . '-' |
304 |
$item->copynumber . '-' |
| 304 |
. $patron->firstname . '-' |
305 |
. $patron->firstname . '-' |
| 305 |
. $ha . '-' |
306 |
. $ha . '-' |
| 306 |
. $hfp |
307 |
. $hfp |
| 307 |
}, |
308 |
}, |
| 308 |
'item' |
309 |
'item' |
| 309 |
. $item->barcode |
310 |
. $item->copynumber |
| 310 |
. ', patron' |
311 |
. ', patron' |
| 311 |
. $patron->firstname |
312 |
. $patron->firstname |
| 312 |
. ', holdallowed: ' |
313 |
. ', holdallowed: ' |
|
Lines 315-326
subtest 'pickup_locations' => sub {
Link Here
|
| 315 |
. $hfp |
316 |
. $hfp |
| 316 |
. ' should return ' |
317 |
. ' should return ' |
| 317 |
. $results->{ |
318 |
. $results->{ |
| 318 |
$item->barcode . '-' |
319 |
$item->copynumber . '-' |
| 319 |
. $patron->firstname . '-' |
320 |
. $patron->firstname . '-' |
| 320 |
. $ha . '-' |
321 |
. $ha . '-' |
| 321 |
. $hfp |
322 |
. $hfp |
| 322 |
} |
323 |
} |
| 323 |
. ' but returns ' |
324 |
. ' and returns ' |
| 324 |
. scalar(@pl) |
325 |
. scalar(@pl) |
| 325 |
); |
326 |
); |
| 326 |
|
327 |
|
|
Lines 338-343
subtest 'pickup_locations' => sub {
Link Here
|
| 338 |
} |
339 |
} |
| 339 |
} |
340 |
} |
| 340 |
|
341 |
|
|
|
342 |
# Now test that branchtransferlimits will further filter the pickup locations |
| 343 |
|
| 344 |
my $item_no_ccode = $builder->build_sample_item( |
| 345 |
{ |
| 346 |
homebranch => $library1->branchcode, |
| 347 |
holdingbranch => $library2->branchcode, |
| 348 |
itype => $item1->itype, |
| 349 |
} |
| 350 |
)->store; |
| 351 |
|
| 352 |
t::lib::Mocks::mock_preference('UseBranchTransferLimits', 1); |
| 353 |
t::lib::Mocks::mock_preference('BranchTransferLimitsType', 'itemtype'); |
| 354 |
Koha::CirculationRules->set_rules( |
| 355 |
{ |
| 356 |
branchcode => undef, |
| 357 |
itemtype => $item1->itype, |
| 358 |
rules => { |
| 359 |
holdallowed => 1, |
| 360 |
hold_fulfillment_policy => 1, |
| 361 |
returnbranch => 'any' |
| 362 |
} |
| 363 |
} |
| 364 |
); |
| 365 |
$builder->build_object( |
| 366 |
{ |
| 367 |
class => 'Koha::Item::Transfer::Limits', |
| 368 |
value => { |
| 369 |
toBranch => $library1->branchcode, |
| 370 |
fromBranch => $library2->branchcode, |
| 371 |
itemtype => $item1->itype, |
| 372 |
ccode => undef, |
| 373 |
} |
| 374 |
} |
| 375 |
); |
| 376 |
|
| 377 |
my $pickup_locations = $item1->pickup_locations( { patron => $patron1 } )->as_list; |
| 378 |
is( scalar @$pickup_locations, $all_count - 1, "With a transfer limits we get back the libraries that are pickup locations minus 1 limited library"); |
| 379 |
|
| 380 |
$builder->build_object( |
| 381 |
{ |
| 382 |
class => 'Koha::Item::Transfer::Limits', |
| 383 |
value => { |
| 384 |
toBranch => $library4->branchcode, |
| 385 |
fromBranch => $library2->branchcode, |
| 386 |
itemtype => $item1->itype, |
| 387 |
ccode => undef, |
| 388 |
} |
| 389 |
} |
| 390 |
); |
| 391 |
|
| 392 |
$pickup_locations = $item1->pickup_locations( { patron => $patron1 } )->as_list; |
| 393 |
is( scalar @$pickup_locations, $all_count - 2, "With 2 transfer limits we get back the libraries that are pickup locations minus 2 limited libraries"); |
| 394 |
|
| 395 |
t::lib::Mocks::mock_preference('BranchTransferLimitsType', 'ccode'); |
| 396 |
$pickup_locations = $item1->pickup_locations( { patron => $patron1 } )->as_list; |
| 397 |
is( scalar @$pickup_locations, $all_count, "With no transfer limits of type ccode we get back the libraries that are pickup locations"); |
| 398 |
|
| 399 |
$pickup_locations = $item_no_ccode->pickup_locations( { patron => $patron1 } )->as_list; |
| 400 |
is( scalar @$pickup_locations, $all_count, "With no transfer limits of type ccode and an item with no ccode we get back the libraries that are pickup locations"); |
| 401 |
|
| 402 |
$builder->build_object( |
| 403 |
{ |
| 404 |
class => 'Koha::Item::Transfer::Limits', |
| 405 |
value => { |
| 406 |
toBranch => $library2->branchcode, |
| 407 |
fromBranch => $library2->branchcode, |
| 408 |
itemtype => undef, |
| 409 |
ccode => $item1->ccode, |
| 410 |
} |
| 411 |
} |
| 412 |
); |
| 413 |
|
| 414 |
$pickup_locations = $item1->pickup_locations( { patron => $patron1 } )->as_list; |
| 415 |
is( scalar @$pickup_locations, $all_count - 1, "With a transfer limits we get back the libraries that are pickup locations minus 1 limited library"); |
| 416 |
|
| 417 |
$builder->build_object( |
| 418 |
{ |
| 419 |
class => 'Koha::Item::Transfer::Limits', |
| 420 |
value => { |
| 421 |
toBranch => $library4->branchcode, |
| 422 |
fromBranch => $library2->branchcode, |
| 423 |
itemtype => undef, |
| 424 |
ccode => $item1->ccode, |
| 425 |
} |
| 426 |
} |
| 427 |
); |
| 428 |
|
| 429 |
$pickup_locations = $item1->pickup_locations( { patron => $patron1 } )->as_list; |
| 430 |
is( scalar @$pickup_locations, $all_count - 2, "With 2 transfer limits we get back the libraries that are pickup locations minus 2 limited libraries"); |
| 431 |
|
| 432 |
t::lib::Mocks::mock_preference('UseBranchTransferLimits', 0); |
| 433 |
|
| 341 |
$schema->storage->txn_rollback; |
434 |
$schema->storage->txn_rollback; |
| 342 |
}; |
435 |
}; |
| 343 |
|
436 |
|