Details
-
Type:
Bug
-
Status:
Open
-
Priority:
Major
-
Resolution: Unresolved
-
Affects Version/s: 1.11.10
-
Fix Version/s: None
-
Component/s: Zend_Currency
Description
For a locale which defines a currency symbol, it's completely useless to define the display option because the constructor overwrites it with the Zend_Currency::USE_SYMBOL constant.
// Get the format if (!empty($this->_options['symbol'])) { $this->_options['display'] = self::USE_SYMBOL; }
So the following code doesn't work:
$currency = new Zend_Currency(array('value' => 100, 'display' => Zend_Currency::USE_SHORTNAME), 'de_DE');
print $currency;
Because this code prints always the currency symbol €.
Reproducing unit test case (against locale en_US for convenience):
Index: tests/Zend/CurrencyTest.php =================================================================== --- tests/Zend/CurrencyTest.php (revision 24537) +++ tests/Zend/CurrencyTest.php (working copy) @@ -826,4 +826,28 @@ $currency->setService('Zend_Currency_Service'); $this->assertTrue($currency->getService() instanceof Zend_Currency_Service); } + + /** + * @group ZF-11798 + * @dataProvider providerConstructorAllowsOverridingCurrencyDisplayFormat + */ + public function testConstructorAllowsOverridingCurrencyDisplayFormat($display, $expected) + { + $currency = new Zend_Currency(array('value' => 100, 'display' => $display), 'en_US'); + $this->assertEquals($expected, $currency->toString()); + } + + /** + * Data Provider for testConstructorAllowsOverridingCurrencyDisplayFormat + * @see ZF-11798 + */ + public function providerConstructorAllowsOverridingCurrencyDisplayFormat() + { + return array( + array(Zend_Currency::NO_SYMBOL, '100.00'), + array(Zend_Currency::USE_SYMBOL, '$100.00'), + array(Zend_Currency::USE_SHORTNAME, 'USD100.00'), + array(Zend_Currency::USE_NAME, 'US Dollar100.00') + ); + } }Result:
Index: tests/Zend/CurrencyTest.php =================================================================== --- tests/Zend/CurrencyTest.php (revision 24537) +++ tests/Zend/CurrencyTest.php (working copy) @@ -826,4 +826,28 @@ $currency->setService('Zend_Currency_Service'); $this->assertTrue($currency->getService() instanceof Zend_Currency_Service); } + + /** + * @group ZF-11798 + * @dataProvider providerConstructorAllowsOverridingCurrencyDisplayFormat + */ + public function testConstructorAllowsOverridingCurrencyDisplayFormat($display, $expected) + { + $currency = new Zend_Currency(array('value' => 100, 'display' => $display), 'en_US'); + $this->assertEquals($expected, $currency->toString()); + } + + /** + * Data Provider for testConstructorAllowsOverridingCurrencyDisplayFormat + * @see ZF-11798 + */ + public function providerConstructorAllowsOverridingCurrencyDisplayFormat() + { + return array( + array(Zend_Currency::NO_SYMBOL, '100.00'), + array(Zend_Currency::USE_SYMBOL, '$100.00'), + array(Zend_Currency::USE_SHORTNAME, 'USD100.00'), + array(Zend_Currency::USE_NAME, 'US Dollar100.00') + ); + } }