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

(-)a/Koha/Biblio.pm (-1 / +5 lines)
Lines 234-240 sub pickup_locations { Link Here
234
    my $bool = $biblio->hidden_in_opac({ [ rules => $rules ] })
234
    my $bool = $biblio->hidden_in_opac({ [ rules => $rules ] })
235
235
236
Returns true if the biblio matches the hidding criteria defined in $rules.
236
Returns true if the biblio matches the hidding criteria defined in $rules.
237
Returns false otherwise.
237
Returns false otherwise. It involves the I<OpacHiddenItems> and
238
I<OpacHiddenItemsHidesRecord> system preferences.
238
239
239
Takes HASHref that can have the following parameters:
240
Takes HASHref that can have the following parameters:
240
    OPTIONAL PARAMETERS:
241
    OPTIONAL PARAMETERS:
Lines 254-259 sub hidden_in_opac { Link Here
254
255
255
    return 0 unless @items; # Do not hide if there is no item
256
    return 0 unless @items; # Do not hide if there is no item
256
257
258
    # Ok, there are items, don't even try the rules unless OpacHiddenItemsHidesRecord
259
    return 0 unless C4::Context->preference('OpacHiddenItemsHidesRecord');
260
257
    return !(any { !$_->hidden_in_opac({ rules => $rules }) } @items);
261
    return !(any { !$_->hidden_in_opac({ rules => $rules }) } @items);
258
}
262
}
259
263
(-)a/t/db_dependent/Koha/Biblio.t (-6 / +25 lines)
Lines 63-75 subtest 'metadata() tests' => sub { Link Here
63
63
64
subtest 'hidden_in_opac() tests' => sub {
64
subtest 'hidden_in_opac() tests' => sub {
65
65
66
    plan tests => 4;
66
    plan tests => 6;
67
67
68
    $schema->storage->txn_begin;
68
    $schema->storage->txn_begin;
69
69
70
    my $biblio = $builder->build_sample_biblio();
70
    my $biblio = $builder->build_sample_biblio();
71
    my $rules  = { withdrawn => [ 2 ] };
72
73
    t::lib::Mocks::mock_preference( 'OpacHiddenItemsHidesRecord', 0 );
71
74
72
    ok( !$biblio->hidden_in_opac({ rules => { withdrawn => [ 2 ] } }), 'Biblio not hidden if there is no item attached' );
75
    ok(
76
        !$biblio->hidden_in_opac({ rules => $rules }),
77
        'Biblio not hidden if there is no item attached (!OpacHiddenItemsHidesRecord)'
78
    );
79
80
    t::lib::Mocks::mock_preference( 'OpacHiddenItemsHidesRecord', 1 );
81
82
    ok(
83
        !$biblio->hidden_in_opac({ rules => $rules }),
84
        'Biblio not hidden if there is no item attached (OpacHiddenItemsHidesRecord)'
85
    );
73
86
74
    my $item_1 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber });
87
    my $item_1 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber });
75
    my $item_2 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber });
88
    my $item_2 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber });
Lines 77-93 subtest 'hidden_in_opac() tests' => sub { Link Here
77
    $item_1->withdrawn( 1 )->store->discard_changes;
90
    $item_1->withdrawn( 1 )->store->discard_changes;
78
    $item_2->withdrawn( 1 )->store->discard_changes;
91
    $item_2->withdrawn( 1 )->store->discard_changes;
79
92
80
    ok( !$biblio->hidden_in_opac({ rules => { withdrawn => [ 2 ] } }), 'Biblio not hidden' );
93
    ok( !$biblio->hidden_in_opac({ rules => $rules }), 'Biblio not hidden' );
81
94
82
    $item_2->withdrawn( 2 )->store->discard_changes;
95
    $item_2->withdrawn( 2 )->store->discard_changes;
83
    $biblio->discard_changes; # refresh
96
    $biblio->discard_changes; # refresh
84
97
85
    ok( !$biblio->hidden_in_opac({ rules => { withdrawn => [ 2 ] } }), 'Biblio not hidden' );
98
    ok( !$biblio->hidden_in_opac({ rules => $rules }), 'Biblio not hidden' );
86
99
87
    $item_1->withdrawn( 2 )->store->discard_changes;
100
    $item_1->withdrawn( 2 )->store->discard_changes;
88
    $biblio->discard_changes; # refresh
101
    $biblio->discard_changes; # refresh
89
102
90
    ok( $biblio->hidden_in_opac({ rules => { withdrawn => [ 2 ] } }), 'Biblio hidden' );
103
    ok( $biblio->hidden_in_opac({ rules => $rules }), 'Biblio hidden' );
104
105
    t::lib::Mocks::mock_preference( 'OpacHiddenItemsHidesRecord', 0 );
106
    ok(
107
        !$biblio->hidden_in_opac( { rules => $rules } ),
108
        'Biblio hidden (!OpacHiddenItemsHidesRecord)'
109
    );
110
91
111
92
    $schema->storage->txn_rollback;
112
    $schema->storage->txn_rollback;
93
};
113
};
94
- 

Return to bug 18989