From c95ab282dc661b9d4971556f14bd921bf4e9728c Mon Sep 17 00:00:00 2001 From: wnasich Date: Thu, 19 Jan 2012 18:24:00 -0300 Subject: [PATCH] Test case and Fix for: Number::currency() issue Fixes currency() for custom formats and numbers between -1 and 1. Fixes #2489 Conflicts: lib/Cake/Test/Case/View/Helper/NumberHelperTest.php lib/Cake/View/Helper/NumberHelper.php --- .../Test/Case/View/Helper/NumberHelperTest.php | 15 ++++++++++----- lib/Cake/View/Helper/NumberHelper.php | 2 +- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/Cake/Test/Case/View/Helper/NumberHelperTest.php b/lib/Cake/Test/Case/View/Helper/NumberHelperTest.php index 0e7a9a9a4a6..160ca2dde85 100644 --- a/lib/Cake/Test/Case/View/Helper/NumberHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/NumberHelperTest.php @@ -136,11 +136,11 @@ public function testCurrency() { $expected = '1.00 $'; $this->assertEquals($expected, $result); - $result = $this->Number->currency(.2, null, array('wholeSymbol' => ' $', 'wholePosition' => 'after', 'fractionSymbol' => 'cents')); + $result = $this->Number->currency(0.2, null, array('wholeSymbol' => ' $', 'wholePosition' => 'after', 'fractionSymbol' => 'cents')); $expected = '20cents'; $this->assertEquals($expected, $result); - $result = $this->Number->currency(.2, null, array('wholeSymbol' => ' $', 'wholePosition' => 'after', 'fractionSymbol' => 'cents', 'fractionPosition' => 'before')); + $result = $this->Number->currency(0.2, null, array('wholeSymbol' => ' $', 'wholePosition' => 'after', 'fractionSymbol' => 'cents', 'fractionPosition' => 'before')); $expected = 'cents20'; $this->assertEquals($expected, $result); @@ -148,7 +148,7 @@ public function testCurrency() { $expected = '311.00$'; $this->assertEquals($expected, $result); - $result = $this->Number->currency(.2, 'EUR'); + $result = $this->Number->currency(0.2, 'EUR'); $expected = '€0,20'; $this->assertEquals($expected, $result); @@ -156,11 +156,11 @@ public function testCurrency() { $expected = '12.00 dollars'; $this->assertEquals($expected, $result); - $result = $this->Number->currency(.12, null, array('wholeSymbol' => ' dollars', 'wholePosition' => 'after', 'fractionSymbol' => ' cents', 'fractionPosition' => 'after')); + $result = $this->Number->currency(0.12, null, array('wholeSymbol' => ' dollars', 'wholePosition' => 'after', 'fractionSymbol' => ' cents', 'fractionPosition' => 'after')); $expected = '12 cents'; $this->assertEquals($expected, $result); - $result = $this->Number->currency(.5, null, array('fractionSymbol' => false, 'fractionPosition' => 'before', 'wholeSymbol' => '$')); + $result = $this->Number->currency(0.5, null, array('fractionSymbol' => false, 'fractionPosition' => 'before', 'wholeSymbol' => '$')); $expected = '$0.50'; $this->assertEquals($expected, $result); } @@ -184,6 +184,11 @@ public function testCurrencyAddFormat() { $result = $this->Number->currency(-10, 'Other'); $expected = '($$ 10.00)'; $this->assertEquals($expected, $result); + + $this->Number->addFormat('Other2', array('before' => '$ ', 'after' => false)); + $result = $this->Number->currency(0.22, 'Other2'); + $expected = '$ 0.22'; + $this->assertEquals($expected,$result); } /** diff --git a/lib/Cake/View/Helper/NumberHelper.php b/lib/Cake/View/Helper/NumberHelper.php index 8c28333a65e..8457133f6fa 100644 --- a/lib/Cake/View/Helper/NumberHelper.php +++ b/lib/Cake/View/Helper/NumberHelper.php @@ -59,7 +59,7 @@ class NumberHelper extends AppHelper { */ protected $_currencyDefaults = array( 'wholeSymbol' => '', 'wholePosition' => 'before', 'fractionSymbol' => '', 'fractionPosition' => 'after', - 'zero' => '0', 'places' => 2, 'thousands' => ',', 'decimals' => '.','negative' => '()', 'escape' => true + 'zero' => '0', 'places' => 2, 'thousands' => ',', 'decimals' => '.','negative' => '()', 'escape' => true, ); /**