Bug 15151: 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

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Tomas Cohen Arazi 2015-11-06 11:21:56 -03:00
parent 7ce858491b
commit f25fe6ddb4
2 changed files with 16 additions and 28 deletions

View File

@ -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 ),
});
}

View File

@ -16,14 +16,12 @@
# along with Koha; if not, see <http://www.gnu.org/licenses>.
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__
# 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
=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
=cut
1;