From f6145a7f6f895ee05970480133ddf949c5dca585 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 13 Aug 2018 12:36:41 -0300 Subject: [PATCH] Bug 21196: Add tests --- t/db_dependent/Circulation/CalcFine.t | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/t/db_dependent/Circulation/CalcFine.t b/t/db_dependent/Circulation/CalcFine.t index 862673f53d..24cf5800b7 100644 --- a/t/db_dependent/Circulation/CalcFine.t +++ b/t/db_dependent/Circulation/CalcFine.t @@ -12,12 +12,14 @@ use Koha::DateUtils qw( dt_from_string ); use t::lib::TestBuilder; use t::lib::Mocks; -our $dbh = C4::Context->dbh; -$dbh->{AutoCommit} = 0; -$dbh->{RaiseError} = 1; +my $schema = Koha::Database->schema; +$schema->storage->txn_begin; +our $dbh = C4::Context->dbh; $dbh->do(q|DELETE FROM issues|); +t::lib::Mocks::mock_preference('item-level_itypes', '1'); + my $builder = t::lib::TestBuilder->new(); my $branch = $builder->build( @@ -51,6 +53,15 @@ my $biblio = $builder->build( } ); +my $itemtype = $builder->build( + { + source => 'Itemtype', + value => { + defaultreplacecost => 6, + }, + } +); + my $item = $builder->build( { source => 'Item', @@ -59,6 +70,7 @@ my $item = $builder->build( homebranch => $branch->{branchcode}, holdingbranch => $branch->{branchcode}, replacementprice => '5.00', + itype => $itemtype->{itemtype}, }, } ); @@ -110,7 +122,9 @@ subtest 'Test basic functionality' => sub { }; subtest 'Test cap_fine_to_replacement_price' => sub { - plan tests => 1; + plan tests => 2; + + t::lib::Mocks::mock_preference('useDefaultReplacementCost', '1'); my $issuingrule = $builder->build( { source => 'Issuingrule', @@ -143,7 +157,14 @@ subtest 'Test cap_fine_to_replacement_price' => sub { my ($amount) = CalcFine( $item, $patron->{categorycode}, $branch->{branchcode}, $start_dt, $end_dt ); - is( $amount, '5.00', 'Amount is calculated correctly' ); + is( int($amount), 5, 'Amount is calculated correctly' ); + + + # Use default replacement cost (useDefaultReplacementCost) is item's replacement price is 0 + my $item_obj = Koha::Items->find($item->{itemnumber}); + $item_obj->replacementprice(0)->store; + ($amount) = CalcFine( $item_obj->unblessed, $patron->{categorycode}, $branch->{branchcode}, $start_dt, $end_dt ); + is( int($amount), 6, 'Amount is calculated correctly' ); teardown(); }; -- 2.11.0