SanitizeFileName.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. /**
  3. * @group formatting
  4. */
  5. class Tests_Formatting_SanitizeFileName extends WP_UnitTestCase {
  6. function test_munges_extensions() {
  7. # r17990
  8. $file_name = sanitize_file_name( 'test.phtml.txt' );
  9. $this->assertEquals( 'test.phtml_.txt', $file_name );
  10. }
  11. function test_removes_special_chars() {
  12. $special_chars = array("?", "[", "]", "/", "\\", "=", "<", ">", ":", ";", ",", "'", "\"", "&", "$", "#", "*", "(", ")", "|", "~", "`", "!", "{", "}", chr(0));
  13. $string = 'test';
  14. foreach ( $special_chars as $char )
  15. $string .= $char;
  16. $string .= 'test';
  17. $this->assertEquals( 'testtest', sanitize_file_name( $string ) );
  18. }
  19. function test_replaces_any_number_of_hyphens_with_one_hyphen() {
  20. $this->assertEquals("a-t-t", sanitize_file_name("a----t----t"));
  21. }
  22. function test_trims_trailing_hyphens() {
  23. $this->assertEquals("a-t-t", sanitize_file_name("a----t----t----"));
  24. }
  25. function test_replaces_any_amount_of_whitespace_with_one_hyphen() {
  26. $this->assertEquals("a-t", sanitize_file_name("a t"));
  27. $this->assertEquals("a-t", sanitize_file_name("a \n\n\nt"));
  28. }
  29. }