From 0dbb41e2ef9f8854bba622b18b4a8f9b7fe2436c Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Mon, 15 May 2017 11:46:00 -0300 Subject: [PATCH] Bug 18434: (QA followup) Move _convert_marc_to_json tests into Indexer.t Signed-off-by: Tomas Cohen Arazi --- t/db_dependent/Koha_Elasticsearch.t | 19 +------- t/db_dependent/Koha_Elasticsearch_Indexer.t | 73 ++++++++++++++++++++++++++++- 2 files changed, 73 insertions(+), 19 deletions(-) diff --git a/t/db_dependent/Koha_Elasticsearch.t b/t/db_dependent/Koha_Elasticsearch.t index b8fdfa6..df76654 100644 --- a/t/db_dependent/Koha_Elasticsearch.t +++ b/t/db_dependent/Koha_Elasticsearch.t @@ -22,8 +22,6 @@ use Test::MockModule; use t::lib::Mocks; use MARC::Record; -use Koha::SearchEngine::Elasticsearch::Indexer; -use JSON::XS; my $schema = Koha::Database->schema; @@ -31,7 +29,7 @@ use_ok('Koha::SearchEngine::Elasticsearch'); subtest 'get_fixer_rules() tests' => sub { - plan tests => 47; + plan tests => 45; $schema->storage->txn_begin; @@ -79,21 +77,6 @@ subtest 'get_fixer_rules() tests' => sub { }, ); - my $marc_record = MARC::Record->new(); - $marc_record->append_fields( - MARC::Field->new( '001', '1234567' ), - MARC::Field->new( '020', '', '', 'a' => '1234567890123' ), - MARC::Field->new( '100', '', '', 'a' => 'Author' ), - MARC::Field->new( '110', '', '', 'a' => 'Corp Author' ), - MARC::Field->new( '245', '', '', 'a' => 'Title' ), - ); - my @records = ( $marc_record ); - - my $importer = Koha::SearchEngine::Elasticsearch::Indexer->new({ index => 'biblios' }); - my $conv = $importer->_convert_marc_to_json( \@records )->next(); - 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"); - 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)}); diff --git a/t/db_dependent/Koha_Elasticsearch_Indexer.t b/t/db_dependent/Koha_Elasticsearch_Indexer.t index 04a8e2a..e08d6c0 100644 --- a/t/db_dependent/Koha_Elasticsearch_Indexer.t +++ b/t/db_dependent/Koha_Elasticsearch_Indexer.t @@ -17,10 +17,16 @@ use Modern::Perl; -use Test::More tests => 5; +use Test::More tests => 6; +use Test::MockModule; +use t::lib::Mocks; use MARC::Record; +use Koha::Database; + +my $schema = Koha::Database->schema(); + use_ok('Koha::SearchEngine::Elasticsearch::Indexer'); my $indexer; @@ -52,4 +58,69 @@ SKIP: { ok( $indexer->update_index(undef,$records), 'Update Index' ); } +subtest '_convert_marc_to_json() tests' => sub { + + plan tests => 2; + + $schema->storage->txn_begin; + + t::lib::Mocks::mock_preference( 'marcflavour', 'MARC21' ); + + my @mappings = ( + { + name => 'author', + type => 'string', + facet => 1, + suggestible => 1, + sort => '~', + marc_type => 'marc21', + marc_field => '100a', + }, + { + name => 'author', + type => 'string', + facet => 1, + suggestible => 1, + sort => '~', + marc_type => 'marc21', + marc_field => '110a', + }, + ); + + + my $se = Test::MockModule->new( 'Koha::SearchEngine::Elasticsearch' ); + $se->mock( '_foreach_mapping', sub { + my ($self, $sub ) = @_; + + foreach my $map ( @mappings ) { + $sub->( + $map->{name}, + $map->{type}, + $map->{facet}, + $map->{suggestible}, + $map->{sort}, + $map->{marc_type}, + $map->{marc_field} + ); + } + }); + + my $marc_record = MARC::Record->new(); + $marc_record->append_fields( + MARC::Field->new( '001', '1234567' ), + MARC::Field->new( '020', '', '', 'a' => '1234567890123' ), + MARC::Field->new( '100', '', '', 'a' => 'Author' ), + MARC::Field->new( '110', '', '', 'a' => 'Corp Author' ), + MARC::Field->new( '245', '', '', 'a' => 'Title' ), + ); + my @records = ( $marc_record ); + + my $importer = Koha::SearchEngine::Elasticsearch::Indexer->new({ index => 'biblios' }); + my $conv = $importer->_convert_marc_to_json( \@records )->next(); + 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"); + + $schema->storage->txn_rollback; +}; + 1; -- 2.7.4