|
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 956-962
subtest 'account_locked' => sub {
Link Here
|
| 956 |
}; |
956 |
}; |
| 957 |
|
957 |
|
| 958 |
subtest 'userid_is_valid' => sub { |
958 |
subtest 'userid_is_valid' => sub { |
| 959 |
plan tests => 10; |
959 |
plan tests => 8; |
| 960 |
|
960 |
|
| 961 |
my $library = $builder->build_object( { class => 'Koha::Libraries' } ); |
961 |
my $library = $builder->build_object( { class => 'Koha::Libraries' } ); |
| 962 |
my $patron_category = $builder->build_object( |
962 |
my $patron_category = $builder->build_object( |
|
Lines 1008-1019
subtest 'userid_is_valid' => sub {
Link Here
|
| 1008 |
is( $patron_2->has_valid_userid, |
1008 |
is( $patron_2->has_valid_userid, |
| 1009 |
0, 'The userid is already in used, it cannot be used for another patron' ); |
1009 |
0, 'The userid is already in used, it cannot be used for another patron' ); |
| 1010 |
|
1010 |
|
| 1011 |
$patron_2 = Koha::Patrons->find($new_borrowernumber); |
|
|
| 1012 |
isnt( $patron_2->userid, 'tomasito', |
| 1013 |
"Patron with duplicate userid has new userid generated" ); |
| 1014 |
is( $patron_2->userid, $expected_userid_patron_1 . '1', # TODO we could make that configurable |
| 1015 |
"Patron with duplicate userid has new userid generated (1 is appened" ); |
| 1016 |
|
| 1017 |
my $new_userid = 'a_user_id'; |
1011 |
my $new_userid = 'a_user_id'; |
| 1018 |
$data{cardnumber} = "234567890"; |
1012 |
$data{cardnumber} = "234567890"; |
| 1019 |
$data{userid} = 'a_user_id'; |
1013 |
$data{userid} = 'a_user_id'; |
|
Lines 1028-1033
subtest 'userid_is_valid' => sub {
Link Here
|
| 1028 |
$patron_3->delete; |
1022 |
$patron_3->delete; |
| 1029 |
}; |
1023 |
}; |
| 1030 |
|
1024 |
|
|
|
1025 |
subtest 'generate_userid' => sub { |
| 1026 |
plan tests => 6; |
| 1027 |
|
| 1028 |
my $library = $builder->build_object( { class => 'Koha::Libraries' } ); |
| 1029 |
my $patron_category = $builder->build_object( |
| 1030 |
{ |
| 1031 |
class => 'Koha::Patron::Categories', |
| 1032 |
value => { category_type => 'P', enrolmentfee => 0 } |
| 1033 |
} |
| 1034 |
); |
| 1035 |
my %data = ( |
| 1036 |
cardnumber => "123456789", |
| 1037 |
firstname => "Tomasito", |
| 1038 |
surname => "None", |
| 1039 |
categorycode => $patron_category->categorycode, |
| 1040 |
branchcode => $library->branchcode, |
| 1041 |
); |
| 1042 |
|
| 1043 |
my $expected_userid_patron_1 = 'tomasito.none'; |
| 1044 |
my $userid = C4::Members::Generate_Userid( undef, $data{firstname}, $data{surname} ); |
| 1045 |
is( $userid, $expected_userid_patron_1, 'Generate_Userid should generate the userid we expect' ); |
| 1046 |
my $borrowernumber = AddMember(%data); |
| 1047 |
my $patron_1 = Koha::Patrons->find($borrowernumber); |
| 1048 |
is ( $patron_1->userid, $expected_userid_patron_1, 'The userid generated should be the one we expect' ); |
| 1049 |
|
| 1050 |
$userid = C4::Members::Generate_Userid( $borrowernumber, $data{firstname}, $data{surname} ); |
| 1051 |
is( $userid, $expected_userid_patron_1 . '1', 'Generate_Userid should generate the userid we expect' ); |
| 1052 |
$data{cardnumber} = '987654321'; |
| 1053 |
my $new_borrowernumber = AddMember(%data); |
| 1054 |
my $patron_2 = Koha::Patrons->find($new_borrowernumber); |
| 1055 |
isnt( $patron_2->userid, 'tomasito', |
| 1056 |
"Patron with duplicate userid has new userid generated" ); |
| 1057 |
is( $patron_2->userid, $expected_userid_patron_1 . '1', # TODO we could make that configurable |
| 1058 |
"Patron with duplicate userid has new userid generated (1 is appened" ); |
| 1059 |
|
| 1060 |
$userid = C4::Members::Generate_Userid( $borrowernumber, $data{firstname}, $data{surname} ); |
| 1061 |
is( $userid, $expected_userid_patron_1 . '2', 'Generate_Userid should generate the userid we expect' ); |
| 1062 |
|
| 1063 |
# Cleanup |
| 1064 |
$patron_1->delete; |
| 1065 |
$patron_2->delete; |
| 1066 |
}; |
| 1067 |
|
| 1068 |
|
| 1031 |
$retrieved_patron_1->delete; |
1069 |
$retrieved_patron_1->delete; |
| 1032 |
is( Koha::Patrons->search->count, $nb_of_patrons + 1, 'Delete should have deleted the patron' ); |
1070 |
is( Koha::Patrons->search->count, $nb_of_patrons + 1, 'Delete should have deleted the patron' ); |
| 1033 |
|
1071 |
|
| 1034 |
- |
|
|