Bug 17600: Standardize our EXPORT_OK
[srvgit] / t / db_dependent / Circulation / Branch.t
index c8fe89d..00352ac 100755 (executable)
 
 use Modern::Perl;
 
-use C4::Circulation;
-use C4::Items;
-use C4::Biblio;
+use C4::Circulation qw( AddIssue AddReturn GetBranchBorrowerCircRule GetBranchItemRule );
+use C4::Items qw( ModItemTransfer );
+use C4::Biblio qw( AddBiblio );
 use C4::Context;
 use Koha::CirculationRules;
 
 use Koha::Patrons;
 
-use Test::More tests => 15;
+use Test::More tests => 16;
 use t::lib::Mocks;
 use t::lib::TestBuilder;
 
 BEGIN {
-    use_ok('C4::Circulation');
+    use_ok('C4::Circulation', qw( AddIssue AddReturn GetBranchBorrowerCircRule GetBranchItemRule ));
 }
 
 can_ok( 'C4::Circulation', qw(
@@ -174,7 +174,7 @@ Koha::CirculationRules->set_rules(
         branchcode   => $samplebranch2->{branchcode},
         itemtype     => undef,
         rules        => {
-            holdallowed       => 1,
+            holdallowed       => 'from_home_library',
             returnbranch      => 'holdingbranch',
         }
     }
@@ -195,7 +195,7 @@ Koha::CirculationRules->set_rules(
         branchcode   => undef,
         itemtype     => undef,
         rules        => {
-            holdallowed       => 3,
+            holdallowed       => 'from_local_hold_group',
             returnbranch      => 'homebranch',
         }
     }
@@ -206,7 +206,7 @@ Koha::CirculationRules->set_rules(
         branchcode   => $samplebranch1->{branchcode},
         itemtype     => $sampleitemtype1->{itemtype},
         rules        => {
-            holdallowed       => 5,
+            holdallowed       => 'invalid_value',
             returnbranch      => 'homebranch',
         }
     }
@@ -216,7 +216,7 @@ Koha::CirculationRules->set_rules(
         branchcode   => $samplebranch2->{branchcode},
         itemtype     => $sampleitemtype1->{itemtype},
         rules        => {
-            holdallowed       => 5,
+            holdallowed       => 'invalid_value',
             returnbranch      => 'holdingbranch',
         }
     }
@@ -226,7 +226,7 @@ Koha::CirculationRules->set_rules(
         branchcode   => $samplebranch2->{branchcode},
         itemtype     => $sampleitemtype2->{itemtype},
         rules        => {
-            holdallowed       => 5,
+            holdallowed       => 'invalid_value',
             returnbranch      => 'noreturn',
         }
     }
@@ -264,22 +264,22 @@ is_deeply(
         $samplebranch1->{branchcode},
         $sampleitemtype1->{itemtype},
     ),
-    { returnbranch => 'homebranch', holdallowed => 5, @lazy_any },
+    { returnbranch => 'homebranch', holdallowed => 'invalid_value', @lazy_any },
     "GetBranchitem returns holdallowed and return branch"
 );
 is_deeply(
     GetBranchItemRule(),
-    { returnbranch => 'homebranch', holdallowed => 3, @lazy_any },
+    { returnbranch => 'homebranch', holdallowed => 'from_local_hold_group', @lazy_any },
 "Without parameters GetBranchItemRule returns the values in default_circ_rules"
 );
 is_deeply(
     GetBranchItemRule( $samplebranch2->{branchcode} ),
-    { returnbranch => 'holdingbranch', holdallowed => 1, @lazy_any },
+    { returnbranch => 'holdingbranch', holdallowed => 'from_home_library', @lazy_any },
 "With only a branchcode GetBranchItemRule returns values in default_branch_circ_rules"
 );
 is_deeply(
     GetBranchItemRule( -1, -1 ),
-    { returnbranch => 'homebranch', holdallowed => 3, @lazy_any },
+    { returnbranch => 'homebranch', holdallowed => 'from_local_hold_group', @lazy_any },
     "With only one parametern GetBranchItemRule returns default values"
 );
 
@@ -307,7 +307,13 @@ is( $messages->{NeedsTransfer}, $samplebranch1->{branchcode}, "AddReturn respect
 ModItemTransfer($item_id2, $samplebranch2->{branchcode}, $samplebranch1->{branchcode}, "ReturnToHolding");
 # Fulfill it
 ($doreturn, $messages, $iteminformation, $borrower) = AddReturn('barcode_2',$samplebranch1->{branchcode});
-is( $messages->{NeedsTransfer}, undef, "AddReturn does not generate a new transfer for return policy when resolving an existing transfer" );
+is( $messages->{NeedsTransfer}, undef, "AddReturn does not generate a new transfer for return policy when resolving an existing non-Reserve transfer" );
+
+# Generate a hold caused transfer which doesn't have a hold i.e. is the hold is cancelled
+ModItemTransfer($item_id2, $samplebranch2->{branchcode}, $samplebranch1->{branchcode}, "Reserve");
+# Fulfill it
+($doreturn, $messages, $iteminformation, $borrower) = AddReturn('barcode_2',$samplebranch1->{branchcode});
+is( $messages->{NeedsTransfer}, $samplebranch2->{branchcode}, "AddReturn generates a new transfer for hold transfer if the hold was cancelled" );
 
 # item3 should not trigger transfer - floating collection
 $query =