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:
Scott Taylor
2015-10-16 21:04:12 +00:00
parent 84272ff8cd
commit e70ebea219
169 changed files with 2631 additions and 2616 deletions

View File

@@ -38,7 +38,7 @@ class Tests_Comment_GetCommentsPagesCount extends WP_UnitTestCase {
*/
function test_empty() {
//setup post and comments
$post_id = $this->factory->post->create( array( 'post_title' => 'comment--post', 'post_type' => 'post' ) );
$post_id = self::$factory->post->create( array( 'post_title' => 'comment--post', 'post_type' => 'post' ) );
$this->go_to( '/?p=' . $post_id );
global $wp_query;
@@ -60,9 +60,9 @@ class Tests_Comment_GetCommentsPagesCount extends WP_UnitTestCase {
*/
function test_threaded_comments( ) {
//setup post and comments
$post = $this->factory->post->create_and_get( array( 'post_title' => 'comment--post', 'post_type' => 'post' ) );
$comments = $this->factory->comment->create_post_comments( $post->ID, 15 );
$this->factory->comment->create_post_comments( $post->ID, 6, array( 'comment_parent' => $comments[0] ) );
$post = self::$factory->post->create_and_get( array( 'post_title' => 'comment--post', 'post_type' => 'post' ) );
$comments = self::$factory->comment->create_post_comments( $post->ID, 15 );
self::$factory->comment->create_post_comments( $post->ID, 6, array( 'comment_parent' => $comments[0] ) );
$comments = get_comments( array( 'post_id' => $post->ID ) );
$this->assertEquals( 3, get_comment_pages_count( $comments, 10, false ) );
@@ -76,9 +76,9 @@ class Tests_Comment_GetCommentsPagesCount extends WP_UnitTestCase {
function test_option_thread_comments() {
//setup post and comments
$post = $this->factory->post->create_and_get( array( 'post_title' => 'comment--post', 'post_type' => 'post' ) );
$comments = $this->factory->comment->create_post_comments( $post->ID, 15 );
$this->factory->comment->create_post_comments( $post->ID, 6, array('comment_parent' => $comments[0] ) );
$post = self::$factory->post->create_and_get( array( 'post_title' => 'comment--post', 'post_type' => 'post' ) );
$comments = self::$factory->comment->create_post_comments( $post->ID, 15 );
self::$factory->comment->create_post_comments( $post->ID, 6, array('comment_parent' => $comments[0] ) );
$comments = get_comments( array( 'post_id' => $post->ID ) );
update_option( 'thread_comments', false );
@@ -104,8 +104,8 @@ class Tests_Comment_GetCommentsPagesCount extends WP_UnitTestCase {
update_option( 'posts_per_rss', 100 );
$post = $this->factory->post->create_and_get( array( 'post_title' => 'comment-post', 'post_type' => 'post' ) );
$comments = $this->factory->comment->create_post_comments( $post->ID, 25 );
$post = self::$factory->post->create_and_get( array( 'post_title' => 'comment-post', 'post_type' => 'post' ) );
$comments = self::$factory->comment->create_post_comments( $post->ID, 25 );
$wp_query = new WP_Query( array( 'p' => $post->ID, 'comments_per_page' => 10, 'feed' =>'comments-' ) );