Bug 11529: Add templates for biblio title display. Unify display.
[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 => 45;
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 { @arr = LinkBibHeadingsToAuthorities(q{}, q{}) }
55            { carped => 'LinkBibHeadingsToAuthorities called on undefined bib record'},
56            "LinkBibHeadingsToAuthorities returns carped warning on undef record";
57
58 is($arr[0], 0, 'LinkBibHeadingsToAuthorities correct error return');
59
60 warning_is { $ret = GetMarcPrice(undef, 'MARC21') }
61            { carped => 'GetMarcPrice called on undefined record'},
62            "GetMarcPrice returns carped warning on undef record";
63
64 ok( !defined $ret, 'GetMarcPrice returns undef if not passed rec');
65
66 warning_is { $ret = GetMarcQuantity(undef, 'MARC21') }
67            { carped => 'GetMarcQuantity called on undefined record'},
68            "GetMarcQuantity returns carped warning on undef record";
69
70 ok( !defined $ret, 'GetMarcQuantity returns undef if not passed rec');
71
72 warning_is { $ret = GetMarcControlnumber() }
73            { carped => 'GetMarcControlnumber called on undefined record'},
74            "GetMarcControlnumber returns carped warning on undef record";
75
76 ok( !defined $ret, 'GetMarcControlnumber returns undef if not passed rec');
77
78 warning_is { $ret = GetMarcISBN() }
79            { carped => 'GetMarcISBN called on undefined record'},
80            "GetMarcISBN returns carped warning on undef record";
81
82 ok( !defined $ret, 'GetMarcISBN returns undef if not passed rec');
83
84 warning_is { $ret = GetMarcISSN() }
85            { carped => 'GetMarcISSN called on undefined record'},
86            "GetMarcISSN returns carped warning on undef record";
87
88 ok( !defined $ret, 'GetMarcISSN returns undef if not passed rec');
89
90 warning_is { $ret = GetMarcNotes() }
91            { carped => 'GetMarcNotes called on undefined record'},
92            "GetMarcNotes returns carped warning on undef record";
93
94 ok( !defined $ret, 'GetMarcNotes returns undef if not passed rec');
95
96 warning_is { $ret = GetMarcSubjects() }
97            { carped => 'GetMarcSubjects called on undefined record'},
98            "GetMarcSubjects returns carped warning on undef record";
99
100 ok( !defined $ret, 'GetMarcSubjects returns undef if not passed rec');
101
102 warning_is { $ret = GetMarcAuthors() }
103            { carped => 'GetMarcAuthors called on undefined record'},
104            "GetMarcAuthors returns carped warning on undef record";
105
106 ok( !defined $ret, 'GetMarcAuthors returns undef if not passed rec');
107
108 warning_is { $ret = GetMarcUrls() }
109            { carped => 'GetMarcUrls called on undefined record'},
110            "GetMarcUrls returns carped warning on undef record";
111
112 ok( !defined $ret, 'GetMarcUrls returns undef if not passed rec');
113
114 warning_is { $ret = GetMarcSeries() }
115            { carped => 'GetMarcSeries called on undefined record'},
116            "GetMarcSeries returns carped warning on undef record";
117
118 ok( !defined $ret, 'GetMarcSeries returns undef if not passed rec');
119
120 warning_is { $ret = GetMarcHosts() }
121            { carped => 'GetMarcHosts called on undefined record'},
122            "GetMarcHosts returns carped warning on undef record";
123
124 ok( !defined $ret, 'GetMarcHosts returns undef if not passed rec');
125
126 my $hash_ref;
127
128 warning_is { $hash_ref = TransformMarcToKoha( undef) }
129            { carped => 'TransformMarcToKoha called with undefined record'},
130            "TransformMarcToKoha returns carped warning on undef record";
131
132 isa_ok( $hash_ref, 'HASH');
133
134 $elements = keys %{$hash_ref};
135
136 is($elements, 0, 'Empty hashref returned for undefined record in TransformMarcToKoha');
137
138 warning_is { $ret = ModBiblioMarc() }
139            { carped => 'ModBiblioMarc passed an undefined record'},
140            "ModBiblioMarc returns carped warning on undef record";
141
142 ok( !defined $ret, 'ModBiblioMarc returns undef if not passed rec');
143
144 warning_is { $ret = RemoveAllNsb() }
145            { carped => 'RemoveAllNsb called with undefined record'},
146            "RemoveAllNsb returns carped warning on undef record";
147
148 ok( !defined $ret, 'RemoveAllNsb returns undef if not passed rec');
149
150 warning_is { $ret = GetMarcBiblio() }
151            { carped => 'GetMarcBiblio called without parameters'},
152            "GetMarcBiblio returns carped warning on no parameters";
153
154 warning_is { $ret = GetMarcBiblio({ biblionumber => undef }) }
155            { carped => 'GetMarcBiblio called with undefined biblionumber'},
156            "GetMarcBiblio returns carped warning on undef biblionumber";
157
158 ok( !defined $ret, 'GetMarcBiblio returns undef if not passed a biblionumber');
159
160 warnings_like { $ret = UpdateTotalIssues() }
161               [ { carped => qr/GetMarcBiblio called with undefined biblionumber/ },
162                 { carped => qr/UpdateTotalIssues could not get biblio record/ } ],
163     "UpdateTotalIssues returns carped warnings if biblio record does not exist";
164
165 ok( !defined $ret, 'UpdateTotalIssues returns carped warning if biblio record does not exist');
166