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 => 9; |
1201 |
plan tests => 10; |
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 1215-1246
subtest 'userid_is_valid' => sub {
Link Here
|
1215 |
branchcode => $library->branchcode, |
1215 |
branchcode => $library->branchcode, |
1216 |
); |
1216 |
); |
1217 |
|
1217 |
|
|
|
1218 |
my $expected_userid_patron_1 = 'tomasito.none'; |
1218 |
my $borrowernumber = AddMember(%data); |
1219 |
my $borrowernumber = AddMember(%data); |
1219 |
my $patron_1 = Koha::Patrons->find($borrowernumber); |
1220 |
my $patron_1 = Koha::Patrons->find($borrowernumber); |
|
|
1221 |
is ( $patron_1->userid, $expected_userid_patron_1, 'The userid generated should be the one we expect' ); |
1220 |
|
1222 |
|
1221 |
is( Check_Userid( 'tomasito.non', $patron_1->borrowernumber ), |
1223 |
$patron_1->userid( 'tomasito.non' ); |
|
|
1224 |
is( $patron_1->has_valid_userid, # FIXME Joubu: What is the difference with the next test? |
1222 |
1, 'recently created userid -> unique (borrowernumber passed)' ); |
1225 |
1, 'recently created userid -> unique (borrowernumber passed)' ); |
1223 |
is( Check_Userid( 'tomasitoxxx', $patron_1->borrowernumber ), |
1226 |
|
|
|
1227 |
$patron_1->userid( 'tomasitoxxx' ); |
1228 |
is( $patron_1->has_valid_userid, |
1224 |
1, 'non-existent userid -> unique (borrowernumber passed)' ); |
1229 |
1, 'non-existent userid -> unique (borrowernumber passed)' ); |
1225 |
is( Check_Userid( 'tomasito.none', '' ), |
1230 |
$patron_1->discard_changes; # We compare with the original userid later |
1226 |
0, 'userid exists (blank borrowernumber)' ); |
1231 |
|
1227 |
is( Check_Userid( 'tomasitoxxx', '' ), |
1232 |
my $patron_not_in_storage = Koha::Patron->new( { userid => '' } ); |
1228 |
1, 'non-existent userid -> unique (blank borrowernumber)' ); |
1233 |
is( $patron_not_in_storage->has_valid_userid, |
|
|
1234 |
0, 'userid exists for another patron, patron is not in storage yet' ); |
1235 |
|
1236 |
$patron_not_in_storage = Koha::Patron->new( { userid => 'tomasitoxxx' } ); |
1237 |
is( $patron_not_in_storage->has_valid_userid, |
1238 |
1, 'non-existent userid, patron is not in storage yet' ); |
1229 |
|
1239 |
|
1230 |
# Regression tests for BZ12226 |
1240 |
# Regression tests for BZ12226 |
1231 |
is( Check_Userid( C4::Context->config('user'), '' ), |
1241 |
my $db_patron = Koha::Patron->new( { userid => C4::Context->config('user') } ); |
1232 |
0, 'Check_Userid should return 0 for the DB user (Bug 12226)' ); |
1242 |
is( $db_patron->has_valid_userid, |
|
|
1243 |
0, 'Koha::Patron->has_valid_userid should return 0 for the DB user (Bug 12226)' ); |
1233 |
|
1244 |
|
1234 |
# Add a new borrower with the same userid but different cardnumber |
1245 |
# Add a new borrower with the same userid but different cardnumber |
1235 |
$data{cardnumber} = "987654321"; |
1246 |
$data{cardnumber} = "987654321"; |
1236 |
my $new_borrowernumber = AddMember(%data); |
1247 |
my $new_borrowernumber = AddMember(%data); |
1237 |
is( Check_Userid( 'tomasito.none', '' ), |
|
|
1238 |
0, 'userid not unique (blank borrowernumber)' ); |
1239 |
is( Check_Userid( 'tomasito.none', $new_borrowernumber ), |
1240 |
0, 'userid not unique (second borrowernumber passed)' ); |
1241 |
my $patron_2 = Koha::Patrons->find($new_borrowernumber); |
1248 |
my $patron_2 = Koha::Patrons->find($new_borrowernumber); |
1242 |
ok( $patron_2->userid ne 'tomasito', |
1249 |
$patron_2->userid($patron_1->userid); |
1243 |
"Borrower with duplicate userid has new userid generated" ); |
1250 |
is( $patron_2->has_valid_userid, |
|
|
1251 |
0, 'The userid is already in used, it cannot be used for another patron' ); |
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" ); |
1244 |
|
1258 |
|
1245 |
my $new_userid = 'a_user_id'; |
1259 |
my $new_userid = 'a_user_id'; |
1246 |
$data{cardnumber} = "234567890"; |
1260 |
$data{cardnumber} = "234567890"; |
1247 |
- |
|
|