Bug 28166: (QA follow-up) Fix and tidy tests and code

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Nick Clemens 2023-09-25 13:50:30 +00:00 committed by Tomas Cohen Arazi
parent 1e1616b993
commit a5d75c47e7
Signed by: tomascohen
GPG key ID: 0A272EA1B2F3C15F
3 changed files with 34 additions and 21 deletions

View file

@ -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;

View file

@ -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'";

View file

@ -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 {