From 26ec9c3a01dbfddc64bb3f757137c5e310d39916 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Fri, 25 May 2018 13:04:40 +0000 Subject: [PATCH] Bug 18163: Unit tests prove -v t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t --- .../Koha/SearchEngine/Elasticsearch/QueryBuilder.t | 42 +++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t b/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t index 025c788..2cb3cb6 100644 --- a/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t +++ b/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 2; +use Test::More tests => 3; use Test::Exception; use Koha::Database; @@ -77,3 +77,43 @@ subtest 'build query from form subtests' => sub { }; + +subtest 'build_query_compat() limit tests' => sub { + plan tests => 6; + + my $builder = Koha::SearchEngine::Elasticsearch::QueryBuilder->new({ 'index' => 'biblios' }), + my @operators = (); + my @operands = (); + my @indexes = (); + my @orig_limits = ('itype:BK'); + my @sort_by = (); + my $scan = undef; + my $lang = undef; + my @params = ( \@operators, \@operands, \@indexes, \@orig_limits, \@sort_by, $scan, $lang ); + my (undef, $query, undef, undef, undef, $limit) = $builder->build_query_compat( @params ); + is( $limit, ( 'itype:BK' ), "We pass through a known type"); + + @orig_limits = ('itype:BK2'); + (undef, $query, undef, undef, undef, $limit) = $builder->build_query_compat( @params ); + is( $limit, ('itype:BK2' ), "We pass through and quote a known type requested as phrase"); + + @orig_limits = ('ti:monkey'); + (undef, $query, undef, undef, undef, $limit) = $builder->build_query_compat( @params ); + is( $limit, ('title:monkey' ), "We convert and pass through a known type"); + + @orig_limits = ('ti,phr:monkey'); + (undef, $query, undef, undef, undef, $limit) = $builder->build_query_compat( @params ); + is( $limit, ('title:"monkey"' ), "We convert, quote, and pass through a known type requested as phrase"); + + @orig_limits = ('monkey:banana'); + (undef, $query, undef, undef, undef, $limit) = $builder->build_query_compat( @params ); + is( $limit, ('monkey:banana' ), "We pass through an unknown type"); + + @orig_limits = ('ti,phr:monkey'); + (undef, $query, undef, undef, undef, $limit) = $builder->build_query_compat( @params ); + is( $limit, ('title:"monkey"' ), "We quote and pass through an unknown type requested as phrase"); + +}; + + + -- 2.1.4