Bug 17170: Unit tests

Sponsored-by: Sponsored by: Round Rock Public Library [https://www.roundrocktexas.gov/departments/library/]

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Nick Clemens 2022-04-13 12:17:25 +00:00 committed by Tomas Cohen Arazi
parent fe508be07a
commit 05ee5d10a8
Signed by: tomascohen
GPG key ID: 0A272EA1B2F3C15F
2 changed files with 53 additions and 2 deletions

View file

@ -22,12 +22,13 @@ use Test::Exception;
use Test::Warn;
use t::lib::Mocks;
use t::lib::TestBuilder;
use Test::More tests => 7;
use Test::More tests => 8;
use List::Util qw( all );
use Koha::Database;
use Koha::SearchEngine::Elasticsearch::QueryBuilder;
use Koha::SearchFilters;
my $schema = Koha::Database->new->schema;
$schema->storage->txn_begin;
@ -783,6 +784,31 @@ subtest 'build_query_compat() SearchLimitLibrary tests' => sub {
};
subtest "Handle search filters" => sub {
plan tests => 4;
my $qb;
ok(
$qb = Koha::SearchEngine::Elasticsearch::QueryBuilder->new({ 'index' => 'biblios' }),
'Creating new query builder object for biblios'
);
my $filter = Koha::SearchFilter->new({
name => "test",
query => q|{"operands":["cat","bat","rat"],"indexes":["kw","ti","au"],"operators":["AND","OR"]}|,
limits => q|{"limits":["mc-itype,phr:BK","available"]}|,
})->store;
my $filter_id = $filter->id;
my ( undef, undef, undef, undef, undef, $limit, $limit_cgi, $limit_desc ) = $qb->build_query_compat( undef, undef, undef, ["search_filter:$filter_id"] );
is( $limit,q{(itype:("BK")) AND (onloan:false) AND (((cat) AND title:(bat) OR author:(rat)))},"Limit correctly formed");
is( $limit_cgi,"&limit=search_filter%3A$filter_id","CGI limit is not expanded");
is( $limit_desc,q{(itype:("BK")) AND (onloan:false) AND (((cat) AND title:(bat) OR author:(rat)))},"Limit description is correctly expanded");
};
subtest "_convert_sort_fields() tests" => sub {
plan tests => 3;

View file

@ -17,7 +17,7 @@
use Modern::Perl;
use Test::More tests => 1;
use Test::More tests => 2;
use t::lib::Mocks;
use t::lib::TestBuilder;
use Test::MockModule;
@ -96,3 +96,28 @@ subtest 'build_query_compat() SearchLimitLibrary tests' => sub {
is( $limit_cgi, "&limit=multibranchlimit%3A$groupid", "Limit cgi does not get expanded");
};
subtest "Handle search filters" => sub {
plan tests => 4;
my $qb;
ok(
$qb = Koha::SearchEngine::Zebra::QueryBuilder->new({ 'index' => 'biblios' }),
'Creating new query builder object for biblios'
);
my $filter = Koha::SearchFilter->new({
name => "test",
query => q|{"operands":["cat","bat","rat"],"indexes":["kw","ti","au"],"operators":["AND","OR"]}|,
limits => q|{"limits":["mc-itype,phr:BK","available"]}|,
})->store;
my $filter_id = $filter->id;
my ( undef, undef, undef, undef, undef, $limit, $limit_cgi, $limit_desc ) = $qb->build_query_compat( undef, undef, undef, ["search_filter:$filter_id"] );
is( $limit,q{(kw=(cat) AND ti=(bat) OR au=(rat)) and (mc-itype,phr=BK) and (( (allrecords,AlwaysMatches='') and (not-onloan-count,st-numeric >= 1) and (lost,st-numeric=0) ))},"Limit correctly formed");
is( $limit_cgi,"&limit=search_filter%3A$filter_id","CGI limit is not expanded");
is( $limit_desc,q{(kw=(cat) AND ti=(bat) OR au=(rat)) and (mc-itype,phr=BK) and (( (allrecords,AlwaysMatches='') and (not-onloan-count,st-numeric >= 1) and (lost,st-numeric=0) ))},"Limit description is correctly expanded");
};