SanitizeTextField.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. /**
  3. * @group formatting
  4. */
  5. class Tests_Formatting_SanitizeTextField extends WP_UnitTestCase {
  6. // #11528
  7. function test_sanitize_text_field() {
  8. $inputs = array(
  9. 'оРангутанг', //Ensure UTF8 text is safe the Р is D0 A0 and A0 is the non-breaking space.
  10. 'САПР', //Ensure UTF8 text is safe the Р is D0 A0 and A0 is the non-breaking space.
  11. 'one is < two',
  12. 'tags <span>are</span> <em>not allowed</em> here',
  13. ' we should trim leading and trailing whitespace ',
  14. 'we also trim extra internal whitespace',
  15. 'tabs get removed too',
  16. 'newlines are not welcome
  17. here',
  18. 'We also %AB remove %ab octets',
  19. 'We don\'t need to wory about %A
  20. B removing %a
  21. b octets even when %a B they are obscured by whitespace',
  22. '%AB%BC%DE', //Just octets
  23. 'Invalid octects remain %II',
  24. 'Nested octects %%%ABABAB %A%A%ABBB',
  25. );
  26. $expected = array(
  27. 'оРангутанг',
  28. 'САПР',
  29. 'one is &lt; two',
  30. 'tags are not allowed here',
  31. 'we should trim leading and trailing whitespace',
  32. 'we also trim extra internal whitespace',
  33. 'tabs get removed too',
  34. 'newlines are not welcome here',
  35. 'We also remove octets',
  36. 'We don\'t need to wory about %A B removing %a b octets even when %a B they are obscured by whitespace',
  37. '', //Emtpy as we strip all the octets out
  38. 'Invalid octects remain %II',
  39. 'Nested octects',
  40. );
  41. foreach ($inputs as $key => $input) {
  42. $this->assertEquals($expected[$key], sanitize_text_field($input));
  43. }
  44. }
  45. }