From 1abaac20a05e06e1a753ddada3a968c088f5c7a7 Mon Sep 17 00:00:00 2001 From: Pedro Amorim Date: Fri, 22 Dec 2023 13:29:27 +0000 Subject: [PATCH] Bug 34978: (QA follow-up): - Rebased tests patch (62->51) - tidy - spelling ( paramater -> parameter ) Signed-off-by: Pedro Amorim --- Koha/Plugins.pm | 18 ++++++++----- misc/devel/install_plugins.pl | 4 +-- t/db_dependent/Koha/Plugins/Plugins.t | 38 +++++++++++++-------------- 3 files changed, 33 insertions(+), 27 deletions(-) diff --git a/Koha/Plugins.pm b/Koha/Plugins.pm index 48bda9394b..5547e33f2f 100644 --- a/Koha/Plugins.pm +++ b/Koha/Plugins.pm @@ -276,19 +276,21 @@ sub InstallPlugins { my $verbose = $params->{verbose} // $self->_verbose; my @plugin_classes = $self->plugins(); - my (@plugins, @classes_filters); + my ( @plugins, @classes_filters ); - my $has_filters = defined($params->{include}) || defined($params->{exclude}); + my $has_filters = defined( $params->{include} ) || defined( $params->{exclude} ); # Warn user if the specified classes doesn't exist and return nothing if ($has_filters) { - @classes_filters = defined($params->{include}) ? @{$params->{include}} : @{$params->{exclude}}; + @classes_filters = defined( $params->{include} ) ? @{ $params->{include} } : @{ $params->{exclude} }; foreach my $classes_filter (@classes_filters) { my $is_found = 0; foreach my $plugin_class (@plugin_classes) { - $is_found = 1 if $plugin_class =~ ":$classes_filter\$|^$classes_filter\$" || ($classes_filter =~ "^::" && $plugin_class =~ "$classes_filter\$"); + $is_found = 1 + if $plugin_class =~ ":$classes_filter\$|^$classes_filter\$" + || ( $classes_filter =~ "^::" && $plugin_class =~ "$classes_filter\$" ); } unless ($is_found) { warn "$classes_filter have not been found, try a different name"; @@ -305,9 +307,13 @@ sub InstallPlugins { if ($has_filters) { my $is_found = 0; foreach my $classes_filter (@classes_filters) { - $is_found = 1 if $plugin_class =~ ":$classes_filter\$|^$classes_filter\$" || ($classes_filter =~ "^::" && $plugin_class =~ "$classes_filter\$"); + $is_found = 1 + if $plugin_class =~ ":$classes_filter\$|^$classes_filter\$" + || ( $classes_filter =~ "^::" && $plugin_class =~ "$classes_filter\$" ); } - next if (defined($params->{include}) && !$is_found) || (defined($params->{exclude}) && $is_found); + next + if ( defined( $params->{include} ) && !$is_found ) + || ( defined( $params->{exclude} ) && $is_found ); } my $plugin; diff --git a/misc/devel/install_plugins.pl b/misc/devel/install_plugins.pl index e51f8b1b50..0a38d82d85 100755 --- a/misc/devel/install_plugins.pl +++ b/misc/devel/install_plugins.pl @@ -26,10 +26,10 @@ use Koha::Script; use C4::Context; use Koha::Plugins; -my ($help, @include, @exclude); +my ( $help, @include, @exclude ); GetOptions( - 'help|?' => \$help, + 'help|?' => \$help, 'include=s' => \@include, 'exclude=s' => \@exclude, ) or die "Installation aborted\n"; diff --git a/t/db_dependent/Koha/Plugins/Plugins.t b/t/db_dependent/Koha/Plugins/Plugins.t index 2fd1d28fca..03681f02cd 100755 --- a/t/db_dependent/Koha/Plugins/Plugins.t +++ b/t/db_dependent/Koha/Plugins/Plugins.t @@ -24,7 +24,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 => 30; +use Test::More tests => 19; use Test::Warn; use C4::Context; @@ -195,23 +195,23 @@ subtest 'InstallPlugins() tests' => sub { Koha::Plugins::Methods->delete; $schema->resultset('PluginData')->delete; - # Tests for the exclude paramater + # Tests for the exclude parameter # Test the returned plugins of the InstallPlugins subroutine - my $plugins = Koha::Plugins->new({ enable_plugins => 1 }); - my @installed_plugins = $plugins->InstallPlugins({ exclude => ["Test", "Koha::Plugin::MarcFieldValues"] }); - my $plugin_classes = join(" ", map{$_->{class}} @installed_plugins); + my $plugins = Koha::Plugins->new( { enable_plugins => 1 } ); + my @installed_plugins = $plugins->InstallPlugins( { exclude => [ "Test", "Koha::Plugin::MarcFieldValues" ] } ); + my $plugin_classes = join( " ", map { $_->{class} } @installed_plugins ); - my $result = grep { $plugin_classes !~ $_ } [":Test |:Test\$", ":MarcFieldValues |:MarcFieldValues\$"] + my $result = grep { $plugin_classes !~ $_ } [ ":Test |:Test\$", ":MarcFieldValues |:MarcFieldValues\$" ] && $plugin_classes =~ ":TestItemBarcodeTransform |:TestItemBarcodeTransform\$"; - ok($result, "Excluded plugins are not returned"); + ok( $result, "Excluded plugins are not returned" ); # Test the plugins in the database - my @plugins = $plugins->GetPlugins({ all => 1, error => 1 }); - $plugin_classes = join(" ", map{$_->{class}} @plugins); + my @plugins = $plugins->GetPlugins( { all => 1, error => 1 } ); + $plugin_classes = join( " ", map { $_->{class} } @plugins ); - $result = grep { $plugin_classes !~ $_ } [":Test |:Test\$", ":MarcFieldValues |:MarcFieldValues\$"] + $result = grep { $plugin_classes !~ $_ } [ ":Test |:Test\$", ":MarcFieldValues |:MarcFieldValues\$" ] && $plugin_classes =~ ":TestItemBarcodeTransform |:TestItemBarcodeTransform\$"; - ok($result, "Excluded plugins are not installed"); + ok( $result, "Excluded plugins are not installed" ); # Remove installed plugins data Koha::Plugins::Methods->delete; @@ -219,22 +219,22 @@ subtest 'InstallPlugins() tests' => sub { # Tests for the include parameter # Test the returned plugins of the InstallPlugins subroutine - @installed_plugins = $plugins->InstallPlugins({ include => ["Test", "Koha::Plugin::MarcFieldValues"]}); + @installed_plugins = $plugins->InstallPlugins( { include => [ "Test", "Koha::Plugin::MarcFieldValues" ] } ); $result = 1; - foreach my $plugin_class ( map{ $_->{class} } @installed_plugins ) { - $result = 0 unless("$plugin_class" =~ ":Test\$" || "$plugin_class" =~ ":MarcFieldValues\$"); + foreach my $plugin_class ( map { $_->{class} } @installed_plugins ) { + $result = 0 unless ( "$plugin_class" =~ ":Test\$" || "$plugin_class" =~ ":MarcFieldValues\$" ); } - ok($result, "Only included plugins are returned"); + ok( $result, "Only included plugins are returned" ); # Test the plugins in the database - @plugins = $plugins->GetPlugins({ all => 1, error => 1}); + @plugins = $plugins->GetPlugins( { all => 1, error => 1 } ); $result = 1; - foreach my $plugin_class ( map{ $_->{class} } @plugins ) { - $result = 0 unless("$plugin_class" =~ ":Test\$" || "$plugin_class" =~ ":MarcFieldValues\$"); + foreach my $plugin_class ( map { $_->{class} } @plugins ) { + $result = 0 unless ( "$plugin_class" =~ ":Test\$" || "$plugin_class" =~ ":MarcFieldValues\$" ); } - ok($result, "Only included plugins are installed"); + ok( $result, "Only included plugins are installed" ); $schema->storage->txn_rollback; }; -- 2.34.1