Unit Tests: after [35225], make factory a method/getter on WP_UnitTestCase and add magic methods for BC for every plugin that is extending WP_UnitTestCase and accessing the $factory instance prop.

Props nerrad, wonderboymusic.
See #30017, #33968.



git-svn-id: https://develop.svn.wordpress.org/trunk@35242 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Scott Taylor
2015-10-17 18:02:16 +00:00
parent 5a0fd03f95
commit b757b37551
170 changed files with 2516 additions and 2507 deletions

View File

@@ -7,10 +7,10 @@ class Tests_IsObjectInTerm extends WP_UnitTestCase {
public function test_terms_are_ints() {
register_taxonomy( 'wptests_tax', 'post' );
$t1 = self::$factory->term->create( array( 'taxonomy' => 'wptests_tax' ) );
$t2 = self::$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 = self::$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 = self::$factory->term->create( array( 'taxonomy' => 'wptests_tax' ) );
$t2 = self::$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 = self::$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 = self::$factory->term->create( array( 'taxonomy' => 'wptests_tax', 'name' => 'Foo' ) );
$t2 = self::$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 = self::$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 = self::$factory->term->create( array( 'taxonomy' => 'wptests_tax', 'slug' => 'foo' ) );
$t2 = self::$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 = self::$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 = self::$factory->term->create( array( 'taxonomy' => 'wptests_tax', 'slug' => 'foo' ) );
$t2 = self::$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 = self::$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 = self::$factory->term->create( array( 'taxonomy' => 'wptests_tax' ) );
$t = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax' ) );
$post_ID = self::$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 = self::$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 = self::$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' );