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