SanitizeTitleWithDashes.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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->assertEquals($expected, sanitize_title($input));
  10. }
  11. function test_strips_unencoded_percent_signs() {
  12. $this->assertEquals("fran%c3%a7ois", sanitize_title_with_dashes("fran%c3%a7%ois"));
  13. }
  14. function test_makes_title_lowercase() {
  15. $this->assertEquals("abc", sanitize_title_with_dashes("ABC"));
  16. }
  17. function test_replaces_any_amount_of_whitespace_with_one_hyphen() {
  18. $this->assertEquals("a-t", sanitize_title_with_dashes("a t"));
  19. $this->assertEquals("a-t", sanitize_title_with_dashes("a \n\n\nt"));
  20. }
  21. function test_replaces_any_number_of_hyphens_with_one_hyphen() {
  22. $this->assertEquals("a-t-t", sanitize_title_with_dashes("a----t----t"));
  23. }
  24. function test_trims_trailing_hyphens() {
  25. $this->assertEquals("a-t-t", sanitize_title_with_dashes("a----t----t----"));
  26. }
  27. function test_handles_non_entity_ampersands() {
  28. $this->assertEquals("penn-teller-bull", sanitize_title_with_dashes("penn & teller bull"));
  29. }
  30. /**
  31. * @ticket 10823
  32. */
  33. function test_strips_entities() {
  34. $this->assertEquals("no-entities-here", sanitize_title_with_dashes("No &nbsp; Entities &ndash; Here &amp;"));
  35. $this->assertEquals("one-two", sanitize_title_with_dashes("One &amp; Two", '', 'save'));
  36. $this->assertEquals("one-two", sanitize_title_with_dashes("One &#123; Two;", '', 'save'));
  37. $this->assertEquals("one-two", sanitize_title_with_dashes("One & Two;", '', 'save'));
  38. $this->assertEquals("one-two", sanitize_title_with_dashes("One Two™;", '', 'save'));
  39. $this->assertEquals("one-two", sanitize_title_with_dashes("One &&amp; Two;", '', 'save'));
  40. $this->assertEquals("onetwo", sanitize_title_with_dashes("One&Two", '', 'save'));
  41. $this->assertEquals("onetwo-test", sanitize_title_with_dashes("One&Two Test;", '', 'save'));
  42. }
  43. function test_replaces_nbsp() {
  44. $this->assertEquals("dont-break-the-space", sanitize_title_with_dashes("don't break the space", '', 'save'));
  45. }
  46. function test_replaces_ndash_mdash() {
  47. $this->assertEquals("do-the-dash", sanitize_title_with_dashes("Do – the Dash", '', 'save'));
  48. $this->assertEquals("do-the-dash", sanitize_title_with_dashes("Do the — Dash", '', 'save'));
  49. }
  50. function test_replaces_iexcel_iquest() {
  51. $this->assertEquals("just-a-slug", sanitize_title_with_dashes("Just ¡a Slug", '', 'save'));
  52. $this->assertEquals("just-a-slug", sanitize_title_with_dashes("Just a Slug¿", '', 'save'));
  53. }
  54. function test_replaces_angle_quotes() {
  55. $this->assertEquals("just-a-slug", sanitize_title_with_dashes("‹Just a Slug›", '', 'save'));
  56. $this->assertEquals("just-a-slug", sanitize_title_with_dashes("«Just a Slug»", '', 'save'));
  57. }
  58. function test_replaces_curly_quotes() {
  59. $this->assertEquals("hey-its-curly-joe", sanitize_title_with_dashes("Hey its “Curly Joe”", '', 'save'));
  60. $this->assertEquals("hey-its-curly-joe", sanitize_title_with_dashes("Hey its ‘Curly Joe’", '', 'save'));
  61. $this->assertEquals("hey-its-curly-joe", sanitize_title_with_dashes("Hey its „Curly Joe“", '', 'save'));
  62. $this->assertEquals("hey-its-curly-joe", sanitize_title_with_dashes("Hey its ‚Curly Joe‛", '', 'save'));
  63. $this->assertEquals("hey-its-curly-joe", sanitize_title_with_dashes("Hey its „Curly Joe‟", '', 'save'));
  64. }
  65. function test_replaces_copy_reg_deg_trade() {
  66. $this->assertEquals("just-a-slug", sanitize_title_with_dashes("Just © a Slug", '', 'save'));
  67. $this->assertEquals("just-a-slug", sanitize_title_with_dashes("® Just a Slug", '', 'save'));
  68. $this->assertEquals("just-a-slug", sanitize_title_with_dashes("Just a ° Slug", '', 'save'));
  69. $this->assertEquals("just-a-slug", sanitize_title_with_dashes("Just ™ a Slug", '', 'save'));
  70. }
  71. /**
  72. * @ticket 19820
  73. */
  74. function test_replaces_multiply_sign() {
  75. $this->assertEquals("6x7-is-42", sanitize_title_with_dashes("6×7 is 42", '', 'save'));
  76. }
  77. /**
  78. * @ticket 20772
  79. */
  80. function test_replaces_standalone_diacritic() {
  81. $this->assertEquals("aaaa", sanitize_title_with_dashes("āáǎà", '', 'save'));
  82. }
  83. /**
  84. * @ticket 22395
  85. */
  86. function test_replaces_acute_accents() {
  87. $this->assertEquals("aaaa", sanitize_title_with_dashes("ááa´aˊ", '', 'save'));
  88. }
  89. }