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>.
20 use Test::More tests => 4;
25 use C4::AuthoritiesMarc ();
29 use t::lib::TestBuilder;
32 # Mock pluginsdir before loading Plugins module
33 my $path = dirname(__FILE__) . '/../../../lib/plugins';
34 t::lib::Mocks::mock_config( 'pluginsdir', $path );
36 use_ok('Koha::Plugins');
37 use_ok('Koha::Plugins::Handler');
38 use_ok('Koha::Plugin::Test');
41 my $schema = Koha::Database->new->schema;
42 my $builder = t::lib::TestBuilder->new;
44 t::lib::Mocks::mock_config( 'enable_plugins', 1 );
46 subtest 'after_authority_action hook' => sub {
49 $schema->storage->txn_begin;
51 my $plugins = Koha::Plugins->new;
52 $plugins->InstallPlugins;
53 my $plugin = Koha::Plugin::Test->new->enable;
56 warning_like { ( $id ) = C4::AuthoritiesMarc::AddAuthority( MARC::Record->new, undef, 'PERSO_NAME' ); }
57 qr/after_authority_action called with action: create, id: \d+/,
58 'AddAuthority calls the hook with action=create, id passed';
60 warning_like { C4::AuthoritiesMarc::ModAuthority( $id, MARC::Record->new, 'PERSO_NAME', { skip_merge => 1 } ); }
61 qr/after_authority_action called with action: modify, id: $id/,
62 'ModAuthority calls the hook with action=modify, id passed';
64 warning_like { C4::AuthoritiesMarc::DelAuthority({ authid => $id, skip_merge => 1 }); }
65 qr/after_authority_action called with action: delete, id: $id/,
66 'DelAuthority calls the hook with action=delete, id passed';
68 $schema->storage->txn_rollback;
69 Koha::Plugins::Methods->delete;