From 196b7fc6572fe6a32ef5f380260c551d5d0a1d71 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 8 Jan 2018 18:35:58 -0300 Subject: [PATCH] Bug 19936: Move and add tests for Generate_Userid --- t/db_dependent/Koha/Patrons.t | 54 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 46 insertions(+), 8 deletions(-) diff --git a/t/db_dependent/Koha/Patrons.t b/t/db_dependent/Koha/Patrons.t index 23cc6387a5..b2b5b206ca 100644 --- a/t/db_dependent/Koha/Patrons.t +++ b/t/db_dependent/Koha/Patrons.t @@ -19,7 +19,7 @@ use Modern::Perl; -use Test::More tests => 26; +use Test::More tests => 27; use Test::Warn; use Time::Fake; use DateTime; @@ -1119,7 +1119,7 @@ subtest 'is_child | is_adult' => sub { }; subtest 'userid_is_valid' => sub { - plan tests => 10; + plan tests => 8; my $library = $builder->build_object( { class => 'Koha::Libraries' } ); my $patron_category = $builder->build_object( @@ -1171,12 +1171,6 @@ subtest 'userid_is_valid' => sub { is( $patron_2->has_valid_userid, 0, 'The userid is already in used, it cannot be used for another patron' ); - $patron_2 = Koha::Patrons->find($new_borrowernumber); - isnt( $patron_2->userid, 'tomasito', - "Patron with duplicate userid has new userid generated" ); - is( $patron_2->userid, $expected_userid_patron_1 . '1', # TODO we could make that configurable - "Patron with duplicate userid has new userid generated (1 is appened" ); - my $new_userid = 'a_user_id'; $data{cardnumber} = "234567890"; $data{userid} = 'a_user_id'; @@ -1191,6 +1185,50 @@ subtest 'userid_is_valid' => sub { $patron_3->delete; }; +subtest 'generate_userid' => sub { + plan tests => 6; + + my $library = $builder->build_object( { class => 'Koha::Libraries' } ); + my $patron_category = $builder->build_object( + { + class => 'Koha::Patron::Categories', + value => { category_type => 'P', enrolmentfee => 0 } + } + ); + my %data = ( + cardnumber => "123456789", + firstname => "Tomasito", + surname => "None", + categorycode => $patron_category->categorycode, + branchcode => $library->branchcode, + ); + + my $expected_userid_patron_1 = 'tomasito.none'; + my $userid = C4::Members::Generate_Userid( undef, $data{firstname}, $data{surname} ); + is( $userid, $expected_userid_patron_1, 'Generate_Userid should generate the userid we expect' ); + my $borrowernumber = AddMember(%data); + my $patron_1 = Koha::Patrons->find($borrowernumber); + is ( $patron_1->userid, $expected_userid_patron_1, 'The userid generated should be the one we expect' ); + + $userid = C4::Members::Generate_Userid( $borrowernumber, $data{firstname}, $data{surname} ); + is( $userid, $expected_userid_patron_1 . '1', 'Generate_Userid should generate the userid we expect' ); + $data{cardnumber} = '987654321'; + my $new_borrowernumber = AddMember(%data); + my $patron_2 = Koha::Patrons->find($new_borrowernumber); + isnt( $patron_2->userid, 'tomasito', + "Patron with duplicate userid has new userid generated" ); + is( $patron_2->userid, $expected_userid_patron_1 . '1', # TODO we could make that configurable + "Patron with duplicate userid has new userid generated (1 is appened" ); + + $userid = C4::Members::Generate_Userid( $borrowernumber, $data{firstname}, $data{surname} ); + is( $userid, $expected_userid_patron_1 . '2', 'Generate_Userid should generate the userid we expect' ); + + # Cleanup + $patron_1->delete; + $patron_2->delete; +}; + + $retrieved_patron_1->delete; is( Koha::Patrons->search->count, $nb_of_patrons + 1, 'Delete should have deleted the patron' ); -- 2.11.0