|
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_DefaultPatronSearchMethod = C4::Context->preference('DefaultPatronSearchMethod'); |
| 23 |
my $original_PatronsPerPage = C4::Context->preference('PatronsPerPage'); |
| 20 |
our @cleanup; |
24 |
our @cleanup; |
|
|
25 |
|
| 21 |
END { |
26 |
END { |
| 22 |
unless ( @cleanup ) { say "WARNING: Cleanup failed!" } |
27 |
unless ( @cleanup ) { say "WARNING: Cleanup failed!" } |
|
|
28 |
C4::Context->set_preference( 'dateformat', $original_dateformat ); |
| 29 |
C4::Context->set_preference( 'DefaultPatronSearchFields', $original_DefaultPatronSearchFields ); |
| 30 |
C4::Context->set_preference( 'DefaultPatronSearchMethod', $original_DefaultPatronSearchMethod ); |
| 31 |
C4::Context->set_preference( 'PatronsPerPage', $original_PatronsPerPage ); |
| 23 |
$_->delete for @cleanup; |
32 |
$_->delete for @cleanup; |
| 24 |
}; |
33 |
}; |
| 25 |
|
34 |
|
|
Lines 43-49
if ( $@ ) {
Link Here
|
| 43 |
plan tests => 1; |
52 |
plan tests => 1; |
| 44 |
} |
53 |
} |
| 45 |
|
54 |
|
| 46 |
|
|
|
| 47 |
my $s = t::lib::Selenium->new; |
55 |
my $s = t::lib::Selenium->new; |
| 48 |
my $driver = $s->driver; |
56 |
my $driver = $s->driver; |
| 49 |
my $opac_base_url = $s->opac_base_url; |
57 |
my $opac_base_url = $s->opac_base_url; |
|
Lines 52-58
my $builder = t::lib::TestBuilder->new;
Link Here
|
| 52 |
my $schema = Koha::Database->schema; |
60 |
my $schema = Koha::Database->schema; |
| 53 |
|
61 |
|
| 54 |
subtest 'Search patrons' => sub { |
62 |
subtest 'Search patrons' => sub { |
| 55 |
plan tests => 25; |
63 |
plan tests => 26; |
| 56 |
|
64 |
|
| 57 |
if ( Koha::Patrons->search({surname => {-like => "test_patron_%"}})->count ) { |
65 |
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"); |
66 |
BAIL_OUT("Cannot run this test, data we need to create already exist in the DB"); |
|
Lines 73-81
subtest 'Search patrons' => sub {
Link Here
|
| 73 |
my $library = $builder->build_object( |
81 |
my $library = $builder->build_object( |
| 74 |
{ class => 'Koha::Libraries', value => { branchname => $branchname } } |
82 |
{ class => 'Koha::Libraries', value => { branchname => $branchname } } |
| 75 |
); |
83 |
); |
| 76 |
my $default_patron_search_fields = C4::Context->preference('DefaultPatronSearchFields'); |
|
|
| 77 |
my $default_patron_search_method = C4::Context->preference('DefaultPatronSearchMethod'); |
| 78 |
my $default_patron_per_page = C4::Context->preference('PatronsPerPage'); |
| 79 |
for my $i ( 1 .. 25 ) { |
84 |
for my $i ( 1 .. 25 ) { |
| 80 |
push @patrons, |
85 |
push @patrons, |
| 81 |
$builder->build_object( |
86 |
$builder->build_object( |
|
Lines 98-105
subtest 'Search patrons' => sub {
Link Here
|
| 98 |
{ |
103 |
{ |
| 99 |
class => 'Koha::Patrons', |
104 |
class => 'Koha::Patrons', |
| 100 |
value => { |
105 |
value => { |
| 101 |
surname => "test", |
106 |
surname => "test", |
| 102 |
firstname => "not_p_a_t_r_o_n", # won't match 'patron' |
107 |
firstname => "not_p_a_t_r_o_n", # won't match 'patron' |
| 103 |
categorycode => $patron_category->categorycode, |
108 |
categorycode => $patron_category->categorycode, |
| 104 |
branchcode => $library->branchcode, |
109 |
branchcode => $library->branchcode, |
| 105 |
borrowernotes => $borrowernotes, |
110 |
borrowernotes => $borrowernotes, |
|
Lines 112-132
subtest 'Search patrons' => sub {
Link Here
|
| 112 |
my $library_2 = $builder->build_object( |
117 |
my $library_2 = $builder->build_object( |
| 113 |
{ class => 'Koha::Libraries', value => { branchname => 'X' . $branchname } } |
118 |
{ class => 'Koha::Libraries', value => { branchname => 'X' . $branchname } } |
| 114 |
); |
119 |
); |
| 115 |
push @patrons, |
120 |
my $patron_27 = |
| 116 |
$builder->build_object( |
121 |
$builder->build_object( |
| 117 |
{ |
122 |
{ |
| 118 |
class => 'Koha::Patrons', |
123 |
class => 'Koha::Patrons', |
| 119 |
value => { |
124 |
value => { |
| 120 |
surname => "test_patron_26", |
125 |
surname => "test_patron_27", |
| 121 |
firstname => $firstname, |
126 |
firstname => $firstname, |
| 122 |
categorycode => $patron_category->categorycode, |
127 |
categorycode => $patron_category->categorycode, |
| 123 |
branchcode => $library_2->branchcode, |
128 |
branchcode => $library_2->branchcode, |
| 124 |
borrowernotes => $borrowernotes, |
129 |
borrowernotes => $borrowernotes, |
| 125 |
address => $address, |
130 |
address => $address, |
| 126 |
email => $email, |
131 |
email => $email, |
|
|
132 |
dateofbirth => '1980-06-17', |
| 127 |
} |
133 |
} |
| 128 |
} |
134 |
} |
| 129 |
); |
135 |
); |
|
|
136 |
push @patrons, $patron_27; |
| 130 |
|
137 |
|
| 131 |
my $attribute_type = Koha::Patron::Attribute::Type->new( |
138 |
my $attribute_type = Koha::Patron::Attribute::Type->new( |
| 132 |
{ |
139 |
{ |
|
Lines 181-186
subtest 'Search patrons' => sub {
Link Here
|
| 181 |
@filter_options = $driver->find_elements('//select[@id="searchfieldstype_filter"]/option'); |
188 |
@filter_options = $driver->find_elements('//select[@id="searchfieldstype_filter"]/option'); |
| 182 |
is( scalar @adv_options, $nb_standard_fields, 'Invalid option not added when DefaultPatronSearchFields is populated with an invalid field'); |
189 |
is( scalar @adv_options, $nb_standard_fields, 'Invalid option not added when DefaultPatronSearchFields is populated with an invalid field'); |
| 183 |
is( scalar @filter_options, $nb_standard_fields, 'Invalid filter option not added when DefaultPatronSearchFields is populated with an invalid field'); |
190 |
is( scalar @filter_options, $nb_standard_fields, 'Invalid filter option not added when DefaultPatronSearchFields is populated with an invalid field'); |
|
|
191 |
|
| 184 |
# NOTE: We should probably ensure the bad field is removed from 'standard' search here, else searches are broken |
192 |
# NOTE: We should probably ensure the bad field is removed from 'standard' search here, else searches are broken |
| 185 |
C4::Context->set_preference('DefaultPatronSearchFields',""); |
193 |
C4::Context->set_preference('DefaultPatronSearchFields',""); |
| 186 |
$driver->get( $base_url . "/members/members-home.pl" ); |
194 |
$driver->get( $base_url . "/members/members-home.pl" ); |
|
Lines 260-265
subtest 'Search patrons' => sub {
Link Here
|
| 260 |
|
268 |
|
| 261 |
# clear form |
269 |
# clear form |
| 262 |
$driver->find_element('//form[@id="patron_search_form"]//*[@id="clear_search"]')->click(); |
270 |
$driver->find_element('//form[@id="patron_search_form"]//*[@id="clear_search"]')->click(); |
|
|
271 |
|
| 263 |
# Search on searchable attribute, we expect 2 patrons |
272 |
# Search on searchable attribute, we expect 2 patrons |
| 264 |
$s->fill_form( { search_patron_filter => 'test_attr_2' } ); |
273 |
$s->fill_form( { search_patron_filter => 'test_attr_2' } ); |
| 265 |
$s->submit_form; |
274 |
$s->submit_form; |
|
Lines 307-314
subtest 'Search patrons' => sub {
Link Here
|
| 307 |
'//input[@type="checkbox"][@name="borrowernumber"]'); |
316 |
'//input[@type="checkbox"][@name="borrowernumber"]'); |
| 308 |
$checkboxes[0]->click; |
317 |
$checkboxes[0]->click; |
| 309 |
$patron_selected_text = $driver->find_element('//div[@id="patron_search_selected"]/span')->get_text; |
318 |
$patron_selected_text = $driver->find_element('//div[@id="patron_search_selected"]/span')->get_text; |
| 310 |
is( $patron_selected_text, "Patrons selected: 3", "Tree patrons are selected" ); |
319 |
is( $patron_selected_text, "Patrons selected: 3", "Three patrons are selected" ); |
| 311 |
|
|
|
| 312 |
|
320 |
|
| 313 |
# Perform another search |
321 |
# Perform another search |
| 314 |
$driver->get( $base_url . "/members/members-home.pl" ); |
322 |
$driver->get( $base_url . "/members/members-home.pl" ); |
|
Lines 316-322
subtest 'Search patrons' => sub {
Link Here
|
| 316 |
$s->submit_form; |
324 |
$s->submit_form; |
| 317 |
$s->wait_for_ajax; |
325 |
$s->wait_for_ajax; |
| 318 |
$patron_selected_text = $driver->find_element('//div[@id="patron_search_selected"]/span')->get_text; |
326 |
$patron_selected_text = $driver->find_element('//div[@id="patron_search_selected"]/span')->get_text; |
| 319 |
is( $patron_selected_text, "Patrons selected: 3", "Tree patrons still selected" ); |
327 |
is( $patron_selected_text, "Patrons selected: 3", "Three patrons still selected" ); |
| 320 |
|
328 |
|
| 321 |
$driver->find_element('//*[@id="patronlist-menu"]')->click; |
329 |
$driver->find_element('//*[@id="patronlist-menu"]')->click; |
| 322 |
$driver->find_element('//a[@class="patron-list-add"]')->click; |
330 |
$driver->find_element('//a[@class="patron-list-add"]')->click; |
|
Lines 331-344
subtest 'Search patrons' => sub {
Link Here
|
| 331 |
$patron_list->delete; |
339 |
$patron_list->delete; |
| 332 |
}; |
340 |
}; |
| 333 |
|
341 |
|
|
|
342 |
subtest 'filter by date of birth' => sub { |
| 343 |
plan tests => 7; |
| 344 |
|
| 345 |
C4::Context->set_preference( 'dateformat', 'metric' ); |
| 346 |
|
| 347 |
# We have a patron with date of birth=1980-06-17 => formatted as 17/06/1980 |
| 348 |
|
| 349 |
$driver->get( $base_url . "/members/members-home.pl" ); |
| 350 |
$s->fill_form( { search_patron_filter => 'test_patron' } ); |
| 351 |
$s->submit_form; |
| 352 |
$s->wait_for_ajax; |
| 353 |
|
| 354 |
$s->show_all_entries( '//div[@id="' . $table_id . '_wrapper"]' ); |
| 355 |
my $dob_search_filter = |
| 356 |
$s->driver->find_element( '//table[@id="' . $table_id . '"]//input[@placeholder="Date of birth search"]' ); |
| 357 |
|
| 358 |
$dob_search_filter->send_keys('1980'); |
| 359 |
$s->wait_for_ajax; |
| 360 |
is( is_patron_shown($patron_27), 1, 'search by correct year shows the patron' ); |
| 361 |
$dob_search_filter->clear; |
| 362 |
|
| 363 |
$dob_search_filter->send_keys('1986'); |
| 364 |
$s->wait_for_ajax; |
| 365 |
is( is_patron_shown($patron_27), 0, 'search by incorrect year does not show the patron' ); |
| 366 |
$dob_search_filter->clear; |
| 367 |
|
| 368 |
$dob_search_filter->send_keys('1980-06'); |
| 369 |
$s->wait_for_ajax; |
| 370 |
is( is_patron_shown($patron_27), 1, 'search by correct year-month shows the patron' ); |
| 371 |
$dob_search_filter->clear; |
| 372 |
|
| 373 |
$dob_search_filter->send_keys('1980-06-17'); |
| 374 |
$s->wait_for_ajax; |
| 375 |
is( is_patron_shown($patron_27), 1, 'search by correct full iso date shows the patron' ); |
| 376 |
$dob_search_filter->clear; |
| 377 |
|
| 378 |
$dob_search_filter->send_keys('1986-06-17'); |
| 379 |
$s->wait_for_ajax; |
| 380 |
is( is_patron_shown($patron_27), 0, 'search by incorrect full iso date does not show the patron' ); |
| 381 |
$dob_search_filter->clear; |
| 382 |
|
| 383 |
$dob_search_filter->send_keys('17/06/1980'); |
| 384 |
$s->wait_for_ajax; |
| 385 |
is( is_patron_shown($patron_27), 1, 'search by correct full formatted date shows the patron' ); |
| 386 |
$dob_search_filter->clear; |
| 387 |
|
| 388 |
$dob_search_filter->send_keys('17/06/1986'); |
| 389 |
$s->wait_for_ajax; |
| 390 |
is( is_patron_shown($patron_27), 0, 'search by incorrect full formatted date does not show the patron' ); |
| 391 |
$dob_search_filter->clear; |
| 392 |
}; |
| 393 |
|
| 334 |
push @cleanup, $_ for @patrons; |
394 |
push @cleanup, $_ for @patrons; |
| 335 |
push @cleanup, $library; |
395 |
push @cleanup, $library; |
| 336 |
push @cleanup, $library_2; |
396 |
push @cleanup, $library_2; |
| 337 |
push @cleanup, $patron_category; |
397 |
push @cleanup, $patron_category; |
| 338 |
push @cleanup, $attribute_type, $attribute_type_searchable; |
398 |
push @cleanup, $attribute_type, $attribute_type_searchable; |
| 339 |
C4::Context->set_preference('DefaultPatronSearchFields',$default_patron_search_fields); |
|
|
| 340 |
C4::Context->set_preference('DefaultPatronSearchMethod',$default_patron_search_method); |
| 341 |
C4::Context->set_preference('PatronsPerPage',$default_patron_per_page); |
| 342 |
|
399 |
|
| 343 |
$driver->quit(); |
400 |
$driver->quit(); |
| 344 |
}; |
401 |
}; |
| 345 |
- |
402 |
|
|
|
403 |
sub is_patron_shown { |
| 404 |
my ($patron) = @_; |
| 405 |
|
| 406 |
my @checkboxes = $driver->find_elements('//input[@type="checkbox"][@name="borrowernumber"]'); |
| 407 |
return scalar( grep { $_->get_value == $patron->borrowernumber } @checkboxes ); |
| 408 |
} |