Bug 11797: add regression test
This patch adds unit tests for C4::AuthoritiesMarc::BuildSummary
for both UNIMARC and MARC21 and a regression test for the "Odd
number of elements in anonymous hash" warning.
To test:
[1] Run prove -v t/db_dependent/AuthoritiesMarc.t. It should
report one failure.
[2] Apply the main patch.
[3] Run t/db_dependent/AuthoritiesMarc.t again; it should pass.
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
This commit is contained in:
parent
c212b9328e
commit
f2b655dfab
|
|
@ -6,9 +6,11 @@
|
|||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Test::More tests => 5;
|
||||
use Test::More tests => 8;
|
||||
use Test::MockModule;
|
||||
use Test::Warn;
|
||||
use MARC::Record;
|
||||
use t::lib::Mocks;
|
||||
|
||||
BEGIN {
|
||||
use_ok('C4::AuthoritiesMarc');
|
||||
|
|
@ -55,6 +57,10 @@ $module->mock('GetAuthority', sub {
|
|||
return $record;
|
||||
});
|
||||
|
||||
my $dbh = C4::Context->dbh;
|
||||
$dbh->{AutoCommit} = 0;
|
||||
$dbh->{RaiseError} = 1;
|
||||
|
||||
is(BuildAuthHierarchies(3, 1), '1,2,3', "Built linked authtrees hierarchy string");
|
||||
|
||||
my $expectedhierarchy = [ [ {
|
||||
|
|
@ -96,3 +102,90 @@ $expectedhierarchy = [ [ {
|
|||
'parents' => []
|
||||
} ] ];
|
||||
is_deeply(GenerateHierarchy(4), $expectedhierarchy, "Generated hierarchy data structure for unlinked hierarchy");
|
||||
|
||||
# set up auth_types for next tests
|
||||
$dbh->do('DELETE FROM auth_types');
|
||||
$dbh->do(q{
|
||||
INSERT INTO auth_types (authtypecode, authtypetext, auth_tag_to_report, summary)
|
||||
VALUES ('GEOGR_NAME', 'Geographic Name', '151', 'Geographic Name')
|
||||
});
|
||||
|
||||
t::lib::Mocks::mock_preference('marcflavour', 'MARC21');
|
||||
my $expected_marc21_summary = {
|
||||
'authorized' => [
|
||||
{
|
||||
'field' => '151',
|
||||
'heading' => 'New York (State)',
|
||||
'hemain' => 'New York (State)'
|
||||
}
|
||||
],
|
||||
'authtypecode' => 'GEOGR_NAME',
|
||||
'mainentry' => 'New York (State)',
|
||||
'mainmainentry' => 'New York (State)',
|
||||
'notes' => [],
|
||||
'otherscript' => [],
|
||||
'seealso' => [
|
||||
{
|
||||
'authid' => '1',
|
||||
'field' => '551',
|
||||
'heading' => 'United States',
|
||||
'hemain' => 'United States',
|
||||
'search' => 'United States',
|
||||
'type' => 'broader'
|
||||
}
|
||||
],
|
||||
'seefrom' => [],
|
||||
'summary' => 'Geographic Name',
|
||||
'type' => 'Geographic Name'
|
||||
};
|
||||
is_deeply(
|
||||
BuildSummary(C4::AuthoritiesMarc::GetAuthority(2), 2, 'GEOGR_NAME'),
|
||||
$expected_marc21_summary,
|
||||
'test BuildSummary for MARC21'
|
||||
);
|
||||
|
||||
my $marc21_subdiv = MARC::Record->new();
|
||||
$marc21_subdiv->add_fields(
|
||||
[ '181', ' ', ' ', x => 'Political aspects' ]
|
||||
);
|
||||
warning_is { BuildSummary($marc21_subdiv, 99999, 'GEN_SUBDIV') } [],
|
||||
'BuildSummary does not generate warning if main heading subfield not present';
|
||||
|
||||
t::lib::Mocks::mock_preference('marcflavour', 'UNIMARC');
|
||||
$dbh->do(q{
|
||||
INSERT INTO auth_types (authtypecode, authtypetext, auth_tag_to_report, summary)
|
||||
VALUES ('NP', 'Auteur', '200', '[200a][, 200b][ 200d][ ; 200c][ (200f)]')
|
||||
});
|
||||
|
||||
my $unimarc_name_auth = MARC::Record->new();
|
||||
$unimarc_name_auth->add_fields(
|
||||
['100', ' ', ' ', a => '20121025 frey50 '],
|
||||
['200', ' ', ' ', a => 'Fossey', b => 'Brigitte' ],
|
||||
['152', ' ', ' ', a => 'NP'],
|
||||
);
|
||||
my $expected_unimarc_name_summary = {
|
||||
'authorized' => [
|
||||
{
|
||||
'field' => '200',
|
||||
'heading' => 'Fossey Brigitte',
|
||||
'hemain' => 'Fossey'
|
||||
}
|
||||
],
|
||||
'authtypecode' => 'NP',
|
||||
'mainentry' => 'Fossey Brigitte',
|
||||
'mainmainentry' => 'Fossey',
|
||||
'notes' => [],
|
||||
'otherscript' => [],
|
||||
'seealso' => [],
|
||||
'seefrom' => [],
|
||||
'summary' => 'Fossey, Brigitte',
|
||||
'type' => 'Auteur'
|
||||
};
|
||||
|
||||
is_deeply(
|
||||
BuildSummary($unimarc_name_auth, 99999, 'NP'),
|
||||
$expected_unimarc_name_summary,
|
||||
'test BuildSummary for UNIMARC'
|
||||
);
|
||||
|
||||
$dbh->rollback;
|
||||
|
|
|
|||
Loading…
Reference in New Issue