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 => 24;
22
use Test::More tests => 25;
23
use Test::Warn;
23
use Test::Warn;
24
use Time::Fake;
24
use Time::Fake;
25
use DateTime;
25
use DateTime;
Lines 1056-1062 subtest 'account_locked' => sub { Link Here
1056
};
1056
};
1057
1057
1058
subtest 'userid_is_valid' => sub {
1058
subtest 'userid_is_valid' => sub {
1059
    plan tests => 10;
1059
    plan tests => 8;
1060
1060
1061
    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
1061
    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
1062
    my $patron_category = $builder->build_object(
1062
    my $patron_category = $builder->build_object(
Lines 1108-1119 subtest 'userid_is_valid' => sub { Link Here
1108
    is( $patron_2->has_valid_userid,
1108
    is( $patron_2->has_valid_userid,
1109
        0, 'The userid is already in used, it cannot be used for another patron' );
1109
        0, 'The userid is already in used, it cannot be used for another patron' );
1110
1110
1111
    $patron_2 = Koha::Patrons->find($new_borrowernumber);
1112
    isnt( $patron_2->userid, 'tomasito',
1113
        "Patron with duplicate userid has new userid generated" );
1114
    is( $patron_2->userid, $expected_userid_patron_1 . '1', # TODO we could make that configurable
1115
        "Patron with duplicate userid has new userid generated (1 is appened" );
1116
1117
    my $new_userid = 'a_user_id';
1111
    my $new_userid = 'a_user_id';
1118
    $data{cardnumber} = "234567890";
1112
    $data{cardnumber} = "234567890";
1119
    $data{userid}     = 'a_user_id';
1113
    $data{userid}     = 'a_user_id';
Lines 1128-1133 subtest 'userid_is_valid' => sub { Link Here
1128
    $patron_3->delete;
1122
    $patron_3->delete;
1129
};
1123
};
1130
1124
1125
subtest 'generate_userid' => sub {
1126
    plan tests => 6;
1127
1128
    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
1129
    my $patron_category = $builder->build_object(
1130
        {
1131
            class => 'Koha::Patron::Categories',
1132
            value => { category_type => 'P', enrolmentfee => 0 }
1133
        }
1134
    );
1135
    my %data = (
1136
        cardnumber   => "123456789",
1137
        firstname    => "Tomasito",
1138
        surname      => "None",
1139
        categorycode => $patron_category->categorycode,
1140
        branchcode   => $library->branchcode,
1141
    );
1142
1143
    my $expected_userid_patron_1 = 'tomasito.none';
1144
    my $userid = C4::Members::Generate_Userid( undef, $data{firstname}, $data{surname} );
1145
    is( $userid, $expected_userid_patron_1, 'Generate_Userid should generate the userid we expect' );
1146
    my $borrowernumber = AddMember(%data);
1147
    my $patron_1 = Koha::Patrons->find($borrowernumber);
1148
    is ( $patron_1->userid, $expected_userid_patron_1, 'The userid generated should be the one we expect' );
1149
1150
    $userid = C4::Members::Generate_Userid( $borrowernumber, $data{firstname}, $data{surname} );
1151
    is( $userid, $expected_userid_patron_1 . '1', 'Generate_Userid should generate the userid we expect' );
1152
    $data{cardnumber} = '987654321';
1153
    my $new_borrowernumber = AddMember(%data);
1154
    my $patron_2 = Koha::Patrons->find($new_borrowernumber);
1155
    isnt( $patron_2->userid, 'tomasito',
1156
        "Patron with duplicate userid has new userid generated" );
1157
    is( $patron_2->userid, $expected_userid_patron_1 . '1', # TODO we could make that configurable
1158
        "Patron with duplicate userid has new userid generated (1 is appened" );
1159
1160
    $userid = C4::Members::Generate_Userid( $borrowernumber, $data{firstname}, $data{surname} );
1161
    is( $userid, $expected_userid_patron_1 . '2', 'Generate_Userid should generate the userid we expect' );
1162
1163
    # Cleanup
1164
    $patron_1->delete;
1165
    $patron_2->delete;
1166
};
1167
1168
1131
$retrieved_patron_1->delete;
1169
$retrieved_patron_1->delete;
1132
is( Koha::Patrons->search->count, $nb_of_patrons + 1, 'Delete should have deleted the patron' );
1170
is( Koha::Patrons->search->count, $nb_of_patrons + 1, 'Delete should have deleted the patron' );
1133
1171
1134
- 

Return to bug 19936