View | Details | Raw Unified | Return to bug 14256
Collapse All | Expand All

(-)a/t/lib/TestBuilder.pm (-9 / +26 lines)
Lines 1-9 Link Here
1
package t::lib::TestBuilder;
1
package t::lib::TestBuilder;
2
2
3
use Modern::Perl;
3
use Modern::Perl;
4
4
use Koha::Database;
5
use Koha::Database;
5
use String::Random;
6
use String::Random;
6
7
use List::MoreUtils qw(any);
7
8
8
my $gen_type = {
9
my $gen_type = {
9
    tinyint   => \&_gen_int,
10
    tinyint   => \&_gen_int,
Lines 34-39 my $gen_type = { Link Here
34
    mediumblob => \&_gen_blob,
35
    mediumblob => \&_gen_blob,
35
    blob       => \&_gen_blob,
36
    blob       => \&_gen_blob,
36
    longblob   => \&_gen_blob,
37
    longblob   => \&_gen_blob,
38
37
};
39
};
38
40
39
our $default_value = {
41
our $default_value = {
Lines 238-254 sub _buildColumnValue { Link Here
238
        $col_value = $default_value->{$source}->{$col_name};
240
        $col_value = $default_value->{$source}->{$col_name};
239
    }
241
    }
240
    elsif( not $col_info->{default_value} and not $col_info->{is_auto_increment} and not $col_info->{is_foreign_key} ) {
242
    elsif( not $col_info->{default_value} and not $col_info->{is_auto_increment} and not $col_info->{is_foreign_key} ) {
241
        eval {
243
242
            my $data_type = $col_info->{data_type};
244
        my $data_type = $col_info->{data_type};
243
            $data_type =~ s| |_|;
245
        $data_type =~ s| |_|;
244
            $col_value = $gen_type->{$data_type}->( $self, { info => $col_info } );
246
245
        };
247
        if ( any { $data_type eq $_ } (keys $gen_type) ) {
246
        die "The type $col_info->{data_type} is not defined\n" if ($@);
248
            my $value_ok = 'no';
249
            while ( $value_ok eq 'no' ) {
250
                # generate value
251
                $col_value = $gen_type->{$data_type}->( $self, { info => $col_info } );
252
                # should value be unique?
253
                my $primary_names = $self->schema->source($source)->primary_columns();
254
                if ( not ( any { $col_name eq $_ } $primary_names and
255
                       $self->schema
256
                            ->resultset($source)
257
                            ->search({ $col_name => $col_value })
258
                            ->count > 0 ) ) {
259
260
                    $value_ok = 'yes';
261
                }
262
            }
263
      } else {
264
          die "The type $col_info->{data_type} is not defined\n";
265
      }
247
    }
266
    }
248
    return $col_value;
267
    return $col_value;
249
}
268
}
250
269
251
252
sub _gen_int {
270
sub _gen_int {
253
    my ($self, $params) = @_;
271
    my ($self, $params) = @_;
254
    my $data_type = $params->{info}->{data_type};
272
    my $data_type = $params->{info}->{data_type};
255
- 

Return to bug 14256