From 1a4fa3d59897b1bc5a89047377500615ccc9b44c Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 26 Dec 2017 16:09:41 -0300 Subject: [PATCH] Bug 19243: Fix tests for AV The tricky part here was to find an alternative for ends-with in Xpath version 1 Indeed there are 2 button with "/admin/authorised_values.pl?op=add_form", and the first one was picked (/admin/authorised_values.pl?op=add_form&category=Asort1) --- t/db_dependent/selenium/administration_tasks.t | 28 ++++++++++++++++++++++---- t/lib/Selenium.pm | 17 +++++++++++++++- 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/t/db_dependent/selenium/administration_tasks.t b/t/db_dependent/selenium/administration_tasks.t index 8ebc3a4e71..eb562fe96f 100644 --- a/t/db_dependent/selenium/administration_tasks.t +++ b/t/db_dependent/selenium/administration_tasks.t @@ -32,7 +32,7 @@ my $login = $ENV{KOHA_USER} || 'koha'; my $itemtype = 'UT_DVD'; my $frameworkcode = 'UTFW'; # frameworkcode is only 4 characters max! my $branchcode = 'UT_BC'; -my $categoryname = 'Test'; +my $av_category = 'AV_CAT_TEST'; our ($cleanup_needed); SKIP: { @@ -131,16 +131,35 @@ SKIP: { $s->click( { href => '/admin/authorised_values.pl', main => 'doc' } ); #Authorized values - $s->click( { href => '/admin/authorised_values.pl?op=add_form&category=Adult', main => 'doc3' } ); # New category - $s->fill_form( { authorised_value => 'Hardover', lib => 'Hardcover book'} ); + $s->click( { href => { 'ends-with' => '/admin/authorised_values.pl?op=add_form' }, main => 'doc3' } ); # New category + $s->fill_form( { category => $av_category } ); $s->submit_form; $s->click( { - href => '/admin/authorised_values.pl?op=delete&searchfield=Adult&id=400', + href => '/admin/authorised_values.pl?op=add_form&category=' . $av_category, + main => 'doc3' + } + ); # New authorised value for ... + $s->fill_form( + { + authorised_value => "$av_category" . "_xxx", + lib => "This is a description for staff", + lib_opac => "This is a description for OPAC" + } + ); + $s->submit_form; + + my $dbh = C4::Context->dbh; + my ( $av_id ) = $dbh->selectrow_array(q| + SELECT id FROM authorised_values WHERE category=?|, undef, $av_category ); + $s->click( + { + href => '/admin/authorised_values.pl?op=delete&searchfield=' . $av_category . '&id=' . $av_id, main => 'doc3' } ); + $s->driver->accept_alert; }; { #Patron categories @@ -171,4 +190,5 @@ sub cleanup { $dbh->do(q|DELETE FROM itemtypes WHERE itemtype=?|, undef, $itemtype); $dbh->do(q|DELETE FROM biblio_framework WHERE frameworkcode=?|, undef, $frameworkcode); $dbh->do(q|DELETE FROM branches WHERE branchcode=?|, undef, $branchcode); + $dbh->do(q|DELETE FROM authorised_value_categories WHERE category_name=?|, undef, $av_category); } diff --git a/t/lib/Selenium.pm b/t/lib/Selenium.pm index f33e26981c..6741f62d32 100644 --- a/t/lib/Selenium.pm +++ b/t/lib/Selenium.pm @@ -99,7 +99,22 @@ sub click { $xpath_selector = '//div[@id="'.$params->{main}.'"]'; } if ( exists $params->{href} ) { - $xpath_selector .= '//a[contains(@href, "'.$params->{href}.'")]'; + if ( ref( $params->{href} ) ) { + for my $k ( keys %{ $params->{href} } ) { + if ( $k eq 'ends-with' ) { + # ends-with version for xpath version 1 + my $ends_with = $params->{href}{"ends-with"}; + $xpath_selector .= '//a[substring(@href, string-length(@href) - string-length("'.$ends_with.'") + 1 ) = "'.$ends_with.'"]'; + # ends-with version for xpath version 2 + #$xpath_selector .= '//a[ends-with(@href, "'.$ends_with.'") ]'; + + } else { + die "Only ends-with is supported so far ($k)"; + } + } + } else { + $xpath_selector .= '//a[contains(@href, "'.$params->{href}.'")]'; + } } if ( exists $params->{id} ) { $xpath_selector .= '//*[@id="'.$params->{id}.'"]'; -- 2.11.0