CurrencyTest.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Currency
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2006 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /**
  23. * Test helper
  24. */
  25. require_once dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'TestHelper.php';
  26. /**
  27. * Zend_Currency
  28. */
  29. require_once 'Zend/Locale.php';
  30. require_once 'Zend/Currency.php';
  31. /**
  32. * PHPUnit test case
  33. */
  34. require_once 'PHPUnit/Framework.php';
  35. /**
  36. * @package Zend_Currency
  37. * @subpackage UnitTests
  38. */
  39. class Zend_CurrencyTest extends PHPUnit_Framework_TestCase
  40. {
  41. public function setUp()
  42. {
  43. require_once 'Zend/Cache.php';
  44. $cache = Zend_Cache::factory('Core', 'File',
  45. array('lifetime' => 120, 'automatic_serialization' => true),
  46. array('cache_dir' => dirname(__FILE__) . '/_files/'));
  47. Zend_Currency::setCache($cache);
  48. }
  49. /**
  50. * tests the creation of Zend_Currency
  51. */
  52. public function testSingleCreation()
  53. {
  54. // look if locale is detectable
  55. try {
  56. $locale = new Zend_Locale();
  57. } catch (Zend_Locale_Exception $e) {
  58. $this->markTestSkipped('Autodetection of locale failed');
  59. return;
  60. }
  61. $locale = new Zend_Locale('de_AT');
  62. try {
  63. $currency = new Zend_Currency();
  64. $this->assertTrue($currency instanceof Zend_Currency);
  65. } catch (Zend_Currency_Exception $e) {
  66. $this->assertContains('No region found within the locale', $e->getMessage());
  67. }
  68. $currency = new Zend_Currency('de_AT');
  69. $this->assertTrue($currency instanceof Zend_Currency);
  70. $this->assertSame('€ 1.000,00', $currency->toCurrency(1000));
  71. $currency = new Zend_Currency('de_DE');
  72. $this->assertTrue($currency instanceof Zend_Currency);
  73. $this->assertSame('1.000,00 €', $currency->toCurrency(1000));
  74. $currency = new Zend_Currency($locale);
  75. $this->assertTrue($currency instanceof Zend_Currency);
  76. $this->assertSame('€ 1.000,00', $currency->toCurrency(1000));
  77. try {
  78. $currency = new Zend_Currency('de_XX');
  79. $this->fail("locale should always include region and therefor not been recognised");
  80. } catch (Zend_Currency_Exception $e) {
  81. // success
  82. }
  83. try {
  84. $currency = new Zend_Currency('xx_XX');
  85. $this->fail("unknown locale should not have been recognised");
  86. } catch (Zend_Currency_Exception $e) {
  87. // success
  88. }
  89. try {
  90. $currency = new Zend_Currency('EUR');
  91. $this->assertTrue($currency instanceof Zend_Currency);
  92. } catch (Zend_Currency_Exception $e) {
  93. $this->assertContains('No region found within the locale', $e->getMessage());
  94. }
  95. try {
  96. $currency = new Zend_Currency('USD');
  97. $this->assertTrue($currency instanceof Zend_Currency);
  98. } catch (Zend_Currency_Exception $e) {
  99. $this->assertContains('No region found within the locale', $e->getMessage());
  100. }
  101. try {
  102. $currency = new Zend_Currency('AWG');
  103. $this->assertTrue($currency instanceof Zend_Currency);
  104. } catch (Zend_Currency_Exception $e) {
  105. $this->assertContains('No region found within the locale', $e->getMessage());
  106. }
  107. try {
  108. $currency = new Zend_Currency('XYZ');
  109. $this->fail("unknown shortname should not have been recognised");
  110. } catch (Zend_Currency_Exception $e) {
  111. // success
  112. }
  113. }
  114. /**
  115. * tests the creation of Zend_Currency
  116. */
  117. public function testDualCreation()
  118. {
  119. $locale = new Zend_Locale('de_AT');
  120. $currency = new Zend_Currency('USD', 'de_AT');
  121. $this->assertTrue($currency instanceof Zend_Currency);
  122. $this->assertSame('$ 1.000,00', $currency->toCurrency(1000));
  123. $currency = new Zend_Currency('USD', $locale);
  124. $this->assertTrue($currency instanceof Zend_Currency);
  125. $this->assertSame('$ 1.000,00', $currency->toCurrency(1000));
  126. $currency = new Zend_Currency('de_AT', 'USD');
  127. $this->assertTrue($currency instanceof Zend_Currency);
  128. $this->assertSame('$ 1.000,00', $currency->toCurrency(1000));
  129. $currency = new Zend_Currency($locale, 'USD');
  130. $this->assertTrue($currency instanceof Zend_Currency);
  131. $this->assertSame('$ 1.000,00', $currency->toCurrency(1000));
  132. $currency = new Zend_Currency('EUR', 'de_AT');
  133. $this->assertTrue($currency instanceof Zend_Currency);
  134. $this->assertSame('€ 1.000,00', $currency->toCurrency(1000));
  135. try {
  136. $currency = new Zend_Currency('EUR', 'xx_YY');
  137. $this->fail("unknown locale should not have been recognised");
  138. } catch (Zend_Currency_Exception $e) {
  139. // success
  140. }
  141. }
  142. /**
  143. * tests the creation of Zend_Currency
  144. */
  145. public function testTripleCreation()
  146. {
  147. $locale = new Zend_Locale('de_AT');
  148. $currency = new Zend_Currency('USD', 'de_AT');
  149. $this->assertTrue($currency instanceof Zend_Currency);
  150. $this->assertSame('$ 1.000,00', $currency->toCurrency(1000));
  151. $currency = new Zend_Currency('USD', $locale);
  152. $this->assertTrue($currency instanceof Zend_Currency);
  153. $this->assertSame('$ 1.000,00', $currency->toCurrency(1000));
  154. try {
  155. $currency = new Zend_Currency('XXX', 'Latin', $locale);
  156. $this->fail("unknown shortname should not have been recognised");
  157. } catch (Zend_Currency_Exception $e) {
  158. // success
  159. }
  160. try {
  161. $currency = new Zend_Currency('USD', 'Xyzz', $locale);
  162. $this->fail("unknown script should not have been recognised");
  163. } catch (Zend_Currency_Exception $e) {
  164. // success
  165. }
  166. try {
  167. $currency = new Zend_Currency('USD', 'Latin', 'xx_YY');
  168. $this->fail("unknown locale should not have been recognised");
  169. } catch (Zend_Currency_Exception $e) {
  170. // success
  171. }
  172. $currency = new Zend_Currency('USD', 'de_AT');
  173. $this->assertTrue($currency instanceof Zend_Currency);
  174. $this->assertSame('$ 1.000,00', $currency->toCurrency(1000));
  175. $currency = new Zend_Currency('Euro', 'de_AT');
  176. $this->assertTrue($currency instanceof Zend_Currency);
  177. $this->assertSame('EUR 1.000,00', $currency->toCurrency(1000));
  178. $currency = new Zend_Currency('USD', $locale);
  179. $this->assertTrue($currency instanceof Zend_Currency);
  180. $this->assertSame('$ 1.000,00', $currency->toCurrency(1000));
  181. $currency = new Zend_Currency('de_AT', 'EUR');
  182. $this->assertTrue($currency instanceof Zend_Currency);
  183. $this->assertSame('€ 1.000,00', $currency->toCurrency(1000));
  184. $currency = new Zend_Currency($locale, 'USD');
  185. $this->assertTrue($currency instanceof Zend_Currency);
  186. $this->assertSame('$ 1.000,00', $currency->toCurrency(1000));
  187. $currency = new Zend_Currency('EUR', 'en_US');
  188. $this->assertTrue($currency instanceof Zend_Currency);
  189. $this->assertSame('€1,000.00', $currency->toCurrency(1000));
  190. $currency = new Zend_Currency('en_US', 'USD');
  191. $this->assertTrue($currency instanceof Zend_Currency);
  192. $this->assertSame('$1,000.00', $currency->toCurrency(1000));
  193. $currency = new Zend_Currency($locale, 'EUR');
  194. $this->assertTrue($currency instanceof Zend_Currency);
  195. $this->assertSame('€ 1.000,00', $currency->toCurrency(1000));
  196. }
  197. /**
  198. * tests failed creation of Zend_Currency
  199. */
  200. public function testFailedCreation()
  201. {
  202. $locale = new Zend_Locale('de_AT');
  203. try {
  204. $currency = new Zend_Currency('de_AT', 'en_US');
  205. $this->fail("exception expected");
  206. } catch (Zend_Currency_Exception $e) {
  207. // success
  208. }
  209. try {
  210. $currency = new Zend_Currency('USD', 'EUR');
  211. $this->fail("exception expected");
  212. } catch (Zend_Currency_Exception $e) {
  213. // success
  214. }
  215. try {
  216. $currency = new Zend_Currency('Arab', 'Latn');
  217. $this->fail("exception expected");
  218. } catch (Zend_Currency_Exception $e) {
  219. // success
  220. }
  221. try {
  222. $currency = new Zend_Currency('EUR');
  223. $currency->toCurrency('value');
  224. $this->fail("exception expected");
  225. } catch (Zend_Currency_Exception $e) {
  226. // success
  227. }
  228. $currency = new Zend_Currency('EUR', 'de_AT');
  229. $currency->setFormat(array('display' => 'SIGN'));
  230. $this->assertSame('SIGN 1.000,00', $currency->toCurrency(1000));
  231. try {
  232. $currency = new Zend_Currency('EUR');
  233. $currency->setFormat(array('format' => 'xy_ZY'));
  234. $this->fail("exception expected");
  235. } catch (Zend_Currency_Exception $e) {
  236. // success
  237. }
  238. }
  239. /*
  240. * testing toCurrency
  241. */
  242. public function testToCurrency()
  243. {
  244. $USD = new Zend_Currency('USD','en_US');
  245. $EGP = new Zend_Currency('EGP','ar_EG');
  246. $this->assertSame('$53,292.18', $USD->toCurrency(53292.18 ));
  247. $this->assertSame('$٥٣,٢٩٢.١٨', $USD->toCurrency(53292.18, array('script' => 'Arab' )));
  248. $this->assertSame('$ ٥٣.٢٩٢,١٨', $USD->toCurrency(53292.18, array('script' => 'Arab', 'format' => 'de_AT')));
  249. $this->assertSame('$ 53.292,18', $USD->toCurrency(53292.18, array('format' => 'de_AT')));
  250. $this->assertSame('ج.م.‏ 53٬292٫18', $EGP->toCurrency(53292.18 ));
  251. $this->assertSame('ج.م.‏ ٥٣٬٢٩٢٫١٨', $EGP->toCurrency(53292.18, array('script' => 'Arab' )));
  252. $this->assertSame('ج.م.‏ ٥٣.٢٩٢,١٨', $EGP->toCurrency(53292.18, array('script' =>'Arab', 'format' => 'de_AT')));
  253. $this->assertSame('ج.م.‏ 53.292,18', $EGP->toCurrency(53292.18, array('format' => 'de_AT')));
  254. $USD = new Zend_Currency('en_US');
  255. $this->assertSame('$53,292.18', $USD->toCurrency(53292.18));
  256. try {
  257. $this->assertSame('$ 53,292.18', $USD->toCurrency('nocontent'));
  258. $this->fail("No currency expected");
  259. } catch (Zend_Currency_Exception $e) {
  260. $this->assertContains("has to be numeric", $e->getMessage());
  261. }
  262. $INR = new Zend_Currency('INR', 'de_AT');
  263. $this->assertSame('₨ 1,20', $INR->toCurrency(1.2));
  264. $this->assertSame('₨ 1,00', $INR->toCurrency(1));
  265. $this->assertSame('₨ 0,00', $INR->toCurrency(0));
  266. $this->assertSame('-₨ 3,00', $INR->toCurrency(-3));
  267. }
  268. /**
  269. * testing setFormat
  270. *
  271. */
  272. public function testSetFormat()
  273. {
  274. $locale = new Zend_Locale('en_US');
  275. $USD = new Zend_Currency('USD','en_US');
  276. $USD->setFormat(array('script' => 'Arab'));
  277. $this->assertSame('$٥٣,٢٩٢.١٨', $USD->toCurrency(53292.18));
  278. $USD->setFormat(array('script' => 'Arab', 'format' => 'de_AT'));
  279. $this->assertSame('$ ٥٣.٢٩٢,١٨', $USD->toCurrency(53292.18));
  280. $USD->setFormat(array('script' => 'Latn', 'format' => 'de_AT'));
  281. $this->assertSame('$ 53.292,18', $USD->toCurrency(53292.18));
  282. $USD->setFormat(array('script' => 'Latn', 'format' => $locale));
  283. $this->assertSame('$53,292.18', $USD->toCurrency(53292.18));
  284. // allignment of currency signs
  285. $USD->setFormat(array('position' => Zend_Currency::RIGHT, 'format' => 'de_AT'));
  286. $this->assertSame('53.292,18 $', $USD->toCurrency(53292.18));
  287. $USD->setFormat(array('position' => Zend_Currency::RIGHT, 'format' => $locale));
  288. $this->assertSame('53,292.18$', $USD->toCurrency(53292.18));
  289. $USD->setFormat(array('position' => Zend_Currency::LEFT, 'format' => 'de_AT'));
  290. $this->assertSame('$ 53.292,18', $USD->toCurrency(53292.18));
  291. $USD->setFormat(array('position' => Zend_Currency::LEFT, 'format' => $locale));
  292. $this->assertSame('$53,292.18', $USD->toCurrency(53292.18));
  293. $USD->setFormat(array('position' => Zend_Currency::STANDARD, 'format' => 'de_AT'));
  294. $this->assertSame('$ 53.292,18', $USD->toCurrency(53292.18));
  295. $USD->setFormat(array('position' => Zend_Currency::STANDARD, 'format' => $locale));
  296. $this->assertSame('$53,292.18', $USD->toCurrency(53292.18));
  297. // enable/disable currency symbols & currency names
  298. $USD->setFormat(array('display' => Zend_Currency::NO_SYMBOL, 'format' => 'de_AT'));
  299. $this->assertSame('53.292,18', $USD->toCurrency(53292.18));
  300. $USD->setFormat(array('display' => Zend_Currency::NO_SYMBOL, 'format' => $locale));
  301. $this->assertSame('53,292.18', $USD->toCurrency(53292.18));
  302. $USD->setFormat(array('display' => Zend_Currency::USE_SHORTNAME, 'format' => 'de_AT'));
  303. $this->assertSame('USD 53.292,18', $USD->toCurrency(53292.18));
  304. $USD->setFormat(array('display' => Zend_Currency::USE_SHORTNAME, 'format' => $locale));
  305. $this->assertSame('USD53,292.18', $USD->toCurrency(53292.18));
  306. $USD->setFormat(array('display' => Zend_Currency::USE_NAME, 'format' => 'de_AT'));
  307. $this->assertSame('US Dollar 53.292,18', $USD->toCurrency(53292.18));
  308. $USD->setFormat(array('display' => Zend_Currency::USE_NAME, 'format' => $locale));
  309. $this->assertSame('US Dollar53,292.18', $USD->toCurrency(53292.18));
  310. $USD->setFormat(array('display' => Zend_Currency::USE_SYMBOL, 'format' => 'de_AT'));
  311. $this->assertSame('$ 53.292,18', $USD->toCurrency(53292.18));
  312. $USD->setFormat(array('display' => Zend_Currency::USE_SYMBOL, 'format' => $locale));
  313. $this->assertSame('$53,292.18', $USD->toCurrency(53292.18));
  314. try {
  315. $USD->setFormat(array('position' => 'unknown'));
  316. $this->fail("Exception expected");
  317. } catch (Zend_Currency_Exception $e) {
  318. $this->assertContains("Unknown position", $e->getMessage());
  319. }
  320. try {
  321. $USD->setFormat(array('format' => 'unknown'));
  322. $this->fail("Exception expected");
  323. } catch (Zend_Currency_Exception $e) {
  324. $this->assertContains("is not a known locale", $e->getMessage());
  325. }
  326. try {
  327. $USD->setFormat(array('display' => -14));
  328. $this->fail("Exception expected");
  329. } catch (Zend_Currency_Exception $e) {
  330. $this->assertContains("Unknown display", $e->getMessage());
  331. }
  332. try {
  333. $USD->setFormat(array('script' => 'unknown'));
  334. $this->fail("Exception expected");
  335. } catch (Zend_Currency_Exception $e) {
  336. $this->assertContains("Unknown script", $e->getMessage());
  337. }
  338. try {
  339. $USD->setFormat(array('unknown' => 'unknown'));
  340. $this->fail("Exception expected");
  341. } catch (Zend_Currency_Exception $e) {
  342. $this->assertContains("Unknown option", $e->getMessage());
  343. }
  344. $USD->setFormat(array('precision' => null));
  345. try {
  346. $USD->setFormat(array('precision' => -14));
  347. $this->fail("Exception expected");
  348. } catch (Zend_Currency_Exception $e) {
  349. $this->assertContains("precision has to be between", $e->getMessage());
  350. }
  351. }
  352. /**
  353. * test getSign
  354. */
  355. public function testGetSign()
  356. {
  357. $locale = new Zend_Locale('ar_EG');
  358. $currency = new Zend_Currency('ar_EG');
  359. $this->assertSame('ج.م.‏', $currency->getSymbol('EGP','ar_EG'));
  360. $this->assertSame('€', $currency->getSymbol('EUR','de_AT'));
  361. $this->assertSame('ج.م.‏', $currency->getSymbol('ar_EG' ));
  362. $this->assertSame('€', $currency->getSymbol('de_AT' ));
  363. $this->assertSame('ج.م.‏', $currency->getSymbol());
  364. try {
  365. $currency->getSymbol('EGP', 'de_XX');
  366. $this->fail("exception expected");
  367. } catch (Zend_Currency_Exception $e) {
  368. // success
  369. }
  370. }
  371. /**
  372. * test getName
  373. */
  374. public function testGetName()
  375. {
  376. $locale = new Zend_Locale('ar_EG');
  377. $currency = new Zend_Currency('ar_EG');
  378. $this->assertSame('جنيه مصرى', $currency->getName('EGP','ar_EG'));
  379. $this->assertSame('Estnische Krone', $currency->getName('EEK','de_AT'));
  380. $this->assertSame('جنيه مصرى', $currency->getName('EGP',$locale));
  381. $this->assertSame('جنيه مصرى', $currency->getName('ar_EG' ));
  382. $this->assertSame('Euro', $currency->getName('de_AT' ));
  383. $this->assertSame('جنيه مصرى', $currency->getName());
  384. try {
  385. $currency->getName('EGP', 'xy_XY');
  386. $this->fail("exception expected");
  387. } catch (Zend_Currency_Exception $e) {
  388. // success
  389. }
  390. }
  391. /**
  392. * test getShortName
  393. */
  394. public function testGetShortName()
  395. {
  396. $locale = new Zend_Locale('de_AT');
  397. $currency = new Zend_Currency('de_AT');
  398. $this->assertSame('EUR', $currency->getShortName('Euro', 'de_AT'));
  399. $this->assertSame('EUR', $currency->getShortName('Euro', $locale));
  400. $this->assertSame('USD', $currency->getShortName('US-Dollar','de_AT'));
  401. $this->assertSame('EUR', $currency->getShortName('de_AT' ));
  402. $this->assertSame('EUR', $currency->getShortName());
  403. try {
  404. $currency->getShortName('EUR', 'xy_ZT');
  405. $this->fail("exception expected");
  406. } catch (Zend_Currency_Exception $e) {
  407. // success
  408. }
  409. }
  410. /**
  411. * testing getRegionList
  412. */
  413. public function testGetRegionList()
  414. {
  415. // look if locale is detectable
  416. try {
  417. $locale = new Zend_Locale();
  418. } catch (Zend_Locale_Exception $e) {
  419. $this->markTestSkipped('Autodetection of locale failed');
  420. return;
  421. }
  422. try {
  423. $currency = new Zend_Currency('USD');
  424. $this->assertTrue(is_array($currency->getRegionList()));
  425. } catch (Zend_Currency_Exception $e) {
  426. $this->assertContains('No region found within the locale', $e->getMessage());
  427. }
  428. $currency = new Zend_Currency('USD', 'en_US');
  429. $currency->setFormat(array('currency' => null));
  430. try {
  431. $this->assertEquals('US', $currency->getRegionList());
  432. $this->fail("Exception expected");
  433. } catch (Zend_Currency_Exception $e) {
  434. $this->assertContains("No currency defined", $e->getMessage());
  435. }
  436. $currency = new Zend_Currency('USD', 'en_US');
  437. $this->assertEquals(array(0 => 'AS', 1 => 'EC', 2 => 'FM', 3 => 'GU', 4 => 'IO', 5 => 'MH', 6 => 'MP',
  438. 7 => 'PR', 8 => 'PW', 9 => "SV", 10 => 'TC', 11 => 'TL', 12 => 'UM', 13 => 'US', 14 => 'VG', 15 => 'VI'), $currency->getRegionList());
  439. }
  440. /**
  441. * testing getCurrencyList
  442. */
  443. public function testGetCurrencyList()
  444. {
  445. // look if locale is detectable
  446. try {
  447. $locale = new Zend_Locale();
  448. } catch (Zend_Locale_Exception $e) {
  449. $this->markTestSkipped('Autodetection of locale failed');
  450. return;
  451. }
  452. $currency = new Zend_Currency('ar_EG');
  453. $this->assertTrue(array_key_exists('EGP', $currency->getCurrencyList()));
  454. }
  455. /**
  456. * testing toString
  457. *
  458. */
  459. public function testToString()
  460. {
  461. $USD = new Zend_Currency('USD','en_US');
  462. $this->assertSame('US Dollar', $USD->toString());
  463. $this->assertSame('US Dollar', $USD->__toString());
  464. }
  465. /**
  466. * testing registry Locale
  467. * ZF-3676
  468. */
  469. public function testRegistryLocale()
  470. {
  471. $locale = new Zend_Locale('de_AT');
  472. require_once 'Zend/Registry.php';
  473. Zend_Registry::set('Zend_Locale', $locale);
  474. $currency = new Zend_Currency('EUR');
  475. $this->assertSame('de_AT', $currency->getLocale());
  476. }
  477. /**
  478. * Caching method tests
  479. */
  480. public function testCaching()
  481. {
  482. $cache = Zend_Currency::getCache();
  483. $this->assertTrue($cache instanceof Zend_Cache_Core);
  484. $this->assertTrue(Zend_Currency::hasCache());
  485. Zend_Currency::clearCache();
  486. $this->assertTrue(Zend_Currency::hasCache());
  487. Zend_Currency::removeCache();
  488. $this->assertFalse(Zend_Currency::hasCache());
  489. }
  490. /**
  491. * @see ZF-6560
  492. */
  493. public function testPrecisionForCurrency()
  494. {
  495. $currency = new Zend_Currency(null, 'de_DE');
  496. $this->assertEquals('75 €', $currency->toCurrency(74.95, array('precision' => 0)));
  497. $this->assertEquals('75,0 €', $currency->toCurrency(74.95, array('precision' => 1)));
  498. $this->assertEquals('74,95 €', $currency->toCurrency(74.95, array('precision' => 2)));
  499. $this->assertEquals('74,950 €', $currency->toCurrency(74.95, array('precision' => 3)));
  500. $this->assertEquals('74,9500 €', $currency->toCurrency(74.95, array('precision' => 4)));
  501. $this->assertEquals('74,95000 €', $currency->toCurrency(74.95, array('precision' => 5)));
  502. }
  503. /**
  504. * @see ZF-6561
  505. */
  506. public function testNegativeRendering()
  507. {
  508. $currency = new Zend_Currency(null, 'de_DE');
  509. $this->assertEquals('-74,9500 €', $currency->toCurrency(-74.95, array('currency' => 'EUR', 'precision' => 4)));
  510. $currency = new Zend_Currency(null, 'en_US');
  511. $this->assertEquals('-$74.9500', $currency->toCurrency(-74.95, array('currency' => 'USD', 'precision' => 4)));
  512. }
  513. /**
  514. * @see ZF-7359
  515. */
  516. public function testPHPsScientificBug()
  517. {
  518. $currency = new Zend_Currency("USD", "en_US");
  519. $this->assertEquals('$0.00', $currency->toCurrency(1.0E-4));
  520. $this->assertEquals('$0.00', $currency->toCurrency(1.0E-5));
  521. }
  522. }