From aca614cd95b32d2953927e8e3e908bc1248b541c Mon Sep 17 00:00:00 2001 From: Fridolin Somers Date: Thu, 6 Jul 2017 08:44:51 +0200 Subject: [PATCH] Bug 18900: add UT to Number/Price.t This patch adds unit tests to t/Number/Price.t in order to valid the problem. Signed-off-by: Katrin Fischer Signed-off-by: Tomas Cohen Arazi Signed-off-by: Jonathan Druart (cherry picked from commit 91dee226cdd089353dc71e559aa9e0b34fddf72e) Signed-off-by: Fridolin Somers --- t/Number/Price.t | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/t/Number/Price.t b/t/Number/Price.t index ad4f0cf7ba..99d23bcbd8 100644 --- a/t/Number/Price.t +++ b/t/Number/Price.t @@ -1,16 +1,21 @@ use Modern::Perl; -use Test::More tests => 28; +use Test::More tests => 30; use Test::MockModule; use t::lib::Mocks; +# Number formating depends by default on system environement +# See http://search.cpan.org/~wrw/Number-Format/Format.pm +use POSIX qw(setlocale LC_NUMERIC); + use Koha::Acquisition::Currencies; my $budget_module = Test::MockModule->new('Koha::Acquisition::Currencies'); my $currency; $budget_module->mock( 'get_active', sub { return $currency; } ); use_ok('Koha::Number::Price'); +my $orig_locale = setlocale(LC_NUMERIC); my $format = { p_cs_precedes => 1, # Force to place the symbol at the beginning p_sep_by_space => 0, # Force to not add a space between the symbol and the number @@ -44,6 +49,14 @@ is( Koha::Number::Price->new(3)->unformat, '3', 'US: unformat 3' ); is( Koha::Number::Price->new(1234567890)->unformat, '1234567890', 'US: unformat 1234567890' ); +# Bug 18900 - Check params are not from system environement +setlocale(LC_NUMERIC, "fr_FR.UTF-8"); +is( Koha::Number::Price->new(12345678.9)->format( { %$format, with_symbol => 1 } ), + '12,345,678.90', 'US: format 12,345,678.90 with symbol' ); +is( Koha::Number::Price->new('12,345,678.90')->unformat, + '12345678.9', 'US: unformat 12345678.9' ); +setlocale(LC_NUMERIC, $orig_locale); + t::lib::Mocks::mock_preference( 'CurrencyFormat', 'FR' ); $currency = Koha::Acquisition::Currency->new({ currency => 'EUR', -- 2.39.5