From d734dd30e8855d892ffad0d90f3e0b648a7388ed Mon Sep 17 00:00:00 2001 From: Hammat Wele Date: Tue, 14 May 2024 20:03:16 +0000 Subject: [PATCH] Bug 34978: (follow-up) Add exception when plugin to install is not found and fix unit test Signed-off-by: Hammat Wele Signed-off-by: Amaury GAU --- Koha/Plugins.pm | 3 +-- t/db_dependent/Koha/Plugins/Plugins.t | 20 +++++++++++++++++--- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/Koha/Plugins.pm b/Koha/Plugins.pm index ec5da1d13b..cc3be556b1 100644 --- a/Koha/Plugins.pm +++ b/Koha/Plugins.pm @@ -318,8 +318,7 @@ sub InstallPlugins { # Warn user if the specified classes doesn't exist and return nothing foreach my $class_name (@classes_filters) { unless ( any { $class_name eq $_ } @plugin_classes ) { - warn "$class_name has not been found, try a different name"; - return; + Koha::Exceptions::BadParameter->throw("$class_name has not been found, try a different name"); } } diff --git a/t/db_dependent/Koha/Plugins/Plugins.t b/t/db_dependent/Koha/Plugins/Plugins.t index 2f2dda2190..90b1f482bd 100755 --- a/t/db_dependent/Koha/Plugins/Plugins.t +++ b/t/db_dependent/Koha/Plugins/Plugins.t @@ -27,6 +27,7 @@ use Test::MockModule; use Test::NoWarnings; use Test::More tests => 20; use Test::Warn; +use Test::Exception; use C4::Context; use Koha::Cache::Memory::Lite; @@ -193,7 +194,7 @@ subtest 'GetPlugins() tests' => sub { subtest 'InstallPlugins() tests' => sub { - plan tests => 4; + plan tests => 6; $schema->storage->txn_begin; @@ -204,7 +205,7 @@ subtest 'InstallPlugins() tests' => sub { # 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 @installed_plugins = $plugins->InstallPlugins( { exclude => [ "Koha::Plugin::Test", "Koha::Plugin::MarcFieldValues" ] } ); my $plugin_classes = join( " ", map { $_->{class} } @installed_plugins ); my $result = grep { $plugin_classes !~ $_ } [ ":Test |:Test\$", ":MarcFieldValues |:MarcFieldValues\$" ] @@ -225,7 +226,7 @@ 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 => [ "Koha::Plugin::Test", "Koha::Plugin::MarcFieldValues" ] } ); $result = 1; foreach my $plugin_class ( map { $_->{class} } @installed_plugins ) { @@ -242,6 +243,19 @@ subtest 'InstallPlugins() tests' => sub { } ok( $result, "Only included plugins are installed" ); + # Tests when both include and exclude parameter are used simultaneously + throws_ok + { + $plugins->InstallPlugins( { exclude => [ "Koha::Plugin::Test" ], include => [ "Koha::Plugin::Test" ] } ); + } + 'Koha::Exceptions::BadParameter'; + # Tests when the plugin to be installled is not found + throws_ok + { + $plugins->InstallPlugins( { include => [ "Koha::Plugin::NotfoundPlugin" ] } ); + } + 'Koha::Exceptions::BadParameter'; + $schema->storage->txn_rollback; }; -- 2.39.5