Lines 1-7
Link Here
|
1 |
#!/usr/bin/env perl |
1 |
#!/usr/bin/env perl |
2 |
|
2 |
|
3 |
use Modern::Perl; |
3 |
use Modern::Perl; |
4 |
use Test::More tests =>14; |
4 |
use Test::More tests =>18; |
5 |
|
5 |
|
6 |
use Test::MockModule; |
6 |
use Test::MockModule; |
7 |
use DBD::Mock; |
7 |
use DBD::Mock; |
Lines 23-65
my $rs = [];
Link Here
|
23 |
|
23 |
|
24 |
my $pref = "10"; |
24 |
my $pref = "10"; |
25 |
set_pref( $module_context, $pref ); |
25 |
set_pref( $module_context, $pref ); |
26 |
|
26 |
is_deeply( [ C4::Members::get_cardnumber_length() ], [ 10, 10 ], '10 => min=10 and max=10'); |
27 |
$dbh->{mock_add_resultset} = $rs; |
27 |
$dbh->{mock_add_resultset} = $rs; |
28 |
is( C4::Members::checkcardnumber( q{123456789} ), 1, "123456789 is shorter than $pref"); |
28 |
is( C4::Members::checkcardnumber( q{123456789} ), 2, "123456789 is shorter than $pref"); |
29 |
$dbh->{mock_add_resultset} = $rs; |
29 |
$dbh->{mock_add_resultset} = $rs; |
30 |
is( C4::Members::checkcardnumber( q{12345678901234567890} ), 1, "12345678901234567890 is longer than $pref"); |
30 |
is( C4::Members::checkcardnumber( q{1234567890123456} ), 2, "1234567890123456 is longer than $pref"); |
31 |
$dbh->{mock_add_resultset} = $rs; |
31 |
$dbh->{mock_add_resultset} = $rs; |
32 |
is( C4::Members::checkcardnumber( q{1234567890} ), 0, "1234567890 is equal to $pref"); |
32 |
is( C4::Members::checkcardnumber( q{1234567890} ), 0, "1234567890 is equal to $pref"); |
33 |
|
33 |
|
34 |
$pref = q|10,10|; # Same as before ! |
34 |
$pref = q|10,10|; # Same as before ! |
35 |
set_pref( $module_context, $pref ); |
35 |
set_pref( $module_context, $pref ); |
|
|
36 |
is_deeply( [ C4::Members::get_cardnumber_length() ], [ 10, 10 ], '10,10 => min=10 and max=10'); |
36 |
$dbh->{mock_add_resultset} = $rs; |
37 |
$dbh->{mock_add_resultset} = $rs; |
37 |
is( C4::Members::checkcardnumber( q{123456789} ), 1, "123456789 is shorter than $pref"); |
38 |
is( C4::Members::checkcardnumber( q{123456789} ), 2, "123456789 is shorter than $pref"); |
38 |
$dbh->{mock_add_resultset} = $rs; |
39 |
$dbh->{mock_add_resultset} = $rs; |
39 |
is( C4::Members::checkcardnumber( q{12345678901234567890} ), 1, "12345678901234567890 is longer than $pref"); |
40 |
is( C4::Members::checkcardnumber( q{1234567890123456} ), 2, "1234567890123456 is longer than $pref"); |
40 |
$dbh->{mock_add_resultset} = $rs; |
41 |
$dbh->{mock_add_resultset} = $rs; |
41 |
is( C4::Members::checkcardnumber( q{1234567890} ), 0, "1234567890 is equal to $pref"); |
42 |
is( C4::Members::checkcardnumber( q{1234567890} ), 0, "1234567890 is equal to $pref"); |
42 |
|
43 |
|
43 |
$pref = q|8,10|; # between 8 and 10 chars |
44 |
$pref = q|8,10|; # between 8 and 10 chars |
44 |
set_pref( $module_context, $pref ); |
45 |
set_pref( $module_context, $pref ); |
|
|
46 |
is_deeply( [ C4::Members::get_cardnumber_length() ], [ 8, 10 ], '8,10 => min=8 and max=10'); |
45 |
$dbh->{mock_add_resultset} = $rs; |
47 |
$dbh->{mock_add_resultset} = $rs; |
46 |
is( C4::Members::checkcardnumber( q{12345678} ), 0, "12345678 matches $pref"); |
48 |
is( C4::Members::checkcardnumber( q{12345678} ), 0, "12345678 matches $pref"); |
47 |
$dbh->{mock_add_resultset} = $rs; |
49 |
$dbh->{mock_add_resultset} = $rs; |
48 |
is( C4::Members::checkcardnumber( q{12345678901234567890} ), 1, "12345678901234567890 is longer than $pref"); |
50 |
is( C4::Members::checkcardnumber( q{1234567890123456} ), 2, "1234567890123456 is longer than $pref"); |
49 |
$dbh->{mock_add_resultset} = $rs; |
51 |
$dbh->{mock_add_resultset} = $rs; |
50 |
is( C4::Members::checkcardnumber( q{1234567} ), 1, "1234567 is shorter than $pref"); |
52 |
is( C4::Members::checkcardnumber( q{1234567} ), 2, "1234567 is shorter than $pref"); |
51 |
$dbh->{mock_add_resultset} = $rs; |
53 |
$dbh->{mock_add_resultset} = $rs; |
52 |
is( C4::Members::checkcardnumber( q{1234567890} ), 0, "1234567890 matches $pref"); |
54 |
is( C4::Members::checkcardnumber( q{1234567890} ), 0, "1234567890 matches $pref"); |
53 |
|
55 |
|
54 |
$pref = q|8,|; # At least 8 chars |
56 |
$pref = q|8,|; # At least 8 chars |
55 |
set_pref( $module_context, $pref ); |
57 |
set_pref( $module_context, $pref ); |
|
|
58 |
is_deeply( [ C4::Members::get_cardnumber_length() ], [ 8, 16 ], '8, => min=8 and max=16'); |
56 |
$dbh->{mock_add_resultset} = $rs; |
59 |
$dbh->{mock_add_resultset} = $rs; |
57 |
is( C4::Members::checkcardnumber( q{1234567} ), 1, "1234567 is shorter than $pref"); |
60 |
is( C4::Members::checkcardnumber( q{1234567} ), 2, "1234567 is shorter than $pref"); |
58 |
$dbh->{mock_add_resultset} = $rs; |
61 |
$dbh->{mock_add_resultset} = $rs; |
59 |
is( C4::Members::checkcardnumber( q{12345678901234567890} ), 0, "12345678901234567890 matches $pref"); |
62 |
is( C4::Members::checkcardnumber( q{1234567890123456} ), 0, "1234567890123456 matches $pref"); |
60 |
$dbh->{mock_add_resultset} = $rs; |
63 |
$dbh->{mock_add_resultset} = $rs; |
61 |
is( C4::Members::checkcardnumber( q{1234567890} ), 0, "12345678 matches $pref"); |
64 |
is( C4::Members::checkcardnumber( q{1234567890} ), 0, "12345678 matches $pref"); |
62 |
|
65 |
|
|
|
66 |
|
67 |
|
63 |
sub set_pref { |
68 |
sub set_pref { |
64 |
my ( $module, $value ) = @_; |
69 |
my ( $module, $value ) = @_; |
65 |
$module->mock('preference', sub { return $value } ); |
70 |
$module->mock('preference', sub { return $value } ); |
66 |
- |
|
|