forked from WordPress/wordpress-develop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwpPostType.php
More file actions
178 lines (141 loc) · 4.61 KB
/
wpPostType.php
File metadata and controls
178 lines (141 loc) · 4.61 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
<?php
/**
* @group post
*/
class Tests_WP_Post_Type extends WP_UnitTestCase {
public function test_instances() {
global $wp_post_types;
foreach ( $wp_post_types as $post_type ) {
$this->assertInstanceOf( 'WP_Post_Type', $post_type );
}
}
public function test_add_supports_defaults() {
$post_type = 'cpt';
$post_type_object = new WP_Post_Type( $post_type );
$post_type_object->add_supports();
$post_type_supports = get_all_post_type_supports( $post_type );
$post_type_object->remove_supports();
$post_type_supports_after = get_all_post_type_supports( $post_type );
$this->assertEqualSets(
array(
'title' => true,
'editor' => true,
),
$post_type_supports
);
$this->assertEqualSets( array(), $post_type_supports_after );
}
public function test_add_supports_custom() {
$post_type = 'cpt';
$post_type_object = new WP_Post_Type(
$post_type,
array(
'supports' => array(
'editor',
'comments',
'revisions',
),
)
);
$post_type_object->add_supports();
$post_type_supports = get_all_post_type_supports( $post_type );
$post_type_object->remove_supports();
$post_type_supports_after = get_all_post_type_supports( $post_type );
$this->assertEqualSets(
array(
'editor' => true,
'comments' => true,
'revisions' => true,
),
$post_type_supports
);
$this->assertEqualSets( array(), $post_type_supports_after );
}
public function test_does_not_add_query_var_if_not_public() {
$this->set_permalink_structure( '/%postname%' );
/* @var WP $wp */
global $wp;
$post_type = 'cpt';
$post_type_object = new WP_Post_Type(
$post_type,
array(
'rewrite' => false,
'query_var' => 'foobar',
)
);
$post_type_object->add_rewrite_rules();
$this->assertFalse( in_array( 'foobar', $wp->public_query_vars ) );
}
public function test_adds_query_var_if_public() {
$this->set_permalink_structure( '/%postname%' );
/* @var WP $wp */
global $wp;
$post_type = 'cpt';
$post_type_object = new WP_Post_Type(
$post_type,
array(
'public' => true,
'rewrite' => false,
'query_var' => 'foobar',
)
);
$post_type_object->add_rewrite_rules();
$in_array = in_array( 'foobar', $wp->public_query_vars );
$post_type_object->remove_rewrite_rules();
$in_array_after = in_array( 'foobar', $wp->public_query_vars );
$this->assertTrue( $in_array );
$this->assertFalse( $in_array_after );
}
public function test_adds_rewrite_rules() {
$this->set_permalink_structure( '/%postname%' );
/* @var WP_Rewrite $wp_rewrite */
global $wp_rewrite;
$post_type = 'cpt';
$post_type_object = new WP_Post_Type(
$post_type,
array(
'public' => true,
'rewrite' => true,
)
);
$post_type_object->add_rewrite_rules();
$rewrite_tags = $wp_rewrite->rewritecode;
$post_type_object->remove_rewrite_rules();
$rewrite_tags_after = $wp_rewrite->rewritecode;
$this->assertNotFalse( array_search( "%$post_type%", $rewrite_tags ) );
$this->assertFalse( array_search( "%$post_type%", $rewrite_tags_after ) );
}
public function test_register_meta_boxes() {
$post_type = 'cpt';
$post_type_object = new WP_Post_Type( $post_type, array( 'register_meta_box_cb' => '__return_false' ) );
$post_type_object->register_meta_boxes();
$has_action = has_action( "add_meta_boxes_$post_type", '__return_false' );
$post_type_object->unregister_meta_boxes();
$has_action_after = has_action( "add_meta_boxes_$post_type", '__return_false' );
$this->assertSame( 10, $has_action );
$this->assertFalse( $has_action_after );
}
public function test_adds_future_post_hook() {
$post_type = 'cpt';
$post_type_object = new WP_Post_Type( $post_type );
$post_type_object->add_hooks();
$has_action = has_action( "future_$post_type", '_future_post_hook' );
$post_type_object->remove_hooks();
$has_action_after = has_action( "future_$post_type", '_future_post_hook' );
$this->assertSame( 5, $has_action );
$this->assertFalse( $has_action_after );
}
public function test_register_taxonomies() {
global $wp_post_types;
$post_type = 'cpt';
$post_type_object = new WP_Post_Type( $post_type, array( 'taxonomies' => array( 'post_tag' ) ) );
$wp_post_types[ $post_type ] = $post_type_object;
$post_type_object->register_taxonomies();
$taxonomies = get_object_taxonomies( $post_type );
$post_type_object->unregister_taxonomies();
$taxonomies_after = get_object_taxonomies( $post_type );
unset( $wp_post_types[ $post_type ] );
$this->assertEqualSets( array( 'post_tag' ), $taxonomies );
$this->assertEqualSets( array(), $taxonomies_after );
}
}