From c7117db8746cd3d2c80825bdd4ec3000565196d4 Mon Sep 17 00:00:00 2001 From: Andreas Jonsson Date: Thu, 8 Feb 2024 01:02:51 +0000 Subject: [PATCH] Bug 36025: Selenium test for the query parameters The test verifies that there is no clause for extended attributes in the patron search query when no patron attribute is searchable by default. NC amended patch - tidied Signed-off-by: Nick Clemens --- t/db_dependent/selenium/patrons_search.t | 43 +++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/selenium/patrons_search.t b/t/db_dependent/selenium/patrons_search.t index 928e64f36ff..553ffc9f72b 100755 --- a/t/db_dependent/selenium/patrons_search.t +++ b/t/db_dependent/selenium/patrons_search.t @@ -61,7 +61,7 @@ my $builder = t::lib::TestBuilder->new; my $schema = Koha::Database->schema; subtest 'Search patrons' => sub { - plan tests => 27; + plan tests => 28; 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"); @@ -427,6 +427,47 @@ subtest 'Search patrons' => sub { $dob_search_filter->clear; }; + subtest 'no clause for extended_attributes when none are default searchable' => sub { + $attribute_type_searchable->update( { searched_by_default => 0 } ); + + $driver->get( $base_url . "/members/members-home.pl" ); + + $driver->execute_script( <<'EOF', 'capture_ajax_data' ); +jQuery( document ).on( "ajaxSend", function( event, request, settings ) { + jQuery('#patron_search_form').after('
'); + var url = new URL(window.location.origin + settings.url); + var parts = url.search.substring(1).split('&'); + var q; + for (var i = 0 ; i < parts.length ; i++) { + var p = parts[i].split('='); + if (p[0] === 'q') { + q = JSON.parse(decodeURIComponent(p[1])); + break; + } + } + + for (var i = 0; i < q.length; i++) { + var q0 = q[i]['-and']; + for (var j = 0; q0 && j < q0.length; j++) { + for (var k = 0; k < q0[j].length; k++) { + if (q0[j][k].hasOwnProperty('extended_attributes.code')) { + jQuery('#patron_search_form').after('
'); + } + } + } + } +} ); +EOF + $s->fill_form( { search_patron_filter => 'test_patron' } ); + $s->submit_form; + sleep $DT_delay && $s->wait_for_ajax; + my $e1 = $driver->find_elements( 'capture_ajax_data_was_executed', 'id' ); + is( scalar(@$e1), 1, 'the capture script was executed' ); + my $e2 = $driver->find_elements( 'had_extended_attributes_clause', 'id' ); + is( scalar(@$e2), 0, 'there were no extended attributes on the search clause' ); + + }; + $driver->quit(); }; -- 2.30.2