Bugzilla – Attachment 39340 Details for
Bug 14195
TestBuilder does not generate the good length for text fields
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 14195: TestBuilder - A random string should not be longer than the DB field
Bug-14195-TestBuilder---A-random-string-should-not.patch (text/plain), 2.42 KB, created by
Marcel de Rooy
on 2015-05-20 11:18:38 UTC
(
hide
)
Description:
Bug 14195: TestBuilder - A random string should not be longer than the DB field
Filename:
MIME Type:
Creator:
Marcel de Rooy
Created:
2015-05-20 11:18:38 UTC
Size:
2.42 KB
patch
obsolete
>From c988317de26209d9e376b4e94954d7b37d4d52b4 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@koha-community.org> >Date: Wed, 13 May 2015 16:39:59 +0200 >Subject: [PATCH] Bug 14195: TestBuilder - A random string should not be > longer than the DB field >Content-Type: text/plain; charset=utf-8 > >t::lib::TestBuilder::_gen_text does not use correctly the regex and the >max parameter to generate the random string (String::Random). > >This can cause future tests to fail. > >http://bugs.koha-community.org/show_bug.cgi?id=14195 >Signed-off-by: Bernardo Gonzalez Kriegel <bgkriegel@gmail.com> > >Script tested, problem occurs, patch fixes it. >Bad number on commit subject >No errors > >Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >--- > t/db_dependent/TestBuilder.t | 1 + > t/lib/TestBuilder.pm | 14 ++++++++++++-- > 2 files changed, 13 insertions(+), 2 deletions(-) > >diff --git a/t/db_dependent/TestBuilder.t b/t/db_dependent/TestBuilder.t >index 6110bea..6635a0b 100644 >--- a/t/db_dependent/TestBuilder.t >+++ b/t/db_dependent/TestBuilder.t >@@ -236,6 +236,7 @@ is( $bookseller_result->in_storage, 1, 'build with only_fk = 1 creates the forei > $bookseller = $builder->build({ > source => 'Aqbookseller', > }); >+ok( length( $bookseller->{phone} ) <= 30, 'The length for a generated string should not be longer than the size of the DB field' ); > delete $bookseller->{_fk}; > $bookseller_from_db = $rs_aqbookseller->find($bookseller); > is( $bookseller_from_db->in_storage, 1, 'build without the parameter only_sk stores the entry correctly' ); >diff --git a/t/lib/TestBuilder.pm b/t/lib/TestBuilder.pm >index 2497ffd..72364e3 100644 >--- a/t/lib/TestBuilder.pm >+++ b/t/lib/TestBuilder.pm >@@ -288,8 +288,18 @@ sub _gen_date { > > sub _gen_text { > my ($self, $params) = @_; >- my $random = String::Random->new( max => $params->{info}->{size} ); >- return $random->randregex('[A-Za-z]+[A-Za-z0-9_]*'); >+ # From perldoc String::Random >+ # max: specify the maximum number of characters to return for * and other >+ # regular expression patters that don't return a fixed number of characters >+ my $regex = '[A-Za-z][A-Za-z0-9_]*'; >+ my $size = $params->{info}{size}; >+ if ( defined $size and $size > 1 ) { >+ $size--; >+ } elsif ( defined $size and $size == 1 ) { >+ $regex = '[A-Za-z]'; >+ } >+ my $random = String::Random->new( max => $size ); >+ return $random->randregex($regex); > } > > sub _gen_set_enum { >-- >1.7.10.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 14195
:
39138
|
39139
|
39200
|
39201
| 39340 |
39341