From e98868bcd3ff2692d6eb267345a4104eee2e72b8 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Mon, 25 Sep 2023 13:50:30 +0000 Subject: [PATCH] Bug 28166: (QA follow-up) Fix and tidy tests and code Signed-off-by: Jonathan Druart --- C4/Breeding.pm | 3 +- .../data/mysql/atomicupdate/bug_28166.pl | 14 ++++--- t/db_dependent/Breeding.t | 38 +++++++++++-------- 3 files changed, 34 insertions(+), 21 deletions(-) diff --git a/C4/Breeding.pm b/C4/Breeding.pm index b441e4d6fb..8dbaae9fff 100644 --- a/C4/Breeding.pm +++ b/C4/Breeding.pm @@ -315,7 +315,7 @@ sub _handle_one_result { $row->{breedingid} = $breedingid; $row->{isbn}=_isbn_replace($row->{isbn}); my $pref_newtags = C4::Context->preference('AdditionalFieldsInZ3950ResultSearch'); - $row = _add_custom_field_rowdata($row, $marcrecord, $pref_newtags); + $row = _add_custom_field_rowdata( $row, $marcrecord, $pref_newtags ); } return ( $row, $error ); } @@ -347,6 +347,7 @@ sub _do_xslt_proc { sub _add_custom_field_rowdata { my ( $row, $record, $pref_newtags ) = @_; + $pref_newtags //= ''; my $pref_flavour = C4::Context->preference('MarcFlavour'); $pref_newtags =~ s/^\s+|\s+$//g; diff --git a/installer/data/mysql/atomicupdate/bug_28166.pl b/installer/data/mysql/atomicupdate/bug_28166.pl index 1939efcd5f..ea99ac1d54 100755 --- a/installer/data/mysql/atomicupdate/bug_28166.pl +++ b/installer/data/mysql/atomicupdate/bug_28166.pl @@ -1,15 +1,19 @@ use Modern::Perl; return { - bug_number => "28166", + bug_number => "28166", description => "Add system preference for additional columns for Z39.50 authority search results", - up => sub { + up => sub { my ($args) = @_; - my ($dbh, $out) = @$args{qw(dbh out)}; + my ( $dbh, $out ) = @$args{qw(dbh out)}; + # Do you stuffs here - $dbh->do(q{INSERT IGNORE INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES + $dbh->do( + q{INSERT IGNORE INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES ('AdditionalFieldsInZ3950ResultAuthSearch', '', NULL, 'Determines which MARC field/subfields are displayed in -Additional field- column in the result of an authority Z39.50 search', 'Free') -}); +} + ); + # Print useful stuff here # sysprefs say $out "Added new system preference 'AdditionalFieldsInZ3950ResultAuthSearch'"; diff --git a/t/db_dependent/Breeding.t b/t/db_dependent/Breeding.t index dd0af9b728..c88763076b 100755 --- a/t/db_dependent/Breeding.t +++ b/t/db_dependent/Breeding.t @@ -56,7 +56,7 @@ subtest '_do_xslt_proc' => sub { }; #Group 4: testing _add_custom_field_rowdata (part of Z3950Search) subtest '_add_custom_field_rowdata' => sub { - plan tests => 3; + plan tests => 5; test_add_custom_field_rowdata(); }; @@ -237,28 +237,36 @@ sub test_do_xslt { sub test_add_custom_field_rowdata { my $row = { - biblionumber => 0, - server => "testServer", - breedingid => 0, - title => "Just a title" - }; + biblionumber => 0, + server => "testServer", + breedingid => 0, + title => "Just a title" + }; my $biblio = MARC::Record->new(); $biblio->append_fields( - MARC::Field->new('245', ' ', ' ', a => 'Just a title'), - MARC::Field->new('035', ' ', ' ', a => 'First 035'), - MARC::Field->new('035', ' ', ' ', a => 'Second 035') + MARC::Field->new( '245', ' ', ' ', a => 'Just a title' ), + MARC::Field->new( '035', ' ', ' ', a => 'First 035' ), + MARC::Field->new( '035', ' ', ' ', a => 'Second 035' ) ); - t::lib::Mocks::mock_preference('AdditionalFieldsInZ3950ResultSearch',"245\$a, 035\$a"); + my $pref_newtags = "245\$a, 035\$a"; - my $returned_row = C4::Breeding::_add_custom_field_rowdata($row, $biblio); + my $returned_row = C4::Breeding::_add_custom_field_rowdata( $row, $biblio, $pref_newtags ); + + is( $returned_row->{title}, "Just a title", "_add_rowdata returns the title of a biblio" ); + is( + $returned_row->{addnumberfields}[0], "245\$a", + "_add_rowdata returns the field number chosen in the AdditionalFieldsInZ3950ResultSearch preference" + ); - is($returned_row->{title}, "Just a title", "_add_rowdata returns the title of a biblio"); - is($returned_row->{addnumberfields}[0], "245\$a", "_add_rowdata returns the field number chosen in the AdditionalFieldsInZ3950ResultSearch preference"); + # Test repeatble tags,the trailing whitespace is a normal side-effect of _add_custom_field_row_data + is_deeply( \$returned_row->{"035\$a"}, \[ "First 035 ", "Second 035 " ], "_add_rowdata supports repeatable tags" ); - # Test repeatble tags,the trailing whitespace is a normal side-effect of _add_custom_field_row_data - is_deeply(\$returned_row->{"035\$a"}, \["First 035 ", "Second 035 "],"_add_rowdata supports repeatable tags"); + warning_is { C4::Breeding::_add_custom_field_rowdata( $row, $biblio, undef ) } undef, + 'no warn from add_custom_field_rowdata when pref_newtags undef'; + warning_is { C4::Breeding::_add_custom_field_rowdata( $row, $biblio, "" ) } undef, + 'no warn from add_custom_field_rowdata when pref_newtags blank'; } sub xsl_file { -- 2.30.2