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

(-)a/t/db_dependent/Koha/Plugins/Barcode_transform_hooks.t (+78 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 t::lib::Mocks;
26
use t::lib::TestBuilder;
27
28
BEGIN {
29
    # Mock pluginsdir before loading Plugins module
30
    my $path = dirname(__FILE__) . '/../../../lib';
31
    t::lib::Mocks::mock_config( 'pluginsdir', $path );
32
33
    use_ok('Koha::Plugins');
34
    use_ok('Koha::Plugins::Handler');
35
    use_ok('Koha::Plugin::Test');
36
}
37
38
my $schema  = Koha::Database->new->schema;
39
my $builder = t::lib::TestBuilder->new;
40
41
t::lib::Mocks::mock_config( 'enable_plugins', 1 );
42
43
subtest '() hook tests' => sub {
44
45
    plan tests => 1;
46
47
    $schema->storage->txn_begin;
48
49
    my $plugins = Koha::Plugins->new;
50
    $plugins->InstallPlugins;
51
52
    my $plugin = Koha::Plugin::Test->new->enable;
53
54
    my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
55
56
    t::lib::Mocks::mock_userenv(
57
        {
58
            patron     => $patron,
59
            branchcode => $patron->branchcode
60
        }
61
    );
62
63
    # Avoid testing useless warnings
64
    my $test_plugin = Test::MockModule->new('Koha::Plugin::Test');
65
    $test_plugin->mock( 'after_item_action',   undef );
66
    $test_plugin->mock( 'after_biblio_action', undef );
67
68
    my $biblio = $builder->build_sample_biblio();
69
    my $item_1 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber } );
70
    $item_1->barcode('THISISATEST');
71
72
    warning_like { $item_1->store(); }
73
        qr/barcode_transform called with parameters: item, THISISATEST/,
74
        'AddReserve calls the after_hold_create hook';
75
76
    $schema->storage->txn_rollback;
77
    Koha::Plugins::Methods->delete;
78
};
(-)a/t/db_dependent/Koha/Plugins/Biblio_and_Items_plugin_hooks.t (+3 lines)
Lines 52-57 subtest 'after_biblio_action() and after_item_action() hooks tests' => sub { Link Here
52
52
53
    my $plugin = Koha::Plugin::Test->new->enable;
53
    my $plugin = Koha::Plugin::Test->new->enable;
54
54
55
    my $test_plugin = Test::MockModule->new('Koha::Plugin::Test');
56
    $test_plugin->mock( 'barcode_transform', undef );
57
55
    my $biblio_id;
58
    my $biblio_id;
56
59
57
    warning_like { ( $biblio_id, undef ) = C4::Biblio::AddBiblio( MARC::Record->new(), '' ); }
60
    warning_like { ( $biblio_id, undef ) = C4::Biblio::AddBiblio( MARC::Record->new(), '' ); }
(-)a/t/db_dependent/Koha/Plugins/Circulation_hooks.t (+1 lines)
Lines 66-71 subtest 'after_circ_action() hook tests' => sub { Link Here
66
    my $test_plugin = Test::MockModule->new('Koha::Plugin::Test');
66
    my $test_plugin = Test::MockModule->new('Koha::Plugin::Test');
67
    $test_plugin->mock( 'after_item_action',   undef );
67
    $test_plugin->mock( 'after_item_action',   undef );
68
    $test_plugin->mock( 'after_biblio_action', undef );
68
    $test_plugin->mock( 'after_biblio_action', undef );
69
    $test_plugin->mock( 'barcode_transform', undef );
69
70
70
    my $biblio = $builder->build_sample_biblio();
71
    my $biblio = $builder->build_sample_biblio();
71
    my $item_1 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber } );
72
    my $item_1 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber } );
(-)a/t/lib/Koha/Plugin/Test.pm (-2 / +1 lines)
Lines 95-101 sub intranet_js { Link Here
95
95
96
sub barcode_transform {
96
sub barcode_transform {
97
    my ( $self, $type, $barcode ) = @_;
97
    my ( $self, $type, $barcode ) = @_;
98
    return "Koha::Plugin::Test::barcode_transform";
98
    Koha::Exceptions::Exception->throw("barcode_transform called with parameters: $type, $barcode");
99
}
99
}
100
100
101
sub barcode_generate {
101
sub barcode_generate {
102
- 

Return to bug 26351