| 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 => 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 | }; | 
            
              | 69 |  |