From 891b1a7f6b6693a6757beace54498b3c42545f0c Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Mon, 12 Dec 2016 13:48:40 +0100 Subject: [PATCH] Bug 17759: Remove invalid guarantorid's in Members.t Content-Type: text/plain; charset=utf-8 See also bug 17733. As long as we have no FK, these invalid guarantorid's can make tests fail. Adding a sql statement to clear them in the beginning of the test. Test plan: [1] Since it seems that AUTO_INC+8, +9 and +10 may fail one or two tests, we should manipulate one or two borrowers: Run this SQL query first: SELECT `AUTO_INCREMENT` FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '[your database]' and table_name='borrowers'; Now run: UPDATE borrowers SET guarantorid=[former value + 8] WHERE borrowernumber=[some existing borrowernumber] [2] Without this patch, run Members.t. Should fail two tests. [3] Apply the patch. Fetch the new AUTO_INCREMENT value and update guarantorid accordingly again for the manipulated borrower. [4] Run the test. It should not fail. Signed-off-by: Marcel de Rooy --- t/db_dependent/Members.t | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/t/db_dependent/Members.t b/t/db_dependent/Members.t index df309f3..dff6431 100755 --- a/t/db_dependent/Members.t +++ b/t/db_dependent/Members.t @@ -39,6 +39,9 @@ my $builder = t::lib::TestBuilder->new; my $dbh = C4::Context->dbh; $dbh->{RaiseError} = 1; +# Remove invalid guarantorid's as long as we have no FK +$dbh->do("UPDATE borrowers b1 LEFT JOIN borrowers b2 ON b2.borrowernumber=b1.guarantorid SET b1.guarantorid=NULL where b1.guarantorid IS NOT NULL AND b2.borrowernumber IS NULL"); + my $library1 = $builder->build({ source => 'Branch', }); @@ -263,6 +266,7 @@ my $borrower1 = $builder->build({ categorycode=>'STAFFER', branchcode => $library3->{branchcode}, dateexpiry => '2015-01-01', + guarantorid=> undef, }, }); my $bor1inlist = $borrower1->{borrowernumber}; @@ -272,6 +276,7 @@ my $borrower2 = $builder->build({ categorycode=>'STAFFER', branchcode => $library3->{branchcode}, dateexpiry => '2015-01-01', + guarantorid=> undef, }, }); @@ -281,6 +286,7 @@ my $guarantee = $builder->build({ categorycode=>'KIDclamp', branchcode => $library3->{branchcode}, dateexpiry => '2015-01-01', + guarantorid=> undef, # will be filled later }, }); @@ -294,11 +300,6 @@ $builder->build({ }, }); -# In some dirty DB, the guarantorid is set to a non existent patron id -# If we pick it, then the tests will fail -# This should not be needed, we should have a FK on the guarantorid instead -Koha::Patrons->search({ guarantorid => { -in => [ $borrower1->{borrowernumber}, $borrower2->{borrowernumber} ] }})->update({ guarantorid => undef }); - my $owner = AddMember (categorycode => 'STAFFER', branchcode => $library2->{branchcode} ); my $list1 = AddPatronList( { name => 'Test List 1', owner => $owner } ); my @listpatrons = ($bor1inlist, $bor2inlist); -- 2.1.4