From eeb73bd78966f9b0f29b9487da1c2bcc910619e6 Mon Sep 17 00:00:00 2001 From: Laura_Escamilla Date: Wed, 1 Jul 2026 17:17:45 +0000 Subject: [PATCH] Bug 42973: Unit test Added a unit test to confirm that search_for_display orders manually positioned news first, followed by unnumbered news by publication date descending. Test passes: prove t/db_dependent/Koha/AdditionalContents.t Signed-off-by: Gretchen Maxeiner Signed-off-by: David Cook Signed-off-by: Lucas Gass --- t/db_dependent/Koha/AdditionalContents.t | 58 ++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/t/db_dependent/Koha/AdditionalContents.t b/t/db_dependent/Koha/AdditionalContents.t index b9cf4fadb5..a3fd9f10cf 100755 --- a/t/db_dependent/Koha/AdditionalContents.t +++ b/t/db_dependent/Koha/AdditionalContents.t @@ -304,6 +304,64 @@ subtest '->search_for_display' => sub { # TODO We should add more tests here + my $older_numbered = $builder->build_object( + { + class => 'Koha::AdditionalContents', + value => { + expirationdate => $tomorrow, + published_on => dt_from_string->add( days => -10 ), + category => 'news', + location => 'opac_only', + branchcode => undef, + number => 1, + } + } + ); + $older_numbered->translated_contents( [ { lang => 'default', content => '' } ] ); + + my $newer_unnumbered = $builder->build_object( + { + class => 'Koha::AdditionalContents', + value => { + expirationdate => $tomorrow, + published_on => $today, + category => 'news', + location => 'opac_only', + branchcode => undef, + number => undef, + } + } + ); + + $newer_unnumbered->translated_contents( [ { lang => 'default', content => '' } ] ); + + my $older_unnumbered = $builder->build_object( + { + class => 'Koha::AdditionalContents', + value => { + expirationdate => $tomorrow, + published_on => dt_from_string->add( days => -5 ), + category => 'news', + location => 'opac_only', + branchcode => undef, + number => undef, + } + } + ); + $older_unnumbered->translated_contents( [ { lang => 'default', content => '' } ] ); + + $news = Koha::AdditionalContents->search_for_display( { location => 'opac_only' } ); + + is_deeply( + [ map { $_->additional_content->id } $news->as_list ], + [ + $older_numbered->id, + $newer_unnumbered->id, + $older_unnumbered->id, + ], + 'Numbered news is displayed first, followed by unnumbered news by publication date descending' + ); + $schema->storage->txn_rollback; subtest 'prevent SQL injections' => sub {