@@ -, +, @@ --- t/db_dependent/Koha/Plugins/Holds_hooks.t | 65 ++++++++++++++++++++++- t/lib/plugins/Koha/Plugin/Test.pm | 10 ++++ 2 files changed, 74 insertions(+), 1 deletion(-) --- a/t/db_dependent/Koha/Plugins/Holds_hooks.t +++ a/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; +}; --- a/t/lib/plugins/Koha/Plugin/Test.pm +++ a/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 ) = @_; --