@@ -, +, @@ - Run $ sudo koha-shell kohadev k$ cd kohaclone k$ prove t/db_dependent/Koha_Elasticsearch_Indexer.t \ t/db_dependent/Koha_Elasticsearch.t --- t/db_dependent/Koha_Elasticsearch.t | 12 ++-- t/db_dependent/Koha_Elasticsearch_Indexer.t | 86 ++++++++++++++++++++++++++++- 2 files changed, 91 insertions(+), 7 deletions(-) --- a/t/db_dependent/Koha_Elasticsearch.t +++ a/t/db_dependent/Koha_Elasticsearch.t @@ -79,11 +79,11 @@ subtest 'get_fixer_rules() tests' => sub { my $result = $see->get_fixer_rules(); is( $result->[0], q{marc_map('} . $mappings[0]->{marc_field} . q{','} . $mappings[0]->{name} . q{.$append', -split => 1)}); - is( $result->[1], q{marc_map('} . $mappings[0]->{marc_field} . q{','} . $mappings[0]->{name} . q{__facet', -split => 1)}); + is( $result->[1], q{marc_map('} . $mappings[0]->{marc_field} . q{','} . $mappings[0]->{name} . q{__facet.$append', -split => 1)}); is( $result->[2], q{marc_map('} . $mappings[0]->{marc_field} . q{','} . $mappings[0]->{name} . q{__suggestion.input.$append')}); is( $result->[3], q{marc_map('} . $mappings[0]->{marc_field} . q{','} . $mappings[0]->{name} . q{__sort', -split => 1)}); is( $result->[4], q{marc_map('} . $mappings[1]->{marc_field} . q{','} . $mappings[1]->{name} . q{.$append', -split => 1)}); - is( $result->[5], q{marc_map('} . $mappings[1]->{marc_field} . q{','} . $mappings[1]->{name} . q{__facet', -split => 1)}); + is( $result->[5], q{marc_map('} . $mappings[1]->{marc_field} . q{','} . $mappings[1]->{name} . q{__facet.$append', -split => 1)}); is( $result->[6], q{marc_map('} . $mappings[1]->{marc_field} . q{','} . $mappings[1]->{name} . q{__suggestion.input.$append')}); is( $result->[7], q{marc_map('} . $mappings[1]->{marc_field} . q{','} . $mappings[1]->{name} . q{__sort', -split => 1)}); is( $result->[8], q{move_field(_id,es_id)}); @@ -92,12 +92,12 @@ subtest 'get_fixer_rules() tests' => sub { $mappings[1]->{type} = 'boolean'; $result = $see->get_fixer_rules(); is( $result->[0], q{marc_map('} . $mappings[0]->{marc_field} . q{','} . $mappings[0]->{name} . q{.$append', -split => 1)}); - is( $result->[1], q{marc_map('} . $mappings[0]->{marc_field} . q{','} . $mappings[0]->{name} . q{__facet', -split => 1)}); + is( $result->[1], q{marc_map('} . $mappings[0]->{marc_field} . q{','} . $mappings[0]->{name} . q{__facet.$append', -split => 1)}); is( $result->[2], q{marc_map('} . $mappings[0]->{marc_field} . q{','} . $mappings[0]->{name} . q{__suggestion.input.$append')}); is( $result->[3], q{unless exists('} . $mappings[0]->{name} . q{') add_field('} . $mappings[0]->{name} . q{', 0) end}); is( $result->[4], q{marc_map('} . $mappings[0]->{marc_field} . q{','} . $mappings[0]->{name} . q{__sort', -split => 1)}); is( $result->[5], q{marc_map('} . $mappings[1]->{marc_field} . q{','} . $mappings[1]->{name} . q{.$append', -split => 1)}); - is( $result->[6], q{marc_map('} . $mappings[1]->{marc_field} . q{','} . $mappings[1]->{name} . q{__facet', -split => 1)}); + is( $result->[6], q{marc_map('} . $mappings[1]->{marc_field} . q{','} . $mappings[1]->{name} . q{__facet.$append', -split => 1)}); is( $result->[7], q{marc_map('} . $mappings[1]->{marc_field} . q{','} . $mappings[1]->{name} . q{__suggestion.input.$append')}); is( $result->[8], q{unless exists('} . $mappings[1]->{name} . q{') add_field('} . $mappings[1]->{name} . q{', 0) end}); is( $result->[9], q{marc_map('} . $mappings[1]->{marc_field} . q{','} . $mappings[1]->{name} . q{__sort', -split => 1)}); @@ -107,12 +107,12 @@ subtest 'get_fixer_rules() tests' => sub { $mappings[1]->{type} = 'sum'; $result = $see->get_fixer_rules(); is( $result->[0], q{marc_map('} . $mappings[0]->{marc_field} . q{','} . $mappings[0]->{name} . q{.$append', )}); - is( $result->[1], q{marc_map('} . $mappings[0]->{marc_field} . q{','} . $mappings[0]->{name} . q{__facet', )}); + is( $result->[1], q{marc_map('} . $mappings[0]->{marc_field} . q{','} . $mappings[0]->{name} . q{__facet.$append', )}); is( $result->[2], q{marc_map('} . $mappings[0]->{marc_field} . q{','} . $mappings[0]->{name} . q{__suggestion.input.$append')}); is( $result->[3], q{sum('} . $mappings[0]->{name} . q{')}); is( $result->[4], q{marc_map('} . $mappings[0]->{marc_field} . q{','} . $mappings[0]->{name} . q{__sort', )}); is( $result->[5], q{marc_map('} . $mappings[1]->{marc_field} . q{','} . $mappings[1]->{name} . q{.$append', )}); - is( $result->[6], q{marc_map('} . $mappings[1]->{marc_field} . q{','} . $mappings[1]->{name} . q{__facet', )}); + is( $result->[6], q{marc_map('} . $mappings[1]->{marc_field} . q{','} . $mappings[1]->{name} . q{__facet.$append', )}); is( $result->[7], q{marc_map('} . $mappings[1]->{marc_field} . q{','} . $mappings[1]->{name} . q{__suggestion.input.$append')}); is( $result->[8], q{sum('} . $mappings[1]->{name} . q{')}); is( $result->[9], q{marc_map('} . $mappings[1]->{marc_field} . q{','} . $mappings[1]->{name} . q{__sort', )}); --- a/t/db_dependent/Koha_Elasticsearch_Indexer.t +++ a/t/db_dependent/Koha_Elasticsearch_Indexer.t @@ -60,7 +60,7 @@ SKIP: { subtest '_convert_marc_to_json() tests' => sub { - plan tests => 2; + plan tests => 13; $schema->storage->txn_begin; @@ -117,9 +117,93 @@ subtest '_convert_marc_to_json() tests' => sub { my $importer = Koha::SearchEngine::Elasticsearch::Indexer->new({ index => 'biblios' }); my $conv = $importer->_convert_marc_to_json( \@records )->next(); + is( scalar @{$conv->{author}}, 2, q{Two authors indexed}); is( $conv->{author}[0][0], "Author", "First mapped author should be 100a"); is( $conv->{author}[1][0], "Corp Author", "Second mapped author should be 110a"); + is( scalar @{$conv->{author__facet}}, 2, q{Two author facets}); + is( $conv->{author__facet}[0][0], "Author", "First mapped author facet should be 100a"); + is( $conv->{author__facet}[1][0], "Corp Author", "Second mapped author facet should be 110a"); + + @mappings = ( + { + name => 'author', + type => 'string', + facet => 1, + suggestible => 1, + sort => '~', + marc_type => 'marc21', + marc_field => '100a', + }, + { + name => 'author', + type => 'string', + facet => 0, + suggestible => 1, + sort => '~', + marc_type => 'marc21', + marc_field => '110a', + }, + ); + + $conv = $importer->_convert_marc_to_json( \@records )->next(); + + is( scalar @{$conv->{author__facet}}, 1, q{Only one author facet}); + is( $conv->{author__facet}[0][0], "Author", "Only author facet should be 100a"); + is( $conv->{author__facet}[1], undef, "No facet for 110a"); + + @mappings = ( + { + name => 'author', + type => 'string', + facet => 0, + suggestible => 1, + sort => '~', + marc_type => 'marc21', + marc_field => '100a', + }, + { + name => 'author', + type => 'string', + facet => 1, + suggestible => 1, + sort => '~', + marc_type => 'marc21', + marc_field => '110a', + }, + ); + + $conv = $importer->_convert_marc_to_json( \@records )->next(); + + is( scalar @{$conv->{author__facet}}, 1, q{Only one author facet}); + is( $conv->{author__facet}[0][0], "Corp Author", "Only author facet should be 110a"); + is( $conv->{author__facet}[1], undef, "No facet for 100a"); + + @mappings = ( + { + name => 'author', + type => 'string', + facet => 0, + suggestible => 1, + sort => '~', + marc_type => 'marc21', + marc_field => '100a', + }, + { + name => 'author', + type => 'string', + facet => 0, + suggestible => 1, + sort => '~', + marc_type => 'marc21', + marc_field => '110a', + }, + ); + + $conv = $importer->_convert_marc_to_json( \@records )->next(); + + is( $conv->{author__facet}, undef, q{No author facet}); + $schema->storage->txn_rollback; }; --