Bug 18936: (follow-up) Adjust circ rule related tests so that they pass
authorJoonas Kylmälä <joonas.kylmala@helsinki.fi>
Wed, 29 Jan 2020 11:09:17 +0000 (11:09 +0000)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Tue, 4 Feb 2020 09:56:29 +0000 (09:56 +0000)
Bunch of tests broke after moving from issuingrules to
circulation_rules. This accomodates the tests for this refactoring and
DB change.

The itemtype did not exist in the DB. We create it at the beginning of
the tests. Ideally we would like to create it filling the form.

Signed-off-by: Minna Kivinen <minna.kivinen@hamk.fi>
Signed-off-by: Joonas Kylmälä <joonas.kylmala@helsinki.fi>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

t/db_dependent/HoldsQueue.t
t/db_dependent/Koha/Biblio.t
t/db_dependent/Koha/Item.t
t/db_dependent/selenium/basic_workflow.t

index 2c52c87..f70e61f 100755 (executable)
@@ -950,7 +950,6 @@ subtest "Test Local Holds Priority - Ensure no duplicate requests in holds queue
     $dbh->do("DELETE FROM tmp_holdsqueue");
     $dbh->do("DELETE FROM hold_fill_targets");
     $dbh->do("DELETE FROM reserves");
-    $dbh->do("DELETE FROM issuingrules");
     $dbh->do("DELETE FROM circulation_rules");
     Koha::Biblios->delete();
 
index 2abacff..790b623 100644 (file)
@@ -187,15 +187,18 @@ subtest 'pickup_locations' => sub {
     Koha::Patrons->search->delete;
     Koha::Items->search->delete;
     Koha::Libraries->search->delete;
+    Koha::CirculationRules->search->delete;
     $dbh->do('DELETE FROM issues');
-    $dbh->do('DELETE FROM issuingrules');
-    $dbh->do(
-        q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed)
-        VALUES (?, ?, ?, ?)},
-        {},
-        '*', '*', '*', 25
+    Koha::CirculationRules->set_rules(
+        {
+            categorycode => undef,
+            itemtype     => undef,
+            branchcode   => undef,
+            rules        => {
+                reservesallowed => 25,
+            }
+        }
     );
-    $dbh->do('DELETE FROM circulation_rules');
 
     my $root1 = $builder->build_object( { class => 'Koha::Library::Groups', value => { ft_local_hold_group => 1 } } );
     my $root2 = $builder->build_object( { class => 'Koha::Library::Groups', value => { ft_local_hold_group => 1 } } );
