From 08d2446063952ec22c26aef96ecd20ba574b45bb Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Fri, 6 Dec 2024 11:22:14 -0300 Subject: [PATCH] Bug 38101: Regression tests Signed-off-by: Tomas Cohen Arazi --- .../Koha/SearchEngine/Elasticsearch.t | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/SearchEngine/Elasticsearch.t b/t/db_dependent/Koha/SearchEngine/Elasticsearch.t index 24159799f82..0abdf470017 100755 --- a/t/db_dependent/Koha/SearchEngine/Elasticsearch.t +++ b/t/db_dependent/Koha/SearchEngine/Elasticsearch.t @@ -186,7 +186,7 @@ subtest 'get_elasticsearch_mappings() tests' => sub { subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () tests' => sub { - plan tests => 69; + plan tests => 70; t::lib::Mocks::mock_preference('marcflavour', 'MARC21'); t::lib::Mocks::mock_preference('ElasticsearchMARCFormat', 'ISO2709'); @@ -393,6 +393,16 @@ subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () tests' marc_type => 'marc21', marc_field => '650(avxyz)', }, + { + name => 'note', + type => 'string', + facet => 0, + suggestible => 0, + searchable => 1, + sort => 1, + marc_type => 'marc21', + marc_field => '522a', + }, ); my $se = Test::MockModule->new('Koha::SearchEngine::Elasticsearch'); @@ -755,15 +765,32 @@ subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () tests' my $marc_record_with_large_field = MARC::Record->new(); $marc_record_with_large_field->leader(' cam 22 a 4500'); + my $xs = 'X' x 8191; + my $ys = 'Y' x 8191; + my $zs = 'Z' x 8191 . 'W'; # one extra character so it needs splitting + $marc_record_with_large_field->append_fields( MARC::Field->new( '100', '', '', a => 'Author 1' ), MARC::Field->new( '245', '', '', a => 'Title:', b => 'record with large field' ), MARC::Field->new( '500', '', '', a => 'X' x 15000 ), + MARC::Field->new( '522', '', '', a => "$xs $ys $zs" ), MARC::Field->new( '999', '', '', c => '1234567' ), ); $docs = $see->marc_records_to_documents( [$marc_record_with_large_field] ); + subtest '_process_mappings() split tests' => sub { + + plan tests => 4; + + my $note_indexes = $docs->[0]->{note}; + + is( $note_indexes->[0], $xs, 'First chunk split using the space' ); + is( $note_indexes->[1], $ys, 'Second chunk split using the space' ); + is( $note_indexes->[2], substr( $zs, 0, 8191 ), 'Third chunk is forced to split' ); + is( $note_indexes->[3], substr( $zs, 8191, 1 ), 'Fourth chunk is just the remaining char' ); + }; + is( $docs->[0]->{marc_format}, 'MARCXML', 'For record with large field marc_format should be set correctly' ); $decoded_marc_record = $see->decode_record_from_result( $docs->[0] ); -- 2.47.1