|
Lines 23-29
use C4::Biblio;
Link Here
|
| 23 |
use C4::Branch; |
23 |
use C4::Branch; |
| 24 |
use Koha::Database; |
24 |
use Koha::Database; |
| 25 |
|
25 |
|
| 26 |
use Test::More tests => 8; |
26 |
use t::lib::Mocks; |
|
|
27 |
|
| 28 |
use Test::More tests => 9; |
| 29 |
|
| 27 |
use Test::Warn; |
30 |
use Test::Warn; |
| 28 |
|
31 |
|
| 29 |
BEGIN { |
32 |
BEGIN { |
|
Lines 431-436
subtest 'Koha::Item(s) tests' => sub {
Link Here
|
| 431 |
is( $holdingbranch->branchcode(), $branch2, "Home branch code matches holdingbranch" ); |
434 |
is( $holdingbranch->branchcode(), $branch2, "Home branch code matches holdingbranch" ); |
| 432 |
}; |
435 |
}; |
| 433 |
|
436 |
|
|
|
437 |
subtest 'C4::Biblio::EmbedItemsInMarcBiblio' => sub { |
| 438 |
plan tests => 7; |
| 439 |
|
| 440 |
$dbh->{AutoCommit} = 0; |
| 441 |
$dbh->{RaiseError} = 1; |
| 442 |
|
| 443 |
my ( $biblionumber, $biblioitemnumber ) = get_biblio(); |
| 444 |
my $item_infos = [ |
| 445 |
{ homebranch => 'CPL', holdingbranch => 'CPL' }, |
| 446 |
{ homebranch => 'CPL', holdingbranch => 'CPL' }, |
| 447 |
{ homebranch => 'CPL', holdingbranch => 'CPL' }, |
| 448 |
{ homebranch => 'MPL', holdingbranch => 'MPL' }, |
| 449 |
{ homebranch => 'MPL', holdingbranch => 'MPL' }, |
| 450 |
{ homebranch => 'CPL', holdingbranch => 'MPL' }, |
| 451 |
{ homebranch => 'CPL', holdingbranch => 'MPL' }, |
| 452 |
{ homebranch => 'CPL', holdingbranch => 'MPL' }, |
| 453 |
]; |
| 454 |
my $number_of_items = scalar @$item_infos; |
| 455 |
my $number_of_items_with_homebranch_is_CPL = |
| 456 |
grep { $_->{homebranch} eq 'CPL' } @$item_infos; |
| 457 |
|
| 458 |
my @itemnumbers; |
| 459 |
for my $item_info (@$item_infos) { |
| 460 |
my ( undef, undef, $itemnumber ) = AddItem( |
| 461 |
{ |
| 462 |
homebranch => $item_info->{homebranch}, |
| 463 |
holdingbranch => $item_info->{holdingbanch} |
| 464 |
}, |
| 465 |
$biblionumber |
| 466 |
); |
| 467 |
push @itemnumbers, $itemnumber; |
| 468 |
} |
| 469 |
|
| 470 |
# Emptied the OpacHiddenItems pref |
| 471 |
t::lib::Mocks::mock_preference( 'OpacHiddenItems', '' ); |
| 472 |
|
| 473 |
my ($itemfield) = |
| 474 |
C4::Biblio::GetMarcFromKohaField( 'items.itemnumber', '' ); |
| 475 |
my $record = C4::Biblio::GetMarcBiblio($biblionumber); |
| 476 |
warning_is { C4::Biblio::EmbedItemsInMarcBiblio() } |
| 477 |
{ carped => 'EmbedItemsInMarcBiblio: No MARC record passed' }, |
| 478 |
'Should crap is no record passed.'; |
| 479 |
|
| 480 |
C4::Biblio::EmbedItemsInMarcBiblio( $record, $biblionumber ); |
| 481 |
my @items = $record->field($itemfield); |
| 482 |
is( scalar @items, $number_of_items, 'Should return all items' ); |
| 483 |
|
| 484 |
C4::Biblio::EmbedItemsInMarcBiblio( $record, $biblionumber, |
| 485 |
[ $itemnumbers[1], $itemnumbers[3] ] ); |
| 486 |
@items = $record->field($itemfield); |
| 487 |
is( scalar @items, 2, 'Should return all items present in the list' ); |
| 488 |
|
| 489 |
C4::Biblio::EmbedItemsInMarcBiblio( $record, $biblionumber, undef, 1 ); |
| 490 |
@items = $record->field($itemfield); |
| 491 |
is( scalar @items, $number_of_items, 'Should return all items for opac' ); |
| 492 |
|
| 493 |
my $opachiddenitems = " |
| 494 |
homebranch: ['CPL']"; |
| 495 |
t::lib::Mocks::mock_preference( 'OpacHiddenItems', $opachiddenitems ); |
| 496 |
|
| 497 |
C4::Biblio::EmbedItemsInMarcBiblio( $record, $biblionumber ); |
| 498 |
@items = $record->field($itemfield); |
| 499 |
is( scalar @items, |
| 500 |
$number_of_items, |
| 501 |
'Even with OpacHiddenItems set, all items should have been embeded' ); |
| 502 |
|
| 503 |
C4::Biblio::EmbedItemsInMarcBiblio( $record, $biblionumber, undef, 1 ); |
| 504 |
@items = $record->field($itemfield); |
| 505 |
is( |
| 506 |
scalar @items, |
| 507 |
$number_of_items - $number_of_items_with_homebranch_is_CPL, |
| 508 |
'For OPAC, the pref OpacHiddenItems should have been take into account. Only items with homebranch ne CPL should have been embeded' |
| 509 |
); |
| 510 |
|
| 511 |
$opachiddenitems = " |
| 512 |
homebranch: ['CPL', 'MPL']"; |
| 513 |
t::lib::Mocks::mock_preference( 'OpacHiddenItems', $opachiddenitems ); |
| 514 |
C4::Biblio::EmbedItemsInMarcBiblio( $record, $biblionumber, undef, 1 ); |
| 515 |
@items = $record->field($itemfield); |
| 516 |
is( |
| 517 |
scalar @items, |
| 518 |
0, |
| 519 |
'For OPAC, If all items are hidden, no item should have been embeded' |
| 520 |
); |
| 521 |
}; |
| 522 |
|
| 434 |
# Helper method to set up a Biblio. |
523 |
# Helper method to set up a Biblio. |
| 435 |
sub get_biblio { |
524 |
sub get_biblio { |
| 436 |
my $bib = MARC::Record->new(); |
525 |
my $bib = MARC::Record->new(); |
| 437 |
- |
|
|