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

(-)a/t/db_dependent/Koha/Patrons.t (-1 / +60 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 27;
22
use Test::More tests => 28;
23
use Test::Warn;
23
use Test::Warn;
24
use Time::Fake;
24
use Time::Fake;
25
use DateTime;
25
use DateTime;
Lines 1197-1202 subtest 'get_overdues' => sub { Link Here
1197
    $patron->delete;
1197
    $patron->delete;
1198
};
1198
};
1199
1199
1200
subtest 'userid_is_valid' => sub {
1201
    plan tests => 9;
1202
1203
    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
1204
    my $patron_category = $builder->build_object(
1205
        {
1206
            class => 'Koha::Patron::Categories',
1207
            value => { category_type => 'P', enrolmentfee => 0 }
1208
        }
1209
    );
1210
    my %data = (
1211
        cardnumber   => "123456789",
1212
        firstname    => "Tomasito",
1213
        surname      => "None",
1214
        categorycode => $patron_category->categorycode,
1215
        branchcode   => $library->branchcode,
1216
    );
1217
1218
    my $borrowernumber = AddMember(%data);
1219
    my $patron_1       = Koha::Patrons->find($borrowernumber);
1220
1221
    is( Check_Userid( 'tomasito.non', $patron_1->borrowernumber ),
1222
        1, 'recently created userid -> unique (borrowernumber passed)' );
1223
    is( Check_Userid( 'tomasitoxxx', $patron_1->borrowernumber ),
1224
        1, 'non-existent userid -> unique (borrowernumber passed)' );
1225
    is( Check_Userid( 'tomasito.none', '' ),
1226
        0, 'userid exists (blank borrowernumber)' );
1227
    is( Check_Userid( 'tomasitoxxx', '' ),
1228
        1, 'non-existent userid -> unique (blank borrowernumber)' );
1229
1230
    # Regression tests for BZ12226
1231
    is( Check_Userid( C4::Context->config('user'), '' ),
1232
        0, 'Check_Userid should return 0 for the DB user (Bug 12226)' );
1233
1234
    # Add a new borrower with the same userid but different cardnumber
1235
    $data{cardnumber} = "987654321";
1236
    my $new_borrowernumber = AddMember(%data);
1237
    is( Check_Userid( 'tomasito.none', '' ),
1238
        0, 'userid not unique (blank borrowernumber)' );
1239
    is( Check_Userid( 'tomasito.none', $new_borrowernumber ),
1240
        0, 'userid not unique (second borrowernumber passed)' );
1241
    my $patron_2 = Koha::Patrons->find($new_borrowernumber);
1242
    ok( $patron_2->userid ne 'tomasito',
1243
        "Borrower with duplicate userid has new userid generated" );
1244
1245
    my $new_userid = 'a_user_id';
1246
    $data{cardnumber} = "234567890";
1247
    $data{userid}     = 'a_user_id';
1248
    $borrowernumber   = AddMember(%data);
1249
    my $patron_3 = Koha::Patrons->find($borrowernumber);
1250
    is( $patron_3->userid, $new_userid,
1251
        'AddMember should insert the given userid' );
1252
1253
    # Cleanup
1254
    $patron_1->delete;
1255
    $patron_2->delete;
1256
    $patron_3->delete;
1257
};
1258
1200
$retrieved_patron_1->delete;
1259
$retrieved_patron_1->delete;
1201
is( Koha::Patrons->search->count, $nb_of_patrons + 1, 'Delete should have deleted the patron' );
1260
is( Koha::Patrons->search->count, $nb_of_patrons + 1, 'Delete should have deleted the patron' );
1202
1261
(-)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 => 60;
20
use Test::More tests => 51;
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 'purgeSelfRegistration' => sub {
352
subtest 'purgeSelfRegistration' => sub {
377
    plan tests => 2;
353
    plan tests => 2;
378
354
379
- 

Return to bug 19936