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