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

(-)a/t/db_dependent/Koha/ILL/Request/Config.t (-1 / +56 lines)
Lines 27-33 use Test::MockObject; Link Here
27
use Test::Exception;
27
use Test::Exception;
28
28
29
use Test::NoWarnings;
29
use Test::NoWarnings;
30
use Test::More tests => 11;
30
use Test::More tests => 12;
31
31
32
BEGIN {
32
BEGIN {
33
    # Mock pluginsdir before loading Plugins module
33
    # Mock pluginsdir before loading Plugins module
Lines 84-89 subtest 'installed_backends() tests' => sub { Link Here
84
    $schema->storage->txn_rollback;
84
    $schema->storage->txn_rollback;
85
};
85
};
86
86
87
subtest 'opac_available_backends() tests' => sub {
88
89
    plan tests => 6;
90
91
    $schema->storage->txn_begin;
92
93
    my $logged_in_user = $builder->build_object( { class => 'Koha::Patrons' } );
94
    my $plugins        = Koha::Plugins->new;
95
    $plugins->InstallPlugins;
96
97
    # ILLOpacUnauthenticatedRequest = 0
98
    t::lib::Mocks::mock_preference( 'ILLOpacUnauthenticatedRequest', 0 );
99
100
    t::lib::Mocks::mock_preference( 'ILLOpacbackends', '' );
101
    is_deeply(
102
        Koha::ILL::Request::Config->new->opac_available_backends($logged_in_user), [ 'Test Plugin', 'Standard' ],
103
        'Two backends are available for OPAC, one plugin and the core Standard backend'
104
    );
105
106
    t::lib::Mocks::mock_preference( 'ILLOpacbackends', 'gibberish' );
107
    is_deeply(
108
        Koha::ILL::Request::Config->new->opac_available_backends($logged_in_user), [],
109
        'ILLOpacbackends contains a non-existing backend'
110
    );
111
112
    t::lib::Mocks::mock_preference( 'ILLOpacbackends', 'Standard' );
113
    is_deeply(
114
        Koha::ILL::Request::Config->new->opac_available_backends($logged_in_user), ['Standard'],
115
        'ILLOpacbackends contains Standard. Only the Standard backend should be returned'
116
    );
117
118
    t::lib::Mocks::mock_preference( 'ILLOpacbackends', 'Standard|Test Plugin' );
119
    is_deeply(
120
        Koha::ILL::Request::Config->new->opac_available_backends($logged_in_user), [ 'Test Plugin', 'Standard' ],
121
        'ILLOpacbackends contains both. Both backends should be returned'
122
    );
123
124
    # ILLOpacUnauthenticatedRequest = 1
125
    t::lib::Mocks::mock_preference( 'ILLOpacUnauthenticatedRequest', 1 );
126
    t::lib::Mocks::mock_preference( 'ILLOpacbackends',               '' );
127
    is_deeply(
128
        Koha::ILL::Request::Config->new->opac_available_backends(undef), ['Standard'],
129
        'Only the standard backend is available for OPAC, the installed plugin does not support unauthenticated requests'
130
    );
131
132
    t::lib::Mocks::mock_preference( 'ILLOpacbackends', 'Test Plugin' );
133
    is_deeply(
134
        Koha::ILL::Request::Config->new->opac_available_backends(undef), [],
135
        'The only backend for the OPAC is Test Plugin but it does not support unauthenticated requests'
136
    );
137
138
    Koha::Plugins::Methods->delete;
139
    $schema->storage->txn_rollback;
140
};
141
87
my $base_limits = {
142
my $base_limits = {
88
    branch  => { CPL   => { count => 1,  method => 'annual' } },
143
    branch  => { CPL   => { count => 1,  method => 'annual' } },
89
    brw_cat => { A     => { count => -1, method => 'active' } },
144
    brw_cat => { A     => { count => -1, method => 'active' } },
(-)a/t/db_dependent/selenium/opac_ill_requests.t (+118 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 = $driver->find_elements('//div[@class="suggestion"]/ul/li');
94
95
            is(
96
                scalar @{$link_exists},
97
                0,
98
                'Search page - Place ILL request link should be absent. '
99
            );
100
101
            # Visiting the create request page directly does not work
102
            $driver->get( $s->opac_base_url . "opac-illrequests.pl?op=create" );
103
            is(
104
                $driver->find_element('(//nav[@id="breadcrumbs"]/ol/li)[last()]')->get_text,
105
                'Log in to your account',
106
                'Correctly on the log in page'
107
            );
108
109
        };
110
    };
111
112
    $driver->quit();
113
}
114
115
END {
116
    C4::Context->set_preference( 'ILLOpacUnauthenticatedRequest', $ILLOpacUnauthenticatedRequest_value );
117
    C4::Context->set_preference( 'ILLModule',                     $ILLModule_value );
118
}
(-)a/t/lib/plugins/Koha/Plugin/ILL/TestPlugin.pm (+72 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
=head1 METHODS
34
35
=head2 new
36
37
    Constructor
38
39
=cut
40
41
sub new {
42
    my ( $self, $params ) = @_;
43
44
    my $backend = {
45
        _logger => $params->{logger},
46
        _config => $params->{config},
47
        _plugin => $self,
48
    };
49
50
    bless $backend, $self;
51
    return $backend;
52
}
53
54
=head2 capabilities
55
56
    Returns a subroutine reference for the given capability name.
57
    Returns undef if the capability is not implemented.
58
59
    $name - The name of the capability to retrieve.
60
61
=cut
62
63
sub capabilities {
64
    my ( $self, $name ) = @_;
65
    my $capabilities = {
66
        opac_unauthenticated_ill_requests => sub { return 0; }
67
    };
68
69
    return $capabilities->{$name};
70
}
71
72
1;
(-)a/t/lib/plugins/Koha/Plugin/Test.pm (-1 / +7 lines)
Lines 425-430 sub ill_backend { Link Here
425
    return 'Test Plugin';
425
    return 'Test Plugin';
426
}
426
}
427
427
428
sub new_ill_backend {
429
    my ( $self, $params ) = @_;
430
431
    require Koha::Plugin::ILL::TestPlugin;
432
    return Koha::Plugin::ILL::TestPlugin->new($params);
433
}
434
428
sub auth_client_get_user {
435
sub auth_client_get_user {
429
    my ( $self, $params ) = @_;
436
    my ( $self, $params ) = @_;
430
437
431
- 

Return to bug 36197