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 {