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

(-)a/t/db_dependent/Koha/ILL/Backends.t (-3 / +66 lines)
Lines 22-28 use File::Basename; Link Here
22
use File::Path qw(make_path remove_tree);
22
use File::Path qw(make_path remove_tree);
23
use Test::MockModule;
23
use Test::MockModule;
24
24
25
use Test::More tests => 4;
25
use Test::More tests => 5;
26
26
27
use Koha::ILL::Backends;
27
use Koha::ILL::Backends;
28
28
Lines 54-61 subtest 'installed_backends() tests' => sub { Link Here
54
    $schema->storage->txn_begin;
54
    $schema->storage->txn_begin;
55
55
56
    # Install a plugin_backend
56
    # Install a plugin_backend
57
    my $plugins = Koha::Plugins->new;
57
    _install_plugin_backend();
58
    $plugins->InstallPlugins;
59
    is_deeply(
58
    is_deeply(
60
        Koha::ILL::Backends->installed_backends, ['Test Plugin'],
59
        Koha::ILL::Backends->installed_backends, ['Test Plugin'],
61
        'Only one backend installed, happens to be a plugin'
60
        'Only one backend installed, happens to be a plugin'
Lines 82-84 subtest 'installed_backends() tests' => sub { Link Here
82
    Koha::Plugins::Methods->delete;
81
    Koha::Plugins::Methods->delete;
83
    $schema->storage->txn_rollback;
82
    $schema->storage->txn_rollback;
84
};
83
};
84
85
subtest 'opac_available_backends() tests' => sub {
86
87
    plan tests => 6;
88
89
    $schema->storage->txn_begin;
90
91
    my $logged_in_user = $builder->build_object(
92
        {
93
            class => 'Koha::Patrons'
94
        }
95
    );
96
    _install_plugin_backend();
97
98
    # ILLOpacUnauthenticatedRequest = 0
99
    t::lib::Mocks::mock_preference( 'ILLOpacUnauthenticatedRequest', 0 );
100
101
    t::lib::Mocks::mock_preference( 'ILLOpacbackends', '' );
102
    is_deeply(
103
        Koha::ILL::Backends->opac_available_backends($logged_in_user), [ 'Test Plugin', 'Standard' ],
104
        'Two backends are available for OPAC, one plugin and the core Standard backend'
105
    );
106
107
    t::lib::Mocks::mock_preference( 'ILLOpacbackends', 'gibberish' );
108
    is_deeply(
109
        Koha::ILL::Backends->opac_available_backends($logged_in_user), [],
110
        'ILLOpacbackends contains a non-existing backend'
111
    );
112
113
    t::lib::Mocks::mock_preference( 'ILLOpacbackends', 'Standard' );
114
    is_deeply(
115
        Koha::ILL::Backends->opac_available_backends($logged_in_user), ['Standard'],
116
        'ILLOpacbackends contains Standard. Only the Standard backend should be returned'
117
    );
118
119
    t::lib::Mocks::mock_preference( 'ILLOpacbackends', 'Standard|Test Plugin' );
120
    is_deeply(
121
        Koha::ILL::Backends->opac_available_backends($logged_in_user), [ 'Test Plugin', 'Standard' ],
122
        'ILLOpacbackends contains both. Both backends should be returned'
123
    );
124
125
    # ILLOpacUnauthenticatedRequest = 1
126
    t::lib::Mocks::mock_preference( 'ILLOpacUnauthenticatedRequest', 1 );
127
    t::lib::Mocks::mock_preference( 'ILLOpacbackends', '' );
128
    is_deeply(
129
        Koha::ILL::Backends->opac_available_backends(undef), [ 'Standard' ],
130
        'Only the standard backend is available for OPAC, the installed plugin does not support unauthenticated requests'
131
    );
132
133
    t::lib::Mocks::mock_preference( 'ILLOpacbackends', 'Test Plugin' );
134
    is_deeply(
135
        Koha::ILL::Backends->opac_available_backends(undef), [],
136
        'The only backend for the OPAC is Test Plugin but it does not support unauthenticated requests'
137
    );
138
139
    Koha::Plugins::Methods->delete;
140
    $schema->storage->txn_rollback;
141
};
142
143
144
sub _install_plugin_backend {
145
    my $plugins = Koha::Plugins->new;
146
    $plugins->InstallPlugins;
147
}
(-)a/t/db_dependent/selenium/opac_ill_requests.t (+119 lines)
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
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
use Test::More tests => 1;
20
21
use C4::Biblio qw(DelBiblio);
22
23
use C4::Context;
24
use Koha::AuthUtils;
25
use t::lib::Mocks;
26
use t::lib::Selenium;
27
use t::lib::TestBuilder;
28
29
our $builder = t::lib::TestBuilder->new;
30
our $ILLOpacUnauthenticatedRequest_value = C4::Context->preference('ILLOpacUnauthenticatedRequest');
31
our $ILLModule_value = C4::Context->preference('ILLModule');
32
33
SKIP: {
34
    eval { require Selenium::Remote::Driver; };
35
    skip "Selenium::Remote::Driver is needed for selenium tests.", 3 if $@;
36
37
    our $s      = t::lib::Selenium->new;
38
    our $driver = $s->driver;
39
40
    subtest 'unauthenticated ill request' => sub {
41
        plan tests => 2;
42
43
        subtest 'ILLOpacUnauthenticatedRequest enabled' => sub {
44
            plan tests => 4;
45
46
            C4::Context->set_preference( 'ILLOpacUnauthenticatedRequest', 1 );
47
            C4::Context->set_preference( 'ILLModule', 1 );
48
49
            $driver->get( $s->opac_base_url . "opac-search.pl?q=music" );
50
51
            like(
52
                $driver->get_title, qr(Results of search for 'music'),
53
                'Correctly in search results page'
54
            );
55
56
            is(
57
                $driver->find_element('//div[@class="suggestion"]/ul/li')->get_text,
58
                'Make an Interlibrary loan request',
59
                'Placing an ILL request through the OPAC is allowed',
60
            );
61
62
            # Clicking on the search results page link works
63
            $driver->find_element('//div[@class="suggestion"]/ul/li/a')->click;
64
            is(
65
                $driver->find_element('(//nav[@id="breadcrumbs"]/ol/li)[last()]')->get_text,
66
                'New interlibrary loan request',
67
                'Correctly on the create new request OPAC page'
68
            );
69
70
            # Visiting the create request page directly works
71
            $driver->get( $s->opac_base_url . "opac-illrequests.pl?op=create" );
72
            is(
73
                $driver->find_element('(//nav[@id="breadcrumbs"]/ol/li)[last()]')->get_text,
74
                'New interlibrary loan request',
75
                'Correctly on the create new request OPAC page'
76
            );
77
78
        };
79
80
        subtest 'ILLOpacUnauthenticatedRequest disabled' => sub {
81
            plan tests => 3;
82
83
            C4::Context->set_preference( 'ILLOpacUnauthenticatedRequest', 0 );
84
            C4::Context->set_preference( 'ILLModule', 1 );
85
86
            $driver->get( $s->opac_base_url . "opac-search.pl?q=music" );
87
88
            like(
89
                $driver->get_title, qr(Results of search for 'music'),
90
                'Correctly in search results page'
91
            );
92
93
            my $link_exists =
94
                $driver->find_elements( '//div[@class="suggestion"]/ul/li' );
95
96
            is(
97
                scalar @{$link_exists},
98
                0,
99
                'Search page - Place ILL request link should be absent. '
100
            );
101
102
            # Visiting the create request page directly does not work
103
            $driver->get( $s->opac_base_url . "opac-illrequests.pl?op=create" );
104
            is(
105
                $driver->find_element('(//nav[@id="breadcrumbs"]/ol/li)[last()]')->get_text,
106
                'Log in to your account',
107
                'Correctly on the log in page'
108
            );
109
110
        };
111
    };
112
113
    $driver->quit();
114
}
115
116
END {
117
    C4::Context->set_preference( 'ILLOpacUnauthenticatedRequest', $ILLOpacUnauthenticatedRequest_value );
118
    C4::Context->set_preference( 'ILLModule', $ILLModule_value );
119
}
(-)a/t/lib/plugins/Koha/Plugin/ILL/TestPlugin.pm (+53 lines)
Line 0 Link Here
1
package Koha::Plugin::ILL::TestPlugin;
2
3
use Modern::Perl;
4
5
use base            qw(Koha::Plugins::Base);
6
use Koha::DateUtils qw( dt_from_string );
7
8
use File::Basename qw( dirname );
9
use C4::Installer;
10
use Cwd            qw(abs_path);
11
use CGI;
12
use JSON qw( encode_json decode_json );
13
14
use JSON           qw( to_json from_json );
15
use File::Basename qw( dirname );
16
17
use Koha::Libraries;
18
use Koha::Patrons;
19
20
our $VERSION = "2.0.4";
21
22
our $metadata = {
23
    name            => 'TestPlugin',
24
    author          => 'PTFS-Europe',
25
    date_authored   => '2023-10-30',
26
    date_updated    => '2024-03-28',
27
    minimum_version => '24.05.00.000',
28
    maximum_version => undef,
29
    version         => $VERSION,
30
    description     => 'This plugin is an ILL backend plugin example'
31
};
32
33
sub new {
34
    my ( $self, $params ) = @_;
35
36
    my $backend = {
37
        _logger => $params->{logger},
38
        _config => $params->{config},
39
        _plugin => $self,
40
    };
41
42
    bless $backend, $self;
43
    return $backend;
44
}
45
46
sub capabilities {
47
    my ( $self, $name ) = @_;
48
    my $capabilities = {
49
        opac_unauthenticated_ill_requests => sub { return 0; }
50
    };
51
52
    return $capabilities->{$name};
53
}
(-)a/t/lib/plugins/Koha/Plugin/Test.pm (-1 / +7 lines)
Lines 431-436 sub ill_backend { Link Here
431
    return 'Test Plugin';
431
    return 'Test Plugin';
432
}
432
}
433
433
434
sub new_ill_backend {
435
    my ( $self, $params ) = @_;
436
437
    require Koha::Plugin::ILL::TestPlugin;
438
    return Koha::Plugin::ILL::TestPlugin->new($params);
439
}
440
434
sub auth_client_get_user {
441
sub auth_client_get_user {
435
    my ( $self, $params ) = @_;
442
    my ( $self, $params ) = @_;
436
443
437
- 

Return to bug 36197