Bugzilla – Attachment 132814 Details for
Bug 30410
Add a way for plugins to register background tasks
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 30410: Unit tests
Bug-30410-Unit-tests.patch (text/plain), 3.75 KB, created by
Tomás Cohen Arazi (tcohen)
on 2022-04-01 07:19:53 UTC
(
hide
)
Description:
Bug 30410: Unit tests
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2022-04-01 07:19:53 UTC
Size:
3.75 KB
patch
obsolete
>From 363c255fed4b196f048f465dea5f606fd05e1362 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Thu, 31 Mar 2022 17:32:40 +0200 >Subject: [PATCH] Bug 30410: Unit tests > >--- > t/db_dependent/Koha/Plugins/BackgroundJob.t | 83 +++++++++++++++++++++ > t/lib/plugins/Koha/Plugin/Test.pm | 8 ++ > 2 files changed, 91 insertions(+) > create mode 100755 t/db_dependent/Koha/Plugins/BackgroundJob.t > >diff --git a/t/db_dependent/Koha/Plugins/BackgroundJob.t b/t/db_dependent/Koha/Plugins/BackgroundJob.t >new file mode 100755 >index 0000000000..0f5932eca0 >--- /dev/null >+++ b/t/db_dependent/Koha/Plugins/BackgroundJob.t >@@ -0,0 +1,83 @@ >+#!/usr/bin/perl >+ >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it under the >+# terms of the GNU General Public License as published by the Free Software >+# Foundation; either version 3 of the License, or (at your option) any later >+# version. >+# >+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY >+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR >+# A PARTICULAR PURPOSE. See the GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License along >+# with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+ >+use Test::More tests => 1; >+use Test::MockModule; >+ >+use File::Basename; >+ >+use Koha::BackgroundJobs; >+ >+use t::lib::Mocks; >+use t::lib::Mocks::Logger; >+use t::lib::TestBuilder; >+ >+BEGIN { >+ # Mock pluginsdir before loading Plugins module >+ my $path = dirname(__FILE__) . '/../../../lib/plugins'; >+ t::lib::Mocks::mock_config( 'pluginsdir', $path ); >+ >+ require Koha::Plugins; >+ require Koha::Plugins::Handler; >+ require Koha::Plugin::Test; >+} >+ >+my $schema = Koha::Database->new->schema; >+my $builder = t::lib::TestBuilder->new; >+my $logger = t::lib::Mocks::Logger->new; >+ >+t::lib::Mocks::mock_config( 'enable_plugins', 1 ); >+ >+subtest 'background_tasks() hooks tests' => sub { >+ >+ plan tests => 5; >+ >+ $schema->storage->txn_begin; >+ >+ my $bj = Koha::BackgroundJob->new; >+ my $tasks = $bj->type_to_class_mapping; >+ >+ ok( !exists $tasks->{foo} ); >+ ok( !exists $tasks->{bar} ); >+ >+ my $plugins = Koha::Plugins->new; >+ $plugins->InstallPlugins; >+ >+ my $plugin = Koha::Plugin::Test->new->enable; >+ >+ $bj = Koha::BackgroundJob->new; >+ $tasks = $bj->type_to_class_mapping; >+ >+ is( $tasks->{plugin_test_foo}, 'MyPlugin::Class::Foo' ); >+ is( $tasks->{plugin_test_bar}, 'MyPlugin::Class::Bar' ); >+ >+ my $metadata = $plugin->get_metadata; >+ delete $metadata->{namespace}; >+ >+ my $test_plugin = Test::MockModule->new('Koha::Plugin::Test'); >+ $test_plugin->mock( 'get_metadata', sub { return $metadata; } ); >+ >+ $plugin = Koha::Plugin::Test->new; >+ >+ $bj = Koha::BackgroundJob->new; >+ $tasks = $bj->type_to_class_mapping; >+ $logger->warn_is("The plugin includes the 'background_tasks' method, but doesn't provide the required 'namespace' method (Koha::Plugin::Test)"); >+ >+ $schema->storage->txn_rollback; >+ Koha::Plugins::Methods->delete; >+}; >diff --git a/t/lib/plugins/Koha/Plugin/Test.pm b/t/lib/plugins/Koha/Plugin/Test.pm >index 61e1f942f2..eee99859d1 100644 >--- a/t/lib/plugins/Koha/Plugin/Test.pm >+++ b/t/lib/plugins/Koha/Plugin/Test.pm >@@ -21,6 +21,7 @@ our $metadata = { > minimum_version => '3.11', > maximum_version => undef, > version => $VERSION, >+ namespace => 'test', > my_example_tag => 'find_me', > }; > >@@ -340,6 +341,13 @@ sub intranet_catalog_biblio_tab { > return @tabs; > } > >+sub background_tasks { >+ return { >+ foo => 'MyPlugin::Class::Foo', >+ bar => 'MyPlugin::Class::Bar', >+ }; >+} >+ > sub _private_sub { > return ""; > } >-- >2.35.1
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 30410
:
132814
|
132815
|
133180
|
133181
|
133192
|
133193
|
133194
|
133195
|
133386