Bug 28211: (QA follow-up) Add unit tests

JD amended patch: typo multipled ==> multiplied

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Kyle M Hall 2021-10-14 11:57:55 +00:00 committed by Jonathan Druart
parent f7acb5eaad
commit 71914b14d1
3 changed files with 52 additions and 3 deletions

View File

@ -25,7 +25,7 @@ use File::Temp qw( tempdir tempfile );
use FindBin qw($Bin);
use Module::Load::Conditional qw(can_load);
use Test::MockModule;
use Test::More tests => 60;
use Test::More tests => 61;
use Test::Warn;
use C4::Context;
@ -43,6 +43,7 @@ BEGIN {
use_ok('Koha::Plugins::Handler');
use_ok('Koha::Plugins::Base');
use_ok('Koha::Plugin::Test');
use_ok('Koha::Plugin::TestItemBarcodeTransform');
}
my $schema = Koha::Database->new->schema;
@ -100,9 +101,11 @@ subtest 'more call() tests' => sub {
$plugin->enable();
}
# Barcode is multiplied by 2 by Koha::Plugin::Test, and again by 4 by Koha::Plugin::TestItemBarcodeTransform
# showing that call has passed the same ref to multiple plugins to operate on
my $bc = 1;
Koha::Plugins->call('item_barcode_transform', \$bc);
is( $bc, 4, "Got expected response" );
is( $bc, 8, "Got expected response" );
my $cn = 'abcd';
Koha::Plugins->call('item_barcode_transform', \$cn);

View File

@ -96,7 +96,9 @@ sub intranet_js {
sub item_barcode_transform {
my ( $self, $barcode ) = @_;
my $param = $$barcode;
$$barcode = 4 if "$$barcode" eq 1;
if ( Scalar::Util::looks_like_number( $$barcode ) ) {
$$barcode = $$barcode * 2
}
Koha::Exceptions::Exception->throw("item_barcode_transform called with parameter: $param");
}

View File

@ -0,0 +1,44 @@
package Koha::Plugin::TestItemBarcodeTransform;
## It's good practice to use Modern::Perl
use Modern::Perl;
use Koha::Exceptions::Exception;
use Koha::Plugins::Tab;
use Mojo::JSON qw( decode_json );
## Required for all plugins
use base qw(Koha::Plugins::Base);
our $VERSION = 1.01;
our $metadata = {
name => 'Test Plugin for item_barcode_transform',
author => 'Kyle M Hall',
description => 'Test plugin',
date_authored => '2021-10-14',
date_updated => '2021-10-14',
minimum_version => '21.11',
maximum_version => undef,
version => $VERSION,
};
## This is the minimum code required for a plugin's 'new' method
## More can be added, but none should be removed
sub new {
my ( $class, $args ) = @_;
$args->{'metadata'} = $metadata;
my $self = $class->SUPER::new($args);
return $self;
}
sub item_barcode_transform {
my ( $self, $barcode ) = @_;
my $param = $$barcode;
if ( Scalar::Util::looks_like_number( $$barcode ) ) {
$$barcode = $$barcode * 4
}
Koha::Exceptions::Exception->throw("item_barcode_transform called with parameter: $param");
}
1;