slashes.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /**
  3. * @group option
  4. * @group slashes
  5. * @ticket 21767
  6. */
  7. class Tests_Option_Slashes extends WP_UnitTestCase {
  8. function setUp() {
  9. parent::setUp();
  10. // it is important to test with both even and odd numbered slashes as
  11. // kses does a strip-then-add slashes in some of it's function calls
  12. $this->slash_1 = 'String with 1 slash \\';
  13. $this->slash_2 = 'String with 2 slashes \\\\';
  14. $this->slash_3 = 'String with 3 slashes \\\\\\';
  15. $this->slash_4 = 'String with 4 slashes \\\\\\\\';
  16. $this->slash_5 = 'String with 5 slashes \\\\\\\\\\';
  17. $this->slash_6 = 'String with 6 slashes \\\\\\\\\\\\';
  18. $this->slash_7 = 'String with 7 slashes \\\\\\\\\\\\\\';
  19. }
  20. /**
  21. * Tests the model function that expects un-slashed data
  22. *
  23. */
  24. function test_add_option() {
  25. add_option( 'slash_test_1', $this->slash_1 );
  26. add_option( 'slash_test_2', $this->slash_2 );
  27. add_option( 'slash_test_3', $this->slash_3 );
  28. add_option( 'slash_test_4', $this->slash_4 );
  29. $this->assertEquals( $this->slash_1, get_option( 'slash_test_1' ) );
  30. $this->assertEquals( $this->slash_2, get_option( 'slash_test_2' ) );
  31. $this->assertEquals( $this->slash_3, get_option( 'slash_test_3' ) );
  32. $this->assertEquals( $this->slash_4, get_option( 'slash_test_4' ) );
  33. }
  34. /**
  35. * Tests the model function that expects un-slashed data
  36. *
  37. */
  38. function test_update_option() {
  39. add_option( 'slash_test_5', 'foo' );
  40. update_option( 'slash_test_5', $this->slash_1 );
  41. $this->assertEquals( $this->slash_1, get_option( 'slash_test_5' ) );
  42. update_option( 'slash_test_5', $this->slash_2 );
  43. $this->assertEquals( $this->slash_2, get_option( 'slash_test_5' ) );
  44. update_option( 'slash_test_5', $this->slash_3 );
  45. $this->assertEquals( $this->slash_3, get_option( 'slash_test_5' ) );
  46. update_option( 'slash_test_5', $this->slash_4 );
  47. $this->assertEquals( $this->slash_4, get_option( 'slash_test_5' ) );
  48. }
  49. }