View | Details | Raw Unified | Return to bug 35604
Collapse All | Expand All

(-)a/Koha/ILL/Backends.pm (-74 lines)
Lines 1-74 Link Here
1
package Koha::ILL::Backends;
2
3
# Copyright PTFS Europe 2023
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
22
use base qw(Koha::Objects);
23
24
=head1 NAME
25
26
Koha::ILL::Backends - Koha Illbackends Object class
27
28
=head2 Class methods
29
30
=head3 new
31
32
New ILL Backend
33
34
=cut
35
36
sub new {
37
    my $class = shift;
38
    my $self  = {};
39
    return bless $self, $class;
40
}
41
42
=head3 installed_backends
43
44
Return a list of installed backends.
45
46
=cut
47
48
sub installed_backends {
49
    my $backends  = Koha::ILL::Request::Config->new->available_backends;
50
    my @installed = grep { !/Standard/ } @{$backends};
51
    return \@installed;
52
}
53
54
=head2 Internal methods
55
56
=head3 _type
57
58
    my $type = Koha::ILL::Backend->_type;
59
60
Return this object's type
61
62
=cut
63
64
sub _type {
65
    return 'Illbackend';
66
}
67
68
=head1 AUTHOR
69
70
Pedro Amorim <pedro.amorim@ptfs-europe.com>
71
72
=cut
73
74
1;
(-)a/Koha/ILL/Request/Config.pm (+13 lines)
Lines 158-163 sub available_backends { Link Here
158
    return \@all_uniq_backends;
158
    return \@all_uniq_backends;
159
}
159
}
160
160
161
=head3 installed_backends
162
163
    my $installed_backends = $config->installed_backends();
164
165
Returns a list of installed backends.
166
167
=cut
168
169
sub installed_backends {
170
    my ($self) = @_;
171
    return [ grep { !/Standard/ } @{ $self->available_backends } ];
172
}
173
161
=head3 has_branch
174
=head3 has_branch
162
175
163
Return whether a 'branch' block is defined
176
Return whether a 'branch' block is defined
(-)a/Koha/ILL/Request/Workflow/ConfirmAuto.pm (-1 lines)
Lines 22-28 use Modern::Perl; Link Here
22
use base qw(Koha::ILL::Request::Workflow);
22
use base qw(Koha::ILL::Request::Workflow);
23
23
24
use JSON qw( encode_json );
24
use JSON qw( encode_json );
25
use Koha::ILL::Backends;
26
25
27
=head1 NAME
26
=head1 NAME
28
27
(-)a/admin/preferences.pl (-2 / +2 lines)
Lines 29-35 use C4::Output qw( output_html_with_http_headers output_and_exit_if_error ) Link Here
29
use C4::Templates;
29
use C4::Templates;
30
use Koha::Acquisition::Currencies;
30
use Koha::Acquisition::Currencies;
31
use Koha::Database::Columns;
31
use Koha::Database::Columns;
32
use Koha::ILL::Backends;
32
use Koha::ILL::Request::Config;
33
use IO::File;
33
use IO::File;
34
use YAML::XS;
34
use YAML::XS;
35
use Encode;
35
use Encode;
Lines 85-91 sub _get_chunk { Link Here
85
        my @priority_enabled_backends = split ",", C4::Context->preference('AutoILLBackendPriority');
85
        my @priority_enabled_backends = split ",", C4::Context->preference('AutoILLBackendPriority');
86
        my @sys_pref_backends         = map( { name => $_, enabled => 1 }, @priority_enabled_backends );
86
        my @sys_pref_backends         = map( { name => $_, enabled => 1 }, @priority_enabled_backends );
87
87
88
        my $installed_backends = Koha::ILL::Backends->installed_backends;
88
        my $installed_backends = Koha::ILL::Request::Config->new->installed_backends;
89
        foreach my $installed_backend ( @{$installed_backends} ) {
89
        foreach my $installed_backend ( @{$installed_backends} ) {
90
            if ( not grep { $installed_backend eq $_->{name} } @sys_pref_backends ) {
90
            if ( not grep { $installed_backend eq $_->{name} } @sys_pref_backends ) {
91
                my $backend = Koha::ILL::Request->new->load_backend($installed_backend);
91
                my $backend = Koha::ILL::Request->new->load_backend($installed_backend);
(-)a/t/db_dependent/Koha/ILL/Backends.t (-84 lines)
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
};
(-)a/t/db_dependent/Koha/ILL/Request/Config.t (-3 / +56 lines)
Lines 17-22 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use File::Basename;
21
use File::Path qw(make_path remove_tree);
22
20
use Koha::Database;
23
use Koha::Database;
21
use t::lib::Mocks;
24
use t::lib::Mocks;
22
use t::lib::TestBuilder;
25
use t::lib::TestBuilder;
Lines 24-34 use Test::MockObject; Link Here
24
use Test::Exception;
27
use Test::Exception;
25
28
26
use Test::NoWarnings;
29
use Test::NoWarnings;
27
use Test::More tests => 7;
30
use Test::More tests => 11;
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::ILL::Request::Config');
38
    use_ok('Koha::Plugins');
39
    use_ok('Koha::Plugins::Handler');
40
    use_ok('Koha::Plugin::Test');
41
}
28
42
29
my $schema  = Koha::Database->new->schema;
43
my $schema  = Koha::Database->new->schema;
30
my $builder = t::lib::TestBuilder->new;
44
my $builder = t::lib::TestBuilder->new;
31
use_ok('Koha::ILL::Request::Config');
45
46
t::lib::Mocks::mock_config( 'enable_plugins', 1 );
47
48
subtest 'installed_backends() tests' => sub {
49
50
    # dir backend    = An ILL backend installed through backend_directory in koha-conf.xml
51
    # plugin backend = An ILL backend installed through a plugin
52
53
    plan tests => 2;
54
55
    $schema->storage->txn_begin;
56
57
    # Install a plugin_backend
58
    my $plugins = Koha::Plugins->new;
59
    $plugins->InstallPlugins;
60
    is_deeply(
61
        Koha::ILL::Request::Config->new->installed_backends, ['Test Plugin'],
62
        'Only one backend installed, happens to be a plugin'
63
    );
64
65
    # Install a dir backend
66
    my $dir_backend = '/tmp/ill_backend_test/Old_Backend';
67
    my $ill_config  = Test::MockModule->new('Koha::ILL::Request::Config');
68
    $ill_config->mock(
69
        'backend_dir',
70
        sub {
71
            return '/tmp/ill_backend_test';
72
        }
73
    );
74
    make_path($dir_backend);
75
    my $installed_backends = Koha::ILL::Request::Config->installed_backends;
76
    is_deeply(
77
        $installed_backends, [ 'Old_Backend', 'Test Plugin' ],
78
        'Two backends are installed, one plugin and one directory backend'
79
    );
80
81
    #cleanup
82
    remove_tree($dir_backend);
83
    Koha::Plugins::Methods->delete;
84
    $schema->storage->txn_rollback;
85
};
32
86
33
my $base_limits = {
87
my $base_limits = {
34
    branch  => { CPL   => { count => 1,  method => 'annual' } },
88
    branch  => { CPL   => { count => 1,  method => 'annual' } },
35
- 

Return to bug 35604