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

(-)a/t/db_dependent/Illrequest/ConfirmAuto.t (+104 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
20
use Test::More tests => 5;
21
22
use Test::MockModule;
23
use Test::MockObject;
24
25
use t::lib::TestBuilder;
26
use t::lib::Mocks;
27
28
use Koha::ILL::Request::Workflow::ConfirmAuto;
29
use Koha::Database;
30
31
my $schema = Koha::Database->new->schema;
32
$schema->storage->txn_begin;
33
34
my $builder = t::lib::TestBuilder->new;
35
36
use_ok('Koha::ILL::Request::Workflow::ConfirmAuto');
37
38
my $metadata = {
39
    title  => 'This is a title',
40
    author => 'This is an author'
41
};
42
43
# Because hashes can reorder themselves, we need to make sure ours is in a
44
# predictable order
45
my $sorted = {};
46
foreach my $key ( keys %{$metadata} ) {
47
    $sorted->{$key} = $metadata->{$key};
48
}
49
50
my $confirm_auto =
51
  Koha::ILL::Request::Workflow::ConfirmAuto->new( $sorted, 'staff' );
52
53
isa_ok( $confirm_auto, 'Koha::ILL::Request::Workflow::ConfirmAuto' );
54
55
is(
56
    $confirm_auto->prep_metadata($sorted),
57
'eyJhdXRob3IiOiJUaGlzIGlzIGFuIGF1dGhvciIsInRpdGxlIjoiVGhpcyBpcyBhIHRpdGxlIn0%3D%0A',
58
    'prep_metadata works'
59
);
60
61
# Mock ILLBackend (as object)
62
my $backend = Test::MockObject->new;
63
$backend->set_isa('Koha::Illbackends::Mock');
64
$backend->set_always( 'name',         'Mock' );
65
$backend->set_always( 'capabilities', sub { return can_create_request => 1 } );
66
$backend->mock(
67
    'metadata',
68
    sub {
69
        my ( $self, $rq ) = @_;
70
        return {
71
            ID    => $rq->illrequest_id,
72
            Title => $rq->patron->borrowernumber
73
        };
74
    }
75
);
76
$backend->mock( 'status_graph', sub { }, );
77
78
# Mock Koha::ILL::Request::load_backend (to load Mocked Backend)
79
my $illreqmodule = Test::MockModule->new('Koha::ILL::Request');
80
$illreqmodule->mock( 'load_backend',
81
    sub { my $self = shift; $self->{_my_backend} = $backend; return $self } );
82
83
# Mock AutoILLBackendPriority enabled
84
t::lib::Mocks::mock_preference( 'AutoILLBackendPriority', 'PluginBackend' );
85
86
my $req_1 = $builder->build_object(
87
    {
88
        class => 'Koha::ILL::Requests',
89
        value => {}
90
    }
91
);
92
93
my $request = $req_1->load_backend('Mock');
94
95
is( $confirm_auto->show_confirm_auto($request),
96
    1, 'able to show confirm auto screen' );
97
98
# Mock AutoILLBackendPriority disabled
99
t::lib::Mocks::mock_preference( 'AutoILLBackendPriority', '' );
100
101
is( $confirm_auto->show_confirm_auto($request),
102
    '', 'not able to show confirm auto screen' );
103
104
$schema->storage->txn_rollback;
(-)a/t/db_dependent/Koha/ILL/Backends.t (+84 lines)
Line 0 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/lib/plugins/Koha/Plugin/Test.pm (-1 / +5 lines)
Lines 410-415 sub ill_table_actions { Link Here
410
    );
410
    );
411
}
411
}
412
412
413
sub ill_backend {
414
    my ( $class, $args ) = @_;
415
    return 'Test Plugin';
416
}
417
413
sub _private_sub {
418
sub _private_sub {
414
    return "";
419
    return "";
415
}
420
}
416
- 

Return to bug 35604