Bug 12478 Increasing test Coverage for Koha::SearchEngine::Elasticsearch::Search

Before this patch it was 24.6%, after it is 64%

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Jesse Weaver <jweaver@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>

Signed-off-by: Brendan Gallagher <brendan@bywatersolutions.com>
This commit is contained in:
Chris Cormack 2016-04-14 21:27:10 +00:00 committed by Brendan Gallagher
parent e09834f3aa
commit 7b7b47ca68
2 changed files with 14 additions and 4 deletions

View File

@ -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;
}

View File

@ -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' } );
@ -36,3 +36,13 @@ is( $searcher->index, 'mydb', 'Testing basic accessor' );
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');