Utf8UriEncode.php 981 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. /**
  3. * @group formatting
  4. */
  5. class Tests_Formatting_Utf8UriEncode extends WP_UnitTestCase {
  6. /**
  7. * Non-ASCII UTF-8 characters should be percent encoded. Spaces etc.
  8. * are dealt with elsewhere.
  9. *
  10. * @dataProvider data
  11. */
  12. function test_percent_encodes_non_reserved_characters( $utf8, $urlencoded ) {
  13. $this->assertEquals($urlencoded, utf8_uri_encode( $utf8 ) );
  14. }
  15. /**
  16. * @dataProvider data
  17. */
  18. function test_output_is_not_longer_than_optional_length_argument( $utf8, $unused_for_this_test ) {
  19. $max_length = 30;
  20. $this->assertTrue( strlen( utf8_uri_encode( $utf8, $max_length ) ) <= $max_length );
  21. }
  22. function data() {
  23. $utf8_urls = file( DIR_TESTDATA . '/formatting/utf-8/utf-8.txt' );
  24. $urlencoded = file( DIR_TESTDATA . '/formatting/utf-8/urlencoded.txt' );
  25. $data_provided = array();
  26. foreach ( $utf8_urls as $key => $value ) {
  27. $data_provided[] = array( trim( $value ), trim( $urlencoded[ $key ] ) );
  28. }
  29. return $data_provided;
  30. }
  31. }