3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 3 of the License, or (at your option) any later
10 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License along
15 # with Koha; if not, see <http://www.gnu.org/licenses>.
19 use Test::More tests => 4;
24 use t::lib::TestBuilder;
27 use C4::Circulation qw();
28 use Koha::CirculationRules;
29 use Koha::Plugins::Methods;
33 # Mock pluginsdir before loading Plugins module
34 my $path = dirname(__FILE__) . '/../../../lib/plugins';
35 t::lib::Mocks::mock_config( 'pluginsdir', $path );
37 use_ok('Koha::Plugins');
38 use_ok('Koha::Plugins::Handler');
39 use_ok('Koha::Plugin::Test');
42 my $schema = Koha::Database->new->schema;
43 my $builder = t::lib::TestBuilder->new;
45 t::lib::Mocks::mock_config( 'enable_plugins', 1 );
47 subtest 'after_recall_action hook' => sub {
51 $schema->storage->txn_begin;
53 my $plugins = Koha::Plugins->new;
54 $plugins->InstallPlugins;
56 my $plugin = Koha::Plugin::Test->new->enable;
57 # Avoid testing useless warnings
58 my $test_plugin = Test::MockModule->new('Koha::Plugin::Test');
59 $test_plugin->mock( 'after_item_action', undef );
60 $test_plugin->mock( 'after_circ_action', undef );
61 $test_plugin->mock( 'after_biblio_action', undef );
62 $test_plugin->mock( 'patron_barcode_transform', undef );
63 $test_plugin->mock( 'item_barcode_transform', undef );
65 my $item = $builder->build_sample_item();
66 my $biblio = $item->biblio;
67 my $branch = $item->holdingbranch;
68 my $category = $builder->build({ source => 'Category' })->{ categorycode };
69 my $patron1 = $builder->build_object({ class => 'Koha::Patrons', value => { categorycode => $category, branchcode => $branch } });
70 my $patron2 = $builder->build_object({ class => 'Koha::Patrons', value => { categorycode => $category, branchcode => $branch } });
71 t::lib::Mocks::mock_userenv({ patron => $patron1 });
73 Koha::CirculationRules->set_rules({
75 categorycode => undef,
78 'recall_due_date_interval' => undef,
79 'recalls_allowed' => 10,
83 C4::Circulation::AddIssue( $patron2->unblessed, $item->barcode );
86 Koha::Recalls->add_recall({
89 branchcode => $branch,
91 expirationdate => undef,
92 interface => 'COMMANDLINE',
95 qr/after_recall_action called with action: add, ref: Koha::Recall/,
96 '->add_recall calls the after_recall_action hook with action add';
98 Koha::Plugins::Methods->delete;
99 $schema->storage->txn_rollback;