CurrencyTest.php 23 KB

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