mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 14:20:15 +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:
@@ -12,13 +12,13 @@ class Tests_Comment_CommentsTemplate extends WP_UnitTestCase {
|
||||
*/
|
||||
public function test_should_respect_comment_order_asc_when_default_comments_page_is_newest() {
|
||||
$now = time();
|
||||
$p = $this->factory->post->create();
|
||||
$comment_1 = $this->factory->comment->create( array(
|
||||
$p = self::$factory->post->create();
|
||||
$comment_1 = self::$factory->comment->create( array(
|
||||
'comment_post_ID' => $p,
|
||||
'comment_content' => '1',
|
||||
'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 100 ),
|
||||
) );
|
||||
$comment_2 = $this->factory->comment->create( array(
|
||||
$comment_2 = self::$factory->comment->create( array(
|
||||
'comment_post_ID' => $p,
|
||||
'comment_content' => '2',
|
||||
'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 200 ),
|
||||
@@ -42,13 +42,13 @@ class Tests_Comment_CommentsTemplate extends WP_UnitTestCase {
|
||||
*/
|
||||
public function test_should_respect_comment_order_desc_when_default_comments_page_is_newest() {
|
||||
$now = time();
|
||||
$p = $this->factory->post->create();
|
||||
$comment_1 = $this->factory->comment->create( array(
|
||||
$p = self::$factory->post->create();
|
||||
$comment_1 = self::$factory->comment->create( array(
|
||||
'comment_post_ID' => $p,
|
||||
'comment_content' => '1',
|
||||
'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 100 ),
|
||||
) );
|
||||
$comment_2 = $this->factory->comment->create( array(
|
||||
$comment_2 = self::$factory->comment->create( array(
|
||||
'comment_post_ID' => $p,
|
||||
'comment_content' => '2',
|
||||
'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 200 ),
|
||||
@@ -72,13 +72,13 @@ class Tests_Comment_CommentsTemplate extends WP_UnitTestCase {
|
||||
*/
|
||||
public function test_should_respect_comment_order_asc_when_default_comments_page_is_oldest() {
|
||||
$now = time();
|
||||
$p = $this->factory->post->create();
|
||||
$comment_1 = $this->factory->comment->create( array(
|
||||
$p = self::$factory->post->create();
|
||||
$comment_1 = self::$factory->comment->create( array(
|
||||
'comment_post_ID' => $p,
|
||||
'comment_content' => '1',
|
||||
'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 100 ),
|
||||
) );
|
||||
$comment_2 = $this->factory->comment->create( array(
|
||||
$comment_2 = self::$factory->comment->create( array(
|
||||
'comment_post_ID' => $p,
|
||||
'comment_content' => '2',
|
||||
'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 200 ),
|
||||
@@ -102,13 +102,13 @@ class Tests_Comment_CommentsTemplate extends WP_UnitTestCase {
|
||||
*/
|
||||
public function test_should_respect_comment_order_desc_when_default_comments_page_is_oldest() {
|
||||
$now = time();
|
||||
$p = $this->factory->post->create();
|
||||
$comment_1 = $this->factory->comment->create( array(
|
||||
$p = self::$factory->post->create();
|
||||
$comment_1 = self::$factory->comment->create( array(
|
||||
'comment_post_ID' => $p,
|
||||
'comment_content' => '1',
|
||||
'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 100 ),
|
||||
) );
|
||||
$comment_2 = $this->factory->comment->create( array(
|
||||
$comment_2 = self::$factory->comment->create( array(
|
||||
'comment_post_ID' => $p,
|
||||
'comment_content' => '2',
|
||||
'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 200 ),
|
||||
@@ -132,33 +132,33 @@ class Tests_Comment_CommentsTemplate extends WP_UnitTestCase {
|
||||
*/
|
||||
public function test_should_respect_comment_order_asc_when_default_comments_page_is_newest_on_subsequent_pages() {
|
||||
$now = time();
|
||||
$p = $this->factory->post->create();
|
||||
$comment_1 = $this->factory->comment->create( array(
|
||||
$p = self::$factory->post->create();
|
||||
$comment_1 = self::$factory->comment->create( array(
|
||||
'comment_post_ID' => $p,
|
||||
'comment_content' => '1',
|
||||
'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 100 ),
|
||||
) );
|
||||
$comment_2 = $this->factory->comment->create( array(
|
||||
$comment_2 = self::$factory->comment->create( array(
|
||||
'comment_post_ID' => $p,
|
||||
'comment_content' => '2',
|
||||
'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 200 ),
|
||||
) );
|
||||
$comment_3 = $this->factory->comment->create( array(
|
||||
$comment_3 = self::$factory->comment->create( array(
|
||||
'comment_post_ID' => $p,
|
||||
'comment_content' => '3',
|
||||
'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 300 ),
|
||||
) );
|
||||
$comment_4 = $this->factory->comment->create( array(
|
||||
$comment_4 = self::$factory->comment->create( array(
|
||||
'comment_post_ID' => $p,
|
||||
'comment_content' => '4',
|
||||
'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 400 ),
|
||||
) );
|
||||
$comment_5 = $this->factory->comment->create( array(
|
||||
$comment_5 = self::$factory->comment->create( array(
|
||||
'comment_post_ID' => $p,
|
||||
'comment_content' => '3',
|
||||
'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 500 ),
|
||||
) );
|
||||
$comment_6 = $this->factory->comment->create( array(
|
||||
$comment_6 = self::$factory->comment->create( array(
|
||||
'comment_post_ID' => $p,
|
||||
'comment_content' => '4',
|
||||
'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 600 ),
|
||||
@@ -187,33 +187,33 @@ class Tests_Comment_CommentsTemplate extends WP_UnitTestCase {
|
||||
*/
|
||||
public function test_should_respect_comment_order_desc_when_default_comments_page_is_newest_on_subsequent_pages() {
|
||||
$now = time();
|
||||
$p = $this->factory->post->create();
|
||||
$comment_1 = $this->factory->comment->create( array(
|
||||
$p = self::$factory->post->create();
|
||||
$comment_1 = self::$factory->comment->create( array(
|
||||
'comment_post_ID' => $p,
|
||||
'comment_content' => '1',
|
||||
'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 100 ),
|
||||
) );
|
||||
$comment_2 = $this->factory->comment->create( array(
|
||||
$comment_2 = self::$factory->comment->create( array(
|
||||
'comment_post_ID' => $p,
|
||||
'comment_content' => '2',
|
||||
'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 200 ),
|
||||
) );
|
||||
$comment_3 = $this->factory->comment->create( array(
|
||||
$comment_3 = self::$factory->comment->create( array(
|
||||
'comment_post_ID' => $p,
|
||||
'comment_content' => '3',
|
||||
'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 300 ),
|
||||
) );
|
||||
$comment_4 = $this->factory->comment->create( array(
|
||||
$comment_4 = self::$factory->comment->create( array(
|
||||
'comment_post_ID' => $p,
|
||||
'comment_content' => '4',
|
||||
'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 400 ),
|
||||
) );
|
||||
$comment_5 = $this->factory->comment->create( array(
|
||||
$comment_5 = self::$factory->comment->create( array(
|
||||
'comment_post_ID' => $p,
|
||||
'comment_content' => '3',
|
||||
'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 500 ),
|
||||
) );
|
||||
$comment_6 = $this->factory->comment->create( array(
|
||||
$comment_6 = self::$factory->comment->create( array(
|
||||
'comment_post_ID' => $p,
|
||||
'comment_content' => '4',
|
||||
'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 600 ),
|
||||
@@ -242,23 +242,23 @@ class Tests_Comment_CommentsTemplate extends WP_UnitTestCase {
|
||||
*/
|
||||
public function test_should_respect_comment_order_asc_when_default_comments_page_is_oldest_on_subsequent_pages() {
|
||||
$now = time();
|
||||
$p = $this->factory->post->create();
|
||||
$comment_1 = $this->factory->comment->create( array(
|
||||
$p = self::$factory->post->create();
|
||||
$comment_1 = self::$factory->comment->create( array(
|
||||
'comment_post_ID' => $p,
|
||||
'comment_content' => '1',
|
||||
'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 100 ),
|
||||
) );
|
||||
$comment_2 = $this->factory->comment->create( array(
|
||||
$comment_2 = self::$factory->comment->create( array(
|
||||
'comment_post_ID' => $p,
|
||||
'comment_content' => '2',
|
||||
'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 200 ),
|
||||
) );
|
||||
$comment_3 = $this->factory->comment->create( array(
|
||||
$comment_3 = self::$factory->comment->create( array(
|
||||
'comment_post_ID' => $p,
|
||||
'comment_content' => '3',
|
||||
'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 300 ),
|
||||
) );
|
||||
$comment_4 = $this->factory->comment->create( array(
|
||||
$comment_4 = self::$factory->comment->create( array(
|
||||
'comment_post_ID' => $p,
|
||||
'comment_content' => '4',
|
||||
'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 400 ),
|
||||
@@ -287,23 +287,23 @@ class Tests_Comment_CommentsTemplate extends WP_UnitTestCase {
|
||||
*/
|
||||
public function test_should_respect_comment_order_desc_when_default_comments_page_is_oldest_on_subsequent_pages() {
|
||||
$now = time();
|
||||
$p = $this->factory->post->create();
|
||||
$comment_1 = $this->factory->comment->create( array(
|
||||
$p = self::$factory->post->create();
|
||||
$comment_1 = self::$factory->comment->create( array(
|
||||
'comment_post_ID' => $p,
|
||||
'comment_content' => '1',
|
||||
'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 100 ),
|
||||
) );
|
||||
$comment_2 = $this->factory->comment->create( array(
|
||||
$comment_2 = self::$factory->comment->create( array(
|
||||
'comment_post_ID' => $p,
|
||||
'comment_content' => '2',
|
||||
'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 200 ),
|
||||
) );
|
||||
$comment_3 = $this->factory->comment->create( array(
|
||||
$comment_3 = self::$factory->comment->create( array(
|
||||
'comment_post_ID' => $p,
|
||||
'comment_content' => '3',
|
||||
'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 300 ),
|
||||
) );
|
||||
$comment_4 = $this->factory->comment->create( array(
|
||||
$comment_4 = self::$factory->comment->create( array(
|
||||
'comment_post_ID' => $p,
|
||||
'comment_content' => '4',
|
||||
'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 400 ),
|
||||
@@ -334,18 +334,18 @@ class Tests_Comment_CommentsTemplate extends WP_UnitTestCase {
|
||||
*/
|
||||
public function test_last_page_of_comments_should_be_full_when_default_comment_page_is_newest() {
|
||||
$now = time();
|
||||
$p = $this->factory->post->create();
|
||||
$comment_1 = $this->factory->comment->create( array(
|
||||
$p = self::$factory->post->create();
|
||||
$comment_1 = self::$factory->comment->create( array(
|
||||
'comment_post_ID' => $p,
|
||||
'comment_content' => '1',
|
||||
'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 100 ),
|
||||
) );
|
||||
$comment_2 = $this->factory->comment->create( array(
|
||||
$comment_2 = self::$factory->comment->create( array(
|
||||
'comment_post_ID' => $p,
|
||||
'comment_content' => '2',
|
||||
'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 200 ),
|
||||
) );
|
||||
$comment_3 = $this->factory->comment->create( array(
|
||||
$comment_3 = self::$factory->comment->create( array(
|
||||
'comment_post_ID' => $p,
|
||||
'comment_content' => '3',
|
||||
'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 300 ),
|
||||
@@ -376,18 +376,18 @@ class Tests_Comment_CommentsTemplate extends WP_UnitTestCase {
|
||||
*/
|
||||
public function test_first_page_of_comments_should_have_remainder_when_default_comments_page_is_newest() {
|
||||
$now = time();
|
||||
$p = $this->factory->post->create();
|
||||
$comment_1 = $this->factory->comment->create( array(
|
||||
$p = self::$factory->post->create();
|
||||
$comment_1 = self::$factory->comment->create( array(
|
||||
'comment_post_ID' => $p,
|
||||
'comment_content' => '1',
|
||||
'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 100 ),
|
||||
) );
|
||||
$comment_2 = $this->factory->comment->create( array(
|
||||
$comment_2 = self::$factory->comment->create( array(
|
||||
'comment_post_ID' => $p,
|
||||
'comment_content' => '2',
|
||||
'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 200 ),
|
||||
) );
|
||||
$comment_3 = $this->factory->comment->create( array(
|
||||
$comment_3 = self::$factory->comment->create( array(
|
||||
'comment_post_ID' => $p,
|
||||
'comment_content' => '3',
|
||||
'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 300 ),
|
||||
@@ -416,23 +416,23 @@ class Tests_Comment_CommentsTemplate extends WP_UnitTestCase {
|
||||
*/
|
||||
public function test_comment_permalinks_should_be_correct_when_using_default_display_callback_with_default_comment_page_oldest() {
|
||||
$now = time();
|
||||
$p = $this->factory->post->create();
|
||||
$comment_1 = $this->factory->comment->create( array(
|
||||
$p = self::$factory->post->create();
|
||||
$comment_1 = self::$factory->comment->create( array(
|
||||
'comment_post_ID' => $p,
|
||||
'comment_content' => '1',
|
||||
'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 100 ),
|
||||
) );
|
||||
$comment_2 = $this->factory->comment->create( array(
|
||||
$comment_2 = self::$factory->comment->create( array(
|
||||
'comment_post_ID' => $p,
|
||||
'comment_content' => '2',
|
||||
'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 200 ),
|
||||
) );
|
||||
$comment_3 = $this->factory->comment->create( array(
|
||||
$comment_3 = self::$factory->comment->create( array(
|
||||
'comment_post_ID' => $p,
|
||||
'comment_content' => '3',
|
||||
'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 300 ),
|
||||
) );
|
||||
$comment_4 = $this->factory->comment->create( array(
|
||||
$comment_4 = self::$factory->comment->create( array(
|
||||
'comment_post_ID' => $p,
|
||||
'comment_content' => '4',
|
||||
'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 400 ),
|
||||
@@ -480,33 +480,33 @@ class Tests_Comment_CommentsTemplate extends WP_UnitTestCase {
|
||||
*/
|
||||
public function test_comment_permalinks_should_be_correct_when_using_default_display_callback_with_default_comment_page_newest() {
|
||||
$now = time();
|
||||
$p = $this->factory->post->create();
|
||||
$comment_1 = $this->factory->comment->create( array(
|
||||
$p = self::$factory->post->create();
|
||||
$comment_1 = self::$factory->comment->create( array(
|
||||
'comment_post_ID' => $p,
|
||||
'comment_content' => '1',
|
||||
'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 100 ),
|
||||
) );
|
||||
$comment_2 = $this->factory->comment->create( array(
|
||||
$comment_2 = self::$factory->comment->create( array(
|
||||
'comment_post_ID' => $p,
|
||||
'comment_content' => '2',
|
||||
'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 200 ),
|
||||
) );
|
||||
$comment_3 = $this->factory->comment->create( array(
|
||||
$comment_3 = self::$factory->comment->create( array(
|
||||
'comment_post_ID' => $p,
|
||||
'comment_content' => '3',
|
||||
'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 300 ),
|
||||
) );
|
||||
$comment_4 = $this->factory->comment->create( array(
|
||||
$comment_4 = self::$factory->comment->create( array(
|
||||
'comment_post_ID' => $p,
|
||||
'comment_content' => '4',
|
||||
'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 400 ),
|
||||
) );
|
||||
$comment_5 = $this->factory->comment->create( array(
|
||||
$comment_5 = self::$factory->comment->create( array(
|
||||
'comment_post_ID' => $p,
|
||||
'comment_content' => '4',
|
||||
'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 500 ),
|
||||
) );
|
||||
$comment_6 = $this->factory->comment->create( array(
|
||||
$comment_6 = self::$factory->comment->create( array(
|
||||
'comment_post_ID' => $p,
|
||||
'comment_content' => '4',
|
||||
'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 600 ),
|
||||
|
||||
Reference in New Issue
Block a user