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>
};
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 );