wordpress-develop/tests/phpunit/tests/option/userSettings.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

64 lines
1.3 KiB
PHP

<?php
/**
* @group 123456
*/
class Tests_User_Settings extends WP_UnitTestCase {
protected $user_id;
public function set_up() {
parent::set_up();
$this->user_id = self::factory()->user->create(
array(
'role' => 'administrator',
)
);
wp_set_current_user( $this->user_id );
}
public function tear_down() {
unset( $GLOBALS['_updated_user_settings'] );
parent::tear_down();
}
public function test_set_user_setting() {
$foo = get_user_setting( 'foo' );
$this->assertEmpty( $foo );
$this->set_user_setting( 'foo', 'bar' );
$this->assertSame( 'bar', get_user_setting( 'foo' ) );
}
public function test_set_user_setting_dashes() {
$foo = get_user_setting( 'foo' );
$this->assertEmpty( $foo );
$this->set_user_setting( 'foo', 'foo-bar-baz' );
$this->assertSame( 'foo-bar-baz', get_user_setting( 'foo' ) );
}
public function test_set_user_setting_strip_asterisks() {
$foo = get_user_setting( 'foo' );
$this->assertEmpty( $foo );
$this->set_user_setting( 'foo', 'foo*bar*baz' );
$this->assertSame( 'foobarbaz', get_user_setting( 'foo' ) );
}
// set_user_setting() bails if `headers_sent()` is true.
private function set_user_setting( $name, $value ) {
$all_user_settings = get_all_user_settings();
$all_user_settings[ $name ] = $value;
return wp_set_all_user_settings( $all_user_settings );
}
}