Bug 21798: Unify the creation of bibliographic record in tests
[koha.git] / t / lib / TestBuilder.pm
index 452d21e..d972437 100644 (file)
@@ -3,6 +3,8 @@ package t::lib::TestBuilder;
 use Modern::Perl;
 
 use Koha::Database;
+use C4::Biblio;
+use Koha::Biblios;
 
 use Bytes::Random::Secure;
 use Carp;
@@ -128,16 +130,31 @@ sub build {
 sub gimme_a_biblio {
     my ( $self, $args ) = @_;
 
-    my $itemtype = $args->{itemtype} || $self->build_object({ class => 'Koha::ItemTypes' })->itemtype;
-    my $title    = $args->{title}    || 'Some boring read';
+    my $title  = $args->{title}  || 'Some boring read';
+    my $author = $args->{author} || 'Some boring author';
+    my $frameworkcode = $args->{frameworkcode} || '';
+    my $itemtype = $args->{itemtype}
+      || $self->build_object( { class => 'Koha::ItemTypes' } )->itemtype;
+
+    my $marcflavour = C4::Context->preference('marcflavour');
 
     my $record = MARC::Record->new();
+    my ( $tag, $subfield ) = $marcflavour eq 'UNIMARC' ? ( 200, 'a' ) : ( 245, 'a' );
+    $record->append_fields(
+        MARC::Field->new( $tag, ' ', ' ', $subfield => $title ),
+    );
+
+    ( $tag, $subfield ) = $marcflavour eq 'UNIMARC' ? ( 200, 'f' ) : ( 100, 'a' );
+    $record->append_fields(
+        MARC::Field->new( $tag, ' ', ' ', $subfield => $author ),
+    );
+
+    ( $tag, $subfield ) = $marcflavour eq 'UNIMARC' ? ( 995, 'r' ) : ( 942, 'c' );
     $record->append_fields(
-        MARC::Field->new( '245', ' ', ' ', a => $title ),
-        MARC::Field->new( '942', ' ', ' ', c => $itemtype )
+        MARC::Field->new( $tag, ' ', ' ', $subfield => $itemtype )
     );
 
-    my ($biblio_id) = AddBiblio( $record, '' );
+    my ($biblio_id) = C4::Biblio::AddBiblio( $record, $frameworkcode );
     return Koha::Biblios->find($biblio_id);
 }