|
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 { |