View | Details | Raw Unified | Return to bug 27173
Collapse All | Expand All

(-)a/t/db_dependent/Koha/Plugins/authority_hooks.t (+70 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
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
8
# version.
9
#
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.
13
#
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>.
16
17
use Modern::Perl;
18
19
use MARC::Record;
20
use Test::More tests => 4;
21
use Test::Warn;
22
23
use File::Basename;
24
25
use C4::AuthoritiesMarc ();
26
use Koha::Database;
27
28
use t::lib::Mocks;
29
use t::lib::TestBuilder;
30
31
BEGIN {
32
    # Mock pluginsdir before loading Plugins module
33
    my $path = dirname(__FILE__) . '/../../../lib';
34
    t::lib::Mocks::mock_config( 'pluginsdir', $path );
35
36
    use_ok('Koha::Plugins');
37
    use_ok('Koha::Plugins::Handler');
38
    use_ok('Koha::Plugin::Test');
39
}
40
41
my $schema  = Koha::Database->new->schema;
42
my $builder = t::lib::TestBuilder->new;
43
44
t::lib::Mocks::mock_config( 'enable_plugins', 1 );
45
46
subtest 'after_authority_action hook' => sub {
47
    plan tests => 3;
48
49
    $schema->storage->txn_begin;
50
51
    my $plugins = Koha::Plugins->new;
52
    $plugins->InstallPlugins;
53
    my $plugin = Koha::Plugin::Test->new->enable;
54
    my $id;
55
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';
59
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';
63
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';
67
68
    $schema->storage->txn_rollback;
69
    Koha::Plugins::Methods->delete;
70
};
(-)a/t/lib/Koha/Plugin/Test.pm (-1 / +7 lines)
Lines 164-169 sub after_item_action { Link Here
164
    }
164
    }
165
}
165
}
166
166
167
sub after_authority_action {
168
    my ( $self, $params ) = @_;
169
    my $action = $params->{action} // q{};
170
    my $id = $params->{authority_id} // 0;
171
    Koha::Exceptions::Exception->throw("after_authority_action called with action: $action, id: $id");
172
}
173
167
sub after_circ_action {
174
sub after_circ_action {
168
    my ( $self, $params ) = @_;
175
    my ( $self, $params ) = @_;
169
176
170
- 

Return to bug 27173