@@ -214,7 +217,6 @@ subtest 'pickup_locations' => sub {
         {
             branchcode => $library1->branchcode,
             itemtype   => undef,
-            categorycode => undef,
             rules => {
                 holdallowed => 1,
                 hold_fulfillment_policy => 'any',
@@ -227,7 +229,6 @@ subtest 'pickup_locations' => sub {
         {
             branchcode => $library2->branchcode,
             itemtype   => undef,
-            categorycode => undef,
             rules => {
                 holdallowed => 3,
                 hold_fulfillment_policy => 'holdgroup',
@@ -240,7 +241,6 @@ subtest 'pickup_locations' => sub {
         {
             branchcode => $library3->branchcode,
             itemtype   => undef,
-            categorycode => undef,
             rules => {
                 holdallowed => 3,
                 hold_fulfillment_policy => 'patrongroup',
@@ -253,7 +253,6 @@ subtest 'pickup_locations' => sub {
         {
             branchcode => $library4->branchcode,
             itemtype   => undef,
-            categorycode => undef,
             rules => {
                 holdallowed => 2,
                 hold_fulfillment_policy => 'holdingbranch',
@@ -266,7 +265,6 @@ subtest 'pickup_locations' => sub {
         {
             branchcode => $library5->branchcode,
             itemtype   => undef,
-            categorycode => undef,
             rules => {
                 holdallowed => 2,
                 hold_fulfillment_policy => 'homebranch',
@@ -279,7 +277,6 @@ subtest 'pickup_locations' => sub {
         {
             branchcode => $library6->branchcode,
             itemtype   => undef,
-            categorycode => undef,
             rules => {
                 holdallowed => 1,
                 hold_fulfillment_policy => 'holdgroup',
@@ -292,7 +289,6 @@ subtest 'pickup_locations' => sub {
         {
             branchcode => $library7->branchcode,
             itemtype   => undef,
-            categorycode => undef,
             rules => {
                 holdallowed => 3,
                 hold_fulfillment_policy => 'holdingbranch',
@@ -306,7 +302,6 @@ subtest 'pickup_locations' => sub {
         {
             branchcode => $library8->branchcode,
             itemtype   => undef,
-            categorycode => undef,
             rules => {
                 holdallowed => 2,
                 hold_fulfillment_policy => 'patrongroup',
index 459c59f..f4484ca 100644 (file)
@@ -157,14 +157,17 @@ subtest 'pickup_locations' => sub {
     Koha::Items->search->delete;
     Koha::Libraries->search->delete;
     $dbh->do('DELETE FROM issues');
-    $dbh->do('DELETE FROM issuingrules');
-    $dbh->do(
-        q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed)
-        VALUES (?, ?, ?, ?)},
-        {},
-        '*', '*', '*', 25
+    Koha::CirculationRules->search->delete;
+    Koha::CirculationRules->set_rules(
+        {
+            categorycode => undef,
+            itemtype     => undef,
+            branchcode   => undef,
+            rules        => {
+                reservesallowed => 25,
+            }
+        }
     );
-    $dbh->do('DELETE FROM circulation_rules');
 
     my $root1 = $builder->build_object( { class => 'Koha::Library::Groups', value => { ft_local_hold_group => 1 } } );
     my $root2 = $builder->build_object( { class => 'Koha::Library::Groups', value => { ft_local_hold_group => 1 } } );
@@ -273,7 +276,6 @@ subtest 'pickup_locations' => sub {
             {
                 branchcode => undef,
                 itemtype   => undef,
-                categorycode => undef,
                 rules => {
                     holdallowed => $ha,
                     hold_fulfillment_policy => $hfp,
index 5f785d2..5fbe949 100644 (file)
@@ -72,7 +72,7 @@ our $sample_data = {
     issuingrule => {
         categorycode  => 'test_cat',
         itemtype      => 'IT4test',
-        branchcode    => '*',
+        branchcode    => undef,
         maxissueqty   => '5',
         issuelength   => '5',
         lengthunit    => 'days',
@@ -81,6 +81,8 @@ our $sample_data = {
 };
 our ( $borrowernumber, $start, $prev_time, $cleanup_needed );
 
+$dbh->do(q|INSERT INTO itemtypes(itemtype) VALUES (?)|, undef, $sample_data->{itemtype}{itemtype});
+
 SKIP: {
     eval { require Selenium::Remote::Driver; };
     skip "Selenium::Remote::Driver is needed for selenium tests.", 20 if $@;
@@ -146,17 +148,18 @@ SKIP: {
     time_diff("add biblio");
 
     my $itemtype = $sample_data->{itemtype};
-    $dbh->do(q|INSERT INTO itemtypes (itemtype, description, rentalcharge, notforloan) VALUES (?, ?, ?, ?)|, undef, $itemtype->{itemtype}, $itemtype->{description}, $itemtype->{rentalcharge}, $itemtype->{notforloan});
 
     my $issuing_rules = $sample_data->{issuingrule};
-    $dbh->do(q|INSERT INTO issuingrules (categorycode, itemtype, branchcode, issuelength, lengthunit, renewalperiod) VALUES (?, ?, ?, ?, ?, ?)|, undef, $issuing_rules->{categorycode}, $issuing_rules->{itemtype}, $issuing_rules->{branchcode}, $issuing_rules->{issuelength}, $issuing_rules->{lengthunit}, $issuing_rules->{renewalperiod});
     Koha::CirculationRules->set_rules(
         {
             categorycode => $issuing_rules->{categorycode},
             itemtype     => $issuing_rules->{itemtype},
             branchcode   => $issuing_rules->{branchcode},
             rules        => {
-                maxissueqty => $issuing_rules->{maxissueqty}
+                maxissueqty => $issuing_rules->{maxissueqty},
+                issuelength => $issuing_rules->{issuelength},
+                lengthunit => $issuing_rules->{lengthunit},
+                renewalperiod => $issuing_rules->{renewalperiod},
             }
         }
     );
@@ -245,7 +248,7 @@ sub cleanup {
         $dbh->do(qq|DELETE FROM biblio WHERE title = "test biblio $i"|);
     };
     $dbh->do(q|DELETE FROM itemtypes WHERE itemtype=?|, undef, $sample_data->{itemtype}{itemtype});
-    $dbh->do(q|DELETE FROM issuingrules WHERE categorycode=? AND itemtype=? AND branchcode=?|, undef, $sample_data->{issuingrule}{categorycode}, $sample_data->{issuingrule}{itemtype}, $sample_data->{issuingrule}{branchcode});
+    $dbh->do(q|DELETE FROM circulation_rules WHERE categorycode=? AND itemtype=? AND branchcode=?|, undef, $sample_data->{issuingrule}{categorycode}, $sample_data->{issuingrule}{itemtype}, $sample_data->{issuingrule}{branchcode});
 }
 
 sub time_diff {