Selaa lähdekoodia

[ZF-9491] Zend_Currency:

- added usage of customized format token

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@21608 44c647ce-9c0f-0410-b52a-842ac1e357ba
thomas 16 vuotta sitten
vanhempi
commit
df7e4f882a
2 muutettua tiedostoa jossa 17 lisäystä ja 6 poistoa
  1. 6 4
      library/Zend/Currency.php
  2. 11 2
      tests/Zend/CurrencyTest.php

+ 6 - 4
library/Zend/Currency.php

@@ -843,10 +843,12 @@ class Zend_Currency
 
                 case 'format':
                     if ((empty($value) === false) and (Zend_Locale::isLocale($value, null, false) === false)) {
-                        require_once 'Zend/Currency/Exception.php';
-                        throw new Zend_Currency_Exception("'" .
-                            ((gettype($value) === 'object') ? get_class($value) : $value)
-                            . "' is not a known locale.");
+                        if (!is_string($value) || (strpos($value, '0') === false)) {
+                            require_once 'Zend/Currency/Exception.php';
+                            throw new Zend_Currency_Exception("'" .
+                                ((gettype($value) === 'object') ? get_class($value) : $value)
+                                . "' is no format token");
+                        }
                     }
                     break;
 

+ 11 - 2
tests/Zend/CurrencyTest.php

@@ -388,7 +388,7 @@ class Zend_CurrencyTest extends PHPUnit_Framework_TestCase
             $USD->setFormat(array('format' => 'unknown'));
             $this->fail("Exception expected");
         } catch (Zend_Currency_Exception $e) {
-            $this->assertContains("is not a known locale", $e->getMessage());
+            $this->assertContains("is no format token", $e->getMessage());
         }
 
         try {
@@ -785,9 +785,18 @@ class Zend_CurrencyTest extends PHPUnit_Framework_TestCase
     /**
      * IsLess values
      */
-    public function testContructingPrecisionValues()
+    public function testConstructingPrecisionValues()
     {
         $currency  = new Zend_Currency(array('value' => 100.5));
         $this->assertEquals('€ 100,50', $currency->toString('de_AT'));
     }
+
+    /**
+     * @ZF-9491
+     */
+    public function testCurrencyWithSelfPattern()
+    {
+        $currency  = new Zend_Currency(array('value' => 10000, 'format' => '#,#0', 'locale' => 'de_DE'));
+        $this->assertEquals('1.00.00', $currency->toString());
+    }
 }