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

(-)a/t/db_dependent/Koha/Plugins/Circulation_hooks.t (+85 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 Test::More tests => 4;
20
use Test::Warn;
21
22
use File::Basename;
23
24
use C4::Circulation qw(AddIssue AddRenewal);
25
26
use t::lib::Mocks;
27
use t::lib::TestBuilder;
28
29
BEGIN {
30
    # Mock pluginsdir before loading Plugins module
31
    my $path = dirname(__FILE__) . '/../../../lib';
32
    t::lib::Mocks::mock_config( 'pluginsdir', $path );
33
34
    use_ok('Koha::Plugins');
35
    use_ok('Koha::Plugins::Handler');
36
    use_ok('Koha::Plugin::Test');
37
}
38
39
my $schema  = Koha::Database->new->schema;
40
my $builder = t::lib::TestBuilder->new;
41
42
t::lib::Mocks::mock_config( 'enable_plugins', 1 );
43
44
subtest 'post_renewal_action() hook tests' => sub {
45
46
    plan tests => 4;
47
48
    $schema->storage->txn_begin;
49
50
    my $plugins = Koha::Plugins->new;
51
    $plugins->InstallPlugins;
52
53
    my $plugin = Koha::Plugin::Test->new->enable;
54
55
    my $patron = $builder->build_object({ class => 'Koha::Patrons' });
56
57
    t::lib::Mocks::mock_userenv(
58
        {
59
            patron     => $patron,
60
            branchcode => $patron->branchcode
61
        }
62
    );
63
64
    my ($biblio, $item);
65
66
    warning_like { $biblio = $builder->build_sample_biblio(); }
67
            qr/after_biblio_action called with action: create, ref: Koha::Biblio/,
68
            'AddBiblio calls the hook with action=create';
69
70
    warning_like { $item = $builder->build_sample_item({ biblionumber => $biblio->biblionumber }); }
71
            qr/after_item_action called with action: create, ref: Koha::Item/,
72
            'AddItem calls the hook with action=create';
73
74
    warning_like { AddIssue( $patron->unblessed, $item->barcode ); }
75
            qr/after_item_action called with action: modify, ref: Koha::Item/,
76
            'AddItem calls the hook with action=modify';
77
78
    warnings_like { AddRenewal( $patron->borrowernumber, $item->id, $patron->branchcode ); }
79
            [ qr/after_item_action called with action: modify, ref: Koha::Item/,
80
              qr/post_renewal_action .* DateTime/ ],
81
            'AddRenewal calls the post_renewal_action hook';
82
83
    $schema->storage->txn_rollback;
84
    Koha::Plugins::Methods->delete;
85
};
(-)a/t/lib/Koha/Plugin/Test.pm (-1 / +25 lines)
Lines 155-160 sub after_item_action { Link Here
155
    }
155
    }
156
}
156
}
157
157
158
sub post_renewal_action {
159
    my ( $self, $params ) = @_;
160
161
    my $renewal_library_id = $params->{renewal_library_id};
162
    my $charge             = $params->{charge};
163
    my $item_id            = $params->{item_id};
164
    my $item_type          = $params->{item_type};
165
    my $shelving_location  = $params->{shelving_location};
166
    my $patron_id          = $params->{patron_id};
167
    my $collection_code    = $params->{collection_code};
168
    my $date_due           = $params->{date_due};
169
170
    Koha::Exceptions::Exception->throw(
171
        "post_renewal_action " .
172
        "$renewal_library_id " .
173
        "$charge " .
174
        "$item_id " .
175
        "$item_type " .
176
        "$shelving_location " .
177
        "$patron_id " .
178
        "$collection_code " .
179
        ref($date_due)
180
    );
181
}
182
158
sub api_routes {
183
sub api_routes {
159
    my ( $self, $args ) = @_;
184
    my ( $self, $args ) = @_;
160
185
161
- 

Return to bug 25855