StubCollatorTest.php 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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\Tests\Component\Locale\Stub;
  11. require_once __DIR__.'/../TestCase.php';
  12. use Symfony\Component\Locale\Locale;
  13. use Symfony\Component\Locale\Stub\StubCollator;
  14. use Symfony\Component\Locale\Stub\StubIntl;
  15. use Symfony\Tests\Component\Locale\TestCase as LocaleTestCase;
  16. class StubCollatorTest extends LocaleTestCase
  17. {
  18. /**
  19. * @expectedException Symfony\Component\Locale\Exception\MethodArgumentValueNotImplementedException
  20. */
  21. public function testConstructorWithUnsupportedLocale()
  22. {
  23. $collator = new StubCollator('pt_BR');
  24. }
  25. /**
  26. * @dataProvider asortProvider
  27. */
  28. public function testAsortStub($array, $sortFlag, $expected)
  29. {
  30. $collator = new StubCollator('en');
  31. $collator->asort($array, $sortFlag);
  32. $this->assertSame($expected, $array);
  33. }
  34. /**
  35. * @dataProvider asortProvider
  36. */
  37. public function testAsortIntl($array, $sortFlag, $expected)
  38. {
  39. $this->skipIfIntlExtensionIsNotLoaded();
  40. $collator = new \Collator('en');
  41. $collator->asort($array, $sortFlag);
  42. $this->assertSame($expected, $array);
  43. }
  44. public function asortProvider()
  45. {
  46. return array(
  47. /* array, sortFlag, expected */
  48. array(
  49. array('a', 'b', 'c'),
  50. StubCollator::SORT_REGULAR,
  51. array('a', 'b', 'c'),
  52. ),
  53. array(
  54. array('c', 'b', 'a'),
  55. StubCollator::SORT_REGULAR,
  56. array(2 => 'a', 1 => 'b', 0 => 'c'),
  57. ),
  58. array(
  59. array('b', 'c', 'a'),
  60. StubCollator::SORT_REGULAR,
  61. array(2 => 'a', 0 => 'b', 1 => 'c'),
  62. ),
  63. );
  64. }
  65. /**
  66. * @expectedException Symfony\Component\Locale\Exception\MethodNotImplementedException
  67. */
  68. public function testCompare()
  69. {
  70. $collator = $this->createStubCollator();
  71. $collator->compare('a', 'b');
  72. }
  73. /**
  74. * @expectedException Symfony\Component\Locale\Exception\MethodNotImplementedException
  75. */
  76. public function testGetAttribute()
  77. {
  78. $collator = $this->createStubCollator();
  79. $collator->getAttribute(StubCollator::NUMERIC_COLLATION);
  80. }
  81. public function testGetErrorCode()
  82. {
  83. $collator = $this->createStubCollator();
  84. $this->assertEquals(StubIntl::U_ZERO_ERROR, $collator->getErrorCode());
  85. }
  86. public function testGetErrorMessage()
  87. {
  88. $collator = $this->createStubCollator();
  89. $this->assertEquals('U_ZERO_ERROR', $collator->getErrorMessage());
  90. }
  91. public function testGetLocale()
  92. {
  93. $collator = $this->createStubCollator();
  94. $this->assertEquals('en', $collator->getLocale());
  95. }
  96. /**
  97. * @expectedException Symfony\Component\Locale\Exception\MethodNotImplementedException
  98. */
  99. public function testGetSortKey()
  100. {
  101. $collator = $this->createStubCollator();
  102. $collator->getSortKey('Hello');
  103. }
  104. /**
  105. * @expectedException Symfony\Component\Locale\Exception\MethodNotImplementedException
  106. */
  107. public function testGetStrength()
  108. {
  109. $collator = $this->createStubCollator();
  110. $collator->getStrength();
  111. }
  112. /**
  113. * @expectedException Symfony\Component\Locale\Exception\MethodNotImplementedException
  114. */
  115. public function testSetAttribute()
  116. {
  117. $collator = $this->createStubCollator();
  118. $collator->setAttribute(StubCollator::NUMERIC_COLLATION, StubCollator::ON);
  119. }
  120. /**
  121. * @expectedException Symfony\Component\Locale\Exception\MethodNotImplementedException
  122. */
  123. public function testSetStrength()
  124. {
  125. $collator = $this->createStubCollator();
  126. $collator->setStrength(StubCollator::PRIMARY);
  127. }
  128. public function testStaticCreate()
  129. {
  130. $collator = StubCollator::create('en');
  131. $this->assertInstanceOf('Symfony\Component\Locale\Stub\StubCollator', $collator);
  132. }
  133. protected function createStubCollator()
  134. {
  135. return new StubCollator('en');
  136. }
  137. }