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 (-18 / +24 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 => 19;
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];
Lines 190-196 subtest 'Search patrons' => sub { Link Here
190
            "Modify patron %s %s (%s) %s (%s) (%s) › Patrons › Koha",
196
            "Modify patron %s %s (%s) %s (%s) (%s) › Patrons › Koha",
191
            $first_patron->title, $first_patron->firstname, $first_patron->othernames, $first_patron->surname, $first_patron->cardnumber,
197
            $first_patron->title, $first_patron->firstname, $first_patron->othernames, $first_patron->surname, $first_patron->cardnumber,
192
            $first_patron->category->description,
198
            $first_patron->category->description,
193
        )
199
        ),
200
        'Page title is correct after following modification link'
194
    );
201
    );
195
202
196
    $driver->get( $base_url . "/members/members-home.pl" );
203
    $driver->get( $base_url . "/members/members-home.pl" );
Lines 200-210 subtest 'Search patrons' => sub { Link Here
200
207
201
    $s->driver->find_element('//*[@id="'.$table_id.'_filter"]//input')->send_keys('test_patron');
208
    $s->driver->find_element('//*[@id="'.$table_id.'_filter"]//input')->send_keys('test_patron');
202
    $s->wait_for_ajax;
209
    $s->wait_for_ajax;
203
    is( $driver->find_element('//div[@id="'.$table_id.'_info"]')->get_text, sprintf('Showing 1 to %s of %s entries (filtered from %s total entries)', $PatronsPerPage, 26, $total_number_of_patrons) );
210
    is( $driver->find_element('//div[@id="'.$table_id.'_info"]')->get_text, sprintf('Showing 1 to %s of %s entries (filtered from %s total entries)', $PatronsPerPage, 26, $total_number_of_patrons), 'Searching in standard brings back correct results' );
204
211
205
    $s->driver->find_element('//table[@id="'.$table_id.'"]//th[@data-filter="libraries"]/select/option[@value="'.$library->branchcode.'"]')->click;
212
    $s->driver->find_element('//table[@id="'.$table_id.'"]//th[@data-filter="libraries"]/select/option[@value="'.$library->branchcode.'"]')->click;
206
    $s->wait_for_ajax;
213
    $s->wait_for_ajax;
207
    is( $driver->find_element('//div[@id="'.$table_id.'_info"]')->get_text, sprintf('Showing 1 to %s of %s entries (filtered from %s total entries)', $PatronsPerPage, 25, $total_number_of_patrons) );
214
    is( $driver->find_element('//div[@id="'.$table_id.'_info"]')->get_text, sprintf('Showing 1 to %s of %s entries (filtered from %s total entries)', $PatronsPerPage, 25, $total_number_of_patrons), 'Filtering on library works in combination with main search' );
208
215
209
    # Reset the filters
216
    # Reset the filters
210
    $driver->find_element('//form[@id="patron_search_form"]//*[@id="clear_search"]')->click();
217
    $driver->find_element('//form[@id="patron_search_form"]//*[@id="clear_search"]')->click();
Lines 212-225 subtest 'Search patrons' => sub { Link Here
212
    $s->wait_for_ajax;
219
    $s->wait_for_ajax;
213
220
214
    # And make sure all the patrons are present
221
    # And make sure all the patrons are present
215
    is( $driver->find_element('//div[@id="'.$table_id.'_info"]')->get_text, sprintf('Showing 1 to %s of %s entries', $PatronsPerPage, $total_number_of_patrons) );
222
    is( $driver->find_element('//div[@id="'.$table_id.'_info"]')->get_text, sprintf('Showing 1 to %s of %s entries', $PatronsPerPage, $total_number_of_patrons), 'Resetting filters works as expected' );
216
223
217
    # Search on non-searchable attribute, we expect no result!
224
    # Search on non-searchable attribute, we expect no result!
218
    $s->fill_form( { search_patron_filter => 'test_attr_1' } );
225
    $s->fill_form( { search_patron_filter => 'test_attr_1' } );
219
    $s->submit_form;
226
    $s->submit_form;
220
    $s->wait_for_ajax;
227
    $s->wait_for_ajax;
221
228
222
    is( $driver->find_element('//div[@id="'.$table_id.'_info"]')->get_text, sprintf('No entries to show (filtered from %s total entries)', $total_number_of_patrons) );
229
    is( $driver->find_element('//div[@id="'.$table_id.'_info"]')->get_text, sprintf('No entries to show (filtered from %s total entries)', $total_number_of_patrons), 'Searching on a non-searchable attribute returns no results' );
223
230
224
    # clear form
231
    # clear form
225
    $driver->find_element('//form[@id="patron_search_form"]//*[@id="clear_search"]')->click();
232
    $driver->find_element('//form[@id="patron_search_form"]//*[@id="clear_search"]')->click();
Lines 228-246 subtest 'Search patrons' => sub { Link Here
228
    $s->submit_form;
235
    $s->submit_form;
229
    $s->wait_for_ajax;
236
    $s->wait_for_ajax;
230
237
231
    is( $driver->find_element('//div[@id="'.$table_id.'_info"]')->get_text, sprintf('Showing 1 to %s of %s entries (filtered from %s total entries)', 2, 2, $total_number_of_patrons) );
238
    is( $driver->find_element('//div[@id="'.$table_id.'_info"]')->get_text, sprintf('Showing 1 to %s of %s entries (filtered from %s total entries)', 2, 2, $total_number_of_patrons), 'Searching on a searchable attribute returns correct results' );
232
239
233
    # Refine search and search for test_patron in all the data using the DT global search
240
    # Refine search and search for test_patron in all the data using the DT global search
234
    # No change in result expected, still 2 patrons
241
    # No change in result expected, still 2 patrons
235
    $s->driver->find_element('//*[@id="'.$table_id.'_filter"]//input')->send_keys('test_patron');
242
    $s->driver->find_element('//*[@id="'.$table_id.'_filter"]//input')->send_keys('test_patron');
236
    $s->wait_for_ajax;
243
    $s->wait_for_ajax;
237
    is( $driver->find_element('//div[@id="'.$table_id.'_info"]')->get_text, sprintf('Showing 1 to %s of %s entries (filtered from %s total entries)', 2, 2, $total_number_of_patrons) );
244
    is( $driver->find_element('//div[@id="'.$table_id.'_info"]')->get_text, sprintf('Showing 1 to %s of %s entries (filtered from %s total entries)', 2, 2, $total_number_of_patrons), 'Refining with DataTables search works to further filter the original query' );
238
245
239
    # Adding the surname of the first patron in the "Name" column
246
    # Adding the surname of the first patron in the "Name" column
240
    # We expect only 1 result
247
    # We expect only 1 result
241
    $s->driver->find_element('//table[@id="'.$table_id.'"]//input[@placeholder="Name search"]')->send_keys($patrons[0]->surname);
248
    $s->driver->find_element('//table[@id="'.$table_id.'"]//input[@placeholder="Name search"]')->send_keys($patrons[0]->surname);
242
    $s->wait_for_ajax;
249
    $s->wait_for_ajax;
243
    is( $driver->find_element('//div[@id="'.$table_id.'_info"]')->get_text, sprintf('Showing 1 to %s of %s entries (filtered from %s total entries)', 1, 1, $total_number_of_patrons) );
250
    is( $driver->find_element('//div[@id="'.$table_id.'_info"]')->get_text, sprintf('Showing 1 to %s of %s entries (filtered from %s total entries)', 1, 1, $total_number_of_patrons), 'Refining with header filters works to further filter the original query' );
244
251
245
    push @cleanup, $_ for @patrons;
252
    push @cleanup, $_ for @patrons;
246
    push @cleanup, $library;
253
    push @cleanup, $library;
247
- 

Return to bug 30576