-
Notifications
You must be signed in to change notification settings - Fork 4
/
support.php
208 lines (179 loc) · 7.54 KB
/
support.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
208
<?php
/**
* @group themes
*/
class Tests_Theme_Support extends WP_UnitTestCase {
public function test_the_basics() {
add_theme_support( 'automatic-feed-links' );
$this->assertTrue( current_theme_supports( 'automatic-feed-links' ) );
remove_theme_support( 'automatic-feed-links' );
$this->assertFalse( current_theme_supports( 'automatic-feed-links' ) );
add_theme_support( 'automatic-feed-links' );
$this->assertTrue( current_theme_supports( 'automatic-feed-links' ) );
}
public function test_admin_bar() {
add_theme_support( 'admin-bar' );
$this->assertTrue( current_theme_supports( 'admin-bar' ) );
remove_theme_support( 'admin-bar' );
$this->assertFalse( current_theme_supports( 'admin-bar' ) );
add_theme_support( 'admin-bar' );
$this->assertTrue( current_theme_supports( 'admin-bar' ) );
add_theme_support( 'admin-bar', array( 'callback' => '__return_false' ) );
$this->assertTrue( current_theme_supports( 'admin-bar' ) );
$this->assertSame(
array( 0 => array( 'callback' => '__return_false' ) ),
get_theme_support( 'admin-bar' )
);
remove_theme_support( 'admin-bar' );
$this->assertFalse( current_theme_supports( 'admin-bar' ) );
$this->assertFalse( get_theme_support( 'admin-bar' ) );
}
public function test_post_thumbnails() {
add_theme_support( 'post-thumbnails' );
$this->assertTrue( current_theme_supports( 'post-thumbnails' ) );
remove_theme_support( 'post-thumbnails' );
$this->assertFalse( current_theme_supports( 'post-thumbnails' ) );
add_theme_support( 'post-thumbnails' );
$this->assertTrue( current_theme_supports( 'post-thumbnails' ) );
}
public function test_post_thumbnails_flat_array_of_post_types() {
remove_theme_support( 'post-thumbnails' );
add_theme_support( 'post-thumbnails', array( 'post', 'page' ) );
$this->assertTrue( current_theme_supports( 'post-thumbnails', 'post' ) );
$this->assertFalse( current_theme_supports( 'post-thumbnails', 'book' ) );
remove_theme_support( 'post-thumbnails' );
$this->assertFalse( current_theme_supports( 'post-thumbnails' ) );
}
/**
* @ticket 22080
*/
public function test_post_thumbnails_mixed_args() {
add_theme_support( 'post-thumbnails', array( 'post', 'page' ) );
add_theme_support( 'post-thumbnails', array( 'page' ) );
$this->assertTrue( current_theme_supports( 'post-thumbnails', 'post' ) );
$this->assertFalse( current_theme_supports( 'post-thumbnails', 'book' ) );
$this->assertSame(
array( 0 => array( 'post', 'page' ) ),
get_theme_support( 'post-thumbnails' )
);
add_theme_support( 'post-thumbnails' );
$this->assertTrue( current_theme_supports( 'post-thumbnails', 'any-type' ) );
// Reset post-thumbnails theme support.
remove_theme_support( 'post-thumbnails' );
$this->assertFalse( current_theme_supports( 'post-thumbnails' ) );
}
/**
* @ticket 24932
*/
public function test_supports_html5() {
remove_theme_support( 'html5' );
$this->assertFalse( current_theme_supports( 'html5' ) );
$this->assertFalse( current_theme_supports( 'html5', 'comment-form' ) );
$this->assertNotFalse( add_theme_support( 'html5' ) );
$this->assertTrue( current_theme_supports( 'html5' ) );
$this->assertTrue( current_theme_supports( 'html5', 'comment-form' ) );
$this->assertTrue( current_theme_supports( 'html5', 'comment-list' ) );
$this->assertTrue( current_theme_supports( 'html5', 'search-form' ) );
$this->assertFalse( current_theme_supports( 'html5', 'something-else' ) );
}
/**
* @ticket 24932
*
* @expectedIncorrectUsage add_theme_support( 'html5' )
*/
public function test_supports_html5_subset() {
remove_theme_support( 'html5' );
$this->assertFalse( current_theme_supports( 'html5' ) );
$this->assertFalse( current_theme_supports( 'html5', 'comment-form' ) );
$this->assertFalse( add_theme_support( 'html5', 'comment-form' ) );
$this->assertNotFalse( add_theme_support( 'html5', array( 'comment-form' ) ) );
$this->assertTrue( current_theme_supports( 'html5', 'comment-form' ) );
// This will return true, which might help a plugin author decide what markup to serve,
// but core should never check for it.
$this->assertTrue( current_theme_supports( 'html5' ) );
// It appends, rather than replaces.
$this->assertFalse( current_theme_supports( 'html5', 'comment-list' ) );
$this->assertNotFalse( add_theme_support( 'html5', array( 'comment-list' ) ) );
$this->assertTrue( current_theme_supports( 'html5', 'comment-form' ) );
$this->assertTrue( current_theme_supports( 'html5', 'comment-list' ) );
$this->assertFalse( current_theme_supports( 'html5', 'search-form' ) );
// Removal is all or nothing.
$this->assertTrue( remove_theme_support( 'html5' ) );
$this->assertFalse( current_theme_supports( 'html5', 'comment-list' ) );
$this->assertFalse( current_theme_supports( 'html5', 'comment-form' ) );
$this->assertFalse( current_theme_supports( 'html5', 'search-form' ) );
}
/**
* @ticket 24932
*
* @expectedIncorrectUsage add_theme_support( 'html5' )
*/
public function test_supports_html5_invalid() {
remove_theme_support( 'html5' );
$this->assertFalse( add_theme_support( 'html5', 'comment-form' ) );
$this->assertFalse( current_theme_supports( 'html5', 'comment-form' ) );
$this->assertFalse( current_theme_supports( 'html5' ) );
}
/**
* @ticket 51390
*
* @expectedIncorrectUsage add_theme_support( 'post-formats' )
*/
public function test_supports_post_formats_doing_it_wrong() {
// The second parameter should be an array.
$this->assertFalse( add_theme_support( 'post-formats' ) );
}
public function supports_foobar( $yesno, $args, $feature ) {
if ( $args[0] === $feature[0] ) {
return true;
}
return false;
}
public function test_plugin_hook() {
$this->assertFalse( current_theme_supports( 'foobar' ) );
add_theme_support( 'foobar' );
$this->assertTrue( current_theme_supports( 'foobar' ) );
add_filter( 'current_theme_supports-foobar', array( $this, 'supports_foobar' ), 10, 3 );
add_theme_support( 'foobar', 'bar' );
$this->assertFalse( current_theme_supports( 'foobar', 'foo' ) );
$this->assertTrue( current_theme_supports( 'foobar', 'bar' ) );
remove_theme_support( 'foobar' );
$this->assertFalse( current_theme_supports( 'foobar', 'bar' ) );
}
/**
* @ticket 26900
*/
public function test_supports_menus() {
// Start fresh.
foreach ( get_registered_nav_menus() as $location => $desc ) {
unregister_nav_menu( $location );
}
_remove_theme_support( 'menus' );
$this->assertFalse( current_theme_supports( 'menus' ) );
// Registering a nav menu automatically adds support.
register_nav_menu( 'primary', 'Primary Navigation' );
register_nav_menu( 'secondary', 'Secondary Navigation' );
$this->assertTrue( current_theme_supports( 'menus' ) );
// Support added internally, can't be removed.
remove_theme_support( 'menus' );
$this->assertTrue( current_theme_supports( 'menus' ) );
// Still supports because of secondary.
unregister_nav_menu( 'primary' );
$this->assertTrue( current_theme_supports( 'menus' ) );
// No longer support because we have no menus.
unregister_nav_menu( 'secondary' );
$this->assertEmpty( get_registered_nav_menus() );
$this->assertFalse( current_theme_supports( 'menus' ) );
}
/**
* @ticket 45125
*/
public function test_responsive_embeds() {
add_theme_support( 'responsive-embeds' );
$this->assertTrue( current_theme_supports( 'responsive-embeds' ) );
remove_theme_support( 'responsive-embeds' );
$this->assertFalse( current_theme_supports( 'responsive-embeds' ) );
add_theme_support( 'responsive-embeds' );
$this->assertTrue( current_theme_supports( 'responsive-embeds' ) );
}
}