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:
parent
73bde8a278
commit
f23a5ef832
@ -84,10 +84,11 @@ class Tests_Canonical extends WP_UnitTestCase {
|
||||
}
|
||||
|
||||
function tearDown() {
|
||||
global $wp_rewrite;
|
||||
parent::tearDown();
|
||||
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..
|
||||
|
@ -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_on_front', $this->factory->post->create( array( 'post_title' => 'front-page', 'post_type' => 'page' ) ) );
|
||||
$wp_rewrite->init();
|
||||
flush_rewrite_rules();
|
||||
$wp_rewrite->flush_rules();
|
||||
}
|
||||
|
||||
function tearDown() {
|
||||
global $wp_rewrite;
|
||||
parent::tearDown();
|
||||
$wp_rewrite->init();
|
||||
}
|
||||
|
||||
function data() {
|
||||
|
@ -4,6 +4,12 @@
|
||||
*/
|
||||
class Tests_Link extends WP_UnitTestCase {
|
||||
|
||||
function tearDown() {
|
||||
global $wp_rewrite;
|
||||
parent::tearDown();
|
||||
$wp_rewrite->init();
|
||||
}
|
||||
|
||||
function _get_pagenum_link_cb( $url ) {
|
||||
return $url . '/WooHoo';
|
||||
}
|
||||
@ -65,7 +71,6 @@ class Tests_Link extends WP_UnitTestCase {
|
||||
$this->assertEquals( '', wp_get_shortlink( 0 ) );
|
||||
$this->assertEquals( '', wp_get_shortlink() );
|
||||
|
||||
$wp_rewrite->permalink_structure = '';
|
||||
$wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
|
||||
$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 ) );
|
||||
$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() {
|
||||
@ -91,14 +93,10 @@ class Tests_Link extends WP_UnitTestCase {
|
||||
$this->assertEquals( home_url( '?p=' . $post_id ), wp_get_shortlink( $post_id, 'post' ) );
|
||||
|
||||
global $wp_rewrite;
|
||||
$wp_rewrite->permalink_structure = '';
|
||||
$wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
|
||||
$wp_rewrite->flush_rules();
|
||||
|
||||
$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();
|
||||
|
||||
$this->assertEquals( home_url( '/' ), wp_get_shortlink( $post_id, 'post' ) );
|
||||
|
||||
$wp_rewrite->set_permalink_structure( '' );
|
||||
$wp_rewrite->flush_rules();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -23,15 +23,19 @@ class Tests_Query_Conditionals extends WP_UnitTestCase {
|
||||
update_option( 'posts_per_page', 5 );
|
||||
|
||||
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();
|
||||
$GLOBALS['wp_rewrite']->init();
|
||||
flush_rewrite_rules();
|
||||
|
||||
$wp_rewrite->flush_rules();
|
||||
}
|
||||
|
||||
function tearDown() {
|
||||
global $wp_rewrite;
|
||||
parent::tearDown();
|
||||
$GLOBALS['wp_rewrite']->init();
|
||||
$wp_rewrite->init();
|
||||
}
|
||||
|
||||
function test_home() {
|
||||
|
@ -22,20 +22,21 @@ class Tests_Query_TaxQuery extends WP_UnitTestCase {
|
||||
protected $tax;
|
||||
|
||||
function setUp() {
|
||||
global $wp_rewrite;
|
||||
parent::setUp();
|
||||
|
||||
set_current_screen( 'front' );
|
||||
|
||||
update_option( 'permalink_structure', '/%year%/%monthnum%/%day%/%postname%/' );
|
||||
|
||||
$GLOBALS['wp_the_query'] = new WP_Query();
|
||||
$GLOBALS['wp_query'] = $GLOBALS['wp_the_query'];
|
||||
|
||||
$wp_rewrite->init();
|
||||
$wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
|
||||
|
||||
create_initial_taxonomies();
|
||||
register_taxonomy( 'testtax', 'post', array( 'public' => true ) );
|
||||
|
||||
$GLOBALS['wp_rewrite']->init();
|
||||
flush_rewrite_rules();
|
||||
$wp_rewrite->flush_rules();
|
||||
|
||||
$this->tag_id = $this->factory->tag->create( array( 'slug' => 'tag-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() {
|
||||
global $wp_rewrite;
|
||||
parent::tearDown();
|
||||
|
||||
_unregister_taxonomy( 'testtax' );
|
||||
|
||||
$wp_rewrite->init();
|
||||
|
||||
remove_action( 'pre_get_posts', array( $this, 'pre_get_posts_tax_category_tax_query' ) );
|
||||
}
|
||||
|
||||
|
@ -8,11 +8,15 @@ require_once dirname( dirname( __FILE__ ) ) . '/query.php';
|
||||
*/
|
||||
class Tests_Query_VerbosePageRules extends Tests_Query_Conditionals {
|
||||
function setUp() {
|
||||
parent::setUp();
|
||||
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();
|
||||
$GLOBALS['wp_rewrite']->init();
|
||||
flush_rewrite_rules();
|
||||
|
||||
$wp_rewrite->flush_rules();
|
||||
}
|
||||
}
|
||||
|
@ -8,19 +8,22 @@
|
||||
class Tests_Rewrite extends WP_UnitTestCase {
|
||||
|
||||
function setUp() {
|
||||
global $wp_rewrite;
|
||||
parent::setUp();
|
||||
|
||||
// Need rewrite rules in place to use url_to_postid
|
||||
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();
|
||||
$GLOBALS['wp_rewrite']->init();
|
||||
flush_rewrite_rules();
|
||||
|
||||
$wp_rewrite->flush_rules();
|
||||
}
|
||||
|
||||
function tearDown() {
|
||||
global $wp_rewrite;
|
||||
parent::tearDown();
|
||||
$GLOBALS['wp_rewrite']->init();
|
||||
$wp_rewrite->init();
|
||||
}
|
||||
|
||||
function test_url_to_postid() {
|
||||
@ -34,16 +37,16 @@ class Tests_Rewrite extends WP_UnitTestCase {
|
||||
|
||||
function test_url_to_postid_custom_post_type() {
|
||||
delete_option( 'rewrite_rules' );
|
||||
|
||||
|
||||
$post_type = rand_str( 12 );
|
||||
register_post_type( $post_type, array( 'public' => true ) );
|
||||
|
||||
|
||||
$id = $this->factory->post->create( array( 'post_type' => $post_type ) );
|
||||
$this->assertEquals( $id, url_to_postid( get_permalink( $id ) ) );
|
||||
|
||||
_unregister_post_type( $post_type );
|
||||
$this->assertEquals( $id, url_to_postid( get_permalink( $id ) ) );
|
||||
|
||||
_unregister_post_type( $post_type );
|
||||
}
|
||||
|
||||
|
||||
function test_url_to_postid_hierarchical() {
|
||||
|
||||
$parent_id = $this->factory->post->create( array( 'post_title' => 'Parent', 'post_type' => 'page' ) );
|
||||
|
Loading…
Reference in New Issue
Block a user