Browse Source

Bug 22544: Update search_for_display to be able to take more types

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
master
Josef Moravec 12 months ago
committed by Jonathan Druart
parent
commit
c4985dd2ee
  1. 4
      Koha/News.pm
  2. 5
      t/db_dependent/Koha/News.t

4
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

5
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';

Loading…
Cancel
Save