From bd4ff7f401d98cb2e724f7b4f89f18143f99ee82 Mon Sep 17 00:00:00 2001
From: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Date: Tue, 26 Dec 2017 16:23:00 -0300
Subject: [PATCH] Bug 19243: Fix tests for patron categories

---
 t/db_dependent/selenium/administration_tasks.t | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/t/db_dependent/selenium/administration_tasks.t b/t/db_dependent/selenium/administration_tasks.t
index 0c9d8e9373..fc12d86de2 100644
--- a/t/db_dependent/selenium/administration_tasks.t
+++ b/t/db_dependent/selenium/administration_tasks.t
@@ -33,6 +33,7 @@ my $itemtype      = 'UT_DVD';
 my $frameworkcode = 'UTFW';     # frameworkcode is only 4 characters max!
 my $branchcode    = 'UT_BC';
 my $av_category   = 'AV_CAT_TEST';
+my $category_code = 'PATRON_CAT';
 our ($cleanup_needed);
 
 SKIP: {
@@ -160,23 +161,28 @@ SKIP: {
                 main => 'doc3'
             }
         );
-        $s->driver->accept_alert;
+        $s->driver->accept_alert; # Accept the modal "Are you sure you want to delete this authorized value?"
     };
 
-    { #Patron categories
+    { # Patron categories
         $driver->get($mainpage);
-        $s->click( { href => '/admin/categories.pl', main => 'doc3' } ); #Koha administration
-        $s->click( { href => '/admin/categories.pl?op=add_form', main => 'doc' } ); #New patron category
+        $s->click( { href => '/admin/admin-home.pl', main => 'container-main' } ); # Koha administration
+        $s->click( { href => '/admin/categories.pl', main => 'doc' } ); # Patron categories
+        $s->click( { href => '/admin/categories.pl?op=add_form', main => 'doc3' } ); # New patron category
 
-        $s->fill_form( { categorycode => 'Test', description => 'Test category', enrolmentperiod => 12, category_type => 'Adult' } );
+        $s->fill_form( { categorycode => $category_code, description => 'Test category', enrolmentperiod => 12, category_type => 'A' } );
         $s->submit_form;
 
         $s->click(
             {
-                href => '/admin/categories.pl?op=delete_confirm&categorycode=TEST',
+                href => '/admin/categories.pl?op=delete_confirm&categorycode=' . $category_code,
                 main => 'doc3'
             }
-        );
+        ); # Delete button
+
+        $s->submit_form; # Delete this category
+
+        # TODO Make sure the category has been deleted
     };
 
     $driver->quit();
@@ -192,4 +198,5 @@ sub cleanup {
     $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);
+    $dbh->do(q|DELETE FROM categories WHERE categorycode=?|, undef, $category_code);
 }
-- 
2.11.0