Browse Source

Bug 8064: Fix unit tests for createMergeHash

Signed-off-by: Bernardo Gonzalez Kriegel <bgkriegel@gmail.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
3.22.x
Julian Maurice 7 years ago
committed by Tomas Cohen Arazi
parent
commit
20636ce194
  1. 58
      t/Koha_MetadataRecord.t
  2. 58
      t/Koha_Util_MARC.t

58
t/Koha_MetadataRecord.t

@ -39,55 +39,43 @@ is(ref($record), 'Koha::MetadataRecord', 'Created valid Koha::MetadataRecord obj
my $samplehash = [
{
'field' => [
{
'value' => '1234',
'tag' => '001',
}
]
'value' => '1234',
'tag' => '001',
},
{
'field' => [
'subfield' => [
{
'subfield' => [
{
'value' => 'Cooking',
'subtag' => 'a'
}
],
'indicator2' => ' ',
'tag' => 150,
'indicator1' => ' ',
'value' => 'Cooking',
'subtag' => 'a'
}
]
],
'indicator2' => ' ',
'tag' => 150,
'indicator1' => ' ',
},
{
'field' => [
'subfield' => [
{
'value' => 'Cookery',
'subtag' => 'a'
},
{
'subfield' => [
{
'value' => 'Cookery',
'subtag' => 'a'
},
{
'value' => 'Instructional manuals',
'subtag' => 'z'
}
],
'indicator2' => ' ',
'tag' => 450,
'indicator1' => ' ',
'value' => 'Instructional manuals',
'subtag' => 'z'
}
]
],
'indicator2' => ' ',
'tag' => 450,
'indicator1' => ' ',
}
];
my $hash = $record->createMergeHash();
my %fieldkeys;
foreach my $field (@$hash) {
$fieldkeys{delete $field->{'field'}->[0]->{'key'}}++;
if (defined $field->{'field'}->[0]->{'subfield'}) {
foreach my $subfield (@{$field->{'field'}->[0]->{'subfield'}}) {
$fieldkeys{delete $field->{'key'}}++;
if (defined $field->{'subfield'}) {
foreach my $subfield (@{$field->{'subfield'}}) {
$fieldkeys{delete $subfield->{'subkey'}}++;
}
}

58
t/Koha_Util_MARC.t

@ -38,55 +38,43 @@ $marcrecord->add_fields(
);
my $samplehash = [
{
'field' => [
{
'value' => '1234',
'tag' => '001',
}
]
'value' => '1234',
'tag' => '001',
},
{
'field' => [
'subfield' => [
{
'subfield' => [
{
'value' => 'Cooking',
'subtag' => 'a'
}
],
'indicator2' => ' ',
'tag' => 150,
'indicator1' => ' ',
'value' => 'Cooking',
'subtag' => 'a'
}
]
],
'indicator2' => ' ',
'tag' => 150,
'indicator1' => ' ',
},
{
'field' => [
'subfield' => [
{
'value' => 'Cookery',
'subtag' => 'a'
},
{
'subfield' => [
{
'value' => 'Cookery',
'subtag' => 'a'
},
{
'value' => 'Instructional manuals',
'subtag' => 'z'
}
],
'indicator2' => ' ',
'tag' => 450,
'indicator1' => ' ',
'value' => 'Instructional manuals',
'subtag' => 'z'
}
]
],
'indicator2' => ' ',
'tag' => 450,
'indicator1' => ' ',
}
];
my $hash = Koha::Util::MARC::createMergeHash($marcrecord);
my %fieldkeys;
foreach my $field (@$hash) {
$fieldkeys{delete $field->{'field'}->[0]->{'key'}}++;
if (defined $field->{'field'}->[0]->{'subfield'}) {
foreach my $subfield (@{$field->{'field'}->[0]->{'subfield'}}) {
$fieldkeys{delete $field->{'key'}}++;
if (defined $field->{'subfield'}) {
foreach my $subfield (@{$field->{'subfield'}}) {
$fieldkeys{delete $subfield->{'subkey'}}++;
}
}

Loading…
Cancel
Save