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; |