forked from WordPress/wordpress-develop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuserSettings.php
More file actions
79 lines (60 loc) · 1.71 KB
/
userSettings.php
File metadata and controls
79 lines (60 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
/**
* @group option
* @group user
*/
class Tests_Option_UserSettings 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();
}
/**
* @covers ::get_user_setting
* @covers ::get_all_user_settings
* @covers ::wp_set_all_user_settings
*/
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' ) );
}
/**
* @covers ::get_user_setting
* @covers ::get_all_user_settings
* @covers ::wp_set_all_user_settings
*/
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' ) );
}
/**
* @covers ::get_user_setting
* @covers ::get_all_user_settings
* @covers ::wp_set_all_user_settings
*/
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 );
}
}