Lines 24-38
my $original_PatronsPerPage = C4::Context->preference('PatronsPerPage
Link Here
|
24 |
our @cleanup; |
24 |
our @cleanup; |
25 |
our $DT_delay = 1; |
25 |
our $DT_delay = 1; |
26 |
|
26 |
|
27 |
END { |
|
|
28 |
unless ( @cleanup ) { say "WARNING: Cleanup failed!" } |
29 |
C4::Context->set_preference( 'dateformat', $original_dateformat ); |
30 |
C4::Context->set_preference( 'DefaultPatronSearchFields', $original_DefaultPatronSearchFields ); |
31 |
C4::Context->set_preference( 'DefaultPatronSearchMethod', $original_DefaultPatronSearchMethod ); |
32 |
C4::Context->set_preference( 'PatronsPerPage', $original_PatronsPerPage ); |
33 |
$_->delete for @cleanup; |
34 |
}; |
35 |
|
36 |
use C4::Context; |
27 |
use C4::Context; |
37 |
|
28 |
|
38 |
use utf8; |
29 |
use utf8; |
Lines 50-56
eval { require Selenium::Remote::Driver; };
Link Here
|
50 |
if ( $@ ) { |
41 |
if ( $@ ) { |
51 |
plan skip_all => "Selenium::Remote::Driver is needed for selenium tests."; |
42 |
plan skip_all => "Selenium::Remote::Driver is needed for selenium tests."; |
52 |
} else { |
43 |
} else { |
53 |
plan tests => 1; |
44 |
plan tests => 2; |
54 |
} |
45 |
} |
55 |
|
46 |
|
56 |
my $s = t::lib::Selenium->new; |
47 |
my $s = t::lib::Selenium->new; |
Lines 60-78
my $base_url = $s->base_url;
Link Here
|
60 |
my $builder = t::lib::TestBuilder->new; |
51 |
my $builder = t::lib::TestBuilder->new; |
61 |
my $schema = Koha::Database->schema; |
52 |
my $schema = Koha::Database->schema; |
62 |
|
53 |
|
63 |
subtest 'Search patrons' => sub { |
|
|
64 |
plan tests => 27; |
65 |
|
54 |
|
66 |
if ( Koha::Patrons->search({surname => {-like => "test_patron_%"}})->count ) { |
55 |
if ( Koha::Patrons->search({surname => {-like => "test_patron_%"}})->count ) { |
67 |
BAIL_OUT("Cannot run this test, data we need to create already exist in the DB"); |
56 |
BAIL_OUT("Cannot run this test, data we need to create already exist in the DB"); |
68 |
} |
57 |
} |
69 |
my @patrons; |
58 |
|
70 |
my $borrowernotes = q|<strong>just 'a" note</strong> \123 ❤|; |
59 |
my @patrons; |
71 |
my $borrowernotes_displayed = q|just 'a" note \123 ❤|; |
60 |
my $PatronsPerPage = 15; |
72 |
my $branchname = q|<strong>just 'another" library</strong> \123 ❤|; |
61 |
my $borrowernotes = q|<strong>just 'a" note</strong> \123 ❤|; |
73 |
my $firstname = q|<strong>fir's"tname</strong> \123 ❤|; |
62 |
my $borrowernotes_displayed = q|just 'a" note \123 ❤|; |
74 |
my $address = q|<strong>add'res"s</strong> \123 ❤|; |
63 |
my $branchname = q|<strong>just 'another" library</strong> \123 ❤|; |
75 |
my $email = q|a<strong>bad_email</strong>@example\123 ❤.com|; |
64 |
my $firstname = q|<strong>fir's"tname</strong> \123 ❤|; |
|
|
65 |
my $address = q|<strong>add'res"s</strong> \123 ❤|; |
66 |
my $email = q|a<strong>bad_email</strong>@example\123 ❤.com|; |
67 |
my ($attribute_type, $attribute_type_searchable, $attribute_type_searchable_not_default); |
68 |
sub setup { |
76 |
my $patron_category = $builder->build_object( |
69 |
my $patron_category = $builder->build_object( |
77 |
{ |
70 |
{ |
78 |
class => 'Koha::Patron::Categories', |
71 |
class => 'Koha::Patron::Categories', |
Lines 144-150
subtest 'Search patrons' => sub {
Link Here
|
144 |
); |
137 |
); |
145 |
unshift @cleanup, $patron_27; |
138 |
unshift @cleanup, $patron_27; |
146 |
|
139 |
|
147 |
my $attribute_type = Koha::Patron::Attribute::Type->new( |
140 |
$attribute_type = Koha::Patron::Attribute::Type->new( |
148 |
{ |
141 |
{ |
149 |
code => 'my code1', |
142 |
code => 'my code1', |
150 |
description => 'my description1', |
143 |
description => 'my description1', |
Lines 152-158
subtest 'Search patrons' => sub {
Link Here
|
152 |
searched_by_default => 0 |
145 |
searched_by_default => 0 |
153 |
} |
146 |
} |
154 |
)->store; |
147 |
)->store; |
155 |
my $attribute_type_searchable = Koha::Patron::Attribute::Type->new( |
148 |
$attribute_type_searchable = Koha::Patron::Attribute::Type->new( |
156 |
{ |
149 |
{ |
157 |
code => 'my code2', |
150 |
code => 'my code2', |
158 |
description => 'my description2', |
151 |
description => 'my description2', |
Lines 161-167
subtest 'Search patrons' => sub {
Link Here
|
161 |
searched_by_default => 1 |
154 |
searched_by_default => 1 |
162 |
} |
155 |
} |
163 |
)->store; |
156 |
)->store; |
164 |
my $attribute_type_searchable_not_default = Koha::Patron::Attribute::Type->new( |
157 |
$attribute_type_searchable_not_default = Koha::Patron::Attribute::Type->new( |
165 |
{ |
158 |
{ |
166 |
code => 'mycode3', |
159 |
code => 'mycode3', |
167 |
description => 'my description3', |
160 |
description => 'my description3', |
Lines 182-188
subtest 'Search patrons' => sub {
Link Here
|
182 |
{ code => $attribute_type_searchable->code, attribute => 'test_attr_2'}, |
175 |
{ code => $attribute_type_searchable->code, attribute => 'test_attr_2'}, |
183 |
{ code => $attribute_type_searchable_not_default->code, attribute => 'test_attr_3'}, |
176 |
{ code => $attribute_type_searchable_not_default->code, attribute => 'test_attr_3'}, |
184 |
]); |
177 |
]); |
|
|
178 |
C4::Context->set_preference('PatronsPerPage', $PatronsPerPage); |
179 |
} |
185 |
|
180 |
|
|
|
181 |
sub teardown { |
182 |
C4::Context->set_preference( 'dateformat', $original_dateformat ); |
183 |
C4::Context->set_preference( 'DefaultPatronSearchFields', $original_DefaultPatronSearchFields ); |
184 |
C4::Context->set_preference( 'DefaultPatronSearchMethod', $original_DefaultPatronSearchMethod ); |
185 |
C4::Context->set_preference( 'PatronsPerPage', $original_PatronsPerPage ); |
186 |
$_->delete for @cleanup; |
187 |
} |
188 |
|
189 |
subtest 'Search patrons' => sub { |
190 |
plan tests => 27; |
191 |
|
192 |
setup(); |
186 |
my $total_number_of_patrons = Koha::Patrons->search->count; |
193 |
my $total_number_of_patrons = Koha::Patrons->search->count; |
187 |
my $table_id = "memberresultst"; |
194 |
my $table_id = "memberresultst"; |
188 |
|
195 |
|
Lines 190-203
subtest 'Search patrons' => sub {
Link Here
|
190 |
C4::Context->set_preference('DefaultPatronSearchFields',""); |
197 |
C4::Context->set_preference('DefaultPatronSearchFields',""); |
191 |
C4::Context->set_preference('DefaultPatronSearchMethod',"contains"); |
198 |
C4::Context->set_preference('DefaultPatronSearchMethod',"contains"); |
192 |
my $searchable_attributes = Koha::Patron::Attribute::Types->search({ staff_searchable => 1 })->count(); |
199 |
my $searchable_attributes = Koha::Patron::Attribute::Types->search({ staff_searchable => 1 })->count(); |
193 |
my $PatronsPerPage = 15; |
|
|
194 |
my $nb_standard_fields = 13 + $searchable_attributes; # Standard fields, plus one searchable attribute |
200 |
my $nb_standard_fields = 13 + $searchable_attributes; # Standard fields, plus one searchable attribute |
195 |
C4::Context->set_preference('PatronsPerPage', $PatronsPerPage); |
|
|
196 |
$driver->get( $base_url . "/members/members-home.pl" ); |
201 |
$driver->get( $base_url . "/members/members-home.pl" ); |
197 |
my @adv_options = $driver->find_elements('//select[@id="searchfieldstype"]/option'); |
202 |
my @adv_options = $driver->find_elements('//select[@id="searchfieldstype"]/option'); |
198 |
is( scalar @adv_options, $nb_standard_fields + 1, 'All standard fields are searchable if DefaultPatronSearchFields not set. middle_name is there.'); |
203 |
is( scalar @adv_options, $nb_standard_fields + 1, 'All standard fields are searchable if DefaultPatronSearchFields not set. middle_name is there.'); |
199 |
is( $adv_options[0]->get_value(), 'standard', 'Standard search uses value "standard"'); |
204 |
is( $adv_options[0]->get_value(), 'standard', 'Standard search uses value "standard"'); |
200 |
my @filter_options = $driver->find_elements('//select[@id="searchfieldstype_filter"]/option'); |
205 |
my @filter_options = $driver->find_elements('//select[@class="searchfieldstype_filter"]/option'); |
201 |
is( scalar @filter_options, $nb_standard_fields + 1, 'All standard fields + middle_name are searchable by filter if DefaultPatronSearchFields not set'); |
206 |
is( scalar @filter_options, $nb_standard_fields + 1, 'All standard fields + middle_name are searchable by filter if DefaultPatronSearchFields not set'); |
202 |
is( $filter_options[0]->get_value(), 'standard', 'Standard filter uses hard coded value "standard" DefaultPatronSearchFields not set'); |
207 |
is( $filter_options[0]->get_value(), 'standard', 'Standard filter uses hard coded value "standard" DefaultPatronSearchFields not set'); |
203 |
C4::Context->set_preference('DefaultPatronSearchFields',"firstname|initials"); |
208 |
C4::Context->set_preference('DefaultPatronSearchFields',"firstname|initials"); |
Lines 205-223
subtest 'Search patrons' => sub {
Link Here
|
205 |
@adv_options = $driver->find_elements('//select[@id="searchfieldstype"]/option'); |
210 |
@adv_options = $driver->find_elements('//select[@id="searchfieldstype"]/option'); |
206 |
is( scalar @adv_options, $nb_standard_fields, 'New option added when DefaultPatronSearchFields is populated with a field. Note that middle_name disappears, we do not want it if not part of DefaultPatronSearchFields'); |
211 |
is( scalar @adv_options, $nb_standard_fields, 'New option added when DefaultPatronSearchFields is populated with a field. Note that middle_name disappears, we do not want it if not part of DefaultPatronSearchFields'); |
207 |
is( $adv_options[0]->get_value(), 'standard', 'Standard search uses value "standard"'); |
212 |
is( $adv_options[0]->get_value(), 'standard', 'Standard search uses value "standard"'); |
208 |
@filter_options = $driver->find_elements('//select[@id="searchfieldstype_filter"]/option'); |
213 |
@filter_options = $driver->find_elements('//select[@class="searchfieldstype_filter"]/option'); |
209 |
is( scalar @filter_options, $nb_standard_fields, 'New filter option added when DefaultPatronSearchFields is populated with a field'); |
214 |
is( scalar @filter_options, $nb_standard_fields, 'New filter option added when DefaultPatronSearchFields is populated with a field'); |
210 |
is( $filter_options[0]->get_value(), 'standard', 'Standard filter uses value "standard"'); |
215 |
is( $filter_options[0]->get_value(), 'standard', 'Standard filter uses value "standard"'); |
211 |
$driver->get( $base_url . "/members/members-home.pl" ); |
216 |
$driver->get( $base_url . "/members/members-home.pl" ); |
212 |
@adv_options = $driver->find_elements('//select[@id="searchfieldstype"]/option'); |
217 |
@adv_options = $driver->find_elements('//select[@id="searchfieldstype"]/option'); |
213 |
@filter_options = $driver->find_elements('//select[@id="searchfieldstype_filter"]/option'); |
218 |
@filter_options = $driver->find_elements('//select[@class="searchfieldstype_filter"]/option'); |
214 |
is( scalar @adv_options, $nb_standard_fields, 'Invalid option not added when DefaultPatronSearchFields is populated with an invalid field'); |
219 |
is( scalar @adv_options, $nb_standard_fields, 'Invalid option not added when DefaultPatronSearchFields is populated with an invalid field'); |
215 |
is( scalar @filter_options, $nb_standard_fields, 'Invalid filter option not added when DefaultPatronSearchFields is populated with an invalid field'); |
220 |
is( scalar @filter_options, $nb_standard_fields, 'Invalid filter option not added when DefaultPatronSearchFields is populated with an invalid field'); |
216 |
|
221 |
|
217 |
# NOTE: We should probably ensure the bad field is removed from 'standard' search here, else searches are broken |
222 |
# NOTE: We should probably ensure the bad field is removed from 'standard' search here, else searches are broken |
218 |
C4::Context->set_preference('DefaultPatronSearchFields',""); |
223 |
C4::Context->set_preference('DefaultPatronSearchFields',""); |
219 |
$driver->get( $base_url . "/members/members-home.pl" ); |
224 |
$driver->get( $base_url . "/members/members-home.pl" ); |
220 |
$s->fill_form( { search_patron_filter => 'test_patron' } ); |
225 |
$s->fill_form( { 'class=search_patron_filter' => 'test_patron' } ); |
221 |
$s->submit_form; |
226 |
$s->submit_form; |
222 |
my $first_patron = $patrons[0]; |
227 |
my $first_patron = $patrons[0]; |
223 |
|
228 |
|
Lines 254-260
subtest 'Search patrons' => sub {
Link Here
|
254 |
); |
259 |
); |
255 |
|
260 |
|
256 |
$driver->get( $base_url . "/members/members-home.pl" ); |
261 |
$driver->get( $base_url . "/members/members-home.pl" ); |
257 |
$s->fill_form( { search_patron_filter => 'test_patron' } ); |
262 |
$s->fill_form( { 'class=search_patron_filter' => 'test_patron' } ); |
258 |
$s->submit_form; |
263 |
$s->submit_form; |
259 |
sleep $DT_delay && $s->wait_for_ajax; |
264 |
sleep $DT_delay && $s->wait_for_ajax; |
260 |
|
265 |
|
Lines 262-273
subtest 'Search patrons' => sub {
Link Here
|
262 |
sleep $DT_delay && $s->wait_for_ajax; |
267 |
sleep $DT_delay && $s->wait_for_ajax; |
263 |
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' ); |
268 |
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' ); |
264 |
|
269 |
|
265 |
$s->driver->find_element('//table[@id="'.$table_id.'"]//th[@data-filter="libraries"]/select/option[@value="'.$library->branchcode.'"]')->click; |
270 |
$s->driver->find_element('//table[@id="'.$table_id.'"]//th[@data-filter="libraries"]/select/option[@value="'.$first_patron->library->branchcode.'"]')->click; |
266 |
sleep $DT_delay && $s->wait_for_ajax; |
271 |
sleep $DT_delay && $s->wait_for_ajax; |
267 |
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' ); |
272 |
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' ); |
268 |
|
273 |
|
269 |
# Reset the filters |
274 |
# Reset the filters |
270 |
$driver->find_element('//form[@id="patron_search_form"]//*[@id="clear_search"]')->click(); |
275 |
$driver->find_element('//form[@class="patron_search_form"]//*[@class="clear_search"]')->click(); |
271 |
$s->submit_form; |
276 |
$s->submit_form; |
272 |
sleep $DT_delay && $s->wait_for_ajax; |
277 |
sleep $DT_delay && $s->wait_for_ajax; |
273 |
|
278 |
|
Lines 275-312
subtest 'Search patrons' => sub {
Link Here
|
275 |
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' ); |
280 |
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' ); |
276 |
|
281 |
|
277 |
# Pattern terms must be split |
282 |
# Pattern terms must be split |
278 |
$s->fill_form( { search_patron_filter => 'test patron' } ); |
283 |
$s->fill_form( { 'class=search_patron_filter' => 'test patron' } ); |
279 |
$s->submit_form; |
284 |
$s->submit_form; |
280 |
|
285 |
|
281 |
sleep $DT_delay && $s->wait_for_ajax; |
286 |
sleep $DT_delay && $s->wait_for_ajax; |
282 |
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) ); |
287 |
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) ); |
283 |
$driver->find_element('//form[@id="patron_search_form"]//*[@id="clear_search"]')->click(); |
288 |
$driver->find_element('//form[@class="patron_search_form"]//*[@class="clear_search"]')->click(); |
284 |
$s->submit_form; |
289 |
$s->submit_form; |
285 |
sleep $DT_delay && $s->wait_for_ajax; |
290 |
sleep $DT_delay && $s->wait_for_ajax; |
286 |
|
291 |
|
287 |
# Search on non-searchable attribute, we expect no result! |
292 |
# Search on non-searchable attribute, we expect no result! |
288 |
$s->fill_form( { search_patron_filter => 'test_attr_1' } ); |
293 |
$s->fill_form( { 'class=search_patron_filter' => 'test_attr_1' } ); |
289 |
$s->submit_form; |
294 |
$s->submit_form; |
290 |
sleep $DT_delay && $s->wait_for_ajax; |
295 |
sleep $DT_delay && $s->wait_for_ajax; |
291 |
|
296 |
|
292 |
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' ); |
297 |
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' ); |
293 |
|
298 |
|
294 |
# clear form |
299 |
# clear form |
295 |
$driver->find_element('//form[@id="patron_search_form"]//*[@id="clear_search"]')->click(); |
300 |
$driver->find_element('//form[@class="patron_search_form"]//*[@class="clear_search"]')->click(); |
296 |
|
301 |
|
297 |
# Search on searchable attribute, we expect 2 patrons |
302 |
# Search on searchable attribute, we expect 2 patrons |
298 |
$s->fill_form( { search_patron_filter => 'test_attr_2' } ); |
303 |
$s->fill_form( { 'class=search_patron_filter' => 'test_attr_2' } ); |
299 |
$s->submit_form; |
304 |
$s->submit_form; |
300 |
sleep $DT_delay && $s->wait_for_ajax; |
305 |
sleep $DT_delay && $s->wait_for_ajax; |
301 |
|
306 |
|
302 |
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' ); |
307 |
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' ); |
303 |
|
308 |
|
304 |
# clear form |
309 |
# clear form |
305 |
$driver->find_element('//form[@id="patron_search_form"]//*[@id="clear_search"]')->click(); |
310 |
$driver->find_element('//form[@class="patron_search_form"]//*[@class="clear_search"]')->click(); |
306 |
|
311 |
|
307 |
# Search on searchable attribute as specific field, we expect 2 patrons |
312 |
# Search on searchable attribute as specific field, we expect 2 patrons |
308 |
$s->fill_form( { search_patron_filter => 'test_attr_3' } ); |
313 |
$s->fill_form( { 'class=search_patron_filter' => 'test_attr_3' } ); |
309 |
$driver->find_element('//form[@id="patron_search_form"]//*[@id="searchfieldstype_filter"]//option[@value="_ATTR_'.$attribute_type_searchable_not_default->code.'"]')->click(); |
314 |
$driver->find_element('//form[@class="patron_search_form"]//*[@class="searchfieldstype_filter"]//option[@value="_ATTR_'.$attribute_type_searchable_not_default->code.'"]')->click(); |
310 |
$s->submit_form; |
315 |
$s->submit_form; |
311 |
sleep $DT_delay && $s->wait_for_ajax; |
316 |
sleep $DT_delay && $s->wait_for_ajax; |
312 |
|
317 |
|
Lines 330-336
subtest 'Search patrons' => sub {
Link Here
|
330 |
|
335 |
|
331 |
C4::Context->set_preference( 'PatronsPerPage', 5 ); |
336 |
C4::Context->set_preference( 'PatronsPerPage', 5 ); |
332 |
$driver->get( $base_url . "/members/members-home.pl" ); |
337 |
$driver->get( $base_url . "/members/members-home.pl" ); |
333 |
$s->fill_form( { search_patron_filter => 'test_patron' } ); |
338 |
$s->fill_form( { 'class=search_patron_filter' => 'test_patron' } ); |
334 |
$s->submit_form; |
339 |
$s->submit_form; |
335 |
sleep $DT_delay && $s->wait_for_ajax; |
340 |
sleep $DT_delay && $s->wait_for_ajax; |
336 |
my $patron_selected_text = $driver->find_element('//div[@id="table_search_selections"]/span')->get_text; |
341 |
my $patron_selected_text = $driver->find_element('//div[@id="table_search_selections"]/span')->get_text; |
Lines 356-362
subtest 'Search patrons' => sub {
Link Here
|
356 |
|
361 |
|
357 |
# Perform another search |
362 |
# Perform another search |
358 |
$driver->get( $base_url . "/members/members-home.pl" ); |
363 |
$driver->get( $base_url . "/members/members-home.pl" ); |
359 |
$s->fill_form( { search_patron_filter => 'test_patron' } ); |
364 |
$s->fill_form( { 'class=search_patron_filter' => 'test_patron' } ); |
360 |
$s->submit_form; |
365 |
$s->submit_form; |
361 |
sleep $DT_delay && $s->wait_for_ajax; |
366 |
sleep $DT_delay && $s->wait_for_ajax; |
362 |
$patron_selected_text = $driver->find_element('//div[@id="table_search_selections"]/span')->get_text; |
367 |
$patron_selected_text = $driver->find_element('//div[@id="table_search_selections"]/span')->get_text; |
Lines 383-389
subtest 'Search patrons' => sub {
Link Here
|
383 |
# We have a patron with date of birth=1980-06-17 => formatted as 17/06/1980 |
388 |
# We have a patron with date of birth=1980-06-17 => formatted as 17/06/1980 |
384 |
|
389 |
|
385 |
$driver->get( $base_url . "/members/members-home.pl" ); |
390 |
$driver->get( $base_url . "/members/members-home.pl" ); |
386 |
$s->fill_form( { search_patron_filter => 'test_patron' } ); |
391 |
$s->fill_form( { 'class=search_patron_filter' => 'test_patron' } ); |
387 |
$s->submit_form; |
392 |
$s->submit_form; |
388 |
sleep $DT_delay && $s->wait_for_ajax; |
393 |
sleep $DT_delay && $s->wait_for_ajax; |
389 |
|
394 |
|
Lines 393-398
subtest 'Search patrons' => sub {
Link Here
|
393 |
|
398 |
|
394 |
$dob_search_filter->send_keys('1980'); |
399 |
$dob_search_filter->send_keys('1980'); |
395 |
sleep $DT_delay && $s->wait_for_ajax; |
400 |
sleep $DT_delay && $s->wait_for_ajax; |
|
|
401 |
my $patron_27 = Koha::Patrons->search( { surname => 'test_patron_27' } )->next; |
396 |
is( is_patron_shown($patron_27), 1, 'search by correct year shows the patron' ); |
402 |
is( is_patron_shown($patron_27), 1, 'search by correct year shows the patron' ); |
397 |
$dob_search_filter->clear; |
403 |
$dob_search_filter->clear; |
398 |
|
404 |
|
Lines 427-435
subtest 'Search patrons' => sub {
Link Here
|
427 |
$dob_search_filter->clear; |
433 |
$dob_search_filter->clear; |
428 |
}; |
434 |
}; |
429 |
|
435 |
|
|
|
436 |
teardown(); |
430 |
$driver->quit(); |
437 |
$driver->quit(); |
431 |
}; |
438 |
}; |
432 |
|
439 |
|
|
|
440 |
subtest 'Search patrons in modal' => sub { |
441 |
plan tests => 2; |
442 |
|
443 |
setup(); |
444 |
|
445 |
my $total_number_of_patrons = Koha::Patrons->search->count; |
446 |
|
447 |
$driver->set_window_size( 3840, 10800 ); |
448 |
|
449 |
subtest 'Add guarantor - simple' => sub { |
450 |
plan tests => 4; |
451 |
|
452 |
my $table_id = "memberresultst"; |
453 |
|
454 |
my $mainpage = $s->base_url . q|mainpage.pl|; |
455 |
$driver->get($mainpage . q|?logout.x=1|); |
456 |
$s->auth; |
457 |
|
458 |
# Go to the add patron form |
459 |
$driver->get( $base_url . "/members/memberentry.pl" ); |
460 |
|
461 |
# Click "Add guarantor" |
462 |
$driver->find_element('//a[@href="#patron_search_modal"]')->click(); |
463 |
|
464 |
# Wait for the modal to be visible |
465 |
$s->wait_for_element_visible('//div[@id="patron_search_modal"]//div[@class="modal-header"]'); |
466 |
|
467 |
# Search for our test patrons |
468 |
$s->fill_form( { 'class=search_patron_filter' => 'test_patron' } ); |
469 |
$s->submit_form; |
470 |
sleep $DT_delay && $s->wait_for_ajax; |
471 |
|
472 |
# => the table is correctly displayed |
473 |
is( |
474 |
$driver->find_element( '//div[@id="' . $table_id . '_info"]' )->get_text, |
475 |
sprintf( |
476 |
'Showing 1 to %s of %s entries (filtered from %s total entries)', $PatronsPerPage, 26, |
477 |
$total_number_of_patrons |
478 |
), |
479 |
'Searching in standard brings back correct results' |
480 |
); |
481 |
|
482 |
# Search for patron 2 and display the patron preview modal |
483 |
my $patron = Koha::Patrons->search( { surname => 'test_patron_2' } )->next; |
484 |
$driver->find_element( |
485 |
sprintf '//a[@data-borrowernumber="%s"][@class="patron_name patron_preview"]', |
486 |
$patron->borrowernumber |
487 |
)->click; |
488 |
$s->wait_for_element_visible('//div[@id="patron_preview_modal"]'); |
489 |
sleep $DT_delay && $s->wait_for_ajax; |
490 |
|
491 |
# => The modal has patron's detail in it |
492 |
is( |
493 |
$driver->find_element('//div[@id="patron_preview_modal"]//h1')->get_text(), |
494 |
sprintf( |
495 |
"%s %s %s (%s) %s (%s)", $patron->title, $patron->firstname, $patron->middle_name, $patron->othernames, |
496 |
$patron->surname, $patron->cardnumber |
497 |
) |
498 |
); |
499 |
|
500 |
# Close the patron preview modal |
501 |
$driver->find_element('//div[@id="patron_preview_modal"]//input[@class="close"]')->click; |
502 |
$s->wait_for_element_hidden('//div[@id="patron_preview_modal"]'); |
503 |
|
504 |
# Select patron 2 |
505 |
$driver->find_element( |
506 |
sprintf '//a[@data-borrowernumber="%s"][@class="btn btn-default btn-xs select_user"]', |
507 |
$patron->borrowernumber |
508 |
)->click; |
509 |
|
510 |
# Wait for the modal to be hidden |
511 |
$s->wait_for_element_hidden('//div[@id="patron_search_modal"]//div[@class="modal-header"]'); |
512 |
|
513 |
# => The guarantor block has the info of the selected patron |
514 |
is( |
515 |
$driver->find_element('//a[@class="new_guarantor_link"]')->get_text(), |
516 |
sprintf( "%s %s (%s)", $patron->firstname, $patron->surname, $patron->cardnumber ) |
517 |
); |
518 |
is( |
519 |
$driver->find_element('//input[@class="new_guarantor_id noEnterSubmit"]')->get_value(), |
520 |
$patron->borrowernumber |
521 |
); |
522 |
|
523 |
}; |
524 |
|
525 |
subtest 'Add funds - double' => sub { |
526 |
plan tests => 11; |
527 |
|
528 |
my $table_id = "patron_search_modal_owner_table"; |
529 |
|
530 |
my $mainpage = $s->base_url . q|mainpage.pl|; |
531 |
$driver->get($mainpage . q|?logout.x=1|); |
532 |
$s->auth; |
533 |
|
534 |
# Go to the add patron form |
535 |
$driver->get( $base_url . "/admin/aqbudgets.pl?op=add_form&budget_id=1&budget_period_id=1" ); |
536 |
|
537 |
# Click "Select owner" |
538 |
$driver->find_element('//a[@href="#patron_search_modal_owner"]')->click(); |
539 |
|
540 |
# Add { acquisition => budget_modify } subpermission to some patrons |
541 |
my $dbh = C4::Context->dbh; |
542 |
my $patrons = Koha::Patrons->search( { surname => { like => 'test_patron_2%' } } ); |
543 |
while ( my $patron = $patrons->next ) { |
544 |
$dbh->do( |
545 |
q{INSERT INTO user_permissions (borrowernumber, module_bit, code) VALUES (?, ?, ?)}, {}, |
546 |
$patron->borrowernumber, 11, "budget_modify" |
547 |
); |
548 |
} |
549 |
|
550 |
# Wait for the modal to be visible |
551 |
$s->wait_for_element_visible('//div[@id="patron_search_modal_owner"]//div[@class="modal-header"]'); |
552 |
|
553 |
# Search for our test patrons |
554 |
$driver->find_element('//div[@id="patron_search_modal_owner"]//input[@class="search_patron_filter"]') |
555 |
->send_keys('test_patron'); |
556 |
$driver->find_element('//div[@id="patron_search_modal_owner"]//input[@type="submit"]')->click; |
557 |
|
558 |
sleep $DT_delay && $s->wait_for_ajax; |
559 |
|
560 |
# => the table is correctly displayed |
561 |
is( |
562 |
$driver->find_element( '//div[@id="' . $table_id . '_info"]' )->is_displayed, |
563 |
1, |
564 |
); |
565 |
|
566 |
# Search for patron 2 and display the patron preview modal |
567 |
my $patron = Koha::Patrons->search( { surname => 'test_patron_2' } )->next; |
568 |
$driver->find_element( |
569 |
sprintf '//a[@data-borrowernumber="%s"][@class="patron_name patron_preview"]', |
570 |
$patron->borrowernumber |
571 |
)->click; |
572 |
$s->wait_for_element_visible('//div[@id="patron_preview_modal"]'); |
573 |
sleep $DT_delay && $s->wait_for_ajax; |
574 |
|
575 |
# => The modal has patron's detail in it |
576 |
is( |
577 |
$driver->find_element('//div[@id="patron_preview_modal"]//h1')->get_text(), |
578 |
sprintf( |
579 |
"%s %s %s (%s) %s (%s)", $patron->title, $patron->firstname, $patron->middle_name, $patron->othernames, |
580 |
$patron->surname, $patron->cardnumber |
581 |
) |
582 |
); |
583 |
|
584 |
# Close the patron preview modal |
585 |
$driver->find_element('//div[@id="patron_preview_modal"]//input[@class="close"]')->click; |
586 |
$s->wait_for_element_hidden('//div[@id="patron_preview_modal"]'); |
587 |
|
588 |
# Select patron 2 |
589 |
$driver->find_element( |
590 |
sprintf '//a[@data-borrowernumber="%s"][@class="btn btn-default btn-xs select_user"]', |
591 |
$patron->borrowernumber |
592 |
)->click; |
593 |
|
594 |
# Wait for the modal to be hidden |
595 |
$s->wait_for_element_hidden('//div[@id="patron_search_modal"]//div[@class="modal-header"]'); |
596 |
|
597 |
# => The block has the info of the selected patron |
598 |
is( |
599 |
$driver->find_element('//span[@id="budget_owner_name"]')->get_text(), |
600 |
sprintf( "%s %s", $patron->firstname, $patron->surname ) |
601 |
); |
602 |
is( |
603 |
$driver->find_element('//input[@id="budget_owner_id"]')->get_value(), |
604 |
$patron->borrowernumber |
605 |
); |
606 |
|
607 |
$table_id = "patron_search_modal_users_table"; |
608 |
|
609 |
# Click "Add users" |
610 |
$driver->find_element('//a[@href="#patron_search_modal_users"]')->click(); |
611 |
|
612 |
# Wait for the modal to be visible |
613 |
$s->wait_for_element_visible('//div[@id="patron_search_modal_users"]//div[@class="modal-header"]'); |
614 |
|
615 |
# Search for our test patrons |
616 |
$driver->find_element('//div[@id="patron_search_modal_users"]//input[@class="search_patron_filter"]') |
617 |
->send_keys('test_patron'); |
618 |
$driver->find_element('//div[@id="patron_search_modal_users"]//input[@type="submit"]')->click; |
619 |
|
620 |
sleep $DT_delay && $s->wait_for_ajax; |
621 |
|
622 |
# => the table is correctly displayed |
623 |
is( |
624 |
$driver->find_element( '//div[@id="' . $table_id . '_info"]' )->is_displayed, |
625 |
1, |
626 |
); |
627 |
|
628 |
# Search for patron 2 and display the patron preview modal |
629 |
$patron = Koha::Patrons->search( { surname => 'test_patron_2' } )->next; |
630 |
$driver->find_element( |
631 |
sprintf '//a[@data-borrowernumber="%s"][@class="patron_name patron_preview"]', |
632 |
$patron->borrowernumber |
633 |
)->click; |
634 |
$s->wait_for_element_visible('//div[@id="patron_preview_modal"]'); |
635 |
sleep $DT_delay && $s->wait_for_ajax; |
636 |
|
637 |
# => The modal has patron's detail in it |
638 |
is( |
639 |
$driver->find_element('//div[@id="patron_preview_modal"]//h1')->get_text(), |
640 |
sprintf( |
641 |
"%s %s %s (%s) %s (%s)", $patron->title, $patron->firstname, $patron->middle_name, $patron->othernames, |
642 |
$patron->surname, $patron->cardnumber |
643 |
) |
644 |
); |
645 |
|
646 |
# Close the patron preview modal |
647 |
$driver->find_element('//div[@id="patron_preview_modal"]//input[@class="close"]')->click; |
648 |
$s->wait_for_element_hidden('//div[@id="patron_preview_modal"]'); |
649 |
|
650 |
# Select patron 2 |
651 |
$driver->find_element( |
652 |
sprintf '//a[@data-borrowernumber="%s"][@class="btn btn-default btn-xs add_user"]', |
653 |
$patron->borrowernumber |
654 |
)->click; |
655 |
|
656 |
# The modal is still displayed |
657 |
is( |
658 |
$driver->find_element('//div[@id="patron_search_modal_users"]//div[@class="modal-header"]')->is_displayed, |
659 |
1, |
660 |
); |
661 |
|
662 |
# Info has been added about the patron |
663 |
is( |
664 |
$driver->find_element('//div[@id="patron_search_modal_users"]//div[@class="info"]')->get_text, |
665 |
sprintf( "Patron '%s %s' added.", $patron->firstname, $patron->surname ) |
666 |
); |
667 |
|
668 |
# Select patron 2 again |
669 |
$driver->find_element( |
670 |
sprintf '//a[@data-borrowernumber="%s"][@class="btn btn-default btn-xs add_user"]', |
671 |
$patron->borrowernumber |
672 |
)->click; |
673 |
|
674 |
# Warning has been added about the patron |
675 |
is( |
676 |
$driver->find_element('//div[@id="patron_search_modal_users"]//div[@class="error"]')->get_text, |
677 |
sprintf( "Patron '%s %s' is already in the list.", $patron->firstname, $patron->surname ) |
678 |
); |
679 |
|
680 |
# Click "Close" |
681 |
$driver->find_element('//div[@id="patron_search_modal_users"]//div[@class="modal-footer"]//a')->click, |
682 |
|
683 |
# The modal is closed |
684 |
if ( |
685 |
$driver->find_element('//div[@id="patron_search_modal_users"]//div[@class="modal-header"]')->is_displayed, |
686 |
0, |
687 |
); |
688 |
|
689 |
# => The block has the info of the selected patron |
690 |
is( |
691 |
$driver->find_element( sprintf '//*[@id="budget_users"]/*[@id="user_%s"]/a', $patron->borrowernumber ) |
692 |
->get_text(), |
693 |
sprintf( "%s %s", $patron->firstname, $patron->surname ) |
694 |
); |
695 |
is( |
696 |
$driver->find_element('//input[@id="budget_users_id"]')->get_value(), |
697 |
sprintf( ":%s", $patron->borrowernumber ), # FIXME There is an extra ':' here |
698 |
); |
699 |
}; |
700 |
|
701 |
teardown(); |
702 |
}; |
703 |
|
433 |
sub is_patron_shown { |
704 |
sub is_patron_shown { |
434 |
my ($patron) = @_; |
705 |
my ($patron) = @_; |
435 |
|
706 |
|