From f38c944c7aa45048a66156095530a8378002eaa3 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 8 Jan 2018 17:14:49 -0300 Subject: [PATCH] Bug 19936: Replace Check_userid - just move the tests This patch moves the tests related to Check_userid out of Members.t The tests must pass with only this patch applied Signed-off-by: Josef Moravec --- t/db_dependent/Koha/Patrons.t | 61 ++++++++++++++++++++++++++++++++++++++++++- t/db_dependent/Members.t | 40 ++++++---------------------- 2 files changed, 68 insertions(+), 33 deletions(-) diff --git a/t/db_dependent/Koha/Patrons.t b/t/db_dependent/Koha/Patrons.t index f0b1992..9f0f042 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 => 27; +use Test::More tests => 28; use Test::Warn; use Time::Fake; use DateTime; @@ -1197,6 +1197,65 @@ subtest 'get_overdues' => sub { $patron->delete; }; +subtest 'userid_is_valid' => sub { + plan tests => 9; + + 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 $borrowernumber = AddMember(%data); + my $patron_1 = Koha::Patrons->find($borrowernumber); + + is( Check_Userid( 'tomasito.non', $patron_1->borrowernumber ), + 1, 'recently created userid -> unique (borrowernumber passed)' ); + is( Check_Userid( 'tomasitoxxx', $patron_1->borrowernumber ), + 1, 'non-existent userid -> unique (borrowernumber passed)' ); + is( Check_Userid( 'tomasito.none', '' ), + 0, 'userid exists (blank borrowernumber)' ); + is( Check_Userid( 'tomasitoxxx', '' ), + 1, 'non-existent userid -> unique (blank borrowernumber)' ); + + # Regression tests for BZ12226 + is( Check_Userid( C4::Context->config('user'), '' ), + 0, 'Check_Userid should return 0 for the DB user (Bug 12226)' ); + + # Add a new borrower with the same userid but different cardnumber + $data{cardnumber} = "987654321"; + my $new_borrowernumber = AddMember(%data); + is( Check_Userid( 'tomasito.none', '' ), + 0, 'userid not unique (blank borrowernumber)' ); + is( Check_Userid( 'tomasito.none', $new_borrowernumber ), + 0, 'userid not unique (second borrowernumber passed)' ); + my $patron_2 = Koha::Patrons->find($new_borrowernumber); + ok( $patron_2->userid ne 'tomasito', + "Borrower with duplicate userid has new userid generated" ); + + my $new_userid = 'a_user_id'; + $data{cardnumber} = "234567890"; + $data{userid} = 'a_user_id'; + $borrowernumber = AddMember(%data); + my $patron_3 = Koha::Patrons->find($borrowernumber); + is( $patron_3->userid, $new_userid, + 'AddMember should insert the given userid' ); + + # Cleanup + $patron_1->delete; + $patron_2->delete; + $patron_3->delete; +}; + $retrieved_patron_1->delete; is( Koha::Patrons->search->count, $nb_of_patrons + 1, 'Delete should have deleted the patron' ); diff --git a/t/db_dependent/Members.t b/t/db_dependent/Members.t index c7bc6b3..07a7a30 100755 --- a/t/db_dependent/Members.t +++ b/t/db_dependent/Members.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 60; +use Test::More tests => 51; use Test::MockModule; use Test::Exception; @@ -139,7 +139,7 @@ $checkcardnum=C4::Members::checkcardnumber($IMPOSSIBLE_CARDNUMBER, ""); is ($checkcardnum, "2", "Card number is too long"); -# Check_Userid tests +# Add a new borrower %data = ( cardnumber => "123456789", firstname => "Tomasito", @@ -151,17 +151,7 @@ is ($checkcardnum, "2", "Card number is too long"); dateexpiry => '', dateenrolled => '', ); -# Add a new borrower my $borrowernumber = AddMember( %data ); -is( Check_Userid( 'tomasito.non', $borrowernumber ), 1, - 'recently created userid -> unique (borrowernumber passed)' ); -is( Check_Userid( 'tomasitoxxx', $borrowernumber ), 1, - 'non-existent userid -> unique (borrowernumber passed)' ); -is( Check_Userid( 'tomasito.none', '' ), 0, - 'userid exists (blank borrowernumber)' ); -is( Check_Userid( 'tomasitoxxx', '' ), 1, - 'non-existent userid -> unique (blank borrowernumber)' ); - my $borrower = Koha::Patrons->find( $borrowernumber )->unblessed; is( $borrower->{dateofbirth}, undef, 'AddMember should undef dateofbirth if empty string is given'); is( $borrower->{debarred}, undef, 'AddMember should undef debarred if empty string is given'); @@ -182,24 +172,14 @@ is( $borrower->{debarred}, '2042-01-01', 'ModMember should correctly set debarre is( $borrower->{dateexpiry}, '9999-12-31', 'ModMember should correctly set dateexpiry if a valid date is given'); is( $borrower->{dateenrolled}, '2015-09-06', 'ModMember should correctly set dateenrolled if a valid date is given'); -# Add a new borrower with the same userid but different cardnumber -$data{ cardnumber } = "987654321"; -my $new_borrowernumber = AddMember( %data ); -is( Check_Userid( 'tomasito.none', '' ), 0, - 'userid not unique (blank borrowernumber)' ); -is( Check_Userid( 'tomasito.none', $new_borrowernumber ), 0, - 'userid not unique (second borrowernumber passed)' ); -$borrower = Koha::Patrons->find( $new_borrowernumber )->unblessed; -ok( $borrower->{userid} ne 'tomasito', "Borrower with duplicate userid has new userid generated" ); - -$data{ cardnumber } = "234567890"; -$data{userid} = 'a_user_id'; -$borrowernumber = AddMember( %data ); -$borrower = Koha::Patrons->find( $borrowernumber )->unblessed; -is( $borrower->{userid}, $data{userid}, 'AddMember should insert the given userid' ); - subtest 'ModMember should not update userid if not true' => sub { plan tests => 3; + + $data{ cardnumber } = "234567890"; + $data{userid} = 'a_user_id'; + $borrowernumber = AddMember( %data ); + $borrower = Koha::Patrons->find( $borrowernumber )->unblessed; + ModMember( borrowernumber => $borrowernumber, firstname => 'Tomas', userid => '' ); $borrower = Koha::Patrons->find( $borrowernumber )->unblessed; is ( $borrower->{userid}, $data{userid}, 'ModMember should not update the userid with an empty string' ); @@ -369,10 +349,6 @@ ok( $borrowernumber > 0, 'AddMember should have inserted the patron even if no u $borrower = Koha::Patrons->find( $borrowernumber )->unblessed; ok( $borrower->{userid}, 'A userid should have been generated correctly' ); -# Regression tests for BZ12226 -is( Check_Userid( C4::Context->config('user'), '' ), 0, - 'Check_Userid should return 0 for the DB user (Bug 12226)'); - subtest 'purgeSelfRegistration' => sub { plan tests => 2; -- 2.1.4