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

@@ -37,7 +37,7 @@ class Tests_Multisite_Network extends WP_UnitTestCase {
* as the main network ID.
*/
function test_get_main_network_id_two_networks() {
$this->factory->network->create();
self::$factory->network->create();
$this->assertEquals( 1, get_main_network_id() );
}
@@ -49,7 +49,7 @@ class Tests_Multisite_Network extends WP_UnitTestCase {
function test_get_main_network_id_after_network_switch() {
global $current_site;
$id = $this->factory->network->create();
$id = self::$factory->network->create();
$current_site->id = (int) $id;
@@ -65,7 +65,7 @@ class Tests_Multisite_Network extends WP_UnitTestCase {
*/
function test_get_main_network_id_after_network_delete() {
global $wpdb, $current_site;
$id = $this->factory->network->create();
$id = self::$factory->network->create();
$current_site->id = (int) $id;
$wpdb->query( "UPDATE {$wpdb->site} SET id=100 WHERE id=1" );
@@ -90,13 +90,13 @@ class Tests_Multisite_Network extends WP_UnitTestCase {
$site_count_start = get_blog_count();
// false for large networks by default
add_filter( 'enable_live_network_counts', '__return_false' );
$this->factory->blog->create_many( 4 );
self::$factory->blog->create_many( 4 );
// count only updated when cron runs, so unchanged
$this->assertEquals( $site_count_start, (int) get_blog_count() );
add_filter( 'enable_live_network_counts', '__return_true' );
$site_ids = $this->factory->blog->create_many( 4 );
$site_ids = self::$factory->blog->create_many( 4 );
$this->assertEquals( $site_count_start + 9, (int) get_blog_count() );
@@ -211,7 +211,7 @@ class Tests_Multisite_Network extends WP_UnitTestCase {
// Only false for large networks as of 3.7
add_filter( 'enable_live_network_counts', '__return_false' );
$this->factory->user->create( array( 'role' => 'administrator' ) );
self::$factory->user->create( array( 'role' => 'administrator' ) );
$count = get_user_count(); // No change, cache not refreshed
$this->assertEquals( $start_count, $count );
@@ -240,8 +240,8 @@ class Tests_Multisite_Network extends WP_UnitTestCase {
$dashboard_blog = get_dashboard_blog();
$this->assertEquals( 1, $dashboard_blog->blog_id );
$user_id = $this->factory->user->create( array( 'role' => 'administrator' ) );
$blog_id = $this->factory->blog->create( array( 'user_id' => $user_id ) );
$user_id = self::$factory->user->create( array( 'role' => 'administrator' ) );
$blog_id = self::$factory->blog->create( array( 'user_id' => $user_id ) );
$this->assertInternalType( 'int', $blog_id );
// set the dashboard blog to another one