mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-04-09 15:14:37 +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:
@@ -7,10 +7,10 @@ class Tests_IsObjectInTerm extends WP_UnitTestCase {
|
||||
public function test_terms_are_ints() {
|
||||
register_taxonomy( 'wptests_tax', 'post' );
|
||||
|
||||
$t1 = $this->factory->term->create( array( 'taxonomy' => 'wptests_tax' ) );
|
||||
$t2 = $this->factory->term->create( array( 'taxonomy' => 'wptests_tax' ) );
|
||||
$t1 = self::$factory->term->create( array( 'taxonomy' => 'wptests_tax' ) );
|
||||
$t2 = self::$factory->term->create( array( 'taxonomy' => 'wptests_tax' ) );
|
||||
|
||||
$posts = $this->factory->post->create_many( 2 );
|
||||
$posts = self::$factory->post->create_many( 2 );
|
||||
wp_set_object_terms( $posts[0], array( $t1 ), 'wptests_tax' );
|
||||
|
||||
$this->assertTrue( is_object_in_term( $posts[0], 'wptests_tax', array( $t1, $t2 ) ) );
|
||||
@@ -22,10 +22,10 @@ class Tests_IsObjectInTerm extends WP_UnitTestCase {
|
||||
public function test_terms_are_strings_and_match_term_id() {
|
||||
register_taxonomy( 'wptests_tax', 'post' );
|
||||
|
||||
$t1 = $this->factory->term->create( array( 'taxonomy' => 'wptests_tax' ) );
|
||||
$t2 = $this->factory->term->create( array( 'taxonomy' => 'wptests_tax' ) );
|
||||
$t1 = self::$factory->term->create( array( 'taxonomy' => 'wptests_tax' ) );
|
||||
$t2 = self::$factory->term->create( array( 'taxonomy' => 'wptests_tax' ) );
|
||||
|
||||
$posts = $this->factory->post->create_many( 2 );
|
||||
$posts = self::$factory->post->create_many( 2 );
|
||||
wp_set_object_terms( $posts[0], array( $t1 ), 'wptests_tax' );
|
||||
|
||||
$t1_str = (string) $t1;
|
||||
@@ -40,10 +40,10 @@ class Tests_IsObjectInTerm extends WP_UnitTestCase {
|
||||
public function test_terms_are_strings_and_match_term_name() {
|
||||
register_taxonomy( 'wptests_tax', 'post' );
|
||||
|
||||
$t1 = $this->factory->term->create( array( 'taxonomy' => 'wptests_tax', 'name' => 'Foo' ) );
|
||||
$t2 = $this->factory->term->create( array( 'taxonomy' => 'wptests_tax', 'name' => 'Bar') );
|
||||
$t1 = self::$factory->term->create( array( 'taxonomy' => 'wptests_tax', 'name' => 'Foo' ) );
|
||||
$t2 = self::$factory->term->create( array( 'taxonomy' => 'wptests_tax', 'name' => 'Bar') );
|
||||
|
||||
$posts = $this->factory->post->create_many( 2 );
|
||||
$posts = self::$factory->post->create_many( 2 );
|
||||
wp_set_object_terms( $posts[0], array( $t1 ), 'wptests_tax' );
|
||||
|
||||
$this->assertTrue( is_object_in_term( $posts[0], 'wptests_tax', array( 'Foo', 'Bar' ) ) );
|
||||
@@ -55,10 +55,10 @@ class Tests_IsObjectInTerm extends WP_UnitTestCase {
|
||||
public function test_terms_are_strings_and_match_term_slug() {
|
||||
register_taxonomy( 'wptests_tax', 'post' );
|
||||
|
||||
$t1 = $this->factory->term->create( array( 'taxonomy' => 'wptests_tax', 'slug' => 'foo' ) );
|
||||
$t2 = $this->factory->term->create( array( 'taxonomy' => 'wptests_tax', 'slug' => 'bar') );
|
||||
$t1 = self::$factory->term->create( array( 'taxonomy' => 'wptests_tax', 'slug' => 'foo' ) );
|
||||
$t2 = self::$factory->term->create( array( 'taxonomy' => 'wptests_tax', 'slug' => 'bar') );
|
||||
|
||||
$posts = $this->factory->post->create_many( 2 );
|
||||
$posts = self::$factory->post->create_many( 2 );
|
||||
wp_set_object_terms( $posts[0], array( $t1 ), 'wptests_tax' );
|
||||
|
||||
$this->assertTrue( is_object_in_term( $posts[0], 'wptests_tax', array( 'foo', 'bar' ) ) );
|
||||
@@ -70,10 +70,10 @@ class Tests_IsObjectInTerm extends WP_UnitTestCase {
|
||||
public function test_terms_contain_strings_and_ints_and_match_term_id_as_int() {
|
||||
register_taxonomy( 'wptests_tax', 'post' );
|
||||
|
||||
$t1 = $this->factory->term->create( array( 'taxonomy' => 'wptests_tax', 'slug' => 'foo' ) );
|
||||
$t2 = $this->factory->term->create( array( 'taxonomy' => 'wptests_tax', 'slug' => 'bar') );
|
||||
$t1 = self::$factory->term->create( array( 'taxonomy' => 'wptests_tax', 'slug' => 'foo' ) );
|
||||
$t2 = self::$factory->term->create( array( 'taxonomy' => 'wptests_tax', 'slug' => 'bar') );
|
||||
|
||||
$posts = $this->factory->post->create_many( 2 );
|
||||
$posts = self::$factory->post->create_many( 2 );
|
||||
wp_set_object_terms( $posts[0], array( $t1 ), 'wptests_tax' );
|
||||
|
||||
$this->assertTrue( is_object_in_term( $posts[0], 'wptests_tax', array( $t1, 'bar' ) ) );
|
||||
@@ -87,9 +87,9 @@ class Tests_IsObjectInTerm extends WP_UnitTestCase {
|
||||
*/
|
||||
public function test_should_not_return_true_if_term_name_begins_with_existing_term_id() {
|
||||
register_taxonomy( 'wptests_tax', 'post' );
|
||||
$t = $this->factory->term->create( array( 'taxonomy' => 'wptests_tax' ) );
|
||||
$t = self::$factory->term->create( array( 'taxonomy' => 'wptests_tax' ) );
|
||||
|
||||
$post_ID = $this->factory->post->create();
|
||||
$post_ID = self::$factory->post->create();
|
||||
wp_set_object_terms( $post_ID, $t, 'wptests_tax' );
|
||||
|
||||
$int_tax_name = $t . '_term_name';
|
||||
@@ -108,7 +108,7 @@ class Tests_IsObjectInTerm extends WP_UnitTestCase {
|
||||
global $wpdb;
|
||||
|
||||
register_taxonomy( 'wptests_tax', 'post' );
|
||||
$terms = $this->factory->term->create_many( 2, array( 'taxonomy' => 'wptests_tax' ) );
|
||||
$terms = self::$factory->term->create_many( 2, array( 'taxonomy' => 'wptests_tax' ) );
|
||||
|
||||
$o = 12345;
|
||||
wp_set_object_terms( $o, $terms[0], 'wptests_tax' );
|
||||
@@ -129,7 +129,7 @@ class Tests_IsObjectInTerm extends WP_UnitTestCase {
|
||||
global $wpdb;
|
||||
|
||||
register_taxonomy( 'wptests_tax', 'post' );
|
||||
$terms = $this->factory->term->create_many( 2, array( 'taxonomy' => 'wptests_tax' ) );
|
||||
$terms = self::$factory->term->create_many( 2, array( 'taxonomy' => 'wptests_tax' ) );
|
||||
|
||||
$o = 12345;
|
||||
wp_set_object_terms( $o, $terms[0], 'wptests_tax' );
|
||||
|
||||
Reference in New Issue
Block a user