diff --git a/tests/phpunit/includes/testcase.php b/tests/phpunit/includes/testcase.php index 933e66f76a..782482f196 100644 --- a/tests/phpunit/includes/testcase.php +++ b/tests/phpunit/includes/testcase.php @@ -47,6 +47,7 @@ class WP_UnitTestCase extends PHPUnit_Framework_TestCase { if ( defined( 'WP_RUN_CORE_TESTS' ) && WP_RUN_CORE_TESTS ) { $this->reset_post_types(); $this->reset_taxonomies(); + $this->reset_post_statuses(); } $this->start_transaction(); @@ -107,6 +108,15 @@ class WP_UnitTestCase extends PHPUnit_Framework_TestCase { create_initial_taxonomies(); } + /** + * Unregister non-built-in post statuses. + */ + protected function reset_post_statuses() { + foreach ( get_post_stati( array( '_builtin' => false ) ) as $post_status ) { + _unregister_post_status( $post_status ); + } + } + /** * Saves the action and filter-related globals so they can be restored later. * diff --git a/tests/phpunit/includes/utils.php b/tests/phpunit/includes/utils.php index 3d91f0663d..d6ea45c5c5 100644 --- a/tests/phpunit/includes/utils.php +++ b/tests/phpunit/includes/utils.php @@ -331,6 +331,17 @@ function _unregister_taxonomy( $taxonomy_name ) { unset( $GLOBALS['wp_taxonomies'][$taxonomy_name] ); } +/** + * Unregister a post status. + * + * @since 4.2.0 + * + * @param string $status + */ +function _unregister_post_status( $status ) { + unset( $GLOBALS['wp_post_statuses'][ $status ] ); +} + function _cleanup_query_vars() { // clean out globals to stop them polluting wp and wp_query foreach ( $GLOBALS['wp']->public_query_vars as $v ) diff --git a/tests/phpunit/tests/includes/helpers.php b/tests/phpunit/tests/includes/helpers.php index c589022e8c..2bcd309dbc 100755 --- a/tests/phpunit/tests/includes/helpers.php +++ b/tests/phpunit/tests/includes/helpers.php @@ -159,4 +159,13 @@ class Tests_TestHelpers extends WP_UnitTestCase { $this->assertEqualSetsWithIndex( $expected, $actual ); } } + + public function test__unregister_post_status() { + register_post_status( 'foo' ); + _unregister_post_status( 'foo' ); + + $stati = get_post_stati(); + + $this->assertFalse( isset( $stati['foo'] ) ); + } }