From 126d8a13a32227bae61b03005b200b8e0d6b152f Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Fri, 6 Nov 2015 11:21:56 -0300 Subject: [PATCH] Bug 15151: (counter patch) Avoid DB access to load C4::Members 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 --- C4/Members.pm | 11 ++++------- t/Circulation_barcodedecode.t | 33 ++++++++++++--------------------- 2 files changed, 16 insertions(+), 28 deletions(-) diff --git a/C4/Members.pm b/C4/Members.pm index 171f3c0..9166b75 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}); } @@ -705,7 +702,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"); @@ -781,7 +778,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 5b1e065..eff9624 100644 --- a/t/Circulation_barcodedecode.t +++ b/t/Circulation_barcodedecode.t @@ -16,14 +16,12 @@ # along with Koha; if not, see . use Modern::Perl; -use Test::More tests => 25; -use t::lib::Mocks; -use C4::Circulation; + +use Test::More tests => 26; + use C4::Context; -BEGIN { - t::lib::Mocks::mock_dbh; -}; +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'); @@ -49,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.6.2