CollatorTest.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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\Intl\Tests\Collator;
  11. use Symfony\Component\Intl\Collator\Collator;
  12. use Symfony\Component\Intl\Globals\IntlGlobals;
  13. class CollatorTest extends AbstractCollatorTest
  14. {
  15. /**
  16. * @expectedException \Symfony\Component\Intl\Exception\MethodArgumentValueNotImplementedException
  17. */
  18. public function testConstructorWithUnsupportedLocale()
  19. {
  20. new Collator('pt_BR');
  21. }
  22. /**
  23. * @expectedException \Symfony\Component\Intl\Exception\MethodNotImplementedException
  24. */
  25. public function testCompare()
  26. {
  27. $collator = $this->getCollator('en');
  28. $collator->compare('a', 'b');
  29. }
  30. /**
  31. * @expectedException \Symfony\Component\Intl\Exception\MethodNotImplementedException
  32. */
  33. public function testGetAttribute()
  34. {
  35. $collator = $this->getCollator('en');
  36. $collator->getAttribute(Collator::NUMERIC_COLLATION);
  37. }
  38. public function testGetErrorCode()
  39. {
  40. $collator = $this->getCollator('en');
  41. $this->assertEquals(IntlGlobals::U_ZERO_ERROR, $collator->getErrorCode());
  42. }
  43. public function testGetErrorMessage()
  44. {
  45. $collator = $this->getCollator('en');
  46. $this->assertEquals('U_ZERO_ERROR', $collator->getErrorMessage());
  47. }
  48. public function testGetLocale()
  49. {
  50. $collator = $this->getCollator('en');
  51. $this->assertEquals('en', $collator->getLocale());
  52. }
  53. public function testConstructWithoutLocale()
  54. {
  55. $collator = $this->getCollator(null);
  56. $this->assertInstanceOf('\Symfony\Component\Intl\Collator\Collator', $collator);
  57. }
  58. /**
  59. * @expectedException \Symfony\Component\Intl\Exception\MethodNotImplementedException
  60. */
  61. public function testGetSortKey()
  62. {
  63. $collator = $this->getCollator('en');
  64. $collator->getSortKey('Hello');
  65. }
  66. /**
  67. * @expectedException \Symfony\Component\Intl\Exception\MethodNotImplementedException
  68. */
  69. public function testGetStrength()
  70. {
  71. $collator = $this->getCollator('en');
  72. $collator->getStrength();
  73. }
  74. /**
  75. * @expectedException \Symfony\Component\Intl\Exception\MethodNotImplementedException
  76. */
  77. public function testSetAttribute()
  78. {
  79. $collator = $this->getCollator('en');
  80. $collator->setAttribute(Collator::NUMERIC_COLLATION, Collator::ON);
  81. }
  82. /**
  83. * @expectedException \Symfony\Component\Intl\Exception\MethodNotImplementedException
  84. */
  85. public function testSetStrength()
  86. {
  87. $collator = $this->getCollator('en');
  88. $collator->setStrength(Collator::PRIMARY);
  89. }
  90. public function testStaticCreate()
  91. {
  92. $collator = Collator::create('en');
  93. $this->assertInstanceOf('\Symfony\Component\Intl\Collator\Collator', $collator);
  94. }
  95. protected function getCollator($locale)
  96. {
  97. return new Collator($locale);
  98. }
  99. }