Bug 30645: Add tests

to highlight the problem

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
Jonathan Druart 2022-04-28 15:13:17 +02:00 committed by Katrin Fischer
parent b42574afdc
commit 92a4c99e24
No known key found for this signature in database
GPG Key ID: 0EF6E2C03357A834
1 changed files with 31 additions and 12 deletions

View File

@ -51,7 +51,6 @@ my $base_url = $s->base_url;
my $builder = t::lib::TestBuilder->new;
my $schema = Koha::Database->schema;
if ( Koha::Patrons->search({surname => {-like => "test_patron_%"}})->count ) {
BAIL_OUT("Cannot run this test, data we need to create already exist in the DB");
}
@ -63,7 +62,7 @@ my $branchname = q|<strong>just 'another" library</strong> \123 ❤
my $firstname = q|<strong>fir's"tname</strong> \123 ❤|;
my $address = q|<strong>add'res"s</strong> \123 ❤|;
my $email = q|a<strong>bad_email</strong>@example\123 ❤.com|;
my ($attribute_type, $attribute_type_searchable, $attribute_type_searchable_not_default);
my ($attribute_type, $attribute_type_searchable_1, $attribute_type_searchable_2, $attribute_type_searchable_not_default);
sub setup {
my $patron_category = $builder->build_object(
{
@ -151,7 +150,7 @@ sub setup {
searched_by_default => 0
}
)->store;
$attribute_type_searchable = Koha::Patron::Attribute::Type->new(
$attribute_type_searchable_1 = Koha::Patron::Attribute::Type->new(
{
code => 'my code2',
description => 'my description2',
@ -160,26 +159,37 @@ sub setup {
searched_by_default => 1
}
)->store;
$attribute_type_searchable_2 = Koha::Patron::Attribute::Type->new(
{
code => 'my code3',
description => 'my description3',
opac_display => 1,
staff_searchable => 1,
searched_by_default => 1
}
)->store;
$attribute_type_searchable_not_default = Koha::Patron::Attribute::Type->new(
{
code => 'mycode3',
description => 'my description3',
code => 'mycode4',
description => 'my description4',
opac_display => 1,
staff_searchable => 1,
searched_by_default => 0
}
)->store;
push @cleanup, $attribute_type, $attribute_type_searchable, $attribute_type_searchable_not_default;
push @cleanup, $attribute_type, $attribute_type_searchable_1, $attribute_type_searchable_2, $attribute_type_searchable_not_default;
$patrons[0]->extended_attributes([
{ code => $attribute_type->code, attribute => 'test_attr_1' },
{ code => $attribute_type_searchable->code, attribute => 'test_attr_2'},
{ code => $attribute_type_searchable_not_default->code, attribute => 'test_attr_3'},
{ code => $attribute_type_searchable_1->code, attribute => 'test_attr_2'},
{ code => $attribute_type_searchable_2->code, attribute => 'test_attr_3'},
{ code => $attribute_type_searchable_not_default->code, attribute => 'test_attr_4'},
]);
$patrons[1]->extended_attributes([
{ code => $attribute_type->code, attribute => 'test_attr_1' },
{ code => $attribute_type_searchable->code, attribute => 'test_attr_2'},
{ code => $attribute_type_searchable_not_default->code, attribute => 'test_attr_3'},
{ code => $attribute_type_searchable_1->code, attribute => 'test_attr_2'},
{ code => $attribute_type_searchable_2->code, attribute => 'test_attr_3'},
{ code => $attribute_type_searchable_not_default->code, attribute => 'test_attr_4'},
]);
C4::Context->set_preference('PatronsPerPage', $PatronsPerPage);
}
@ -194,7 +204,7 @@ sub teardown {
}
subtest 'Search patrons' => sub {
plan tests => 27;
plan tests => 28;
setup();
my $total_number_of_patrons = Koha::Patrons->search->count;
@ -316,8 +326,17 @@ subtest 'Search patrons' => sub {
# clear form
$driver->find_element('//form[@class="patron_search_form"]//*[@class="btn btn-default clear_search"]')->click();
$s->fill_form( { 'class=search_patron_filter' => 'test_attr_3' } ); # Terms must be split
$s->submit_form;
sleep $DT_delay && $s->wait_for_ajax;
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' );
# clear form
$driver->find_element('//form[@class="patron_search_form"]//*[@class="btn btn-default clear_search"]')->click();
# Search on searchable attribute as specific field, we expect 2 patrons
$s->fill_form( { 'class=search_patron_filter' => 'test_attr_3' } );
$s->fill_form( { 'class=search_patron_filter' => 'test_attr_4' } );
$driver->find_element('//form[@class="patron_search_form"]//*[@class="searchfieldstype_filter"]//option[@value="_ATTR_'.$attribute_type_searchable_not_default->code.'"]')->click();
$s->submit_form;
sleep $DT_delay && $s->wait_for_ajax;