|
Lines 17-23
Link Here
|
| 17 |
|
17 |
|
| 18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
| 19 |
|
19 |
|
| 20 |
use Test::More tests => 3; |
20 |
use Test::More tests => 4; |
| 21 |
use Test::Mojo; |
21 |
use Test::Mojo; |
| 22 |
use Test::Warn; |
22 |
use Test::Warn; |
| 23 |
|
23 |
|
|
Lines 69-76
subtest 'Bad plugins tests' => sub {
Link Here
|
| 69 |
my $routes = get_defined_routes($t); |
69 |
my $routes = get_defined_routes($t); |
| 70 |
# Support placeholders () and <> (latter style used starting with Mojolicious::Plugin::OpenAPI@1.28) |
70 |
# Support placeholders () and <> (latter style used starting with Mojolicious::Plugin::OpenAPI@1.28) |
| 71 |
# TODO: remove () if minimum version is bumped to at least 1.28. |
71 |
# TODO: remove () if minimum version is bumped to at least 1.28. |
| 72 |
ok( !exists $routes->{'/contrib/badass/patrons/(:patron_id)/bother_wrong'} && !exists $routes->{'/contrib/badass/patrons/<:patron_id>/bother_wrong'}, 'Route doesn\'t exist' ); |
72 |
ok( !exists $routes->{'/contrib/badass/patrons/bother_wrong'}, 'Route doesn\'t exist' ); |
| 73 |
ok( exists $routes->{'/contrib/testplugin/patrons/(:patron_id)/bother'} || exists $routes->{'/contrib/testplugin/patrons/<:patron_id>/bother'}, 'Route exists' ); |
73 |
ok( exists $routes->{'/contrib/testplugin/patrons/bother'}, 'Route exists' ); |
| 74 |
|
74 |
|
| 75 |
$schema->storage->txn_rollback; |
75 |
$schema->storage->txn_rollback; |
| 76 |
}; |
76 |
}; |
|
Lines 102-108
subtest 'Disabled plugins tests' => sub {
Link Here
|
| 102 |
my $routes = get_defined_routes($t); |
102 |
my $routes = get_defined_routes($t); |
| 103 |
# Support placeholders () and <> (latter style used starting with Mojolicious::Plugin::OpenAPI@1.28) |
103 |
# Support placeholders () and <> (latter style used starting with Mojolicious::Plugin::OpenAPI@1.28) |
| 104 |
# TODO: remove () if minimum version is bumped to at least 1.28. |
104 |
# TODO: remove () if minimum version is bumped to at least 1.28. |
| 105 |
ok( !exists $routes->{'/contrib/testplugin/patrons/(:patron_id)/bother'} && !exists $routes->{'/contrib/testplugin/patrons/<:patron_id>/bother'}, |
105 |
ok( !exists $routes->{'/contrib/testplugin/patrons/bother'}, |
| 106 |
'Plugin disabled, route not defined' ); |
106 |
'Plugin disabled, route not defined' ); |
| 107 |
|
107 |
|
| 108 |
$good_plugin->enable; |
108 |
$good_plugin->enable; |
|
Lines 112-123
subtest 'Disabled plugins tests' => sub {
Link Here
|
| 112 |
|
112 |
|
| 113 |
# Support placeholders () and <> (latter style used starting with Mojolicious::Plugin::OpenAPI@1.28) |
113 |
# Support placeholders () and <> (latter style used starting with Mojolicious::Plugin::OpenAPI@1.28) |
| 114 |
# TODO: remove () if minimum version is bumped to at least 1.28. |
114 |
# TODO: remove () if minimum version is bumped to at least 1.28. |
| 115 |
ok( exists $routes->{'/contrib/testplugin/patrons/(:patron_id)/bother'} || exists $routes->{'/contrib/testplugin/patrons/<:patron_id>/bother'}, |
115 |
ok( exists $routes->{'/contrib/testplugin/patrons/bother'}, |
| 116 |
'Plugin enabled, route defined' ); |
116 |
'Plugin enabled, route defined' ); |
| 117 |
|
117 |
|
| 118 |
$schema->storage->txn_rollback; |
118 |
$schema->storage->txn_rollback; |
| 119 |
}; |
119 |
}; |
| 120 |
|
120 |
|
|
|
121 |
subtest 'Anonymous access routes plugins tests' => sub { |
| 122 |
|
| 123 |
plan tests => 9; |
| 124 |
|
| 125 |
$schema->storage->txn_begin; |
| 126 |
|
| 127 |
# enable plugins |
| 128 |
t::lib::Mocks::mock_config( 'enable_plugins', 1 ); |
| 129 |
|
| 130 |
# remove any existing plugins that might interfere |
| 131 |
Koha::Plugins::Methods->search->delete; |
| 132 |
my $plugins = Koha::Plugins->new; |
| 133 |
$plugins->InstallPlugins; |
| 134 |
|
| 135 |
my @plugins = $plugins->GetPlugins( { all => 1 } ); |
| 136 |
foreach my $plugin (@plugins) { |
| 137 |
$plugin->enable; |
| 138 |
} |
| 139 |
|
| 140 |
# initialize Koha::REST::V1 after mocking |
| 141 |
my $t; |
| 142 |
warning_is |
| 143 |
{ $t = Test::Mojo->new('Koha::REST::V1'); } |
| 144 |
'The resulting spec is invalid. Skipping Bad API Route Plugin', |
| 145 |
'Bad plugins raise warning'; |
| 146 |
|
| 147 |
my $routes = get_defined_routes($t); |
| 148 |
ok( exists $routes->{'/contrib/testplugin/patrons/bother'}, 'Route exists' ); |
| 149 |
ok( exists $routes->{'/contrib/testplugin/public/patrons/bother'}, 'Route exists' ); |
| 150 |
|
| 151 |
C4::Context->set_preference( 'RESTPublicAnonymousRequests', 0 ); |
| 152 |
|
| 153 |
$t->get_ok('/api/v1/contrib/testplugin/public/patrons/bother') |
| 154 |
->status_is(200, 'Plugin routes not affected by RESTPublicAnonymousRequests') |
| 155 |
->json_is( { bothered => Mojo::JSON->true } ); |
| 156 |
|
| 157 |
C4::Context->set_preference( 'RESTPublicAnonymousRequests', 1 ); |
| 158 |
|
| 159 |
$t->get_ok('/api/v1/contrib/testplugin/public/patrons/bother') |
| 160 |
->status_is(200, 'Plugin routes not affected by RESTPublicAnonymousRequests') |
| 161 |
->json_is( { bothered => Mojo::JSON->true } ); |
| 162 |
|
| 163 |
$schema->storage->txn_rollback; |
| 164 |
}; |
| 165 |
|
| 121 |
subtest 'needs_install use case tests' => sub { |
166 |
subtest 'needs_install use case tests' => sub { |
| 122 |
|
167 |
|
| 123 |
plan tests => 2; |
168 |
plan tests => 2; |
|
Lines 142-149
subtest 'needs_install use case tests' => sub {
Link Here
|
| 142 |
# Support placeholders () and <> (latter style used starting with Mojolicious::Plugin::OpenAPI@1.28) |
187 |
# Support placeholders () and <> (latter style used starting with Mojolicious::Plugin::OpenAPI@1.28) |
| 143 |
# TODO: remove () if minimum version is bumped to at least 1.28. |
188 |
# TODO: remove () if minimum version is bumped to at least 1.28. |
| 144 |
ok( |
189 |
ok( |
| 145 |
!exists $routes->{'/contrib/testplugin/patrons/(:patron_id)/bother'} |
190 |
!exists $routes->{'/contrib/testplugin/patrons/bother'}, |
| 146 |
&& !exists $routes->{'/contrib/testplugin/patrons/<:patron_id>/bother'}, |
|
|
| 147 |
'Plugin enabled, route not defined as C4::Context->needs_install is true' |
191 |
'Plugin enabled, route not defined as C4::Context->needs_install is true' |
| 148 |
); |
192 |
); |
| 149 |
|
193 |
|
|
Lines 159-166
subtest 'needs_install use case tests' => sub {
Link Here
|
| 159 |
# Support placeholders () and <> (latter style used starting with Mojolicious::Plugin::OpenAPI@1.28) |
203 |
# Support placeholders () and <> (latter style used starting with Mojolicious::Plugin::OpenAPI@1.28) |
| 160 |
# TODO: remove () if minimum version is bumped to at least 1.28. |
204 |
# TODO: remove () if minimum version is bumped to at least 1.28. |
| 161 |
ok( |
205 |
ok( |
| 162 |
exists $routes->{'/contrib/testplugin/patrons/(:patron_id)/bother'} |
206 |
exists $routes->{'/contrib/testplugin/patrons/bother'}, |
| 163 |
|| exists $routes->{'/contrib/testplugin/patrons/<:patron_id>/bother'}, |
|
|
| 164 |
'Plugin enabled, route defined as C4::Context->needs_install is false' |
207 |
'Plugin enabled, route defined as C4::Context->needs_install is false' |
| 165 |
); |
208 |
); |
| 166 |
|
209 |
|