mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-11 12:20:22 +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:
@@ -21,7 +21,7 @@ class Tests_Category extends WP_UnitTestCase {
|
||||
*/
|
||||
function test_get_all_category_ids() {
|
||||
// create categories
|
||||
$this->factory->category->create_many( 2 );
|
||||
self::$factory->category->create_many( 2 );
|
||||
|
||||
// create new taxonomy to ensure not included
|
||||
register_taxonomy( 'test_tax_cat', 'post' );
|
||||
@@ -38,13 +38,13 @@ class Tests_Category extends WP_UnitTestCase {
|
||||
function test_get_category_by_slug() {
|
||||
|
||||
// create Test Categories
|
||||
$testcat = $this->factory->category->create_and_get(
|
||||
$testcat = self::$factory->category->create_and_get(
|
||||
array(
|
||||
'slug' => 'testcat',
|
||||
'name' => 'Test Category 1'
|
||||
)
|
||||
);
|
||||
$testcat2 = $this->factory->category->create_and_get(
|
||||
$testcat2 = self::$factory->category->create_and_get(
|
||||
array(
|
||||
'slug' => 'testcat2',
|
||||
'name' => 'Test Category 2'
|
||||
@@ -73,7 +73,7 @@ class Tests_Category extends WP_UnitTestCase {
|
||||
'name' => 'Test MCC',
|
||||
'description' => 'Category Test'
|
||||
);
|
||||
$testcat = $this->factory->category->create_and_get( $testcat_array );
|
||||
$testcat = self::$factory->category->create_and_get( $testcat_array );
|
||||
$testcat_array['term_id'] = $testcat->term_id;
|
||||
|
||||
$testcat2_array = array(
|
||||
@@ -82,7 +82,7 @@ class Tests_Category extends WP_UnitTestCase {
|
||||
'description' => 'Category Test',
|
||||
'parent' => $testcat->term_id
|
||||
);
|
||||
$testcat2 = $this->factory->category->create_and_get( $testcat2_array );
|
||||
$testcat2 = self::$factory->category->create_and_get( $testcat2_array );
|
||||
$testcat2_array['term_id'] = $testcat2->term_id;
|
||||
|
||||
// unset properties to enable validation of object
|
||||
@@ -145,7 +145,7 @@ class Tests_Category extends WP_UnitTestCase {
|
||||
function test_get_cat_name() {
|
||||
|
||||
// create Test Category
|
||||
$testcat = $this->factory->category->create_and_get(
|
||||
$testcat = self::$factory->category->create_and_get(
|
||||
array(
|
||||
'slug' => 'testcat',
|
||||
'name' => 'Test Category 1'
|
||||
@@ -165,7 +165,7 @@ class Tests_Category extends WP_UnitTestCase {
|
||||
function test_get_cat_ID() {
|
||||
|
||||
// create Test Category
|
||||
$testcat = $this->factory->category->create_and_get(
|
||||
$testcat = self::$factory->category->create_and_get(
|
||||
array(
|
||||
'slug' => 'testcat',
|
||||
'name' => 'Test Category 1'
|
||||
@@ -185,42 +185,42 @@ class Tests_Category extends WP_UnitTestCase {
|
||||
function test_get_category_by_path() {
|
||||
|
||||
// create Test Categories
|
||||
$root_id = $this->factory->category->create(
|
||||
$root_id = self::$factory->category->create(
|
||||
array(
|
||||
'slug' => 'root',
|
||||
)
|
||||
);
|
||||
$root_cat_id = $this->factory->category->create(
|
||||
$root_cat_id = self::$factory->category->create(
|
||||
array(
|
||||
'slug' => 'cat',
|
||||
'parent' => $root_id
|
||||
)
|
||||
);
|
||||
$root_cat_cat_id = $this->factory->category->create(
|
||||
$root_cat_cat_id = self::$factory->category->create(
|
||||
array(
|
||||
'slug' => 'cat', //note this is modified on create
|
||||
'parent' => $root_cat_id
|
||||
)
|
||||
);
|
||||
$root_path_id = $this->factory->category->create(
|
||||
$root_path_id = self::$factory->category->create(
|
||||
array(
|
||||
'slug' => 'path',
|
||||
'parent' => $root_id
|
||||
)
|
||||
);
|
||||
$root_path_cat_id = $this->factory->category->create(
|
||||
$root_path_cat_id = self::$factory->category->create(
|
||||
array(
|
||||
'slug' => 'cat', //note this is modified on create
|
||||
'parent' => $root_path_id
|
||||
)
|
||||
);
|
||||
$root_level_id = $this->factory->category->create(
|
||||
$root_level_id = self::$factory->category->create(
|
||||
array(
|
||||
'slug' => 'level-1',
|
||||
'parent' => $root_id
|
||||
)
|
||||
);
|
||||
$root_level_cat_id = $this->factory->category->create(
|
||||
$root_level_cat_id = self::$factory->category->create(
|
||||
array(
|
||||
'slug' => 'cat', //note this is modified on create
|
||||
'parent' => $root_level_id
|
||||
@@ -248,7 +248,7 @@ class Tests_Category extends WP_UnitTestCase {
|
||||
*/
|
||||
public function test_wp_dropdown_categories_value_field_should_default_to_term_id() {
|
||||
// Create a test category.
|
||||
$cat_id = $this->factory->category->create( array(
|
||||
$cat_id = self::$factory->category->create( array(
|
||||
'name' => 'Test Category',
|
||||
'slug' => 'test_category',
|
||||
) );
|
||||
@@ -268,7 +268,7 @@ class Tests_Category extends WP_UnitTestCase {
|
||||
*/
|
||||
public function test_wp_dropdown_categories_value_field_term_id() {
|
||||
// Create a test category.
|
||||
$cat_id = $this->factory->category->create( array(
|
||||
$cat_id = self::$factory->category->create( array(
|
||||
'name' => 'Test Category',
|
||||
'slug' => 'test_category',
|
||||
) );
|
||||
@@ -289,7 +289,7 @@ class Tests_Category extends WP_UnitTestCase {
|
||||
*/
|
||||
public function test_wp_dropdown_categories_value_field_slug() {
|
||||
// Create a test category.
|
||||
$cat_id = $this->factory->category->create( array(
|
||||
$cat_id = self::$factory->category->create( array(
|
||||
'name' => 'Test Category',
|
||||
'slug' => 'test_category',
|
||||
) );
|
||||
@@ -310,7 +310,7 @@ class Tests_Category extends WP_UnitTestCase {
|
||||
*/
|
||||
public function test_wp_dropdown_categories_value_field_should_fall_back_on_term_id_when_an_invalid_value_is_provided() {
|
||||
// Create a test category.
|
||||
$cat_id = $this->factory->category->create( array(
|
||||
$cat_id = self::$factory->category->create( array(
|
||||
'name' => 'Test Category',
|
||||
'slug' => 'test_category',
|
||||
) );
|
||||
@@ -330,12 +330,12 @@ class Tests_Category extends WP_UnitTestCase {
|
||||
* @ticket 32330
|
||||
*/
|
||||
public function test_wp_dropdown_categories_selected_should_respect_custom_value_field() {
|
||||
$c1 = $this->factory->category->create( array(
|
||||
$c1 = self::$factory->category->create( array(
|
||||
'name' => 'Test Category 1',
|
||||
'slug' => 'test_category_1',
|
||||
) );
|
||||
|
||||
$c2 = $this->factory->category->create( array(
|
||||
$c2 = self::$factory->category->create( array(
|
||||
'name' => 'Test Category 2',
|
||||
'slug' => 'test_category_2',
|
||||
) );
|
||||
@@ -354,7 +354,7 @@ class Tests_Category extends WP_UnitTestCase {
|
||||
* @ticket 33452
|
||||
*/
|
||||
public function test_wp_dropdown_categories_show_option_all_should_be_selected_if_no_selected_value_is_explicitly_passed_and_value_field_does_not_have_string_values() {
|
||||
$cats = $this->factory->category->create_many( 3 );
|
||||
$cats = self::$factory->category->create_many( 3 );
|
||||
|
||||
$found = wp_dropdown_categories( array(
|
||||
'echo' => 0,
|
||||
@@ -375,7 +375,7 @@ class Tests_Category extends WP_UnitTestCase {
|
||||
* @ticket 33452
|
||||
*/
|
||||
public function test_wp_dropdown_categories_show_option_all_should_be_selected_if_selected_value_of_0_string_is_explicitly_passed_and_value_field_does_not_have_string_values() {
|
||||
$cats = $this->factory->category->create_many( 3 );
|
||||
$cats = self::$factory->category->create_many( 3 );
|
||||
|
||||
$found = wp_dropdown_categories( array(
|
||||
'echo' => 0,
|
||||
|
||||
Reference in New Issue
Block a user