From c4985dd2ee530f74ec044bc3557a8af9d211917a 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 Signed-off-by: Martin Renvoize Signed-off-by: Marcel de Rooy Signed-off-by: Jonathan Druart --- 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 4572286b30..d93a07d411 100755 --- a/t/db_dependent/Koha/News.t +++ b/t/db_dependent/Koha/News.t @@ -143,7 +143,7 @@ subtest '->author' => sub { subtest '->search_for_display' => sub { - plan tests => 12; + plan tests => 13; $schema->storage->txn_begin; @@ -248,6 +248,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.39.5