Setup rewrite changes in tests in a predictable fashion. Don't mix method calls with wrapper function calls.

See #28706.


git-svn-id: https://develop.svn.wordpress.org/trunk@28966 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Scott Taylor 2014-07-03 01:42:57 +00:00
parent 73bde8a278
commit f23a5ef832
7 changed files with 53 additions and 36 deletions

View File

@ -84,10 +84,11 @@ class Tests_Canonical extends WP_UnitTestCase {
} }
function tearDown() { function tearDown() {
global $wp_rewrite;
parent::tearDown(); parent::tearDown();
wp_set_current_user( $this->old_current_user ); wp_set_current_user( $this->old_current_user );
$GLOBALS['wp_rewrite']->init(); $wp_rewrite->init();
} }
// URL's are relative to the site "front", ie. /category/uncategorized/ instead of http://site.../category.. // URL's are relative to the site "front", ie. /category/uncategorized/ instead of http://site.../category..

View File

@ -15,7 +15,13 @@ class Tests_Canonical_PageOnFront extends Tests_Canonical {
update_option( 'page_for_posts', $this->factory->post->create( array( 'post_title' => 'blog-page', 'post_type' => 'page' ) ) ); update_option( 'page_for_posts', $this->factory->post->create( array( 'post_title' => 'blog-page', 'post_type' => 'page' ) ) );
update_option( 'page_on_front', $this->factory->post->create( array( 'post_title' => 'front-page', 'post_type' => 'page' ) ) ); update_option( 'page_on_front', $this->factory->post->create( array( 'post_title' => 'front-page', 'post_type' => 'page' ) ) );
$wp_rewrite->init(); $wp_rewrite->init();
flush_rewrite_rules(); $wp_rewrite->flush_rules();
}
function tearDown() {
global $wp_rewrite;
parent::tearDown();
$wp_rewrite->init();
} }
function data() { function data() {

View File

@ -4,6 +4,12 @@
*/ */
class Tests_Link extends WP_UnitTestCase { class Tests_Link extends WP_UnitTestCase {
function tearDown() {
global $wp_rewrite;
parent::tearDown();
$wp_rewrite->init();
}
function _get_pagenum_link_cb( $url ) { function _get_pagenum_link_cb( $url ) {
return $url . '/WooHoo'; return $url . '/WooHoo';
} }
@ -65,7 +71,6 @@ class Tests_Link extends WP_UnitTestCase {
$this->assertEquals( '', wp_get_shortlink( 0 ) ); $this->assertEquals( '', wp_get_shortlink( 0 ) );
$this->assertEquals( '', wp_get_shortlink() ); $this->assertEquals( '', wp_get_shortlink() );
$wp_rewrite->permalink_structure = '';
$wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' ); $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
$wp_rewrite->flush_rules(); $wp_rewrite->flush_rules();
@ -78,9 +83,6 @@ class Tests_Link extends WP_UnitTestCase {
$this->assertEquals( home_url( '?p=' . $post_id ), wp_get_shortlink( 0, 'post' ) ); $this->assertEquals( home_url( '?p=' . $post_id ), wp_get_shortlink( 0, 'post' ) );
$this->assertEquals( home_url( '?p=' . $post_id ), wp_get_shortlink( 0 ) ); $this->assertEquals( home_url( '?p=' . $post_id ), wp_get_shortlink( 0 ) );
$this->assertEquals( home_url( '?p=' . $post_id ), wp_get_shortlink() ); $this->assertEquals( home_url( '?p=' . $post_id ), wp_get_shortlink() );
$wp_rewrite->set_permalink_structure( '' );
$wp_rewrite->flush_rules();
} }
function test_wp_get_shortlink_with_page() { function test_wp_get_shortlink_with_page() {
@ -91,14 +93,10 @@ class Tests_Link extends WP_UnitTestCase {
$this->assertEquals( home_url( '?p=' . $post_id ), wp_get_shortlink( $post_id, 'post' ) ); $this->assertEquals( home_url( '?p=' . $post_id ), wp_get_shortlink( $post_id, 'post' ) );
global $wp_rewrite; global $wp_rewrite;
$wp_rewrite->permalink_structure = '';
$wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' ); $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
$wp_rewrite->flush_rules(); $wp_rewrite->flush_rules();
$this->assertEquals( home_url( '?p=' . $post_id ), wp_get_shortlink( $post_id, 'post' ) ); $this->assertEquals( home_url( '?p=' . $post_id ), wp_get_shortlink( $post_id, 'post' ) );
$wp_rewrite->set_permalink_structure( '' );
$wp_rewrite->flush_rules();
} }
/** /**
@ -117,9 +115,6 @@ class Tests_Link extends WP_UnitTestCase {
$wp_rewrite->flush_rules(); $wp_rewrite->flush_rules();
$this->assertEquals( home_url( '/' ), wp_get_shortlink( $post_id, 'post' ) ); $this->assertEquals( home_url( '/' ), wp_get_shortlink( $post_id, 'post' ) );
$wp_rewrite->set_permalink_structure( '' );
$wp_rewrite->flush_rules();
} }
/** /**

View File

@ -23,15 +23,19 @@ class Tests_Query_Conditionals extends WP_UnitTestCase {
update_option( 'posts_per_page', 5 ); update_option( 'posts_per_page', 5 );
global $wp_rewrite; global $wp_rewrite;
update_option( 'permalink_structure', '/%year%/%monthnum%/%day%/%postname%/' );
$wp_rewrite->init();
$wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
create_initial_taxonomies(); create_initial_taxonomies();
$GLOBALS['wp_rewrite']->init();
flush_rewrite_rules(); $wp_rewrite->flush_rules();
} }
function tearDown() { function tearDown() {
global $wp_rewrite;
parent::tearDown(); parent::tearDown();
$GLOBALS['wp_rewrite']->init(); $wp_rewrite->init();
} }
function test_home() { function test_home() {

View File

@ -22,20 +22,21 @@ class Tests_Query_TaxQuery extends WP_UnitTestCase {
protected $tax; protected $tax;
function setUp() { function setUp() {
global $wp_rewrite;
parent::setUp(); parent::setUp();
set_current_screen( 'front' ); set_current_screen( 'front' );
update_option( 'permalink_structure', '/%year%/%monthnum%/%day%/%postname%/' );
$GLOBALS['wp_the_query'] = new WP_Query(); $GLOBALS['wp_the_query'] = new WP_Query();
$GLOBALS['wp_query'] = $GLOBALS['wp_the_query']; $GLOBALS['wp_query'] = $GLOBALS['wp_the_query'];
$wp_rewrite->init();
$wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
create_initial_taxonomies(); create_initial_taxonomies();
register_taxonomy( 'testtax', 'post', array( 'public' => true ) ); register_taxonomy( 'testtax', 'post', array( 'public' => true ) );
$GLOBALS['wp_rewrite']->init(); $wp_rewrite->flush_rules();
flush_rewrite_rules();
$this->tag_id = $this->factory->tag->create( array( 'slug' => 'tag-slug' ) ); $this->tag_id = $this->factory->tag->create( array( 'slug' => 'tag-slug' ) );
$this->cat_id = $this->factory->category->create( array( 'slug' => 'cat-slug' ) ); $this->cat_id = $this->factory->category->create( array( 'slug' => 'cat-slug' ) );
@ -56,10 +57,13 @@ class Tests_Query_TaxQuery extends WP_UnitTestCase {
} }
function tearDown() { function tearDown() {
global $wp_rewrite;
parent::tearDown(); parent::tearDown();
_unregister_taxonomy( 'testtax' ); _unregister_taxonomy( 'testtax' );
$wp_rewrite->init();
remove_action( 'pre_get_posts', array( $this, 'pre_get_posts_tax_category_tax_query' ) ); remove_action( 'pre_get_posts', array( $this, 'pre_get_posts_tax_category_tax_query' ) );
} }

View File

@ -8,11 +8,15 @@ require_once dirname( dirname( __FILE__ ) ) . '/query.php';
*/ */
class Tests_Query_VerbosePageRules extends Tests_Query_Conditionals { class Tests_Query_VerbosePageRules extends Tests_Query_Conditionals {
function setUp() { function setUp() {
parent::setUp();
global $wp_rewrite; global $wp_rewrite;
update_option( 'permalink_structure', '/%category%/%year%/%postname%/' );
parent::setUp();
$wp_rewrite->init();
$wp_rewrite->set_permalink_structure( '/%category%/%year%/%postname%/' );
create_initial_taxonomies(); create_initial_taxonomies();
$GLOBALS['wp_rewrite']->init();
flush_rewrite_rules(); $wp_rewrite->flush_rules();
} }
} }

View File

@ -8,19 +8,22 @@
class Tests_Rewrite extends WP_UnitTestCase { class Tests_Rewrite extends WP_UnitTestCase {
function setUp() { function setUp() {
global $wp_rewrite;
parent::setUp(); parent::setUp();
// Need rewrite rules in place to use url_to_postid // Need rewrite rules in place to use url_to_postid
global $wp_rewrite; $wp_rewrite->init();
update_option( 'permalink_structure', '/%year%/%monthnum%/%day%/%postname%/' ); $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
create_initial_taxonomies(); create_initial_taxonomies();
$GLOBALS['wp_rewrite']->init();
flush_rewrite_rules(); $wp_rewrite->flush_rules();
} }
function tearDown() { function tearDown() {
global $wp_rewrite;
parent::tearDown(); parent::tearDown();
$GLOBALS['wp_rewrite']->init(); $wp_rewrite->init();
} }
function test_url_to_postid() { function test_url_to_postid() {