Ticket #14761: 14761.2.diff
File 14761.2.diff, 28.8 KB (added by , 10 years ago) |
---|
-
src/wp-includes/capabilities.php
diff --git src/wp-includes/capabilities.php src/wp-includes/capabilities.php index 7c570c4..d8f52fe 100644
16 16 * 17 17 * @since 2.0.0 18 18 * 19 * @global array $post_type_meta_caps Used to get post type meta capabilities. 20 * 19 21 * @param string $cap Capability name. 20 22 * @param int $user_id User ID. 21 23 * @param int $object_id Optional. ID of the specific object to check against if `$cap` is a "meta" cap. … … function map_meta_cap( $cap, $user_id ) { 377 379 break; 378 380 default: 379 381 // Handle meta capabilities for custom post types. 380 $post_type_meta_caps = _post_type_meta_capabilities();382 global $post_type_meta_caps; 381 383 if ( isset( $post_type_meta_caps[ $cap ] ) ) { 382 384 $args = array_merge( array( $post_type_meta_caps[ $cap ], $user_id ), $args ); 383 385 return call_user_func_array( 'map_meta_cap', $args ); -
src/wp-includes/class-wp-rewrite.php
diff --git src/wp-includes/class-wp-rewrite.php src/wp-includes/class-wp-rewrite.php index 035bbc3..467f823 100644
class WP_Rewrite { 842 842 } 843 843 844 844 /** 845 * Adds or updates existing rewrite tags (e.g. %postname%). 846 * 847 * If the tag already exists, replace the existing pattern and query for 848 * that tag, otherwise add the new tag. 849 * 850 * @since 4.5.0 851 * @access public 852 * 853 * @see WP_Rewrite::$rewritecode 854 * @see WP_Rewrite::$rewritereplace 855 * @see WP_Rewrite::$queryreplace 856 * 857 * @param string $tag Name of the rewrite tag. 858 */ 859 public function remove_rewrite_tag( $tag ) { 860 $position = array_search( $tag, $this->rewritecode ); 861 if ( false !== $position && null !== $position ) { 862 unset( $this->rewritecode[ $position ] ); 863 unset( $this->rewritereplace[ $position ] ); 864 unset( $this->queryreplace[ $position ] ); 865 } 866 } 867 868 /** 845 869 * Generates rewrite rules from a permalink structure. 846 870 * 847 871 * The main WP_Rewrite function for building the rewrite rule list. The -
src/wp-includes/post.php
diff --git src/wp-includes/post.php src/wp-includes/post.php index 0fb1dfa..f906e01 100644
function register_post_type( $post_type, $args = array() ) { 1187 1187 } 1188 1188 1189 1189 /** 1190 * Unregister a post type. 1191 * 1192 * @since 4.5.0 1193 * 1194 * @global WP_Rewrite $wp_rewrite WordPress rewrite component. 1195 * @global WP $wp Current WordPress environment instance. 1196 * @global array $_wp_post_type_features Used to remove post type features. 1197 * @global array $post_type_meta_caps Used to remove meta capabilities. 1198 * @global array $wp_post_types List of post types. 1199 * 1200 * @param string $post_type Post type key. 1201 * @return bool True on success, false on failure. 1202 */ 1203 function unregister_post_type( $post_type ) { 1204 $post_type_args = get_post_type_object( $post_type ); 1205 1206 if ( ! $post_type_args ) { 1207 return false; 1208 } 1209 1210 // Do not allow unregistering internal post types. 1211 if ( $post_type_args->_builtin ) { 1212 return false; 1213 } 1214 1215 global $wp, $wp_rewrite, $_wp_post_type_features, $post_type_meta_caps, $wp_post_types; 1216 1217 // Post type does not exist. 1218 if ( ! isset( $wp_post_types[ $post_type ] ) ) { 1219 return false; 1220 } 1221 1222 // Remove query vars. 1223 if ( false !== $post_type_args->query_var ) { 1224 $wp->public_query_vars = array_diff( $wp->public_query_vars, array( $post_type_args->query_var ) ); 1225 } 1226 1227 // Remove any rewrite rules, permastructs, and rules. 1228 if ( false !== $post_type_args->rewrite ) { 1229 remove_rewrite_tag( "%$post_type%" ); 1230 foreach ( $wp_rewrite->extra_rules_top as $regex => $query ) { 1231 if ( false !== strpos( $query, "index.php?post_type=$post_type" ) ) { 1232 unset( $wp_rewrite->extra_rules_top[ $regex ] ); 1233 } 1234 } 1235 1236 unset( $wp_rewrite->extra_permastructs[ $post_type ] ); 1237 } 1238 1239 // Remove registered custom meta capabilities. 1240 foreach ( $post_type_args->cap as $cap ) { 1241 unset( $post_type_meta_caps[ $cap ] ); 1242 } 1243 1244 // Remove all post type support. 1245 unset( $_wp_post_type_features[ $post_type ] ); 1246 1247 // Remove meta boxes. 1248 remove_all_actions( 'add_meta_boxes_' . $post_type ); 1249 1250 // Remove the post type from all taxonomies. 1251 foreach ( get_object_taxonomies( $post_type ) as $taxonomy ) { 1252 unregister_taxonomy_for_object_type( $taxonomy, $post_type ); 1253 } 1254 1255 // Remove the future post hook actions. 1256 remove_all_actions( 'future_' . $post_type ); 1257 1258 unset( $wp_post_types[ $post_type ] ); 1259 1260 /** 1261 * Fires after a post type is unregistered. 1262 * 1263 * @since 4.5.0 1264 * 1265 * @param string $post_type Post type. 1266 */ 1267 do_action( 'unregistered_post_type', $post_type ); 1268 1269 return true; 1270 } 1271 1272 /** 1190 1273 * Build an object with all post type capabilities out of a post type object 1191 1274 * 1192 1275 * Post type capabilities use the 'capability_type' argument as a base, if the … … function get_post_type_capabilities( $args ) { 1293 1376 * @since 3.1.0 1294 1377 * @access private 1295 1378 * 1296 * @ staticvar array $meta_caps1379 * @global array $post_type_meta_caps Used to store meta capabilities. 1297 1380 * 1298 * @param array |void$capabilities Post type meta capabilities.1381 * @param array $capabilities Post type meta capabilities. 1299 1382 */ 1300 1383 function _post_type_meta_capabilities( $capabilities = null ) { 1301 static $meta_caps = array(); 1302 if ( null === $capabilities ) 1303 return $meta_caps; 1384 global $post_type_meta_caps; 1385 1304 1386 foreach ( $capabilities as $core => $custom ) { 1305 if ( in_array( $core, array( 'read_post', 'delete_post', 'edit_post' ) ) ) 1306 $meta_caps[ $custom ] = $core; 1387 if ( in_array( $core, array( 'read_post', 'delete_post', 'edit_post' ) ) ) { 1388 $post_type_meta_caps[ $custom ] = $core; 1389 } 1307 1390 } 1308 1391 } 1309 1392 -
src/wp-includes/rewrite.php
diff --git src/wp-includes/rewrite.php src/wp-includes/rewrite.php index 7f3b2ed..826ced2 100644
function add_rewrite_tag( $tag, $regex, $query = '' ) { 173 173 } 174 174 175 175 /** 176 * Removes an existing rewrite tag (like %postname%). 177 * 178 * @since 4.5.0 179 * 180 * @global WP_Rewrite $wp_rewrite WordPress rewrite component. 181 * @global WP $wp Current WordPress environment instance. 182 * 183 * @param string $tag Name of the rewrite tag. 184 */ 185 function remove_rewrite_tag( $tag ) { 186 global $wp_rewrite; 187 $wp_rewrite->remove_rewrite_tag( $tag ); 188 } 189 190 /** 176 191 * Add permalink structure. 177 192 * 178 193 * @since 3.0.0 -
tests/phpunit/includes/testcase.php
diff --git tests/phpunit/includes/testcase.php tests/phpunit/includes/testcase.php index a468deb..d9687d5 100644
class WP_UnitTestCase extends PHPUnit_Framework_TestCase { 157 157 */ 158 158 protected function reset_post_types() { 159 159 foreach ( get_post_types() as $pt ) { 160 _unregister_post_type( $pt );160 unregister_post_type( $pt ); 161 161 } 162 162 create_initial_post_types(); 163 163 } -
tests/phpunit/includes/utils.php
diff --git tests/phpunit/includes/utils.php tests/phpunit/includes/utils.php index 0a6dfc1..7adb234 100644
if ( !function_exists( 'str_getcsv' ) ) { 319 319 } 320 320 } 321 321 322 /**323 * Removes the post type and its taxonomy associations.324 */325 function _unregister_post_type( $cpt_name ) {326 unset( $GLOBALS['wp_post_types'][ $cpt_name ] );327 unset( $GLOBALS['_wp_post_type_features'][ $cpt_name ] );328 329 foreach ( $GLOBALS['wp_taxonomies'] as $taxonomy ) {330 if ( false !== $key = array_search( $cpt_name, $taxonomy->object_type ) ) {331 unset( $taxonomy->object_type[$key] );332 }333 }334 }335 336 322 function _unregister_taxonomy( $taxonomy_name ) { 337 323 unset( $GLOBALS['wp_taxonomies'][$taxonomy_name] ); 338 324 } … … class wpdb_exposed_methods_for_testing extends wpdb { 398 384 */ 399 385 function benchmark_pcre_backtracking( $pattern, $subject, $strategy ) { 400 386 $saved_config = ini_get( 'pcre.backtrack_limit' ); 401 387 402 388 // Attempt to prevent PHP crashes. Adjust these lower when needed. 403 389 if ( version_compare( phpversion(), '5.4.8', '>' ) ) { 404 390 $limit = 1000000; … … function benchmark_pcre_backtracking( $pattern, $subject, $strategy ) { 410 396 for( $i = 4; $i <= $limit; $i *= 2 ) { 411 397 412 398 ini_set( 'pcre.backtrack_limit', $i ); 413 399 414 400 switch( $strategy ) { 415 401 case 'split': 416 402 preg_split( $pattern, $subject ); -
tests/phpunit/tests/adminbar.php
diff --git tests/phpunit/tests/adminbar.php tests/phpunit/tests/adminbar.php index a2f61f2..c79a8fb 100644
class Tests_AdminBar extends WP_UnitTestCase { 48 48 $this->assertFalse( $nodes['new-content']->parent ); 49 49 $this->assertEquals( 'new-content', $nodes['add-new-content']->parent ); 50 50 51 _unregister_post_type( 'content' );51 unregister_post_type( 'content' ); 52 52 } 53 53 54 54 /** -
tests/phpunit/tests/comment/query.php
diff --git tests/phpunit/tests/comment/query.php tests/phpunit/tests/comment/query.php index 5d250ea..bf639cd 100644
class Tests_Comment_Query extends WP_UnitTestCase { 1469 1469 1470 1470 $this->assertEqualSets( $c2, $found ); 1471 1471 1472 _unregister_post_type( 'post-type-1' );1473 _unregister_post_type( 'post-type-2' );1472 unregister_post_type( 'post-type-1' ); 1473 unregister_post_type( 'post-type-2' ); 1474 1474 } 1475 1475 1476 1476 /** … … class Tests_Comment_Query extends WP_UnitTestCase { 1494 1494 1495 1495 $this->assertEqualSets( $c2, $found ); 1496 1496 1497 _unregister_post_type( 'post-type-1' );1498 _unregister_post_type( 'post-type-2' );1497 unregister_post_type( 'post-type-1' ); 1498 unregister_post_type( 'post-type-2' ); 1499 1499 } 1500 1500 1501 1501 /** … … class Tests_Comment_Query extends WP_UnitTestCase { 1521 1521 1522 1522 $this->assertEqualSets( array_merge( $c1, $c3 ), $found ); 1523 1523 1524 _unregister_post_type( 'post-type-1' );1525 _unregister_post_type( 'post-type-2' );1524 unregister_post_type( 'post-type-1' ); 1525 unregister_post_type( 'post-type-2' ); 1526 1526 } 1527 1527 1528 1528 public function test_post_name_single_value() { -
tests/phpunit/tests/customize/nav-menu-item-setting.php
diff --git tests/phpunit/tests/customize/nav-menu-item-setting.php tests/phpunit/tests/customize/nav-menu-item-setting.php index 39ed42e..ec6add1 100644
class Test_WP_Customize_Nav_Menu_Item_Setting extends WP_UnitTestCase { 742 742 $value_object = $setting->value_as_wp_post_nav_menu_item(); 743 743 $this->assertFalse( $value_object->_invalid ); 744 744 745 _unregister_post_type( 'poem' );745 unregister_post_type( 'poem' ); 746 746 $setting = new WP_Customize_Nav_Menu_Item_Setting( $this->wp_customize, $setting_id ); 747 747 $value = $setting->value(); 748 748 $this->assertTrue( $value['_invalid'] ); -
tests/phpunit/tests/post.php
diff --git tests/phpunit/tests/post.php tests/phpunit/tests/post.php index a1ec373..a9a90f3 100644
class Tests_Post extends WP_UnitTestCase { 816 816 ) ); 817 817 $count = wp_count_posts( $post_type, 'readable' ); 818 818 $this->assertEquals( 1, $count->publish ); 819 _unregister_post_type( $post_type );819 unregister_post_type( $post_type ); 820 820 $this->assertEquals( new stdClass, wp_count_posts( $post_type, 'readable' ) ); 821 821 } 822 822 … … class Tests_Post extends WP_UnitTestCase { 1083 1083 1084 1084 $this->assertEquals( 'open', $post->comment_status ); 1085 1085 $this->assertEquals( 'open', $post->ping_status ); 1086 _unregister_post_type( $post_type );1086 unregister_post_type( $post_type ); 1087 1087 } 1088 1088 1089 1089 /** … … class Tests_Post extends WP_UnitTestCase { 1103 1103 1104 1104 $this->assertEquals( 'closed', $post->comment_status ); 1105 1105 $this->assertEquals( 'closed', $post->ping_status ); 1106 _unregister_post_type( $post_type );1106 unregister_post_type( $post_type ); 1107 1107 } 1108 1108 1109 1109 /** -
tests/phpunit/tests/post/getPages.php
diff --git tests/phpunit/tests/post/getPages.php tests/phpunit/tests/post/getPages.php index 5391815..467dba2 100644
class Tests_Post_getPages extends WP_UnitTestCase { 356 356 $this->assertContains( 'current_page_item', $output ); 357 357 $this->assertEquals( 1, substr_count( $output, 'current_page_item' ) ); 358 358 359 _unregister_post_type( $type );359 unregister_post_type( $type ); 360 360 } 361 361 362 362 function test_exclude_tree() { -
tests/phpunit/tests/post/getPostsByAuthorSql.php
diff --git tests/phpunit/tests/post/getPostsByAuthorSql.php tests/phpunit/tests/post/getPostsByAuthorSql.php index 26de5b8..398e4c9 100644
class Tests_Post_GetPostsByAuthorSql extends WP_UnitTestCase { 28 28 $this->assertContains( "post_type = 'foo'", $maybe_string ); 29 29 $this->assertContains( "post_type = 'bar'", $maybe_string ); 30 30 31 _unregister_post_type( 'foo' );32 _unregister_post_type( 'bar' );31 unregister_post_type( 'foo' ); 32 unregister_post_type( 'bar' ); 33 33 } 34 34 35 35 public function test_full_true(){ … … class Tests_Post_GetPostsByAuthorSql extends WP_UnitTestCase { 143 143 $this->assertNotContains( "post_type = 'bar' AND ( post_status = 'publish' OR post_status = 'private' )", $maybe_string ); 144 144 $this->assertContains( "post_type = 'baz' AND ( post_status = 'publish' OR post_status = 'private' )", $maybe_string ); 145 145 146 _unregister_post_type( 'foo' );147 _unregister_post_type( 'bar' );148 _unregister_post_type( 'baz' );146 unregister_post_type( 'foo' ); 147 unregister_post_type( 'bar' ); 148 unregister_post_type( 'baz' ); 149 149 wp_set_current_user( $current_user ); 150 150 } 151 151 } -
tests/phpunit/tests/post/types.php
diff --git tests/phpunit/tests/post/types.php tests/phpunit/tests/post/types.php index 02d4590..0fbd532 100644
class Tests_Post_Types extends WP_UnitTestCase { 16 16 $this->assertFalse( is_post_type_hierarchical( 'foo' ) ); 17 17 $this->assertEquals( array(), get_object_taxonomies( 'foo' ) ); 18 18 19 _unregister_post_type( 'foo' );19 unregister_post_type( 'foo' ); 20 20 } 21 21 22 22 /** … … class Tests_Post_Types extends WP_UnitTestCase { 58 58 $this->assertFalse( is_object_in_taxonomy( 'bar', 'post_tag' ) ); 59 59 $this->assertFalse( is_object_in_taxonomy( 'bar', 'post_tag' ) ); 60 60 61 _unregister_post_type( 'bar' );61 unregister_post_type( 'bar' ); 62 62 } 63 63 64 64 function test_post_type_exists() { … … class Tests_Post_Types extends WP_UnitTestCase { 81 81 register_post_type( 'foo', array( 'supports' => array() ) ); 82 82 $this->assertTrue( post_type_supports( 'foo', 'editor' ) ); 83 83 $this->assertTrue( post_type_supports( 'foo', 'title' ) ); 84 _unregister_post_type( 'foo' );84 unregister_post_type( 'foo' ); 85 85 86 86 register_post_type( 'foo', array( 'supports' => false ) ); 87 87 $this->assertFalse( post_type_supports( 'foo', 'editor' ) ); 88 88 $this->assertFalse( post_type_supports( 'foo', 'title' ) ); 89 _unregister_post_type( 'foo' );89 unregister_post_type( 'foo' ); 90 90 } 91 91 92 92 /** … … class Tests_Post_Types extends WP_UnitTestCase { 99 99 register_post_type( 'foo', array( 'rewrite' => array( 'feeds' => false ) ) ); 100 100 $this->assertFalse( $wp_rewrite->extra_permastructs['foo']['feed'] ); 101 101 update_option( 'permalink_structure', $old_permastruct ); 102 _unregister_post_type( 'foo' );102 unregister_post_type( 'foo' ); 103 103 } 104 104 105 105 /** … … class Tests_Post_Types extends WP_UnitTestCase { 112 112 $this->assertObjectHasAttribute( 'featured_image', get_post_type_object( 'foo' )->labels ); 113 113 $this->assertObjectHasAttribute( 'set_featured_image', get_post_type_object( 'foo' )->labels ); 114 114 115 _unregister_post_type( 'foo' );115 unregister_post_type( 'foo' ); 116 116 remove_filter( 'post_type_labels_foo', array( $this, 'filter_post_type_labels' ) ); 117 117 } 118 118 … … class Tests_Post_Types extends WP_UnitTestCase { 138 138 $this->assertNull( get_post_type_object( array( 'foo' ) ) ); 139 139 $this->assertNull( get_post_type_object( new stdClass ) ); 140 140 141 _unregister_post_type( 'foo' );141 unregister_post_type( 'foo' ); 142 142 143 143 $this->assertFalse( post_type_exists( 'foo' ) ); 144 144 } … … class Tests_Post_Types extends WP_UnitTestCase { 157 157 158 158 $this->assertEquals( $before, $after ); 159 159 160 _unregister_post_type( 'foo' ); 160 unregister_post_type( 'foo' ); 161 } 162 163 /** 164 * @ticket 14761 165 */ 166 public function test_unregister_post_type() { 167 register_post_type( 'foo' ); 168 $this->assertTrue( unregister_post_type( 'foo' ) ); 169 } 170 171 /** 172 * @ticket 14761 173 */ 174 public function test_unregister_post_type_unknown_post_type() { 175 $this->assertFalse( unregister_post_type( 'foo' ) ); 176 } 177 178 /** 179 * @ticket 14761 180 */ 181 public function test_unregister_post_type_twice() { 182 register_post_type( 'foo' ); 183 $this->assertTrue( unregister_post_type( 'foo' ) ); 184 $this->assertFalse( unregister_post_type( 'foo' ) ); 185 } 186 187 /** 188 * @ticket 14761 189 */ 190 public function test_unregister_post_type_disallow_builtin_post_type() { 191 $this->assertFalse( unregister_post_type( 'post' ) ); 192 } 193 194 /** 195 * @ticket 14761 196 */ 197 public function test_unregister_post_type_removes_query_vars() { 198 global $wp; 199 200 register_post_type( 'foo', array( 201 'public' => true, 202 'query_var' => 'bar', 203 ) ); 204 205 $this->assertInternalType( 'int', array_search( 'bar', $wp->public_query_vars ) ); 206 $this->assertTrue( unregister_post_type( 'foo' ) ); 207 $this->assertFalse( array_search( 'bar', $wp->public_query_vars ) ); 208 } 209 210 /** 211 * @ticket 14761 212 */ 213 public function test_unregister_post_type_removes_rewrite_rules() { 214 $this->set_permalink_structure( '/%postname%' ); 215 216 global $wp_rewrite; 217 218 register_post_type( 'foo', array( 219 'public' => true, 220 'query_var' => 'bar', 221 ) ); 222 223 $count_before = count( $wp_rewrite->rewritereplace ); 224 225 $this->assertInternalType( 'int', array_search( '%foo%', $wp_rewrite->rewritecode ) ); 226 $this->assertInternalType( 'int', array_search( 'bar=', $wp_rewrite->queryreplace ) ); 227 $this->assertTrue( unregister_post_type( 'foo' ) ); 228 $this->assertFalse( array_search( '%foo%', $wp_rewrite->rewritecode ) ); 229 $this->assertFalse( array_search( 'bar=', $wp_rewrite->queryreplace ) ); 230 $this->assertSame( --$count_before, count( $wp_rewrite->rewritereplace ) ); // Array was reduced by one value. 231 } 232 233 /** 234 * @ticket 14761 235 */ 236 public function test_unregister_post_type_removes_custom_meta_capabilities() { 237 global $post_type_meta_caps; 238 239 register_post_type( 'foo', array( 240 'public' => true, 241 'capability_type' => 'bar', 242 ) ); 243 244 $post_type_args = get_post_type_object( 'foo' ); 245 $this->assertTrue( unregister_post_type( 'foo' ) ); 246 247 foreach ( $post_type_args->cap as $cap ) { 248 $this->assertFalse( isset( $post_type_meta_caps[ $cap ] ) ); 249 } 250 } 251 252 /** 253 * @ticket 14761 254 */ 255 public function test_unregister_post_type_removes_post_type_supports() { 256 global $_wp_post_type_features; 257 258 register_post_type( 'foo', array( 259 'public' => true, 260 'supports' => array( 'editor', 'author', 'title' ), 261 ) ); 262 263 $this->assertSame( 3, count( $_wp_post_type_features['foo'] ) ); 264 $this->assertTrue( unregister_post_type( 'foo' ) ); 265 $this->assertFalse( isset( $_wp_post_type_features['foo'] ) ); 266 } 267 268 /** 269 * @ticket 14761 270 */ 271 public function test_unregister_post_type_removes_post_type_from_taxonomies() { 272 global $wp_taxonomies; 273 274 register_post_type( 'foo', array( 275 'public' => true, 276 'taxonomies' => array( 'category', 'post_tag' ), 277 ) ); 278 279 $this->assertInternalType( 'int', array_search( 'foo', $wp_taxonomies['category']->object_type, true ) ); 280 $this->assertInternalType( 'int', array_search( 'foo', $wp_taxonomies['post_tag']->object_type, true ) ); 281 $this->assertTrue( unregister_post_type( 'foo' ) ); 282 $this->assertFalse( array_search( 'foo', $wp_taxonomies['category']->object_type, true ) ); 283 $this->assertFalse( array_search( 'foo', $wp_taxonomies['post_tag']->object_type, true ) ); 284 } 285 286 /** 287 * @ticket 14761 288 */ 289 public function test_unregister_post_type_removes_the_future_post_hooks() { 290 global $wp_filter; 291 292 register_post_type( 'foo', array( 293 'public' => true, 294 ) ); 295 296 add_action( 'future_foo', 'var_dump' ); 297 298 $this->assertSame( 2, count( $wp_filter['future_foo'] ) ); 299 $this->assertTrue( unregister_post_type( 'foo' ) ); 300 $this->assertSame( array(), $wp_filter['future_foo'] ); 301 } 302 303 /** 304 * @ticket 14761 305 */ 306 public function test_unregister_post_type_removes_meta_boxes() { 307 global $wp_filter; 308 309 register_post_type( 'foo', array( 310 'public' => true, 311 ) ); 312 313 add_action( 'add_meta_boxes_foo', 'var_dump' ); 314 315 $this->assertSame( 1, count( $wp_filter['add_meta_boxes_foo'] ) ); 316 $this->assertTrue( unregister_post_type( 'foo' ) ); 317 $this->assertSame( array(), $wp_filter['add_meta_boxes_foo'] ); 318 } 319 320 /** 321 * @ticket 14761 322 */ 323 public function test_unregister_post_type_removes_post_type_from_global() { 324 global $wp_post_types; 325 326 register_post_type( 'foo', array( 327 'public' => true, 328 ) ); 329 330 $this->assertInternalType( 'object', $wp_post_types['foo'] ); 331 $this->assertInternalType( 'object', get_post_type_object( 'foo' ) ); 332 333 $this->assertTrue( unregister_post_type( 'foo' ) ); 334 335 $this->assertFalse( isset( $wp_post_types['foo'] ) ); 336 $this->assertNull( get_post_type_object( 'foo' ) ); 161 337 } 162 338 } -
tests/phpunit/tests/post/wpUniquePostSlug.php
diff --git tests/phpunit/tests/post/wpUniquePostSlug.php tests/phpunit/tests/post/wpUniquePostSlug.php index 354997e..46caccc 100644
class Tests_Post_WpUniquePostSlug extends WP_UnitTestCase { 61 61 $this->assertEquals( 'some-other-slug', wp_unique_post_slug( 'some-other-slug', $one, 'publish', 'post-type-1', 0 ) ); 62 62 $this->assertEquals( 'some-other-slug', wp_unique_post_slug( 'some-other-slug', $one, 'publish', 'post-type-2', 0 ) ); 63 63 64 _unregister_post_type( 'post-type-1' );65 _unregister_post_type( 'post-type-2' );64 unregister_post_type( 'post-type-1' ); 65 unregister_post_type( 'post-type-2' ); 66 66 } 67 67 68 68 /** … … class Tests_Post_WpUniquePostSlug extends WP_UnitTestCase { 85 85 86 86 $this->assertEquals( 'some-slug-3', wp_unique_post_slug( 'some-slug', 0, 'publish', 'post-type-1', 0 ) ); 87 87 88 _unregister_post_type( 'post-type-1' );88 unregister_post_type( 'post-type-1' ); 89 89 } 90 90 91 91 /** … … class Tests_Post_WpUniquePostSlug extends WP_UnitTestCase { 123 123 // 'image' can be a child of image-2 124 124 $this->assertEquals( 'image', wp_unique_post_slug( 'image', 0, 'publish', 'post-type-1', $two ) ); 125 125 126 _unregister_post_type( 'post-type-1' );126 unregister_post_type( 'post-type-1' ); 127 127 } 128 128 129 129 /** -
tests/phpunit/tests/query/search.php
diff --git tests/phpunit/tests/query/search.php tests/phpunit/tests/query/search.php index caf862c..5deb7f2 100644
class Tests_Query_Search extends WP_UnitTestCase { 18 18 } 19 19 20 20 function tearDown() { 21 _unregister_post_type( $this->post_type );21 unregister_post_type( $this->post_type ); 22 22 unset( $this->q ); 23 23 24 24 parent::tearDown(); -
tests/phpunit/tests/rewrite.php
diff --git tests/phpunit/tests/rewrite.php tests/phpunit/tests/rewrite.php index 1f7426e..15956e5 100644
class Tests_Rewrite extends WP_UnitTestCase { 131 131 $id = self::factory()->post->create( array( 'post_type' => $post_type ) ); 132 132 $this->assertEquals( $id, url_to_postid( get_permalink( $id ) ) ); 133 133 134 _unregister_post_type( $post_type );134 unregister_post_type( $post_type ); 135 135 } 136 136 137 137 function test_url_to_postid_hierarchical() { … … class Tests_Rewrite extends WP_UnitTestCase { 236 236 237 237 $this->go_to( $url ); 238 238 239 _unregister_post_type( 'foo' );239 unregister_post_type( 'foo' ); 240 240 241 241 $this->assertEquals( array(), $GLOBALS['wp']->query_vars ); 242 242 } -
tests/phpunit/tests/taxonomy.php
diff --git tests/phpunit/tests/taxonomy.php tests/phpunit/tests/taxonomy.php index 2063bbe..ecb35fc 100644
class Tests_Taxonomy extends WP_UnitTestCase { 235 235 $this->assertFalse( unregister_taxonomy_for_object_type( $tax, 'user' ) ); 236 236 237 237 unset($GLOBALS['wp_taxonomies'][$tax]); 238 _unregister_post_type( $post_type );238 unregister_post_type( $post_type ); 239 239 240 240 } 241 241 … … class Tests_Taxonomy extends WP_UnitTestCase { 408 408 ) ); 409 409 410 410 $this->assertEqualSets( array( $p2, $p1 ), get_ancestors( $p3, 'wptests_pt' ) ); 411 _unregister_post_type( 'wptests_pt' );411 unregister_post_type( 'wptests_pt' ); 412 412 } 413 413 414 414 /** … … class Tests_Taxonomy extends WP_UnitTestCase { 440 440 $this->assertEqualSets( array( $p1 ), get_ancestors( $p2, 'wptests_conflict', 'post_type' ) ); 441 441 $this->assertEqualSets( array( $t1 ), get_ancestors( $t2, 'wptests_conflict', 'taxonomy' ) ); 442 442 $this->assertEqualSets( array( $t1 ), get_ancestors( $t2, 'wptests_conflict' ) ); 443 _unregister_post_type( 'wptests_pt' );443 unregister_post_type( 'wptests_pt' ); 444 444 } 445 445 446 446 /** -
tests/phpunit/tests/user/author.php
diff --git tests/phpunit/tests/user/author.php tests/phpunit/tests/user/author.php index 73ae3b6..f00af82 100644
class Tests_User_Author_Template extends WP_UnitTestCase { 98 98 99 99 $this->assertEquals( 2, get_the_author_posts() ); 100 100 101 _unregister_post_type( 'wptests_pt' );101 unregister_post_type( 'wptests_pt' ); 102 102 } 103 103 104 104 /** -
tests/phpunit/tests/user/capabilities.php
diff --git tests/phpunit/tests/user/capabilities.php tests/phpunit/tests/user/capabilities.php index 1316c17..183fed0 100644
class Tests_User_Capabilities extends WP_UnitTestCase { 760 760 $something = get_post_type_object( 'something' ); 761 761 $this->assertEquals( 'draw_somethings', $something->cap->edit_posts ); 762 762 $this->assertEquals( 'create_somethings', $something->cap->create_posts ); 763 _unregister_post_type( 'something' );763 unregister_post_type( 'something' ); 764 764 765 765 // Test meta authorization callbacks 766 766 if ( function_exists( 'register_meta') ) { … … class Tests_User_Capabilities extends WP_UnitTestCase { 845 845 $this->assertTrue($author_2->has_cap( $cap->create_posts )); 846 846 $this->assertTrue($contributor->has_cap( $cap->create_posts )); 847 847 848 _unregister_post_type( 'foobar' );848 unregister_post_type( 'foobar' ); 849 849 850 850 // Primitive capability edit_foobars is not assigned to any users. 851 851 register_post_type( 'foobar', array( 'capability_type' => array( 'foobar', 'foobars' ) ) ); … … class Tests_User_Capabilities extends WP_UnitTestCase { 868 868 $this->assertFalse($author_2->has_cap( $cap->create_posts )); 869 869 $this->assertFalse($contributor->has_cap( $cap->create_posts )); 870 870 871 _unregister_post_type( 'foobar' );871 unregister_post_type( 'foobar' ); 872 872 873 873 $cap = get_post_type_object( 'attachment' )->cap; 874 874 $this->assertEquals( 'upload_files', $cap->create_posts ); … … class Tests_User_Capabilities extends WP_UnitTestCase { 1116 1116 function test_require_edit_others_posts_if_post_type_doesnt_exist() { 1117 1117 register_post_type( 'existed' ); 1118 1118 $post_id = self::factory()->post->create( array( 'post_type' => 'existed' ) ); 1119 _unregister_post_type( 'existed' );1119 unregister_post_type( 'existed' ); 1120 1120 1121 1121 $subscriber_id = self::$users['subscriber']->ID; 1122 1122 $editor_id = self::$users['editor']->ID; … … class Tests_User_Capabilities extends WP_UnitTestCase { 1175 1175 $this->assertFalse( user_can( $author->ID, 'edit_post', $author_post->ID ) ); 1176 1176 $this->assertFalse( user_can( $contributor->ID, 'edit_post', $author_post->ID ) ); 1177 1177 1178 _unregister_post_type( 'page_capability' );1178 unregister_post_type( 'page_capability' ); 1179 1179 1180 1180 } 1181 1181 -
tests/phpunit/tests/user/countUserPosts.php
diff --git tests/phpunit/tests/user/countUserPosts.php tests/phpunit/tests/user/countUserPosts.php index bc91ceb..3ff92ef 100644
class Tests_User_CountUserPosts extends WP_UnitTestCase { 27 27 'post_author' => 12345, 28 28 'post_type' => 'wptests_pt', 29 29 ) ) ); 30 30 31 31 self::$post_ids[] = $factory->post->create( array( 32 32 'post_author' => 12345, 33 33 'post_type' => 'wptests_pt', … … class Tests_User_CountUserPosts extends WP_UnitTestCase { 48 48 } 49 49 50 50 public function tearDown() { 51 _unregister_post_type( 'wptests_pt' );51 unregister_post_type( 'wptests_pt' ); 52 52 parent::tearDown(); 53 53 } 54 54 -
tests/phpunit/tests/xmlrpc/wp/getPostType.php
diff --git tests/phpunit/tests/xmlrpc/wp/getPostType.php tests/phpunit/tests/xmlrpc/wp/getPostType.php index a00dbda..450ed36 100644
class Tests_XMLRPC_wp_getPostType extends WP_XMLRPC_UnitTestCase { 24 24 } 25 25 26 26 function tearDown() { 27 _unregister_post_type( $this->cpt_name );27 unregister_post_type( $this->cpt_name ); 28 28 29 29 parent::tearDown(); 30 30 } -
tests/phpunit/tests/xmlrpc/wp/getPosts.php
diff --git tests/phpunit/tests/xmlrpc/wp/getPosts.php tests/phpunit/tests/xmlrpc/wp/getPosts.php index 3d8dff4..bdd2dba 100644
class Tests_XMLRPC_wp_getPosts extends WP_XMLRPC_UnitTestCase { 104 104 $this->assertEquals( 1, count( $results3 ) ); 105 105 $this->assertEquals( $post->ID, $results3[0]['post_id'] ); 106 106 107 _unregister_post_type( $cpt_name );107 unregister_post_type( $cpt_name ); 108 108 } 109 109 110 110 function test_fields() { … … class Tests_XMLRPC_wp_getPosts extends WP_XMLRPC_UnitTestCase { 152 152 $this->assertEquals( 1, count( $results ) ); 153 153 } 154 154 155 } 156 No newline at end of file 155 }