Bug 26138: Make Koha::Plugins->call return consistent value

It must return an empty array in case the enable_plugins config flag is
disabled

Test plan:
Turn the config off in koha-conf
Start a search at the OPAC
Without this patch you got:
  Can't use string ("0") as a HASH ref while "strict refs" in use at /home/vagrant/kohaclone/opac/opac-search.pl line 661
With this patch applied you see the search result

Followed test plan - works as described.

Signed-off-by: Alex Buckley <alexbuckley@catalyst.net.nz>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Jonathan Druart 2020-08-05 09:30:31 +02:00
parent c34d222d57
commit 88506d7bb6
2 changed files with 8 additions and 4 deletions

View file

@ -63,9 +63,9 @@ Calls a plugin method for all enabled plugins
sub call {
my ($class, $method, @args) = @_;
my @responses;
if (C4::Context->config('enable_plugins')) {
my @plugins = $class->new({ enable_plugins => 1 })->GetPlugins({ method => $method });
my @responses;
@plugins = grep { $_->can($method) } @plugins;
foreach my $plugin (@plugins) {
my $response = eval { $plugin->$method(@args) };
@ -77,8 +77,8 @@ sub call {
push @responses, $response;
}
return @responses;
}
return @responses;
}
=head2 GetPlugins

View file

@ -47,12 +47,13 @@ BEGIN {
my $schema = Koha::Database->new->schema;
subtest 'call() tests' => sub {
plan tests => 2;
plan tests => 3;
$schema->storage->txn_begin;
# Temporarily remove any installed plugins data
Koha::Plugins::Methods->delete;
t::lib::Mocks::mock_config('enable_plugins', 1);
my $plugins = Koha::Plugins->new({ enable_plugins => 1 });
my @plugins = $plugins->InstallPlugins;
foreach my $plugin (@plugins) {
@ -70,6 +71,10 @@ subtest 'call() tests' => sub {
$expected = [ { error => 0 } ];
is_deeply(\@responses, $expected, 'call() should return all responses from plugins');
t::lib::Mocks::mock_config('enable_plugins', 0);
@responses = Koha::Plugins->call('check_password', { password => '1234' });
is_deeply(\@responses, [], 'call() should return an empty array if plugins are disabled');
$schema->storage->txn_rollback;
};
@ -352,5 +357,4 @@ subtest 'new() tests' => sub {
is( ref($result), 'Koha::Plugins', 'calling new with enable_plugins makes it override the config' );
};
$schema->storage->txn_rollback;
Koha::Plugins::Methods->delete;