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 <MaxeinerGL@gcc.edu>
Signed-off-by: David Cook <dcook@prosentient.com.au>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
Laura_Escamilla 2026-07-01 17:17:45 +00:00 committed by Lucas Gass
parent 2c29581606
commit eeb73bd789
No known key found for this signature in database
GPG Key ID: 60B447398B0D36CA
1 changed files with 58 additions and 0 deletions

View File

@ -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 {