Bug 16453: Make Elasticsearch tests be skipped if configuration entry missing
[koha.git] / t / Biblio.t
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;
21 use Test::MockModule;
22 use Test::Warn;
23
24 use Module::Load::Conditional qw/check_install/;
25
26 BEGIN {
27     if ( check_install( module => 'Test::DBIx::Class' ) ) {
28         plan tests => 46;
29     } else {
30         plan skip_all => "Need Test::DBIx::Class"
31     }
32 }
33
34 use_ok('C4::Biblio');
35
36 use Test::DBIx::Class {
37     schema_class => 'Koha::Schema',
38     connect_info => ['dbi:SQLite:dbname=:memory:','',''],
39     connect_opts => { name_sep => '.', quote_char => '`', },
40     fixture_class => '::Populate',
41 }, 'Biblio' ;
42
43 sub fixtures {
44     my ( $data ) = @_;
45     fixtures_ok [
46         Biblio => [
47             [ qw/ biblionumber datecreated timestamp  / ],
48             @$data,
49         ],
50     ], 'add fixtures';
51 }
52
53 my $db = Test::MockModule->new('Koha::Database');
54 $db->mock( _new_schema => sub { return Schema(); } );
55
56 my @arr;
57 my $ret;
58
59 warning_is { @arr = AddBiblio(undef, q{}) }
60            { carped => 'AddBiblio called with undefined record'},
61            "AddBiblio returns carped warning on undef record";
62
63 my $elements = @arr;
64
65 is($elements, 0, 'Add Biblio returns empty array for undef record');
66
67 warning_is { $ret = ModBiblio(undef, 0, '') }
68            { carped => 'No record passed to ModBiblio'},
69            "ModBiblio returns carped warning on undef record";
70
71 is( $ret, 0, 'ModBiblio returns zero if not passed rec');
72
73 warning_is { $ret = BiblioAutoLink(undef, q{}) }
74            { carped => 'Undefined record passed to BiblioAutoLink'},
75            "BiblioAutoLink returns carped warning on undef record";
76
77 is( $ret, 0, 'BiblioAutoLink returns zero if not passed rec');
78
79 warning_is { $ret = GetRecordValue('100', undef, q{}) }
80            { carped => 'GetRecordValue called with undefined record'},
81            "GetRecordValue returns carped warning on undef record";
82
83 ok( !defined $ret, 'GetRecordValue returns undef if not passed rec');
84
85 warning_is { @arr = LinkBibHeadingsToAuthorities(q{}, q{}) }
86            { carped => 'LinkBibHeadingsToAuthorities called on undefined bib record'},
87            "LinkBibHeadingsToAuthorities returns carped warning on undef record";
88
89 is($arr[0], 0, 'LinkBibHeadingsToAuthorities correct error return');
90
91 warning_is { $ret = GetCOinSBiblio() }
92            { carped => 'GetCOinSBiblio called with undefined record'},
93            "GetCOinSBiblio returns carped warning on undef record";
94
95 ok( !defined $ret, 'GetCOinSBiblio returns undef if not passed rec');
96
97 warning_is { $ret = GetMarcPrice(undef, 'MARC21') }
98            { carped => 'GetMarcPrice called on undefined record'},
99            "GetMarcPrice returns carped warning on undef record";
100
101 ok( !defined $ret, 'GetMarcPrice returns undef if not passed rec');
102
103 warning_is { $ret = GetMarcQuantity(undef, 'MARC21') }
104            { carped => 'GetMarcQuantity called on undefined record'},
105            "GetMarcQuantity returns carped warning on undef record";
106
107 ok( !defined $ret, 'GetMarcQuantity returns undef if not passed rec');
108
109 warning_is { $ret = GetMarcControlnumber() }
110            { carped => 'GetMarcControlnumber called on undefined record'},
111            "GetMarcControlnumber returns carped warning on undef record";
112
113 ok( !defined $ret, 'GetMarcControlnumber returns undef if not passed rec');
114
115 warning_is { $ret = GetMarcISBN() }
116            { carped => 'GetMarcISBN called on undefined record'},
117            "GetMarcISBN returns carped warning on undef record";
118
119 ok( !defined $ret, 'GetMarcISBN returns undef if not passed rec');
120
121 warning_is { $ret = GetMarcISSN() }
122            { carped => 'GetMarcISSN called on undefined record'},
123            "GetMarcISSN returns carped warning on undef record";
124
125 ok( !defined $ret, 'GetMarcISSN returns undef if not passed rec');
126
127 warning_is { $ret = GetMarcNotes() }
128            { carped => 'GetMarcNotes called on undefined record'},
129            "GetMarcNotes returns carped warning on undef record";
130
131 ok( !defined $ret, 'GetMarcNotes returns undef if not passed rec');
132
133 warning_is { $ret = GetMarcSubjects() }
134            { carped => 'GetMarcSubjects called on undefined record'},
135            "GetMarcSubjects returns carped warning on undef record";
136
137 ok( !defined $ret, 'GetMarcSubjects returns undef if not passed rec');
138
139 warning_is { $ret = GetMarcAuthors() }
140            { carped => 'GetMarcAuthors called on undefined record'},
141            "GetMarcAuthors returns carped warning on undef record";
142
143 ok( !defined $ret, 'GetMarcAuthors returns undef if not passed rec');
144
145 warning_is { $ret = GetMarcUrls() }
146            { carped => 'GetMarcUrls called on undefined record'},
147            "GetMarcUrls returns carped warning on undef record";
148
149 ok( !defined $ret, 'GetMarcUrls returns undef if not passed rec');
150
151 warning_is { $ret = GetMarcSeries() }
152            { carped => 'GetMarcSeries called on undefined record'},
153            "GetMarcSeries returns carped warning on undef record";
154
155 ok( !defined $ret, 'GetMarcSeries returns undef if not passed rec');
156
157 warning_is { $ret = GetMarcHosts() }
158            { carped => 'GetMarcHosts called on undefined record'},
159            "GetMarcHosts returns carped warning on undef record";
160
161 ok( !defined $ret, 'GetMarcHosts returns undef if not passed rec');
162
163 my $hash_ref;
164
165 warning_is { $hash_ref = TransformMarcToKoha( undef) }
166            { carped => 'TransformMarcToKoha called with undefined record'},
167            "TransformMarcToKoha returns carped warning on undef record";
168
169 isa_ok( $hash_ref, 'HASH');
170
171 $elements = keys %{$hash_ref};
172
173 is($elements, 0, 'Empty hashref returned for undefined record in TransformMarcToKoha');
174
175 warning_is { $ret = ModBiblioMarc() }
176            { carped => 'ModBiblioMarc passed an undefined record'},
177            "ModBiblioMarc returns carped warning on undef record";
178
179 ok( !defined $ret, 'ModBiblioMarc returns undef if not passed rec');
180
181 warning_is { $ret = RemoveAllNsb() }
182            { carped => 'RemoveAllNsb called with undefined record'},
183            "RemoveAllNsb returns carped warning on undef record";
184
185 ok( !defined $ret, 'RemoveAllNsb returns undef if not passed rec');
186
187 warning_is { $ret = GetMarcBiblio() }
188            { carped => 'GetMarcBiblio called with undefined biblionumber'},
189            "GetMarcBiblio returns carped warning on undef biblionumber";
190
191 ok( !defined $ret, 'GetMarcBiblio returns undef if not passed a biblionumber');
192
193 warnings_like { $ret = UpdateTotalIssues() }
194               [ { carped => qr/GetMarcBiblio called with undefined biblionumber/ },
195                 { carped => qr/UpdateTotalIssues could not get biblio record/ } ],
196     "UpdateTotalIssues returns carped warnings if biblio record does not exist";
197
198 ok( !defined $ret, 'UpdateTotalIssues returns carped warning if biblio record does not exist');
199
200 1;