View | Details | Raw Unified | Return to bug 12252
Collapse All | Expand All

(-)a/t/db_dependent/Items.t (-2 / +90 lines)
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 'C4::Biblio::EmbedItemsInMarcBiblio' => sub {
347
    plan tests => 7;
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
    # Emptied the OpacHiddenItems pref
380
    t::lib::Mocks::mock_preference( 'OpacHiddenItems', '' );
381
382
    my ($itemfield) =
383
      C4::Biblio::GetMarcFromKohaField( 'items.itemnumber', '' );
384
    my $record = C4::Biblio::GetMarcBiblio($biblionumber);
385
    warning_is { C4::Biblio::EmbedItemsInMarcBiblio() }
386
    { carped => 'EmbedItemsInMarcBiblio: No MARC record passed' },
387
      'Should crap is no record passed.';
388
389
    C4::Biblio::EmbedItemsInMarcBiblio( $record, $biblionumber );
390
    my @items = $record->field($itemfield);
391
    is( scalar @items, $number_of_items, 'Should return all items' );
392
393
    C4::Biblio::EmbedItemsInMarcBiblio( $record, $biblionumber,
394
        [ $itemnumbers[1], $itemnumbers[3] ] );
395
    @items = $record->field($itemfield);
396
    is( scalar @items, 2, 'Should return all items present in the list' );
397
398
    C4::Biblio::EmbedItemsInMarcBiblio( $record, $biblionumber, undef, 1 );
399
    @items = $record->field($itemfield);
400
    is( scalar @items, $number_of_items, 'Should return all items for opac' );
401
402
    my $opachiddenitems = "
403
        homebranch: ['CPL']";
404
    t::lib::Mocks::mock_preference( 'OpacHiddenItems', $opachiddenitems );
405
406
    C4::Biblio::EmbedItemsInMarcBiblio( $record, $biblionumber );
407
    @items = $record->field($itemfield);
408
    is( scalar @items,
409
        $number_of_items,
410
        'Even with OpacHiddenItems set, all items should have been embeded' );
411
412
    C4::Biblio::EmbedItemsInMarcBiblio( $record, $biblionumber, undef, 1 );
413
    @items = $record->field($itemfield);
414
    is(
415
        scalar @items,
416
        $number_of_items - $number_of_items_with_homebranch_is_CPL,
417
'For OPAC, the pref OpacHiddenItems should have been take into account. Only items with homebranch ne CPL should have been embeded'
418
    );
419
420
    $opachiddenitems = "
421
        homebranch: ['CPL', 'MPL']";
422
    t::lib::Mocks::mock_preference( 'OpacHiddenItems', $opachiddenitems );
423
    C4::Biblio::EmbedItemsInMarcBiblio( $record, $biblionumber, undef, 1 );
424
    @items = $record->field($itemfield);
425
    is(
426
        scalar @items,
427
        0,
428
'For OPAC, If all items are hidden, no item should have been embeded'
429
    );
430
};
431
343
# Helper method to set up a Biblio.
432
# Helper method to set up a Biblio.
344
sub get_biblio {
433
sub get_biblio {
345
    my $bib = MARC::Record->new();
434
    my $bib = MARC::Record->new();
346
- 

Return to bug 12252