From a147759803166b61931937cfc2bde6b459cc76a6 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 16 Jul 2025 12:52:28 +0200 Subject: [PATCH] Bug 40411: Remove warnings from Koha/SearchEngine/Elasticsearch.t Warnings encountered while roundtripping a MARC record to/from USMARC. Failing over to MARCXML. at t/db_dependent/Koha/SearchEngine/Elasticsearch.t line 854. => This one is expected: we have generated a record with large fields item-level_itypes set but no itemtype set for item (1568) at /kohadevbox/koha/Koha/Schema/Result/Item.pm line 1100. item-level_itypes set but no itemtype set for item (1568) at /kohadevbox/koha/Koha/Schema/Result/Item.pm line 1100. => Those 2 ones can be removed by create a biblio and items using build_sample_biblio and build_sample_item --- .../Koha/SearchEngine/Elasticsearch.t | 32 ++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/t/db_dependent/Koha/SearchEngine/Elasticsearch.t b/t/db_dependent/Koha/SearchEngine/Elasticsearch.t index 2e4b3402ec6..66b267fc343 100755 --- a/t/db_dependent/Koha/SearchEngine/Elasticsearch.t +++ b/t/db_dependent/Koha/SearchEngine/Elasticsearch.t @@ -18,7 +18,9 @@ use Modern::Perl; use Encode; -use Test::More tests => 8; +use Test::More tests => 9; +use Test::NoWarnings; +use Test::Warn; use Test::Exception; use t::lib::Mocks; @@ -209,7 +211,7 @@ subtest 'get_elasticsearch_mappings() tests' => sub { subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () tests' => sub { - plan tests => 70; + plan tests => 71; t::lib::Mocks::mock_preference( 'marcflavour', 'MARC21' ); t::lib::Mocks::mock_preference( 'ElasticsearchMARCFormat', 'base64ISO2709' ); @@ -851,7 +853,10 @@ subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () tests' MARC::Field->new( '999', '', '', c => '1234567' ), ); - $docs = $see->marc_records_to_documents( [$marc_record_with_large_field] ); + warning_is { + $docs = $see->marc_records_to_documents( [$marc_record_with_large_field] ); + } + "Warnings encountered while roundtripping a MARC record to/from USMARC. Failing over to MARCXML."; subtest '_process_mappings() split tests' => sub { @@ -1225,21 +1230,18 @@ subtest 'marc_records_to_documents should set the "available" field' => sub { # sort_fields will call this and use the actual db values unless we call it first $see->get_elasticsearch_mappings(); - my $marc_record_1 = MARC::Record->new(); - $marc_record_1->leader(' cam 22 a 4500'); - $marc_record_1->append_fields( - MARC::Field->new( '245', '', '', a => 'Title' ), - ); - my ($biblionumber) = C4::Biblio::AddBiblio( $marc_record_1, '' ); + my $builder = t::lib::TestBuilder->new; + my $biblio = $builder->build_sample_biblio; + my $marc_record_1 = $biblio->metadata->record; my $docs = $see->marc_records_to_documents( [$marc_record_1] ); is_deeply( $docs->[0]->{available}, \0, 'a biblio without items is not available' ); - my $item = Koha::Item->new( + my $item = $builder->build_sample_item( { - biblionumber => $biblionumber, + biblionumber => $biblio->biblionumber, } - )->store(); + ); $docs = $see->marc_records_to_documents( [$marc_record_1] ); is_deeply( $docs->[0]->{available}, \1, 'a biblio with one item that has no particular status is available' ); @@ -1264,11 +1266,11 @@ subtest 'marc_records_to_documents should set the "available" field' => sub { $docs = $see->marc_records_to_documents( [$marc_record_1] ); is_deeply( $docs->[0]->{available}, \1, 'a biblio with one item that is damaged is available' ); - my $item2 = Koha::Item->new( + my $item2 = $builder->build_sample_item( { - biblionumber => $biblionumber, + biblionumber => $biblio->biblionumber, } - )->store(); + ); $docs = $see->marc_records_to_documents( [$marc_record_1] ); is_deeply( $docs->[0]->{available}, \1, -- 2.34.1