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

(-)a/t/lib/TestBuilder.pm (-17 / +4 lines)
Lines 12-18 use Koha::DateUtils qw( dt_from_string ); Link Here
12
use Bytes::Random::Secure;
12
use Bytes::Random::Secure;
13
use Carp;
13
use Carp;
14
use Module::Load;
14
use Module::Load;
15
use String::Random;
15
use Text::Lorem;
16
16
17
use constant {
17
use constant {
18
    SIZE_BARCODE => 20, # Not perfect but avoid to fetch the value when creating a new item
18
    SIZE_BARCODE => 20, # Not perfect but avoid to fetch the value when creating a new item
Lines 504-525 sub _gen_datetime { Link Here
504
504
505
sub _gen_text {
505
sub _gen_text {
506
    my ($self, $params) = @_;
506
    my ($self, $params) = @_;
507
    # From perldoc String::Random
507
    my $text = Text::Lorem->new();
508
    my $words = $text->words(int(rand(10)));
508
    my $size = $params->{info}{size} // 10;
509
    my $size = $params->{info}{size} // 10;
509
    $size -= alt_rand(0.5 * $size);
510
    return length($words) > $size ? substr( $words, 1, $size ) : $words;
510
    my $regex = $size > 1
511
        ? '[A-Za-z][A-Za-z0-9_]{'.($size-1).'}'
512
        : '[A-Za-z]';
513
    my $random = String::Random->new( rand_gen => \&alt_rand );
514
    # rand_gen is only supported from 0.27 onward
515
    return $random->randregex($regex);
516
}
517
518
sub alt_rand { #Alternative randomizer
519
    my ($max) = @_;
520
    my $random = Bytes::Random::Secure->new( NonBlocking => 1 );
521
    my $r = $random->irand / 2**32;
522
    return int( $r * $max );
523
}
511
}
524
512
525
sub _gen_set_enum {
513
sub _gen_set_enum {
526
- 

Return to bug 24310