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

@@ -9,7 +9,7 @@ class Tests_Post_GetPostClass extends WP_UnitTestCase {
public function setUp() {
parent::setUp();
$this->post_id = $this->factory->post->create();
$this->post_id = self::$factory->post->create();
}
public function test_with_tags() {
@@ -22,7 +22,7 @@ class Tests_Post_GetPostClass extends WP_UnitTestCase {
}
public function test_with_categories() {
$cats = $this->factory->category->create_many( 2 );
$cats = self::$factory->category->create_many( 2 );
wp_set_post_terms( $this->post_id, $cats, 'category' );
$cat0 = get_term( $cats[0], 'category' );
@@ -57,9 +57,9 @@ class Tests_Post_GetPostClass extends WP_UnitTestCase {
* @ticket 30883
*/
public function test_with_utf8_category_slugs() {
$cat_id1 = $this->factory->category->create( array( 'name' => 'Первая рубрика' ) );
$cat_id2 = $this->factory->category->create( array( 'name' => 'Вторая рубрика' ) );
$cat_id3 = $this->factory->category->create( array( 'name' => '25кадр' ) );
$cat_id1 = self::$factory->category->create( array( 'name' => 'Первая рубрика' ) );
$cat_id2 = self::$factory->category->create( array( 'name' => 'Вторая рубрика' ) );
$cat_id3 = self::$factory->category->create( array( 'name' => '25кадр' ) );
wp_set_post_terms( $this->post_id, array( $cat_id1, $cat_id2, $cat_id3 ), 'category' );
$found = get_post_class( '', $this->post_id );
@@ -73,9 +73,9 @@ class Tests_Post_GetPostClass extends WP_UnitTestCase {
* @ticket 30883
*/
public function test_with_utf8_tag_slugs() {
$tag_id1 = $this->factory->tag->create( array( 'name' => 'Первая метка' ) );
$tag_id2 = $this->factory->tag->create( array( 'name' => 'Вторая метка' ) );
$tag_id3 = $this->factory->tag->create( array( 'name' => '25кадр' ) );
$tag_id1 = self::$factory->tag->create( array( 'name' => 'Первая метка' ) );
$tag_id2 = self::$factory->tag->create( array( 'name' => 'Вторая метка' ) );
$tag_id3 = self::$factory->tag->create( array( 'name' => '25кадр' ) );
wp_set_post_terms( $this->post_id, array( $tag_id1, $tag_id2, $tag_id3 ), 'post_tag' );
$found = get_post_class( '', $this->post_id );
@@ -90,9 +90,9 @@ class Tests_Post_GetPostClass extends WP_UnitTestCase {
*/
public function test_with_utf8_term_slugs() {
register_taxonomy( 'wptests_tax', 'post' );
$term_id1 = $this->factory->term->create( array( 'taxonomy' => 'wptests_tax', 'name' => 'Первая метка' ) );
$term_id2 = $this->factory->term->create( array( 'taxonomy' => 'wptests_tax', 'name' => 'Вторая метка' ) );
$term_id3 = $this->factory->term->create( array( 'taxonomy' => 'wptests_tax', 'name' => '25кадр' ) );
$term_id1 = self::$factory->term->create( array( 'taxonomy' => 'wptests_tax', 'name' => 'Первая метка' ) );
$term_id2 = self::$factory->term->create( array( 'taxonomy' => 'wptests_tax', 'name' => 'Вторая метка' ) );
$term_id3 = self::$factory->term->create( array( 'taxonomy' => 'wptests_tax', 'name' => '25кадр' ) );
wp_set_post_terms( $this->post_id, array( $term_id1, $term_id2, $term_id3 ), 'wptests_tax' );
$found = get_post_class( '', $this->post_id );