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;
27 use t::lib::TestBuilder;
30 # Mock pluginsdir before loading Plugins module
31 my $path = dirname(__FILE__) . '/../../../lib';
32 t::lib::Mocks::mock_config( 'pluginsdir', $path );
34 use_ok('Koha::Plugins');
35 use_ok('Koha::Plugins::Handler');
36 use_ok('Koha::Plugin::Test');
39 my $schema = Koha::Database->new->schema;
40 my $builder = t::lib::TestBuilder->new;
42 t::lib::Mocks::mock_config( 'enable_plugins', 1 );
44 subtest 'after_biblio_action() and after_item_action() hooks tests' => sub {
48 $schema->storage->txn_begin;
50 my $plugins = Koha::Plugins->new;
51 $plugins->InstallPlugins;
53 my $plugin = Koha::Plugin::Test->new->enable;
55 my $test_plugin = Test::MockModule->new('Koha::Plugin::Test');
56 $test_plugin->mock( 'item_barcode_transform', undef );
60 warning_like { ( $biblio_id, undef ) = C4::Biblio::AddBiblio( MARC::Record->new(), '' ); }
61 qr/after_biblio_action called with action: create, ref: Koha::Biblio/,
62 'AddBiblio calls the hook with action=create';
64 warning_like { C4::Biblio::ModBiblio( MARC::Record->new(), $biblio_id, '' ); }
65 qr/after_biblio_action called with action: modify, ref: Koha::Biblio/,
66 'ModBiblio calls the hook with action=modify';
69 warning_like { $item = $builder->build_sample_item({ biblionumber => $biblio_id }); }
70 qr/after_item_action called with action: create, ref: Koha::Item item_id defined: yes itemnumber defined: yes/,
71 'AddItem calls the hook with action=create';
73 warning_like { $item->location('shelves')->store; }
74 qr/after_item_action called with action: modify, ref: Koha::Item item_id defined: yes itemnumber defined: yes/,
75 'ModItem calls the hook with action=modify';
77 my $itemnumber = $item->id;
78 warning_like { $item->delete; }
79 qr/after_item_action called with action: delete, id: $itemnumber/,
80 'DelItem calls the hook with action=delete, item_id passed';
82 warning_like { C4::Biblio::DelBiblio( $biblio_id ); }
83 qr/after_biblio_action called with action: delete, id: $biblio_id/,
84 'DelBiblio calls the hook with action=delete biblio_id passed';
86 $schema->storage->txn_rollback;
87 Koha::Plugins::Methods->delete;