mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-04-02 11:44:33 +00:00
Unit Tests: one $factory to rule them all, and it shall be static.
Using more than one instance of `WP_UnitTest_Factory` causes all kinds of craziness, due to out-of-sync internal generator sequences. Since we want to use `setUpBeforeClass`, we were creating ad hoc instances. To avoid that, we were injecting one `static` instance via Dependency Injection in `wpSetUpBeforeClass`. All tests should really use the `static` instance, so we will remove the instance prop `$factory`. Replace `$this->factory` with `self::$factory` over 2000 times. Rewrite all of the tests that were hard-coding dynamic values. #YOLOFriday git-svn-id: https://develop.svn.wordpress.org/trunk@35225 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -39,7 +39,7 @@ class Tests_Query_SetupPostdata extends WP_UnitTestCase {
|
||||
}
|
||||
|
||||
public function test_id() {
|
||||
$p = $this->factory->post->create_and_get();
|
||||
$p = self::$factory->post->create_and_get();
|
||||
setup_postdata( $p );
|
||||
|
||||
$this->assertNotEmpty( $p->ID );
|
||||
@@ -50,7 +50,7 @@ class Tests_Query_SetupPostdata extends WP_UnitTestCase {
|
||||
* @ticket 30970
|
||||
*/
|
||||
public function test_setup_by_id() {
|
||||
$p = $this->factory->post->create_and_get();
|
||||
$p = self::$factory->post->create_and_get();
|
||||
setup_postdata( $p->ID );
|
||||
|
||||
$this->assertSame( $p->ID, $GLOBALS['id'] );
|
||||
@@ -72,7 +72,7 @@ class Tests_Query_SetupPostdata extends WP_UnitTestCase {
|
||||
* @ticket 30970
|
||||
*/
|
||||
public function test_setup_by_postish_object() {
|
||||
$p = $this->factory->post->create();
|
||||
$p = self::$factory->post->create();
|
||||
|
||||
$post = new stdClass();
|
||||
$post->ID = $p;
|
||||
@@ -82,8 +82,8 @@ class Tests_Query_SetupPostdata extends WP_UnitTestCase {
|
||||
}
|
||||
|
||||
public function test_authordata() {
|
||||
$u = $this->factory->user->create_and_get();
|
||||
$p = $this->factory->post->create_and_get( array(
|
||||
$u = self::$factory->user->create_and_get();
|
||||
$p = self::$factory->post->create_and_get( array(
|
||||
'post_author' => $u->ID,
|
||||
) );
|
||||
setup_postdata( $p );
|
||||
@@ -93,7 +93,7 @@ class Tests_Query_SetupPostdata extends WP_UnitTestCase {
|
||||
}
|
||||
|
||||
public function test_currentday() {
|
||||
$p = $this->factory->post->create_and_get( array(
|
||||
$p = self::$factory->post->create_and_get( array(
|
||||
'post_date' => '1980-09-09 06:30:00',
|
||||
) );
|
||||
setup_postdata( $p );
|
||||
@@ -102,7 +102,7 @@ class Tests_Query_SetupPostdata extends WP_UnitTestCase {
|
||||
}
|
||||
|
||||
public function test_currentmonth() {
|
||||
$p = $this->factory->post->create_and_get( array(
|
||||
$p = self::$factory->post->create_and_get( array(
|
||||
'post_date' => '1980-09-09 06:30:00',
|
||||
) );
|
||||
setup_postdata( $p );
|
||||
@@ -111,14 +111,14 @@ class Tests_Query_SetupPostdata extends WP_UnitTestCase {
|
||||
}
|
||||
|
||||
public function test_secondary_query_post_vars() {
|
||||
$users = $this->factory->user->create_many( 2 );
|
||||
$users = self::$factory->user->create_many( 2 );
|
||||
|
||||
$post1 = $this->factory->post->create_and_get( array(
|
||||
$post1 = self::$factory->post->create_and_get( array(
|
||||
'post_author' => $users[0],
|
||||
'post_date' => '2012-02-02 02:00:00',
|
||||
) );
|
||||
|
||||
$post2 = $this->factory->post->create_and_get( array(
|
||||
$post2 = self::$factory->post->create_and_get( array(
|
||||
'post_author' => $users[1],
|
||||
'post_date' => '2013-03-03 03:00:00',
|
||||
) );
|
||||
@@ -157,7 +157,7 @@ class Tests_Query_SetupPostdata extends WP_UnitTestCase {
|
||||
}
|
||||
|
||||
public function test_single_page() {
|
||||
$post = $this->factory->post->create_and_get( array(
|
||||
$post = self::$factory->post->create_and_get( array(
|
||||
'post_content' => 'Page 0',
|
||||
) );
|
||||
setup_postdata( $post );
|
||||
@@ -168,7 +168,7 @@ class Tests_Query_SetupPostdata extends WP_UnitTestCase {
|
||||
}
|
||||
|
||||
public function test_multi_page() {
|
||||
$post = $this->factory->post->create_and_get( array(
|
||||
$post = self::$factory->post->create_and_get( array(
|
||||
'post_content' => 'Page 0<!--nextpage-->Page 1<!--nextpage-->Page 2<!--nextpage-->Page 3',
|
||||
) );
|
||||
setup_postdata( $post );
|
||||
@@ -182,7 +182,7 @@ class Tests_Query_SetupPostdata extends WP_UnitTestCase {
|
||||
* @ticket 16746
|
||||
*/
|
||||
public function test_nextpage_at_start_of_content() {
|
||||
$post = $this->factory->post->create_and_get( array(
|
||||
$post = self::$factory->post->create_and_get( array(
|
||||
'post_content' => '<!--nextpage-->Page 1<!--nextpage-->Page 2<!--nextpage-->Page 3',
|
||||
) );
|
||||
setup_postdata( $post );
|
||||
@@ -193,7 +193,7 @@ class Tests_Query_SetupPostdata extends WP_UnitTestCase {
|
||||
}
|
||||
|
||||
public function test_trim_nextpage_linebreaks() {
|
||||
$post = $this->factory->post->create_and_get( array(
|
||||
$post = self::$factory->post->create_and_get( array(
|
||||
'post_content' => "Page 0\n<!--nextpage-->\nPage 1\nhas a line break\n<!--nextpage-->Page 2<!--nextpage-->\n\nPage 3",
|
||||
) );
|
||||
setup_postdata( $post );
|
||||
@@ -205,10 +205,10 @@ class Tests_Query_SetupPostdata extends WP_UnitTestCase {
|
||||
* @ticket 25349
|
||||
*/
|
||||
public function test_secondary_query_nextpage() {
|
||||
$post1 = $this->factory->post->create( array(
|
||||
$post1 = self::$factory->post->create( array(
|
||||
'post_content' => 'Post 1 Page 1<!--nextpage-->Post 1 Page 2',
|
||||
) );
|
||||
$post2 = $this->factory->post->create( array(
|
||||
$post2 = self::$factory->post->create( array(
|
||||
'post_content' => 'Post 2 Page 1<!--nextpage-->Post 2 Page 2',
|
||||
) );
|
||||
|
||||
@@ -237,7 +237,7 @@ class Tests_Query_SetupPostdata extends WP_UnitTestCase {
|
||||
}
|
||||
|
||||
public function test_page_from_wp_query() {
|
||||
$page = $this->factory->post->create_and_get( array(
|
||||
$page = self::$factory->post->create_and_get( array(
|
||||
'post_type' => 'page',
|
||||
) );
|
||||
|
||||
@@ -250,7 +250,7 @@ class Tests_Query_SetupPostdata extends WP_UnitTestCase {
|
||||
}
|
||||
|
||||
public function test_page_when_on_page() {
|
||||
$page = $this->factory->post->create_and_get( array(
|
||||
$page = self::$factory->post->create_and_get( array(
|
||||
'post_type' => 'page',
|
||||
) );
|
||||
$this->go_to( get_permalink( $page ) );
|
||||
@@ -263,7 +263,7 @@ class Tests_Query_SetupPostdata extends WP_UnitTestCase {
|
||||
* @ticket 20904
|
||||
*/
|
||||
public function test_secondary_query_page() {
|
||||
$post = $this->factory->post->create_and_get();
|
||||
$post = self::$factory->post->create_and_get();
|
||||
$this->go_to( '/?page=3' );
|
||||
setup_postdata( $post );
|
||||
|
||||
@@ -271,7 +271,7 @@ class Tests_Query_SetupPostdata extends WP_UnitTestCase {
|
||||
$this->assertSame( 3, $GLOBALS['page'] );
|
||||
|
||||
// Secondary loop.
|
||||
$posts = $this->factory->post->create_many( 5 );
|
||||
$posts = self::$factory->post->create_many( 5 );
|
||||
$q = new WP_Query( array(
|
||||
'page' => 4,
|
||||
'posts_per_page' => 1,
|
||||
@@ -294,7 +294,7 @@ class Tests_Query_SetupPostdata extends WP_UnitTestCase {
|
||||
* @ticket 20904
|
||||
*/
|
||||
public function test_more_when_on_setup_post() {
|
||||
$post = $this->factory->post->create_and_get();
|
||||
$post = self::$factory->post->create_and_get();
|
||||
$this->go_to( get_permalink( $post ) );
|
||||
setup_postdata( $post );
|
||||
|
||||
@@ -307,8 +307,8 @@ class Tests_Query_SetupPostdata extends WP_UnitTestCase {
|
||||
* $more should not be true when the set-up post is not the same as the current post.
|
||||
*/
|
||||
public function test_more_when_on_single() {
|
||||
$post1 = $this->factory->post->create_and_get();
|
||||
$post2 = $this->factory->post->create_and_get();
|
||||
$post1 = self::$factory->post->create_and_get();
|
||||
$post2 = self::$factory->post->create_and_get();
|
||||
$this->go_to( get_permalink( $post1 ) );
|
||||
setup_postdata( $post2 );
|
||||
|
||||
@@ -321,8 +321,8 @@ class Tests_Query_SetupPostdata extends WP_UnitTestCase {
|
||||
* $more should not be true when the set-up post is not the same as the current page.
|
||||
*/
|
||||
public function test_more_when_on_page() {
|
||||
$post = $this->factory->post->create_and_get();
|
||||
$page = $this->factory->post->create_and_get( array(
|
||||
$post = self::$factory->post->create_and_get();
|
||||
$page = self::$factory->post->create_and_get( array(
|
||||
'post_type' => 'page',
|
||||
) );
|
||||
$this->go_to( get_permalink( $page ) );
|
||||
@@ -335,7 +335,7 @@ class Tests_Query_SetupPostdata extends WP_UnitTestCase {
|
||||
* @ticket 20904
|
||||
*/
|
||||
public function test_more_when_on_feed() {
|
||||
$post = $this->factory->post->create_and_get();
|
||||
$post = self::$factory->post->create_and_get();
|
||||
$this->go_to( '/?feed=rss' );
|
||||
setup_postdata( $post );
|
||||
|
||||
@@ -347,7 +347,7 @@ class Tests_Query_SetupPostdata extends WP_UnitTestCase {
|
||||
* @ticket 25349
|
||||
*/
|
||||
public function test_secondary_query_more() {
|
||||
$post = $this->factory->post->create_and_get();
|
||||
$post = self::$factory->post->create_and_get();
|
||||
$this->go_to( get_permalink( $post ) );
|
||||
setup_postdata( $post );
|
||||
|
||||
@@ -379,10 +379,10 @@ class Tests_Query_SetupPostdata extends WP_UnitTestCase {
|
||||
* global $post should use the content of $a_post rather then the global post.
|
||||
*/
|
||||
function test_setup_postdata_loop() {
|
||||
$post_id = $this->factory->post->create( array( 'post_content' => 'global post' ) );
|
||||
$post_id = self::$factory->post->create( array( 'post_content' => 'global post' ) );
|
||||
$GLOBALS['wp_query']->post = $GLOBALS['post'] = get_post( $post_id );
|
||||
|
||||
$ids = $this->factory->post->create_many(5);
|
||||
$ids = self::$factory->post->create_many(5);
|
||||
foreach ( $ids as $id ) {
|
||||
$page = get_post( $id );
|
||||
if ( $page ) {
|
||||
|
||||
Reference in New Issue
Block a user