Bug 18928: Update new occurrences
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Thu, 21 Feb 2019 20:27:57 +0000 (17:27 -0300)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Mon, 1 Jul 2019 13:57:10 +0000 (14:57 +0100)
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Agustin Moyano <agustinmoyano@theke.io>
Signed-off-by: Liz Rea <wizzyrea@gmail.com>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

t/db_dependent/Circulation/Branch.t
t/db_dependent/Circulation/SwitchOnSiteCheckouts.t
t/db_dependent/Circulation/TooMany.t
t/db_dependent/Holds/DisallowHoldIfItemsAvailable.t

index 1c2d17a..dfd65d3 100644 (file)
@@ -176,12 +176,6 @@ Koha::CirculationRules->set_rules(
     }
 );
 
-$query = q|
-    INSERT INTO default_circ_rules
-    (singleton, holdallowed, returnbranch)
-    VALUES( ?, ?, ? )
-|;
-$dbh->do( $query, {}, 'singleton', 3, 'homebranch' );
 Koha::CirculationRules->set_rules(
     {
         branchcode   => undef,
index 7ef05ee..fed7bc2 100644 (file)
@@ -37,11 +37,7 @@ $schema->storage->txn_begin;
 
 our $dbh = C4::Context->dbh;
 
-$dbh->do(q|DELETE FROM branch_item_rules|);
 $dbh->do(q|DELETE FROM issues|);
-$dbh->do(q|DELETE FROM default_branch_circ_rules|);
-$dbh->do(q|DELETE FROM default_circ_rules|);
-$dbh->do(q|DELETE FROM default_branch_item_rules|);
 $dbh->do(q|DELETE FROM issuingrules|);
 
 my $builder = t::lib::TestBuilder->new();
index a5ad926..0f39f11 100644 (file)
@@ -43,10 +43,6 @@ $dbh->do(q|DELETE FROM branches|);
 $dbh->do(q|DELETE FROM categories|);
 $dbh->do(q|DELETE FROM accountlines|);
 $dbh->do(q|DELETE FROM itemtypes|);
-$dbh->do(q|DELETE FROM branch_item_rules|);
-$dbh->do(q|DELETE FROM default_branch_circ_rules|);
-$dbh->do(q|DELETE FROM default_circ_rules|);
-$dbh->do(q|DELETE FROM default_branch_item_rules|);
 $dbh->do(q|DELETE FROM issuingrules|);
 Koha::CirculationRules->search()->delete();
 
index c5a3b8f..755721d 100755 (executable)
@@ -114,9 +114,6 @@ AddReturn( $item1->barcode );
 
         my $hold_allowed_from_home_library = 1;
         my $hold_allowed_from_any_libraries = 2;
-        my $sth_delete_rules = $dbh->prepare(q|DELETE FROM default_circ_rules|);
-        my $sth_insert_rule = $dbh->prepare(q|INSERT INTO default_circ_rules(singleton, holdallowed, hold_fulfillment_policy, returnbranch) VALUES ('singleton', ?, 'any', 'homebranch');|);
-        my $sth_insert_branch_rule = $dbh->prepare(q|INSERT INTO default_branch_circ_rules(branchcode, holdallowed, hold_fulfillment_policy, returnbranch) VALUES (?, ?, 'any', 'homebranch');|);
 
         subtest 'Item is available at a different library' => sub {
             plan tests => 7;
@@ -129,15 +126,14 @@ AddReturn( $item1->barcode );
             #Borrower1 is from library A
 
             {
-                $sth_delete_rules->execute;
-                $sth_insert_rule->execute( $hold_allowed_from_home_library );
+                set_holdallowed_rule( $hold_allowed_from_home_library );
 
                 t::lib::Mocks::mock_preference('ReservesControlBranch', 'ItemHomeLibrary');
                 $is = IsAvailableForItemLevelRequest( $item1, $patron1);
                 is( $is, 1, "Hold allowed from home library + ReservesControlBranch=ItemHomeLibrary, One item is available at different library, not holdable = none available => the hold is allowed at item level" );
                 $is = IsAvailableForItemLevelRequest( $item1, $patron2);
                 is( $is, 1, "Hold allowed from home library + ReservesControlBranch=ItemHomeLibrary, One item is available at home library, holdable = one available => the hold is not allowed at item level" );
-                $sth_insert_branch_rule->execute( $library_B, $hold_allowed_from_any_libraries );
+                set_holdallowed_rule( $hold_allowed_from_any_libraries, $library_B );
                 #Adding a rule for the item's home library affects the availability for a borrower from another library because ReservesControlBranch is set to ItemHomeLibrary
                 $is = IsAvailableForItemLevelRequest( $item1, $patron1);
                 is( $is, 0, "Hold allowed from home library + ReservesControlBranch=ItemHomeLibrary, One item is available at different library, holdable = one available => the hold is not allowed at item level" );
@@ -146,14 +142,13 @@ AddReturn( $item1->barcode );
                 $is = IsAvailableForItemLevelRequest( $item1, $patron1);
                 is( $is, 1, "Hold allowed from home library + ReservesControlBranch=PatronLibrary, One item is available at different library, not holdable = none available => the hold is allowed at item level" );
                 #Adding a rule for the patron's home library affects the availability for an item from another library because ReservesControlBranch is set to PatronLibrary
-                $sth_insert_branch_rule->execute( $library_A, $hold_allowed_from_any_libraries );
+                set_holdallowed_rule( $hold_allowed_from_any_libraries, $library_A );
                 $is = IsAvailableForItemLevelRequest( $item1, $patron1);
                 is( $is, 0, "Hold allowed from home library + ReservesControlBranch=PatronLibrary, One item is available at different library, holdable = one available => the hold is not allowed at item level" );
             }
 
             {
-                $sth_delete_rules->execute;
-                $sth_insert_rule->execute( $hold_allowed_from_any_libraries );
+                set_holdallowed_rule( $hold_allowed_from_any_libraries );
 
                 t::lib::Mocks::mock_preference('ReservesControlBranch', 'ItemHomeLibrary');
                 $is = IsAvailableForItemLevelRequest( $item1, $patron1);
@@ -178,8 +173,7 @@ AddReturn( $item1->barcode );
             #ReservesControlBranch is not checked in these subs we are testing?
 
             {
-                $sth_delete_rules->execute;
-                $sth_insert_rule->execute( $hold_allowed_from_home_library );
+                set_holdallowed_rule( $hold_allowed_from_home_library );
 
                 t::lib::Mocks::mock_preference('ReservesControlBranch', 'ItemHomeLibrary');
                 $is = IsAvailableForItemLevelRequest( $item1, $patron1);
@@ -191,8 +185,7 @@ AddReturn( $item1->barcode );
             }
 
             {
-                $sth_delete_rules->execute;
-                $sth_insert_rule->execute( $hold_allowed_from_any_libraries );
+                set_holdallowed_rule( $hold_allowed_from_any_libraries );
 
                 t::lib::Mocks::mock_preference('ReservesControlBranch', 'ItemHomeLibrary');
                 $is = IsAvailableForItemLevelRequest( $item1, $patron1);
@@ -238,3 +231,19 @@ is( $is, 1, "Item can be held, items in transit are not available" );
 
 # Cleanup
 $schema->storage->txn_rollback;
+
+sub set_holdallowed_rule {
+    my ( $holdallowed, $branchcode ) = @_;
+    Koha::CirculationRules->set_rules(
+        {
+            branchcode   => $branchcode || undef,
+            categorycode => undef,
+            itemtype     => undef,
+            rules        => {
+                holdallowed              => $holdallowed,
+                hold_fulfillment_policy  => 'any',
+                returnbranch             => 'homebranch',
+            }
+        }
+    );
+}