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

(-)a/t/db_dependent/Koha/Patrons.t (-9 / +46 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 28;
22
use Test::More tests => 29;
23
use Test::Warn;
23
use Test::Warn;
24
use Time::Fake;
24
use Time::Fake;
25
use DateTime;
25
use DateTime;
Lines 1198-1204 subtest 'get_overdues' => sub { Link Here
1198
};
1198
};
1199
1199
1200
subtest 'userid_is_valid' => sub {
1200
subtest 'userid_is_valid' => sub {
1201
    plan tests => 10;
1201
    plan tests => 8;
1202
1202
1203
    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
1203
    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
1204
    my $patron_category = $builder->build_object(
1204
    my $patron_category = $builder->build_object(
Lines 1250-1261 subtest 'userid_is_valid' => sub { Link Here
1250
    is( $patron_2->has_valid_userid,
1250
    is( $patron_2->has_valid_userid,
1251
        0, 'The userid is already in used, it cannot be used for another patron' );
1251
        0, 'The userid is already in used, it cannot be used for another patron' );
1252
1252
1253
    $patron_2 = Koha::Patrons->find($new_borrowernumber);
1254
    isnt( $patron_2->userid, 'tomasito',
1255
        "Patron with duplicate userid has new userid generated" );
1256
    is( $patron_2->userid, $expected_userid_patron_1 . '1', # TODO we could make that configurable
1257
        "Patron with duplicate userid has new userid generated (1 is appened" );
1258
1259
    my $new_userid = 'a_user_id';
1253
    my $new_userid = 'a_user_id';
1260
    $data{cardnumber} = "234567890";
1254
    $data{cardnumber} = "234567890";
1261
    $data{userid}     = 'a_user_id';
1255
    $data{userid}     = 'a_user_id';
Lines 1270-1275 subtest 'userid_is_valid' => sub { Link Here
1270
    $patron_3->delete;
1264
    $patron_3->delete;
1271
};
1265
};
1272
1266
1267
subtest 'generate_userid' => sub {
1268
    plan tests => 6;
1269
1270
    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
1271
    my $patron_category = $builder->build_object(
1272
        {
1273
            class => 'Koha::Patron::Categories',
1274
            value => { category_type => 'P', enrolmentfee => 0 }
1275
        }
1276
    );
1277
    my %data = (
1278
        cardnumber   => "123456789",
1279
        firstname    => "Tomasito",
1280
        surname      => "None",
1281
        categorycode => $patron_category->categorycode,
1282
        branchcode   => $library->branchcode,
1283
    );
1284
1285
    my $expected_userid_patron_1 = 'tomasito.none';
1286
    my $userid = C4::Members::Generate_Userid( undef, $data{firstname}, $data{surname} );
1287
    is( $userid, $expected_userid_patron_1, 'Generate_Userid should generate the userid we expect' );
1288
    my $borrowernumber = AddMember(%data);
1289
    my $patron_1 = Koha::Patrons->find($borrowernumber);
1290
    is ( $patron_1->userid, $expected_userid_patron_1, 'The userid generated should be the one we expect' );
1291
1292
    $userid = C4::Members::Generate_Userid( $borrowernumber, $data{firstname}, $data{surname} );
1293
    is( $userid, $expected_userid_patron_1 . '1', 'Generate_Userid should generate the userid we expect' );
1294
    $data{cardnumber} = '987654321';
1295
    my $new_borrowernumber = AddMember(%data);
1296
    my $patron_2 = Koha::Patrons->find($new_borrowernumber);
1297
    isnt( $patron_2->userid, 'tomasito',
1298
        "Patron with duplicate userid has new userid generated" );
1299
    is( $patron_2->userid, $expected_userid_patron_1 . '1', # TODO we could make that configurable
1300
        "Patron with duplicate userid has new userid generated (1 is appened" );
1301
1302
    $userid = C4::Members::Generate_Userid( $borrowernumber, $data{firstname}, $data{surname} );
1303
    is( $userid, $expected_userid_patron_1 . '2', 'Generate_Userid should generate the userid we expect' );
1304
1305
    # Cleanup
1306
    $patron_1->delete;
1307
    $patron_2->delete;
1308
};
1309
1310
1273
$retrieved_patron_1->delete;
1311
$retrieved_patron_1->delete;
1274
is( Koha::Patrons->search->count, $nb_of_patrons + 1, 'Delete should have deleted the patron' );
1312
is( Koha::Patrons->search->count, $nb_of_patrons + 1, 'Delete should have deleted the patron' );
1275
1313
1276
- 

Return to bug 19936