From fffa3ac62f2b462f7c55ffd331fd77aebe9e348c Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Fri, 25 Feb 2022 05:49:56 -0300 Subject: [PATCH] Bug 30180: Unit tests Signed-off-by: Tomas Cohen Arazi --- t/db_dependent/Koha/Plugins/Holds_hooks.t | 47 ++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/Plugins/Holds_hooks.t b/t/db_dependent/Koha/Plugins/Holds_hooks.t index 04d19929ca..d1dd61f033 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 => 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; -- 2.35.1