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