From bc668dccd3af3fba14e04a764499b0d762c63455 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Fri, 6 Nov 2015 11:21:56 -0300 Subject: [PATCH] Bug 15151: Avoid DB access to load C4::Members MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit In order to avoid loading Koha::NorwegianPatronDB a DB query was used. Instead, a require should be used. This causes non-db_dependent tests that load C4::Members to fail. To test: - Shut mysql down $ sudo service mysql stop - Run the tests: prove t/Circulation_barcodedecode.t => FAIL: DB connection is expected, tests fail - Apply the patch - Run the tests: prove t/Circulation_barcodedecode.t => SUCCESS: Tests pass - Sign off .-D Signed-off-by: Kyle M Hall Signed-off-by: Martin Renvoize Signed-off-by: Tomas Cohen Arazi cherry-picked from f25fe6ddb4a340f12613784dc841ab5bfd672d6b Signed-off-by: Frédéric Demians --- C4/Members.pm | 11 ++++------- t/Circulation_barcodedecode.t | 34 ++++++++++++---------------------- 2 files changed, 16 insertions(+), 29 deletions(-) diff --git a/C4/Members.pm b/C4/Members.pm index abf843a7f8..a20565e4d0 100644 --- a/C4/Members.pm +++ b/C4/Members.pm @@ -41,10 +41,7 @@ use Koha::Borrower::Debarments qw(IsDebarred); use Text::Unaccent qw( unac_string ); use Koha::AuthUtils qw(hash_password); use Koha::Database; -use Module::Load; -if ( C4::Context->preference('NorwegianPatronDBEnable') && C4::Context->preference('NorwegianPatronDBEnable') == 1 ) { - load Koha::NorwegianPatronDB, qw( NLUpdateHashedPIN NLEncryptPIN NLSync ); -} +require Koha::NorwegianPatronDB; our ($VERSION,@ISA,@EXPORT,@EXPORT_OK,$debug); @@ -651,7 +648,7 @@ sub ModMember { } else { if ( C4::Context->preference('NorwegianPatronDBEnable') && C4::Context->preference('NorwegianPatronDBEnable') == 1 ) { # Update the hashed PIN in borrower_sync.hashed_pin, before Koha hashes it - NLUpdateHashedPIN( $data{'borrowernumber'}, $data{password} ); + Koha::NorwegianPatronDB::NLUpdateHashedPIN( $data{'borrowernumber'}, $data{password} ); } $data{password} = hash_password($data{password}); } @@ -703,7 +700,7 @@ sub ModMember { # Set the value of 'sync' $borrowersync->update( { 'sync' => $data{'sync'} } ); # Try to do the live sync - NLSync({ 'borrowernumber' => $data{'borrowernumber'} }); + Koha::NorwegianPatronDB::NLSync({ 'borrowernumber' => $data{'borrowernumber'} }); } logaction("MEMBERS", "MODIFY", $data{'borrowernumber'}, "UPDATE (executed w/ arg: $data{'borrowernumber'})") if C4::Context->preference("BorrowersLog"); @@ -779,7 +776,7 @@ sub AddMember { 'synctype' => 'norwegianpatrondb', 'sync' => 1, 'syncstatus' => 'new', - 'hashed_pin' => NLEncryptPIN( $plain_text_password ), + 'hashed_pin' => Koha::NorwegianPatronDB::NLEncryptPIN( $plain_text_password ), }); } diff --git a/t/Circulation_barcodedecode.t b/t/Circulation_barcodedecode.t index f397cc9b68..c55bc35fa5 100644 --- a/t/Circulation_barcodedecode.t +++ b/t/Circulation_barcodedecode.t @@ -18,17 +18,14 @@ use Modern::Perl; use Test::More tests => 26; -use t::lib::Mocks; + +use C4::Context; + +use_ok( 'C4::Circulation' ); C4::Context->_new_userenv(123456); C4::Context->set_userenv(1,'kmkale' , 1, 'km', 'kale' , 'IMS', 'IMS Branch DEscription', 0, 'kmkale@anantcorp.com'); -BEGIN { - # Mock the DB connexion and C4::Context - my $context = t::lib::Mocks::mock_dbh; - use_ok('C4::Circulation'); -} - our %inputs = ( cuecat => ["26002315", '.C3nZC3nZC3nYD3b6ENnZCNnY.fHmc.C3D1Dxr2C3nZE3n7.', ".C3nZC3nZC3nYD3b6ENnZCNnY.fHmc.C3D1Dxr2C3nZE3n7.\r\n", 'q.C3nZC3nZC3nWDNzYDxf2CNnY.fHmc.C3DWC3nZCNjXD3nW.', '.C3nZC3nZC3nWCxjWE3D1C3nX.cGf2.ENr7C3v7D3T3ENj3C3zYDNnZ.' ], @@ -50,25 +47,18 @@ our %outputs = ( my @filters = sort keys %inputs; foreach my $filter (@filters) { foreach my $datum (@{$inputs{$filter}}) { - my $expect = shift @{$outputs{$filter}} or die "Internal Test Error: missing expected output for filter '$filter' on input '$datum'"; + my $expect = shift @{$outputs{$filter}} + or die "Internal Test Error: missing expected output for filter '$filter' on input '$datum'"; my $output = C4::Circulation::barcodedecode($datum, $filter); ok($output eq $expect, sprintf("%12s: %20s => %15s", $filter, "'$datum'", "'$expect'")); ($output eq $expect) or diag "Bad output: '$output'"; } } -__END__ - -=head2 C4::Circulation::barcodedecode() - -This tests avoids being dependent on the database by using the optional -second argument to barcodedecode. - -T-prefix style is derived from zero-padded "Follett Classic Code 3 of 9". From: - www.fsc.follett.com/_file/File/pdf/Barcode%20Symbology%20Q%20%20A%203_05.pdf - - ~ 1 to 7 characters - ~ T, P or X followed by numeric characters - ~ No checkdigit +# T-prefix style is derived from zero-padded "Follett Classic Code 3 of 9". From: +# www.fsc.follett.com/_file/File/pdf/Barcode%20Symbology%20Q%20%20A%203_05.pdf +# ~ 1 to 7 characters +# ~ T, P or X followed by numeric characters +# ~ No checkdigit -=cut +1; -- 2.39.5