From e2d1109692933e0fb88ac08613014e9dcdbd9d2f Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Fri, 25 Jun 2021 07:47:30 +0000 Subject: [PATCH] Bug 28384: (QA follow-up) Rearranging unit tests Content-Type: text/plain; charset=utf-8 This does two things: [1] Rearranging makes clearing the cache twice no longer needed. [2] Preparing the ground for an additional refinement in the TransformMarcToKoha routine. Test plan: Run TransformMarcToKoha.t. Should fail now for: not ok 1 - Biblio field 510a not ok 5 - Biblio field returned when "no_items" passed Signed-off-by: Marcel de Rooy --- t/db_dependent/Biblio/TransformMarcToKoha.t | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/t/db_dependent/Biblio/TransformMarcToKoha.t b/t/db_dependent/Biblio/TransformMarcToKoha.t index 1a08ded4f0..12f8babcd2 100755 --- a/t/db_dependent/Biblio/TransformMarcToKoha.t +++ b/t/db_dependent/Biblio/TransformMarcToKoha.t @@ -110,30 +110,34 @@ subtest 'Testing _adjust_pubyear' => sub { is( C4::Biblio::_adjust_pubyear('broken'), undef, 'Non-matchign data returns nothing as the field must be int' ); }; -subtest 'Test repeatable subfields' => sub { - plan tests => 5; +subtest 'Test repeatable subfields and no_items parameter' => sub { + plan tests => 7; # 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; + # Add 510a, 510b biblio fields + Koha::MarcSubfieldStructure->new({ frameworkcode => '', tagfield => '510', tagsubfield => 'a', kohafield => 'biblio.field1' })->store; + Koha::MarcSubfieldStructure->new({ frameworkcode => '', tagfield => '510', tagsubfield => 'b', kohafield => 'biblio.field2' })->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) + $marc->append_fields( MARC::Field->new( '510', '', '', a => '0', b => '', x => '1', x => '2', y => '3 | 4', y => '5' ) ); + # actually, we should only have one $y (BZ 24652) + # By adding '0' in $a and empty string in $b, we are testing a small adjustment in TransformMarcToKohaOneField too my $result = C4::Biblio::TransformMarcToKoha( $marc ); + is( $result->{field1}, '0', 'Biblio field 510a' ); + is( exists $result->{field2}, '', 'No field for empty string expected' ); is( $result->{test}, '1 | 2', 'Check 510x for two values' ); is( $result->{norepeat}, '3 | 4 | 5', 'Check 510y too' ); - Koha::MarcSubfieldStructure->new({ frameworkcode => '', tagfield => '510', tagsubfield => 'a', kohafield => 'biblio.field1' })->store; - Koha::Caches->get_instance->clear_from_cache( "MarcSubfieldStructure-" ); - $marc->append_fields( MARC::Field->new( '510', '', '', a => '1' ) ); # actually, we should only have one $y (BZ 24652) - + # Now test no_items parameter $result = C4::Biblio::TransformMarcToKoha( $marc, '', 'no_items' ); + is( $result->{field1}, '0', 'Biblio field returned when "no_items" passed' ); is( $result->{test}, undef, 'Item field not returned when "no_items" passed' ); is( $result->{norepeat}, undef, 'Item field not returned when "no_items" passed' ); - is( $result->{field1}, 1, 'Biblio field returned when "no_items" passed' ); }; # Cleanup -- 2.20.1