Bug 4502: Catch software error if no active budget defined
[koha.git] / t / Koha_Util_MARC.t
blob84494692a9059cc01d43ec8186d74b95e82c6794
1 #!/usr/bin/perl
3 # Copyright 2013 C & P Bibliography Services
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20 # Note that at present this test is almost identical to the one testing
21 # the encapsulating method in Koha::MetadataRecord.
23 use strict;
24 use warnings;
26 use Test::More tests => 4;
28 BEGIN {
29 use_ok('Koha::Util::MARC');
32 my $marcrecord = MARC::Record->new;
34 $marcrecord->add_fields(
35 [ '001', '1234' ],
36 [ '150', ' ', ' ', a => 'Cooking' ],
37 [ '450', ' ', ' ', a => 'Cookery', z => 'Instructional manuals' ],
39 my $samplehash = [
41 'field' => [
43 'value' => '1234',
44 'tag' => '001',
49 'field' => [
51 'subfield' => [
53 'value' => 'Cooking',
54 'subtag' => 'a'
57 'indicator2' => ' ',
58 'tag' => 150,
59 'indicator1' => ' ',
64 'field' => [
66 'subfield' => [
68 'value' => 'Cookery',
69 'subtag' => 'a'
72 'value' => 'Instructional manuals',
73 'subtag' => 'z'
76 'indicator2' => ' ',
77 'tag' => 450,
78 'indicator1' => ' ',
84 my $hash = Koha::Util::MARC::createMergeHash($marcrecord);
85 my %fieldkeys;
86 foreach my $field (@$hash) {
87 $fieldkeys{delete $field->{'field'}->[0]->{'key'}}++;
88 if (defined $field->{'field'}->[0]->{'subfield'}) {
89 foreach my $subfield (@{$field->{'field'}->[0]->{'subfield'}}) {
90 $fieldkeys{delete $subfield->{'subkey'}}++;
95 is_deeply($hash, $samplehash, 'Generated hash correctly');
96 my $dupkeys = grep { $_ > 1 } values %fieldkeys;
97 is($dupkeys, 0, 'No duplicate keys');
99 is(Koha::Util::MARC::getAuthorityAuthorizedHeading($marcrecord, 'marc21'), 'Cooking', 'Routine for retrieving authorized heading works');