|
Lines 17-22
Link Here
|
| 17 |
|
17 |
|
| 18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
| 19 |
|
19 |
|
|
|
20 |
our @cleanup; |
| 21 |
END { |
| 22 |
unless ( @cleanup ) { say "WARNING: Cleanup failed!" } |
| 23 |
$_->delete for @cleanup; |
| 24 |
}; |
| 25 |
|
| 20 |
use C4::Context; |
26 |
use C4::Context; |
| 21 |
|
27 |
|
| 22 |
use utf8; |
28 |
use utf8; |
|
Lines 25-30
use Test::MockModule;
Link Here
|
| 25 |
|
31 |
|
| 26 |
use C4::Context; |
32 |
use C4::Context; |
| 27 |
use Koha::AuthUtils; |
33 |
use Koha::AuthUtils; |
|
|
34 |
use Koha::Patrons; |
| 28 |
use t::lib::Mocks; |
35 |
use t::lib::Mocks; |
| 29 |
use t::lib::Selenium; |
36 |
use t::lib::Selenium; |
| 30 |
use t::lib::TestBuilder; |
37 |
use t::lib::TestBuilder; |
|
Lines 43-52
my $opac_base_url = $s->opac_base_url;
Link Here
|
| 43 |
my $base_url = $s->base_url; |
50 |
my $base_url = $s->base_url; |
| 44 |
my $builder = t::lib::TestBuilder->new; |
51 |
my $builder = t::lib::TestBuilder->new; |
| 45 |
|
52 |
|
| 46 |
our @cleanup; |
|
|
| 47 |
subtest 'Search patrons' => sub { |
53 |
subtest 'Search patrons' => sub { |
| 48 |
plan tests => 12; |
54 |
plan tests => 17; |
| 49 |
|
55 |
|
|
|
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"); |
| 58 |
} |
| 50 |
my @patrons; |
59 |
my @patrons; |
| 51 |
my $borrowernotes = q|<strong>just 'a" note</strong> \123 ❤|; |
60 |
my $borrowernotes = q|<strong>just 'a" note</strong> \123 ❤|; |
| 52 |
my $borrowernotes_displayed = q|just 'a" note \123 ❤|; |
61 |
my $borrowernotes_displayed = q|just 'a" note \123 ❤|; |
|
Lines 64-69
subtest 'Search patrons' => sub {
Link Here
|
| 64 |
{ class => 'Koha::Libraries', value => { branchname => $branchname } } |
73 |
{ class => 'Koha::Libraries', value => { branchname => $branchname } } |
| 65 |
); |
74 |
); |
| 66 |
my $default_patron_search_fields = C4::Context->preference('DefaultPatronSearchFields'); |
75 |
my $default_patron_search_fields = C4::Context->preference('DefaultPatronSearchFields'); |
|
|
76 |
my $default_patron_per_page = C4::Context->preference('PatronsPerPage'); |
| 67 |
for my $i ( 1 .. 25 ) { |
77 |
for my $i ( 1 .. 25 ) { |
| 68 |
push @patrons, |
78 |
push @patrons, |
| 69 |
$builder->build_object( |
79 |
$builder->build_object( |
|
Lines 81-89
subtest 'Search patrons' => sub {
Link Here
|
| 81 |
} |
91 |
} |
| 82 |
); |
92 |
); |
| 83 |
} |
93 |
} |
|
|
94 |
my $library_2 = $builder->build_object( |
| 95 |
{ class => 'Koha::Libraries', value => { branchname => 'X' . $branchname } } |
| 96 |
); |
| 97 |
push @patrons, |
| 98 |
$builder->build_object( |
| 99 |
{ |
| 100 |
class => 'Koha::Patrons', |
| 101 |
value => { |
| 102 |
surname => "test_patron_26", |
| 103 |
firstname => $firstname, |
| 104 |
categorycode => $patron_category->categorycode, |
| 105 |
branchcode => $library_2->branchcode, |
| 106 |
borrowernotes => $borrowernotes, |
| 107 |
address => $address, |
| 108 |
email => $email, |
| 109 |
} |
| 110 |
} |
| 111 |
); |
| 112 |
|
| 113 |
my $attribute_type = Koha::Patron::Attribute::Type->new( |
| 114 |
{ |
| 115 |
code => 'my code1', |
| 116 |
description => 'my description1', |
| 117 |
} |
| 118 |
)->store; |
| 119 |
my $attribute_type_searchable = Koha::Patron::Attribute::Type->new( |
| 120 |
{ |
| 121 |
code => 'my code2', |
| 122 |
description => 'my description2', |
| 123 |
opac_display => 1, |
| 124 |
staff_searchable => 1 |
| 125 |
} |
| 126 |
)->store; |
| 127 |
$patrons[0]->extended_attributes([ |
| 128 |
{ code => $attribute_type->code, attribute => 'test_attr_1' }, |
| 129 |
{ code => $attribute_type_searchable->code, attribute => 'test_attr_2'}, |
| 130 |
]); |
| 131 |
$patrons[1]->extended_attributes([ |
| 132 |
{ code => $attribute_type->code, attribute => 'test_attr_1' }, |
| 133 |
{ code => $attribute_type_searchable->code, attribute => 'test_attr_2'}, |
| 134 |
]); |
| 135 |
|
| 136 |
my $total_number_of_patrons = Koha::Patrons->search->count; |
| 137 |
my $table_id = "memberresultst"; |
| 84 |
|
138 |
|
| 85 |
$s->auth; |
139 |
$s->auth; |
| 86 |
C4::Context->set_preference('DefaultPatronSearchFields',""); |
140 |
C4::Context->set_preference('DefaultPatronSearchFields',""); |
|
|
141 |
my $PatronsPerPage = 15; |
| 142 |
C4::Context->set_preference('PatronsPerPage', $PatronsPerPage); |
| 87 |
$driver->get( $base_url . "/members/members-home.pl" ); |
143 |
$driver->get( $base_url . "/members/members-home.pl" ); |
| 88 |
my @adv_options = $driver->find_elements('//select[@id="searchfieldstype"]/option'); |
144 |
my @adv_options = $driver->find_elements('//select[@id="searchfieldstype"]/option'); |
| 89 |
my @filter_options = $driver->find_elements('//select[@id="searchfieldstype_filter"]/option'); |
145 |
my @filter_options = $driver->find_elements('//select[@id="searchfieldstype_filter"]/option'); |
|
Lines 106-113
subtest 'Search patrons' => sub {
Link Here
|
| 106 |
$s->submit_form; |
162 |
$s->submit_form; |
| 107 |
my $first_patron = $patrons[0]; |
163 |
my $first_patron = $patrons[0]; |
| 108 |
|
164 |
|
| 109 |
$s->wait_for_datatable_visible('//table[@id="memberresultst"]'); |
165 |
$s->wait_for_ajax; |
| 110 |
my @td = $driver->find_elements('//table[@id="memberresultst"]/tbody/tr/td'); |
166 |
my @td = $driver->find_elements('//table[@id="'.$table_id.'"]/tbody/tr/td'); |
| 111 |
like ($td[2]->get_text, qr[\Q$firstname\E], |
167 |
like ($td[2]->get_text, qr[\Q$firstname\E], |
| 112 |
'Column "Name" should be the 3rd and contain the firstname correctly filtered' |
168 |
'Column "Name" should be the 3rd and contain the firstname correctly filtered' |
| 113 |
); |
169 |
); |
|
Lines 136-149
subtest 'Search patrons' => sub {
Link Here
|
| 136 |
$first_patron->category->description, |
192 |
$first_patron->category->description, |
| 137 |
) |
193 |
) |
| 138 |
); |
194 |
); |
|
|
195 |
|
| 196 |
$driver->get( $base_url . "/members/members-home.pl" ); |
| 197 |
$s->fill_form( { search_patron_filter => 'test_patron' } ); |
| 198 |
$s->submit_form; |
| 199 |
$s->wait_for_ajax; |
| 200 |
|
| 201 |
$s->driver->find_element('//*[@id="'.$table_id.'_filter"]//input')->send_keys('test_patron'); |
| 202 |
$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) ); |
| 204 |
|
| 205 |
$s->driver->find_element('//table[@id="'.$table_id.'"]//th[@data-filter="libraries"]/select/option[@value="'.$library->branchcode.'"]')->click; |
| 206 |
$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) ); |
| 208 |
|
| 209 |
# Reset the filters |
| 210 |
$driver->find_element('//form[@id="patron_search_form"]//*[@id="clear_search"]')->click(); |
| 211 |
$s->submit_form; |
| 212 |
$s->wait_for_ajax; |
| 213 |
|
| 214 |
# 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) ); |
| 216 |
|
| 217 |
# Search on non-searchable attribute, we expect no result! |
| 218 |
$s->fill_form( { search_patron_filter => 'test_attr_1' } ); |
| 219 |
$s->submit_form; |
| 220 |
$s->wait_for_ajax; |
| 221 |
|
| 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) ); |
| 223 |
|
| 224 |
# clear form |
| 225 |
$driver->find_element('//form[@id="patron_search_form"]//*[@id="clear_search"]')->click(); |
| 226 |
# Search on searchable attribute, we expect 2 patrons |
| 227 |
$s->fill_form( { search_patron_filter => 'test_attr_2' } ); |
| 228 |
$s->submit_form; |
| 229 |
$s->wait_for_ajax; |
| 230 |
|
| 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) ); |
| 232 |
|
| 233 |
# 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 |
| 235 |
$s->driver->find_element('//*[@id="'.$table_id.'_filter"]//input')->send_keys('test_patron'); |
| 236 |
$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) ); |
| 238 |
|
| 239 |
# Adding the surname of the first patron in the "Name" column |
| 240 |
# We expect only 1 result |
| 241 |
$s->driver->find_element('//*[@id="'.$table_id.'_filter"]//input')->send_keys($patrons[0]->surname); |
| 242 |
$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) ); |
| 244 |
|
| 139 |
push @cleanup, $_ for @patrons; |
245 |
push @cleanup, $_ for @patrons; |
| 140 |
push @cleanup, $library; |
246 |
push @cleanup, $library; |
|
|
247 |
push @cleanup, $library_2; |
| 141 |
push @cleanup, $patron_category; |
248 |
push @cleanup, $patron_category; |
|
|
249 |
push @cleanup, $attribute_type, $attribute_type_searchable; |
| 142 |
C4::Context->set_preference('DefaultPatronSearchFields',$default_patron_search_fields); |
250 |
C4::Context->set_preference('DefaultPatronSearchFields',$default_patron_search_fields); |
|
|
251 |
C4::Context->set_preference('PatronsPerPage',$default_patron_per_page); |
| 143 |
|
252 |
|
| 144 |
$driver->quit(); |
253 |
$driver->quit(); |
| 145 |
}; |
254 |
}; |
| 146 |
|
|
|
| 147 |
END { |
| 148 |
$_->delete for @cleanup; |
| 149 |
} |