View | Details | Raw Unified | Return to bug 30576
Collapse All | Expand All

(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search-header.inc (-1 / +2 lines)
Lines 24-30 Link Here
24
        <p><label for="searchfieldstype">Search fields:</label>
24
        <p><label for="searchfieldstype">Search fields:</label>
25
            <select name="searchfieldstype" id="searchfieldstype">
25
            <select name="searchfieldstype" id="searchfieldstype">
26
              [% SET standard = Koha.Preference('DefaultPatronSearchFields') || 'firstname,surname,othernames,cardnumber,userid' %]
26
              [% SET standard = Koha.Preference('DefaultPatronSearchFields') || 'firstname,surname,othernames,cardnumber,userid' %]
27
              [% SET search_options = [ standard, 'surname', 'cardnumber', 'email', 'borrowernumber', 'userid', 'phone', 'address', 'dateofbirth', 'sort1', 'sort2' ] %]
27
              [% default_fields = [ standard, 'surname', 'cardnumber', 'email', 'borrowernumber', 'userid', 'phone', 'address', 'dateofbirth', 'sort1', 'sort2' ] %]
28
              [% search_options = default_fields.merge(standard.split(',')).unique %]
28
              [% FOREACH s_o IN search_options %]
29
              [% FOREACH s_o IN search_options %]
29
                  [% display_name = PROCESS patron_fields name=s_o %]
30
                  [% display_name = PROCESS patron_fields name=s_o %]
30
                  [% NEXT IF !display_name.length %]
31
                  [% NEXT IF !display_name.length %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc (-1 / +2 lines)
Lines 61-67 Link Here
61
                            <label for="searchfieldstype_filter">Search field:</label>
61
                            <label for="searchfieldstype_filter">Search field:</label>
62
                            <select name="searchfieldstype" id="searchfieldstype_filter">
62
                            <select name="searchfieldstype" id="searchfieldstype_filter">
63
                                [% SET standard = Koha.Preference('DefaultPatronSearchFields') || 'firstname,surname,othernames,cardnumber,userid' %]
63
                                [% SET standard = Koha.Preference('DefaultPatronSearchFields') || 'firstname,surname,othernames,cardnumber,userid' %]
64
                                [% SET search_options = [ standard, 'surname', 'cardnumber', 'email', 'borrowernumber', 'userid', 'phone', 'address', 'dateofbirth', 'sort1', 'sort2' ] %]
64
                                [% default_fields = [ standard, 'surname', 'cardnumber', 'email', 'borrowernumber', 'userid', 'phone', 'address', 'dateofbirth', 'sort1', 'sort2' ] %]
65
                                [% search_options = default_fields.merge(standard.split(',')).unique %]
65
                                [% FOREACH s_o IN search_options %]
66
                                [% FOREACH s_o IN search_options %]
66
                                    [% display_name = PROCESS patron_fields name=s_o %]
67
                                    [% display_name = PROCESS patron_fields name=s_o %]
67
                                    [% NEXT IF !display_name %]
68
                                    [% NEXT IF !display_name %]
(-)a/t/db_dependent/selenium/patrons_search.t (-10 / +15 lines)
Lines 51-57 my $base_url = $s->base_url; Link Here
51
my $builder       = t::lib::TestBuilder->new;
51
my $builder       = t::lib::TestBuilder->new;
52
52
53
subtest 'Search patrons' => sub {
53
subtest 'Search patrons' => sub {
54
    plan tests => 17;
54
    plan tests => 23;
55
55
56
    if ( Koha::Patrons->search({surname => {-like => "test_patron_%"}})->count ) {
56
    if ( Koha::Patrons->search({surname => {-like => "test_patron_%"}})->count ) {
57
        BAIL_OUT("Cannot run this test, data we need to create already exist in the DB");
57
        BAIL_OUT("Cannot run this test, data we need to create already exist in the DB");
Lines 142-163 subtest 'Search patrons' => sub { Link Here
142
    C4::Context->set_preference('PatronsPerPage', $PatronsPerPage);
142
    C4::Context->set_preference('PatronsPerPage', $PatronsPerPage);
143
    $driver->get( $base_url . "/members/members-home.pl" );
143
    $driver->get( $base_url . "/members/members-home.pl" );
144
    my @adv_options = $driver->find_elements('//select[@id="searchfieldstype"]/option');
144
    my @adv_options = $driver->find_elements('//select[@id="searchfieldstype"]/option');
145
    is( scalar @adv_options, 13, 'All standard fields are searchable if DefaultPatronSearchFields not set');
146
    is( $adv_options[0]->get_value(), 'firstname,surname,othernames,cardnumber,userid', 'Standard search uses hard coded list when DefaultPatronSearchFields not set');
145
    my @filter_options = $driver->find_elements('//select[@id="searchfieldstype_filter"]/option');
147
    my @filter_options = $driver->find_elements('//select[@id="searchfieldstype_filter"]/option');
146
    is( scalar @adv_options, 11, 'All standard fields are searchable if DefaultPatronSearchFields not set');
148
    is( scalar @filter_options, 13, 'All standard fields are searchable by filter if DefaultPatronSearchFields not set');
147
    is( scalar @filter_options, 11, 'All standard fields are searchable by filter if DefaultPatronSearchFields not set');
149
    is( $filter_options[0]->get_value(), 'firstname,surname,othernames,cardnumber,userid', 'Standard filter uses hard coded list when DefaultPatronSearchFields not set');
148
    C4::Context->set_preference('DefaultPatronSearchFields',"initials");
150
    C4::Context->set_preference('DefaultPatronSearchFields',"firstname,initials");
149
    $driver->get( $base_url . "/members/members-home.pl" );
151
    $driver->get( $base_url . "/members/members-home.pl" );
150
    @adv_options = $driver->find_elements('//select[@id="searchfieldstype"]/option');
152
    @adv_options = $driver->find_elements('//select[@id="searchfieldstype"]/option');
153
    is( scalar @adv_options, 13, 'New option added when DefaultPatronSearchFields is populated with a field');
154
    is( $adv_options[0]->get_value(), 'firstname,initials', 'Standard search uses DefaultPatronSearchFields when populated');
151
    @filter_options = $driver->find_elements('//select[@id="searchfieldstype_filter"]/option');
155
    @filter_options = $driver->find_elements('//select[@id="searchfieldstype_filter"]/option');
152
    is( scalar @adv_options, 12, 'New option added when DefaultPatronSearchFields is populated with a field');
156
    is( scalar @filter_options, 13, 'New filter option added when DefaultPatronSearchFields is populated with a field');
153
    is( scalar @filter_options, 12, 'New filter option added when DefaultPatronSearchFields is populated with a field');
157
    is( $filter_options[0]->get_value(), 'firstname,initials', 'Standard filter uses DefaultPatronSearchFields when populated');
154
    C4::Context->set_preference('DefaultPatronSearchFields',"initials,horses");
158
    C4::Context->set_preference('DefaultPatronSearchFields',"firstname,initials,horses");
155
    $driver->get( $base_url . "/members/members-home.pl" );
159
    $driver->get( $base_url . "/members/members-home.pl" );
156
    @adv_options = $driver->find_elements('//select[@id="searchfieldstype"]/option');
160
    @adv_options = $driver->find_elements('//select[@id="searchfieldstype"]/option');
157
    @filter_options = $driver->find_elements('//select[@id="searchfieldstype_filter"]/option');
161
    @filter_options = $driver->find_elements('//select[@id="searchfieldstype_filter"]/option');
158
    is( scalar @adv_options, 12, 'Invalid option not added when DefaultPatronSearchFields is populated with an invalid field');
162
    is( scalar @adv_options, 13, 'Invalid option not added when DefaultPatronSearchFields is populated with an invalid field');
159
    is( scalar @filter_options, 12, 'Invalid filter option not added when DefaultPatronSearchFields is populated with an invalid field');
163
    is( scalar @filter_options, 13, 'Invalid filter option not added when DefaultPatronSearchFields is populated with an invalid field');
164
    # NOTE: We should probably ensure the bad field is removed from 'standard' search here, else searches are broken
160
    C4::Context->set_preference('DefaultPatronSearchFields',"");
165
    C4::Context->set_preference('DefaultPatronSearchFields',"");
166
    $driver->get( $base_url . "/members/members-home.pl" );
161
    $s->fill_form( { search_patron_filter => 'test_patron' } );
167
    $s->fill_form( { search_patron_filter => 'test_patron' } );
162
    $s->submit_form;
168
    $s->submit_form;
163
    my $first_patron = $patrons[0];
169
    my $first_patron = $patrons[0];
164
- 

Return to bug 30576