@@ -, +, @@ --- t/db_dependent/Koha/Plugins/Holds_hooks.t | 47 ++++++++++++++++++++++- 1 file changed, 46 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 => 5; +use Test::More tests => 6; use Test::MockModule; use Test::Warn; @@ -67,6 +67,7 @@ subtest 'after_hold_create() hook tests' => sub { $test_plugin->mock( 'after_item_action', undef ); $test_plugin->mock( 'after_biblio_action', undef ); $test_plugin->mock( 'item_barcode_transform', undef ); + $test_plugin->mock( 'after_hold_action', undef ); my $biblio = $builder->build_sample_biblio(); my $item_1 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber } ); @@ -82,6 +83,50 @@ subtest 'after_hold_create() hook tests' => sub { Koha::Plugins::Methods->delete; }; +subtest 'after_hold_action (placed) hook tests' => sub { + + plan tests => 1; + + $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' } ); + + t::lib::Mocks::mock_userenv( + { + patron => $patron, + branchcode => $patron->branchcode + } + ); + + # Avoid testing useless warnings + my $test_plugin = Test::MockModule->new('Koha::Plugin::Test'); + $test_plugin->mock( 'after_item_action', undef ); + $test_plugin->mock( 'after_biblio_action', undef ); + $test_plugin->mock( 'item_barcode_transform', undef ); + $test_plugin->mock( 'after_hold_create', undef ); + + my $biblio = $builder->build_sample_biblio(); + my $item_1 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber } ); + + warning_like { + AddReserve( + { branchcode => $patron->branchcode, + borrowernumber => $patron->borrowernumber, + biblionumber => $item_1->biblionumber + } + ); + } + qr/after_hold_action called with action: place, ref: Koha::Hold/, 'AddReserve calls the after_hold_action hook'; + + $schema->storage->txn_rollback; + Koha::Plugins::Methods->delete; +}; + subtest 'Koha::Hold tests' => sub { plan tests => 4; --