From fc363dbc24ac4e46ec845c1a65ffbb2bd5715f36 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) Fix rebase issues - Rebased tests patch (62->51) - tidy - spelling ( paramater -> parameter ) Signed-off-by: Pedro Amorim Signed-off-by: Tomas Cohen Arazi --- 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 6669da3702f..f7efc14d386 100644 --- a/Koha/Plugins.pm +++ b/Koha/Plugins.pm @@ -277,19 +277,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"; @@ -306,9 +308,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 02c96474cfe..99ecdec65f9 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 7fdebf55a1e..1db51568c40 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.45.0