|
Lines 20-25
Link Here
|
| 20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
| 21 |
|
21 |
|
| 22 |
use Test::More tests => 4; |
22 |
use Test::More tests => 4; |
|
|
23 |
use JSON qw( encode_json ); |
| 23 |
|
24 |
|
| 24 |
use Koha::Database; |
25 |
use Koha::Database; |
| 25 |
use Koha::SearchFilters; |
26 |
use Koha::SearchFilters; |
|
Lines 30-36
use t::lib::TestBuilder;
Link Here
|
| 30 |
my $schema = Koha::Database->new->schema; |
31 |
my $schema = Koha::Database->new->schema; |
| 31 |
$schema->storage->txn_begin; |
32 |
$schema->storage->txn_begin; |
| 32 |
|
33 |
|
| 33 |
my $original_count = Koha::SearchFilters->count(); |
34 |
my $original_count = Koha::SearchFilters->search->count(); |
|
|
35 |
my $original_count_opac = Koha::SearchFilters->search( { opac => 1 } )->count(); |
| 34 |
|
36 |
|
| 35 |
my $search_filter = Koha::SearchFilter->new( |
37 |
my $search_filter = Koha::SearchFilter->new( |
| 36 |
{ |
38 |
{ |
|
Lines 44-61
my $search_filter = Koha::SearchFilter->new(
Link Here
|
| 44 |
|
46 |
|
| 45 |
is( Koha::SearchFilters->search()->count(), $original_count + 1, "New filter is added" ); |
47 |
is( Koha::SearchFilters->search()->count(), $original_count + 1, "New filter is added" ); |
| 46 |
is( |
48 |
is( |
| 47 |
Koha::SearchFilters->search( { opac => 1 } )->count(), $original_count + 1, |
49 |
Koha::SearchFilters->search( { opac => 1 } )->count(), $original_count_opac + 1, |
| 48 |
"Searching by opac returns the filter if set" |
50 |
"Searching by opac returns the filter if set" |
| 49 |
); |
51 |
); |
| 50 |
$search_filter->opac(0)->store(); |
52 |
$search_filter->opac(0)->store(); |
| 51 |
is( |
53 |
is( |
| 52 |
Koha::SearchFilters->search( { opac => 1 } )->count(), $original_count, |
54 |
Koha::SearchFilters->search( { opac => 1 } )->count(), $original_count_opac, |
| 53 |
"Searching by opac doesn't return the filter if not set" |
55 |
"Searching by opac doesn't return the filter if not set" |
| 54 |
); |
56 |
); |
| 55 |
|
57 |
|
| 56 |
subtest 'expand_filter tests' => sub { |
58 |
subtest 'expand_filter tests' => sub { |
| 57 |
|
59 |
|
| 58 |
plan tests => 2; |
60 |
plan tests => 4; |
| 59 |
|
61 |
|
| 60 |
my $search_filter = Koha::SearchFilter->new( |
62 |
my $search_filter = Koha::SearchFilter->new( |
| 61 |
{ |
63 |
{ |
|
Lines 72-77
subtest 'expand_filter tests' => sub {
Link Here
|
| 72 |
is_deeply( $limits, [ 'mc-itype,phr:BK', 'fic:0' ], "Limit from filter is correctly expanded" ); |
74 |
is_deeply( $limits, [ 'mc-itype,phr:BK', 'fic:0' ], "Limit from filter is correctly expanded" ); |
| 73 |
is( $query_limit, '(su=(programming) OR su=(internet))', "Query from filter is correctly expanded and grouped" ); |
75 |
is( $query_limit, '(su=(programming) OR su=(internet))', "Query from filter is correctly expanded and grouped" ); |
| 74 |
|
76 |
|
|
|
77 |
my $empty_query = { |
| 78 |
indexes => [ ("kw") x 3 ], |
| 79 |
operands => [ ("") x 3 ], |
| 80 |
operators => [], |
| 81 |
}; |
| 82 |
$search_filter = Koha::SearchFilter->new( |
| 83 |
{ |
| 84 |
name => "Test", |
| 85 |
query => encode_json($empty_query), |
| 86 |
limits => q|{"limits":["mc-itype,phr:BK","fic:0"]}|, |
| 87 |
opac => 1, |
| 88 |
staff_client => 1 |
| 89 |
} |
| 90 |
)->store; |
| 91 |
|
| 92 |
( $limits, $query_limit ) = $search_filter->expand_filter(); |
| 93 |
|
| 94 |
is_deeply( $limits, [ 'mc-itype,phr:BK', 'fic:0' ], "Limit from filter is correctly expanded" ); |
| 95 |
is( $query_limit, '', "Empty query does not generate anything" ); |
| 96 |
|
| 75 |
}; |
97 |
}; |
| 76 |
|
98 |
|
| 77 |
$schema->storage->txn_rollback; |
99 |
$schema->storage->txn_rollback; |
| 78 |
- |
|
|