Bug 15809: Redefine multi_param is CGI < 4.08 is used
[koha.git] / t / Members / cardnumber.t
blobb2ec79fdbb33e665167d62be4525f69fba96224f
1 #!/usr/bin/env perl
3 use Modern::Perl;
4 use Test::More tests => 23;
6 use t::lib::Mocks;
8 use_ok('C4::Members');
10 BEGIN {
11 t::lib::Mocks::mock_dbh;
14 my $dbh = C4::Context->dbh;
15 my $rs = [];
17 t::lib::Mocks::mock_preference('BorrowerMandatoryField', '');
18 my $pref = "10";
19 t::lib::Mocks::mock_preference('CardnumberLength', $pref);
20 is_deeply( [ C4::Members::get_cardnumber_length() ], [ 10, 10 ], '10 => min=10 and max=10');
21 $dbh->{mock_add_resultset} = $rs;
22 is( C4::Members::checkcardnumber( q{123456789} ), 2, "123456789 is shorter than $pref");
23 $dbh->{mock_add_resultset} = $rs;
24 is( C4::Members::checkcardnumber( q{1234567890123456} ), 2, "1234567890123456 is longer than $pref");
25 $dbh->{mock_add_resultset} = $rs;
26 is( C4::Members::checkcardnumber( q{1234567890} ), 0, "1234567890 is equal to $pref");
28 $pref = q|10,10|; # Same as before !
29 t::lib::Mocks::mock_preference('CardnumberLength', $pref);
30 is_deeply( [ C4::Members::get_cardnumber_length() ], [ 10, 10 ], '10,10 => min=10 and max=10');
31 $dbh->{mock_add_resultset} = $rs;
32 is( C4::Members::checkcardnumber( q{123456789} ), 2, "123456789 is shorter than $pref");
33 $dbh->{mock_add_resultset} = $rs;
34 is( C4::Members::checkcardnumber( q{1234567890123456} ), 2, "1234567890123456 is longer than $pref");
35 $dbh->{mock_add_resultset} = $rs;
36 is( C4::Members::checkcardnumber( q{1234567890} ), 0, "1234567890 is equal to $pref");
38 $pref = q|8,10|; # between 8 and 10 chars
39 t::lib::Mocks::mock_preference('CardnumberLength', $pref);
40 is_deeply( [ C4::Members::get_cardnumber_length() ], [ 8, 10 ], '8,10 => min=8 and max=10');
41 $dbh->{mock_add_resultset} = $rs;
42 is( C4::Members::checkcardnumber( q{12345678} ), 0, "12345678 matches $pref");
43 $dbh->{mock_add_resultset} = $rs;
44 is( C4::Members::checkcardnumber( q{1234567890123456} ), 2, "1234567890123456 is longer than $pref");
45 $dbh->{mock_add_resultset} = $rs;
46 is( C4::Members::checkcardnumber( q{1234567} ), 2, "1234567 is shorter than $pref");
47 $dbh->{mock_add_resultset} = $rs;
48 is( C4::Members::checkcardnumber( q{1234567890} ), 0, "1234567890 matches $pref");
50 $pref = q|8,|; # At least 8 chars
51 t::lib::Mocks::mock_preference('CardnumberLength', $pref);
52 is_deeply( [ C4::Members::get_cardnumber_length() ], [ 8, 16 ], '8, => min=8 and max=16');
53 $dbh->{mock_add_resultset} = $rs;
54 is( C4::Members::checkcardnumber( q{1234567} ), 2, "1234567 is shorter than $pref");
55 $dbh->{mock_add_resultset} = $rs;
56 is( C4::Members::checkcardnumber( q{1234567890123456} ), 0, "1234567890123456 matches $pref");
57 $dbh->{mock_add_resultset} = $rs;
58 is( C4::Members::checkcardnumber( q{1234567890} ), 0, "1234567890 matches $pref");
60 $pref = q|,8|; # max 8 chars
61 t::lib::Mocks::mock_preference('CardnumberLength', $pref);
62 is_deeply( [ C4::Members::get_cardnumber_length() ], [ 0, 8 ], ',8 => min=0 and max=8');
63 $dbh->{mock_add_resultset} = $rs;
64 is( C4::Members::checkcardnumber( q{1234567} ), 0, "1234567 matches $pref");
65 $dbh->{mock_add_resultset} = $rs;
66 is( C4::Members::checkcardnumber( q{1234567890123456} ), 2, "1234567890123456 is longer than $pref");
67 $dbh->{mock_add_resultset} = $rs;
68 is( C4::Members::checkcardnumber( q{1234567890} ), 2, "1234567890 is longer than $pref");
70 t::lib::Mocks::mock_preference('BorrowerMandatoryField', 'cardnumber');
71 is_deeply( [ C4::Members::get_cardnumber_length() ], [ 1, 8 ], ',8 => min=1 and max=8 if cardnumber is mandatory');