From 9bcd5393b413c6c59519738811d1b07d8fe61c5a Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Thu, 13 Feb 2020 11:55:32 +0000 Subject: [PATCH] Bug 21800: Add tests for repeatable subfields Content-Type: text/plain; charset=utf-8 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 --- t/db_dependent/Biblio/TransformKohaToMarc.t | 14 +++++++++----- t/db_dependent/Biblio/TransformMarcToKoha.t | 19 ++++++++++++++++++- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/t/db_dependent/Biblio/TransformKohaToMarc.t b/t/db_dependent/Biblio/TransformKohaToMarc.t index 90b4d847dd..f1b203b3bf 100644 --- a/t/db_dependent/Biblio/TransformKohaToMarc.t +++ b/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", diff --git a/t/db_dependent/Biblio/TransformMarcToKoha.t b/t/db_dependent/Biblio/TransformMarcToKoha.t index b9c02a8cc9..8d1e94c1eb 100644 --- a/t/db_dependent/Biblio/TransformMarcToKoha.t +++ b/t/db_dependent/Biblio/TransformMarcToKoha.t @@ -19,7 +19,7 @@ # with Koha; if not, see . 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; -- 2.11.0