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 my $record = MARC::Record->new;
57 $record->append_fields( MARC::Field->new( '100', '1', '2', a => 'Name' ) );
58 my $type = $builder->build( { source => 'AuthType', value => { auth_tag_to_report => '100' } } );
60 warnings_exist { ( $id ) = C4::AuthoritiesMarc::AddAuthority( $record, undef, $type->{authtypecode} ); }
61 qr/after_authority_action called with action: create, id: \d+/,
62 'AddAuthority calls the hook with action=create, id passed';
64 warnings_exist { C4::AuthoritiesMarc::ModAuthority( $id, $record, $type->{authtypecode}, { skip_merge => 1 } ); }
65 qr/after_authority_action called with action: modify, id: $id/,
66 'ModAuthority calls the hook with action=modify, id passed';
68 warnings_exist { C4::AuthoritiesMarc::DelAuthority({ authid => $id, skip_merge => 1 }); }
69 qr/after_authority_action called with action: delete, id: $id/,
70 'DelAuthority calls the hook with action=delete, id passed';
72 Koha::Plugins->RemovePlugins;
73 $schema->storage->txn_rollback;