Bugzilla – Attachment 125018 Details for
Bug 28847
Branch limits while searching should be expanded in query building and not in CGI
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 28847: Unit tests
Bug-28847-Unit-tests.patch (text/plain), 12.14 KB, created by
Joonas Kylmälä
on 2021-09-18 08:16:02 UTC
(
hide
)
Description:
Bug 28847: Unit tests
Filename:
MIME Type:
Creator:
Joonas Kylmälä
Created:
2021-09-18 08:16:02 UTC
Size:
12.14 KB
patch
obsolete
>From c4a456fb57283f95defe6aeca75c9d0139f926cd Mon Sep 17 00:00:00 2001 >From: Nick Clemens <nick@bywatersolutions.com> >Date: Thu, 12 Aug 2021 11:11:54 +0000 >Subject: [PATCH] Bug 28847: Unit tests >MIME-Version: 1.0 >Content-Type: text/plain; charset=UTF-8 >Content-Transfer-Encoding: 8bit > >Note: tests are very similar between ES and Zebra, however, ES requires the uppercase >OR and doesn't use '=' in the same way. I feel having test coverage in each module is fair and more future >proof in case of changes to search engine > >Signed-off-by: Andrew Fuerste-Henry <andrew@bywatersolutions.com> > >Signed-off-by: Joonas Kylmälä <joonas.kylmala@iki.fi> >--- > .../SearchEngine/Elasticsearch/QueryBuilder.t | 75 ++++++++++++- > .../Koha/SearchEngine/Zebra/QueryBuilder.t | 101 ++++++++++++++++++ > 2 files changed, 175 insertions(+), 1 deletion(-) > create mode 100755 t/db_dependent/Koha/SearchEngine/Zebra/QueryBuilder.t > >diff --git a/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t b/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t >index 8de1607f40..b322fb8d03 100755 >--- a/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t >+++ b/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t >@@ -22,7 +22,7 @@ use Test::Exception; > use Test::Warn; > use t::lib::Mocks; > use t::lib::TestBuilder; >-use Test::More tests => 6; >+use Test::More tests => 7; > > use List::Util qw( all ); > >@@ -690,6 +690,79 @@ subtest 'build_query with weighted fields tests' => sub { > > }; > >+subtest 'build_query_compat() SearchLimitLibrary tests' => sub { >+ >+ plan tests => 18; >+ >+ $schema->storage->txn_begin; >+ >+ my $builder = t::lib::TestBuilder->new; >+ >+ my $branch_1 = $builder->build_object({ class => 'Koha::Libraries' }); >+ my $branch_2 = $builder->build_object({ class => 'Koha::Libraries' }); >+ my $group = $builder->build_object({ class => 'Koha::Library::Groups', value => { >+ ft_search_groups_opac => 1, >+ ft_search_groups_staff => 1, >+ parent_id => undef, >+ branchcode => undef >+ } >+ }); >+ my $group_1 = $builder->build_object({ class => 'Koha::Library::Groups', value => { >+ parent_id => $group->id, >+ branchcode => $branch_1->id >+ } >+ }); >+ my $group_2 = $builder->build_object({ class => 'Koha::Library::Groups', value => { >+ parent_id => $group->id, >+ branchcode => $branch_2->id >+ } >+ }); >+ my $groupid = $group->id; >+ my @branchcodes = sort { $a cmp $b } ( $branch_1->id, $branch_2->id ); >+ >+ >+ my $query_builder = Koha::SearchEngine::Elasticsearch::QueryBuilder->new({index => $Koha::SearchEngine::BIBLIOS_INDEX}); >+ t::lib::Mocks::mock_preference('SearchLimitLibrary', 'both'); >+ diag(" SearchLimitLibrary set to 'both'"); >+ my ( undef, undef, undef, undef, undef, $limit, $limit_cgi, $limit_desc, undef ) = >+ $query_builder->build_query_compat( undef, undef, undef, [ "branch:CPL" ], undef, undef, undef, undef ); >+ is( $limit, "(homebranch: CPL OR holdingbranch: CPL)", "Branch limit expanded to home/holding branch"); >+ is( $limit_desc, "(homebranch: CPL OR holdingbranch: CPL)", "Limit description correctly expanded"); >+ is( $limit_cgi, "&limit=branch%3ACPL", "Limit cgi does not get expanded"); >+ ( undef, undef, undef, undef, undef, $limit, $limit_cgi, $limit_desc, undef ) = >+ $query_builder->build_query_compat( undef, undef, undef, [ "multibranchlimit:$groupid" ], undef, undef, undef, undef ); >+ is( $limit, "(homebranch: $branchcodes[0] OR homebranch: $branchcodes[1] OR holdingbranch: $branchcodes[0] OR holdingbranch: $branchcodes[1])", "Multibranch limit expanded to home/holding branches"); >+ is( $limit_desc, "(homebranch: $branchcodes[0] OR homebranch: $branchcodes[1] OR holdingbranch: $branchcodes[0] OR holdingbranch: $branchcodes[1])", "Multibranch limit description correctly expanded"); >+ is( $limit_cgi, "&limit=multibranchlimit%3A$groupid", "Multibranch limit cgi does not get expanded"); >+ >+ t::lib::Mocks::mock_preference('SearchLimitLibrary', 'homebranch'); >+ diag(" SearchLimitLibrary set to 'homebranch'"); >+ ( undef, undef, undef, undef, undef, $limit, $limit_cgi, $limit_desc, undef ) = >+ $query_builder->build_query_compat( undef, undef, undef, [ "branch:CPL" ], undef, undef, undef, undef ); >+ is( $limit, "(homebranch: CPL)", "branch limit expanded to home branch"); >+ is( $limit_desc, "(homebranch: CPL)", "limit description correctly expanded"); >+ is( $limit_cgi, "&limit=branch%3ACPL", "limit cgi does not get expanded"); >+ ( undef, undef, undef, undef, undef, $limit, $limit_cgi, $limit_desc, undef ) = >+ $query_builder->build_query_compat( undef, undef, undef, [ "multibranchlimit:$groupid" ], undef, undef, undef, undef ); >+ is( $limit, "(homebranch: $branchcodes[0] OR homebranch: $branchcodes[1])", "branch limit expanded to home branch"); >+ is( $limit_desc, "(homebranch: $branchcodes[0] OR homebranch: $branchcodes[1])", "limit description correctly expanded"); >+ is( $limit_cgi, "&limit=multibranchlimit%3A$groupid", "Limit cgi does not get expanded"); >+ >+ t::lib::Mocks::mock_preference('SearchLimitLibrary', 'holdingbranch'); >+ diag(" SearchLimitLibrary set to 'homebranch'"); >+ ( undef, undef, undef, undef, undef, $limit, $limit_cgi, $limit_desc, undef ) = >+ $query_builder->build_query_compat( undef, undef, undef, [ "branch:CPL" ], undef, undef, undef, undef ); >+ is( $limit, "(holdingbranch: CPL)", "branch limit expanded to holding branch"); >+ is( $limit_desc, "(holdingbranch: CPL)", "Limit description correctly expanded"); >+ is( $limit_cgi, "&limit=branch%3ACPL", "Limit cgi does not get expanded"); >+ ( undef, undef, undef, undef, undef, $limit, $limit_cgi, $limit_desc, undef ) = >+ $query_builder->build_query_compat( undef, undef, undef, [ "multibranchlimit:$groupid" ], undef, undef, undef, undef ); >+ is( $limit, "(holdingbranch: $branchcodes[0] OR holdingbranch: $branchcodes[1])", "branch limit expanded to holding branch"); >+ is( $limit_desc, "(holdingbranch: $branchcodes[0] OR holdingbranch: $branchcodes[1])", "Limit description correctly expanded"); >+ is( $limit_cgi, "&limit=multibranchlimit%3A$groupid", "Limit cgi does not get expanded"); >+ >+}; >+ > subtest "_convert_sort_fields() tests" => sub { > plan tests => 3; > >diff --git a/t/db_dependent/Koha/SearchEngine/Zebra/QueryBuilder.t b/t/db_dependent/Koha/SearchEngine/Zebra/QueryBuilder.t >new file mode 100755 >index 0000000000..f26fc2e516 >--- /dev/null >+++ b/t/db_dependent/Koha/SearchEngine/Zebra/QueryBuilder.t >@@ -0,0 +1,101 @@ >+#!/usr/bin/perl >+# >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+ >+use Test::More tests => 1; >+use t::lib::Mocks; >+use t::lib::TestBuilder; >+use Test::MockModule; >+ >+use Koha::Database; >+use Koha::SearchEngine::Zebra::QueryBuilder; >+ >+my $schema = Koha::Database->new->schema; >+ >+subtest 'build_query_compat() SearchLimitLibrary tests' => sub { >+ >+ plan tests => 18; >+ >+ $schema->storage->txn_begin; >+ >+ my $builder = t::lib::TestBuilder->new; >+ >+ my $branch_1 = $builder->build_object({ class => 'Koha::Libraries' }); >+ my $branch_2 = $builder->build_object({ class => 'Koha::Libraries' }); >+ my $group = $builder->build_object({ class => 'Koha::Library::Groups', value => { >+ ft_search_groups_opac => 1, >+ ft_search_groups_staff => 1, >+ parent_id => undef, >+ branchcode => undef >+ } >+ }); >+ my $group_1 = $builder->build_object({ class => 'Koha::Library::Groups', value => { >+ parent_id => $group->id, >+ branchcode => $branch_1->id >+ } >+ }); >+ my $group_2 = $builder->build_object({ class => 'Koha::Library::Groups', value => { >+ parent_id => $group->id, >+ branchcode => $branch_2->id >+ } >+ }); >+ my $groupid = $group->id; >+ my @branchcodes = sort { $a cmp $b } ( $branch_1->id, $branch_2->id ); >+ >+ >+ my $query_builder = Koha::SearchEngine::Zebra::QueryBuilder->new({index => $Koha::SearchEngine::BIBLIOS_INDEX}); >+ t::lib::Mocks::mock_preference('SearchLimitLibrary', 'both'); >+ diag(" SearchLimitLibrary set to 'both'"); >+ my ( undef, undef, undef, undef, undef, $limit, $limit_cgi, $limit_desc, undef ) = >+ $query_builder->build_query_compat( undef, undef, undef, [ "branch:CPL" ], undef, undef, undef, undef ); >+ is( $limit, "(homebranch= CPL or holdingbranch= CPL)", "Branch limit expanded to home/holding branch"); >+ is( $limit_desc, "(homebranch: CPL or holdingbranch: CPL)", "Limit description correctly expanded"); >+ is( $limit_cgi, "&limit=branch%3ACPL", "Limit cgi does not get expanded"); >+ ( undef, undef, undef, undef, undef, $limit, $limit_cgi, $limit_desc, undef ) = >+ $query_builder->build_query_compat( undef, undef, undef, [ "multibranchlimit:$groupid" ], undef, undef, undef, undef ); >+ is( $limit, "(homebranch= $branchcodes[0] or homebranch= $branchcodes[1] or holdingbranch= $branchcodes[0] or holdingbranch= $branchcodes[1])", "Multibranch limit expanded to home/holding branches"); >+ is( $limit_desc, "(homebranch: $branchcodes[0] or homebranch: $branchcodes[1] or holdingbranch: $branchcodes[0] or holdingbranch: $branchcodes[1])", "Multibranch limit description correctly expanded"); >+ is( $limit_cgi, "&limit=multibranchlimit%3A$groupid", "Multibranch limit cgi does not get expanded"); >+ >+ t::lib::Mocks::mock_preference('SearchLimitLibrary', 'homebranch'); >+ diag(" SearchLimitLibrary set to 'homebranch'"); >+ ( undef, undef, undef, undef, undef, $limit, $limit_cgi, $limit_desc, undef ) = >+ $query_builder->build_query_compat( undef, undef, undef, [ "branch:CPL" ], undef, undef, undef, undef ); >+ is( $limit, "(homebranch= CPL)", "branch limit expanded to home branch"); >+ is( $limit_desc, "(homebranch: CPL)", "limit description correctly expanded"); >+ is( $limit_cgi, "&limit=branch%3ACPL", "limit cgi does not get expanded"); >+ ( undef, undef, undef, undef, undef, $limit, $limit_cgi, $limit_desc, undef ) = >+ $query_builder->build_query_compat( undef, undef, undef, [ "multibranchlimit:$groupid" ], undef, undef, undef, undef ); >+ is( $limit, "(homebranch= $branchcodes[0] or homebranch= $branchcodes[1])", "branch limit expanded to home branch"); >+ is( $limit_desc, "(homebranch: $branchcodes[0] or homebranch: $branchcodes[1])", "limit description correctly expanded"); >+ is( $limit_cgi, "&limit=multibranchlimit%3A$groupid", "Limit cgi does not get expanded"); >+ >+ t::lib::Mocks::mock_preference('SearchLimitLibrary', 'holdingbranch'); >+ diag(" SearchLimitLibrary set to 'homebranch'"); >+ ( undef, undef, undef, undef, undef, $limit, $limit_cgi, $limit_desc, undef ) = >+ $query_builder->build_query_compat( undef, undef, undef, [ "branch:CPL" ], undef, undef, undef, undef ); >+ is( $limit, "(holdingbranch= CPL)", "branch limit expanded to holding branch"); >+ is( $limit_desc, "(holdingbranch: CPL)", "Limit description correctly expanded"); >+ is( $limit_cgi, "&limit=branch%3ACPL", "Limit cgi does not get expanded"); >+ ( undef, undef, undef, undef, undef, $limit, $limit_cgi, $limit_desc, undef ) = >+ $query_builder->build_query_compat( undef, undef, undef, [ "multibranchlimit:$groupid" ], undef, undef, undef, undef ); >+ is( $limit, "(holdingbranch= $branchcodes[0] or holdingbranch= $branchcodes[1])", "branch limit expanded to holding branch"); >+ is( $limit_desc, "(holdingbranch: $branchcodes[0] or holdingbranch: $branchcodes[1])", "Limit description correctly expanded"); >+ is( $limit_cgi, "&limit=multibranchlimit%3A$groupid", "Limit cgi does not get expanded"); >+ >+}; >-- >2.20.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 28847
:
123807
|
123808
|
123809
|
123830
|
123832
|
123833
|
123835
|
123836
|
123837
|
123841
|
124574
|
124575
|
124576
|
124577
|
124797
|
124831
|
125017
| 125018 |
125019
|
125020
|
125021
|
125022
|
126827