From 9fcbf153f035ac9f857306c70f18d029dff9d5f0 Mon Sep 17 00:00:00 2001 From: Josef Moravec Date: Thu, 1 Oct 2020 05:03:52 +0000 Subject: [PATCH] Bug 22544: Update search_for_display to be able to take more types --- Koha/News.pm | 4 ++-- t/db_dependent/Koha/News.t | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Koha/News.pm b/Koha/News.pm index 79f2a2104a..923805fbff 100644 --- a/Koha/News.pm +++ b/Koha/News.pm @@ -75,7 +75,7 @@ sub search_for_display { $search_params->{lang} = [ $params->{type}, '' ]; } elsif ( $params->{type} eq 'opac' && $params->{lang} ) { $search_params->{lang} = [ $params->{lang}, '' ]; - } elsif ( $params->{type} eq 'OpacNavRight' && $params->{lang} ) { + } elsif ( $params->{lang} ) { $search_params->{lang} = $params->{type} . '_' . $params->{lang}; } else { Koha::Exceptions::BadParameter->throw("The type and lang parameters combination is not valid"); @@ -90,7 +90,7 @@ sub search_for_display { return $self->SUPER::search($search_params, { order_by => 'number' }); } -=head3 type +=head3 _type =cut diff --git a/t/db_dependent/Koha/News.t b/t/db_dependent/Koha/News.t index 3d0ba8fc5e..d6b25654d5 100755 --- a/t/db_dependent/Koha/News.t +++ b/t/db_dependent/Koha/News.t @@ -158,7 +158,7 @@ subtest '->author' => sub { subtest '->search_for_display' => sub { - plan tests => 12; + plan tests => 13; $schema->storage->txn_begin; @@ -263,6 +263,9 @@ subtest '->search_for_display' => sub { $news = Koha::News->search_for_display({ library_id => $library2->branchcode}); is($news->count, 2, 'Filtering by library returns right number of news items'); + $news = Koha::News->search_for_display({ type => 'NonExistantType', lang => 'en'}); + is($news->count, 0, 'Non-existant type is searched, but should not find any item'); + throws_ok { Koha::News->search_for_display({type => 'opac'}) } 'Koha::Exceptions::BadParameter', 'Exception raised when type is opac and no language given'; -- 2.11.0