From 20017c042c0f4c217ba0984aebc4f40ef0b9cb93 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Fri, 24 Apr 2020 16:32:06 +0000 Subject: [PATCH] Bug 25278: Unit tests Signed-off-by: Victor Grousset/tuxayo Signed-off-by: Jonathan Druart --- .../SearchEngine/Elasticsearch/QueryBuilder.t | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t b/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t index 3992e09b18..d1e5a5cab3 100644 --- a/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t +++ b/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t @@ -548,10 +548,32 @@ subtest 'build query from form subtests' => sub { }; subtest 'build_query with weighted fields tests' => sub { - plan tests => 4; + plan tests => 6; $se->mock( '_load_elasticsearch_mappings', sub { return { + authorities => { + heading => { + label => 'heading', + type => 'string', + opac => 0, + staff_client => 1, + mappings => [{ + marc_field => '150', + marc_type => 'marc21', + }] + }, + headingmain => { + label => 'headingmain', + type => 'string', + opac => 1, + staff_client => 1, + mappings => [{ + marc_field => '150', + marc_type => 'marc21', + }] + } + }, biblios => { abstract => { label => 'abstract', @@ -636,6 +658,18 @@ subtest 'build_query with weighted fields tests' => sub { ['abstract'], 'Only OPAC search fields are used when opac search is performed' ); + + $qb = Koha::SearchEngine::Elasticsearch::QueryBuilder->new( { index => 'authorities' } ); + ( undef, $query ) = $qb->build_query_compat( undef, ['title:"donald duck"'], undef, undef, + undef, undef, undef, { weighted_fields => 1 }); + $fields = $query->{query}{query_string}{fields}; + is_deeply( [sort @$fields], ['heading','headingmain'],'Authorities fields retrieve for authorities index'); + + ( undef, $query ) = $qb->build_query_compat( undef, ['title:"donald duck"'], undef, undef, + undef, undef, undef, { weighted_fields => 1, is_opac => 1 }); + $fields = $query->{query}{query_string}{fields}; + is_deeply($fields,['headingmain'],'Only opac authorities fields retrieved for authorities index is is_opac'); + }; subtest "_convert_sort_fields() tests" => sub { -- 2.20.1