Lines 1602-1608
subtest 'userid_is_valid' => sub {
Link Here
|
1602 |
}; |
1602 |
}; |
1603 |
|
1603 |
|
1604 |
subtest 'generate_userid' => sub { |
1604 |
subtest 'generate_userid' => sub { |
1605 |
plan tests => 7; |
1605 |
plan tests => 12; |
1606 |
|
1606 |
|
1607 |
my $library = $builder->build_object( { class => 'Koha::Libraries' } ); |
1607 |
my $library = $builder->build_object( { class => 'Koha::Libraries' } ); |
1608 |
my $patron_category = $builder->build_object( |
1608 |
my $patron_category = $builder->build_object( |
Lines 1617-1624
subtest 'generate_userid' => sub {
Link Here
|
1617 |
surname => "Ñoné", |
1617 |
surname => "Ñoné", |
1618 |
categorycode => $patron_category->categorycode, |
1618 |
categorycode => $patron_category->categorycode, |
1619 |
branchcode => $library->branchcode, |
1619 |
branchcode => $library->branchcode, |
|
|
1620 |
email => 'tomasito@example.com', |
1620 |
); |
1621 |
); |
1621 |
|
1622 |
|
|
|
1623 |
# "default" should generate userids like firstname.surname |
1624 |
t::lib::Mocks::mock_preference( 'PatronSelfRegistrationUseridGenerationMethod', 'default' ); |
1625 |
|
1622 |
my $expected_userid_patron_1 = 'tomasito.none'; |
1626 |
my $expected_userid_patron_1 = 'tomasito.none'; |
1623 |
my $new_patron = Koha::Patron->new({ firstname => $data{firstname}, surname => $data{surname} } ); |
1627 |
my $new_patron = Koha::Patron->new({ firstname => $data{firstname}, surname => $data{surname} } ); |
1624 |
$new_patron->generate_userid; |
1628 |
$new_patron->generate_userid; |
Lines 1637-1643
subtest 'generate_userid' => sub {
Link Here
|
1637 |
isnt( $patron_2->userid, 'tomasito', |
1641 |
isnt( $patron_2->userid, 'tomasito', |
1638 |
"Patron with duplicate userid has new userid generated" ); |
1642 |
"Patron with duplicate userid has new userid generated" ); |
1639 |
is( $patron_2->userid, $expected_userid_patron_1 . '1', # TODO we could make that configurable |
1643 |
is( $patron_2->userid, $expected_userid_patron_1 . '1', # TODO we could make that configurable |
1640 |
"Patron with duplicate userid has new userid generated (1 is appened" ); |
1644 |
"Patron with duplicate userid has new userid generated (1 is appended)" ); |
1641 |
|
1645 |
|
1642 |
$new_patron->generate_userid; |
1646 |
$new_patron->generate_userid; |
1643 |
$userid = $new_patron->userid; |
1647 |
$userid = $new_patron->userid; |
Lines 1652-1657
subtest 'generate_userid' => sub {
Link Here
|
1652 |
# Cleanup |
1656 |
# Cleanup |
1653 |
$patron_1->delete; |
1657 |
$patron_1->delete; |
1654 |
$patron_2->delete; |
1658 |
$patron_2->delete; |
|
|
1659 |
|
1660 |
# "email" should use email as userid if there is an email, otherwise fall back to firstname.surname |
1661 |
t::lib::Mocks::mock_preference( 'PatronSelfRegistrationUseridGenerationMethod', 'email' ); |
1662 |
|
1663 |
my $new_patron_email = Koha::Patron->new({ firstname => $data{firstname}, surname => $data{surname}, email => $data{email} } ); |
1664 |
$new_patron_email->generate_userid; |
1665 |
my $userid_email = $new_patron_email->userid; |
1666 |
is( $userid_email, $data{email}, 'userid should be the email address' ); |
1667 |
my $borrowernumber_email = Koha::Patron->new(\%data)->store->borrowernumber; |
1668 |
my $patron_1_email = Koha::Patrons->find($borrowernumber_email); |
1669 |
is ( $patron_1_email->userid, $data{email}, 'userid should be the email address also after storing' ); |
1670 |
|
1671 |
my $expected_userid_email_in_use = 'tomasito.none'; |
1672 |
$new_patron_email->generate_userid; |
1673 |
$userid = $new_patron_email->userid; |
1674 |
is( $userid, $expected_userid_email_in_use, 'generate_userid should default to firstname.surname if email is already in use' ); |
1675 |
|
1676 |
my $expected_userid_noemail = 'tomasito.none'; |
1677 |
my $new_patron_noemail = Koha::Patron->new({ firstname => $data{firstname}, surname => $data{surname} } ); |
1678 |
$new_patron_noemail->generate_userid; |
1679 |
my $userid_noemail = $new_patron_noemail->userid; |
1680 |
is( $userid_noemail, $expected_userid_noemail, 'generate_userid should default to firstname.surname wheren there is no email address' ); |
1681 |
delete $data{email}; |
1682 |
$data{cardnumber} = '9876543210'; |
1683 |
my $borrowernumber_noemail = Koha::Patron->new(\%data)->store->borrowernumber; |
1684 |
my $patron_2_noemail = Koha::Patrons->find($borrowernumber_noemail); |
1685 |
is ( $patron_2_noemail->userid, $expected_userid_noemail, 'generate_userid should be firstname.surname also after storing' ); |
1686 |
|
1687 |
$patron_1_email->delete; |
1688 |
$patron_2_noemail->delete; |
1655 |
}; |
1689 |
}; |
1656 |
|
1690 |
|
1657 |
$nb_of_patrons = Koha::Patrons->search->count; |
1691 |
$nb_of_patrons = Koha::Patrons->search->count; |
1658 |
- |
|
|