Bug 18226 - Remove "use Test::DBIx::Class" instantiations' dangerous code duplication. Replace mock_dbh 2

Couldn't make the tests pass using Test::DBIx::Class, so reverted to the "usual way" since these tests are
in db_dependent anyway.

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Olli-Antti Kivilahti 2017-03-08 17:34:28 +02:00 committed by Jonathan Druart
parent 1985e6e4b3
commit 617988a7c1
2 changed files with 18 additions and 33 deletions

View file

@ -7,31 +7,29 @@ use Test::MockModule;
use DBI;
use DateTime;
use t::lib::Mocks;
BEGIN {
t::lib::Mocks::mock_dbh;
}
use t::lib::TestBuilder;
use_ok('C4::Circulation');
my $dbh = C4::Context->dbh();
my $issuelength = 10;
my $renewalperiod = 5;
my $lengthunit = 'days';
my $mock_undef = [
[]
];
my $mock_loan_length = [
['issuelength', 'renewalperiod', 'lengthunit'],
[$issuelength, $renewalperiod, $lengthunit]
];
my $schema = Koha::Database->new->schema;
$schema->storage->txn_begin;
my $builder = t::lib::TestBuilder->new;
my $categorycode = 'B';
my $itemtype = 'MX';
my $branchcode = 'FPL';
my $issuelength = 10;
my $renewalperiod = 5;
my $lengthunit = 'days';
Koha::Database->schema->resultset('Issuingrule')->create({
categorycode => $categorycode,
itemtype => $itemtype,
branchcode => $branchcode,
issuelength => $issuelength,
renewalperiod => $renewalperiod,
lengthunit => $lengthunit,
});
#Set syspref ReturnBeforeExpiry = 1 and useDaysMode = 'Days'
t::lib::Mocks::mock_preference('ReturnBeforeExpiry', 1);
@ -41,10 +39,8 @@ my $dateexpiry = '2013-01-01';
my $borrower = {categorycode => 'B', dateexpiry => $dateexpiry};
my $start_date = DateTime->new({year => 2013, month => 2, day => 9});
$dbh->{mock_add_resultset} = $mock_loan_length;
my $date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower );
is($date, $dateexpiry . 'T23:59:00', 'date expiry');
$dbh->{mock_add_resultset} = $mock_loan_length;
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower, 1 );
@ -54,11 +50,9 @@ t::lib::Mocks::mock_preference('useDaysMode', 'noDays');
$borrower = {categorycode => 'B', dateexpiry => $dateexpiry};
$start_date = DateTime->new({year => 2013, month => 2, day => 9});
$dbh->{mock_add_resultset} = $mock_loan_length;
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower );
is($date, $dateexpiry . 'T23:59:00', 'date expiry');
$dbh->{mock_add_resultset} = $mock_loan_length;
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower, 1 );
@ -68,10 +62,10 @@ t::lib::Mocks::mock_preference('useDaysMode', 'Days');
$borrower = {categorycode => 'B', dateexpiry => $dateexpiry};
$start_date = DateTime->new({year => 2013, month => 2, day => 9});
$dbh->{mock_add_resultset} = $mock_loan_length;
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower );
is($date, '2013-02-' . (9 + $issuelength) . 'T23:59:00', "date expiry ( 9 + $issuelength )");
$dbh->{mock_add_resultset} = $mock_loan_length;
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower, 1 );
is($date, '2013-02-' . (9 + $renewalperiod) . 'T23:59:00', "date expiry ( 9 + $renewalperiod )");
$schema->storage->txn_rollback;

View file

@ -41,13 +41,4 @@ sub mock_preference {
});
}
sub mock_dbh {
our $context = new Test::MockModule('Koha::Database');
$context->mock( '_new_schema', sub {
my $dbh = Koha::Schema->connect( 'DBI:Mock:', '', '' );
return $dbh;
} );
return $context;
}
1;