|
Line 0
Link Here
|
| 0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
| 3 |
# This file is part of Koha. |
| 4 |
# |
| 5 |
# Copyright (C) 2018 Mark Tompsett |
| 6 |
# |
| 7 |
# Koha is free software; you can redistribute it and/or modify it |
| 8 |
# under the terms of the GNU General Public License as published by |
| 9 |
# the Free Software Foundation; either version 3 of the License, or |
| 10 |
# (at your option) any later version. |
| 11 |
# |
| 12 |
# Koha is distributed in the hope that it will be useful, but |
| 13 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
# GNU General Public License for more details. |
| 16 |
# |
| 17 |
# You should have received a copy of the GNU General Public License |
| 18 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
| 19 |
|
| 20 |
use Modern::Perl; |
| 21 |
use Test::More tests => 6; |
| 22 |
use t::lib::Mocks; |
| 23 |
|
| 24 |
use C4::Acquisition; |
| 25 |
|
| 26 |
my $exact_price = 3.14; |
| 27 |
my $up_price = 3.145592; |
| 28 |
my $down_price = 3.141592; |
| 29 |
my $round_up_price = sprintf( '%0.2f', $up_price ); |
| 30 |
my $round_down_price = sprintf( '%0.2f', $down_price ); |
| 31 |
|
| 32 |
t::lib::Mocks::mock_preference( 'OrderPriceRounding', q{} ); |
| 33 |
my $not_rounded_result1 = C4::Acquisition::get_rounded_price($exact_price); |
| 34 |
my $not_rounded_result2 = C4::Acquisition::get_rounded_price($up_price); |
| 35 |
my $not_rounded_result3 = C4::Acquisition::get_rounded_price($down_price); |
| 36 |
t::lib::Mocks::mock_preference( 'OrderPriceRounding', q{nearest_cent} ); |
| 37 |
my $rounded_result1 = C4::Acquisition::get_rounded_price($exact_price); |
| 38 |
my $rounded_result2 = C4::Acquisition::get_rounded_price($up_price); |
| 39 |
my $rounded_result3 = C4::Acquisition::get_rounded_price($down_price); |
| 40 |
|
| 41 |
is( $not_rounded_result1, $exact_price, "Price ($exact_price) was correctly not rounded ($not_rounded_result1)" ); |
| 42 |
is( $not_rounded_result2, $up_price, "Price ($up_price) was correctly not rounded ($not_rounded_result2)" ); |
| 43 |
is( $not_rounded_result3, $down_price, "Price ($down_price) was correctly not rounded ($not_rounded_result3)" ); |
| 44 |
is( $rounded_result1, $exact_price, "Price ($exact_price) was correctly rounded ($rounded_result1)" ); |
| 45 |
is( $rounded_result2, $round_up_price, "Price ($up_price) was correctly rounded ($rounded_result2)" ); |
| 46 |
is( $rounded_result3, $round_down_price, "Price ($down_price) was correctly rounded ($rounded_result3)" ); |