From 5adb36c474a6f46d5ebaefaa0450c74f3be430d6 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Fri, 11 Feb 2022 15:28:10 -0300 Subject: [PATCH] Bug 30072: Unit tests Signed-off-by: Tomas Cohen Arazi Signed-off-by: Kyle M Hall --- t/db_dependent/Koha/Plugins/Holds_hooks.t | 65 ++++++++++++++++++++++- t/lib/plugins/Koha/Plugin/Test.pm | 10 ++++ 2 files changed, 74 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/Plugins/Holds_hooks.t b/t/db_dependent/Koha/Plugins/Holds_hooks.t index 2e40b9d939..2f56ce1081 100755 --- a/t/db_dependent/Koha/Plugins/Holds_hooks.t +++ b/t/db_dependent/Koha/Plugins/Holds_hooks.t @@ -16,7 +16,7 @@ use Modern::Perl; -use Test::More tests => 4; +use Test::More tests => 5; use Test::MockModule; use Test::Warn; @@ -80,3 +80,66 @@ subtest 'after_hold_create() hook tests' => sub { $schema->storage->txn_rollback; Koha::Plugins::Methods->delete; }; + +subtest 'Koha::Hold tests' => sub { + + plan tests => 4; + + $schema->storage->txn_begin; + + my $plugins = Koha::Plugins->new; + $plugins->InstallPlugins; + + my $plugin = Koha::Plugin::Test->new->enable; + + my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); + + # Reduce noise + t::lib::Mocks::mock_preference( 'HoldFeeMode', 'not_always' ); + t::lib::Mocks::mock_preference( 'HoldsLog', 0 ); + + my $hold = $builder->build_object( + { + class => 'Koha::Holds', + value => { + borrowernumber => $patron->id, + } + } + ); + + warning_like { + $hold->fill; + } + qr/after_hold_action called with action: fill, ref: Koha::Old::Hold/, + '->fill calls the after_hold_action hook'; + + $hold = $builder->build_object( + { + class => 'Koha::Holds', + value => { + borrowernumber => $patron->id, + } + } + ); + + warning_like { + $hold->suspend_hold; + } + qr/after_hold_action called with action: suspend, ref: Koha::Hold/, + '->suspend_hold calls the after_hold_action hook'; + + warning_like { + $hold->resume; + } + qr/after_hold_action called with action: resume, ref: Koha::Hold/, + '->resume calls the after_hold_action hook'; + + warning_like { + $hold->cancel; + } + qr/after_hold_action called with action: cancel, ref: Koha::Old::Hold/, + '->cancel calls the after_hold_action hook'; + + $schema->storage->txn_rollback; + Koha::Plugins::Methods->delete; +}; diff --git a/t/lib/plugins/Koha/Plugin/Test.pm b/t/lib/plugins/Koha/Plugin/Test.pm index c52064c199..9b135e2d2b 100644 --- a/t/lib/plugins/Koha/Plugin/Test.pm +++ b/t/lib/plugins/Koha/Plugin/Test.pm @@ -206,6 +206,16 @@ sub after_circ_action { } } +sub after_hold_action { + my ( $self, $params ) = @_; + + my $action = $params->{action}; + my $hold = $params->{payload}->{hold}; + + Koha::Exceptions::Exception->throw( + "after_hold_action called with action: $action, ref: " . ref($hold) ); +} + sub api_routes { my ( $self, $args ) = @_; -- 2.30.2