Bugzilla – Attachment 57463 Details for
Bug 15690
Unconstrained CardnumberLength preference conflicts with table column limit of 16
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 15690: Hardcoded 16 is uncool
Bug-15690-Hardcoded-16-is-uncool.patch (text/plain), 4.52 KB, created by
Tomás Cohen Arazi (tcohen)
on 2016-11-12 03:23:24 UTC
(
hide
)
Description:
Bug 15690: Hardcoded 16 is uncool
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2016-11-12 03:23:24 UTC
Size:
4.52 KB
patch
obsolete
>From 9ab15442a6c5ca55216abfeb16dc8000c1481eac Mon Sep 17 00:00:00 2001 >From: Mark Tompsett <mtompset@hotmail.com> >Date: Wed, 14 Sep 2016 15:14:02 -0400 >Subject: [PATCH] Bug 15690: Hardcoded 16 is uncool > >Signed-off-by: Mark Tompsett <mtompset@hotmail.com> > >Followed test plan in comment #7, works as expectd. >Signed-off-by: Marc <veron@veron.ch> >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >--- > C4/Members.pm | 5 ++++- > .../prog/en/modules/admin/preferences/patrons.pref | 2 +- > t/Members/cardnumber.t | 15 +++++++++++---- > 3 files changed, 16 insertions(+), 6 deletions(-) > >diff --git a/C4/Members.pm b/C4/Members.pm >index 287a270..9b44b32 100644 >--- a/C4/Members.pm >+++ b/C4/Members.pm >@@ -44,6 +44,7 @@ use Koha::Holds; > use Koha::List::Patron; > use Koha::Patrons; > use Koha::Patron::Categories; >+use Koha::Schema; > > our (@ISA,@EXPORT,@EXPORT_OK,$debug); > >@@ -1102,7 +1103,9 @@ sub get_cardnumber_length { > } > > } >- $min = 16 if $min > 16; >+ my $borrower = Koha::Schema->resultset('Borrower'); >+ my $field_size = $borrower->result_source->column_info('cardnumber')->{size}; >+ $min = $field_size if $min > $field_size; > return ( $min, $max ); > } > >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref >index d2eb139..e0e36d8 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref >@@ -165,7 +165,7 @@ Patrons: > - Card numbers for patrons must be > - pref: CardnumberLength > - "characters long. The length can be a single number to specify an exact length, a range separated by a comma (i.e., 'Min,Max'), or a maximum with no minimum (i.e., ',Max')." >- - "If 'cardnumber' is included in the BorrowerMandatoryField list, the minimum length, if not specified here, defaults to one. Maximum cannot be bigger than 16." >+ - "If 'cardnumber' is included in the BorrowerMandatoryField list, the minimum length, if not specified here, defaults to one. Maximum cannot be bigger than the database field size." > - > - pref: useDischarge > choices: >diff --git a/t/Members/cardnumber.t b/t/Members/cardnumber.t >index deb76de..af3a4bb 100644 >--- a/t/Members/cardnumber.t >+++ b/t/Members/cardnumber.t >@@ -5,6 +5,7 @@ use Test::More tests => 25; > > use t::lib::Mocks; > >+use Koha::Schema; > use_ok('C4::Members'); > > BEGIN { >@@ -14,6 +15,9 @@ BEGIN { > my $dbh = C4::Context->dbh; > my $rs = []; > >+my $borrower = Koha::Schema->resultset('Borrower'); >+my $cardnumber_size = $borrower->result_source->column_info('cardnumber')->{size}; >+ > t::lib::Mocks::mock_preference('BorrowerMandatoryField', ''); > my $pref = "10"; > t::lib::Mocks::mock_preference('CardnumberLength', $pref); >@@ -49,7 +53,7 @@ is( C4::Members::checkcardnumber( q{1234567890} ), 0, "1234567890 matches $pref" > > $pref = q|8,|; # At least 8 chars > t::lib::Mocks::mock_preference('CardnumberLength', $pref); >-is_deeply( [ C4::Members::get_cardnumber_length() ], [ 8, 16 ], '8, => min=8 and max=16'); >+is_deeply( [ C4::Members::get_cardnumber_length() ], [ 8, $cardnumber_size ], "8, => min=8 and max=$cardnumber_size"); > $dbh->{mock_add_resultset} = $rs; > is( C4::Members::checkcardnumber( q{1234567} ), 2, "1234567 is shorter than $pref"); > $dbh->{mock_add_resultset} = $rs; >@@ -67,11 +71,14 @@ is( C4::Members::checkcardnumber( q{1234567890123456} ), 2, "1234567890123456 is > $dbh->{mock_add_resultset} = $rs; > is( C4::Members::checkcardnumber( q{1234567890} ), 2, "1234567890 is longer than $pref"); > >-$pref = q|,40|; # max 40 chars, not allowed >+$pref = sprintf(',%d', $cardnumber_size+1); > t::lib::Mocks::mock_preference('CardnumberLength', $pref); >-is_deeply( [ C4::Members::get_cardnumber_length() ], [ 0, 16 ], ',40 => min=0 and max=16'); >+is_deeply( [ C4::Members::get_cardnumber_length() ], [ 0, $cardnumber_size ], >+ sprintf(",%d => min=0 and max=%d",$cardnumber_size+1,$cardnumber_size) ); > $dbh->{mock_add_resultset} = $rs; >-is( C4::Members::checkcardnumber( q{12345678901234567890} ), 2, "12345678901234567890 is longer than $pref => 16 is max!"); >+ >+my $generated_cardnumber = sprintf("%s1234567890",q|9|x$cardnumber_size); >+is( C4::Members::checkcardnumber( $generated_cardnumber ), 2, "$generated_cardnumber is longer than $pref => $cardnumber_size is max!"); > > $pref = q|,8|; # max 8 chars > t::lib::Mocks::mock_preference('CardnumberLength', $pref); >-- >2.10.2
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 15690
:
55540
|
55573
|
55575
|
55576
|
55620
|
55621
|
57462
| 57463