View | Details | Raw Unified | Return to bug 19936
Collapse All | Expand All

(-)a/t/db_dependent/Koha/Patrons.t (+59 lines)
Lines 1055-1060 subtest 'account_locked' => sub { Link Here
1055
    $patron->delete;
1055
    $patron->delete;
1056
};
1056
};
1057
1057
1058
subtest 'userid_is_valid' => sub {
1059
    plan tests => 9;
1060
1061
    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
1062
    my $patron_category = $builder->build_object(
1063
        {
1064
            class => 'Koha::Patron::Categories',
1065
            value => { category_type => 'P', enrolmentfee => 0 }
1066
        }
1067
    );
1068
    my %data = (
1069
        cardnumber   => "123456789",
1070
        firstname    => "Tomasito",
1071
        surname      => "None",
1072
        categorycode => $patron_category->categorycode,
1073
        branchcode   => $library->branchcode,
1074
    );
1075
1076
    my $borrowernumber = AddMember(%data);
1077
    my $patron_1       = Koha::Patrons->find($borrowernumber);
1078
1079
    is( Check_Userid( 'tomasito.non', $patron_1->borrowernumber ),
1080
        1, 'recently created userid -> unique (borrowernumber passed)' );
1081
    is( Check_Userid( 'tomasitoxxx', $patron_1->borrowernumber ),
1082
        1, 'non-existent userid -> unique (borrowernumber passed)' );
1083
    is( Check_Userid( 'tomasito.none', '' ),
1084
        0, 'userid exists (blank borrowernumber)' );
1085
    is( Check_Userid( 'tomasitoxxx', '' ),
1086
        1, 'non-existent userid -> unique (blank borrowernumber)' );
1087
1088
    # Regression tests for BZ12226
1089
    is( Check_Userid( C4::Context->config('user'), '' ),
1090
        0, 'Check_Userid should return 0 for the DB user (Bug 12226)' );
1091
1092
    # Add a new borrower with the same userid but different cardnumber
1093
    $data{cardnumber} = "987654321";
1094
    my $new_borrowernumber = AddMember(%data);
1095
    is( Check_Userid( 'tomasito.none', '' ),
1096
        0, 'userid not unique (blank borrowernumber)' );
1097
    is( Check_Userid( 'tomasito.none', $new_borrowernumber ),
1098
        0, 'userid not unique (second borrowernumber passed)' );
1099
    my $patron_2 = Koha::Patrons->find($new_borrowernumber);
1100
    ok( $patron_2->userid ne 'tomasito',
1101
        "Borrower with duplicate userid has new userid generated" );
1102
1103
    my $new_userid = 'a_user_id';
1104
    $data{cardnumber} = "234567890";
1105
    $data{userid}     = 'a_user_id';
1106
    $borrowernumber   = AddMember(%data);
1107
    my $patron_3 = Koha::Patrons->find($borrowernumber);
1108
    is( $patron_3->userid, $new_userid,
1109
        'AddMember should insert the given userid' );
1110
1111
    # Cleanup
1112
    $patron_1->delete;
1113
    $patron_2->delete;
1114
    $patron_3->delete;
1115
};
1116
1058
$retrieved_patron_1->delete;
1117
$retrieved_patron_1->delete;
1059
is( Koha::Patrons->search->count, $nb_of_patrons + 1, 'Delete should have deleted the patron' );
1118
is( Koha::Patrons->search->count, $nb_of_patrons + 1, 'Delete should have deleted the patron' );
1060
1119
(-)a/t/db_dependent/Members.t (-33 / +8 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 62;
20
use Test::More tests => 53;
21
use Test::MockModule;
21
use Test::MockModule;
22
use Test::Exception;
22
use Test::Exception;
23
23
Lines 139-145 $checkcardnum=C4::Members::checkcardnumber($IMPOSSIBLE_CARDNUMBER, ""); Link Here
139
is ($checkcardnum, "2", "Card number is too long");
139
is ($checkcardnum, "2", "Card number is too long");
140
140
141
141
142
# Check_Userid tests
142
# Add a new borrower
143
%data = (
143
%data = (
144
    cardnumber   => "123456789",
144
    cardnumber   => "123456789",
145
    firstname    => "Tomasito",
145
    firstname    => "Tomasito",
Lines 151-167 is ($checkcardnum, "2", "Card number is too long"); Link Here
151
    dateexpiry   => '',
151
    dateexpiry   => '',
152
    dateenrolled => '',
152
    dateenrolled => '',
153
);
153
);
154
# Add a new borrower
155
my $borrowernumber = AddMember( %data );
154
my $borrowernumber = AddMember( %data );
156
is( Check_Userid( 'tomasito.non', $borrowernumber ), 1,
157
    'recently created userid -> unique (borrowernumber passed)' );
158
is( Check_Userid( 'tomasitoxxx', $borrowernumber ), 1,
159
    'non-existent userid -> unique (borrowernumber passed)' );
160
is( Check_Userid( 'tomasito.none', '' ), 0,
161
    'userid exists (blank borrowernumber)' );
162
is( Check_Userid( 'tomasitoxxx', '' ), 1,
163
    'non-existent userid -> unique (blank borrowernumber)' );
164
165
my $borrower = Koha::Patrons->find( $borrowernumber )->unblessed;
155
my $borrower = Koha::Patrons->find( $borrowernumber )->unblessed;
166
is( $borrower->{dateofbirth}, undef, 'AddMember should undef dateofbirth if empty string is given');
156
is( $borrower->{dateofbirth}, undef, 'AddMember should undef dateofbirth if empty string is given');
167
is( $borrower->{debarred}, undef, 'AddMember should undef debarred if empty string is given');
157
is( $borrower->{debarred}, undef, 'AddMember should undef debarred if empty string is given');
Lines 182-205 is( $borrower->{debarred}, '2042-01-01', 'ModMember should correctly set debarre Link Here
182
is( $borrower->{dateexpiry}, '9999-12-31', 'ModMember should correctly set dateexpiry if a valid date is given');
172
is( $borrower->{dateexpiry}, '9999-12-31', 'ModMember should correctly set dateexpiry if a valid date is given');
183
is( $borrower->{dateenrolled}, '2015-09-06', 'ModMember should correctly set dateenrolled if a valid date is given');
173
is( $borrower->{dateenrolled}, '2015-09-06', 'ModMember should correctly set dateenrolled if a valid date is given');
184
174
185
# Add a new borrower with the same userid but different cardnumber
186
$data{ cardnumber } = "987654321";
187
my $new_borrowernumber = AddMember( %data );
188
is( Check_Userid( 'tomasito.none', '' ), 0,
189
    'userid not unique (blank borrowernumber)' );
190
is( Check_Userid( 'tomasito.none', $new_borrowernumber ), 0,
191
    'userid not unique (second borrowernumber passed)' );
192
$borrower = Koha::Patrons->find( $new_borrowernumber )->unblessed;
193
ok( $borrower->{userid} ne 'tomasito', "Borrower with duplicate userid has new userid generated" );
194
195
$data{ cardnumber } = "234567890";
196
$data{userid} = 'a_user_id';
197
$borrowernumber = AddMember( %data );
198
$borrower = Koha::Patrons->find( $borrowernumber )->unblessed;
199
is( $borrower->{userid}, $data{userid}, 'AddMember should insert the given userid' );
200
201
subtest 'ModMember should not update userid if not true' => sub {
175
subtest 'ModMember should not update userid if not true' => sub {
202
    plan tests => 3;
176
    plan tests => 3;
177
178
    $data{ cardnumber } = "234567890";
179
    $data{userid} = 'a_user_id';
180
    $borrowernumber = AddMember( %data );
181
    $borrower = Koha::Patrons->find( $borrowernumber )->unblessed;
182
203
    ModMember( borrowernumber => $borrowernumber, firstname => 'Tomas', userid => '' );
183
    ModMember( borrowernumber => $borrowernumber, firstname => 'Tomas', userid => '' );
204
    $borrower = Koha::Patrons->find( $borrowernumber )->unblessed;
184
    $borrower = Koha::Patrons->find( $borrowernumber )->unblessed;
205
    is ( $borrower->{userid}, $data{userid}, 'ModMember should not update the userid with an empty string' );
185
    is ( $borrower->{userid}, $data{userid}, 'ModMember should not update the userid with an empty string' );
Lines 369-378 ok( $borrowernumber > 0, 'AddMember should have inserted the patron even if no u Link Here
369
$borrower = Koha::Patrons->find( $borrowernumber )->unblessed;
349
$borrower = Koha::Patrons->find( $borrowernumber )->unblessed;
370
ok( $borrower->{userid},  'A userid should have been generated correctly' );
350
ok( $borrower->{userid},  'A userid should have been generated correctly' );
371
351
372
# Regression tests for BZ12226
373
is( Check_Userid( C4::Context->config('user'), '' ), 0,
374
    'Check_Userid should return 0 for the DB user (Bug 12226)');
375
376
subtest 'GetMemberAccountRecords' => sub {
352
subtest 'GetMemberAccountRecords' => sub {
377
353
378
    plan tests => 2;
354
    plan tests => 2;
379
- 

Return to bug 19936