wordpress-develop/tests/phpunit/tests/option/slashes.php
Sergey Biryukov ffc129395c Tests: Speed up slashed data tests by reusing shared fixtures.
Follow-up to [35249].

See #51344.

git-svn-id: https://develop.svn.wordpress.org/trunk@49003 602fd350-edb4-49c9-b593-d223f7449a82
2020-09-19 10:34:54 +00:00

58 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->assertSame( $this->slash_1, get_option( 'slash_test_1' ) );
$this->assertSame( $this->slash_2, get_option( 'slash_test_2' ) );
$this->assertSame( $this->slash_3, get_option( 'slash_test_3' ) );
$this->assertSame( $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->assertSame( $this->slash_1, get_option( 'slash_test_5' ) );
update_option( 'slash_test_5', $this->slash_2 );
$this->assertSame( $this->slash_2, get_option( 'slash_test_5' ) );
update_option( 'slash_test_5', $this->slash_3 );
$this->assertSame( $this->slash_3, get_option( 'slash_test_5' ) );
update_option( 'slash_test_5', $this->slash_4 );
$this->assertSame( $this->slash_4, get_option( 'slash_test_5' ) );
}
}