Bug 34978: (follow-up) Add exception when plugin to install is not found and fix unit test
Signed-off-by: Hammat Wele <hammat.wele@inlibro.com> Signed-off-by: Amaury GAU <amaurygau@gmail.com> Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
parent
a9dbb26290
commit
41c3020e64
|
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue