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 => 9; |
1059 |
plan tests => 10; |
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 1073-1104
subtest 'userid_is_valid' => sub {
Link Here
|
1073 |
branchcode => $library->branchcode, |
1073 |
branchcode => $library->branchcode, |
1074 |
); |
1074 |
); |
1075 |
|
1075 |
|
|
|
1076 |
my $expected_userid_patron_1 = 'tomasito.none'; |
1076 |
my $borrowernumber = AddMember(%data); |
1077 |
my $borrowernumber = AddMember(%data); |
1077 |
my $patron_1 = Koha::Patrons->find($borrowernumber); |
1078 |
my $patron_1 = Koha::Patrons->find($borrowernumber); |
|
|
1079 |
is ( $patron_1->userid, $expected_userid_patron_1, 'The userid generated should be the one we expect' ); |
1078 |
|
1080 |
|
1079 |
is( Check_Userid( 'tomasito.non', $patron_1->borrowernumber ), |
1081 |
$patron_1->userid( 'tomasito.non' ); |
|
|
1082 |
is( $patron_1->has_valid_userid, # FIXME Joubu: What is the difference with the next test? |
1080 |
1, 'recently created userid -> unique (borrowernumber passed)' ); |
1083 |
1, 'recently created userid -> unique (borrowernumber passed)' ); |
1081 |
is( Check_Userid( 'tomasitoxxx', $patron_1->borrowernumber ), |
1084 |
|
|
|
1085 |
$patron_1->userid( 'tomasitoxxx' ); |
1086 |
is( $patron_1->has_valid_userid, |
1082 |
1, 'non-existent userid -> unique (borrowernumber passed)' ); |
1087 |
1, 'non-existent userid -> unique (borrowernumber passed)' ); |
1083 |
is( Check_Userid( 'tomasito.none', '' ), |
1088 |
$patron_1->discard_changes; # We compare with the original userid later |
1084 |
0, 'userid exists (blank borrowernumber)' ); |
1089 |
|
1085 |
is( Check_Userid( 'tomasitoxxx', '' ), |
1090 |
my $patron_not_in_storage = Koha::Patron->new( { userid => '' } ); |
1086 |
1, 'non-existent userid -> unique (blank borrowernumber)' ); |
1091 |
is( $patron_not_in_storage->has_valid_userid, |
|
|
1092 |
0, 'userid exists for another patron, patron is not in storage yet' ); |
1093 |
|
1094 |
$patron_not_in_storage = Koha::Patron->new( { userid => 'tomasitoxxx' } ); |
1095 |
is( $patron_not_in_storage->has_valid_userid, |
1096 |
1, 'non-existent userid, patron is not in storage yet' ); |
1087 |
|
1097 |
|
1088 |
# Regression tests for BZ12226 |
1098 |
# Regression tests for BZ12226 |
1089 |
is( Check_Userid( C4::Context->config('user'), '' ), |
1099 |
my $db_patron = Koha::Patron->new( { userid => C4::Context->config('user') } ); |
1090 |
0, 'Check_Userid should return 0 for the DB user (Bug 12226)' ); |
1100 |
is( $db_patron->has_valid_userid, |
|
|
1101 |
0, 'Koha::Patron->has_valid_userid should return 0 for the DB user (Bug 12226)' ); |
1091 |
|
1102 |
|
1092 |
# Add a new borrower with the same userid but different cardnumber |
1103 |
# Add a new borrower with the same userid but different cardnumber |
1093 |
$data{cardnumber} = "987654321"; |
1104 |
$data{cardnumber} = "987654321"; |
1094 |
my $new_borrowernumber = AddMember(%data); |
1105 |
my $new_borrowernumber = AddMember(%data); |
1095 |
is( Check_Userid( 'tomasito.none', '' ), |
|
|
1096 |
0, 'userid not unique (blank borrowernumber)' ); |
1097 |
is( Check_Userid( 'tomasito.none', $new_borrowernumber ), |
1098 |
0, 'userid not unique (second borrowernumber passed)' ); |
1099 |
my $patron_2 = Koha::Patrons->find($new_borrowernumber); |
1106 |
my $patron_2 = Koha::Patrons->find($new_borrowernumber); |
1100 |
ok( $patron_2->userid ne 'tomasito', |
1107 |
$patron_2->userid($patron_1->userid); |
1101 |
"Borrower with duplicate userid has new userid generated" ); |
1108 |
is( $patron_2->has_valid_userid, |
|
|
1109 |
0, 'The userid is already in used, it cannot be used for another patron' ); |
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" ); |
1102 |
|
1116 |
|
1103 |
my $new_userid = 'a_user_id'; |
1117 |
my $new_userid = 'a_user_id'; |
1104 |
$data{cardnumber} = "234567890"; |
1118 |
$data{cardnumber} = "234567890"; |
1105 |
- |
|
|