From 03c56ce495a8fac455acb8a1c523026481c0b7d2 Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Fri, 15 Dec 2017 09:46:54 +0100 Subject: [PATCH] Bug 19444: (QA follow-up) Fix tests for UNIMARC Signed-off-by: Julian Maurice Signed-off-by: Jonathan Druart Signed-off-by: Nick Clemens (cherry picked from commit e4aee4b799574736dfe62355e7d78bfa227e85a2) Signed-off-by: Fridolin Somers --- t/db_dependent/Circulation.t | 62 +++++++++++++++++------------------- 1 file changed, 30 insertions(+), 32 deletions(-) diff --git a/t/db_dependent/Circulation.t b/t/db_dependent/Circulation.t index 0abd9c0d45..359f7a9be2 100755 --- a/t/db_dependent/Circulation.t +++ b/t/db_dependent/Circulation.t @@ -217,14 +217,8 @@ C4::Context->dbh->do("DELETE FROM accountlines"); # CanBookBeRenewed tests # Generate test biblio - my $biblio = MARC::Record->new(); my $title = 'Silence in the library'; - $biblio->append_fields( - MARC::Field->new('100', ' ', ' ', a => 'Moffat, Steven'), - MARC::Field->new('245', ' ', ' ', a => $title), - ); - - my ($biblionumber, $biblioitemnumber) = AddBiblio($biblio, ''); + my ($biblionumber, $biblioitemnumber) = add_biblio($title, 'Moffat, Steven'); my $barcode = 'R00000342'; my $branch = $library2->{branchcode}; @@ -898,13 +892,8 @@ C4::Context->dbh->do("DELETE FROM accountlines"); my $branch = $library2->{branchcode}; #Create another record - my $biblio2 = MARC::Record->new(); my $title2 = 'Something is worng here'; - $biblio2->append_fields( - MARC::Field->new('100', ' ', ' ', a => 'Anonymous'), - MARC::Field->new('245', ' ', ' ', a => $title2), - ); - my ($biblionumber2, $biblioitemnumber2) = AddBiblio($biblio2, ''); + my ($biblionumber2, $biblioitemnumber2) = add_biblio($title2, 'Anonymous'); #Create third item AddItem( @@ -983,8 +972,7 @@ C4::Context->dbh->do("DELETE FROM accountlines"); my $barcode = '1234567890'; my $branch = $library2->{branchcode}; - my $biblio = MARC::Record->new(); - my ($biblionumber, $biblioitemnumber) = AddBiblio($biblio, ''); + my ($biblionumber, $biblioitemnumber) = add_biblio(); #Create third item my ( undef, undef, $itemnumber ) = AddItem( @@ -1040,8 +1028,7 @@ C4::Context->dbh->do("DELETE FROM accountlines"); undef, 0, .10, 1 ); - my $biblio = MARC::Record->new(); - my ( $biblionumber, $biblioitemnumber ) = AddBiblio( $biblio, '' ); + my ( $biblionumber, $biblioitemnumber ) = add_biblio(); my $barcode1 = '1234'; my ( undef, undef, $itemnumber1 ) = AddItem( @@ -1124,12 +1111,7 @@ C4::Context->dbh->do("DELETE FROM accountlines"); my $branch = $library->{branchcode}; #Create another record - my $biblio = MARC::Record->new(); - $biblio->append_fields( - MARC::Field->new('100', ' ', ' ', a => 'Anonymous'), - MARC::Field->new('245', ' ', ' ', a => 'A title'), - ); - my ($biblionumber, $biblioitemnumber) = AddBiblio($biblio, ''); + my ($biblionumber, $biblioitemnumber) = add_biblio('A title', 'Anonymous'); my (undef, undef, $itemnumber) = AddItem( { @@ -1158,8 +1140,7 @@ C4::Context->dbh->do("DELETE FROM accountlines"); { my $library = $builder->build({ source => 'Branch' }); - my $biblio = MARC::Record->new(); - my ($biblionumber, $biblioitemnumber) = AddBiblio($biblio, ''); + my ($biblionumber, $biblioitemnumber) = add_biblio(); my $barcode = 'just a barcode'; my ( undef, undef, $itemnumber ) = AddItem( @@ -1427,14 +1408,8 @@ subtest 'CanBookBeIssued + Koha::Patron->is_debarred|has_overdues' => sub { subtest 'MultipleReserves' => sub { plan tests => 3; - my $biblio = MARC::Record->new(); my $title = 'Silence in the library'; - $biblio->append_fields( - MARC::Field->new('100', ' ', ' ', a => 'Moffat, Steven'), - MARC::Field->new('245', ' ', ' ', a => $title), - ); - - my ($biblionumber, $biblioitemnumber) = AddBiblio($biblio, ''); + my ($biblionumber, $biblioitemnumber) = add_biblio($title, 'Moffat, Steven'); my $branch = $library2->{branchcode}; @@ -1781,3 +1756,26 @@ sub str { $s .= %$alert ? ' (alert: ' . join( ' ', keys %$alert ) . ')' : ''; return $s; } + +sub add_biblio { + my ($title, $author) = @_; + + my $marcflavour = C4::Context->preference('marcflavour'); + + my $biblio = MARC::Record->new(); + if ($title) { + my $tag = $marcflavour eq 'UNIMARC' ? '200' : '245'; + $biblio->append_fields( + MARC::Field->new($tag, ' ', ' ', a => $title), + ); + } + + if ($author) { + my ($tag, $code) = $marcflavour eq 'UNIMARC' ? (200, 'f') : (100, 'a'); + $biblio->append_fields( + MARC::Field->new($tag, ' ', ' ', $code => $author), + ); + } + + return AddBiblio($biblio, ''); +} -- 2.39.5