diff --git a/tests/phpunit/tests/general/document-title.php b/tests/phpunit/tests/general/document-title.php index 7ba319666a..e1cf583681 100644 --- a/tests/phpunit/tests/general/document-title.php +++ b/tests/phpunit/tests/general/document-title.php @@ -9,34 +9,39 @@ class Tests_General_DocumentTitle extends WP_UnitTestCase { public $blog_name; + public static $category_id; + public static $author_id; + public static $post_id; + + public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { + self::$category_id = $factory->category->create( array( + 'name' => 'test_category', + ) ); + + self::$author_id = $factory->user->create( array( + 'role' => 'author', + 'user_login' => 'test_author', + 'description' => 'test_author', + ) ); + + self::$post_id = $factory->post->create( array( + 'post_author' => self::$author_id, + 'post_status' => 'publish', + 'post_title' => 'test_title', + 'post_type' => 'post', + 'post_date' => '2015-09-22 18:52:17', + 'category' => self::$category_id, + ) ); + } function setUp() { parent::setUp(); add_action( 'after_setup_theme', array( $this, '_add_title_tag_support' ) ); - $this->category_id = $this->factory->category->create( array( - 'name' => 'test_category', - ) ); - - $this->author_id = $this->factory->user->create( array( - 'role' => 'author', - 'user_login' => 'test_author', - 'description' => 'test_author', - ) ); - - $this->post_id = $this->factory->post->create( array( - 'post_author' => $this->author_id, - 'post_status' => 'publish', - 'post_title' => 'test_title', - 'post_type' => 'post', - 'post_date' => '2015-09-22 18:52:17', - 'category' => $this->category_id, - ) ); - $this->blog_name = get_option( 'blogname' ); - setup_postdata( get_post( $this->post_id ) ); + setup_postdata( get_post( self::$post_id ) ); } function tearDown() { @@ -126,7 +131,7 @@ class Tests_General_DocumentTitle extends WP_UnitTestCase { } function test_singular_title() { - $this->go_to( '?p=' . $this->post_id ); + $this->go_to( '?p=' . self::$post_id ); add_filter( 'document_title_parts', array( $this, '_singular_title_parts' ) ); @@ -142,7 +147,7 @@ class Tests_General_DocumentTitle extends WP_UnitTestCase { } function test_category_title() { - $this->go_to( '?cat=' . $this->category_id ); + $this->go_to( '?cat=' . self::$category_id ); $this->assertEquals( sprintf( 'test_category – %s', $this->blog_name ), wp_get_document_title() ); } @@ -154,7 +159,7 @@ class Tests_General_DocumentTitle extends WP_UnitTestCase { } function test_author_title() { - $this->go_to( '?author=' . $this->author_id ); + $this->go_to( '?author=' . self::$author_id ); $this->assertEquals( sprintf( 'test_author – %s', $this->blog_name ), wp_get_document_title() ); } @@ -202,7 +207,7 @@ class Tests_General_DocumentTitle extends WP_UnitTestCase { } function test_paged_post_title() { - $this->go_to( '?paged=4&p=' . $this->post_id ); + $this->go_to( '?paged=4&p=' . self::$post_id ); add_filter( 'title_tag_parts', array( $this, '_paged_post_title_parts' ) ); @@ -219,7 +224,7 @@ class Tests_General_DocumentTitle extends WP_UnitTestCase { } function test_rearrange_title_parts() { - $this->go_to( '?p=' . $this->post_id ); + $this->go_to( '?p=' . self::$post_id ); add_filter( 'document_title_parts', array( $this, '_rearrange_title_parts' ) ); @@ -236,7 +241,7 @@ class Tests_General_DocumentTitle extends WP_UnitTestCase { } function test_change_title_separator() { - $this->go_to( '?p=' . $this->post_id ); + $this->go_to( '?p=' . self::$post_id ); add_filter( 'document_title_separator', array( $this, '_change_title_separator' ) );