diff --git a/Koha/Plugins.pm b/Koha/Plugins.pm index 1360afa174..3b31fc5bd9 100644 --- a/Koha/Plugins.pm +++ b/Koha/Plugins.pm @@ -63,7 +63,7 @@ sub GetPlugins { foreach my $plugin_class (@plugin_classes) { if ( can_load( modules => { $plugin_class => undef } ) ) { - my $plugin = $plugin_class->new(); + my $plugin = $plugin_class->new({ enable_plugins => $self->{'enable_plugins'} }); if ($method) { if ( $plugin->can($method) ) { diff --git a/Koha/Plugins/Handler.pm b/Koha/Plugins/Handler.pm index 18ceba120a..41c242b5c4 100644 --- a/Koha/Plugins/Handler.pm +++ b/Koha/Plugins/Handler.pm @@ -58,7 +58,7 @@ sub run { my $cgi = $args->{'cgi'}; if ( can_load( modules => { $plugin_class => undef } ) ) { - my $plugin = $plugin_class->new( { cgi => $cgi } ); + my $plugin = $plugin_class->new( { cgi => $cgi, enable_plugins => $args->{'enable_plugins'} } ); if ( $plugin->can($plugin_method) ) { return $plugin->$plugin_method(); } else { diff --git a/t/db_dependent/Plugins.t b/t/db_dependent/Plugins.t index 03fa4bf2b3..1b87d2afc5 100755 --- a/t/db_dependent/Plugins.t +++ b/t/db_dependent/Plugins.t @@ -33,7 +33,7 @@ ok( $plugin->can('configure'), 'Test plugin can configure' ); ok( $plugin->can('install'), 'Test plugin can install' ); ok( $plugin->can('uninstall'), 'Test plugin can install' ); -ok( Koha::Plugins::Handler->run({ class => "Koha::Plugin::Test", method => 'report' }) eq "Koha::Plugin::Test::report", 'Test run plugin report method' ); +ok( Koha::Plugins::Handler->run({ class => "Koha::Plugin::Test", method => 'report', enable_plugins => 1 }) eq "Koha::Plugin::Test::report", 'Test run plugin report method' ); my $metadata = $plugin->get_metadata(); ok( $metadata->{'name'} eq 'Test Plugin', 'Test $plugin->get_metadata()' ); @@ -41,17 +41,22 @@ ok( $metadata->{'name'} eq 'Test Plugin', 'Test $plugin->get_metadata()' ); ok( $plugin->get_qualified_table_name('mytable') eq 'koha_plugin_test_mytable', 'Test $plugin->get_qualified_table_name()' ); ok( $plugin->get_plugin_http_path() eq '/plugin/Koha/Plugin/Test', 'Test $plugin->get_plugin_http_path()' ); -my @plugins = Koha::Plugins->new()->GetPlugins( 'report' ); +my @plugins = Koha::Plugins->new({ enable_plugins => 1 })->GetPlugins( 'report' ); ok( $plugins[0]->get_metadata()->{'name'} eq 'Test Plugin', "Koha::Plugins::GetPlugins functions correctly" ); -my $plugins_dir = C4::Context->config("pluginsdir"); -my $ae = Archive::Extract->new( archive => "$Bin/KitchenSinkPlugin.kpz", type => 'zip' ); -unless ( $ae->extract( to => $plugins_dir ) ) { - warn "ERROR: " . $ae->error; -} -use_ok('Koha::Plugin::Com::ByWaterSolutions::KitchenSink'); -$plugin = Koha::Plugin::Com::ByWaterSolutions::KitchenSink->new({ enable_plugins => 1}); +SKIP: { + skip "plugindir not set", 3 unless C4::Context->config("pluginsdir"); + + my $plugins_dir = C4::Context->config("pluginsdir"); + my $ae = Archive::Extract->new( archive => "$Bin/KitchenSinkPlugin.kpz", type => 'zip' ); + unless ( $ae->extract( to => $plugins_dir ) ) { + warn "ERROR: " . $ae->error; + } + use_ok('Koha::Plugin::Com::ByWaterSolutions::KitchenSink'); + $plugin = Koha::Plugin::Com::ByWaterSolutions::KitchenSink->new({ enable_plugins => 1}); + + ok( -f $plugins_dir . "/Koha/Plugin/Com/ByWaterSolutions/KitchenSink.pm", "KitchenSink plugin installed successfully" ); + Koha::Plugins::Handler->delete({ class => "Koha::Plugin::Com::ByWaterSolutions::KitchenSink" }); + ok( !( -f $plugins_dir . "/Koha/Plugin/Com/ByWaterSolutions/KitchenSink.pm" ), "Koha::Plugins::Handler::delete works correctly." ); +} -ok( -f $plugins_dir . "/Koha/Plugin/Com/ByWaterSolutions/KitchenSink.pm", "KitchenSink plugin installed successfully" ); -Koha::Plugins::Handler->delete({ class => "Koha::Plugin::Com::ByWaterSolutions::KitchenSink" }); -ok( !( -f $plugins_dir . "/Koha/Plugin/Com/ByWaterSolutions/KitchenSink.pm" ), "Koha::Plugins::Handler::delete works correctly." );