Bug 39020: Add tests

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
(cherry picked from commit 5127534f5c)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
This commit is contained in:
Jonathan Druart 2025-02-10 14:10:46 +01:00 committed by Fridolin Somers
parent 6b75fe9034
commit 0ca30deab0
No known key found for this signature in database
GPG Key ID: 9A8E73E2A8B96537
1 changed files with 26 additions and 4 deletions

View File

@ -20,6 +20,7 @@
use Modern::Perl;
use Test::More tests => 4;
use JSON qw( encode_json );
use Koha::Database;
use Koha::SearchFilters;
@ -30,7 +31,8 @@ use t::lib::TestBuilder;
my $schema = Koha::Database->new->schema;
$schema->storage->txn_begin;
my $original_count = Koha::SearchFilters->count();
my $original_count = Koha::SearchFilters->search->count();
my $original_count_opac = Koha::SearchFilters->search( { opac => 1 } )->count();
my $search_filter = Koha::SearchFilter->new(
{
@ -44,18 +46,18 @@ my $search_filter = Koha::SearchFilter->new(
is( Koha::SearchFilters->search()->count(), $original_count + 1, "New filter is added" );
is(
Koha::SearchFilters->search( { opac => 1 } )->count(), $original_count + 1,
Koha::SearchFilters->search( { opac => 1 } )->count(), $original_count_opac + 1,
"Searching by opac returns the filter if set"
);
$search_filter->opac(0)->store();
is(
Koha::SearchFilters->search( { opac => 1 } )->count(), $original_count,
Koha::SearchFilters->search( { opac => 1 } )->count(), $original_count_opac,
"Searching by opac doesn't return the filter if not set"
);
subtest 'expand_filter tests' => sub {
plan tests => 2;
plan tests => 4;
my $search_filter = Koha::SearchFilter->new(
{
@ -72,6 +74,26 @@ subtest 'expand_filter tests' => sub {
is_deeply( $limits, [ 'mc-itype,phr:BK', 'fic:0' ], "Limit from filter is correctly expanded" );
is( $query_limit, '(su=(programming) OR su=(internet))', "Query from filter is correctly expanded and grouped" );
my $empty_query = {
indexes => [ ("kw") x 3 ],
operands => [ ("") x 3 ],
operators => [],
};
$search_filter = Koha::SearchFilter->new(
{
name => "Test",
query => encode_json($empty_query),
limits => q|{"limits":["mc-itype,phr:BK","fic:0"]}|,
opac => 1,
staff_client => 1
}
)->store;
( $limits, $query_limit ) = $search_filter->expand_filter();
is_deeply( $limits, [ 'mc-itype,phr:BK', 'fic:0' ], "Limit from filter is correctly expanded" );
is( $query_limit, '', "Empty query does not generate anything" );
};
$schema->storage->txn_rollback;