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

(-)a/t/db_dependent/Illrequest/Availability.t (-7 / +70 lines)
Lines 17-27 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Koha::Illrequest::Availability;
20
use Test::More tests => 5;
21
21
22
use Test::More tests => 3;
22
use Test::MockModule;
23
use Test::MockObject;
23
24
24
use_ok('Koha::Illrequest::Availability');
25
use t::lib::TestBuilder;
26
use t::lib::Mocks;
27
28
use Koha::Illrequest::Workflow::Availability;
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::Illrequest::Workflow::Availability');
25
37
26
my $metadata = {
38
my $metadata = {
27
    title  => 'This is a title',
39
    title  => 'This is a title',
Lines 31-46 my $metadata = { Link Here
31
# Because hashes can reorder themselves, we need to make sure ours is in a
43
# Because hashes can reorder themselves, we need to make sure ours is in a
32
# predictable order
44
# predictable order
33
my $sorted = {};
45
my $sorted = {};
34
foreach my $key( keys %{$metadata} ) {
46
foreach my $key ( keys %{$metadata} ) {
35
    $sorted->{$key} = $metadata->{$key};
47
    $sorted->{$key} = $metadata->{$key};
36
}
48
}
37
49
38
my $availability = Koha::Illrequest::Availability->new($sorted);
50
my $availability =
51
  Koha::Illrequest::Workflow::Availability->new( $sorted, 'staff' );
39
52
40
isa_ok( $availability, 'Koha::Illrequest::Availability' );
53
isa_ok( $availability, 'Koha::Illrequest::Workflow::Availability' );
41
54
42
is(
55
is(
43
    $availability->prep_metadata($sorted),
56
    $availability->prep_metadata($sorted),
44
    'eyJhdXRob3IiOiJUaGlzIGlzIGFuIGF1dGhvciIsInRpdGxlIjoiVGhpcyBpcyBhIHRpdGxlIn0%3D%0A',
57
'eyJhdXRob3IiOiJUaGlzIGlzIGFuIGF1dGhvciIsInRpdGxlIjoiVGhpcyBpcyBhIHRpdGxlIn0%3D%0A',
45
    'prep_metadata works'
58
    'prep_metadata works'
46
);
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::Illrequest::load_backend (to load Mocked Backend)
79
my $illreqmodule = Test::MockModule->new('Koha::Illrequest');
80
$illreqmodule->mock( 'load_backend',
81
    sub { my $self = shift; $self->{_my_backend} = $backend; return $self } );
82
83
# Mock ILLModuleDisclaimerByType with valid YAML
84
t::lib::Mocks::mock_preference( 'ILLCheckAvailability', 1 );
85
86
# Mock not empty availability services
87
my $availability_module =
88
  Test::MockModule->new('Koha::Illrequest::Workflow::Availability');
89
$availability_module->mock( 'get_services', [ { name => 'service' } ] );
90
91
my $req_1 = $builder->build_object(
92
    {
93
        class => 'Koha::Illrequests',
94
        value => {}
95
    }
96
);
97
98
my $request = $req_1->load_backend('Mock');
99
100
is( $availability->show_availability($request),
101
    1, 'able to show availability search' );
102
103
# Mock empty availability services
104
$availability_module->mock( 'get_services', [] );
105
106
is( $availability->show_availability($request),
107
    0, 'unable to show type disclaimer form' );
108
109
$schema->storage->txn_rollback;
(-)a/t/db_dependent/Illrequest/TypeDisclaimer.t (-1 / +117 lines)
Line 0 Link Here
0
- 
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::Illrequest::Workflow::TypeDisclaimer;
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::Illrequest::Workflow::TypeDisclaimer');
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 $type_disclaimer =
51
  Koha::Illrequest::Workflow::TypeDisclaimer->new( $sorted, 'staff' );
52
53
isa_ok( $type_disclaimer, 'Koha::Illrequest::Workflow::TypeDisclaimer' );
54
55
is(
56
    $type_disclaimer->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::Illrequest::load_backend (to load Mocked Backend)
79
my $illreqmodule = Test::MockModule->new('Koha::Illrequest');
80
$illreqmodule->mock( 'load_backend',
81
    sub { my $self = shift; $self->{_my_backend} = $backend; return $self } );
82
83
# Mock ILLModuleDisclaimerByType with valid YAML
84
t::lib::Mocks::mock_preference(
85
    'ILLModuleDisclaimerByType', "all:
86
 text: |
87
  <h2>HTML title</h2>
88
  <p>This is an HTML paragraph</p>
89
  <p>This is another HTML paragraph</p>
90
 av_category_code: YES_NO
91
article:
92
 text: copyright text for all article type requests
93
 av_category_code: YES_NO
94
 bypass: 1"
95
);
96
97
my $req_1 = $builder->build_object(
98
    {
99
        class => 'Koha::Illrequests',
100
        value => {}
101
    }
102
);
103
104
my $request = $req_1->load_backend('Mock');
105
106
is( $type_disclaimer->show_type_disclaimer($request),
107
    1, 'able to show type disclaimer form' );
108
109
# Mock ILLModuleDisclaimerByType with invalid YAML
110
my $type_disclaimer_module =
111
  Test::MockModule->new('Koha::Illrequest::Workflow::TypeDisclaimer');
112
$type_disclaimer_module->mock( '_get_type_disclaimer_sys_pref', {} );
113
114
is( $type_disclaimer->show_type_disclaimer($request),
115
    0, 'not able to show type disclaimer form' );
116
117
$schema->storage->txn_rollback;

Return to bug 33716