|
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 340-345
subtest 'SearchItems test' => sub {
Link Here
|
| 340 |
$dbh->rollback; |
343 |
$dbh->rollback; |
| 341 |
}; |
344 |
}; |
| 342 |
|
345 |
|
|
|
346 |
subtest '' => sub { |
| 347 |
plan tests => 6; |
| 348 |
|
| 349 |
$dbh->{AutoCommit} = 0; |
| 350 |
$dbh->{RaiseError} = 1; |
| 351 |
|
| 352 |
my ( $biblionumber, $biblioitemnumber ) = get_biblio(); |
| 353 |
my $item_infos = [ |
| 354 |
{ homebranch => 'CPL', holdingbranch => 'CPL' }, |
| 355 |
{ homebranch => 'CPL', holdingbranch => 'CPL' }, |
| 356 |
{ homebranch => 'CPL', holdingbranch => 'CPL' }, |
| 357 |
{ homebranch => 'MPL', holdingbranch => 'MPL' }, |
| 358 |
{ homebranch => 'MPL', holdingbranch => 'MPL' }, |
| 359 |
{ homebranch => 'CPL', holdingbranch => 'MPL' }, |
| 360 |
{ homebranch => 'CPL', holdingbranch => 'MPL' }, |
| 361 |
{ homebranch => 'CPL', holdingbranch => 'MPL' }, |
| 362 |
]; |
| 363 |
my $number_of_items = scalar @$item_infos; |
| 364 |
my $number_of_items_with_homebranch_is_CPL = |
| 365 |
grep { $_->{homebranch} eq 'CPL' } @$item_infos; |
| 366 |
|
| 367 |
my @itemnumbers; |
| 368 |
for my $item_info (@$item_infos) { |
| 369 |
my ( undef, undef, $itemnumber ) = AddItem( |
| 370 |
{ |
| 371 |
homebranch => $item_info->{homebranch}, |
| 372 |
holdingbranch => $item_info->{holdingbanch} |
| 373 |
}, |
| 374 |
$biblionumber |
| 375 |
); |
| 376 |
push @itemnumbers, $itemnumber; |
| 377 |
} |
| 378 |
|
| 379 |
my ($itemfield) = |
| 380 |
C4::Biblio::GetMarcFromKohaField( 'items.itemnumber', '' ); |
| 381 |
my $record = C4::Biblio::GetMarcBiblio($biblionumber); |
| 382 |
warning_is { C4::Biblio::EmbedItemsInMarcBiblio() } |
| 383 |
{ carped => 'EmbedItemsInMarcBiblio: No MARC record passed' }, |
| 384 |
'Should crap is no record passed.'; |
| 385 |
|
| 386 |
C4::Biblio::EmbedItemsInMarcBiblio( $record, $biblionumber ); |
| 387 |
my @items = $record->field($itemfield); |
| 388 |
is( scalar @items, $number_of_items, 'Should return all items' ); |
| 389 |
|
| 390 |
C4::Biblio::EmbedItemsInMarcBiblio( $record, $biblionumber, |
| 391 |
[ $itemnumbers[1], $itemnumbers[3] ] ); |
| 392 |
@items = $record->field($itemfield); |
| 393 |
is( scalar @items, 2, 'Should return all items present in the list' ); |
| 394 |
|
| 395 |
C4::Biblio::EmbedItemsInMarcBiblio( $record, $biblionumber, undef, 1 ); |
| 396 |
@items = $record->field($itemfield); |
| 397 |
is( scalar @items, $number_of_items, 'Should return all items for opac' ); |
| 398 |
|
| 399 |
my $opachiddenitems = " |
| 400 |
homebranch: ['CPL']"; |
| 401 |
t::lib::Mocks::mock_preference( 'OpacHiddenItems', $opachiddenitems ); |
| 402 |
|
| 403 |
C4::Biblio::EmbedItemsInMarcBiblio( $record, $biblionumber ); |
| 404 |
@items = $record->field($itemfield); |
| 405 |
is( scalar @items, |
| 406 |
$number_of_items, |
| 407 |
'Even with OpacHiddenItems set, all items should have been embeded' ); |
| 408 |
|
| 409 |
C4::Biblio::EmbedItemsInMarcBiblio( $record, $biblionumber, undef, 1 ); |
| 410 |
@items = $record->field($itemfield); |
| 411 |
is( |
| 412 |
scalar @items, |
| 413 |
$number_of_items - $number_of_items_with_homebranch_is_CPL, |
| 414 |
'For OPAC, the pref OpacHiddenItems should have been take into account. Only items with homebranch ne CPL should habe been embeded' |
| 415 |
); |
| 416 |
}; |
| 417 |
|
| 343 |
# Helper method to set up a Biblio. |
418 |
# Helper method to set up a Biblio. |
| 344 |
sub get_biblio { |
419 |
sub get_biblio { |
| 345 |
my $bib = MARC::Record->new(); |
420 |
my $bib = MARC::Record->new(); |
| 346 |
- |
|
|