556eb67718
This patch finishes the work started in one of the previous follow-ups and allows CardnumberLength to be set to a value like ',5'. In conjunction with not including cardnumber in BorrowerMandatoryField, this allows a cardnumber to not be required but, if present, to not exceed the specified length. This patch also updates t/db_dependent/Members.t so that it runs in a transaction, tests the new return value of checkcardnumber, and manages the CardnumberLength syspref. To test: [1] Verify that prove -v t/db_dependent/Members.t and prove -v t/Members/cardnumber.t pass. [2] Set CardnumberLength to ",5" and take cardnubmer out of the BorrowerMandatoryField list. [3] Verify that you can save a patron record without a cardnumber, but if you supply one, that it can be at most 5 characters long. [4] Add cardnumber back to BorrowerMandatoryField. This time, the minimum length is 1 even though CardnumberLength is ",5". Signed-off-by: Galen Charlton <gmc@esilibrary.com>
79 lines
3.5 KiB
Perl
79 lines
3.5 KiB
Perl
#!/usr/bin/env perl
|
|
|
|
use Modern::Perl;
|
|
use Test::More tests => 23;
|
|
|
|
use Test::MockModule;
|
|
use DBD::Mock;
|
|
use t::lib::Mocks;
|
|
|
|
use_ok('C4::Members');
|
|
|
|
my $module_context = new Test::MockModule('C4::Context');
|
|
$module_context->mock(
|
|
'_new_dbh',
|
|
sub {
|
|
my $dbh = DBI->connect( 'DBI:Mock:', '', '' )
|
|
|| die "Cannot create handle: $DBI::errstr\n";
|
|
return $dbh;
|
|
}
|
|
);
|
|
|
|
my $dbh = C4::Context->dbh;
|
|
my $rs = [];
|
|
|
|
t::lib::Mocks::mock_preference('BorrowerMandatoryField', '');
|
|
my $pref = "10";
|
|
t::lib::Mocks::mock_preference('CardnumberLength', $pref);
|
|
is_deeply( [ C4::Members::get_cardnumber_length() ], [ 10, 10 ], '10 => min=10 and max=10');
|
|
$dbh->{mock_add_resultset} = $rs;
|
|
is( C4::Members::checkcardnumber( q{123456789} ), 2, "123456789 is shorter than $pref");
|
|
$dbh->{mock_add_resultset} = $rs;
|
|
is( C4::Members::checkcardnumber( q{1234567890123456} ), 2, "1234567890123456 is longer than $pref");
|
|
$dbh->{mock_add_resultset} = $rs;
|
|
is( C4::Members::checkcardnumber( q{1234567890} ), 0, "1234567890 is equal to $pref");
|
|
|
|
$pref = q|10,10|; # Same as before !
|
|
t::lib::Mocks::mock_preference('CardnumberLength', $pref);
|
|
is_deeply( [ C4::Members::get_cardnumber_length() ], [ 10, 10 ], '10,10 => min=10 and max=10');
|
|
$dbh->{mock_add_resultset} = $rs;
|
|
is( C4::Members::checkcardnumber( q{123456789} ), 2, "123456789 is shorter than $pref");
|
|
$dbh->{mock_add_resultset} = $rs;
|
|
is( C4::Members::checkcardnumber( q{1234567890123456} ), 2, "1234567890123456 is longer than $pref");
|
|
$dbh->{mock_add_resultset} = $rs;
|
|
is( C4::Members::checkcardnumber( q{1234567890} ), 0, "1234567890 is equal to $pref");
|
|
|
|
$pref = q|8,10|; # between 8 and 10 chars
|
|
t::lib::Mocks::mock_preference('CardnumberLength', $pref);
|
|
is_deeply( [ C4::Members::get_cardnumber_length() ], [ 8, 10 ], '8,10 => min=8 and max=10');
|
|
$dbh->{mock_add_resultset} = $rs;
|
|
is( C4::Members::checkcardnumber( q{12345678} ), 0, "12345678 matches $pref");
|
|
$dbh->{mock_add_resultset} = $rs;
|
|
is( C4::Members::checkcardnumber( q{1234567890123456} ), 2, "1234567890123456 is longer than $pref");
|
|
$dbh->{mock_add_resultset} = $rs;
|
|
is( C4::Members::checkcardnumber( q{1234567} ), 2, "1234567 is shorter than $pref");
|
|
$dbh->{mock_add_resultset} = $rs;
|
|
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');
|
|
$dbh->{mock_add_resultset} = $rs;
|
|
is( C4::Members::checkcardnumber( q{1234567} ), 2, "1234567 is shorter than $pref");
|
|
$dbh->{mock_add_resultset} = $rs;
|
|
is( C4::Members::checkcardnumber( q{1234567890123456} ), 0, "1234567890123456 matches $pref");
|
|
$dbh->{mock_add_resultset} = $rs;
|
|
is( C4::Members::checkcardnumber( q{1234567890} ), 0, "1234567890 matches $pref");
|
|
|
|
$pref = q|,8|; # max 8 chars
|
|
t::lib::Mocks::mock_preference('CardnumberLength', $pref);
|
|
is_deeply( [ C4::Members::get_cardnumber_length() ], [ 0, 8 ], ',8 => min=0 and max=8');
|
|
$dbh->{mock_add_resultset} = $rs;
|
|
is( C4::Members::checkcardnumber( q{1234567} ), 0, "1234567 matches $pref");
|
|
$dbh->{mock_add_resultset} = $rs;
|
|
is( C4::Members::checkcardnumber( q{1234567890123456} ), 2, "1234567890123456 is longer than $pref");
|
|
$dbh->{mock_add_resultset} = $rs;
|
|
is( C4::Members::checkcardnumber( q{1234567890} ), 2, "1234567890 is longer than $pref");
|
|
|
|
t::lib::Mocks::mock_preference('BorrowerMandatoryField', 'cardnumber');
|
|
is_deeply( [ C4::Members::get_cardnumber_length() ], [ 1, 8 ], ',8 => min=1 and max=8 if cardnumber is mandatory');
|