forked from WordPress/wordpress-develop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetBodyClass.php
More file actions
261 lines (207 loc) · 7.47 KB
/
getBodyClass.php
File metadata and controls
261 lines (207 loc) · 7.47 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
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
<?php
/**
* @group post
* @covers ::get_body_class
*/
class Tests_Post_GetBodyClass extends WP_UnitTestCase {
protected $post_id;
public function setUp() {
parent::setUp();
$this->post_id = self::factory()->post->create();
}
/**
* @ticket 30883
*/
public function test_with_utf8_category_slugs() {
$cat_id1 = self::factory()->category->create( array( 'name' => 'Первая рубрика' ) );
$cat_id2 = self::factory()->category->create( array( 'name' => 'Вторая рубрика' ) );
$cat_id3 = self::factory()->category->create( array( 'name' => '25кадр' ) );
wp_set_post_terms( $this->post_id, array( $cat_id1, $cat_id2, $cat_id3 ), 'category' );
$this->go_to( home_url( "?cat=$cat_id1" ) );
$this->assertContains( "category-$cat_id1", get_body_class() );
$this->go_to( home_url( "?cat=$cat_id2" ) );
$this->assertContains( "category-$cat_id2", get_body_class() );
$this->go_to( home_url( "?cat=$cat_id3" ) );
$this->assertContains( "category-$cat_id3", get_body_class() );
}
/**
* @ticket 30883
*/
public function test_with_utf8_tag_slugs() {
$tag_id1 = self::factory()->tag->create( array( 'name' => 'Первая метка' ) );
$tag_id2 = self::factory()->tag->create( array( 'name' => 'Вторая метка' ) );
$tag_id3 = self::factory()->tag->create( array( 'name' => '25кадр' ) );
wp_set_post_terms( $this->post_id, array( $tag_id1, $tag_id2, $tag_id3 ), 'post_tag' );
$tag1 = get_term( $tag_id1, 'post_tag' );
$tag2 = get_term( $tag_id2, 'post_tag' );
$tag3 = get_term( $tag_id3, 'post_tag' );
$this->go_to( home_url( "?tag={$tag1->slug}" ) );
$this->assertContains( "tag-$tag_id1", get_body_class() );
$this->go_to( home_url( "?tag={$tag2->slug}" ) );
$this->assertContains( "tag-$tag_id2", get_body_class() );
$this->go_to( home_url( "?tag={$tag3->slug}" ) );
$this->assertContains( "tag-$tag_id3", get_body_class() );
}
/**
* @ticket 30883
*/
public function test_with_utf8_term_slugs() {
register_taxonomy( 'wptests_tax', 'post' );
$term_id1 = self::factory()->term->create(
array(
'taxonomy' => 'wptests_tax',
'name' => 'Первая метка',
)
);
$term_id2 = self::factory()->term->create(
array(
'taxonomy' => 'wptests_tax',
'name' => 'Вторая метка',
)
);
$term_id3 = self::factory()->term->create(
array(
'taxonomy' => 'wptests_tax',
'name' => '25кадр',
)
);
wp_set_post_terms( $this->post_id, array( $term_id1, $term_id2, $term_id3 ), 'wptests_tax' );
$term1 = get_term( $term_id1, 'wptests_tax' );
$term2 = get_term( $term_id2, 'wptests_tax' );
$term3 = get_term( $term_id3, 'wptests_tax' );
$this->go_to( home_url( "?wptests_tax={$term1->slug}" ) );
$this->assertContains( "term-$term_id1", get_body_class() );
$this->go_to( home_url( "?wptests_tax={$term2->slug}" ) );
$this->assertContains( "term-$term_id2", get_body_class() );
$this->go_to( home_url( "?wptests_tax={$term3->slug}" ) );
$this->assertContains( "term-$term_id3", get_body_class() );
}
/**
* @ticket 35164
* @ticket 36510
*/
public function test_singular_body_classes() {
$post_id = self::factory()->post->create();
$this->go_to( get_permalink( $post_id ) );
$class = get_body_class();
$this->assertContains( 'single-post', $class );
$this->assertContains( "postid-{$post_id}", $class );
$this->assertContains( 'single-format-standard', $class );
}
public function test_page_template_body_classes_no_template() {
$post_id = self::factory()->post->create(
array(
'post_type' => 'page',
)
);
$this->go_to( get_permalink( $post_id ) );
$class = get_body_class();
$this->assertNotContains( 'page-template', $class );
$this->assertContains( 'page-template-default', $class );
}
public function test_page_template_body_classes() {
$post_id = self::factory()->post->create(
array(
'post_type' => 'page',
)
);
add_post_meta( $post_id, '_wp_page_template', 'templates/cpt.php' );
$this->go_to( get_permalink( $post_id ) );
$class = get_body_class();
$this->assertContains( 'page-template', $class );
$this->assertContains( 'page-template-templates', $class );
$this->assertContains( 'page-template-cpt', $class );
$this->assertContains( 'page-template-templatescpt-php', $class );
}
/**
* @ticket 18375
*/
public function test_page_template_body_classes_attachment() {
$post_id = self::factory()->post->create(
array(
'post_type' => 'attachment',
)
);
add_post_meta( $post_id, '_wp_page_template', 'templates/cpt.php' );
$this->go_to( get_permalink( $post_id ) );
$class = get_body_class();
$this->assertContains( 'attachment-template', $class );
$this->assertContains( 'attachment-template-templates', $class );
$this->assertContains( 'attachment-template-cpt', $class );
$this->assertContains( 'attachment-template-templatescpt-php', $class );
}
/**
* @ticket 18375
*/
public function test_page_template_body_classes_post() {
$post_id = self::factory()->post->create();
add_post_meta( $post_id, '_wp_page_template', 'templates/cpt.php' );
$this->go_to( get_permalink( $post_id ) );
$class = get_body_class();
$this->assertContains( 'post-template', $class );
$this->assertContains( 'post-template-templates', $class );
$this->assertContains( 'post-template-cpt', $class );
$this->assertContains( 'post-template-templatescpt-php', $class );
}
/**
* @ticket 38225
*/
public function test_attachment_body_classes() {
$post_id = self::factory()->post->create();
$attachment_id = self::factory()->attachment->create_object(
'image.jpg',
$post_id,
array(
'post_mime_type' => 'image/jpeg',
)
);
$this->go_to( get_permalink( $attachment_id ) );
$class = get_body_class();
$this->assertContains( 'attachment', $class );
$this->assertContains( "attachmentid-{$attachment_id}", $class );
$this->assertContains( 'attachment-jpeg', $class );
}
/**
* @ticket 38168
*/
public function test_custom_background_class_is_added_when_theme_supports_it() {
add_theme_support( 'custom-background', array( 'default-color', '#ffffff' ) );
set_theme_mod( 'background_color', '#000000' );
$class = get_body_class();
$theme_supports_background = current_theme_supports( 'custom-background' );
remove_theme_mod( 'background_color' );
remove_theme_support( 'custom-background' );
$this->assertTrue( $theme_supports_background );
$this->assertContains( 'custom-background', $class );
}
/**
* @ticket 38168
*/
public function test_custom_background_class_is_not_added_when_theme_support_is_missing() {
set_theme_mod( 'background_color', '#000000' );
$class = get_body_class();
$theme_supports_background = current_theme_supports( 'custom-background' );
remove_theme_mod( 'background_color' );
$this->assertFalse( $theme_supports_background );
$this->assertNotContains( 'custom-background', $class );
}
/**
* @ticket 44005
* @group privacy
*/
public function test_privacy_policy_body_class() {
$page_id = self::factory()->post->create(
array(
'post_type' => 'page',
'post_title' => 'Privacy Policy',
)
);
update_option( 'wp_page_for_privacy_policy', $page_id );
$this->go_to( get_permalink( $page_id ) );
$class = get_body_class();
$this->assertContains( 'privacy-policy', $class );
$this->assertContains( 'page-template-default', $class );
$this->assertContains( 'page', $class );
$this->assertContains( "page-id-{$page_id}", $class );
}
}