SanitizeTitleWithDashes.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <?php
  2. /**
  3. * @group formatting
  4. */
  5. class Tests_Formatting_SanitizeTitleWithDashes extends WP_UnitTestCase {
  6. function test_strips_html() {
  7. $input = 'Captain <strong>Awesome</strong>';
  8. $expected = 'captain-awesome';
  9. $this->assertSame( $expected, sanitize_title_with_dashes( $input ) );
  10. }
  11. function test_strips_unencoded_percent_signs() {
  12. $this->assertSame( 'fran%c3%a7ois', sanitize_title_with_dashes( 'fran%c3%a7%ois' ) );
  13. }
  14. function test_makes_title_lowercase() {
  15. $this->assertSame( 'abc', sanitize_title_with_dashes( 'ABC' ) );
  16. }
  17. function test_replaces_any_amount_of_whitespace_with_one_hyphen() {
  18. $this->assertSame( 'a-t', sanitize_title_with_dashes( 'a t' ) );
  19. $this->assertSame( 'a-t', sanitize_title_with_dashes( "a \n\n\nt" ) );
  20. }
  21. function test_replaces_any_number_of_hyphens_with_one_hyphen() {
  22. $this->assertSame( 'a-t-t', sanitize_title_with_dashes( 'a----t----t' ) );
  23. }
  24. function test_trims_trailing_hyphens() {
  25. $this->assertSame( 'a-t-t', sanitize_title_with_dashes( 'a----t----t----' ) );
  26. }
  27. function test_handles_non_entity_ampersands() {
  28. $this->assertSame( 'penn-teller-bull', sanitize_title_with_dashes( 'penn & teller bull' ) );
  29. }
  30. public function test_strips_nbsp_ndash_and_amp() {
  31. $this->assertSame( 'no-entities-here', sanitize_title_with_dashes( 'No &nbsp; Entities &ndash; Here &amp;' ) );
  32. }
  33. public function test_strips_encoded_ampersand() {
  34. $this->assertSame( 'one-two', sanitize_title_with_dashes( 'One &amp; Two', '', 'save' ) );
  35. }
  36. public function test_strips_url_encoded_ampersand() {
  37. $this->assertSame( 'one-two', sanitize_title_with_dashes( 'One &#123; Two;', '', 'save' ) );
  38. }
  39. public function test_strips_trademark_symbol() {
  40. $this->assertSame( 'one-two', sanitize_title_with_dashes( 'One Two™;', '', 'save' ) );
  41. }
  42. public function test_strips_unencoded_ampersand_followed_by_encoded_ampersand() {
  43. $this->assertSame( 'one-two', sanitize_title_with_dashes( 'One &&amp; Two;', '', 'save' ) );
  44. }
  45. public function test_strips_unencoded_ampersand_when_not_surrounded_by_spaces() {
  46. $this->assertSame( 'onetwo', sanitize_title_with_dashes( 'One&Two', '', 'save' ) );
  47. }
  48. function test_replaces_nbsp() {
  49. $this->assertSame( 'dont-break-the-space', sanitize_title_with_dashes( "don't break the space", '', 'save' ) );
  50. }
  51. /**
  52. * @ticket 31790
  53. */
  54. function test_replaces_nbsp_entities() {
  55. $this->assertSame( 'dont-break-the-space', sanitize_title_with_dashes( "don't&nbsp;break&#160;the&nbsp;space", '', 'save' ) );
  56. }
  57. function test_replaces_ndash_mdash() {
  58. $this->assertSame( 'do-the-dash', sanitize_title_with_dashes( 'Do – the Dash', '', 'save' ) );
  59. $this->assertSame( 'do-the-dash', sanitize_title_with_dashes( 'Do the — Dash', '', 'save' ) );
  60. }
  61. /**
  62. * @ticket 31790
  63. */
  64. function test_replaces_ndash_mdash_entities() {
  65. $this->assertSame( 'do-the-dash', sanitize_title_with_dashes( 'Do &ndash; the &#8211; Dash', '', 'save' ) );
  66. $this->assertSame( 'do-the-dash', sanitize_title_with_dashes( 'Do &mdash; the &#8212; Dash', '', 'save' ) );
  67. }
  68. function test_replaces_iexcel_iquest() {
  69. $this->assertSame( 'just-a-slug', sanitize_title_with_dashes( 'Just ¡a Slug', '', 'save' ) );
  70. $this->assertSame( 'just-a-slug', sanitize_title_with_dashes( 'Just a Slug¿', '', 'save' ) );
  71. }
  72. function test_replaces_angle_quotes() {
  73. $this->assertSame( 'just-a-slug', sanitize_title_with_dashes( '‹Just a Slug›', '', 'save' ) );
  74. $this->assertSame( 'just-a-slug', sanitize_title_with_dashes( '«Just a Slug»', '', 'save' ) );
  75. }
  76. function test_replaces_curly_quotes() {
  77. $this->assertSame( 'hey-its-curly-joe', sanitize_title_with_dashes( 'Hey its “Curly Joe”', '', 'save' ) );
  78. $this->assertSame( 'hey-its-curly-joe', sanitize_title_with_dashes( 'Hey its ‘Curly Joe’', '', 'save' ) );
  79. $this->assertSame( 'hey-its-curly-joe', sanitize_title_with_dashes( 'Hey its „Curly Joe“', '', 'save' ) );
  80. $this->assertSame( 'hey-its-curly-joe', sanitize_title_with_dashes( 'Hey its ‚Curly Joe‛', '', 'save' ) );
  81. $this->assertSame( 'hey-its-curly-joe', sanitize_title_with_dashes( 'Hey its „Curly Joe‟', '', 'save' ) );
  82. }
  83. /**
  84. * @ticket 49791
  85. */
  86. function test_replaces_bullet() {
  87. $this->assertSame( 'fancy-title-amazing', sanitize_title_with_dashes( 'Fancy Title • Amazing', '', 'save' ) );
  88. }
  89. function test_replaces_copy_reg_deg_trade() {
  90. $this->assertSame( 'just-a-slug', sanitize_title_with_dashes( 'Just © a Slug', '', 'save' ) );
  91. $this->assertSame( 'just-a-slug', sanitize_title_with_dashes( '® Just a Slug', '', 'save' ) );
  92. $this->assertSame( 'just-a-slug', sanitize_title_with_dashes( 'Just a ° Slug', '', 'save' ) );
  93. $this->assertSame( 'just-a-slug', sanitize_title_with_dashes( 'Just ™ a Slug', '', 'save' ) );
  94. }
  95. /**
  96. * @ticket 10792
  97. */
  98. function test_replaces_forward_slash() {
  99. $this->assertSame( 'songs-by-lennon-mccartney', sanitize_title_with_dashes( 'songs by Lennon/McCartney', '', 'save' ) );
  100. $this->assertSame( 'songs-by-lennon-mccartney', sanitize_title_with_dashes( 'songs by Lennon//McCartney', '', 'save' ) );
  101. $this->assertSame( 'songs-by-lennon-mccartney', sanitize_title_with_dashes( 'songs by Lennon///McCartney', '', 'save' ) );
  102. $this->assertSame( 'songs-by-lennon-mccartney', sanitize_title_with_dashes( 'songs by Lennon/-McCartney', '', 'save' ) );
  103. $this->assertSame( 'songs-by-lennon-mccartney', sanitize_title_with_dashes( '//songs by Lennon/McCartney', '', 'save' ) );
  104. }
  105. /**
  106. * @ticket 19820
  107. */
  108. function test_replaces_multiply_sign() {
  109. $this->assertSame( '6x7-is-42', sanitize_title_with_dashes( '6×7 is 42', '', 'save' ) );
  110. }
  111. /**
  112. * @ticket 20772
  113. */
  114. function test_replaces_standalone_diacritic() {
  115. $this->assertSame( 'aaaa', sanitize_title_with_dashes( 'āáǎà', '', 'save' ) );
  116. }
  117. /**
  118. * @ticket 22395
  119. */
  120. function test_replaces_acute_accents() {
  121. $this->assertSame( 'aaaa', sanitize_title_with_dashes( 'ááa´aˊ', '', 'save' ) );
  122. }
  123. }