Bug 26265: (QA follow-up) Remove g option from regex, add few dirs
[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 plan tests => 47;
25
26 use_ok('C4::Biblio');
27
28 my $db = Test::MockModule->new('Koha::Database');
29 $db->mock( _new_schema => sub { return Schema(); } );
30
31 my @arr;
32 my $ret;
33
34 warning_is { @arr = AddBiblio(undef, q{}) }
35            { carped => 'AddBiblio called with undefined record'},
36            "AddBiblio returns carped warning on undef record";
37
38 my $elements = @arr;
39
40 is($elements, 0, 'Add Biblio returns empty array for undef record');
41
42 warning_is { $ret = ModBiblio(undef, 0, '') }
43            { carped => 'No record passed to ModBiblio'},
44            "ModBiblio returns carped warning on undef record";
45
46 is( $ret, 0, 'ModBiblio returns zero if not passed rec');
47
48 warning_is { $ret = BiblioAutoLink(undef, q{}) }
49            { carped => 'Undefined record passed to BiblioAutoLink'},
50            "BiblioAutoLink returns carped warning on undef record";
51
52 is( $ret, 0, 'BiblioAutoLink returns zero if not passed rec');
53
54 warning_is { $ret = GetRecordValue('100', undef, q{}) }
55            { carped => 'GetRecordValue called with undefined record'},
56            "GetRecordValue returns carped warning on undef record";
57
58 ok( !defined $ret, 'GetRecordValue returns undef if not passed rec');
59
60 warning_is { @arr = LinkBibHeadingsToAuthorities(q{}, q{}) }
61            { carped => 'LinkBibHeadingsToAuthorities called on undefined bib record'},
62            "LinkBibHeadingsToAuthorities returns carped warning on undef record";
63
64 is($arr[0], 0, 'LinkBibHeadingsToAuthorities correct error return');
65
66 warning_is { $ret = GetCOinSBiblio() }
67            { carped => 'GetCOinSBiblio called with undefined record'},
68            "GetCOinSBiblio returns carped warning on undef record";
69
70 ok( !defined $ret, 'GetCOinSBiblio returns undef if not passed rec');
71
72 warning_is { $ret = GetMarcPrice(undef, 'MARC21') }
73            { carped => 'GetMarcPrice called on undefined record'},
74            "GetMarcPrice returns carped warning on undef record";
75
76 ok( !defined $ret, 'GetMarcPrice returns undef if not passed rec');
77
78 warning_is { $ret = GetMarcQuantity(undef, 'MARC21') }
79            { carped => 'GetMarcQuantity called on undefined record'},
80            "GetMarcQuantity returns carped warning on undef record";
81
82 ok( !defined $ret, 'GetMarcQuantity returns undef if not passed rec');
83
84 warning_is { $ret = GetMarcControlnumber() }
85            { carped => 'GetMarcControlnumber called on undefined record'},
86            "GetMarcControlnumber returns carped warning on undef record";
87
88 ok( !defined $ret, 'GetMarcControlnumber returns undef if not passed rec');
89
90 warning_is { $ret = GetMarcISBN() }
91            { carped => 'GetMarcISBN called on undefined record'},
92            "GetMarcISBN returns carped warning on undef record";
93
94 ok( !defined $ret, 'GetMarcISBN returns undef if not passed rec');
95
96 warning_is { $ret = GetMarcISSN() }
97            { carped => 'GetMarcISSN called on undefined record'},
98            "GetMarcISSN returns carped warning on undef record";
99
100 ok( !defined $ret, 'GetMarcISSN returns undef if not passed rec');
101
102 warning_is { $ret = GetMarcNotes() }
103            { carped => 'GetMarcNotes called on undefined record'},
104            "GetMarcNotes returns carped warning on undef record";
105
106 ok( !defined $ret, 'GetMarcNotes returns undef if not passed rec');
107
108 warning_is { $ret = GetMarcSubjects() }
109            { carped => 'GetMarcSubjects called on undefined record'},
110            "GetMarcSubjects returns carped warning on undef record";
111
112 ok( !defined $ret, 'GetMarcSubjects returns undef if not passed rec');
113
114 warning_is { $ret = GetMarcAuthors() }
115            { carped => 'GetMarcAuthors called on undefined record'},
116            "GetMarcAuthors returns carped warning on undef record";
117
118 ok( !defined $ret, 'GetMarcAuthors returns undef if not passed rec');
119
120 warning_is { $ret = GetMarcUrls() }
121            { carped => 'GetMarcUrls called on undefined record'},
122            "GetMarcUrls returns carped warning on undef record";
123
124 ok( !defined $ret, 'GetMarcUrls returns undef if not passed rec');
125
126 warning_is { $ret = GetMarcSeries() }
127            { carped => 'GetMarcSeries called on undefined record'},
128            "GetMarcSeries returns carped warning on undef record";
129
130 ok( !defined $ret, 'GetMarcSeries returns undef if not passed rec');
131
132 warning_is { $ret = GetMarcHosts() }
133            { carped => 'GetMarcHosts called on undefined record'},
134            "GetMarcHosts returns carped warning on undef record";
135
136 ok( !defined $ret, 'GetMarcHosts returns undef if not passed rec');
137
138 my $hash_ref;
139
140 warning_is { $hash_ref = TransformMarcToKoha( undef) }
141            { carped => 'TransformMarcToKoha called with undefined record'},
142            "TransformMarcToKoha returns carped warning on undef record";
143
144 isa_ok( $hash_ref, 'HASH');
145
146 $elements = keys %{$hash_ref};
147
148 is($elements, 0, 'Empty hashref returned for undefined record in TransformMarcToKoha');
149
150 warning_is { $ret = ModBiblioMarc() }
151            { carped => 'ModBiblioMarc passed an undefined record'},
152            "ModBiblioMarc returns carped warning on undef record";
153
154 ok( !defined $ret, 'ModBiblioMarc returns undef if not passed rec');
155
156 warning_is { $ret = RemoveAllNsb() }
157            { carped => 'RemoveAllNsb called with undefined record'},
158            "RemoveAllNsb returns carped warning on undef record";
159
160 ok( !defined $ret, 'RemoveAllNsb returns undef if not passed rec');
161
162 warning_is { $ret = GetMarcBiblio() }
163            { carped => 'GetMarcBiblio called without parameters'},
164            "GetMarcBiblio returns carped warning on no parameters";
165
166 warning_is { $ret = GetMarcBiblio({ biblionumber => undef }) }
167            { carped => 'GetMarcBiblio called with undefined biblionumber'},
168            "GetMarcBiblio returns carped warning on undef biblionumber";
169
170 ok( !defined $ret, 'GetMarcBiblio returns undef if not passed a biblionumber');
171
172 warnings_like { $ret = UpdateTotalIssues() }
173               [ { carped => qr/GetMarcBiblio called with undefined biblionumber/ },
174                 { carped => qr/UpdateTotalIssues could not get biblio record/ } ],
175     "UpdateTotalIssues returns carped warnings if biblio record does not exist";
176
177 ok( !defined $ret, 'UpdateTotalIssues returns carped warning if biblio record does not exist');
178