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

(-)a/Koha/Recalls.pm (+9 lines)
Lines 22-27 use Modern::Perl; Link Here
22
use Koha::Database;
22
use Koha::Database;
23
use Koha::Recall;
23
use Koha::Recall;
24
use Koha::DateUtils qw( dt_from_string );
24
use Koha::DateUtils qw( dt_from_string );
25
use Koha::Plugins;
25
26
26
use C4::Stats qw( UpdateStats );
27
use C4::Stats qw( UpdateStats );
27
28
Lines 173-178 sub add_recall { Link Here
173
            ccode => $item->ccode,
174
            ccode => $item->ccode,
174
        });
175
        });
175
176
177
        Koha::Plugins->call(
178
            'after_recall_action',
179
            {
180
                action  => 'add',
181
                payload => { recall => $recall }
182
            }
183
        );
184
176
        # add action log
185
        # add action log
177
        C4::Log::logaction( 'RECALLS', 'CREATE', $recall->id, "Recall requested by borrower #" . $recall->patron_id, $interface ) if ( C4::Context->preference('RecallsLog') );
186
        C4::Log::logaction( 'RECALLS', 'CREATE', $recall->id, "Recall requested by borrower #" . $recall->patron_id, $interface ) if ( C4::Context->preference('RecallsLog') );
178
187
(-)a/t/db_dependent/Koha/Plugins/Recall_hooks.t (+98 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::MockModule;
21
use Test::Warn;
22
23
use File::Basename;
24
25
use Koha::Account qw( add_credit );
26
27
use t::lib::Mocks;
28
use t::lib::TestBuilder;
29
30
BEGIN {
31
    # Mock pluginsdir before loading Plugins module
32
    my $path = dirname(__FILE__) . '/../../../lib/plugins';
33
    t::lib::Mocks::mock_config( 'pluginsdir', $path );
34
35
    use_ok('Koha::Plugins');
36
    use_ok('Koha::Plugins::Handler');
37
    use_ok('Koha::Plugin::Test');
38
}
39
40
my $schema  = Koha::Database->new->schema;
41
my $builder = t::lib::TestBuilder->new;
42
43
t::lib::Mocks::mock_config( 'enable_plugins', 1 );
44
45
subtest 'after_recall_action hook' => sub {
46
47
    plan tests => 1;
48
49
    $schema->storage->txn_begin;
50
51
    my $plugins = Koha::Plugins->new;
52
    $plugins->InstallPlugins;
53
54
    my $plugin = Koha::Plugin::Test->new->enable;
55
    # Avoid testing useless warnings
56
    my $test_plugin = Test::MockModule->new('Koha::Plugin::Test');
57
    $test_plugin->mock( 'after_item_action',   undef );
58
    $test_plugin->mock( 'after_circ_action', undef );
59
    $test_plugin->mock( 'after_biblio_action', undef );
60
    $test_plugin->mock( 'patron_barcode_transform', undef );
61
    $test_plugin->mock( 'item_barcode_transform', undef );
62
    
63
    my $item = $builder->build_sample_item();
64
    my $biblio = $item->biblio;
65
    my $branch = $item->holdingbranch;
66
    my $category = $builder->build({ source => 'Category' })->{ categorycode };
67
    my $patron1 = $builder->build_object({ class => 'Koha::Patrons', value => { categorycode => $category, branchcode => $branch } });
68
    my $patron2 = $builder->build_object({ class => 'Koha::Patrons', value => { categorycode => $category, branchcode => $branch } });
69
    t::lib::Mocks::mock_userenv({ patron => $patron1 });
70
71
    Koha::CirculationRules->set_rules({
72
        branchcode => undef,
73
        categorycode => undef,
74
        itemtype => undef,
75
        rules => {
76
            'recall_due_date_interval' => undef,
77
            'recalls_allowed' => 10,
78
        }
79
    });
80
81
    C4::Circulation::AddIssue( $patron2->unblessed, $item->barcode );
82
83
    warning_like {
84
      Koha::Recalls->add_recall({
85
          patron => $patron1,
86
          biblio => $biblio,
87
          branchcode => $branch,
88
          item => undef,
89
          expirationdate => undef,
90
          interface => 'COMMANDLINE',
91
      });
92
    }
93
    qr/after_recall_action called with action: add, ref: Koha::Recall/,
94
      '->add_recall calls the after_recall_action hook with action add';
95
96
    $schema->storage->txn_rollback;
97
    Koha::Plugins::Methods->delete;
98
};
(-)a/t/lib/plugins/Koha/Plugin/Test.pm (-1 / +10 lines)
Lines 348-353 sub background_tasks { Link Here
348
    };
348
    };
349
}
349
}
350
350
351
sub after_recall_action {
352
    my ( $self, $params ) = @_;
353
354
    my $action = $params->{action};
355
    my $recall   = $params->{payload}->{recall};
356
357
    Koha::Exception->throw(
358
        "after_recall_action called with action: $action, ref: " . ref($recall) );
359
}
360
351
sub _private_sub {
361
sub _private_sub {
352
    return "";
362
    return "";
353
}
363
}
354
- 

Return to bug 31896