StripSlashesDeep.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. /**
  3. * @group formatting
  4. */
  5. class Tests_Formatting_StripSlashesDeep extends WP_UnitTestCase {
  6. /**
  7. * @ticket 18026
  8. */
  9. function test_preserves_original_datatype() {
  10. $this->assertEquals( true, stripslashes_deep( true ) );
  11. $this->assertEquals( false, stripslashes_deep( false ) );
  12. $this->assertEquals( 4, stripslashes_deep( 4 ) );
  13. $this->assertEquals( 'foo', stripslashes_deep( 'foo' ) );
  14. $arr = array( 'a' => true, 'b' => false, 'c' => 4, 'd' => 'foo' );
  15. $arr['e'] = $arr; // Add a sub-array
  16. $this->assertEquals( $arr, stripslashes_deep( $arr ) ); // Keyed array
  17. $this->assertEquals( array_values( $arr ), stripslashes_deep( array_values( $arr ) ) ); // Non-keyed
  18. $obj = new stdClass;
  19. foreach ( $arr as $k => $v )
  20. $obj->$k = $v;
  21. $this->assertEquals( $obj, stripslashes_deep( $obj ) );
  22. }
  23. function test_strips_slashes() {
  24. $old = "I can\'t see, isn\'t that it?";
  25. $new = "I can't see, isn't that it?";
  26. $this->assertEquals( $new, stripslashes_deep( $old ) );
  27. $this->assertEquals( $new, stripslashes_deep( "I can\\'t see, isn\\'t that it?" ) );
  28. $this->assertEquals( array( 'a' => $new ), stripslashes_deep( array( 'a' => $old ) ) ); // Keyed array
  29. $this->assertEquals( array( $new ), stripslashes_deep( array( $old ) ) ); // Non-keyed
  30. $obj_old = new stdClass;
  31. $obj_old->a = $old;
  32. $obj_new = new stdClass;
  33. $obj_new->a = $new;
  34. $this->assertEquals( $obj_new, stripslashes_deep( $obj_old ) );
  35. }
  36. function test_permits_escaped_slash() {
  37. $txt = "I can't see, isn\'t that it?";
  38. $this->assertEquals( $txt, stripslashes_deep( "I can\'t see, isn\\\'t that it?" ) );
  39. $this->assertEquals( $txt, stripslashes_deep( "I can\'t see, isn\\\\\'t that it?" ) );
  40. }
  41. }