wordpress-develop/tests/phpunit/tests/option/slashes.php
Gary Pendergast 8f95800d52 Code is Poetry.
WordPress' code just... wasn't.
This is now dealt with.

Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS.
Fixes #41057.



git-svn-id: https://develop.svn.wordpress.org/trunk@42343 602fd350-edb4-49c9-b593-d223f7449a82
2017-11-30 23:09:33 +00:00

56 lines
1.8 KiB
PHP

<?php
/**
* @group option
* @group slashes
* @ticket 21767
*/
class Tests_Option_Slashes extends WP_UnitTestCase {
function setUp() {
parent::setUp();
// it is important to test with both even and odd numbered slashes as
// kses does a strip-then-add slashes in some of its function calls
$this->slash_1 = 'String with 1 slash \\';
$this->slash_2 = 'String with 2 slashes \\\\';
$this->slash_3 = 'String with 3 slashes \\\\\\';
$this->slash_4 = 'String with 4 slashes \\\\\\\\';
$this->slash_5 = 'String with 5 slashes \\\\\\\\\\';
$this->slash_6 = 'String with 6 slashes \\\\\\\\\\\\';
$this->slash_7 = 'String with 7 slashes \\\\\\\\\\\\\\';
}
/**
* Tests the model function that expects un-slashed data
*/
function test_add_option() {
add_option( 'slash_test_1', $this->slash_1 );
add_option( 'slash_test_2', $this->slash_2 );
add_option( 'slash_test_3', $this->slash_3 );
add_option( 'slash_test_4', $this->slash_4 );
$this->assertEquals( $this->slash_1, get_option( 'slash_test_1' ) );
$this->assertEquals( $this->slash_2, get_option( 'slash_test_2' ) );
$this->assertEquals( $this->slash_3, get_option( 'slash_test_3' ) );
$this->assertEquals( $this->slash_4, get_option( 'slash_test_4' ) );
}
/**
* Tests the model function that expects un-slashed data
*/
function test_update_option() {
add_option( 'slash_test_5', 'foo' );
update_option( 'slash_test_5', $this->slash_1 );
$this->assertEquals( $this->slash_1, get_option( 'slash_test_5' ) );
update_option( 'slash_test_5', $this->slash_2 );
$this->assertEquals( $this->slash_2, get_option( 'slash_test_5' ) );
update_option( 'slash_test_5', $this->slash_3 );
$this->assertEquals( $this->slash_3, get_option( 'slash_test_5' ) );
update_option( 'slash_test_5', $this->slash_4 );
$this->assertEquals( $this->slash_4, get_option( 'slash_test_5' ) );
}
}