Bug 25808: (QA follow-up) Add regression test
authorMartin Renvoize <martin.renvoize@ptfs-europe.com>
Thu, 14 Jan 2021 14:40:31 +0000 (14:40 +0000)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Thu, 21 Jan 2021 14:40:13 +0000 (15:40 +0100)
This patch adds a basic regression test for the bug.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
JD amended patch: remove trailing space char

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
t/db_dependent/SIP/ILS.t

index f08a259..d5031e5 100755 (executable)
 
 use Modern::Perl;
 
-use Test::More tests => 10;
+use Test::More tests => 11;
 
 use t::lib::TestBuilder;
 use t::lib::Mocks;
 
 use C4::Reserves;
+use C4::Circulation;
 use Koha::CirculationRules;
 use Koha::Database;
+use Koha::DateUtils;
 
 BEGIN {
     use_ok('C4::SIP::ILS');
@@ -122,4 +124,53 @@ subtest cancel_hold => sub {
     is( $item->biblio->holds->count(), 0, "Bib has 0 holds remaining");
     is( $item->holds->count(), 0,  "Item has 0 holds remaining");
 };
+
+subtest checkout => sub {
+    plan tests => 1;
+
+    my $library = $builder->build_object ({ class => 'Koha::Libraries' });
+    my $patron = $builder->build_object(
+        {
+            class => 'Koha::Patrons',
+            value => {
+                branchcode => $library->branchcode,
+            }
+        }
+    );
+    t::lib::Mocks::mock_userenv({ branchcode => $library->branchcode, flags => 1 });
+
+    my $item = $builder->build_sample_item({
+        library       => $library->branchcode,
+    });
+
+    Koha::CirculationRules->set_rules(
+        {
+            categorycode => $patron->categorycode,
+            branchcode   => $library->branchcode,
+            itemtype     => $item->effective_itemtype,
+            rules        => {
+                onshelfholds     => 1,
+                reservesallowed  => 3,
+                holds_per_record => 3,
+                issuelength      => 5,
+                lengthunit       => 'days',
+                renewalsallowed  => 6,
+            }
+        }
+    );
+
+    AddIssue( $patron->unblessed, $item->barcode, undef, 0 );
+    my $checkout = $item->checkout;
+    ok( defined($checkout), "Checkout added");
+    is( $checkout->renewals, 0, "Correct renewals");
+
+    my $ils = C4::SIP::ILS->new({ id => $library->branchcode });
+    my $sip_patron = C4::SIP::ILS::Patron->new( $patron->cardnumber );
+    my $transaction = $ils->checkout($patron->cardnumber,$item->barcode,undef,undef);
+
+    is( $transaction->{screen_msg},"Item already checked out to you: renewing item.","We get a success message when issue is renewed");
+
+    is( $checkout->renewals, 1, "Renewals has been reduced");
+};
+
 $schema->storage->txn_rollback;