Koha/t/Members/cardnumber.t
Jonathan Druart 87380d8b46 Bug 15690: CardnumberLength should not be bigger than 16
borrowers.cardnumber is a varchar(16), so CardnumberLength should not
have a max > 16

Test plan:
Test different value in CardnumberLength ("20", "20,30", "40,")
Edit a patron a make sure the text display under the cardnumber input is
correct

Signed-off-by: Mark Tompsett <mtompset@hotmail.com>
Signed-off-by: Marc <veron@veron.ch>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
2016-11-14 11:28:42 +00:00

79 lines
3.7 KiB
Perl

#!/usr/bin/env perl
use Modern::Perl;
use Test::More tests => 25;
use t::lib::Mocks;
use_ok('C4::Members');
BEGIN {
t::lib::Mocks::mock_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");
$pref = q|,40|; # max 40 chars, not allowed
t::lib::Mocks::mock_preference('CardnumberLength', $pref);
is_deeply( [ C4::Members::get_cardnumber_length() ], [ 0, 16 ], ',40 => min=0 and max=16');
$dbh->{mock_add_resultset} = $rs;
is( C4::Members::checkcardnumber( q{12345678901234567890} ), 2, "12345678901234567890 is longer than $pref => 16 is max!");
$pref = q|,8|; # max 8 chars
t::lib::Mocks::mock_preference('CardnumberLength', $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');