LanguageUzTest.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. /**
  3. * PHPUnit tests for the Uzbek language.
  4. * The language can be represented using two scripts:
  5. * - Latin (uz-latn)
  6. * - Cyrillic (uz-cyrl)
  7. *
  8. * @author Robin Pepermans
  9. * @author Antoine Musso <hashar at free dot fr>
  10. * @copyright Copyright © 2012, Robin Pepermans
  11. * @copyright Copyright © 2011, Antoine Musso <hashar at free dot fr>
  12. * @file
  13. *
  14. * @todo methods in test class should be tidied:
  15. * - Should be split into separate test methods and data providers
  16. * - Tests for LanguageConverter and Language should probably be separate..
  17. */
  18. /**
  19. * @covers LanguageUz
  20. * @covers UzConverter
  21. */
  22. class LanguageUzTest extends LanguageClassesTestCase {
  23. /**
  24. * @author Nikola Smolenski
  25. * @covers LanguageConverter::convertTo
  26. */
  27. public function testConversionToCyrillic() {
  28. // A convertion of Latin to Cyrillic
  29. $this->assertEquals( 'абвгғ',
  30. $this->convertToCyrillic( 'abvggʻ' )
  31. );
  32. // Same as above, but assert that -{}-s must be removed and not converted
  33. $this->assertEquals( 'ljабnjвгўоdb',
  34. $this->convertToCyrillic( '-{lj}-ab-{nj}-vgoʻo-{db}-' )
  35. );
  36. // A simple convertion of Cyrillic to Cyrillic
  37. $this->assertEquals( 'абвг',
  38. $this->convertToCyrillic( 'абвг' )
  39. );
  40. // Same as above, but assert that -{}-s must be removed and not converted
  41. $this->assertEquals( 'ljабnjвгdaž',
  42. $this->convertToCyrillic( '-{lj}-аб-{nj}-вг-{da}-ž' )
  43. );
  44. }
  45. /**
  46. * @covers LanguageConverter::convertTo
  47. */
  48. public function testConversionToLatin() {
  49. // A simple convertion of Latin to Latin
  50. $this->assertEquals( 'abdef',
  51. $this->convertToLatin( 'abdef' )
  52. );
  53. // A convertion of Cyrillic to Latin
  54. $this->assertEquals( 'gʻabtsdOʻQyo',
  55. $this->convertToLatin( 'ғабцдЎҚё' )
  56. );
  57. }
  58. # #### HELPERS #####################################################
  59. /**
  60. * Wrapper to verify text stay the same after applying conversion
  61. * @param string $text Text to convert
  62. * @param string $variant Language variant 'uz-cyrl' or 'uz-latn'
  63. * @param string $msg Optional message
  64. */
  65. protected function assertUnConverted( $text, $variant, $msg = '' ) {
  66. $this->assertEquals(
  67. $text,
  68. $this->convertTo( $text, $variant ),
  69. $msg
  70. );
  71. }
  72. /**
  73. * Wrapper to verify a text is different once converted to a variant.
  74. * @param string $text Text to convert
  75. * @param string $variant Language variant 'uz-cyrl' or 'uz-latn'
  76. * @param string $msg Optional message
  77. */
  78. protected function assertConverted( $text, $variant, $msg = '' ) {
  79. $this->assertNotEquals(
  80. $text,
  81. $this->convertTo( $text, $variant ),
  82. $msg
  83. );
  84. }
  85. /**
  86. * Verifiy the given Cyrillic text is not converted when using
  87. * using the cyrillic variant and converted to Latin when using
  88. * the Latin variant.
  89. * @param string $text Text to convert
  90. * @param string $msg Optional message
  91. */
  92. protected function assertCyrillic( $text, $msg = '' ) {
  93. $this->assertUnConverted( $text, 'uz-cyrl', $msg );
  94. $this->assertConverted( $text, 'uz-latn', $msg );
  95. }
  96. /**
  97. * Verifiy the given Latin text is not converted when using
  98. * using the Latin variant and converted to Cyrillic when using
  99. * the Cyrillic variant.
  100. * @param string $text Text to convert
  101. * @param string $msg Optional message
  102. */
  103. protected function assertLatin( $text, $msg = '' ) {
  104. $this->assertUnConverted( $text, 'uz-latn', $msg );
  105. $this->assertConverted( $text, 'uz-cyrl', $msg );
  106. }
  107. /** Wrapper for converter::convertTo() method*/
  108. protected function convertTo( $text, $variant ) {
  109. return $this->getLang()->mConverter->convertTo( $text, $variant );
  110. }
  111. protected function convertToCyrillic( $text ) {
  112. return $this->convertTo( $text, 'uz-cyrl' );
  113. }
  114. protected function convertToLatin( $text ) {
  115. return $this->convertTo( $text, 'uz-latn' );
  116. }
  117. }