From 30de4400fb3975befeb7fe523828a82fb808f9e6 Mon Sep 17 00:00:00 2001 From: Chris Cormack Date: Thu, 14 Apr 2016 21:27:10 +0000 Subject: [PATCH] Bug 12478 Increasing test Coverage for Koha::SearchEngine::Elasticsearch::Search Before this patch it was 24.6%, after it is 64% --- Koha/SearchEngine/Elasticsearch/Search.pm | 6 +++--- t/db_dependent/Koha_SearchEngine_Elasticsearch_Search.t | 13 ++++++++++++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/Koha/SearchEngine/Elasticsearch/Search.pm b/Koha/SearchEngine/Elasticsearch/Search.pm index 0950139..cfdad81 100644 --- a/Koha/SearchEngine/Elasticsearch/Search.pm +++ b/Koha/SearchEngine/Elasticsearch/Search.pm @@ -43,7 +43,7 @@ use C4::Context; use Koha::ItemTypes; use Koha::AuthorisedValues; use Koha::SearchEngine::QueryBuilder; - +use MARC::Record; use Catmandu::Store::ElasticSearch; use Data::Dumper; #TODO remove @@ -120,8 +120,8 @@ sub count { Catmandu::Store::ElasticSearch->new( %$params, trace_calls => 0, ) ) unless $self->store; - my $searcher = $self->store->bag->searcher(query => $query); - my $count = $searcher->count(); + my $search = $self->store->bag->search( %$query); + my $count = $search->total() || 0; return $count; } diff --git a/t/db_dependent/Koha_SearchEngine_Elasticsearch_Search.t b/t/db_dependent/Koha_SearchEngine_Elasticsearch_Search.t index 8b41492..631c476 100644 --- a/t/db_dependent/Koha_SearchEngine_Elasticsearch_Search.t +++ b/t/db_dependent/Koha_SearchEngine_Elasticsearch_Search.t @@ -17,7 +17,7 @@ use strict; use warnings; -use Test::More tests => 5; # last test to print +use Test::More tests => 10; # last test to print use Koha::SearchEngine::Elasticsearch::QueryBuilder; my $builder = Koha::SearchEngine::Elasticsearch::QueryBuilder->new( { index => 'mydb' } ); @@ -37,3 +37,14 @@ ok( my $query = $builder->build_query('easy'), 'Build a search query'); ok( my $results = $searcher->search( $query) , 'Do a search ' ); +ok( my $marc = $searcher->json2marc( $results->first ), 'Convert JSON to MARC'); + +is (my $count = $searcher->count( $query ), 0 , 'Get a count of the results, without returning results '); + +ok ($results = $searcher->search_compat( $query ), 'Test search_compat' ); + +ok (($results,$count) = $searcher->search_auth_compat ( $query ), 'Test search_auth_compat' ); + +is ( $count = $searcher->count_auth_use($searcher,1), 0, 'Testing count_auth_use'); + + -- 2.1.4