|
Lines 17-23
Link Here
|
| 17 |
|
17 |
|
| 18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
| 19 |
|
19 |
|
| 20 |
use Test::More tests => 7; |
20 |
use Test::More tests => 8; |
| 21 |
|
21 |
|
| 22 |
use C4::Biblio; |
22 |
use C4::Biblio; |
| 23 |
use Koha::Database; |
23 |
use Koha::Database; |
|
Lines 170-172
subtest 'is_serial() tests' => sub {
Link Here
|
| 170 |
|
170 |
|
| 171 |
$schema->storage->txn_rollback; |
171 |
$schema->storage->txn_rollback; |
| 172 |
}; |
172 |
}; |
|
|
173 |
|
| 174 |
subtest 'pickup_locations' => sub { |
| 175 |
plan tests => 29; |
| 176 |
|
| 177 |
$schema->storage->txn_begin; |
| 178 |
|
| 179 |
my $dbh = C4::Context->dbh; |
| 180 |
|
| 181 |
# Cleanup database |
| 182 |
Koha::Holds->search->delete; |
| 183 |
Koha::Patrons->search->delete; |
| 184 |
Koha::Items->search->delete; |
| 185 |
Koha::Libraries->search->delete; |
| 186 |
$dbh->do('DELETE FROM issues'); |
| 187 |
$dbh->do('DELETE FROM issuingrules'); |
| 188 |
$dbh->do( |
| 189 |
q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed) |
| 190 |
VALUES (?, ?, ?, ?)}, |
| 191 |
{}, |
| 192 |
'*', '*', '*', 25 |
| 193 |
); |
| 194 |
$dbh->do('DELETE FROM circulation_rules'); |
| 195 |
|
| 196 |
my $root1 = $builder->build_object( { class => 'Koha::Library::Groups', value => { ft_local_hold_group => 1 } } ); |
| 197 |
my $root2 = $builder->build_object( { class => 'Koha::Library::Groups', value => { ft_local_hold_group => 1 } } ); |
| 198 |
my $root3 = $builder->build_object( { class => 'Koha::Library::Groups', value => { ft_local_hold_group => 1 } } ); |
| 199 |
|
| 200 |
my $library1 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } ); |
| 201 |
my $library2 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } ); |
| 202 |
my $library3 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 0 } } ); |
| 203 |
my $library4 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } ); |
| 204 |
my $library5 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } ); |
| 205 |
my $library6 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } ); |
| 206 |
my $library7 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } ); |
| 207 |
my $library8 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 0 } } ); |
| 208 |
|
| 209 |
Koha::CirculationRules->set_rules( |
| 210 |
{ |
| 211 |
branchcode => $library1->branchcode, |
| 212 |
itemtype => undef, |
| 213 |
categorycode => undef, |
| 214 |
rules => { |
| 215 |
holdallowed => 1, |
| 216 |
hold_fulfillment_policy => 'any', |
| 217 |
returnbranch => 'any' |
| 218 |
} |
| 219 |
} |
| 220 |
); |
| 221 |
|
| 222 |
Koha::CirculationRules->set_rules( |
| 223 |
{ |
| 224 |
branchcode => $library2->branchcode, |
| 225 |
itemtype => undef, |
| 226 |
categorycode => undef, |
| 227 |
rules => { |
| 228 |
holdallowed => 3, |
| 229 |
hold_fulfillment_policy => 'holdgroup', |
| 230 |
returnbranch => 'any' |
| 231 |
} |
| 232 |
} |
| 233 |
); |
| 234 |
|
| 235 |
Koha::CirculationRules->set_rules( |
| 236 |
{ |
| 237 |
branchcode => $library3->branchcode, |
| 238 |
itemtype => undef, |
| 239 |
categorycode => undef, |
| 240 |
rules => { |
| 241 |
holdallowed => 3, |
| 242 |
hold_fulfillment_policy => 'patrongroup', |
| 243 |
returnbranch => 'any' |
| 244 |
} |
| 245 |
} |
| 246 |
); |
| 247 |
|
| 248 |
Koha::CirculationRules->set_rules( |
| 249 |
{ |
| 250 |
branchcode => $library4->branchcode, |
| 251 |
itemtype => undef, |
| 252 |
categorycode => undef, |
| 253 |
rules => { |
| 254 |
holdallowed => 2, |
| 255 |
hold_fulfillment_policy => 'holdingbranch', |
| 256 |
returnbranch => 'any' |
| 257 |
} |
| 258 |
} |
| 259 |
); |
| 260 |
|
| 261 |
Koha::CirculationRules->set_rules( |
| 262 |
{ |
| 263 |
branchcode => $library5->branchcode, |
| 264 |
itemtype => undef, |
| 265 |
categorycode => undef, |
| 266 |
rules => { |
| 267 |
holdallowed => 2, |
| 268 |
hold_fulfillment_policy => 'homebranch', |
| 269 |
returnbranch => 'any' |
| 270 |
} |
| 271 |
} |
| 272 |
); |
| 273 |
|
| 274 |
Koha::CirculationRules->set_rules( |
| 275 |
{ |
| 276 |
branchcode => $library6->branchcode, |
| 277 |
itemtype => undef, |
| 278 |
categorycode => undef, |
| 279 |
rules => { |
| 280 |
holdallowed => 1, |
| 281 |
hold_fulfillment_policy => 'holdgroup', |
| 282 |
returnbranch => 'any' |
| 283 |
} |
| 284 |
} |
| 285 |
); |
| 286 |
|
| 287 |
Koha::CirculationRules->set_rules( |
| 288 |
{ |
| 289 |
branchcode => $library7->branchcode, |
| 290 |
itemtype => undef, |
| 291 |
categorycode => undef, |
| 292 |
rules => { |
| 293 |
holdallowed => 3, |
| 294 |
hold_fulfillment_policy => 'holdingbranch', |
| 295 |
returnbranch => 'any' |
| 296 |
} |
| 297 |
} |
| 298 |
); |
| 299 |
|
| 300 |
|
| 301 |
Koha::CirculationRules->set_rules( |
| 302 |
{ |
| 303 |
branchcode => $library8->branchcode, |
| 304 |
itemtype => undef, |
| 305 |
categorycode => undef, |
| 306 |
rules => { |
| 307 |
holdallowed => 2, |
| 308 |
hold_fulfillment_policy => 'patrongroup', |
| 309 |
returnbranch => 'any' |
| 310 |
} |
| 311 |
} |
| 312 |
); |
| 313 |
|
| 314 |
my $group1_1 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root1->id, branchcode => $library1->branchcode } } ); |
| 315 |
my $group1_2 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root1->id, branchcode => $library2->branchcode } } ); |
| 316 |
|
| 317 |
my $group2_3 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root2->id, branchcode => $library3->branchcode } } ); |
| 318 |
my $group2_4 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root2->id, branchcode => $library4->branchcode } } ); |
| 319 |
|
| 320 |
my $group3_5 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root3->id, branchcode => $library5->branchcode } } ); |
| 321 |
my $group3_6 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root3->id, branchcode => $library6->branchcode } } ); |
| 322 |
my $group3_7 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root3->id, branchcode => $library7->branchcode } } ); |
| 323 |
my $group3_8 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root3->id, branchcode => $library8->branchcode } } ); |
| 324 |
|
| 325 |
my $biblio1 = $builder->build_object( { class => 'Koha::Biblios', value => {title => '1'} } ); |
| 326 |
my $biblioitem1 = $builder->build_object( { class => 'Koha::Biblioitems', value => { biblionumber => $biblio1->biblionumber } } ); |
| 327 |
my $biblio2 = $builder->build_object( { class => 'Koha::Biblios', value => {title => '2'} } ); |
| 328 |
my $biblioitem2 = $builder->build_object( { class => 'Koha::Biblioitems', value => { biblionumber => $biblio2->biblionumber } } ); |
| 329 |
|
| 330 |
my $item1_1 = Koha::Item->new({ |
| 331 |
biblionumber => $biblio1->biblionumber, |
| 332 |
biblioitemnumber => $biblioitem1->biblioitemnumber, |
| 333 |
homebranch => $library1->branchcode, |
| 334 |
holdingbranch => $library2->branchcode, |
| 335 |
itype => 'test', |
| 336 |
barcode => "item11barcode", |
| 337 |
})->store; |
| 338 |
|
| 339 |
my $item1_3 = Koha::Item->new({ |
| 340 |
biblionumber => $biblio1->biblionumber, |
| 341 |
biblioitemnumber => $biblioitem1->biblioitemnumber, |
| 342 |
homebranch => $library3->branchcode, |
| 343 |
holdingbranch => $library4->branchcode, |
| 344 |
itype => 'test', |
| 345 |
barcode => "item13barcode", |
| 346 |
})->store; |
| 347 |
|
| 348 |
my $item1_7 = Koha::Item->new({ |
| 349 |
biblionumber => $biblio1->biblionumber, |
| 350 |
biblioitemnumber => $biblioitem1->biblioitemnumber, |
| 351 |
homebranch => $library7->branchcode, |
| 352 |
holdingbranch => $library4->branchcode, |
| 353 |
itype => 'test', |
| 354 |
barcode => "item17barcode", |
| 355 |
})->store; |
| 356 |
|
| 357 |
my $item2_2 = Koha::Item->new({ |
| 358 |
biblionumber => $biblio2->biblionumber, |
| 359 |
biblioitemnumber => $biblioitem2->biblioitemnumber, |
| 360 |
homebranch => $library2->branchcode, |
| 361 |
holdingbranch => $library1->branchcode, |
| 362 |
itype => 'test', |
| 363 |
barcode => "item22barcode", |
| 364 |
})->store; |
| 365 |
|
| 366 |
my $item2_4 = Koha::Item->new({ |
| 367 |
biblionumber => $biblio2->biblionumber, |
| 368 |
biblioitemnumber => $biblioitem2->biblioitemnumber, |
| 369 |
homebranch => $library4->branchcode, |
| 370 |
holdingbranch => $library3->branchcode, |
| 371 |
itype => 'test', |
| 372 |
barcode => "item23barcode", |
| 373 |
})->store; |
| 374 |
|
| 375 |
my $item2_6 = Koha::Item->new({ |
| 376 |
biblionumber => $biblio2->biblionumber, |
| 377 |
biblioitemnumber => $biblioitem2->biblioitemnumber, |
| 378 |
homebranch => $library6->branchcode, |
| 379 |
holdingbranch => $library4->branchcode, |
| 380 |
itype => 'test', |
| 381 |
barcode => "item26barcode", |
| 382 |
})->store; |
| 383 |
|
| 384 |
my $patron1 = $builder->build_object( { class => 'Koha::Patrons', value => { firstname=>'1', branchcode => $library1->branchcode } } ); |
| 385 |
my $patron8 = $builder->build_object( { class => 'Koha::Patrons', value => { firstname=>'8', branchcode => $library8->branchcode } } ); |
| 386 |
|
| 387 |
my $results = { |
| 388 |
"ItemHomeLibrary-1-1" => 6, |
| 389 |
"ItemHomeLibrary-1-8" => 1, |
| 390 |
"ItemHomeLibrary-2-1" => 2, |
| 391 |
"ItemHomeLibrary-2-8" => 0, |
| 392 |
"PatronLibrary-1-1" => 6, |
| 393 |
"PatronLibrary-1-8" => 3, |
| 394 |
"PatronLibrary-2-1" => 0, |
| 395 |
"PatronLibrary-2-8" => 3, |
| 396 |
}; |
| 397 |
|
| 398 |
sub _doTest { |
| 399 |
my ( $cbranch, $biblio, $patron, $results ) = @_; |
| 400 |
t::lib::Mocks::mock_preference('ReservesControlBranch', $cbranch); |
| 401 |
|
| 402 |
my @pl = $biblio->pickup_locations( { patron => $patron} ); |
| 403 |
|
| 404 |
foreach my $pickup_location (@pl) { |
| 405 |
is( ref($pickup_location), 'Koha::Library', 'Object type is correct' ); |
| 406 |
} |
| 407 |
|
| 408 |
ok( |
| 409 |
scalar(@pl) == $results->{ $cbranch . '-' |
| 410 |
. $biblio->title . '-' |
| 411 |
. $patron->firstname }, |
| 412 |
'ReservesControlBranch: ' |
| 413 |
. $cbranch |
| 414 |
. ', biblio' |
| 415 |
. $biblio->title |
| 416 |
. ', patron' |
| 417 |
. $patron->firstname |
| 418 |
. ' should return ' |
| 419 |
. $results->{ $cbranch . '-' |
| 420 |
. $biblio->title . '-' |
| 421 |
. $patron->firstname } |
| 422 |
. ' but returns ' |
| 423 |
. scalar(@pl) |
| 424 |
); |
| 425 |
} |
| 426 |
|
| 427 |
foreach my $cbranch ('ItemHomeLibrary','PatronLibrary') { |
| 428 |
foreach my $biblio ($biblio1, $biblio2) { |
| 429 |
foreach my $patron ($patron1, $patron8) { |
| 430 |
_doTest($cbranch, $biblio, $patron, $results); |
| 431 |
} |
| 432 |
} |
| 433 |
} |
| 434 |
|
| 435 |
$schema->storage->txn_rollback; |
| 436 |
}; |