Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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
  • Loading branch information
wnasich authored and markstory committed Jan 20, 2012
1 parent 2c239cc commit c95ab28
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
15 changes: 10 additions & 5 deletions lib/Cake/Test/Case/View/Helper/NumberHelperTest.php
Expand Up @@ -136,31 +136,31 @@ 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);

$result = $this->Number->currency(311, 'USD', array('wholePosition' => 'after'));
$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);

$result = $this->Number->currency(12, null, array('wholeSymbol' => ' dollars', 'wholePosition' => 'after', 'fractionSymbol' => ' cents', 'fractionPosition' => 'after'));
$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);
}
Expand All @@ -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);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/View/Helper/NumberHelper.php
Expand Up @@ -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,
);

/**
Expand Down

0 comments on commit c95ab28

Please sign in to comment.