From b244a74fe1a9c7d40a63f915f2fed401e46a693a Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Sat, 21 Dec 2019 12:13:41 +0100 Subject: [PATCH] Bug 24310: Use Text::Lorem instead of String::Random (new dependency) --- t/lib/TestBuilder.pm | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/t/lib/TestBuilder.pm b/t/lib/TestBuilder.pm index 7e70f29c9e4..c46ed4c7e02 100644 --- a/t/lib/TestBuilder.pm +++ b/t/lib/TestBuilder.pm @@ -11,8 +11,8 @@ use Koha::DateUtils qw( dt_from_string ); use Bytes::Random::Secure; use Carp qw( carp ); use Module::Load qw( load ); -use String::Random; use Array::Utils qw( array_minus ); +use Text::Lorem; use constant { SIZE_BARCODE => 20, # Not perfect but avoid to fetch the value when creating a new item @@ -538,22 +538,10 @@ sub _gen_datetime { sub _gen_text { my ($self, $params) = @_; - # From perldoc String::Random + my $text = Text::Lorem->new(); + my $words = $text->words(int(rand(10))); my $size = $params->{info}{size} // 10; - $size -= alt_rand(0.5 * $size); - my $regex = $size > 1 - ? '[A-Za-z][A-Za-z0-9_]{'.($size-1).'}' - : '[A-Za-z]'; - my $random = String::Random->new( rand_gen => \&alt_rand ); - # rand_gen is only supported from 0.27 onward - return $random->randregex($regex); -} - -sub alt_rand { #Alternative randomizer - my ($max) = @_; - my $random = Bytes::Random::Secure->new( NonBlocking => 1 ); - my $r = $random->irand / 2**32; - return int( $r * $max ); + return length($words) > $size ? substr( $words, 1, $size ) : $words; } sub _gen_set_enum { -- 2.25.1