From c26f4bced87e3208105666e9fcd847d5b29dc6e2 Mon Sep 17 00:00:00 2001 From: Fabio Bas Date: Tue, 17 Sep 2013 23:24:10 +0200 Subject: NumberFormat: force the use of C locale when formatting numbers. Add some testcases. Fixes #486 --- tests/unit/I18N/core/NumberFormatTest.php | 67 ++++++++++++++++++++++++------- 1 file changed, 53 insertions(+), 14 deletions(-) (limited to 'tests/unit') diff --git a/tests/unit/I18N/core/NumberFormatTest.php b/tests/unit/I18N/core/NumberFormatTest.php index 6a6f2dd0..958f05f4 100644 --- a/tests/unit/I18N/core/NumberFormatTest.php +++ b/tests/unit/I18N/core/NumberFormatTest.php @@ -24,6 +24,7 @@ class NumberFormatTest extends PHPUnit_Framework_TestCase { $fr = new NumberFormat('fr'); $de = new NumberFormat('de'); $ja = new NumberFormat('ja_JP'); + $it = new NumberFormat('it_IT'); $number = '123456789.125156'; @@ -42,6 +43,10 @@ class NumberFormatTest extends PHPUnit_Framework_TestCase { //custom/unkown currency $wanted = 'DLL123,456,789'; $this->assertEquals($wanted, $ja->format($number,'c','DLL')); + + //italian + $wanted = '€ 123.456.789,13'; + $this->assertEquals($wanted, $it->format($number,'c','EUR')); } function testCustomFormat() { @@ -108,24 +113,58 @@ class NumberFormatTest extends PHPUnit_Framework_TestCase { function testRounding() { - $formatter = new NumberFormat(); - - $number = 349.999; - $pattern = '#.00'; - $expected = '350.00'; - - $this->assertEquals($expected, $formatter->format($number, $pattern)); + $formatter = new NumberFormat(); + + $number = 349.999; + $pattern = '#.00'; + $expected = '350.00'; + + $this->assertEquals($expected, $formatter->format($number, $pattern)); } function testRounding2() { - $formatter = new NumberFormat(); - - $number = 349.99; - $pattern = '#.00'; - $expected = '349.99'; - - $this->assertEquals($expected, $formatter->format($number, $pattern)); + $formatter = new NumberFormat(); + + $number = 349.99; + $pattern = '#.00'; + $expected = '349.99'; + + $this->assertEquals($expected, $formatter->format($number, $pattern)); + } + + function testLocalizedCurrencyFormats2() { + + $it = new NumberFormat('it_IT'); + + $number = 12.41; + $wanted = '12,41'; + $this->assertEquals($wanted, $it->format($number,'d')); + + $number = 10.23; + $wanted = '10,23'; + $this->assertEquals($wanted, $it->format($number,'d')); + + $number = 10010.23; + $wanted = '10.010,23'; + $this->assertEquals($wanted, $it->format($number,'d')); + + $old= setlocale(LC_ALL,"0"); + setlocale(LC_ALL,"it_IT"); + + $number = 12.41; + $wanted = '12,41'; + $this->assertEquals($wanted, $it->format($number,'d')); + + $number = 10.23; + $wanted = '10,23'; + $this->assertEquals($wanted, $it->format($number,'d')); + + $number = 10010.23; + $wanted = '10.010,23'; + $this->assertEquals($wanted, $it->format($number,'d')); + + setlocale(LC_ALL,$old); } } -- cgit v1.2.3