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 => 6; |
26 |
use t::lib::Mocks; |
|
|
27 |
|
28 |
use Test::More tests => 7; |
29 |
use Test::Warn; |
27 |
|
30 |
|
28 |
BEGIN { |
31 |
BEGIN { |
29 |
use_ok('C4::Items'); |
32 |
use_ok('C4::Items'); |
Lines 386-391
subtest 'SearchItems test' => sub {
Link Here
|
386 |
$dbh->rollback; |
389 |
$dbh->rollback; |
387 |
}; |
390 |
}; |
388 |
|
391 |
|
|
|
392 |
subtest 'C4::Biblio::EmbedItemsInMarcBiblio' => sub { |
393 |
plan tests => 7; |
394 |
|
395 |
$dbh->{AutoCommit} = 0; |
396 |
$dbh->{RaiseError} = 1; |
397 |
|
398 |
my ( $biblionumber, $biblioitemnumber ) = get_biblio(); |
399 |
my $item_infos = [ |
400 |
{ homebranch => 'CPL', holdingbranch => 'CPL' }, |
401 |
{ homebranch => 'CPL', holdingbranch => 'CPL' }, |
402 |
{ homebranch => 'CPL', holdingbranch => 'CPL' }, |
403 |
{ homebranch => 'MPL', holdingbranch => 'MPL' }, |
404 |
{ homebranch => 'MPL', holdingbranch => 'MPL' }, |
405 |
{ homebranch => 'CPL', holdingbranch => 'MPL' }, |
406 |
{ homebranch => 'CPL', holdingbranch => 'MPL' }, |
407 |
{ homebranch => 'CPL', holdingbranch => 'MPL' }, |
408 |
]; |
409 |
my $number_of_items = scalar @$item_infos; |
410 |
my $number_of_items_with_homebranch_is_CPL = |
411 |
grep { $_->{homebranch} eq 'CPL' } @$item_infos; |
412 |
|
413 |
my @itemnumbers; |
414 |
for my $item_info (@$item_infos) { |
415 |
my ( undef, undef, $itemnumber ) = AddItem( |
416 |
{ |
417 |
homebranch => $item_info->{homebranch}, |
418 |
holdingbranch => $item_info->{holdingbanch} |
419 |
}, |
420 |
$biblionumber |
421 |
); |
422 |
push @itemnumbers, $itemnumber; |
423 |
} |
424 |
|
425 |
# Emptied the OpacHiddenItems pref |
426 |
t::lib::Mocks::mock_preference( 'OpacHiddenItems', '' ); |
427 |
|
428 |
my ($itemfield) = |
429 |
C4::Biblio::GetMarcFromKohaField( 'items.itemnumber', '' ); |
430 |
my $record = C4::Biblio::GetMarcBiblio($biblionumber); |
431 |
warning_is { C4::Biblio::EmbedItemsInMarcBiblio() } |
432 |
{ carped => 'EmbedItemsInMarcBiblio: No MARC record passed' }, |
433 |
'Should crap is no record passed.'; |
434 |
|
435 |
C4::Biblio::EmbedItemsInMarcBiblio( $record, $biblionumber ); |
436 |
my @items = $record->field($itemfield); |
437 |
is( scalar @items, $number_of_items, 'Should return all items' ); |
438 |
|
439 |
C4::Biblio::EmbedItemsInMarcBiblio( $record, $biblionumber, |
440 |
[ $itemnumbers[1], $itemnumbers[3] ] ); |
441 |
@items = $record->field($itemfield); |
442 |
is( scalar @items, 2, 'Should return all items present in the list' ); |
443 |
|
444 |
C4::Biblio::EmbedItemsInMarcBiblio( $record, $biblionumber, undef, 1 ); |
445 |
@items = $record->field($itemfield); |
446 |
is( scalar @items, $number_of_items, 'Should return all items for opac' ); |
447 |
|
448 |
my $opachiddenitems = " |
449 |
homebranch: ['CPL']"; |
450 |
t::lib::Mocks::mock_preference( 'OpacHiddenItems', $opachiddenitems ); |
451 |
|
452 |
C4::Biblio::EmbedItemsInMarcBiblio( $record, $biblionumber ); |
453 |
@items = $record->field($itemfield); |
454 |
is( scalar @items, |
455 |
$number_of_items, |
456 |
'Even with OpacHiddenItems set, all items should have been embeded' ); |
457 |
|
458 |
C4::Biblio::EmbedItemsInMarcBiblio( $record, $biblionumber, undef, 1 ); |
459 |
@items = $record->field($itemfield); |
460 |
is( |
461 |
scalar @items, |
462 |
$number_of_items - $number_of_items_with_homebranch_is_CPL, |
463 |
'For OPAC, the pref OpacHiddenItems should have been take into account. Only items with homebranch ne CPL should have been embeded' |
464 |
); |
465 |
|
466 |
$opachiddenitems = " |
467 |
homebranch: ['CPL', 'MPL']"; |
468 |
t::lib::Mocks::mock_preference( 'OpacHiddenItems', $opachiddenitems ); |
469 |
C4::Biblio::EmbedItemsInMarcBiblio( $record, $biblionumber, undef, 1 ); |
470 |
@items = $record->field($itemfield); |
471 |
is( |
472 |
scalar @items, |
473 |
0, |
474 |
'For OPAC, If all items are hidden, no item should have been embeded' |
475 |
); |
476 |
}; |
477 |
|
389 |
# Helper method to set up a Biblio. |
478 |
# Helper method to set up a Biblio. |
390 |
sub get_biblio { |
479 |
sub get_biblio { |
391 |
my $bib = MARC::Record->new(); |
480 |
my $bib = MARC::Record->new(); |
392 |
- |
|
|