Bug 13669: followup to add DBIx::RunSQL dependency
[koha.git] / t / Biblio.t
blob1cec33be516ee931a56c714ec793f57af3f85fd8
1 #!/usr/bin/perl
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>.
18 use Modern::Perl;
20 use Test::More;
21 use Test::MockModule;
22 use Test::Warn;
24 use Module::Load::Conditional qw/check_install/;
26 BEGIN {
27 if ( check_install( module => 'Test::DBIx::Class' ) ) {
28 plan tests => 46;
29 } else {
30 plan skip_all => "Need Test::DBIx::Class"
34 use_ok('C4::Biblio');
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' ;
43 sub fixtures {
44 my ( $data ) = @_;
45 fixtures_ok [
46 Biblio => [
47 [ qw/ biblionumber datecreated timestamp / ],
48 @$data,
50 ], 'add fixtures';
53 my $db = Test::MockModule->new('Koha::Database');
54 $db->mock( _new_schema => sub { return Schema(); } );
56 my @arr;
57 my $ret;
59 warning_is { @arr = AddBiblio(undef, q{}) }
60 { carped => 'AddBiblio called with undefined record'},
61 "AddBiblio returns carped warning on undef record";
63 my $elements = @arr;
65 is($elements, 0, 'Add Biblio returns empty array for undef record');
67 warning_is { $ret = ModBiblio(undef, 0, '') }
68 { carped => 'No record passed to ModBiblio'},
69 "ModBiblio returns carped warning on undef record";
71 is( $ret, 0, 'ModBiblio returns zero if not passed rec');
73 warning_is { $ret = BiblioAutoLink(undef, q{}) }
74 { carped => 'Undefined record passed to BiblioAutoLink'},
75 "BiblioAutoLink returns carped warning on undef record";
77 is( $ret, 0, 'BiblioAutoLink returns zero if not passed rec');
79 warning_is { $ret = GetRecordValue('100', undef, q{}) }
80 { carped => 'GetRecordValue called with undefined record'},
81 "GetRecordValue returns carped warning on undef record";
83 ok( !defined $ret, 'GetRecordValue returns undef if not passed rec');
85 warning_is { @arr = LinkBibHeadingsToAuthorities(q{}, q{}) }
86 { carped => 'LinkBibHeadingsToAuthorities called on undefined bib record'},
87 "LinkBibHeadingsToAuthorities returns carped warning on undef record";
89 is($arr[0], 0, 'LinkBibHeadingsToAuthorities correct error return');
91 warning_is { $ret = GetCOinSBiblio() }
92 { carped => 'GetCOinSBiblio called with undefined record'},
93 "GetCOinSBiblio returns carped warning on undef record";
95 ok( !defined $ret, 'GetCOinSBiblio returns undef if not passed rec');
97 warning_is { $ret = GetMarcPrice(undef, 'MARC21') }
98 { carped => 'GetMarcPrice called on undefined record'},
99 "GetMarcPrice returns carped warning on undef record";
101 ok( !defined $ret, 'GetMarcPrice returns undef if not passed rec');
103 warning_is { $ret = GetMarcQuantity(undef, 'MARC21') }
104 { carped => 'GetMarcQuantity called on undefined record'},
105 "GetMarcQuantity returns carped warning on undef record";
107 ok( !defined $ret, 'GetMarcQuantity returns undef if not passed rec');
109 warning_is { $ret = GetMarcControlnumber() }
110 { carped => 'GetMarcControlnumber called on undefined record'},
111 "GetMarcControlnumber returns carped warning on undef record";
113 ok( !defined $ret, 'GetMarcControlnumber returns undef if not passed rec');
115 warning_is { $ret = GetMarcISBN() }
116 { carped => 'GetMarcISBN called on undefined record'},
117 "GetMarcISBN returns carped warning on undef record";
119 ok( !defined $ret, 'GetMarcISBN returns undef if not passed rec');
121 warning_is { $ret = GetMarcISSN() }
122 { carped => 'GetMarcISSN called on undefined record'},
123 "GetMarcISSN returns carped warning on undef record";
125 ok( !defined $ret, 'GetMarcISSN returns undef if not passed rec');
127 warning_is { $ret = GetMarcNotes() }
128 { carped => 'GetMarcNotes called on undefined record'},
129 "GetMarcNotes returns carped warning on undef record";
131 ok( !defined $ret, 'GetMarcNotes returns undef if not passed rec');
133 warning_is { $ret = GetMarcSubjects() }
134 { carped => 'GetMarcSubjects called on undefined record'},
135 "GetMarcSubjects returns carped warning on undef record";
137 ok( !defined $ret, 'GetMarcSubjects returns undef if not passed rec');
139 warning_is { $ret = GetMarcAuthors() }
140 { carped => 'GetMarcAuthors called on undefined record'},
141 "GetMarcAuthors returns carped warning on undef record";
143 ok( !defined $ret, 'GetMarcAuthors returns undef if not passed rec');
145 warning_is { $ret = GetMarcUrls() }
146 { carped => 'GetMarcUrls called on undefined record'},
147 "GetMarcUrls returns carped warning on undef record";
149 ok( !defined $ret, 'GetMarcUrls returns undef if not passed rec');
151 warning_is { $ret = GetMarcSeries() }
152 { carped => 'GetMarcSeries called on undefined record'},
153 "GetMarcSeries returns carped warning on undef record";
155 ok( !defined $ret, 'GetMarcSeries returns undef if not passed rec');
157 warning_is { $ret = GetMarcHosts() }
158 { carped => 'GetMarcHosts called on undefined record'},
159 "GetMarcHosts returns carped warning on undef record";
161 ok( !defined $ret, 'GetMarcHosts returns undef if not passed rec');
163 my $hash_ref;
165 warning_is { $hash_ref = TransformMarcToKoha( undef) }
166 { carped => 'TransformMarcToKoha called with undefined record'},
167 "TransformMarcToKoha returns carped warning on undef record";
169 isa_ok( $hash_ref, 'HASH');
171 $elements = keys %{$hash_ref};
173 is($elements, 0, 'Empty hashref returned for undefined record in TransformMarcToKoha');
175 warning_is { $ret = ModBiblioMarc() }
176 { carped => 'ModBiblioMarc passed an undefined record'},
177 "ModBiblioMarc returns carped warning on undef record";
179 ok( !defined $ret, 'ModBiblioMarc returns undef if not passed rec');
181 warning_is { $ret = RemoveAllNsb() }
182 { carped => 'RemoveAllNsb called with undefined record'},
183 "RemoveAllNsb returns carped warning on undef record";
185 ok( !defined $ret, 'RemoveAllNsb returns undef if not passed rec');
187 warning_is { $ret = GetMarcBiblio() }
188 { carped => 'GetMarcBiblio called with undefined biblionumber'},
189 "GetMarcBiblio returns carped warning on undef biblionumber";
191 ok( !defined $ret, 'GetMarcBiblio returns undef if not passed a biblionumber');
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";
198 ok( !defined $ret, 'UpdateTotalIssues returns carped warning if biblio record does not exist');