Bugzilla – Attachment 89043 Details for
Bug 22053
Ability to disable some plugins
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 22053: (QA follow-up) More tests
Bug-22053-QA-follow-up-More-tests.patch (text/plain), 4.70 KB, created by
Tomás Cohen Arazi
on 2019-04-29 18:30:29 UTC
(
hide
)
Description:
Bug 22053: (QA follow-up) More tests
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi
Created:
2019-04-29 18:30:29 UTC
Size:
4.70 KB
patch
obsolete
>From e0727ec8089be9ad3aca5e0ff25ca5a82c3782ab Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Mon, 29 Apr 2019 15:21:32 -0300 >Subject: [PATCH] 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> >--- > Koha/Plugins/Base.pm | 2 + > .../Koha/REST/Plugin/PluginRoutes.t | 54 +++++++++++++++++-- > t/db_dependent/Plugins.t | 8 +-- > 3 files changed, 58 insertions(+), 6 deletions(-) > >diff --git a/Koha/Plugins/Base.pm b/Koha/Plugins/Base.pm >index 20d8b79829..392ab4c900 100644 >--- a/Koha/Plugins/Base.pm >+++ b/Koha/Plugins/Base.pm >@@ -300,6 +300,8 @@ sub disable { > my ($self) = @_; > > $self->store_data( {'__ENABLED__' => 0} ); >+ >+ return $self; > } > > 1; >diff --git a/t/db_dependent/Koha/REST/Plugin/PluginRoutes.t b/t/db_dependent/Koha/REST/Plugin/PluginRoutes.t >index 06fecd38fa..cc50b56b90 100644 >--- a/t/db_dependent/Koha/REST/Plugin/PluginRoutes.t >+++ b/t/db_dependent/Koha/REST/Plugin/PluginRoutes.t >@@ -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 ); > >+ my @plugins = Koha::Plugins->new->GetPlugins( { all => 1 } ); >+ foreach my $plugin (@plugins) { >+ $plugin->enable; >+ } >+ > # initialize Koha::REST::V1 after mocking >- my $remote_address = '127.0.0.1'; > 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 { >diff --git a/t/db_dependent/Plugins.t b/t/db_dependent/Plugins.t >index f34500e146..e89cebe0b3 100755 >--- a/t/db_dependent/Plugins.t >+++ b/t/db_dependent/Plugins.t >@@ -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; >-- >2.21.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 22053
:
83537
|
83538
|
83539
|
83540
|
83666
|
83667
|
86961
|
86962
|
86963
|
86964
|
88783
|
88784
|
88785
|
88818
|
88819
|
88820
|
89040
|
89041
|
89042
| 89043 |
89116
|
89551
|
89558