3 # This file is part of Koha.
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.
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.
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>.
27 use_ok('C4::Biblio', qw( AddBiblio ModBiblio BiblioAutoLink LinkBibHeadingsToAuthorities GetMarcPrice GetMarcQuantity GetMarcControlnumber GetMarcISBN GetMarcISSN GetMarcSubjects GetMarcAuthors GetMarcUrls GetMarcSeries TransformMarcToKoha ModBiblioMarc RemoveAllNsb GetMarcBiblio UpdateTotalIssues ));
29 my $db = Test::MockModule->new('Koha::Database');
30 $db->mock( _new_schema => sub { return Schema(); } );
35 warning_is { @arr = AddBiblio(undef, q{}) }
36 { carped => 'AddBiblio called with undefined record'},
37 "AddBiblio returns carped warning on undef record";
41 is($elements, 0, 'Add Biblio returns empty array for undef record');
43 warning_is { $ret = ModBiblio(undef, 0, '') }
44 { carped => 'No record passed to ModBiblio'},
45 "ModBiblio returns carped warning on undef record";
47 is( $ret, 0, 'ModBiblio returns zero if not passed rec');
49 warning_is { $ret = BiblioAutoLink(undef, q{}) }
50 { carped => 'Undefined record passed to BiblioAutoLink'},
51 "BiblioAutoLink returns carped warning on undef record";
53 is( $ret, 0, 'BiblioAutoLink returns zero if not passed rec');
55 warning_is { @arr = LinkBibHeadingsToAuthorities(q{}, q{}) }
56 { carped => 'LinkBibHeadingsToAuthorities called on undefined bib record'},
57 "LinkBibHeadingsToAuthorities returns carped warning on undef record";
59 is($arr[0], 0, 'LinkBibHeadingsToAuthorities correct error return');
61 warning_is { $ret = GetMarcPrice(undef, 'MARC21') }
62 { carped => 'GetMarcPrice called on undefined record'},
63 "GetMarcPrice returns carped warning on undef record";
65 ok( !defined $ret, 'GetMarcPrice returns undef if not passed rec');
67 warning_is { $ret = GetMarcQuantity(undef, 'MARC21') }
68 { carped => 'GetMarcQuantity called on undefined record'},
69 "GetMarcQuantity returns carped warning on undef record";
71 ok( !defined $ret, 'GetMarcQuantity returns undef if not passed rec');
73 warning_is { $ret = GetMarcControlnumber() }
74 { carped => 'GetMarcControlnumber called on undefined record'},
75 "GetMarcControlnumber returns carped warning on undef record";
77 ok( !defined $ret, 'GetMarcControlnumber returns undef if not passed rec');
79 warning_is { $ret = GetMarcISBN() }
80 { carped => 'GetMarcISBN called on undefined record'},
81 "GetMarcISBN returns carped warning on undef record";
83 ok( !defined $ret, 'GetMarcISBN returns undef if not passed rec');
85 warning_is { $ret = GetMarcISSN() }
86 { carped => 'GetMarcISSN called on undefined record'},
87 "GetMarcISSN returns carped warning on undef record";
89 ok( !defined $ret, 'GetMarcISSN returns undef if not passed rec');
91 warning_is { $ret = GetMarcSubjects() }
92 { carped => 'GetMarcSubjects called on undefined record'},
93 "GetMarcSubjects returns carped warning on undef record";
95 ok( !defined $ret, 'GetMarcSubjects returns undef if not passed rec');
97 warning_is { $ret = GetMarcAuthors() }
98 { carped => 'GetMarcAuthors called on undefined record'},
99 "GetMarcAuthors returns carped warning on undef record";
101 ok( !defined $ret, 'GetMarcAuthors returns undef if not passed rec');
103 warning_is { $ret = GetMarcUrls() }
104 { carped => 'GetMarcUrls called on undefined record'},
105 "GetMarcUrls returns carped warning on undef record";
107 ok( !defined $ret, 'GetMarcUrls returns undef if not passed rec');
109 warning_is { $ret = GetMarcSeries() }
110 { carped => 'GetMarcSeries called on undefined record'},
111 "GetMarcSeries returns carped warning on undef record";
113 ok( !defined $ret, 'GetMarcSeries returns undef if not passed rec');
117 warning_is { $hash_ref = TransformMarcToKoha( undef) }
118 { carped => 'TransformMarcToKoha called with undefined record'},
119 "TransformMarcToKoha returns carped warning on undef record";
121 isa_ok( $hash_ref, 'HASH');
123 $elements = keys %{$hash_ref};
125 is($elements, 0, 'Empty hashref returned for undefined record in TransformMarcToKoha');
127 warning_is { $ret = ModBiblioMarc() }
128 { carped => 'ModBiblioMarc passed an undefined record'},
129 "ModBiblioMarc returns carped warning on undef record";
131 ok( !defined $ret, 'ModBiblioMarc returns undef if not passed rec');
133 warning_is { $ret = RemoveAllNsb() }
134 { carped => 'RemoveAllNsb called with undefined record'},
135 "RemoveAllNsb returns carped warning on undef record";
137 ok( !defined $ret, 'RemoveAllNsb returns undef if not passed rec');
139 warning_is { $ret = GetMarcBiblio() }
140 { carped => 'GetMarcBiblio called without parameters'},
141 "GetMarcBiblio returns carped warning on no parameters";
143 warning_is { $ret = GetMarcBiblio({ biblionumber => undef }) }
144 { carped => 'GetMarcBiblio called with undefined biblionumber'},
145 "GetMarcBiblio returns carped warning on undef biblionumber";
147 ok( !defined $ret, 'GetMarcBiblio returns undef if not passed a biblionumber');
149 warnings_like { $ret = UpdateTotalIssues() }
150 [ { carped => qr/GetMarcBiblio called with undefined biblionumber/ },
151 { carped => qr/UpdateTotalIssues could not get biblio record/ } ],
152 "UpdateTotalIssues returns carped warnings if biblio record does not exist";
154 ok( !defined $ret, 'UpdateTotalIssues returns carped warning if biblio record does not exist');