Lines 5-10
use Test::More tests => 25;
Link Here
|
5 |
|
5 |
|
6 |
use t::lib::Mocks; |
6 |
use t::lib::Mocks; |
7 |
|
7 |
|
|
|
8 |
use Koha::Schema; |
8 |
use_ok('C4::Members'); |
9 |
use_ok('C4::Members'); |
9 |
|
10 |
|
10 |
BEGIN { |
11 |
BEGIN { |
Lines 14-19
BEGIN {
Link Here
|
14 |
my $dbh = C4::Context->dbh; |
15 |
my $dbh = C4::Context->dbh; |
15 |
my $rs = []; |
16 |
my $rs = []; |
16 |
|
17 |
|
|
|
18 |
my $borrower = Koha::Schema->resultset('Borrower'); |
19 |
my $cardnumber_size = $borrower->result_source->column_info('cardnumber')->{size}; |
20 |
|
17 |
t::lib::Mocks::mock_preference('BorrowerMandatoryField', ''); |
21 |
t::lib::Mocks::mock_preference('BorrowerMandatoryField', ''); |
18 |
my $pref = "10"; |
22 |
my $pref = "10"; |
19 |
t::lib::Mocks::mock_preference('CardnumberLength', $pref); |
23 |
t::lib::Mocks::mock_preference('CardnumberLength', $pref); |
Lines 49-55
is( C4::Members::checkcardnumber( q{1234567890} ), 0, "1234567890 matches $pref"
Link Here
|
49 |
|
53 |
|
50 |
$pref = q|8,|; # At least 8 chars |
54 |
$pref = q|8,|; # At least 8 chars |
51 |
t::lib::Mocks::mock_preference('CardnumberLength', $pref); |
55 |
t::lib::Mocks::mock_preference('CardnumberLength', $pref); |
52 |
is_deeply( [ C4::Members::get_cardnumber_length() ], [ 8, 16 ], '8, => min=8 and max=16'); |
56 |
is_deeply( [ C4::Members::get_cardnumber_length() ], [ 8, $cardnumber_size ], "8, => min=8 and max=$cardnumber_size"); |
53 |
$dbh->{mock_add_resultset} = $rs; |
57 |
$dbh->{mock_add_resultset} = $rs; |
54 |
is( C4::Members::checkcardnumber( q{1234567} ), 2, "1234567 is shorter than $pref"); |
58 |
is( C4::Members::checkcardnumber( q{1234567} ), 2, "1234567 is shorter than $pref"); |
55 |
$dbh->{mock_add_resultset} = $rs; |
59 |
$dbh->{mock_add_resultset} = $rs; |
Lines 67-77
is( C4::Members::checkcardnumber( q{1234567890123456} ), 2, "1234567890123456 is
Link Here
|
67 |
$dbh->{mock_add_resultset} = $rs; |
71 |
$dbh->{mock_add_resultset} = $rs; |
68 |
is( C4::Members::checkcardnumber( q{1234567890} ), 2, "1234567890 is longer than $pref"); |
72 |
is( C4::Members::checkcardnumber( q{1234567890} ), 2, "1234567890 is longer than $pref"); |
69 |
|
73 |
|
70 |
$pref = q|,40|; # max 40 chars, not allowed |
74 |
$pref = sprintf(',%d', $cardnumber_size+1); |
71 |
t::lib::Mocks::mock_preference('CardnumberLength', $pref); |
75 |
t::lib::Mocks::mock_preference('CardnumberLength', $pref); |
72 |
is_deeply( [ C4::Members::get_cardnumber_length() ], [ 0, 16 ], ',40 => min=0 and max=16'); |
76 |
is_deeply( [ C4::Members::get_cardnumber_length() ], [ 0, $cardnumber_size ], |
|
|
77 |
sprintf(",%d => min=0 and max=%d",$cardnumber_size+1,$cardnumber_size) ); |
73 |
$dbh->{mock_add_resultset} = $rs; |
78 |
$dbh->{mock_add_resultset} = $rs; |
74 |
is( C4::Members::checkcardnumber( q{12345678901234567890} ), 2, "12345678901234567890 is longer than $pref => 16 is max!"); |
79 |
|
|
|
80 |
my $generated_cardnumber = sprintf("%s1234567890",q|9|x$cardnumber_size); |
81 |
is( C4::Members::checkcardnumber( $generated_cardnumber ), 2, "$generated_cardnumber is longer than $pref => $cardnumber_size is max!"); |
75 |
|
82 |
|
76 |
$pref = q|,8|; # max 8 chars |
83 |
$pref = q|,8|; # max 8 chars |
77 |
t::lib::Mocks::mock_preference('CardnumberLength', $pref); |
84 |
t::lib::Mocks::mock_preference('CardnumberLength', $pref); |
78 |
- |
|
|