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 => 26;
22
use Test::More tests => 27;
23
use Test::Warn;
23
use Test::Warn;
24
use Time::Fake;
24
use Time::Fake;
25
use DateTime;
25
use DateTime;
Lines 1119-1125 subtest 'is_child | is_adult' => sub { Link Here
1119
};
1119
};
1120
1120
1121
subtest 'userid_is_valid' => sub {
1121
subtest 'userid_is_valid' => sub {
1122
    plan tests => 10;
1122
    plan tests => 8;
1123
1123
1124
    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
1124
    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
1125
    my $patron_category = $builder->build_object(
1125
    my $patron_category = $builder->build_object(
Lines 1171-1182 subtest 'userid_is_valid' => sub { Link Here
1171
    is( $patron_2->has_valid_userid,
1171
    is( $patron_2->has_valid_userid,
1172
        0, 'The userid is already in used, it cannot be used for another patron' );
1172
        0, 'The userid is already in used, it cannot be used for another patron' );
1173
1173
1174
    $patron_2 = Koha::Patrons->find($new_borrowernumber);
1175
    isnt( $patron_2->userid, 'tomasito',
1176
        "Patron with duplicate userid has new userid generated" );
1177
    is( $patron_2->userid, $expected_userid_patron_1 . '1', # TODO we could make that configurable
1178
        "Patron with duplicate userid has new userid generated (1 is appened" );
1179
1180
    my $new_userid = 'a_user_id';
1174
    my $new_userid = 'a_user_id';
1181
    $data{cardnumber} = "234567890";
1175
    $data{cardnumber} = "234567890";
1182
    $data{userid}     = 'a_user_id';
1176
    $data{userid}     = 'a_user_id';
Lines 1191-1196 subtest 'userid_is_valid' => sub { Link Here
1191
    $patron_3->delete;
1185
    $patron_3->delete;
1192
};
1186
};
1193
1187
1188
subtest 'generate_userid' => sub {
1189
    plan tests => 6;
1190
1191
    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
1192
    my $patron_category = $builder->build_object(
1193
        {
1194
            class => 'Koha::Patron::Categories',
1195
            value => { category_type => 'P', enrolmentfee => 0 }
1196
        }
1197
    );
1198
    my %data = (
1199
        cardnumber   => "123456789",
1200
        firstname    => "Tomasito",
1201
        surname      => "None",
1202
        categorycode => $patron_category->categorycode,
1203
        branchcode   => $library->branchcode,
1204
    );
1205
1206
    my $expected_userid_patron_1 = 'tomasito.none';
1207
    my $userid = C4::Members::Generate_Userid( undef, $data{firstname}, $data{surname} );
1208
    is( $userid, $expected_userid_patron_1, 'Generate_Userid should generate the userid we expect' );
1209
    my $borrowernumber = AddMember(%data);
1210
    my $patron_1 = Koha::Patrons->find($borrowernumber);
1211
    is ( $patron_1->userid, $expected_userid_patron_1, 'The userid generated should be the one we expect' );
1212
1213
    $userid = C4::Members::Generate_Userid( $borrowernumber, $data{firstname}, $data{surname} );
1214
    is( $userid, $expected_userid_patron_1 . '1', 'Generate_Userid should generate the userid we expect' );
1215
    $data{cardnumber} = '987654321';
1216
    my $new_borrowernumber = AddMember(%data);
1217
    my $patron_2 = Koha::Patrons->find($new_borrowernumber);
1218
    isnt( $patron_2->userid, 'tomasito',
1219
        "Patron with duplicate userid has new userid generated" );
1220
    is( $patron_2->userid, $expected_userid_patron_1 . '1', # TODO we could make that configurable
1221
        "Patron with duplicate userid has new userid generated (1 is appened" );
1222
1223
    $userid = C4::Members::Generate_Userid( $borrowernumber, $data{firstname}, $data{surname} );
1224
    is( $userid, $expected_userid_patron_1 . '2', 'Generate_Userid should generate the userid we expect' );
1225
1226
    # Cleanup
1227
    $patron_1->delete;
1228
    $patron_2->delete;
1229
};
1230
1231
1194
$retrieved_patron_1->delete;
1232
$retrieved_patron_1->delete;
1195
is( Koha::Patrons->search->count, $nb_of_patrons + 1, 'Delete should have deleted the patron' );
1233
is( Koha::Patrons->search->count, $nb_of_patrons + 1, 'Delete should have deleted the patron' );
1196
1234
1197
- 

Return to bug 19936