Bug 12863 [LESS follow-up] News in OPAC: HTML broken with nested p tags and multiple...
[koha.git] / t / db_dependent / AuthoritiesMarc.t
blobbc4adeb266fca42f5fba612ab77af0238f395669
1 #!/usr/bin/perl
3 # This Koha test module is a stub!
4 # Add more tests here!!!
6 use strict;
7 use warnings;
9 use Test::More tests => 8;
10 use Test::MockModule;
11 use Test::Warn;
12 use MARC::Record;
13 use t::lib::Mocks;
15 BEGIN {
16 use_ok('C4::AuthoritiesMarc');
19 # We are now going to be testing the authorities hierarchy code, and
20 # therefore need to pretend that we have consistent data in our database
21 my $module = new Test::MockModule('C4::AuthoritiesMarc');
22 $module->mock('GetHeaderAuthority', sub {
23 return {'authtrees' => ''};
24 });
25 $module->mock('AddAuthorityTrees', sub {
26 return;
27 });
28 $module->mock('GetAuthority', sub {
29 my ($authid) = @_;
30 my $record = MARC::Record->new();
31 if ($authid eq '1') {
32 $record->add_fields(
33 [ '001', '1' ],
34 [ '151', ' ', ' ', a => 'United States' ]
36 } elsif ($authid eq '2') {
37 $record->add_fields(
38 [ '001', '2' ],
39 [ '151', ' ', ' ', a => 'New York (State)' ],
40 [ '551', ' ', ' ', a => 'United States', w => 'g', 9 => '1' ]
42 } elsif ($authid eq '3') {
43 $record->add_fields(
44 [ '001', '3' ],
45 [ '151', ' ', ' ', a => 'New York (City)' ],
46 [ '551', ' ', ' ', a => 'New York (State)', w => 'g', 9 => '2' ]
48 } elsif ($authid eq '4') {
49 $record->add_fields(
50 [ '001', '4' ],
51 [ '151', ' ', ' ', a => 'New York (City)' ],
52 [ '551', ' ', ' ', a => 'New York (State)', w => 'g' ]
54 } else {
55 undef $record;
57 return $record;
58 });
60 my $dbh = C4::Context->dbh;
61 $dbh->{AutoCommit} = 0;
62 $dbh->{RaiseError} = 1;
64 is(BuildAuthHierarchies(3, 1), '1,2,3', "Built linked authtrees hierarchy string");
66 my $expectedhierarchy = [ [ {
67 'authid' => '1',
68 'value' => 'United States',
69 'class' => 'child0',
70 'children' => [ {
71 'authid' => '2',
72 'value' => 'New York (State)',
73 'class' => 'child1',
74 'children' => [ {
75 'authid' => '3',
76 'current_value' => 1,
77 'value' => 'New York (City)',
78 'class' => 'child2',
79 'children' => [],
80 'parents' => [ {
81 'authid' => '2',
82 'value' => 'New York (State)'
83 } ]
84 } ],
85 'parents' => [ {
86 'authid' => '1',
87 'value' => 'United States'
88 } ]
89 } ],
90 'parents' => []
91 } ] ];
93 is_deeply(GenerateHierarchy(3), $expectedhierarchy, "Generated hierarchy data structure for linked hierarchy");
95 is(BuildAuthHierarchies(4, 1), '4', "Built unlinked authtrees hierarchy string");
96 $expectedhierarchy = [ [ {
97 'authid' => '4',
98 'current_value' => 1,
99 'value' => 'New York (City)',
100 'class' => 'child0',
101 'children' => [],
102 'parents' => []
103 } ] ];
104 is_deeply(GenerateHierarchy(4), $expectedhierarchy, "Generated hierarchy data structure for unlinked hierarchy");
106 # set up auth_types for next tests
107 $dbh->do('DELETE FROM auth_types');
108 $dbh->do(q{
109 INSERT INTO auth_types (authtypecode, authtypetext, auth_tag_to_report, summary)
110 VALUES ('GEOGR_NAME', 'Geographic Name', '151', 'Geographic Name')
113 t::lib::Mocks::mock_preference('marcflavour', 'MARC21');
114 my $expected_marc21_summary = {
115 'authorized' => [
117 'field' => '151',
118 'heading' => 'New York (State)',
119 'hemain' => 'New York (State)'
122 'authtypecode' => 'GEOGR_NAME',
123 'mainentry' => 'New York (State)',
124 'mainmainentry' => 'New York (State)',
125 'notes' => [],
126 'otherscript' => [],
127 'seealso' => [
129 'authid' => '1',
130 'field' => '551',
131 'heading' => 'United States',
132 'hemain' => 'United States',
133 'search' => 'United States',
134 'type' => 'broader'
137 'seefrom' => [],
138 'summary' => 'Geographic Name',
139 'type' => 'Geographic Name'
141 is_deeply(
142 BuildSummary(C4::AuthoritiesMarc::GetAuthority(2), 2, 'GEOGR_NAME'),
143 $expected_marc21_summary,
144 'test BuildSummary for MARC21'
147 my $marc21_subdiv = MARC::Record->new();
148 $marc21_subdiv->add_fields(
149 [ '181', ' ', ' ', x => 'Political aspects' ]
151 warning_is { BuildSummary($marc21_subdiv, 99999, 'GEN_SUBDIV') } [],
152 'BuildSummary does not generate warning if main heading subfield not present';
154 t::lib::Mocks::mock_preference('marcflavour', 'UNIMARC');
155 $dbh->do(q{
156 INSERT INTO auth_types (authtypecode, authtypetext, auth_tag_to_report, summary)
157 VALUES ('NP', 'Auteur', '200', '[200a][, 200b][ 200d][ ; 200c][ (200f)]')
160 my $unimarc_name_auth = MARC::Record->new();
161 $unimarc_name_auth->add_fields(
162 ['100', ' ', ' ', a => '20121025 frey50 '],
163 ['200', ' ', ' ', a => 'Fossey', b => 'Brigitte' ],
164 ['152', ' ', ' ', a => 'NP'],
166 my $expected_unimarc_name_summary = {
167 'authorized' => [
169 'field' => '200',
170 'heading' => 'Fossey Brigitte',
171 'hemain' => 'Fossey'
174 'authtypecode' => 'NP',
175 'mainentry' => 'Fossey Brigitte',
176 'mainmainentry' => 'Fossey',
177 'notes' => [],
178 'otherscript' => [],
179 'seealso' => [],
180 'seefrom' => [],
181 'repets' => [
182 'Fossey, Brigitte'
184 'type' => 'Auteur'
187 is_deeply(
188 BuildSummary($unimarc_name_auth, 99999, 'NP'),
189 $expected_unimarc_name_summary,
190 'test BuildSummary for UNIMARC'
193 $dbh->rollback;