Bug 19532: (follow-up) aria-hidden attr on OPAC, and more
[koha.git] / t / Koha_Util_MARC.t
1 #!/usr/bin/perl
2
3 # Copyright 2013 C & P Bibliography Services
4 #
5 # This file is part of Koha.
6 #
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.
11 #
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.
16 #
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>.
19
20 # Note that at present this test is almost identical to the one testing
21 # the encapsulating method in Koha::MetadataRecord.
22
23 use strict;
24 use warnings;
25
26 use Test::More tests => 4;
27 use MARC::Record;
28
29 BEGIN {
30         use_ok('Koha::Util::MARC');
31 }
32
33 my $marcrecord = MARC::Record->new;
34
35 $marcrecord->add_fields(
36         [ '001', '1234' ],
37         [ '150', ' ', ' ', a => 'Cooking' ],
38         [ '450', ' ', ' ', a => 'Cookery', z => 'Instructional manuals' ],
39         );
40 my $samplehash = [
41     {
42         'value' => '1234',
43         'tag'   => '001',
44     },
45     {
46         'subfield' => [
47             {
48                 'value'  => 'Cooking',
49                 'subtag' => 'a'
50             }
51         ],
52         'indicator2' => ' ',
53         'tag'        => 150,
54         'indicator1' => ' ',
55     },
56     {
57         'subfield' => [
58             {
59                 'value'  => 'Cookery',
60                 'subtag' => 'a'
61             },
62             {
63                 'value'  => 'Instructional manuals',
64                 'subtag' => 'z'
65             }
66         ],
67         'indicator2' => ' ',
68         'tag'        => 450,
69         'indicator1' => ' ',
70     }
71 ];
72
73 my $hash = Koha::Util::MARC::createMergeHash($marcrecord);
74 my %fieldkeys;
75 foreach my $field (@$hash) {
76     $fieldkeys{delete $field->{'key'}}++;
77     if (defined $field->{'subfield'}) {
78         foreach my $subfield (@{$field->{'subfield'}}) {
79             $fieldkeys{delete $subfield->{'subkey'}}++;
80         }
81     }
82 }
83
84 is_deeply($hash, $samplehash, 'Generated hash correctly');
85 my $dupkeys = grep { $_ > 1 } values %fieldkeys;
86 is($dupkeys, 0, 'No duplicate keys');
87
88 is(Koha::Util::MARC::getAuthorityAuthorizedHeading($marcrecord, 'marc21'), 'Cooking', 'Routine for retrieving authorized heading works');