diff --git a/tests/phpunit/tests/rewrite/oldSlugRedirect.php b/tests/phpunit/tests/rewrite/oldSlugRedirect.php index 754ad996ff..cf38ba452e 100644 --- a/tests/phpunit/tests/rewrite/oldSlugRedirect.php +++ b/tests/phpunit/tests/rewrite/oldSlugRedirect.php @@ -8,17 +8,19 @@ class Tests_Rewrite_OldSlugRedirect extends WP_UnitTestCase { protected $old_slug_redirect_url; - protected $post_id; + protected static $post_id; - public function set_up() { - parent::set_up(); - - $this->post_id = self::factory()->post->create( + public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { + self::$post_id = $factory->post->create( array( 'post_title' => 'Foo Bar', 'post_name' => 'foo-bar', ) ); + } + + public function set_up() { + parent::set_up(); add_filter( 'old_slug_redirect_url', array( $this, 'filter_old_slug_redirect_url' ), 10, 1 ); @@ -37,16 +39,16 @@ class Tests_Rewrite_OldSlugRedirect extends WP_UnitTestCase { } public function test_old_slug_redirect() { - $old_permalink = user_trailingslashit( get_permalink( $this->post_id ) ); + $old_permalink = user_trailingslashit( get_permalink( self::$post_id ) ); wp_update_post( array( - 'ID' => $this->post_id, + 'ID' => self::$post_id, 'post_name' => 'bar-baz', ) ); - $permalink = user_trailingslashit( get_permalink( $this->post_id ) ); + $permalink = user_trailingslashit( get_permalink( self::$post_id ) ); $this->go_to( $old_permalink ); wp_old_slug_redirect(); @@ -57,16 +59,16 @@ class Tests_Rewrite_OldSlugRedirect extends WP_UnitTestCase { * @ticket 36723 */ public function test_old_slug_redirect_cache() { - $old_permalink = user_trailingslashit( get_permalink( $this->post_id ) ); + $old_permalink = user_trailingslashit( get_permalink( self::$post_id ) ); wp_update_post( array( - 'ID' => $this->post_id, + 'ID' => self::$post_id, 'post_name' => 'bar-baz', ) ); - $permalink = user_trailingslashit( get_permalink( $this->post_id ) ); + $permalink = user_trailingslashit( get_permalink( self::$post_id ) ); $this->go_to( $old_permalink ); @@ -83,16 +85,16 @@ class Tests_Rewrite_OldSlugRedirect extends WP_UnitTestCase { * @ticket 36723 */ public function test_old_slug_redirect_cache_invalidation() { - $old_permalink = user_trailingslashit( get_permalink( $this->post_id ) ); + $old_permalink = user_trailingslashit( get_permalink( self::$post_id ) ); wp_update_post( array( - 'ID' => $this->post_id, + 'ID' => self::$post_id, 'post_name' => 'bar-baz', ) ); - $permalink = user_trailingslashit( get_permalink( $this->post_id ) ); + $permalink = user_trailingslashit( get_permalink( self::$post_id ) ); $this->go_to( $old_permalink ); @@ -101,12 +103,12 @@ class Tests_Rewrite_OldSlugRedirect extends WP_UnitTestCase { wp_update_post( array( - 'ID' => $this->post_id, + 'ID' => self::$post_id, 'post_name' => 'foo-bar-baz', ) ); - $permalink = user_trailingslashit( get_permalink( $this->post_id ) ); + $permalink = user_trailingslashit( get_permalink( self::$post_id ) ); $num_queries = get_num_queries(); wp_old_slug_redirect(); @@ -118,7 +120,7 @@ class Tests_Rewrite_OldSlugRedirect extends WP_UnitTestCase { $file = DIR_TESTDATA . '/images/canola.jpg'; $attachment_id = self::factory()->attachment->create_object( $file, - $this->post_id, + self::$post_id, array( 'post_mime_type' => 'image/jpeg', 'post_name' => 'my-attachment', @@ -129,7 +131,7 @@ class Tests_Rewrite_OldSlugRedirect extends WP_UnitTestCase { wp_update_post( array( - 'ID' => $this->post_id, + 'ID' => self::$post_id, 'post_name' => 'bar-baz', ) ); @@ -148,7 +150,7 @@ class Tests_Rewrite_OldSlugRedirect extends WP_UnitTestCase { ) ); - $permalink = user_trailingslashit( trailingslashit( get_permalink( $this->post_id ) ) . 'the-attachment' ); + $permalink = user_trailingslashit( trailingslashit( get_permalink( self::$post_id ) ) . 'the-attachment' ); $this->go_to( $old_permalink ); wp_old_slug_redirect(); @@ -158,21 +160,21 @@ class Tests_Rewrite_OldSlugRedirect extends WP_UnitTestCase { public function test_old_slug_redirect_paged() { wp_update_post( array( - 'ID' => $this->post_id, + 'ID' => self::$post_id, 'post_content' => 'TestTest', ) ); - $old_permalink = user_trailingslashit( trailingslashit( get_permalink( $this->post_id ) ) . 'page/2' ); + $old_permalink = user_trailingslashit( trailingslashit( get_permalink( self::$post_id ) ) . 'page/2' ); wp_update_post( array( - 'ID' => $this->post_id, + 'ID' => self::$post_id, 'post_name' => 'bar-baz', ) ); - $permalink = user_trailingslashit( trailingslashit( get_permalink( $this->post_id ) ) . 'page/2' ); + $permalink = user_trailingslashit( trailingslashit( get_permalink( self::$post_id ) ) . 'page/2' ); $this->go_to( $old_permalink ); wp_old_slug_redirect(); @@ -183,11 +185,11 @@ class Tests_Rewrite_OldSlugRedirect extends WP_UnitTestCase { * @ticket 35031 */ public function test_old_slug_doesnt_redirect_when_reused() { - $old_permalink = user_trailingslashit( get_permalink( $this->post_id ) ); + $old_permalink = user_trailingslashit( get_permalink( self::$post_id ) ); wp_update_post( array( - 'ID' => $this->post_id, + 'ID' => self::$post_id, 'post_name' => 'bar-baz', ) );