Bug 17600: Standardize our EXPORT_OK
[srvgit] / t / lib / TestBuilder.pm
index a39be70..e8b0dbf 100644 (file)
@@ -2,16 +2,15 @@ package t::lib::TestBuilder;
 
 use Modern::Perl;
 
-use Koha::Database;
-use C4::Biblio;
-use C4::Items;
-use Koha::Biblios;
-use Koha::Items;
+use Koha::Database qw( schema );
+use C4::Biblio qw( AddBiblio );
+use Koha::Biblios qw( _type );
+use Koha::Items qw( _type );
 use Koha::DateUtils qw( dt_from_string );
 
 use Bytes::Random::Secure;
-use Carp;
-use Module::Load;
+use Carp qw( carp );
+use Module::Load qw( load );
 use String::Random;
 
 use constant {
@@ -231,8 +230,15 @@ sub _create_links {
     if( $cnt_scalar == @$keys ) {
         # if one or more fk cols are null, the FK constraint will not be forced
         return {} if $cnt_null > 0;
+
         # does the record exist already?
-        return {} if $self->schema->resultset($linked_tbl)->find( $fk_value );
+        my @pks = $self->schema->source( $linked_tbl )->primary_columns;
+        my %fk_pk_value;
+        for (@pks) {
+            $fk_pk_value{$_} = $fk_value->{$_} if defined $fk_value->{$_};
+        }
+        return {} if !(keys %fk_pk_value);
+        return {} if $self->schema->resultset($linked_tbl)->find( \%fk_pk_value );
     }
     # create record with a recursive build call
     my $row = $self->build({ source => $linked_tbl, value => $fk_value });
@@ -585,7 +591,10 @@ sub _gen_default_values {
         },
         AuthHeader => {
             marcxml => '',
-        }
+        },
+        BorrowerAttributeType => {
+            mandatory => 0,
+        },
     };
 }