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

(-)a/t/db_dependent/Koha/Plugins/Plugins.t (-2 / +5 lines)
Lines 25-31 use File::Temp qw( tempdir tempfile ); Link Here
25
use FindBin qw($Bin);
25
use FindBin qw($Bin);
26
use Module::Load::Conditional qw(can_load);
26
use Module::Load::Conditional qw(can_load);
27
use Test::MockModule;
27
use Test::MockModule;
28
use Test::More tests => 60;
28
use Test::More tests => 61;
29
use Test::Warn;
29
use Test::Warn;
30
30
31
use C4::Context;
31
use C4::Context;
Lines 43-48 BEGIN { Link Here
43
    use_ok('Koha::Plugins::Handler');
43
    use_ok('Koha::Plugins::Handler');
44
    use_ok('Koha::Plugins::Base');
44
    use_ok('Koha::Plugins::Base');
45
    use_ok('Koha::Plugin::Test');
45
    use_ok('Koha::Plugin::Test');
46
    use_ok('Koha::Plugin::TestItemBarcodeTransform');
46
}
47
}
47
48
48
my $schema = Koha::Database->new->schema;
49
my $schema = Koha::Database->new->schema;
Lines 100-108 subtest 'more call() tests' => sub { Link Here
100
        $plugin->enable();
101
        $plugin->enable();
101
    }
102
    }
102
103
104
    # Barcode is multipled by 2 by Koha::Plugin::Test, and again by 4 by Koha::Plugin::TestItemBarcodeTransform
105
    # showing that call has passed the same ref to multiple plugins to operate on
103
    my $bc = 1;
106
    my $bc = 1;
104
    Koha::Plugins->call('item_barcode_transform', \$bc);
107
    Koha::Plugins->call('item_barcode_transform', \$bc);
105
    is( $bc, 4, "Got expected response" );
108
    is( $bc, 8, "Got expected response" );
106
109
107
    my $cn = 'abcd';
110
    my $cn = 'abcd';
108
    Koha::Plugins->call('item_barcode_transform', \$cn);
111
    Koha::Plugins->call('item_barcode_transform', \$cn);
(-)a/t/lib/Koha/Plugin/Test.pm (-1 / +3 lines)
Lines 96-102 sub intranet_js { Link Here
96
sub item_barcode_transform {
96
sub item_barcode_transform {
97
    my ( $self, $barcode ) = @_;
97
    my ( $self, $barcode ) = @_;
98
    my $param = $$barcode;
98
    my $param = $$barcode;
99
    $$barcode = 4 if "$$barcode" eq 1;
99
    if ( Scalar::Util::looks_like_number( $$barcode ) ) {
100
        $$barcode = $$barcode * 2
101
    }
100
    Koha::Exceptions::Exception->throw("item_barcode_transform called with parameter: $param");
102
    Koha::Exceptions::Exception->throw("item_barcode_transform called with parameter: $param");
101
}
103
}
102
104
(-)a/t/lib/Koha/Plugin/TestItemBarcodeTransform.pm (-1 / +44 lines)
Line 0 Link Here
0
- 
1
package Koha::Plugin::TestItemBarcodeTransform;
2
3
## It's good practice to use Modern::Perl
4
use Modern::Perl;
5
6
use Koha::Exceptions::Exception;
7
use Koha::Plugins::Tab;
8
9
use Mojo::JSON qw( decode_json );
10
11
## Required for all plugins
12
use base qw(Koha::Plugins::Base);
13
14
our $VERSION = 1.01;
15
our $metadata = {
16
    name            => 'Test Plugin for item_barcode_transform',
17
    author          => 'Kyle M Hall',
18
    description     => 'Test plugin',
19
    date_authored   => '2021-10-14',
20
    date_updated    => '2021-10-14',
21
    minimum_version => '21.11',
22
    maximum_version => undef,
23
    version         => $VERSION,
24
};
25
26
## This is the minimum code required for a plugin's 'new' method
27
## More can be added, but none should be removed
28
sub new {
29
    my ( $class, $args ) = @_;
30
    $args->{'metadata'} = $metadata;
31
    my $self = $class->SUPER::new($args);
32
    return $self;
33
}
34
35
sub item_barcode_transform {
36
    my ( $self, $barcode ) = @_;
37
    my $param = $$barcode;
38
    if ( Scalar::Util::looks_like_number( $$barcode ) ) {
39
        $$barcode = $$barcode * 4
40
    }
41
    Koha::Exceptions::Exception->throw("item_barcode_transform called with parameter: $param");
42
}
43
44
1;

Return to bug 28211