Bug 25278: Unit tests
authorNick Clemens <nick@bywatersolutions.com>
Fri, 24 Apr 2020 16:32:06 +0000 (16:32 +0000)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Mon, 18 May 2020 14:28:25 +0000 (15:28 +0100)
Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t

index 3992e09..d1e5a5c 100644 (file)
@@ -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 {