From a3a542a04daaa614f3752d614a135f6e9833b02a Mon Sep 17 00:00:00 2001
From: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Date: Wed, 6 Mar 2013 14:58:29 +0100
Subject: [PATCH] Bug 9743: Unit test for mandatory hold notes
Content-Type: text/plain; charset="utf-8"

Test plan:
Export PERL5LIB and KOHA_CONF to your test database.
Run t/db_dependent/Reserves.t.
You should have 7 tests running ok.
---
 t/db_dependent/Reserves.t |   29 ++++++++++++++++++++++++-----
 1 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/t/db_dependent/Reserves.t b/t/db_dependent/Reserves.t
index 1e20318..19d5a0b 100755
--- a/t/db_dependent/Reserves.t
+++ b/t/db_dependent/Reserves.t
@@ -4,7 +4,7 @@ use strict;
 use warnings;
 use C4::Branch;
 
-use Test::More tests => 4;
+use Test::More tests => 7;
 use MARC::Record;
 use C4::Biblio;
 use C4::Items;
@@ -21,8 +21,10 @@ diag("\nCreating biblio instance for testing.");
 my ($bibnum, $title, $bibitemnum) = create_helper_biblio();
 
 # Helper item for that biblio.
+my @branches = GetBranchesLoop();
+my $branch = $branches[0][0]{value};
 diag("Creating item instance for testing.");
-my ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => 'CPL', holdingbranch => 'CPL' } , $bibnum);
+my ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch||'CPL', holdingbranch => $branch||'CPL' } , $bibnum);
 
 # Modify item; setting barcode.
 my $testbarcode = '97531';
@@ -50,9 +52,6 @@ my $notes          = '';
 my $checkitem      = undef;
 my $found          = undef;
 
-my @branches = GetBranchesLoop();
-my $branch = $branches[0][0]{value};
-
 AddReserve($branch,    $borrowernumber, $biblionumber,
         $constraint, $bibitems,  $priority, $resdate, $expdate, $notes,
         $title,      $checkitem, $found);
@@ -66,6 +65,25 @@ ok($status eq "Reserved", "CheckReserves Test 2");
 ($status, $reserve, $all_reserves) = CheckReserves(undef, $barcode);
 ok($status eq "Reserved", "CheckReserves Test 3");
 
+#tests for mandatory hold notes
+my $shownotes=C4::Context->preference('OPACShowHoldNotes');
+my $mandnotes=C4::Context->preference('OPACMandatoryHoldNotes');
+C4::Context->set_preference('OPACShowHoldNotes', 1);
+C4::Context->set_preference('OPACMandatoryHoldNotes', '1&2');
+my $record=GetMarcBiblio($bibnum);
+my $retval= C4::Reserves::GetMandatoryNoteReason($bibnum,$record);
+ok($retval==1, "Mandatory hold notes test 1");
+C4::Context->set_preference('OPACMandatoryHoldNotes', '4');
+$retval= C4::Reserves::GetMandatoryNoteReason($bibnum,$record);
+ok($retval==0, "Mandatory hold notes test 2");
+C4::Context->set_preference('OPACMandatoryHoldNotes', '1&2');
+C4::Context->set_preference('OPACShowHoldNotes', 0);
+$retval= C4::Reserves::GetMandatoryNoteReason($bibnum,$record);
+ok($retval==0, "Mandatory hold notes test 3");
+#reset prefs
+C4::Context->set_preference('OPACShowHoldNotes', $shownotes);
+C4::Context->set_preference('OPACMandatoryHoldNotes', $mandnotes);
+
 
 # Teardown Test---------------------
 # Delete item.
@@ -83,6 +101,7 @@ sub create_helper_biblio {
     $bib->append_fields(
         MARC::Field->new('100', ' ', ' ', a => 'Moffat, Steven'),
         MARC::Field->new('245', ' ', ' ', a => $title),
+        MARC::Field->new('300', ' ', ' ', a => '2 vols for triggering notes'),
     );
     return ($bibnum, $title, $bibitemnum) = AddBiblio($bib, '');
 }
-- 
1.7.7.6