From 892d1eb2e96401bb276cf09d7e69e8ff096ba8ca Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Thu, 16 Jul 2026 14:18:05 -0400 Subject: [PATCH] Bug 43101: Add unit tests Signed-off-by: David Nind Signed-off-by: Jonathan Druart Signed-off-by: Lucas Gass --- .../Koha/Database/DataInconsistency.t | 39 ++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/Database/DataInconsistency.t b/t/db_dependent/Koha/Database/DataInconsistency.t index 5e4ab5ed18..606cb3775c 100755 --- a/t/db_dependent/Koha/Database/DataInconsistency.t +++ b/t/db_dependent/Koha/Database/DataInconsistency.t @@ -1,9 +1,10 @@ use Modern::Perl; use Test::NoWarnings; -use Test::More tests => 8; +use Test::More tests => 9; use Test::Warn; +use Koha::Biblios; use Koha::Items; use Koha::Database::DataInconsistency; @@ -465,3 +466,39 @@ subtest 'for_biblio' => sub { }; }; + +subtest 'ids() tests' => sub { + + plan tests => 4; + + $schema->storage->txn_begin(); + + my $biblio_1 = $builder->build_sample_biblio; + my $biblio_2 = $builder->build_sample_biblio; + $builder->build_sample_item( { biblionumber => $biblio_1->biblionumber } ); + $builder->build_sample_item( { biblionumber => $biblio_2->biblionumber } ); + + is_deeply( + Koha::Database::DataInconsistency->ids($biblio_1), + [ $biblio_1->biblionumber ], + 'A single Koha::Object gives an arrayref containing its biblionumber' + ); + + my $biblios = + Koha::Biblios->search( { biblionumber => { -in => [ $biblio_1->biblionumber, $biblio_2->biblionumber ] } } ); + + my $ids = Koha::Database::DataInconsistency->ids($biblios); + is( ref($ids), 'REF', 'A Koha::Objects set gives a subquery instead of a materialized list of ids' ); + like( + ${$ids}->[0], qr/SELECT\s+`?me`?\.`?biblionumber`?\s+FROM\s+`?biblio`?/, + 'The subquery selects biblionumber from biblio' + ); + + my $items = Koha::Items->search( + { 'me.biblionumber' => { -in => $ids } }, + { join => [ 'biblioitem', 'biblio' ] } + ); + is( $items->count, 2, 'The subquery is usable in an IN search' ); + + $schema->storage->txn_rollback(); +};