3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 3 of the License, or (at your option) any later
10 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License along
15 # with Koha; if not, see <http://www.gnu.org/licenses>.
19 use Test::More tests => 1;
24 use Koha::BackgroundJobs;
27 use t::lib::Mocks::Logger;
28 use t::lib::TestBuilder;
31 # Mock pluginsdir before loading Plugins module
32 my $path = dirname(__FILE__) . '/../../../lib/plugins';
33 t::lib::Mocks::mock_config( 'pluginsdir', $path );
35 require Koha::Plugins;
36 require Koha::Plugins::Handler;
37 require Koha::Plugin::Test;
40 my $schema = Koha::Database->new->schema;
41 my $builder = t::lib::TestBuilder->new;
42 my $logger = t::lib::Mocks::Logger->new;
44 t::lib::Mocks::mock_config( 'enable_plugins', 1 );
46 subtest 'background_tasks() hooks tests' => sub {
50 $schema->storage->txn_begin;
52 my $bj = Koha::BackgroundJob->new;
53 my $tasks = $bj->type_to_class_mapping;
55 ok( !exists $tasks->{foo} );
56 ok( !exists $tasks->{bar} );
58 my $plugins = Koha::Plugins->new;
59 $plugins->InstallPlugins;
61 my $plugin = Koha::Plugin::Test->new->enable;
63 $bj = Koha::BackgroundJob->new;
64 $tasks = $bj->type_to_class_mapping;
66 is( $tasks->{plugin_test_foo}, 'MyPlugin::Class::Foo' );
67 is( $tasks->{plugin_test_bar}, 'MyPlugin::Class::Bar' );
69 my $metadata = $plugin->get_metadata;
70 delete $metadata->{namespace};
72 my $test_plugin = Test::MockModule->new('Koha::Plugin::Test');
73 $test_plugin->mock( 'get_metadata', sub { return $metadata; } );
75 $plugin = Koha::Plugin::Test->new;
77 $bj = Koha::BackgroundJob->new;
78 $tasks = $bj->type_to_class_mapping;
79 $logger->warn_is("A plugin includes the 'background_tasks' method, but doesn't provide the required 'namespace' method (Koha::Plugin::Test)");
81 t::lib::Mocks::mock_config( 'enable_plugins', 0 );
82 $bj = Koha::BackgroundJob->new;
83 $tasks = $bj->type_to_class_mapping;
85 is_deeply( $tasks, $bj->core_types_to_classes, 'Only core mapping returned when plugins disabled' );
87 $schema->storage->txn_rollback;
88 Koha::Plugins::Methods->delete;