3 # This Koha test module is a stub!
4 # Add more tests here!!!
9 use Test
::More tests
=> 8;
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' => ''};
25 $module->mock('AddAuthorityTrees', sub {
28 $module->mock('GetAuthority', sub {
30 my $record = MARC
::Record
->new();
34 [ '151', ' ', ' ', a
=> 'United States' ]
36 } elsif ($authid eq '2') {
39 [ '151', ' ', ' ', a
=> 'New York (State)' ],
40 [ '551', ' ', ' ', a
=> 'United States', w
=> 'g', 9 => '1' ]
42 } elsif ($authid eq '3') {
45 [ '151', ' ', ' ', a
=> 'New York (City)' ],
46 [ '551', ' ', ' ', a
=> 'New York (State)', w
=> 'g', 9 => '2' ]
48 } elsif ($authid eq '4') {
51 [ '151', ' ', ' ', a
=> 'New York (City)' ],
52 [ '551', ' ', ' ', a
=> 'New York (State)', w
=> 'g' ]
60 my $dbh = C4
::Context
->dbh;
61 $dbh->{AutoCommit
} = 0;
62 $dbh->{RaiseError
} = 1;
64 t
::lib
::Mocks
::mock_preference
('marcflavour', 'MARC21');
66 is
(BuildAuthHierarchies
(3, 1), '1,2,3', "Built linked authtrees hierarchy string");
68 my $expectedhierarchy = [ [ {
70 'value' => 'United States',
74 'value' => 'New York (State)',
79 'value' => 'New York (City)',
84 'value' => 'New York (State)'
89 'value' => 'United States'
95 is_deeply
(GenerateHierarchy
(3), $expectedhierarchy, "Generated hierarchy data structure for linked hierarchy");
97 is
(BuildAuthHierarchies
(4, 1), '4', "Built unlinked authtrees hierarchy string");
98 $expectedhierarchy = [ [ {
100 'current_value' => 1,
101 'value' => 'New York (City)',
106 is_deeply
(GenerateHierarchy
(4), $expectedhierarchy, "Generated hierarchy data structure for unlinked hierarchy");
108 # set up auth_types for next tests
109 $dbh->do('DELETE FROM auth_types');
111 INSERT INTO auth_types (authtypecode, authtypetext, auth_tag_to_report, summary)
112 VALUES ('GEOGR_NAME', 'Geographic Name', '151', 'Geographic Name')
115 t
::lib
::Mocks
::mock_preference
('marcflavour', 'MARC21');
116 my $expected_marc21_summary = {
120 'heading' => 'New York (State)',
121 'hemain' => 'New York (State)'
124 'authtypecode' => 'GEOGR_NAME',
125 'mainentry' => 'New York (State)',
126 'mainmainentry' => 'New York (State)',
133 'heading' => 'United States',
134 'hemain' => 'United States',
135 'search' => 'United States',
140 'label' => 'Geographic Name',
141 'type' => 'Geographic Name'
144 BuildSummary
(C4
::AuthoritiesMarc
::GetAuthority
(2), 2, 'GEOGR_NAME'),
145 $expected_marc21_summary,
146 'test BuildSummary for MARC21'
149 my $marc21_subdiv = MARC
::Record
->new();
150 $marc21_subdiv->add_fields(
151 [ '181', ' ', ' ', x
=> 'Political aspects' ]
153 warning_is
{ BuildSummary
($marc21_subdiv, 99999, 'GEN_SUBDIV') } [],
154 'BuildSummary does not generate warning if main heading subfield not present';
156 t
::lib
::Mocks
::mock_preference
('marcflavour', 'UNIMARC');
158 INSERT INTO auth_types (authtypecode, authtypetext, auth_tag_to_report, summary)
159 VALUES ('NP', 'Auteur', '200', '[200a][, 200b][ 200d][ ; 200c][ (200f)]')
162 my $unimarc_name_auth = MARC
::Record
->new();
163 $unimarc_name_auth->add_fields(
164 ['100', ' ', ' ', a
=> '20121025 frey50 '],
165 ['200', ' ', ' ', a
=> 'Fossey', b
=> 'Brigitte' ],
166 ['152', ' ', ' ', a
=> 'NP'],
168 my $expected_unimarc_name_summary = {
172 'heading' => 'Fossey Brigitte',
176 'authtypecode' => 'NP',
177 'mainentry' => 'Fossey Brigitte',
178 'mainmainentry' => 'Fossey',
183 'summary' => 'Fossey, Brigitte',
188 BuildSummary
($unimarc_name_auth, 99999, 'NP'),
189 $expected_unimarc_name_summary,
190 'test BuildSummary for UNIMARC'