Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/4805' into develop
Browse files Browse the repository at this point in the history
Forward port #4805
  • Loading branch information
weierophinney committed Jul 19, 2013
2 parents a6ac2b9 + 8bc0d47 commit ec73597
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
26 changes: 23 additions & 3 deletions library/Zend/I18n/View/Helper/CurrencyFormat.php
Expand Up @@ -90,13 +90,33 @@ public function __invoke(
if (null === $currencyCode) {
$currencyCode = $this->getCurrencyCode();
}
if (null !== $showDecimals) {
$this->setShouldShowDecimals($showDecimals);
if (null === $showDecimals) {
$showDecimals = $this->shouldShowDecimals();
}
if (null === $pattern) {
$pattern = $this->getCurrencyPattern();
}

return $this->formatCurrency($number, $currencyCode, $showDecimals, $locale, $pattern);
}

/**
* Format a number
*
* @param float $number
* @param string $currencyCode
* @param bool $showDecimals
* @param string $locale
* @param string $pattern
* @return string
*/
protected function formatCurrency(
$number,
$currencyCode,
$showDecimals,
$locale,
$pattern
) {
$formatterId = md5($locale);

if (!isset($this->formatters[$formatterId])) {
Expand All @@ -110,7 +130,7 @@ public function __invoke(
$this->formatters[$formatterId]->setPattern($pattern);
}

if ($this->shouldShowDecimals()) {
if ($showDecimals) {
$this->formatters[$formatterId]->setAttribute(NumberFormatter::FRACTION_DIGITS, 2);
} else {
$this->formatters[$formatterId]->setAttribute(NumberFormatter::FRACTION_DIGITS, 0);
Expand Down
10 changes: 10 additions & 0 deletions tests/ZendTest/I18n/View/Helper/CurrencyFormatTest.php
Expand Up @@ -103,6 +103,16 @@ public function testSettersProvideDefaults(
$this->assertMbStringEquals($expected, $this->helper->__invoke($number));
}

public function testViewhelperExecutedSequentially()
{
$helper = $this->helper;
$helper->setShouldShowDecimals(true);

$this->assertEquals('1.234,43 €', $helper(1234.4321, 'EUR', null, 'de_DE'));
$this->assertEquals('1.234 €', $helper(1234.4321, 'EUR', false, 'de_DE'));
$this->assertEquals('1.234,43 €', $helper(1234.4321, 'EUR', null, 'de_DE'));
}

public function testDefaultLocale()
{
$this->assertMbStringEquals(Locale::getDefault(), $this->helper->getLocale());
Expand Down

0 comments on commit ec73597

Please sign in to comment.