IcuRegionBundleTest.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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\IcuData;
  12. use Symfony\Component\Icu\IcuRegionBundle;
  13. /**
  14. * @author Bernhard Schussek <bschussek@gmail.com>
  15. */
  16. class IcuRegionBundleTest extends IcuTestCase
  17. {
  18. /**
  19. * @var string
  20. */
  21. private $resDir;
  22. /**
  23. * @var IcuRegionBundle
  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() . '/region';
  34. $this->reader = $this->getMock('Symfony\Component\Intl\ResourceBundle\Reader\StructuredBundleReaderInterface');
  35. $this->bundle = new IcuRegionBundle($this->reader);
  36. }
  37. public function testGetCountryNameOfUnknownCountry()
  38. {
  39. $this->reader->expects($this->never())
  40. ->method('readEntry');
  41. $this->assertNull($this->bundle->getCountryName('ZZ', 'en'));
  42. }
  43. public function testGetCountryNameOfNumericalRegion()
  44. {
  45. $this->reader->expects($this->never())
  46. ->method('readEntry');
  47. $this->assertNull($this->bundle->getCountryName(123, 'en'));
  48. }
  49. public function testGetCountryNameOfNumericalRegionWithLeadingZero()
  50. {
  51. $this->reader->expects($this->never())
  52. ->method('readEntry');
  53. $this->assertNull($this->bundle->getCountryName('010', 'en'));
  54. }
  55. public function testGetCountryNames()
  56. {
  57. $countries = array(
  58. 'DE' => 'Germany',
  59. 'AT' => 'Austria',
  60. 'ZZ' => 'Unknown Country',
  61. '010' => 'Europe',
  62. 110 => 'America',
  63. );
  64. $this->reader->expects($this->once())
  65. ->method('readEntry')
  66. ->with($this->resDir, 'en', array('Countries'))
  67. ->will($this->returnValue($countries));
  68. $sortedCountries = array(
  69. 'AT' => 'Austria',
  70. 'DE' => 'Germany',
  71. );
  72. $this->assertSame($sortedCountries, $this->bundle->getCountryNames('en'));
  73. }
  74. }