StubCollatorTest.php 4.2 KB

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