Browse Source

Bug 21800: Add tests for repeatable subfields

Test plan:
Do not apply the second patch [note 1].
Run t/db_dependent/Biblio/TransformKohaToMarc.t
Run t/db_dependent/Biblio/TransformMarcToKoha.t
Apply the second patch and run them again. Both tests should pass now.

Note 1: The TransformKohaToMarc test should fail with something like:
    #   Failed test 'Check 260e'
    #   at t/db_dependent/Biblio/TransformKohaToMarc.t line 60.
    #          got: 'A'
    #     expected: 'A | B'

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Ere Maijala <ere.maijala@helsinki.fi>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
20.05.x
Marcel de Rooy 4 years ago
committed by Martin Renvoize
parent
commit
661702e669
Signed by: martin.renvoize GPG Key ID: 422B469130441A0F
  1. 14
      t/db_dependent/Biblio/TransformKohaToMarc.t
  2. 19
      t/db_dependent/Biblio/TransformMarcToKoha.t

14
t/db_dependent/Biblio/TransformKohaToMarc.t

@ -17,7 +17,7 @@ $schema->storage->txn_begin;
Koha::MarcSubfieldStructures->search({ frameworkcode => '', tagfield => '300', tagsubfield => 'a' })->delete;
Koha::MarcSubfieldStructure->new({ frameworkcode => '', tagfield => '300', tagsubfield => 'a', kohafield => "mytable.nicepages" })->store;
Koha::MarcSubfieldStructures->search({ frameworkcode => '', tagfield => '300', tagsubfield => 'b' })->delete;
Koha::MarcSubfieldStructure->new({ frameworkcode => '', tagfield => '300', tagsubfield => 'b', kohafield => "mytable2.goodillustrations" })->store;
Koha::MarcSubfieldStructure->new({ frameworkcode => '', tagfield => '300', tagsubfield => 'b', kohafield => "mytable2.goodillustrations", repeatable => 1 })->store;
Koha::Caches->get_instance->clear_from_cache( "MarcSubfieldStructure-" );
my $record = C4::Biblio::TransformKohaToMarc({
@ -40,20 +40,24 @@ is_deeply( \@subfields, [
# Now test multiple mappings per kohafield too
subtest "Multiple Koha to MARC mappings (BZ 10306)" => sub {
plan tests => 4;
plan tests => 5;
# Add260d mapping so that 300a and 260d both map to mytable.nicepages
Koha::MarcSubfieldStructures->search({ frameworkcode => '', tagfield => '260', tagsubfield => 'd' })->delete;
# Add 260d mapping so that 300a and 260d both map to mytable.nicepages
# Add 260e to test not-repeatable behavior
Koha::MarcSubfieldStructures->search({ frameworkcode => '', tagfield => '260' })->delete;
Koha::MarcSubfieldStructure->new({ frameworkcode => '', tagfield => '260', tagsubfield => 'd', kohafield => "mytable.nicepages" })->store;
Koha::MarcSubfieldStructure->new({ frameworkcode => '', tagfield => '260', tagsubfield => 'e', kohafield => "mytable.unrepeatable", repeatable => 0 })->store;
Koha::Caches->get_instance->clear_from_cache( "MarcSubfieldStructure-" );
# Include two values in goodillustrations too: should result in two
# subfields.
# subfields. But unrepeatable should result in one field.
my $record = C4::Biblio::TransformKohaToMarc({
"mytable2.goodillustrations" => "good | better",
"mytable.nicepages" => "nice",
"mytable.unrepeatable" => "A | B",
});
is( $record->subfield('260','d'), "nice", "Check 260d" );
is( $record->subfield('260','e'), "A | B", "Check 260e" );
is( $record->subfield('300','a'), "nice", "Check 300a" );
is( $record->subfield('300','b'), "good", "Check first 300b" );
is( ($record->field('300')->subfield('b'))[1], "better",

19
t/db_dependent/Biblio/TransformMarcToKoha.t

@ -19,7 +19,7 @@
# with Koha; if not, see <http://www.gnu.org/licenses>.
use Modern::Perl;
use Test::More tests => 3;
use Test::More tests => 4;
use MARC::Record;
use t::lib::Mocks;
@ -108,6 +108,23 @@ subtest 'Testing _adjust_pubyear' => sub {
is( C4::Biblio::_adjust_pubyear('198-?'), '1980', '198-?' );
};
subtest 'Test repeatable subfields' => sub {
plan tests => 2;
# Make 510x repeatable and 510y not
Koha::MarcSubfieldStructures->search({ frameworkcode => '', tagfield => '510' })->delete;
Koha::MarcSubfieldStructure->new({ frameworkcode => '', tagfield => '510', tagsubfield => 'x', kohafield => 'items.test', repeatable => 1 })->store;
Koha::MarcSubfieldStructure->new({ frameworkcode => '', tagfield => '510', tagsubfield => 'y', kohafield => 'items.norepeat', repeatable => 0 })->store;
Koha::Caches->get_instance->clear_from_cache( "MarcSubfieldStructure-" );
my $marc = MARC::Record->new;
$marc->append_fields( MARC::Field->new( '510', '', '', x => '1', x => '2', y => '3 | 4', y => '5' ) ); # actually, we should only have one $y (BZ 24652)
my $result = C4::Biblio::TransformMarcToKoha( $marc );
is( $result->{test}, '1 | 2', 'Check 510x for two values' );
is( $result->{norepeat}, '3 | 4 | 5', 'Check 510y too' );
};
# Cleanup
Koha::Caches->get_instance->clear_from_cache( "MarcSubfieldStructure-" );
$schema->storage->txn_rollback;

Loading…
Cancel
Save