forked from WordPress/wordpress-develop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathregistration.php
More file actions
165 lines (144 loc) · 3.96 KB
/
registration.php
File metadata and controls
165 lines (144 loc) · 3.96 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<?php
/**
* @group option
*/
class Tests_Option_Registration extends WP_UnitTestCase {
/**
* @covers ::register_setting
*/
public function test_register() {
register_setting( 'test_group', 'test_option' );
$registered = get_registered_settings();
$this->assertArrayHasKey( 'test_option', $registered );
$args = $registered['test_option'];
$this->assertSame( 'test_group', $args['group'] );
// Check defaults.
$this->assertSame( 'string', $args['type'] );
$this->assertFalse( $args['show_in_rest'] );
$this->assertSame( '', $args['description'] );
}
/**
* @covers ::register_setting
* @covers ::apply_filters
*/
public function test_register_with_callback() {
register_setting( 'test_group', 'test_option', array( $this, 'filter_registered_setting' ) );
$filtered = apply_filters( 'sanitize_option_test_option', 'smart', 'test_option', 'smart' );
$this->assertSame( 'S-M-R-T', $filtered );
}
/**
* @covers ::register_setting
* @covers WP_REST_Settings_Controller
* @covers ::apply_filters
*/
public function test_register_with_array() {
register_setting(
'test_group',
'test_option',
array(
'sanitize_callback' => array( $this, 'filter_registered_setting' ),
)
);
$filtered = apply_filters( 'sanitize_option_test_option', 'smart', 'test_option', 'smart' );
$this->assertSame( 'S-M-R-T', $filtered );
}
public function filter_registered_setting() {
return 'S-M-R-T';
}
/**
* @ticket 38176
*
* @covers ::register_setting
*/
public function test_register_with_default() {
register_setting(
'test_group',
'test_default',
array(
'default' => 'Got that Viper with them rally stripes',
)
);
$this->assertSame( 'Got that Viper with them rally stripes', get_option( 'test_default' ) );
}
/**
* @ticket 38176
*
* @covers ::register_setting
*/
public function test_register_with_default_override() {
register_setting(
'test_group',
'test_default',
array(
'default' => 'Got that Viper with them rally stripes',
)
);
// This set of tests/references (and a previous version) are in support of Viper007Bond.
// His Viper doesn't have rally stripes, but for the sake of the Big Tymers, we'll go with it.
$this->assertSame( 'We the #1 Stunnas', get_option( 'test_default', 'We the #1 Stunnas' ) );
}
/**
* @ticket 38930
*
* @covers ::register_setting
* @covers ::add_option
* @covers ::get_option
*/
public function test_add_option_with_no_options_cache() {
register_setting(
'test_group',
'test_default',
array(
'default' => 'My Default :)',
)
);
wp_cache_delete( 'notoptions', 'options' );
$this->assertTrue( add_option( 'test_default', 'hello' ) );
$this->assertSame( 'hello', get_option( 'test_default' ) );
}
/**
* @expectedDeprecated register_setting
*
* @covers ::register_setting
*/
public function test_register_deprecated_group_misc() {
register_setting( 'misc', 'test_option' );
}
/**
* @expectedDeprecated register_setting
*
* @covers ::register_setting
*/
public function test_register_deprecated_group_privacy() {
register_setting( 'privacy', 'test_option' );
}
/**
* @ticket 43207
*
* @covers ::register_setting
* @covers ::unregister_setting
*/
public function test_unregister_setting_removes_default() {
register_setting(
'test_group',
'test_default',
array(
'default' => 'Got that Viper with them rally stripes',
)
);
unregister_setting( 'test_group', 'test_default' );
$this->assertFalse( has_filter( 'default_option_test_default', 'filter_default_option' ) );
}
/**
* Ensures that unregister_setting() does not throw a notice or warning for unknown settings.
*
* @ticket 57674
*
* @covers ::unregister_setting
*/
public function test_unregister_invalid_setting_does_not_throw_notice_or_warning() {
$setting = uniqid();
unregister_setting( $setting, $setting );
$this->assertFalse( has_filter( 'default_option_' . $setting, 'filter_default_option' ) );
}
}