|
Lines 1-84
Link Here
|
| 1 |
#!/usr/bin/perl |
|
|
| 2 |
|
| 3 |
# Copyright 2023 Koha Development team |
| 4 |
# |
| 5 |
# This file is part of Koha |
| 6 |
# |
| 7 |
# Koha is free software; you can redistribute it and/or modify it |
| 8 |
# under the terms of the GNU General Public License as published by |
| 9 |
# the Free Software Foundation; either version 3 of the License, or |
| 10 |
# (at your option) any later version. |
| 11 |
# |
| 12 |
# Koha is distributed in the hope that it will be useful, but |
| 13 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
# GNU General Public License for more details. |
| 16 |
# |
| 17 |
# You should have received a copy of the GNU General Public License |
| 18 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
| 19 |
|
| 20 |
use Modern::Perl; |
| 21 |
use File::Basename; |
| 22 |
use File::Path qw(make_path remove_tree); |
| 23 |
use Test::MockModule; |
| 24 |
|
| 25 |
use Test::More tests => 4; |
| 26 |
|
| 27 |
use Koha::ILL::Backends; |
| 28 |
|
| 29 |
use t::lib::TestBuilder; |
| 30 |
use t::lib::Mocks; |
| 31 |
|
| 32 |
BEGIN { |
| 33 |
# Mock pluginsdir before loading Plugins module |
| 34 |
my $path = dirname(__FILE__) . '/../../../lib/plugins'; |
| 35 |
t::lib::Mocks::mock_config( 'pluginsdir', $path ); |
| 36 |
|
| 37 |
use_ok('Koha::Plugins'); |
| 38 |
use_ok('Koha::Plugins::Handler'); |
| 39 |
use_ok('Koha::Plugin::Test'); |
| 40 |
} |
| 41 |
|
| 42 |
my $builder = t::lib::TestBuilder->new; |
| 43 |
my $schema = Koha::Database->new->schema; |
| 44 |
|
| 45 |
t::lib::Mocks::mock_config( 'enable_plugins', 1 ); |
| 46 |
|
| 47 |
subtest 'installed_backends() tests' => sub { |
| 48 |
|
| 49 |
# dir backend = An ILL backend installed through backend_directory in koha-conf.xml |
| 50 |
# plugin backend = An ILL backend installed through a plugin |
| 51 |
|
| 52 |
plan tests => 2; |
| 53 |
|
| 54 |
$schema->storage->txn_begin; |
| 55 |
|
| 56 |
# Install a plugin_backend |
| 57 |
my $plugins = Koha::Plugins->new; |
| 58 |
$plugins->InstallPlugins; |
| 59 |
is_deeply( |
| 60 |
Koha::ILL::Backends->installed_backends, ['Test Plugin'], |
| 61 |
'Only one backend installed, happens to be a plugin' |
| 62 |
); |
| 63 |
|
| 64 |
# Install a dir backend |
| 65 |
my $dir_backend = '/tmp/ill_backend_test/Old_Backend'; |
| 66 |
my $ill_config = Test::MockModule->new('Koha::ILL::Request::Config'); |
| 67 |
$ill_config->mock( |
| 68 |
'backend_dir', |
| 69 |
sub { |
| 70 |
return '/tmp/ill_backend_test'; |
| 71 |
} |
| 72 |
); |
| 73 |
make_path($dir_backend); |
| 74 |
my $installed_backends = Koha::ILL::Backends->installed_backends; |
| 75 |
is_deeply( |
| 76 |
$installed_backends, [ 'Old_Backend', 'Test Plugin' ], |
| 77 |
'Two backends are installed, one plugin and one directory backend' |
| 78 |
); |
| 79 |
|
| 80 |
#cleanup |
| 81 |
remove_tree($dir_backend); |
| 82 |
Koha::Plugins::Methods->delete; |
| 83 |
$schema->storage->txn_rollback; |
| 84 |
}; |