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