Bug 19243: Fix tests for AV
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Tue, 26 Dec 2017 19:09:41 +0000 (16:09 -0300)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Tue, 13 Feb 2018 19:56:28 +0000 (16:56 -0300)
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)

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
t/db_dependent/selenium/administration_tasks.t
t/lib/Selenium.pm

index 8ebc3a4..eb562fe 100644 (file)
@@ -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);
 }
index f33e269..6741f62 100644 (file)
@@ -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}.'"]';