diff --git a/tests/phpunit/tests/multisite/site.php b/tests/phpunit/tests/multisite/site.php index 99aa2108f6..38ac177863 100644 --- a/tests/phpunit/tests/multisite/site.php +++ b/tests/phpunit/tests/multisite/site.php @@ -571,188 +571,230 @@ class Tests_Multisite_Site extends WP_UnitTestCase { $this->assertEquals( $blog, wp_cache_get( $blog_id, 'blog-details' ) ); } + /** + * Updating a field returns the sme value that was passed. + */ function test_update_blog_status() { + $result = update_blog_status( 1, 'spam', 0 ); + $this->assertEquals( 0, $result ); + } + + /** + * Updating an invalid field returns the same value that was passed. + */ + function test_update_blog_status_invalid_status() { + $result = update_blog_status( 1, 'doesnotexist', 'invalid' ); + $this->assertEquals( 'invalid', $result ); + } + + function test_update_blog_status_make_ham_blog_action() { global $test_action_counter; - - $user_id = $this->factory->user->create( array( 'role' => 'administrator' ) ); - $blog_id = $this->factory->blog->create( array( 'user_id' => $user_id, 'path' => '/test_blogpath', 'title' => 'Test Title' ) ); - $this->assertInternalType( 'int', $blog_id ); - $test_action_counter = 0; - $count = 1; - add_action( 'make_ham_blog', array( $this, '_action_counter_cb' ), 10, 1 ); - $result = update_blog_status( $blog_id, 'spam', 0 ); - $this->assertEquals( 0, $result ); + $blog_id = $this->factory->blog->create(); + update_blog_details( $blog_id, array( 'spam' => 1 ) ); + + add_action( 'make_ham_blog', array( $this, '_action_counter_cb' ), 10 ); + update_blog_status( $blog_id, 'spam', 0 ); $blog = get_blog_details( $blog_id ); + $this->assertEquals( '0', $blog->spam ); - $this->assertEquals( $count, $test_action_counter ); + $this->assertEquals( 1, $test_action_counter ); - // Same again - $count++; - $result = update_blog_status( $blog_id, 'spam', 0 ); - $this->assertEquals( 0, $result ); + // The action should fire if the status of 'spam' stays the same. + update_blog_status( $blog_id, 'spam', 0 ); $blog = get_blog_details( $blog_id ); + $this->assertEquals( '0', $blog->spam ); - $this->assertEquals( $count, $test_action_counter ); - remove_action( 'make_ham_blog', array( $this, '_action_counter_cb' ), 10, 1 ); + $this->assertEquals( 2, $test_action_counter ); - $count++; - add_action( 'make_spam_blog', array( $this, '_action_counter_cb' ), 10, 1 ); - $result = update_blog_status( $blog_id, 'spam', 1 ); - $this->assertEquals( 1, $result ); + remove_action( 'make_ham_blog', array( $this, '_action_counter_cb' ), 10 ); + } + + function test_update_blog_status_make_spam_blog_action() { + global $test_action_counter; + $test_action_counter = 0; + + $blog_id = $this->factory->blog->create(); + + add_action( 'make_spam_blog', array( $this, '_action_counter_cb' ), 10 ); + update_blog_status( $blog_id, 'spam', 1 ); $blog = get_blog_details( $blog_id ); + $this->assertEquals( '1', $blog->spam ); - $this->assertEquals( $count, $test_action_counter ); + $this->assertEquals( 1, $test_action_counter ); - // Same again - $count++; - $result = update_blog_status( $blog_id, 'spam', 1 ); - $this->assertEquals( 1, $result ); + // The action should fire if the status of 'spam' stays the same. + update_blog_status( $blog_id, 'spam', 1 ); $blog = get_blog_details( $blog_id ); + $this->assertEquals( '1', $blog->spam ); - $this->assertEquals( $count, $test_action_counter ); - remove_action( 'make_spam_blog', array( $this, '_action_counter_cb' ), 10, 1 ); + $this->assertEquals( 2, $test_action_counter ); - add_action( 'archive_blog', array( $this, '_action_counter_cb' ), 10, 1 ); - $count++; - $result = update_blog_status( $blog_id, 'archived', 1 ); - $this->assertEquals( 1, $result ); + remove_action( 'make_spam_blog', array( $this, '_action_counter_cb' ), 10 ); + } + + function test_update_blog_status_archive_blog_action() { + global $test_action_counter; + $test_action_counter = 0; + + $blog_id = $this->factory->blog->create(); + + add_action( 'archive_blog', array( $this, '_action_counter_cb' ), 10 ); + update_blog_status( $blog_id, 'archived', 1 ); $blog = get_blog_details( $blog_id ); - $this->assertEquals( '1', $blog->archived ); - $this->assertEquals( $count, $test_action_counter ); - // Same again - $count++; - $result = update_blog_status( $blog_id, 'archived', 1 ); - $this->assertEquals( 1, $result ); + $this->assertEquals( '1', $blog->archived ); + $this->assertEquals( 1, $test_action_counter ); + + // The action should fire if the status of 'archived' stays the same. + update_blog_status( $blog_id, 'archived', 1 ); $blog = get_blog_details( $blog_id ); - $this->assertEquals( '1', $blog->archived ); - $this->assertEquals( $count, $test_action_counter ); - remove_action( 'archive_blog', array( $this, '_action_counter_cb' ), 10, 1 ); - add_action( 'unarchive_blog', array( $this, '_action_counter_cb' ), 10, 1 ); - $count++; - $result = update_blog_status( $blog_id, 'archived', 0 ); - $this->assertEquals( 0, $result ); + $this->assertEquals( '1', $blog->archived ); + $this->assertEquals( 2, $test_action_counter ); + + remove_action( 'archive_blog', array( $this, '_action_counter_cb' ), 10 ); + } + + function test_update_blog_status_unarchive_blog_action() { + global $test_action_counter; + $test_action_counter = 0; + + $blog_id = $this->factory->blog->create(); + update_blog_details( $blog_id, array( 'archived' => 1 ) ); + + add_action( 'unarchive_blog', array( $this, '_action_counter_cb' ), 10 ); + update_blog_status( $blog_id, 'archived', 0 ); + $blog = get_blog_details( $blog_id ); + + $this->assertEquals( '0', $blog->archived ); + $this->assertEquals( 1, $test_action_counter ); + + // The action should fire if the status of 'archived' stays the same. + update_blog_status( $blog_id, 'archived', 0 ); $blog = get_blog_details( $blog_id ); $this->assertEquals( '0', $blog->archived ); - $this->assertEquals( $count, $test_action_counter ); + $this->assertEquals( 2, $test_action_counter ); - // Same again - $result = update_blog_status( $blog_id, 'archived', 0 ); - $count++; - $this->assertEquals( 0, $result ); - $blog = get_blog_details( $blog_id ); - $this->assertEquals( '0', $blog->archived ); - $this->assertEquals( $count, $test_action_counter ); - remove_action( 'unarchive_blog', array( $this, '_action_counter_cb' ), 10, 1 ); + remove_action( 'unarchive_blog', array( $this, '_action_counter_cb' ), 10 ); + } - add_action( 'make_delete_blog', array( $this, '_action_counter_cb' ), 10, 1 ); - $count++; - $result = update_blog_status( $blog_id, 'deleted', 1 ); - $this->assertEquals( 1, $result ); + function test_update_blog_status_make_delete_blog_action() { + global $test_action_counter; + $test_action_counter = 0; + + $blog_id = $this->factory->blog->create(); + + add_action( 'make_delete_blog', array( $this, '_action_counter_cb' ), 10 ); + update_blog_status( $blog_id, 'deleted', 1 ); $blog = get_blog_details( $blog_id ); + $this->assertEquals( '1', $blog->deleted ); - $this->assertEquals( $count, $test_action_counter ); + $this->assertEquals( 1, $test_action_counter ); - // Same again - $count++; - $result = update_blog_status( $blog_id, 'deleted', 1 ); - $this->assertEquals( 1, $result ); + // The action should fire if the status of 'deleted' stays the same. + update_blog_status( $blog_id, 'deleted', 1 ); $blog = get_blog_details( $blog_id ); + $this->assertEquals( '1', $blog->deleted ); - $this->assertEquals( $count, $test_action_counter ); - remove_action( 'make_delete_blog', array( $this, '_action_counter_cb' ), 10, 1 ); + $this->assertEquals( 2, $test_action_counter ); - add_action( 'make_undelete_blog', array( $this, '_action_counter_cb' ), 10, 1 ); - $count++; - $result = update_blog_status( $blog_id, 'deleted', 0 ); - $this->assertEquals( 0, $result ); + remove_action( 'make_delete_blog', array( $this, '_action_counter_cb' ), 10 ); + } + + function test_update_blog_status_make_undelete_blog_action() { + global $test_action_counter; + $test_action_counter = 0; + + $blog_id = $this->factory->blog->create(); + update_blog_details( $blog_id, array( 'deleted' => 1 ) ); + + add_action( 'make_undelete_blog', array( $this, '_action_counter_cb' ), 10 ); + update_blog_status( $blog_id, 'deleted', 0 ); $blog = get_blog_details( $blog_id ); + $this->assertEquals( '0', $blog->deleted ); - $this->assertEquals( $count, $test_action_counter ); + $this->assertEquals( 1, $test_action_counter ); - // Same again - $count++; - $result = update_blog_status( $blog_id, 'deleted', 0 ); - $this->assertEquals( 0, $result ); + // The action should fire if the status of 'deleted' stays the same. + update_blog_status( $blog_id, 'deleted', 0 ); $blog = get_blog_details( $blog_id ); + $this->assertEquals( '0', $blog->deleted ); - $this->assertEquals( $count, $test_action_counter ); - remove_action( 'make_undelete_blog', array( $this, '_action_counter_cb' ), 10, 1 ); + $this->assertEquals( 2, $test_action_counter ); - add_action( 'mature_blog', array( $this, '_action_counter_cb' ), 10, 1 ); - $count++; - $result = update_blog_status( $blog_id, 'mature', 1 ); - $this->assertEquals( 1, $result ); + remove_action( 'make_undelete_blog', array( $this, '_action_counter_cb' ), 10 ); + } + + function test_update_blog_status_mature_blog_action() { + global $test_action_counter; + $test_action_counter = 0; + + $blog_id = $this->factory->blog->create(); + + add_action( 'mature_blog', array( $this, '_action_counter_cb' ), 10 ); + update_blog_status( $blog_id, 'mature', 1 ); $blog = get_blog_details( $blog_id ); - $this->assertEquals( '1', $blog->mature ); - $this->assertEquals( $count, $test_action_counter ); - // Same again - $count++; - $result = update_blog_status( $blog_id, 'mature', 1 ); - $this->assertEquals( 1, $result ); + $this->assertEquals( '1', $blog->mature ); + $this->assertEquals( 1, $test_action_counter ); + + // The action should fire if the status of 'mature' stays the same. + update_blog_status( $blog_id, 'mature', 1 ); $blog = get_blog_details( $blog_id ); - $this->assertEquals( '1', $blog->mature ); - $this->assertEquals( $count, $test_action_counter ); - remove_action( 'mature_blog', array( $this, '_action_counter_cb' ), 10, 1 ); - add_action( 'unmature_blog', array( $this, '_action_counter_cb' ), 10, 1 ); - $count++; - $result = update_blog_status( $blog_id, 'mature', 0 ); - $this->assertEquals( 0, $result ); + $this->assertEquals( '1', $blog->mature ); + $this->assertEquals( 2, $test_action_counter ); + + remove_action( 'mature_blog', array( $this, '_action_counter_cb' ), 10 ); + } + + function test_update_blog_status_unmature_blog_action() { + global $test_action_counter; + $test_action_counter = 0; + + $blog_id = $this->factory->blog->create(); + update_blog_details( $blog_id, array( 'mature' => 1 ) ); + + add_action( 'unmature_blog', array( $this, '_action_counter_cb' ), 10 ); + update_blog_status( $blog_id, 'mature', 0 ); + $blog = get_blog_details( $blog_id ); $this->assertEquals( '0', $blog->mature ); - $this->assertEquals( $count, $test_action_counter ); + $this->assertEquals( 1, $test_action_counter ); - // Same again - $count++; - $result = update_blog_status( $blog_id, 'mature', 0 ); - $this->assertEquals( 0, $result ); + // The action should fire if the status of 'mature' stays the same. + update_blog_status( $blog_id, 'mature', 0 ); $blog = get_blog_details( $blog_id ); + $this->assertEquals( '0', $blog->mature ); - $this->assertEquals( $count, $test_action_counter ); - remove_action( 'unmature_blog', array( $this, '_action_counter_cb' ), 10, 1 ); + $this->assertEquals( 2, $test_action_counter ); + + remove_action( 'unmature_blog', array( $this, '_action_counter_cb' ), 10 ); + } + + function test_update_blog_status_update_blog_public_action() { + global $test_action_counter; + $test_action_counter = 0; + + $blog_id = $this->factory->blog->create(); + + add_action( 'update_blog_public', array( $this, '_action_counter_cb' ), 10 ); + update_blog_status( $blog_id, 'public', 0 ); - add_action( 'update_blog_public', array( $this, '_action_counter_cb' ), 10, 1 ); - $count++; - $result = update_blog_status( $blog_id, 'public', 0 ); - $this->assertEquals( 0, $result ); $blog = get_blog_details( $blog_id ); $this->assertEquals( '0', $blog->public ); - $this->assertEquals( $count, $test_action_counter ); + $this->assertEquals( 1, $test_action_counter ); - // Same again - $count++; - $result = update_blog_status( $blog_id, 'public', 0 ); - $this->assertEquals( 0, $result ); + // The action should fire if the status of 'mature' stays the same. + update_blog_status( $blog_id, 'public', 0 ); $blog = get_blog_details( $blog_id ); + $this->assertEquals( '0', $blog->public ); - $this->assertEquals( $count, $test_action_counter ); - remove_action( 'update_blog_public', array( $this, '_action_counter_cb' ), 10, 1 ); + $this->assertEquals( 2, $test_action_counter ); - add_action( 'update_blog_public', array( $this, '_action_counter_cb' ), 10, 1 ); - $count++; - $result = update_blog_status( $blog_id, 'public', 1 ); - $this->assertEquals( 1, $result ); - $blog = get_blog_details( $blog_id ); - $this->assertEquals( '1', $blog->public ); - $this->assertEquals( $count, $test_action_counter ); - - // Same again - $count++; - $result = update_blog_status( $blog_id, 'public', 1 ); - $this->assertEquals( 1, $result ); - $blog = get_blog_details( $blog_id ); - $this->assertEquals( '1', $blog->public ); - $this->assertEquals( $count, $test_action_counter ); - remove_action( 'update_blog_public', array( $this, '_action_counter_cb' ), 10, 1 ); - - // Updating a dummy field returns the value passed. Go fig. - $result = update_blog_status( $blog_id, 'doesnotexist', 1 ); - $this->assertEquals( 1, $result ); + remove_action( 'update_blog_public', array( $this, '_action_counter_cb' ), 10 ); } /**