Bug 18736: (QA follow-up) Change to signed, add large int test
[1] Add trivial subtest in t/Number/Price.t
Checking a negative number and a large number for the MAX_INT change.
Note: Confusing to have t/Prices.t too.
[2] Change UNSIGNED to SIGNED in get_rounding_sql. Although I did not spot
problems with negative prices, we theoretically could while casting.
cast(-2 as unsigned) == 18446744073709551614
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
(cherry picked from commit 2f5e839bf7)
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
This commit is contained in:
parent
b67eb18c8a
commit
545551b173
|
|
@ -2012,7 +2012,7 @@ sub get_rounding_sql {
|
|||
my ( $round_string ) = @_;
|
||||
my $rounding_pref = C4::Context->preference('OrderPriceRounding') // q{};
|
||||
if ( $rounding_pref eq "nearest_cent" ) {
|
||||
return "CAST($round_string*100 AS UNSIGNED)/100";
|
||||
return "CAST($round_string*100 AS SIGNED)/100";
|
||||
}
|
||||
return $round_string;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use Modern::Perl;
|
||||
|
||||
use Test::More tests => 33;
|
||||
use Test::More tests => 34;
|
||||
|
||||
use Test::MockModule;
|
||||
use t::lib::Mocks;
|
||||
|
|
@ -134,3 +134,17 @@ is( Koha::Number::Price->new->unformat, '0', 'CHF: unformat 0' );
|
|||
is( Koha::Number::Price->new(3)->unformat, '3', 'CHF: unformat 3' );
|
||||
is( Koha::Number::Price->new(1234567890)->unformat,
|
||||
'1234567890', 'CHF: unformat 1234567890' );
|
||||
|
||||
subtest 'Changes for format' => sub { # See also bug 18736
|
||||
plan tests => 3;
|
||||
|
||||
t::lib::Mocks::mock_preference( 'CurrencyFormat', 'US' );
|
||||
|
||||
is( Koha::Number::Price->new(-2.125)->format, "-2.13", "Check negative value" );
|
||||
my $large_number = 2**53; # MAX_INT
|
||||
my $price = Koha::Number::Price->new($large_number);
|
||||
is( $price->format, $price->value, 'Format '.$price->value.' returns value' );
|
||||
like( Koha::Number::Price->new( 2**53/100 )->format,
|
||||
qr/\d\.\d{2}$/, 'This price still seems to be formatted' );
|
||||
# Note that the comparison with MAX_INT is already subject to rounding
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue