RemoveAccents.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. /**
  3. * @group formatting
  4. */
  5. class Tests_Formatting_RemoveAccents extends WP_UnitTestCase {
  6. public function test_remove_accents_simple() {
  7. $this->assertEquals( 'abcdefghijkl', remove_accents( 'abcdefghijkl' ) );
  8. }
  9. /**
  10. * @ticket 9591
  11. */
  12. public function test_remove_accents_latin1_supplement() {
  13. $input = 'ªºÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ';
  14. $output = 'aoAAAAAAAECEEEEIIIIDNOOOOOOUUUUYTHsaaaaaaaeceeeeiiiidnoooooouuuuythy';
  15. $this->assertEquals( $output, remove_accents( $input ), 'remove_accents replaces Latin-1 Supplement' );
  16. }
  17. public function test_remove_accents_latin_extended_a() {
  18. $input = 'ĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĬĭĮįİıIJijĴĵĶķĸĹĺĻļĽľĿŀŁłŃńŅņŇňʼnŊŋŌōŎŏŐőŒœŔŕŖŗŘřŚśŜŝŞşŠšŢţŤťŦŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŸŹźŻżŽžſ';
  19. $output = 'AaAaAaCcCcCcCcDdDdEeEeEeEeEeGgGgGgGgHhHhIiIiIiIiIiIJijJjKkkLlLlLlLlLlNnNnNnNnNOoOoOoOEoeRrRrRrSsSsSsSsTtTtTtUuUuUuUuUuUuWwYyYZzZzZzs';
  20. $this->assertEquals( $output, remove_accents( $input ), 'remove_accents replaces Latin Extended A' );
  21. }
  22. public function test_remove_accents_latin_extended_b() {
  23. $this->assertEquals( 'SsTt', remove_accents( 'ȘșȚț' ), 'remove_accents replaces Latin Extended B' );
  24. }
  25. public function test_remove_accents_euro_pound_signs() {
  26. $this->assertEquals( 'E', remove_accents( '€' ), 'remove_accents replaces euro sign' );
  27. $this->assertEquals( '', remove_accents( '£' ), 'remove_accents replaces pound sign' );
  28. }
  29. public function test_remove_accents_iso8859() {
  30. // File is Latin1 encoded
  31. $file = DIR_TESTDATA . '/formatting/remove_accents.01.input.txt';
  32. $input = file_get_contents( $file );
  33. $input = trim( $input );
  34. $output = "EfSZszYcYuAAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyyOEoeAEDHTHssaedhth";
  35. $this->assertEquals( $output, remove_accents( $input ), 'remove_accents from ISO-8859-1 text' );
  36. }
  37. /**
  38. * @ticket 17738
  39. */
  40. public function test_remove_accents_vowels_diacritic() {
  41. // Vowels with diacritic
  42. // unmarked
  43. $this->assertEquals( 'OoUu', remove_accents( 'ƠơƯư' ) );
  44. // grave accent
  45. $this->assertEquals( 'AaAaEeOoOoUuYy', remove_accents( 'ẦầẰằỀềỒồỜờỪừỲỳ' ) );
  46. // hook
  47. $this->assertEquals( 'AaAaAaEeEeIiOoOoOoUuUuYy', remove_accents( 'ẢảẨẩẲẳẺẻỂểỈỉỎỏỔổỞởỦủỬửỶỷ' ) );
  48. // tilde
  49. $this->assertEquals( 'AaAaEeEeOoOoUuYy', remove_accents( 'ẪẫẴẵẼẽỄễỖỗỠỡỮữỸỹ' ) );
  50. // acute accent
  51. $this->assertEquals( 'AaAaEeOoOoUu', remove_accents( 'ẤấẮắẾếỐốỚớỨứ' ) );
  52. // dot below
  53. $this->assertEquals( 'AaAaAaEeEeIiOoOoOoUuUuYy', remove_accents( 'ẠạẬậẶặẸẹỆệỊịỌọỘộỢợỤụỰựỴỵ' ) );
  54. }
  55. /**
  56. * @ticket 20772
  57. */
  58. public function test_remove_accents_hanyu_pinyin() {
  59. // Vowels with diacritic (Chinese, Hanyu Pinyin)
  60. // macron
  61. $this->assertEquals( 'aeiouuAEIOUU', remove_accents( 'āēīōūǖĀĒĪŌŪǕ' ) );
  62. // acute accent
  63. $this->assertEquals( 'aeiouuAEIOUU', remove_accents( 'áéíóúǘÁÉÍÓÚǗ' ) );
  64. // caron
  65. $this->assertEquals( 'aeiouuAEIOUU', remove_accents( 'ǎěǐǒǔǚǍĚǏǑǓǙ' ) );
  66. // grave accent
  67. $this->assertEquals( 'aeiouuAEIOUU', remove_accents( 'àèìòùǜÀÈÌÒÙǛ' ) );
  68. // unmarked
  69. $this->assertEquals( 'aaeiouuAEIOUU', remove_accents( 'aɑeiouüAEIOUÜ' ) );
  70. }
  71. function _remove_accents_germanic_umlauts_cb() {
  72. return 'de_DE';
  73. }
  74. /**
  75. * @ticket 3782
  76. */
  77. public function test_remove_accents_germanic_umlauts() {
  78. add_filter( 'locale', array( $this, '_remove_accents_germanic_umlauts_cb' ) );
  79. $this->assertEquals( 'AeOeUeaeoeuess', remove_accents( 'ÄÖÜäöüß' ) );
  80. remove_filter( 'locale', array( $this, '_remove_accents_germanic_umlauts_cb' ) );
  81. }
  82. public function _set_locale_to_danish() {
  83. return 'da_DK';
  84. }
  85. /**
  86. * @ticket 23907
  87. */
  88. public function test_remove_danish_accents() {
  89. add_filter( 'locale', array( $this, '_set_locale_to_danish' ) );
  90. $this->assertEquals( 'AeOeAaaeoeaa', remove_accents( 'ÆØÅæøå' ) );
  91. remove_filter( 'locale', array( $this, '_set_locale_to_danish' ) );
  92. }
  93. }