View | Details | Raw Unified | Return to bug 22618
Collapse All | Expand All

(-)a/t/Acquisition.t (-68 lines)
Lines 1-68 Link Here
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 => 3;
22
use t::lib::Mocks;
23
24
use_ok( 'C4::Acquisition' );
25
26
subtest 'Tests for get_rounding_sql' => sub {
27
28
    plan tests => 2;
29
30
    my $value = '3.141592';
31
32
    t::lib::Mocks::mock_preference( 'OrderPriceRounding', q{} );
33
    my $no_rounding_result = C4::Acquisition::get_rounding_sql($value);
34
    t::lib::Mocks::mock_preference( 'OrderPriceRounding', q{nearest_cent} );
35
    my $rounding_result = C4::Acquisition::get_rounding_sql($value);
36
37
    ok( $no_rounding_result eq $value, "Value ($value) not to be rounded" );
38
    ok( $rounding_result =~ /CAST/,    "Value ($value) will be rounded" );
39
40
};
41
42
subtest 'Test for get_rounded_price' => sub {
43
44
    plan tests => 6;
45
46
    my $exact_price      = 3.14;
47
    my $up_price         = 3.145592;
48
    my $down_price       = 3.141592;
49
    my $round_up_price   = sprintf( '%0.2f', $up_price );
50
    my $round_down_price = sprintf( '%0.2f', $down_price );
51
52
    t::lib::Mocks::mock_preference( 'OrderPriceRounding', q{} );
53
    my $not_rounded_result1 = C4::Acquisition::get_rounded_price($exact_price);
54
    my $not_rounded_result2 = C4::Acquisition::get_rounded_price($up_price);
55
    my $not_rounded_result3 = C4::Acquisition::get_rounded_price($down_price);
56
    t::lib::Mocks::mock_preference( 'OrderPriceRounding', q{nearest_cent} );
57
    my $rounded_result1 = C4::Acquisition::get_rounded_price($exact_price);
58
    my $rounded_result2 = C4::Acquisition::get_rounded_price($up_price);
59
    my $rounded_result3 = C4::Acquisition::get_rounded_price($down_price);
60
61
    is( $not_rounded_result1, $exact_price,      "Price ($exact_price) was correctly not rounded ($not_rounded_result1)" );
62
    is( $not_rounded_result2, $up_price,         "Price ($up_price) was correctly not rounded ($not_rounded_result2)" );
63
    is( $not_rounded_result3, $down_price,       "Price ($down_price) was correctly not rounded ($not_rounded_result3)" );
64
    is( $rounded_result1,     $exact_price,      "Price ($exact_price) was correctly rounded ($rounded_result1)" );
65
    is( $rounded_result2,     $round_up_price,   "Price ($up_price) was correctly rounded ($rounded_result2)" );
66
    is( $rounded_result3,     $round_down_price, "Price ($down_price) was correctly rounded ($rounded_result3)" );
67
68
};
(-)a/t/db_dependent/Acquisition.t (-2 / +44 lines)
Lines 19-25 use Modern::Perl; Link Here
19
19
20
use POSIX qw(strftime);
20
use POSIX qw(strftime);
21
21
22
use Test::More tests => 75;
22
use Test::More tests => 77;
23
use t::lib::Mocks;
23
use t::lib::Mocks;
24
use Koha::Database;
24
use Koha::Database;
25
use Koha::Acquisition::Basket;
25
use Koha::Acquisition::Basket;
Lines 795-798 subtest 'GetHistory with additional fields' => sub { Link Here
795
    is( scalar( @$history ), 1, 'GetHistory returns the order when additional field is set');
795
    is( scalar( @$history ), 1, 'GetHistory returns the order when additional field is set');
796
};
796
};
797
797
798
subtest 'Tests for get_rounding_sql' => sub {
799
800
    plan tests => 2;
801
802
    my $value = '3.141592';
803
804
    t::lib::Mocks::mock_preference( 'OrderPriceRounding', q{} );
805
    my $no_rounding_result = C4::Acquisition::get_rounding_sql($value);
806
    t::lib::Mocks::mock_preference( 'OrderPriceRounding', q{nearest_cent} );
807
    my $rounding_result = C4::Acquisition::get_rounding_sql($value);
808
809
    ok( $no_rounding_result eq $value, "Value ($value) not to be rounded" );
810
    ok( $rounding_result =~ /CAST/,    "Value ($value) will be rounded" );
811
812
};
813
814
subtest 'Test for get_rounded_price' => sub {
815
816
    plan tests => 6;
817
818
    my $exact_price      = 3.14;
819
    my $up_price         = 3.145592;
820
    my $down_price       = 3.141592;
821
    my $round_up_price   = sprintf( '%0.2f', $up_price );
822
    my $round_down_price = sprintf( '%0.2f', $down_price );
823
824
    t::lib::Mocks::mock_preference( 'OrderPriceRounding', q{} );
825
    my $not_rounded_result1 = C4::Acquisition::get_rounded_price($exact_price);
826
    my $not_rounded_result2 = C4::Acquisition::get_rounded_price($up_price);
827
    my $not_rounded_result3 = C4::Acquisition::get_rounded_price($down_price);
828
    t::lib::Mocks::mock_preference( 'OrderPriceRounding', q{nearest_cent} );
829
    my $rounded_result1 = C4::Acquisition::get_rounded_price($exact_price);
830
    my $rounded_result2 = C4::Acquisition::get_rounded_price($up_price);
831
    my $rounded_result3 = C4::Acquisition::get_rounded_price($down_price);
832
833
    is( $not_rounded_result1, $exact_price,      "Price ($exact_price) was correctly not rounded ($not_rounded_result1)" );
834
    is( $not_rounded_result2, $up_price,         "Price ($up_price) was correctly not rounded ($not_rounded_result2)" );
835
    is( $not_rounded_result3, $down_price,       "Price ($down_price) was correctly not rounded ($not_rounded_result3)" );
836
    is( $rounded_result1,     $exact_price,      "Price ($exact_price) was correctly rounded ($rounded_result1)" );
837
    is( $rounded_result2,     $round_up_price,   "Price ($up_price) was correctly rounded ($rounded_result2)" );
838
    is( $rounded_result3,     $round_down_price, "Price ($down_price) was correctly rounded ($rounded_result3)" );
839
840
};
798
$schema->storage->txn_rollback();
841
$schema->storage->txn_rollback();
799
- 

Return to bug 22618