forked from WordPress/wordpress-develop
/
includesTemplate.php
207 lines (159 loc) · 7.4 KB
/
includesTemplate.php
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
<?php
/**
* @group admin
*/
class Tests_Admin_includesTemplate extends WP_UnitTestCase {
function test_equal() {
$this->assertEquals( ' selected=\'selected\'', selected( 'foo', 'foo', false ) );
$this->assertEquals( ' checked=\'checked\'', checked( 'foo', 'foo', false ) );
$this->assertEquals( ' selected=\'selected\'', selected( '1', 1, false ) );
$this->assertEquals( ' checked=\'checked\'', checked( '1', 1, false ) );
$this->assertEquals( ' selected=\'selected\'', selected( '1', true, false ) );
$this->assertEquals( ' checked=\'checked\'', checked( '1', true, false ) );
$this->assertEquals( ' selected=\'selected\'', selected( 1, 1, false ) );
$this->assertEquals( ' checked=\'checked\'', checked( 1, 1, false ) );
$this->assertEquals( ' selected=\'selected\'', selected( 1, true, false ) );
$this->assertEquals( ' checked=\'checked\'', checked( 1, true, false ) );
$this->assertEquals( ' selected=\'selected\'', selected( true, true, false ) );
$this->assertEquals( ' checked=\'checked\'', checked( true, true, false ) );
$this->assertEquals( ' selected=\'selected\'', selected( '0', 0, false ) );
$this->assertEquals( ' checked=\'checked\'', checked( '0', 0, false ) );
$this->assertEquals( ' selected=\'selected\'', selected( 0, 0, false ) );
$this->assertEquals( ' checked=\'checked\'', checked( 0, 0, false ) );
$this->assertEquals( ' selected=\'selected\'', selected( '', false, false ) );
$this->assertEquals( ' checked=\'checked\'', checked( '', false, false ) );
$this->assertEquals( ' selected=\'selected\'', selected( false, false, false ) );
$this->assertEquals( ' checked=\'checked\'', checked( false, false, false ) );
}
function test_notequal() {
$this->assertEquals( '', selected( '0', '', false ) );
$this->assertEquals( '', checked( '0', '', false ) );
$this->assertEquals( '', selected( 0, '', false ) );
$this->assertEquals( '', checked( 0, '', false ) );
$this->assertEquals( '', selected( 0, false, false ) );
$this->assertEquals( '', checked( 0, false, false ) );
}
public function test_add_meta_box() {
global $wp_meta_boxes;
add_meta_box( 'testbox1', 'Test Metabox', '__return_false', 'post' );
$this->assertArrayHasKey( 'testbox1', $wp_meta_boxes['post']['advanced']['default'] );
}
public function test_remove_meta_box() {
global $wp_meta_boxes;
// Add a meta box to remove.
add_meta_box( 'testbox1', 'Test Metabox', '__return_false', $current_screen = 'post' );
// Confirm it's there.
$this->assertArrayHasKey( 'testbox1', $wp_meta_boxes[ $current_screen ]['advanced']['default'] );
// Remove the meta box.
remove_meta_box( 'testbox1', $current_screen, 'advanced' );
// Check that it was removed properly (the meta box should be set to false once that it has been removed).
$this->assertFalse( $wp_meta_boxes[ $current_screen ]['advanced']['default']['testbox1'] );
}
/**
* @ticket 15000
*/
public function test_add_meta_box_on_multiple_screens() {
global $wp_meta_boxes;
// Add a meta box to three different post types.
add_meta_box( 'testbox1', 'Test Metabox', '__return_false', array( 'post', 'comment', 'attachment' ) );
$this->assertArrayHasKey( 'testbox1', $wp_meta_boxes['post']['advanced']['default'] );
$this->assertArrayHasKey( 'testbox1', $wp_meta_boxes['comment']['advanced']['default'] );
$this->assertArrayHasKey( 'testbox1', $wp_meta_boxes['attachment']['advanced']['default'] );
}
/**
* @ticket 15000
*/
public function test_remove_meta_box_from_multiple_screens() {
global $wp_meta_boxes;
// Add a meta box to three different screens.
add_meta_box( 'testbox1', 'Test Metabox', '__return_false', array( 'post', 'comment', 'attachment' ) );
// Remove meta box from posts.
remove_meta_box( 'testbox1', 'post', 'advanced' );
// Check that we have removed the meta boxes only from posts.
$this->assertFalse( $wp_meta_boxes['post']['advanced']['default']['testbox1'] );
$this->assertArrayHasKey( 'testbox1', $wp_meta_boxes['comment']['advanced']['default'] );
$this->assertArrayHasKey( 'testbox1', $wp_meta_boxes['attachment']['advanced']['default'] );
// Remove the meta box from the other screens.
remove_meta_box( 'testbox1', array( 'comment', 'attachment' ), 'advanced' );
$this->assertFalse( $wp_meta_boxes['comment']['advanced']['default']['testbox1'] );
$this->assertFalse( $wp_meta_boxes['attachment']['advanced']['default']['testbox1'] );
}
/**
* @ticket 50019
*/
public function test_add_meta_box_with_previously_removed_box_and_sorted_priority() {
global $wp_meta_boxes;
// Add a meta box to remove.
add_meta_box( 'testbox1', 'Test Metabox', '__return_false', $current_screen = 'post' );
// Remove the meta box.
remove_meta_box( 'testbox1', $current_screen, 'advanced' );
// Attempt to re-add the meta box with the 'sorted' priority.
add_meta_box( 'testbox1', null, null, $current_screen, 'advanced', 'sorted' );
// Check that the meta box was not re-added.
$this->assertFalse( $wp_meta_boxes[ $current_screen ]['advanced']['default']['testbox1'] );
}
/**
* Test calling get_settings_errors() with variations on where it gets errors from.
*
* @ticket 42498
* @covers ::get_settings_errors()
* @global array $wp_settings_errors
*/
public function test_get_settings_errors_sources() {
global $wp_settings_errors;
$blogname_error = array(
'setting' => 'blogname',
'code' => 'blogname',
'message' => 'Capital P dangit!',
'type' => 'error',
);
$blogdescription_error = array(
'setting' => 'blogdescription',
'code' => 'blogdescription',
'message' => 'Too short',
'type' => 'error',
);
$wp_settings_errors = null;
$this->assertSame( array(), get_settings_errors( 'blogname' ) );
// Test getting errors from transient.
$_GET['settings-updated'] = '1';
set_transient( 'settings_errors', array( $blogname_error ) );
$wp_settings_errors = null;
$this->assertSame( array( $blogname_error ), get_settings_errors( 'blogname' ) );
// Test getting errors from transient and from global.
$_GET['settings-updated'] = '1';
set_transient( 'settings_errors', array( $blogname_error ) );
$wp_settings_errors = null;
add_settings_error( $blogdescription_error['setting'], $blogdescription_error['code'], $blogdescription_error['message'], $blogdescription_error['type'] );
$this->assertEqualSets( array( $blogname_error, $blogdescription_error ), get_settings_errors() );
$wp_settings_errors = null;
}
/**
* @ticket 44941
* @covers ::settings_errors()
* @global array $wp_settings_errors
* @dataProvider settings_errors_css_classes_provider
*/
public function test_settings_errors_css_classes( $type, $expected ) {
global $wp_settings_errors;
add_settings_error( 'foo', 'bar', 'Capital P dangit!', $type );
ob_start();
settings_errors();
$output = ob_get_clean();
$wp_settings_errors = null;
$expected = sprintf( 'notice %s settings-error is-dismissible', $expected );
$this->assertStringContainsString( $expected, $output );
$this->assertStringNotContainsString( 'notice-notice-', $output );
}
public function settings_errors_css_classes_provider() {
return array(
array( 'error', 'notice-error' ),
array( 'success', 'notice-success' ),
array( 'warning', 'notice-warning' ),
array( 'info', 'notice-info' ),
array( 'updated', 'notice-success' ),
array( 'notice-error', 'notice-error' ),
array( 'error my-own-css-class hello world', 'error my-own-css-class hello world' ),
);
}
}