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
+14 -11
View File
@@ -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' ) );