Lines 17-25
Link Here
|
17 |
|
17 |
|
18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
19 |
|
19 |
|
|
|
20 |
my $original_dateformat = C4::Context->preference('dateformat'); |
21 |
my $original_DefaultPatronSearchFields = C4::Context->preference('DefaultPatronSearchFields'); |
22 |
my $original_PatronsPerPage = C4::Context->preference('PatronsPerPage'); |
20 |
our @cleanup; |
23 |
our @cleanup; |
21 |
END { |
24 |
END { |
|
|
25 |
|
22 |
unless ( @cleanup ) { say "WARNING: Cleanup failed!" } |
26 |
unless ( @cleanup ) { say "WARNING: Cleanup failed!" } |
|
|
27 |
C4::Context->set_preference('dateformat', $original_dateformat); |
28 |
C4::Context->set_preference('DefaultPatronSearchFields', $original_DefaultPatronSearchFields); |
29 |
C4::Context->set_preference('PatronsPerPage', $original_PatronsPerPage); |
23 |
$_->delete for @cleanup; |
30 |
$_->delete for @cleanup; |
24 |
}; |
31 |
}; |
25 |
|
32 |
|
Lines 52-58
my $builder = t::lib::TestBuilder->new;
Link Here
|
52 |
my $schema = Koha::Database->schema; |
59 |
my $schema = Koha::Database->schema; |
53 |
|
60 |
|
54 |
subtest 'Search patrons' => sub { |
61 |
subtest 'Search patrons' => sub { |
55 |
plan tests => 25; |
62 |
plan tests => 26; |
56 |
|
63 |
|
57 |
if ( Koha::Patrons->search({surname => {-like => "test_patron_%"}})->count ) { |
64 |
if ( Koha::Patrons->search({surname => {-like => "test_patron_%"}})->count ) { |
58 |
BAIL_OUT("Cannot run this test, data we need to create already exist in the DB"); |
65 |
BAIL_OUT("Cannot run this test, data we need to create already exist in the DB"); |
Lines 73-80
subtest 'Search patrons' => sub {
Link Here
|
73 |
my $library = $builder->build_object( |
80 |
my $library = $builder->build_object( |
74 |
{ class => 'Koha::Libraries', value => { branchname => $branchname } } |
81 |
{ class => 'Koha::Libraries', value => { branchname => $branchname } } |
75 |
); |
82 |
); |
76 |
my $default_patron_search_fields = C4::Context->preference('DefaultPatronSearchFields'); |
|
|
77 |
my $default_patron_per_page = C4::Context->preference('PatronsPerPage'); |
78 |
for my $i ( 1 .. 25 ) { |
83 |
for my $i ( 1 .. 25 ) { |
79 |
push @patrons, |
84 |
push @patrons, |
80 |
$builder->build_object( |
85 |
$builder->build_object( |
Lines 111-117
subtest 'Search patrons' => sub {
Link Here
|
111 |
my $library_2 = $builder->build_object( |
116 |
my $library_2 = $builder->build_object( |
112 |
{ class => 'Koha::Libraries', value => { branchname => 'X' . $branchname } } |
117 |
{ class => 'Koha::Libraries', value => { branchname => 'X' . $branchname } } |
113 |
); |
118 |
); |
114 |
push @patrons, |
119 |
my $patron_26 = |
115 |
$builder->build_object( |
120 |
$builder->build_object( |
116 |
{ |
121 |
{ |
117 |
class => 'Koha::Patrons', |
122 |
class => 'Koha::Patrons', |
Lines 123-131
subtest 'Search patrons' => sub {
Link Here
|
123 |
borrowernotes => $borrowernotes, |
128 |
borrowernotes => $borrowernotes, |
124 |
address => $address, |
129 |
address => $address, |
125 |
email => $email, |
130 |
email => $email, |
|
|
131 |
dateofbirth => '1980-06-17', |
126 |
} |
132 |
} |
127 |
} |
133 |
} |
128 |
); |
134 |
); |
|
|
135 |
push @patrons, $patron_26; |
129 |
|
136 |
|
130 |
my $attribute_type = Koha::Patron::Attribute::Type->new( |
137 |
my $attribute_type = Koha::Patron::Attribute::Type->new( |
131 |
{ |
138 |
{ |
Lines 304-310
subtest 'Search patrons' => sub {
Link Here
|
304 |
'//input[@type="checkbox"][@name="borrowernumber"]'); |
311 |
'//input[@type="checkbox"][@name="borrowernumber"]'); |
305 |
$checkboxes[0]->click; |
312 |
$checkboxes[0]->click; |
306 |
$patron_selected_text = $driver->find_element('//div[@id="patron_search_selected"]/span')->get_text; |
313 |
$patron_selected_text = $driver->find_element('//div[@id="patron_search_selected"]/span')->get_text; |
307 |
is( $patron_selected_text, "Patrons selected: 3", "Tree patrons are selected" ); |
314 |
is( $patron_selected_text, "Patrons selected: 3", "Three patrons are selected" ); |
308 |
|
315 |
|
309 |
|
316 |
|
310 |
# Perform another search |
317 |
# Perform another search |
Lines 313-319
subtest 'Search patrons' => sub {
Link Here
|
313 |
$s->submit_form; |
320 |
$s->submit_form; |
314 |
$s->wait_for_ajax; |
321 |
$s->wait_for_ajax; |
315 |
$patron_selected_text = $driver->find_element('//div[@id="patron_search_selected"]/span')->get_text; |
322 |
$patron_selected_text = $driver->find_element('//div[@id="patron_search_selected"]/span')->get_text; |
316 |
is( $patron_selected_text, "Patrons selected: 3", "Tree patrons still selected" ); |
323 |
is( $patron_selected_text, "Patrons selected: 3", "Three patrons still selected" ); |
317 |
|
324 |
|
318 |
$driver->find_element('//*[@id="patronlist-menu"]')->click; |
325 |
$driver->find_element('//*[@id="patronlist-menu"]')->click; |
319 |
$driver->find_element('//a[@class="patron-list-add"]')->click; |
326 |
$driver->find_element('//a[@class="patron-list-add"]')->click; |
Lines 328-340
subtest 'Search patrons' => sub {
Link Here
|
328 |
$patron_list->delete; |
335 |
$patron_list->delete; |
329 |
}; |
336 |
}; |
330 |
|
337 |
|
|
|
338 |
subtest 'filter by date of birth' => sub { |
339 |
plan tests => 7; |
340 |
|
341 |
C4::Context->set_preference('dateformat', 'metric'); |
342 |
|
343 |
# We have a patron with date of birth=1980-06-17 => formatted as 17/06/1980 |
344 |
|
345 |
$driver->get( $base_url . "/members/members-home.pl" ); |
346 |
$s->fill_form( { search_patron_filter => 'test_patron' } ); |
347 |
$s->submit_form; |
348 |
$s->wait_for_ajax; |
349 |
|
350 |
$s->show_all_entries('//div[@id="'.$table_id.'_wrapper"]'); |
351 |
my $dob_search_filter = $s->driver->find_element('//table[@id="'.$table_id.'"]//input[@placeholder="Date of birth search"]'); |
352 |
|
353 |
$dob_search_filter->send_keys('1980'); |
354 |
$s->wait_for_ajax; |
355 |
is( is_patron_shown($patron_26), 1, 'search by correct year shows the patron' ); |
356 |
$dob_search_filter->clear; |
357 |
|
358 |
$dob_search_filter->send_keys('1986'); |
359 |
$s->wait_for_ajax; |
360 |
is( is_patron_shown($patron_26), 0, 'search by incorrect year does not show the patron' ); |
361 |
$dob_search_filter->clear; |
362 |
|
363 |
$dob_search_filter->send_keys('1980-06'); |
364 |
$s->wait_for_ajax; |
365 |
is( is_patron_shown($patron_26), 1, 'search by correct year-month shows the patron' ); |
366 |
$dob_search_filter->clear; |
367 |
|
368 |
$dob_search_filter->send_keys('1980-06-17'); |
369 |
$s->wait_for_ajax; |
370 |
is( is_patron_shown($patron_26), 1, 'search by correct full iso date shows the patron' ); |
371 |
$dob_search_filter->clear; |
372 |
|
373 |
$dob_search_filter->send_keys('1986-06-17'); |
374 |
$s->wait_for_ajax; |
375 |
is( is_patron_shown($patron_26), 0, 'search by incorrect full iso date does not show the patron' ); |
376 |
$dob_search_filter->clear; |
377 |
|
378 |
$dob_search_filter->send_keys('17/06/1980'); |
379 |
$s->wait_for_ajax; |
380 |
is( is_patron_shown($patron_26), 1, 'search by correct full formatted date shows the patron' ); |
381 |
$dob_search_filter->clear; |
382 |
|
383 |
$dob_search_filter->send_keys('17/06/1986'); |
384 |
$s->wait_for_ajax; |
385 |
is( is_patron_shown($patron_26), 0, 'search by incorrect full formatted date does not show the patron' ); |
386 |
$dob_search_filter->clear; |
387 |
}; |
388 |
|
331 |
push @cleanup, $_ for @patrons; |
389 |
push @cleanup, $_ for @patrons; |
332 |
push @cleanup, $library; |
390 |
push @cleanup, $library; |
333 |
push @cleanup, $library_2; |
391 |
push @cleanup, $library_2; |
334 |
push @cleanup, $patron_category; |
392 |
push @cleanup, $patron_category; |
335 |
push @cleanup, $attribute_type, $attribute_type_searchable; |
393 |
push @cleanup, $attribute_type, $attribute_type_searchable; |
336 |
C4::Context->set_preference('DefaultPatronSearchFields',$default_patron_search_fields); |
|
|
337 |
C4::Context->set_preference('PatronsPerPage',$default_patron_per_page); |
338 |
|
394 |
|
339 |
$driver->quit(); |
395 |
$driver->quit(); |
340 |
}; |
396 |
}; |
341 |
- |
397 |
|
|
|
398 |
sub is_patron_shown { |
399 |
my ( $patron ) = @_; |
400 |
|
401 |
my @checkboxes = $driver->find_elements('//input[@type="checkbox"][@name="borrowernumber"]'); |
402 |
return scalar(grep {$_->get_value == $patron->borrowernumber} @checkboxes); |
403 |
} |