wordpress-develop/tests/phpunit/tests/option/slashes.php
Tonya Mork 40ac5de838 Coding Standards: Add visibility to methods in tests/phpunit/tests/.
Adds a `public` visibility to test fixtures, tests, data providers, and callbacks methods.

Adds a `private` visibility to helper methods within test classes.

Renames callbacks and helpers that previously started with a `_` prefix. Why? For consistency and to leverage using the method visibility. Further naming standardizations is beyond the scope of this commit.

Props costdev, jrf, hellofromTonya.
Fixes #54177.

git-svn-id: https://develop.svn.wordpress.org/trunk@52010 602fd350-edb4-49c9-b593-d223f7449a82
2021-11-04 15:22:47 +00:00

58 lines
1.9 KiB
PHP

<?php
/**
* @group option
* @group slashes
* @ticket 21767
*/
class Tests_Option_Slashes extends WP_UnitTestCase {
public function set_up() {
parent::set_up();
// 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
*/
public 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
*/
public 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' ) );
}
}