|
Line 0
Link Here
|
|
|
1 |
#!/usr/bin/perl |
| 2 |
|
| 3 |
# This file is part of Koha. |
| 4 |
# |
| 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 |
| 8 |
# version. |
| 9 |
# |
| 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. |
| 13 |
# |
| 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>. |
| 16 |
|
| 17 |
use Modern::Perl; |
| 18 |
|
| 19 |
use Test::More tests => 1; |
| 20 |
use Test::MockModule; |
| 21 |
|
| 22 |
use File::Basename; |
| 23 |
|
| 24 |
use Koha::BackgroundJobs; |
| 25 |
|
| 26 |
use t::lib::Mocks; |
| 27 |
use t::lib::Mocks::Logger; |
| 28 |
use t::lib::TestBuilder; |
| 29 |
|
| 30 |
BEGIN { |
| 31 |
# Mock pluginsdir before loading Plugins module |
| 32 |
my $path = dirname(__FILE__) . '/../../../lib/plugins'; |
| 33 |
t::lib::Mocks::mock_config( 'pluginsdir', $path ); |
| 34 |
|
| 35 |
require Koha::Plugins; |
| 36 |
require Koha::Plugins::Handler; |
| 37 |
require Koha::Plugin::Test; |
| 38 |
} |
| 39 |
|
| 40 |
my $schema = Koha::Database->new->schema; |
| 41 |
my $builder = t::lib::TestBuilder->new; |
| 42 |
my $logger = t::lib::Mocks::Logger->new; |
| 43 |
|
| 44 |
t::lib::Mocks::mock_config( 'enable_plugins', 1 ); |
| 45 |
|
| 46 |
subtest 'background_tasks() hooks tests' => sub { |
| 47 |
|
| 48 |
plan tests => 5; |
| 49 |
|
| 50 |
$schema->storage->txn_begin; |
| 51 |
|
| 52 |
my $bj = Koha::BackgroundJob->new; |
| 53 |
my $tasks = $bj->type_to_class_mapping; |
| 54 |
|
| 55 |
ok( !exists $tasks->{foo} ); |
| 56 |
ok( !exists $tasks->{bar} ); |
| 57 |
|
| 58 |
my $plugins = Koha::Plugins->new; |
| 59 |
$plugins->InstallPlugins; |
| 60 |
|
| 61 |
my $plugin = Koha::Plugin::Test->new->enable; |
| 62 |
|
| 63 |
$bj = Koha::BackgroundJob->new; |
| 64 |
$tasks = $bj->type_to_class_mapping; |
| 65 |
|
| 66 |
is( $tasks->{plugin_test_foo}, 'MyPlugin::Class::Foo' ); |
| 67 |
is( $tasks->{plugin_test_bar}, 'MyPlugin::Class::Bar' ); |
| 68 |
|
| 69 |
my $metadata = $plugin->get_metadata; |
| 70 |
delete $metadata->{namespace}; |
| 71 |
|
| 72 |
my $test_plugin = Test::MockModule->new('Koha::Plugin::Test'); |
| 73 |
$test_plugin->mock( 'get_metadata', sub { return $metadata; } ); |
| 74 |
|
| 75 |
$plugin = Koha::Plugin::Test->new; |
| 76 |
|
| 77 |
$bj = Koha::BackgroundJob->new; |
| 78 |
$tasks = $bj->type_to_class_mapping; |
| 79 |
$logger->warn_is("The plugin includes the 'background_tasks' method, but doesn't provide the required 'namespace' method (Koha::Plugin::Test)"); |
| 80 |
|
| 81 |
$schema->storage->txn_rollback; |
| 82 |
Koha::Plugins::Methods->delete; |
| 83 |
}; |