IcuCurrencyBundleTest.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Icu\Tests;
  11. use Symfony\Component\Icu\IcuCurrencyBundle;
  12. use Symfony\Component\Icu\IcuData;
  13. /**
  14. * @author Bernhard Schussek <bschussek@gmail.com>
  15. */
  16. class IcuCurrencyBundleTest extends IcuTestCase
  17. {
  18. /**
  19. * @var string
  20. */
  21. private $resDir;
  22. /**
  23. * @var IcuCurrencyBundle
  24. */
  25. private $bundle;
  26. /**
  27. * @var \PHPUnit_Framework_MockObject_MockObject
  28. */
  29. private $reader;
  30. protected function setUp()
  31. {
  32. parent::setUp();
  33. $this->resDir = IcuData::getResourceDirectory() . '/curr';
  34. $this->reader = $this->getMock('Symfony\Component\Intl\ResourceBundle\Reader\StructuredBundleReaderInterface');
  35. $this->bundle = new IcuCurrencyBundle($this->reader);
  36. }
  37. public function testGetCurrencySymbol()
  38. {
  39. $this->reader->expects($this->once())
  40. ->method('readEntry')
  41. ->with($this->resDir, 'en', array('Currencies', 'EUR', 0))
  42. ->will($this->returnValue('€'));
  43. $this->assertSame('€', $this->bundle->getCurrencySymbol('EUR', 'en'));
  44. }
  45. public function testGetCurrencyName()
  46. {
  47. $this->reader->expects($this->once())
  48. ->method('readEntry')
  49. ->with($this->resDir, 'en', array('Currencies', 'EUR', 1))
  50. ->will($this->returnValue('Euro'));
  51. $this->assertSame('Euro', $this->bundle->getCurrencyName('EUR', 'en'));
  52. }
  53. public function testGetCurrencyNames()
  54. {
  55. $currencies = array(
  56. 'EUR' => array(1 => 'Euro'),
  57. 'USD' => array(1 => 'Dollar'),
  58. );
  59. $this->reader->expects($this->once())
  60. ->method('readEntry')
  61. ->with($this->resDir, 'en', array('Currencies'))
  62. ->will($this->returnValue($currencies));
  63. $sortedCurrencies = array(
  64. 'USD' => 'Dollar',
  65. 'EUR' => 'Euro',
  66. );
  67. $this->assertSame($sortedCurrencies, $this->bundle->getCurrencyNames('en'));
  68. }
  69. public function testGetFractionDigits()
  70. {
  71. $currencyData = array(
  72. 'EUR' => array(0 => 123),
  73. 'USD' => array(0 => 456),
  74. );
  75. $this->reader->expects($this->once())
  76. ->method('readEntry')
  77. ->with($this->resDir, 'supplementaldata', array('CurrencyMeta'))
  78. ->will($this->returnValue($currencyData));
  79. $this->assertSame(123, $this->bundle->getFractionDigits('EUR'));
  80. }
  81. public function testGetFractionDigitsFromDefaultBlock()
  82. {
  83. $currencyData = array(
  84. 'USD' => array(0 => 456),
  85. 'DEFAULT' => array(0 => 123),
  86. );
  87. $this->reader->expects($this->once())
  88. ->method('readEntry')
  89. ->with($this->resDir, 'supplementaldata', array('CurrencyMeta'))
  90. ->will($this->returnValue($currencyData));
  91. $this->assertSame(123, $this->bundle->getFractionDigits('EUR'));
  92. }
  93. public function testGetRoundingIncrement()
  94. {
  95. $currencyData = array(
  96. 'EUR' => array(1 => 123),
  97. 'USD' => array(1 => 456),
  98. );
  99. $this->reader->expects($this->once())
  100. ->method('readEntry')
  101. ->with($this->resDir, 'supplementaldata', array('CurrencyMeta'))
  102. ->will($this->returnValue($currencyData));
  103. $this->assertSame(123, $this->bundle->getRoundingIncrement('EUR'));
  104. }
  105. public function testGetRoundingIncrementFromDefaultBlock()
  106. {
  107. $currencyData = array(
  108. 'USD' => array(1 => 456),
  109. 'DEFAULT' => array(1 => 123),
  110. );
  111. $this->reader->expects($this->once())
  112. ->method('readEntry')
  113. ->with($this->resDir, 'supplementaldata', array('CurrencyMeta'))
  114. ->will($this->returnValue($currencyData));
  115. $this->assertSame(123, $this->bundle->getRoundingIncrement('EUR'));
  116. }
  117. }