@@ -, +, @@ $ kshell k$ prove t/db_dependent/Koha/Items.t --- Koha/Items.pm | 7 +++---- t/db_dependent/Koha/Items.t | 23 +++++++++++++++-------- 2 files changed, 18 insertions(+), 12 deletions(-) --- a/Koha/Items.pm +++ a/Koha/Items.pm @@ -52,18 +52,17 @@ sub filter_by_for_loan { =head3 filter_by_visible_in_opac - my $filered_items = $items->filter_by_visible_in_opac({ rules => $rules }); + my $filered_items = $items->filter_by_visible_in_opac; Returns a new resultset, containing those items that are not expected to be hidden in OPAC. -If no I are passed, it returns the whole resultset, with the only caveat that the -I system preference is honoured. +The I and I system preferences are honoured. =cut sub filter_by_visible_in_opac { my ($self, $params) = @_; - my $rules = $params->{rules} // {}; + my $rules = C4::Context->yaml_preference('OpacHiddenItems') // {}; my $rules_params; foreach my $field (keys %$rules){ --- a/t/db_dependent/Koha/Items.t +++ a/t/db_dependent/Koha/Items.t @@ -1380,41 +1380,48 @@ subtest 'filter_by_visible_in_opac() tests' => sub { } ); - my $rules = {}; + my $rules = undef; + + my $mocked_context = Test::MockModule->new('C4::Context'); + $mocked_context->mock( 'yaml_preference', sub { + return $rules; + }); t::lib::Mocks::mock_preference( 'hidelostitems', 0 ); is( $biblio->items->filter_by_visible_in_opac->count, 6, 'No rules passed, hidelostitems unset' ); + $rules = {}; + t::lib::Mocks::mock_preference( 'hidelostitems', 1 ); is( - $biblio->items->filter_by_visible_in_opac( { rules => $rules } )->count, + $biblio->items->filter_by_visible_in_opac->count, 3, 'No rules passed, hidelostitems set' ); $rules = { withdrawn => [ 1, 2 ] }; is( - $biblio->items->filter_by_visible_in_opac( { rules => $rules } )->count, + $biblio->items->filter_by_visible_in_opac->count, 2, 'Rules on withdrawn, hidelostitems set' ); $rules = { itype => [ $itype_1->itemtype ] }; is( - $biblio->items->filter_by_visible_in_opac( { rules => $rules } )->count, + $biblio->items->filter_by_visible_in_opac->count, 2, 'Rules on itype, hidelostitems set' ); $rules = { withdrawn => [ 1, 2 ], itype => [ $itype_1->itemtype ] }; is( - $biblio->items->filter_by_visible_in_opac( { rules => $rules } )->count, + $biblio->items->filter_by_visible_in_opac->count, 1, 'Rules on itype and withdrawn, hidelostitems set' ); is( - $biblio->items->filter_by_visible_in_opac( { rules => $rules } ) + $biblio->items->filter_by_visible_in_opac ->next->itemnumber, $item_4->itemnumber, 'The right item is returned' @@ -1422,12 +1429,12 @@ subtest 'filter_by_visible_in_opac() tests' => sub { $rules = { withdrawn => [ 1, 2 ], itype => [ $itype_2->itemtype ] }; is( - $biblio->items->filter_by_visible_in_opac( { rules => $rules } )->count, + $biblio->items->filter_by_visible_in_opac->count, 1, 'Rules on itype and withdrawn, hidelostitems set' ); is( - $biblio->items->filter_by_visible_in_opac( { rules => $rules } ) + $biblio->items->filter_by_visible_in_opac ->next->itemnumber, $item_5->itemnumber, 'The right item is returned' --