mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 22:30:04 +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,11 +12,11 @@ class Tests_Term_GetTermLink extends WP_UnitTestCase {
|
||||
}
|
||||
|
||||
public function test_integer_should_be_interpreted_as_term_id() {
|
||||
$t1 = $this->factory->term->create( array(
|
||||
$t1 = self::$factory->term->create( array(
|
||||
'taxonomy' => 'wptests_tax',
|
||||
'name' => 'foo',
|
||||
) );
|
||||
$t2 = $this->factory->term->create( array(
|
||||
$t2 = self::$factory->term->create( array(
|
||||
'taxonomy' => 'wptests_tax',
|
||||
'slug' => $t1,
|
||||
) );
|
||||
@@ -28,11 +28,11 @@ class Tests_Term_GetTermLink extends WP_UnitTestCase {
|
||||
}
|
||||
|
||||
public function test_numeric_string_should_be_interpreted_as_term_slug() {
|
||||
$t1 = $this->factory->term->create( array(
|
||||
$t1 = self::$factory->term->create( array(
|
||||
'taxonomy' => 'wptests_tax',
|
||||
'name' => 'foo',
|
||||
) );
|
||||
$t2 = $this->factory->term->create( array(
|
||||
$t2 = self::$factory->term->create( array(
|
||||
'taxonomy' => 'wptests_tax',
|
||||
'slug' => $t1,
|
||||
) );
|
||||
@@ -49,7 +49,7 @@ class Tests_Term_GetTermLink extends WP_UnitTestCase {
|
||||
}
|
||||
|
||||
public function test_category_should_use_cat_query_var_with_term_id() {
|
||||
$c = $this->factory->category->create();
|
||||
$c = self::$factory->category->create();
|
||||
|
||||
$actual = get_term_link( $c, 'category' );
|
||||
$this->assertContains( 'cat=' . $c, $actual );
|
||||
@@ -60,7 +60,7 @@ class Tests_Term_GetTermLink extends WP_UnitTestCase {
|
||||
'query_var' => 'foo',
|
||||
) );
|
||||
|
||||
$t = $this->factory->term->create( array(
|
||||
$t = self::$factory->term->create( array(
|
||||
'taxonomy' => 'wptests_tax2',
|
||||
'slug' => 'bar',
|
||||
) );
|
||||
@@ -74,7 +74,7 @@ class Tests_Term_GetTermLink extends WP_UnitTestCase {
|
||||
'query_var' => false,
|
||||
) );
|
||||
|
||||
$t = $this->factory->term->create( array(
|
||||
$t = self::$factory->term->create( array(
|
||||
'taxonomy' => 'wptests_tax2',
|
||||
'slug' => 'bar',
|
||||
) );
|
||||
@@ -97,12 +97,12 @@ class Tests_Term_GetTermLink extends WP_UnitTestCase {
|
||||
|
||||
flush_rewrite_rules();
|
||||
|
||||
$t1 = $this->factory->term->create( array(
|
||||
$t1 = self::$factory->term->create( array(
|
||||
'taxonomy' => 'wptests_tax2',
|
||||
'slug' => 'term1',
|
||||
) );
|
||||
|
||||
$t2 = $this->factory->term->create( array(
|
||||
$t2 = self::$factory->term->create( array(
|
||||
'taxonomy' => 'wptests_tax2',
|
||||
'slug' => 'term2',
|
||||
'parent' => $t1,
|
||||
@@ -126,12 +126,12 @@ class Tests_Term_GetTermLink extends WP_UnitTestCase {
|
||||
|
||||
flush_rewrite_rules();
|
||||
|
||||
$t1 = $this->factory->term->create( array(
|
||||
$t1 = self::$factory->term->create( array(
|
||||
'taxonomy' => 'wptests_tax2',
|
||||
'slug' => 'term1',
|
||||
) );
|
||||
|
||||
$t2 = $this->factory->term->create( array(
|
||||
$t2 = self::$factory->term->create( array(
|
||||
'taxonomy' => 'wptests_tax2',
|
||||
'slug' => 'term2',
|
||||
'parent' => $t1,
|
||||
|
||||
Reference in New Issue
Block a user