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 is(BuildAuthHierarchies(3, 1), '1,2,3', "Built linked authtrees hierarchy string");
66 my $expectedhierarchy = [ [ {
68 'value' => 'United States',
72 'value' => 'New York (State)',
77 'value' => 'New York (City)',
82 'value' => 'New York (State)'
87 'value' => 'United States'
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 = [ [ {
99 'value' => 'New York (City)',
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');
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 = {
118 'heading' => 'New York (State)',
119 'hemain' => 'New York (State)'
122 'authtypecode' => 'GEOGR_NAME',
123 'mainentry' => 'New York (State)',
124 'mainmainentry' => 'New York (State)',
131 'heading' => 'United States',
132 'hemain' => 'United States',
133 'search' => 'United States',
138 'summary' => 'Geographic Name',
139 'type' => 'Geographic Name'
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');
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 = {
170 'heading' => 'Fossey Brigitte',
174 'authtypecode' => 'NP',
175 'mainentry' => 'Fossey Brigitte',
176 'mainmainentry' => 'Fossey',
181 'summary' => 'Fossey, Brigitte',
186 BuildSummary($unimarc_name_auth, 99999, 'NP'),
187 $expected_unimarc_name_summary,
188 'test BuildSummary for UNIMARC'