From ed8b76bdf200fede1a3425d764b0a73dce26c7a3 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 21 Oct 2025 15:37:26 +0200 Subject: [PATCH] Bug 40777: Add tests for empty_title --- .../Koha/Database/DataInconsistency.t | 44 ++++++++++++++++++- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/t/db_dependent/Koha/Database/DataInconsistency.t b/t/db_dependent/Koha/Database/DataInconsistency.t index 445ee4ea7b1..3d773b688a6 100755 --- a/t/db_dependent/Koha/Database/DataInconsistency.t +++ b/t/db_dependent/Koha/Database/DataInconsistency.t @@ -1,7 +1,7 @@ use Modern::Perl; -#use Test::NoWarnings; -use Test::More tests => 5; +use Test::NoWarnings; +use Test::More tests => 7; use Test::Warn; use Koha::Items; @@ -396,3 +396,43 @@ subtest 'nonexistent_AV' => sub { is( scalar(@errors), 1 ); }; }; + +subtest 'empty_title' => sub { + + plan tests => 3; + + $schema->storage->txn_begin(); + + my $biblio_ok = $builder->build_sample_biblio; + my $item_ok = $builder->build_sample_item( { biblionumber => $biblio_ok->biblionumber } ); + my $biblio_ko = $builder->build_sample_biblio; + my $item_ko = $builder->build_sample_item( { biblionumber => $biblio_ko->biblionumber } ); + + my $biblios = Koha::Biblios->search( { biblionumber => [ $biblio_ok->biblionumber, $biblio_ko->biblionumber ] } ); + + subtest 'ok' => sub { + plan tests => 1; + my @errors = Koha::Database::DataInconsistency->empty_title($biblios); + is_deeply( \@errors, [] ); + }; + + subtest 'title => undef' => sub { + plan tests => 1; + $biblio_ko->set( { title => undef } )->store; + my @errors = Koha::Database::DataInconsistency->empty_title($biblios); + is_deeply( + \@errors, + [ sprintf 'Biblio with biblionumber=%s does not have title defined', $biblio_ko->biblionumber ] + ); + }; + + subtest 'title => ""' => sub { + plan tests => 1; + $biblio_ko->set( { title => q{} } )->store; + my @errors = Koha::Database::DataInconsistency->empty_title($biblios); + is_deeply( + \@errors, + [ sprintf 'Biblio with biblionumber=%s does not have title defined', $biblio_ko->biblionumber ] + ); + }; +}; -- 2.34.1