Tests: Reset post-related globals after each test.

Globals like `$pages` were leaking between tests, resulting in various
bits of weirdness.

Globals will kill WordPress. Globals are killing WordPress.

See #38196.

git-svn-id: https://develop.svn.wordpress.org/trunk@38678 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Boone Gorges
2016-09-30 03:15:36 +00:00
parent 907b5fc527
commit c4c80d3dd4
2 changed files with 31 additions and 2 deletions
+23
View File
@@ -212,4 +212,27 @@ class Tests_TestHelpers extends WP_UnitTestCase {
public function test_die_handler_should_handle_wp_error() {
wp_die( new WP_Error( 'test', 'test' ) );
}
/**
* This test is just a setup for the one that follows.
*
* @ticket 38196
*/
public function test_setup_postdata_globals_should_be_reset_on_teardown__setup() {
$post = self::factory()->post->create_and_get();
$GLOBALS['wp_query'] = new WP_Query();
$GLOBALS['wp_query']->setup_postdata( $post );
$this->assertNotEmpty( $post );
}
/**
* @ticket 38196
*/
public function test_setup_postdata_globals_should_be_reset_on_teardown() {
$globals = array( 'post', 'id', 'authordata', 'currentday', 'currentmonth', 'page', 'pages', 'multipage', 'more', 'numpages' );
foreach ( $globals as $global ) {
$this->assertTrue( ! isset( $GLOBALS[ $global ] ), $global );
}
}
}