View | Details | Raw Unified | Return to bug 26138
Collapse All | Expand All

(-)a/Koha/Plugins.pm (-2 / +2 lines)
Lines 63-71 Calls a plugin method for all enabled plugins Link Here
63
sub call {
63
sub call {
64
    my ($class, $method, @args) = @_;
64
    my ($class, $method, @args) = @_;
65
65
66
    my @responses;
66
    if (C4::Context->config('enable_plugins')) {
67
    if (C4::Context->config('enable_plugins')) {
67
        my @plugins = $class->new({ enable_plugins => 1 })->GetPlugins({ method => $method });
68
        my @plugins = $class->new({ enable_plugins => 1 })->GetPlugins({ method => $method });
68
        my @responses;
69
        @plugins = grep { $_->can($method) } @plugins;
69
        @plugins = grep { $_->can($method) } @plugins;
70
        foreach my $plugin (@plugins) {
70
        foreach my $plugin (@plugins) {
71
            my $response = eval { $plugin->$method(@args) };
71
            my $response = eval { $plugin->$method(@args) };
Lines 77-84 sub call { Link Here
77
            push @responses, $response;
77
            push @responses, $response;
78
        }
78
        }
79
79
80
        return @responses;
81
    }
80
    }
81
    return @responses;
82
}
82
}
83
83
84
=head2 GetPlugins
84
=head2 GetPlugins
(-)a/t/db_dependent/Koha/Plugins/Plugins.t (-3 / +6 lines)
Lines 47-58 BEGIN { Link Here
47
my $schema = Koha::Database->new->schema;
47
my $schema = Koha::Database->new->schema;
48
48
49
subtest 'call() tests' => sub {
49
subtest 'call() tests' => sub {
50
    plan tests => 2;
50
    plan tests => 3;
51
51
52
    $schema->storage->txn_begin;
52
    $schema->storage->txn_begin;
53
    # Temporarily remove any installed plugins data
53
    # Temporarily remove any installed plugins data
54
    Koha::Plugins::Methods->delete;
54
    Koha::Plugins::Methods->delete;
55
55
56
    t::lib::Mocks::mock_config('enable_plugins', 1);
56
    my $plugins = Koha::Plugins->new({ enable_plugins => 1 });
57
    my $plugins = Koha::Plugins->new({ enable_plugins => 1 });
57
    my @plugins = $plugins->InstallPlugins;
58
    my @plugins = $plugins->InstallPlugins;
58
    foreach my $plugin (@plugins) {
59
    foreach my $plugin (@plugins) {
Lines 70-75 subtest 'call() tests' => sub { Link Here
70
    $expected = [ { error => 0 } ];
71
    $expected = [ { error => 0 } ];
71
    is_deeply(\@responses, $expected, 'call() should return all responses from plugins');
72
    is_deeply(\@responses, $expected, 'call() should return all responses from plugins');
72
73
74
    t::lib::Mocks::mock_config('enable_plugins', 0);
75
    @responses = Koha::Plugins->call('check_password', { password => '1234' });
76
    is_deeply(\@responses, [], 'call() should return an empty array if plugins are disabled');
77
73
    $schema->storage->txn_rollback;
78
    $schema->storage->txn_rollback;
74
};
79
};
75
80
Lines 352-356 subtest 'new() tests' => sub { Link Here
352
    is( ref($result), 'Koha::Plugins', 'calling new with enable_plugins makes it override the config' );
357
    is( ref($result), 'Koha::Plugins', 'calling new with enable_plugins makes it override the config' );
353
};
358
};
354
359
355
$schema->storage->txn_rollback;
356
Koha::Plugins::Methods->delete;
360
Koha::Plugins::Methods->delete;
357
- 

Return to bug 26138