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

(-)a/Koha/Plugins/Base.pm (+2 lines)
Lines 300-305 sub disable { Link Here
300
    my ($self) = @_;
300
    my ($self) = @_;
301
301
302
    $self->store_data( {'__ENABLED__' => 0}  );
302
    $self->store_data( {'__ENABLED__' => 0}  );
303
304
    return $self;
303
}
305
}
304
306
305
1;
307
1;
(-)a/t/db_dependent/Koha/REST/Plugin/PluginRoutes.t (-3 / +51 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 1;
20
use Test::More tests => 2;
21
use Test::Mojo;
21
use Test::Mojo;
22
use Test::Warn;
22
use Test::Warn;
23
23
Lines 35-52 BEGIN { Link Here
35
    t::lib::Mocks::mock_config( 'pluginsdir', $path );
35
    t::lib::Mocks::mock_config( 'pluginsdir', $path );
36
}
36
}
37
37
38
use Koha::Database;
39
use Koha::Plugins;
40
41
my $schema = Koha::Database->new->schema;
42
38
subtest 'Bad plugins tests' => sub {
43
subtest 'Bad plugins tests' => sub {
39
44
40
    plan tests => 3;
45
    plan tests => 3;
41
46
47
    $schema->storage->txn_begin;
48
42
    # enable plugins
49
    # enable plugins
43
    t::lib::Mocks::mock_config( 'enable_plugins', 1 );
50
    t::lib::Mocks::mock_config( 'enable_plugins', 1 );
44
    t::lib::Mocks::mock_preference( 'UseKohaPlugins', 1 );
51
    t::lib::Mocks::mock_preference( 'UseKohaPlugins', 1 );
45
52
53
    my @plugins = Koha::Plugins->new->GetPlugins( { all => 1 } );
54
    foreach my $plugin (@plugins) {
55
        $plugin->enable;
56
    }
57
46
    # initialize Koha::REST::V1 after mocking
58
    # initialize Koha::REST::V1 after mocking
47
    my $remote_address = '127.0.0.1';
48
    my $t;
59
    my $t;
49
50
    warning_is
60
    warning_is
51
        { $t = Test::Mojo->new('Koha::REST::V1'); }
61
        { $t = Test::Mojo->new('Koha::REST::V1'); }
52
        'The resulting spec is invalid. Skipping Bad API Route Plugin',
62
        'The resulting spec is invalid. Skipping Bad API Route Plugin',
Lines 56-61 subtest 'Bad plugins tests' => sub { Link Here
56
    ok( !exists $routes->{'/contrib/badass/patrons/(:patron_id)/bother_wrong'}, 'Route doesn\'t exist' );
66
    ok( !exists $routes->{'/contrib/badass/patrons/(:patron_id)/bother_wrong'}, 'Route doesn\'t exist' );
57
    ok( exists $routes->{'/contrib/testplugin/patrons/(:patron_id)/bother'}, 'Route exists' );
67
    ok( exists $routes->{'/contrib/testplugin/patrons/(:patron_id)/bother'}, 'Route exists' );
58
68
69
    $schema->storage->txn_rollback;
70
};
71
72
subtest 'Disabled plugins tests' => sub {
73
74
    plan tests => 2;
75
76
    $schema->storage->txn_begin;
77
78
    # enable plugins
79
    t::lib::Mocks::mock_config( 'enable_plugins', 1 );
80
    t::lib::Mocks::mock_preference( 'UseKohaPlugins', 1 );
81
82
    my $good_plugin;
83
84
    my @plugins = Koha::Plugins->new->GetPlugins( { all => 1 } );
85
    foreach my $plugin (@plugins) {
86
        $plugin->disable;
87
        $good_plugin = $plugin
88
            if $plugin->{metadata}->{description} eq 'Test plugin';
89
    }
90
91
    # initialize Koha::REST::V1 after mocking
92
    my $t = Test::Mojo->new('Koha::REST::V1');
93
94
    my $routes = get_defined_routes($t);
95
    ok( !exists $routes->{'/contrib/testplugin/patrons/(:patron_id)/bother'},
96
        'Plugin disabled, route not defined' );
97
98
    $good_plugin->enable;
99
100
    $t      = Test::Mojo->new('Koha::REST::V1');
101
    $routes = get_defined_routes($t);
102
103
    ok( exists $routes->{'/contrib/testplugin/patrons/(:patron_id)/bother'},
104
        'Plugin enabled, route defined' );
105
106
    $schema->storage->txn_rollback;
59
};
107
};
60
108
61
sub get_defined_routes {
109
sub get_defined_routes {
(-)a/t/db_dependent/Plugins.t (-4 / +5 lines)
Lines 9-15 use File::Temp qw( tempdir tempfile ); Link Here
9
use FindBin qw($Bin);
9
use FindBin qw($Bin);
10
use Module::Load::Conditional qw(can_load);
10
use Module::Load::Conditional qw(can_load);
11
use Test::MockModule;
11
use Test::MockModule;
12
use Test::More tests => 44;
12
use Test::More tests => 46;
13
13
14
use C4::Context;
14
use C4::Context;
15
use Koha::Database;
15
use Koha::Database;
Lines 77-83 close $fh; Link Here
77
my $classname = ref($plugin);
77
my $classname = ref($plugin);
78
like( $plugin->test_template($fn), qr/^I am $fn/, 'Template works' );
78
like( $plugin->test_template($fn), qr/^I am $fn/, 'Template works' );
79
79
80
$plugin->enable;
80
my $result = $plugin->enable;
81
is( ref($result), 'Koha::Plugin::Test' );
81
82
82
# testing GetPlugins
83
# testing GetPlugins
83
my @plugins = Koha::Plugins->new({ enable_plugins => 1 })->GetPlugins({
84
my @plugins = Koha::Plugins->new({ enable_plugins => 1 })->GetPlugins({
Lines 99-105 my @plugins2 = Koha::Plugins->new({ enable_plugins => 1 })->GetPlugins({ Link Here
99
});
100
});
100
isnt( scalar @plugins2, scalar @plugins, 'GetPlugins with two metadata conditions' );
101
isnt( scalar @plugins2, scalar @plugins, 'GetPlugins with two metadata conditions' );
101
102
102
$plugin->disable;
103
$result = $plugin->disable;
104
is( ref($result), 'Koha::Plugin::Test' );
103
105
104
@plugins = Koha::Plugins->new({ enable_plugins => 1 })->GetPlugins();
106
@plugins = Koha::Plugins->new({ enable_plugins => 1 })->GetPlugins();
105
@names = map { $_->get_metadata()->{'name'} } @plugins;
107
@names = map { $_->get_metadata()->{'name'} } @plugins;
106
- 

Return to bug 22053