From fde8932a7af6c7e4544bbaa2e7fd9e9aed8b0f42 Mon Sep 17 00:00:00 2001
From: Arthur Suzuki <arthur.suzuki@biblibre.com>
Date: Thu, 27 Feb 2020 14:45:17 +0100
Subject: [PATCH] Bug 17229: moved UnitTest to t/db_dependant/ILSDI_Service.t

---
 t/db_dependent/Holds.t          | 23 ++-------------------
 t/db_dependent/ILSDI_Services.t | 36 ++++++++++++++++++++++++++++++++-
 2 files changed, 37 insertions(+), 22 deletions(-)

diff --git a/t/db_dependent/Holds.t b/t/db_dependent/Holds.t
index 9ab804829d..4d946c681b 100755
--- a/t/db_dependent/Holds.t
+++ b/t/db_dependent/Holds.t
@@ -7,7 +7,7 @@ use t::lib::TestBuilder;
 
 use C4::Context;
 
-use Test::More tests => 62;
+use Test::More tests => 61;
 use MARC::Record;
 
 use C4::Biblio;
@@ -42,12 +42,7 @@ my $dbh     = C4::Context->dbh;
 my $branch_1 = $builder->build({ source => 'Branch' })->{ branchcode };
 my $branch_2 = $builder->build({ source => 'Branch' })->{ branchcode };
 
-my $category = $builder->build({
-    source => 'Category',
-    value => {
-        BlockExpiredPatronOpacActions => -1,
-    },
-});
+my $category = $builder->build({ source => 'Category' });
 
 my $borrowers_count = 5;
 
@@ -136,20 +131,6 @@ my $patron = Koha::Patrons->find( $borrowernumbers[0] );
 $holds = $patron->holds;
 is( $holds->next->borrowernumber, $borrowernumbers[0], "Test Koha::Patron->holds");
 
-my $expired_borrowernumber = Koha::Patron->new({
-        firstname =>  'Expired',
-        surname => 'Patron',
-        categorycode => $category->{categorycode},
-        branchcode => $branch_1,
-	dateexpiry => '2000-01-01',
-    })->store->borrowernumber;
-
-t::lib::Mocks::mock_preference('BlockExpiredPatronOpacActions', 1);
-ok(
-    CanItemBeReserved($expired_borrowernumber, $itemnumber)->{status} eq 'patronExpired',
-    'Expired patron cannot reserve'
-);
-
 $holds = $item->current_holds;
 $first_hold = $holds->next;
 $borrowernumber = $first_hold->borrowernumber;
diff --git a/t/db_dependent/ILSDI_Services.t b/t/db_dependent/ILSDI_Services.t
index 430d900c77..b7e0b7622b 100644
--- a/t/db_dependent/ILSDI_Services.t
+++ b/t/db_dependent/ILSDI_Services.t
@@ -302,7 +302,7 @@ subtest 'LookupPatron test' => sub {
 
 subtest 'Holds test' => sub {
 
-    plan tests => 5;
+    plan tests => 6;
 
     $schema->storage->txn_begin;
 
@@ -448,6 +448,40 @@ subtest 'Holds test' => sub {
     $reply = C4::ILSDI::Services::HoldItem( $query );
     is( $reply->{code}, 'damaged', "Item is damaged" );
 
+    # Test Patron cannot reserve if expired and BlockExpiredPatronOpacActions
+    my $category = $builder->build({
+        source => 'Category',
+        value => { BlockExpiredPatronOpacActions => -1 }
+        });
+
+    my $branch_1 = $builder->build({ source => 'Branch' })->{ branchcode };
+
+    my $expired_borrowernumber = Koha::Patron->new({
+        firstname =>  'Expired',
+        surname => 'Patron',
+        categorycode => $category->{categorycode},
+        branchcode => $branch_1,
+        dateexpiry => '2000-01-01',
+    })->store->borrowernumber;
+
+    t::lib::Mocks::mock_preference('BlockExpiredPatronOpacActions', 1);
+
+    my $item5 = $builder->build({
+        source => 'Item',
+        value => {
+            biblionumber => $biblio->{biblionumber},
+            damaged => 0,
+        }
+    });
+
+    $query = new CGI;
+    $query->param( 'patron_id', $expired_borrowernumber);
+    $query->param( 'bib_id', $biblio->{biblionumber});
+    $query->param( 'item_id', $item5->{itemnumber});
+
+    $reply = C4::ILSDI::Services::HoldItem( $query );
+    is( $reply->{code}, 'PatronExpired', "Patron is expired" );
+
     $schema->storage->txn_rollback;
 };
 
-- 
2.20.1