From 2e5a5747840c21968dd34515e88a1ecabbba51df Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Fri, 22 Apr 2022 15:19:29 +0100 Subject: [PATCH] Bug 30576: (follow-up) Corrections to behaviour to reflect unit tests The unit tests highlighted my original patch didn't cover the full preference description. We now replace the 'standard' option with the fields from the preference and we also add those fields as options to the field selection in advanced searches. This patch also adjusts the tests to test for that and reflects the expected changes to the number of options displayed in the select boxes. Signed-off-by: Jonathan Druart --- .../prog/en/includes/patron-search-header.inc | 3 ++- .../prog/en/includes/patron-search.inc | 3 ++- t/db_dependent/selenium/patrons_search.t | 24 ++++++++++++------- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search-header.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search-header.inc index 5a1df7600e6..f5e8dddcded 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search-header.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search-header.inc @@ -24,7 +24,8 @@

[% SET standard = Koha.Preference('DefaultPatronSearchFields') || 'firstname,surname,othernames,cardnumber,userid' %] - [% SET search_options = [ standard, 'surname', 'cardnumber', 'email', 'borrowernumber', 'userid', 'phone', 'address', 'dateofbirth', 'sort1', 'sort2' ] %] + [% default_fields = [ standard, 'surname', 'cardnumber', 'email', 'borrowernumber', 'userid', 'phone', 'address', 'dateofbirth', 'sort1', 'sort2' ] %] + [% search_options = default_fields.merge(standard.split(',')).unique %] [% FOREACH s_o IN search_options %] [% display_name = PROCESS patron_fields name=s_o %] [% NEXT IF !display_name %] diff --git a/t/db_dependent/selenium/patrons_search.t b/t/db_dependent/selenium/patrons_search.t index 8c232b2c15b..8bd4758711b 100755 --- a/t/db_dependent/selenium/patrons_search.t +++ b/t/db_dependent/selenium/patrons_search.t @@ -51,7 +51,7 @@ my $base_url = $s->base_url; my $builder = t::lib::TestBuilder->new; subtest 'Search patrons' => sub { - plan tests => 17; + plan tests => 23; if ( Koha::Patrons->search({surname => {-like => "test_patron_%"}})->count ) { BAIL_OUT("Cannot run this test, data we need to create already exist in the DB"); @@ -142,22 +142,28 @@ subtest 'Search patrons' => sub { C4::Context->set_preference('PatronsPerPage', $PatronsPerPage); $driver->get( $base_url . "/members/members-home.pl" ); my @adv_options = $driver->find_elements('//select[@id="searchfieldstype"]/option'); + is( scalar @adv_options, 13, 'All standard fields are searchable if DefaultPatronSearchFields not set'); + is( $adv_options[0]->get_value(), 'firstname,surname,othernames,cardnumber,userid', 'Standard search uses hard coded list when DefaultPatronSearchFields not set'); my @filter_options = $driver->find_elements('//select[@id="searchfieldstype_filter"]/option'); - is( scalar @adv_options, 11, 'All standard fields are searchable if DefaultPatronSearchFields not set'); - is( scalar @filter_options, 11, 'All standard fields are searchable by filter if DefaultPatronSearchFields not set'); - C4::Context->set_preference('DefaultPatronSearchFields',"initials"); + is( scalar @filter_options, 13, 'All standard fields are searchable by filter if DefaultPatronSearchFields not set'); + is( $filter_options[0]->get_value(), 'firstname,surname,othernames,cardnumber,userid', 'Standard filter uses hard coded list when DefaultPatronSearchFields not set'); + C4::Context->set_preference('DefaultPatronSearchFields',"firstname,initials"); $driver->get( $base_url . "/members/members-home.pl" ); @adv_options = $driver->find_elements('//select[@id="searchfieldstype"]/option'); + is( scalar @adv_options, 13, 'New option added when DefaultPatronSearchFields is populated with a field'); + is( $adv_options[0]->get_value(), 'firstname,initials', 'Standard search uses DefaultPatronSearchFields when populated'); @filter_options = $driver->find_elements('//select[@id="searchfieldstype_filter"]/option'); - is( scalar @adv_options, 12, 'New option added when DefaultPatronSearchFields is populated with a field'); - is( scalar @filter_options, 12, 'New filter option added when DefaultPatronSearchFields is populated with a field'); - C4::Context->set_preference('DefaultPatronSearchFields',"initials,horses"); + is( scalar @filter_options, 13, 'New filter option added when DefaultPatronSearchFields is populated with a field'); + is( $filter_options[0]->get_value(), 'firstname,initials', 'Standard filter uses DefaultPatronSearchFields when populated'); + C4::Context->set_preference('DefaultPatronSearchFields',"firstname,initials,horses"); $driver->get( $base_url . "/members/members-home.pl" ); @adv_options = $driver->find_elements('//select[@id="searchfieldstype"]/option'); @filter_options = $driver->find_elements('//select[@id="searchfieldstype_filter"]/option'); - is( scalar @adv_options, 12, 'Invalid option not added when DefaultPatronSearchFields is populated with an invalid field'); - is( scalar @filter_options, 12, 'Invalid filter option not added when DefaultPatronSearchFields is populated with an invalid field'); + is( scalar @adv_options, 13, 'Invalid option not added when DefaultPatronSearchFields is populated with an invalid field'); + is( scalar @filter_options, 13, 'Invalid filter option not added when DefaultPatronSearchFields is populated with an invalid field'); + # NOTE: We should probably ensure the bad field is removed from 'standard' search here, else searches are broken C4::Context->set_preference('DefaultPatronSearchFields',""); + $driver->get( $base_url . "/members/members-home.pl" ); $s->fill_form( { search_patron_filter => 'test_patron' } ); $s->submit_form; my $first_patron = $patrons[0]; -- 2.25.1