Bug 9532: add regression test
authorGalen Charlton <gmc@esilibrary.com>
Mon, 5 May 2014 17:16:37 +0000 (17:16 +0000)
committerGalen Charlton <gmc@esilibrary.com>
Mon, 5 May 2014 17:17:36 +0000 (17:17 +0000)
To test:

[1] Run prove -v t/db_dependent/Holds.t.  The last test
    should fail.
[2] Apply the main patch.
[3] Run step 1 again.  This time the tests should all pass.

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
t/db_dependent/Holds.t

index d72a81d..d51dfdb 100755 (executable)
@@ -6,7 +6,7 @@ use t::lib::Mocks;
 use C4::Context;
 use C4::Branch;
 
-use Test::More tests => 29;
+use Test::More tests => 32;
 use MARC::Record;
 use C4::Biblio;
 use C4::Items;
@@ -26,6 +26,11 @@ $dbh->{RaiseError} = 1;
 
 my $borrowers_count = 5;
 
+$dbh->do('DELETE FROM itemtypes');
+my $insert_sth = $dbh->prepare('INSERT INTO itemtypes (itemtype) VALUES (?)');
+$insert_sth->execute('CAN');
+$insert_sth->execute('CANNOT');
+
 # Setup Test------------------------
 # Helper biblio.
 diag("Creating biblio instance for testing.");
@@ -187,6 +192,12 @@ $dbh->do(
     {},
     '*', '*', '*', 25
 );
+$dbh->do(
+    q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed)
+      VALUES (?, ?, ?, ?)}, 
+    {},
+    '*', '*', 'CANNOT', 0 
+);
 
 # make sure some basic sysprefs are set
 t::lib::Mocks::mock_preference('ReservesControlBranch', 'homebranch');
@@ -216,7 +227,6 @@ ok(
 
 # Regression test for bug 11336
 ($bibnum, $title, $bibitemnum) = create_helper_biblio();
-my ( $hold1, $hold2 );
 ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => 'CPL', holdingbranch => 'CPL' } , $bibnum);
 AddReserve(
     $branch,
@@ -286,14 +296,43 @@ C4::Context->set_preference( 'AllowHoldsOnDamagedItems', 0 );
 ok( !CanItemBeReserved( $borrowernumbers[0], $itemnumber), "Patron cannot reserve damaged item with AllowHoldsOnDamagedItems disabled" );
 ok( !defined( ( CheckReserves($itemnumber) )[1] ), "Hold cannot be trapped for damaged item with AllowHoldsOnDamagedItems disabled" );
 
+# Regression test for bug 9532
+($bibnum, $title, $bibitemnum) = create_helper_biblio('CANNOT');
+($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => 'CPL', holdingbranch => 'CPL', itype => 'CANNOT' } , $bibnum);
+AddReserve(
+    $branch,
+    $borrowernumbers[0],
+    $bibnum,
+    'a',
+    '',
+    1,
+);
+ok(
+    !CanItemBeReserved( $borrowernumbers[0], $itemnumber),
+    "cannot request item if policy that matches on item-level item type forbids it"
+);
+ModItem({ itype => 'CAN' }, $item_bibnum, $itemnumber);
+ok(
+    CanItemBeReserved( $borrowernumbers[0], $itemnumber),
+    "can request item if policy that matches on item type allows it"
+);
+
+t::lib::Mocks::mock_preference('item-level_itypes', 0);
+ModItem({ itype => undef }, $item_bibnum, $itemnumber);
+ok(
+    !CanItemBeReserved( $borrowernumbers[0], $itemnumber),
+    "cannot request item if policy that matches on bib-level item type forbids it (bug 9532)"
+);
 
 # Helper method to set up a Biblio.
 sub create_helper_biblio {
+    my $itemtype = shift;
     my $bib = MARC::Record->new();
     my $title = 'Silence in the library';
     $bib->append_fields(
         MARC::Field->new('100', ' ', ' ', a => 'Moffat, Steven'),
         MARC::Field->new('245', ' ', ' ', a => $title),
+        MARC::Field->new('942', ' ', ' ', c => $itemtype),
     );
     return ($bibnum, $title, $bibitemnum) = AddBiblio($bib, '');
 }