Bug 26108: Regression tests
authorTomas Cohen Arazi <tomascohen@theke.io>
Fri, 31 Jul 2020 12:47:56 +0000 (09:47 -0300)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Fri, 31 Jul 2020 13:04:44 +0000 (15:04 +0200)
The current implementation makes the assumption that if $issue is
defined, then it is the 'return' use case. This is correct, but
incomplete: after verifying that there's actually an issue, the return
can be rejected for various reasons.

This patch introduces a regression test for one of those situations
(which I consider enough for testing purposes) . It highlights that the
hook shouldn't be called if there hasn't been an actual checkin.

To test:
1. Apply this patch
2. Run:
   $ kshell
  k$ prove t/db_dependent/Koha/Plugins/Circulation_hooks.t
=> FAIL: Tests fail because there's an unexpected warining printed by
the erroneous plugin call (i.e. there's been no return but the plugin is
called anyway).

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

t/db_dependent/Koha/Plugins/Circulation_hooks.t

index be0f707..5f8569d 100755 (executable)
@@ -92,7 +92,17 @@ subtest 'after_circ_action() hook tests' => sub {
     };
 
     subtest 'AddReturn' => sub {
-        plan tests => 1;
+        plan tests => 2;
+
+        t::lib::Mocks::mock_preference('BlockReturnOfWithdrawnItems', 1);
+        $item_1->set({ withdrawn => 1 })->store;
+
+        warning_is {
+            AddReturn( $item_1->barcode, $patron->branchcode );
+        } undef, 'No hook called because no return happened';
+
+        t::lib::Mocks::mock_preference('BlockReturnOfWithdrawnItems', 0);
+        $item_1->set({ withdrawn => 0 })->store;
 
         warning_like {
             AddReturn( $item_1->barcode, $patron->branchcode );