From 0bc2990b0088624dfaee917b35a313f635957724 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 23 Oct 2023 11:19:27 +0200 Subject: [PATCH] Bug 31383: (bug 29691 follow-up) Remove get_opac_news_by_id We can simply use get here Signed-off-by: Tomas Cohen Arazi --- Koha/Template/Plugin/AdditionalContents.pm | 23 +--------- .../bootstrap/en/modules/opac-main.tt | 2 +- .../Template/Plugin/AdditionalContents.t | 45 +++++-------------- 3 files changed, 14 insertions(+), 56 deletions(-) diff --git a/Koha/Template/Plugin/AdditionalContents.pm b/Koha/Template/Plugin/AdditionalContents.pm index 6d25255a2e..a44de966dc 100644 --- a/Koha/Template/Plugin/AdditionalContents.pm +++ b/Koha/Template/Plugin/AdditionalContents.pm @@ -36,13 +36,14 @@ sub get { my $blocktitle = $params->{blocktitle}; my $lang = $params->{lang} || 'default'; my $library = $params->{library}; + my $id = $params->{id}; my $content = Koha::AdditionalContents->search_for_display( { category => $category, location => $location, lang => $lang, - library_id => $library, + ( $library ? ( library_id => $library ) : () ), } ); @@ -56,26 +57,6 @@ sub get { return; } -sub get_opac_news_by_id { - my ( $self, $params ) = @_; - - my $news_id = $params->{news_id}; - - my $content = Koha::AdditionalContents->search( - { - location => ['opac_only', 'staff_and_opac'], - idnew => $news_id, - category => 'news', - } - ); - - if ( $content->count ) { - return { - content => $content, - }; - } -} - 1; =head1 NAME diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-main.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-main.tt index bc541e0f9a..e8cf85bc9d 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-main.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-main.tt @@ -89,7 +89,7 @@ [% END %] [% IF news_id %] - [% SET koha_news = AdditionalContents.get_opac_news_by_id( news_id => news_id ) %] + [% SET koha_news = AdditionalContents.get( category => 'news', location => ['opac_only', 'staff_and_opac'], lang => lang, news_id => news_id ) %] [% ELSE %] [% SET koha_news = AdditionalContents.get( category => 'news', location => ['opac_only', 'staff_and_opac'], lang => lang, library => branchcode ) %] [% END %] diff --git a/t/db_dependent/Template/Plugin/AdditionalContents.t b/t/db_dependent/Template/Plugin/AdditionalContents.t index 2dce9cc444..cf30973e1e 100755 --- a/t/db_dependent/Template/Plugin/AdditionalContents.t +++ b/t/db_dependent/Template/Plugin/AdditionalContents.t @@ -16,7 +16,7 @@ use Modern::Perl; -use Test::More tests => 2; +use Test::More tests => 1; use C4::Context; use Koha::Caches; @@ -37,15 +37,23 @@ subtest 'get' => sub { my $additional_contents = Koha::Template::Plugin::AdditionalContents->get({ category => 'news', location => ['opac_only', 'staff_and_opac'], lang => 'default', library => '%' }); my $before_count = $additional_contents ? $additional_contents->{content}->count() : 0; - $builder->build_object({ + my $additional_content = $builder->build_object({ class => 'Koha::AdditionalContents', value => { category => 'news', location => 'opac_only', - lang => 'default', branchcode => undef } }); + $builder->build_object( + { + class => 'Koha::AdditionalContentsLocalizations', + value => { + additional_content_id => $additional_content->id, + lang => 'default', + } + } + ); $additional_contents = Koha::Template::Plugin::AdditionalContents->get({ category => 'news', location => ['opac_only', 'staff_and_opac'], lang => 'default' }); is( $additional_contents->{content}->count, $before_count + 1, "We get the additional one we added"); @@ -54,37 +62,6 @@ subtest 'get' => sub { is( $additional_contents->{blocktitle}, 'blockhead', "Block title is passed through"); -}; - -subtest 'get_opac_news_by_id' => sub { - - plan tests => 4; - - my $news_item = $builder->build_object({ - class => 'Koha::AdditionalContents', - value => { - category => 'news', - location => 'opac_only' - } - }); - - my $fetched_news = Koha::Template::Plugin::AdditionalContents->get_opac_news_by_id({ news_id => $news_item->id }); - is( $fetched_news->{content}->next->content, $news_item->content, "Correct news fetched for opac location" ); - - $news_item->location('staff_and_opac')->store(); - $fetched_news = Koha::Template::Plugin::AdditionalContents->get_opac_news_by_id({ news_id => $news_item->id }); - is( $fetched_news->{content}->next->content, $news_item->content, "Correct news fetched for oac and staff location" ); - - $news_item->location('staff_only')->store(); - $fetched_news = Koha::Template::Plugin::AdditionalContents->get_opac_news_by_id({ news_id => $news_item->id }); - is( $fetched_news, 0, "News item not fetched when location is staff_only" ); - - $news_item->location('opac_only')->category('HtmlCustomizations')->store(); - $fetched_news = Koha::Template::Plugin::AdditionalContents->get_opac_news_by_id({ news_id => $news_item->id }); - is( $fetched_news, 0, "News not fetched from a different category" ); - - - }; $schema->storage->txn_rollback; -- 2.39.5