Bug 22053: (QA follow-up) More tests
This patch adds tests for:
- $plugin->enable and $plugin->disable are chainable (i.e. return $self)
- Disabled plugins don't inject routes
To test:
- Apply this patch
- Run:
$ kshell
k$ prove t/db_dependent/Koha/REST/Plugin/PluginRoutes.t \
t/db_dependent/Plugins.t
=> SUCCESS: Tests pass
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
This commit is contained in:
parent
d0e053e24d
commit
4aa2e16ec1
|
|
@ -300,6 +300,8 @@ sub disable {
|
|||
my ($self) = @_;
|
||||
|
||||
$self->store_data( {'__ENABLED__' => 0} );
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
use Modern::Perl;
|
||||
|
||||
use Test::More tests => 1;
|
||||
use Test::More tests => 2;
|
||||
use Test::Mojo;
|
||||
use Test::Warn;
|
||||
|
||||
|
|
@ -35,18 +35,28 @@ BEGIN {
|
|||
t::lib::Mocks::mock_config( 'pluginsdir', $path );
|
||||
}
|
||||
|
||||
use Koha::Database;
|
||||
use Koha::Plugins;
|
||||
|
||||
my $schema = Koha::Database->new->schema;
|
||||
|
||||
subtest 'Bad plugins tests' => sub {
|
||||
|
||||
plan tests => 3;
|
||||
|
||||
$schema->storage->txn_begin;
|
||||
|
||||
# enable plugins
|
||||
t::lib::Mocks::mock_config( 'enable_plugins', 1 );
|
||||
t::lib::Mocks::mock_preference( 'UseKohaPlugins', 1 );
|
||||
|
||||
# initialize Koha::REST::V1 after mocking
|
||||
my $remote_address = '127.0.0.1';
|
||||
my $t;
|
||||
my @plugins = Koha::Plugins->new->GetPlugins( { all => 1 } );
|
||||
foreach my $plugin (@plugins) {
|
||||
$plugin->enable;
|
||||
}
|
||||
|
||||
# initialize Koha::REST::V1 after mocking
|
||||
my $t;
|
||||
warning_is
|
||||
{ $t = Test::Mojo->new('Koha::REST::V1'); }
|
||||
'The resulting spec is invalid. Skipping Bad API Route Plugin',
|
||||
|
|
@ -56,6 +66,44 @@ subtest 'Bad plugins tests' => sub {
|
|||
ok( !exists $routes->{'/contrib/badass/patrons/(:patron_id)/bother_wrong'}, 'Route doesn\'t exist' );
|
||||
ok( exists $routes->{'/contrib/testplugin/patrons/(:patron_id)/bother'}, 'Route exists' );
|
||||
|
||||
$schema->storage->txn_rollback;
|
||||
};
|
||||
|
||||
subtest 'Disabled plugins tests' => sub {
|
||||
|
||||
plan tests => 2;
|
||||
|
||||
$schema->storage->txn_begin;
|
||||
|
||||
# enable plugins
|
||||
t::lib::Mocks::mock_config( 'enable_plugins', 1 );
|
||||
t::lib::Mocks::mock_preference( 'UseKohaPlugins', 1 );
|
||||
|
||||
my $good_plugin;
|
||||
|
||||
my @plugins = Koha::Plugins->new->GetPlugins( { all => 1 } );
|
||||
foreach my $plugin (@plugins) {
|
||||
$plugin->disable;
|
||||
$good_plugin = $plugin
|
||||
if $plugin->{metadata}->{description} eq 'Test plugin';
|
||||
}
|
||||
|
||||
# initialize Koha::REST::V1 after mocking
|
||||
my $t = Test::Mojo->new('Koha::REST::V1');
|
||||
|
||||
my $routes = get_defined_routes($t);
|
||||
ok( !exists $routes->{'/contrib/testplugin/patrons/(:patron_id)/bother'},
|
||||
'Plugin disabled, route not defined' );
|
||||
|
||||
$good_plugin->enable;
|
||||
|
||||
$t = Test::Mojo->new('Koha::REST::V1');
|
||||
$routes = get_defined_routes($t);
|
||||
|
||||
ok( exists $routes->{'/contrib/testplugin/patrons/(:patron_id)/bother'},
|
||||
'Plugin enabled, route defined' );
|
||||
|
||||
$schema->storage->txn_rollback;
|
||||
};
|
||||
|
||||
sub get_defined_routes {
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ use File::Temp qw( tempdir tempfile );
|
|||
use FindBin qw($Bin);
|
||||
use Module::Load::Conditional qw(can_load);
|
||||
use Test::MockModule;
|
||||
use Test::More tests => 44;
|
||||
use Test::More tests => 46;
|
||||
|
||||
use C4::Context;
|
||||
use Koha::Database;
|
||||
|
|
@ -77,7 +77,8 @@ close $fh;
|
|||
my $classname = ref($plugin);
|
||||
like( $plugin->test_template($fn), qr/^I am $fn/, 'Template works' );
|
||||
|
||||
$plugin->enable;
|
||||
my $result = $plugin->enable;
|
||||
is( ref($result), 'Koha::Plugin::Test' );
|
||||
|
||||
# testing GetPlugins
|
||||
my @plugins = Koha::Plugins->new({ enable_plugins => 1 })->GetPlugins({
|
||||
|
|
@ -99,7 +100,8 @@ my @plugins2 = Koha::Plugins->new({ enable_plugins => 1 })->GetPlugins({
|
|||
});
|
||||
isnt( scalar @plugins2, scalar @plugins, 'GetPlugins with two metadata conditions' );
|
||||
|
||||
$plugin->disable;
|
||||
$result = $plugin->disable;
|
||||
is( ref($result), 'Koha::Plugin::Test' );
|
||||
|
||||
@plugins = Koha::Plugins->new({ enable_plugins => 1 })->GetPlugins();
|
||||
@names = map { $_->get_metadata()->{'name'} } @plugins;
|
||||
|
|
|
|||
Loading…
Reference in New Issue