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