From 0a262a214f2c2ff6e836d7283cae413ee354cdce Mon Sep 17 00:00:00 2001 From: Alex Arnaud Date: Fri, 28 Dec 2018 17:48:43 +0100 Subject: [PATCH] Bug 22053: create unit tests Rebased-on: 2019-03-25 Alex Arnaud Signed-off-by: Claire Gravely Signed-off-by: Agustin Moyano Signed-off-by: Tomas Cohen Arazi Signed-off-by: Nick Clemens --- t/db_dependent/Plugins.t | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Plugins.t b/t/db_dependent/Plugins.t index 7bbd8d9d78..f34500e146 100755 --- a/t/db_dependent/Plugins.t +++ b/t/db_dependent/Plugins.t @@ -9,7 +9,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 => 42; +use Test::More tests => 44; use C4::Context; use Koha::Database; @@ -77,15 +77,19 @@ close $fh; my $classname = ref($plugin); like( $plugin->test_template($fn), qr/^I am $fn/, 'Template works' ); +$plugin->enable; + # testing GetPlugins my @plugins = Koha::Plugins->new({ enable_plugins => 1 })->GetPlugins({ method => 'report' }); + my @names = map { $_->get_metadata()->{'name'} } @plugins; is( scalar grep( /^Test Plugin$/, @names), 1, "Koha::Plugins::GetPlugins functions correctly" ); @plugins = Koha::Plugins->new({ enable_plugins => 1 })->GetPlugins({ metadata => { my_example_tag => 'find_me' }, }); + @names = map { $_->get_metadata()->{'name'} } @plugins; is( scalar grep( /^Test Plugin$/, @names), 1, "GetPlugins also found Test Plugin via a metadata tag" ); # Test two metadata conditions; one does not exist for Test.pm @@ -95,6 +99,16 @@ my @plugins2 = Koha::Plugins->new({ enable_plugins => 1 })->GetPlugins({ }); isnt( scalar @plugins2, scalar @plugins, 'GetPlugins with two metadata conditions' ); +$plugin->disable; + +@plugins = Koha::Plugins->new({ enable_plugins => 1 })->GetPlugins(); +@names = map { $_->get_metadata()->{'name'} } @plugins; +is( scalar grep( /^Test Plugin$/, @names), 0, "GetPlugins does not found disabled Test Plugin" ); + +@plugins = Koha::Plugins->new({ enable_plugins => 1 })->GetPlugins({ all => 1 }); +@names = map { $_->get_metadata()->{'name'} } @plugins; +is( scalar grep( /^Test Plugin$/, @names), 1, "With all param, GetPlugins found disabled Test Plugin" ); + for my $pass ( 1 .. 2 ) { my $plugins_dir; my $module_name = 'Koha::Plugin::Com::ByWaterSolutions::KitchenSink'; -- 2.39.5