From 3754a19cdf3bdb0c3ffbfcb5261a61b6ed0bd732 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 --- 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 636a4d5692..335ae50d7f 100644 --- a/Koha/Plugins.pm +++ b/Koha/Plugins.pm @@ -311,8 +311,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 1db51568c4..f56d8ddce0 100755 --- a/t/db_dependent/Koha/Plugins/Plugins.t +++ b/t/db_dependent/Koha/Plugins/Plugins.t @@ -26,6 +26,7 @@ use Module::Load::Conditional qw(can_load); use Test::MockModule; use Test::More tests => 19; use Test::Warn; +use Test::Exception; use C4::Context; use Koha::Cache::Memory::Lite; @@ -187,7 +188,7 @@ subtest 'GetPlugins() tests' => sub { subtest 'InstallPlugins() tests' => sub { - plan tests => 4; + plan tests => 6; $schema->storage->txn_begin; @@ -198,7 +199,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\$" ] @@ -219,7 +220,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 ) { @@ -236,6 +237,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.34.1