Split current tests for update_blog_status()
The current tests for `update_blog_status()` mirrored the tests for `update_blog_details()` in many ways and can be split in the same way. A noticeable difference is that the the matching actions fire even when no change is made to a field. See #30080 git-svn-id: https://develop.svn.wordpress.org/trunk@30785 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
7a8bceabaa
commit
a4c7261823
@ -571,188 +571,230 @@ class Tests_Multisite_Site extends WP_UnitTestCase {
|
|||||||
$this->assertEquals( $blog, wp_cache_get( $blog_id, 'blog-details' ) );
|
$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() {
|
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;
|
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;
|
$test_action_counter = 0;
|
||||||
$count = 1;
|
|
||||||
|
|
||||||
add_action( 'make_ham_blog', array( $this, '_action_counter_cb' ), 10, 1 );
|
$blog_id = $this->factory->blog->create();
|
||||||
$result = update_blog_status( $blog_id, 'spam', 0 );
|
update_blog_details( $blog_id, array( 'spam' => 1 ) );
|
||||||
$this->assertEquals( 0, $result );
|
|
||||||
|
add_action( 'make_ham_blog', array( $this, '_action_counter_cb' ), 10 );
|
||||||
|
update_blog_status( $blog_id, 'spam', 0 );
|
||||||
$blog = get_blog_details( $blog_id );
|
$blog = get_blog_details( $blog_id );
|
||||||
|
|
||||||
$this->assertEquals( '0', $blog->spam );
|
$this->assertEquals( '0', $blog->spam );
|
||||||
$this->assertEquals( $count, $test_action_counter );
|
$this->assertEquals( 1, $test_action_counter );
|
||||||
|
|
||||||
// Same again
|
// The action should fire if the status of 'spam' stays the same.
|
||||||
$count++;
|
update_blog_status( $blog_id, 'spam', 0 );
|
||||||
$result = update_blog_status( $blog_id, 'spam', 0 );
|
|
||||||
$this->assertEquals( 0, $result );
|
|
||||||
$blog = get_blog_details( $blog_id );
|
$blog = get_blog_details( $blog_id );
|
||||||
|
|
||||||
$this->assertEquals( '0', $blog->spam );
|
$this->assertEquals( '0', $blog->spam );
|
||||||
$this->assertEquals( $count, $test_action_counter );
|
$this->assertEquals( 2, $test_action_counter );
|
||||||
remove_action( 'make_ham_blog', array( $this, '_action_counter_cb' ), 10, 1 );
|
|
||||||
|
|
||||||
$count++;
|
remove_action( 'make_ham_blog', array( $this, '_action_counter_cb' ), 10 );
|
||||||
add_action( 'make_spam_blog', array( $this, '_action_counter_cb' ), 10, 1 );
|
}
|
||||||
$result = update_blog_status( $blog_id, 'spam', 1 );
|
|
||||||
$this->assertEquals( 1, $result );
|
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 );
|
$blog = get_blog_details( $blog_id );
|
||||||
|
|
||||||
$this->assertEquals( '1', $blog->spam );
|
$this->assertEquals( '1', $blog->spam );
|
||||||
$this->assertEquals( $count, $test_action_counter );
|
$this->assertEquals( 1, $test_action_counter );
|
||||||
|
|
||||||
// Same again
|
// The action should fire if the status of 'spam' stays the same.
|
||||||
$count++;
|
update_blog_status( $blog_id, 'spam', 1 );
|
||||||
$result = update_blog_status( $blog_id, 'spam', 1 );
|
|
||||||
$this->assertEquals( 1, $result );
|
|
||||||
$blog = get_blog_details( $blog_id );
|
$blog = get_blog_details( $blog_id );
|
||||||
|
|
||||||
$this->assertEquals( '1', $blog->spam );
|
$this->assertEquals( '1', $blog->spam );
|
||||||
$this->assertEquals( $count, $test_action_counter );
|
$this->assertEquals( 2, $test_action_counter );
|
||||||
remove_action( 'make_spam_blog', array( $this, '_action_counter_cb' ), 10, 1 );
|
|
||||||
|
|
||||||
add_action( 'archive_blog', array( $this, '_action_counter_cb' ), 10, 1 );
|
remove_action( 'make_spam_blog', array( $this, '_action_counter_cb' ), 10 );
|
||||||
$count++;
|
}
|
||||||
$result = update_blog_status( $blog_id, 'archived', 1 );
|
|
||||||
$this->assertEquals( 1, $result );
|
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 );
|
$blog = get_blog_details( $blog_id );
|
||||||
$this->assertEquals( '1', $blog->archived );
|
|
||||||
$this->assertEquals( $count, $test_action_counter );
|
|
||||||
|
|
||||||
// Same again
|
$this->assertEquals( '1', $blog->archived );
|
||||||
$count++;
|
$this->assertEquals( 1, $test_action_counter );
|
||||||
$result = update_blog_status( $blog_id, 'archived', 1 );
|
|
||||||
$this->assertEquals( 1, $result );
|
// 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 );
|
$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 );
|
$this->assertEquals( '1', $blog->archived );
|
||||||
$count++;
|
$this->assertEquals( 2, $test_action_counter );
|
||||||
$result = update_blog_status( $blog_id, 'archived', 0 );
|
|
||||||
$this->assertEquals( 0, $result );
|
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 );
|
$blog = get_blog_details( $blog_id );
|
||||||
$this->assertEquals( '0', $blog->archived );
|
$this->assertEquals( '0', $blog->archived );
|
||||||
$this->assertEquals( $count, $test_action_counter );
|
$this->assertEquals( 2, $test_action_counter );
|
||||||
|
|
||||||
// Same again
|
remove_action( 'unarchive_blog', array( $this, '_action_counter_cb' ), 10 );
|
||||||
$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 );
|
|
||||||
|
|
||||||
add_action( 'make_delete_blog', array( $this, '_action_counter_cb' ), 10, 1 );
|
function test_update_blog_status_make_delete_blog_action() {
|
||||||
$count++;
|
global $test_action_counter;
|
||||||
$result = update_blog_status( $blog_id, 'deleted', 1 );
|
$test_action_counter = 0;
|
||||||
$this->assertEquals( 1, $result );
|
|
||||||
|
$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 );
|
$blog = get_blog_details( $blog_id );
|
||||||
|
|
||||||
$this->assertEquals( '1', $blog->deleted );
|
$this->assertEquals( '1', $blog->deleted );
|
||||||
$this->assertEquals( $count, $test_action_counter );
|
$this->assertEquals( 1, $test_action_counter );
|
||||||
|
|
||||||
// Same again
|
// The action should fire if the status of 'deleted' stays the same.
|
||||||
$count++;
|
update_blog_status( $blog_id, 'deleted', 1 );
|
||||||
$result = update_blog_status( $blog_id, 'deleted', 1 );
|
|
||||||
$this->assertEquals( 1, $result );
|
|
||||||
$blog = get_blog_details( $blog_id );
|
$blog = get_blog_details( $blog_id );
|
||||||
|
|
||||||
$this->assertEquals( '1', $blog->deleted );
|
$this->assertEquals( '1', $blog->deleted );
|
||||||
$this->assertEquals( $count, $test_action_counter );
|
$this->assertEquals( 2, $test_action_counter );
|
||||||
remove_action( 'make_delete_blog', array( $this, '_action_counter_cb' ), 10, 1 );
|
|
||||||
|
|
||||||
add_action( 'make_undelete_blog', array( $this, '_action_counter_cb' ), 10, 1 );
|
remove_action( 'make_delete_blog', array( $this, '_action_counter_cb' ), 10 );
|
||||||
$count++;
|
}
|
||||||
$result = update_blog_status( $blog_id, 'deleted', 0 );
|
|
||||||
$this->assertEquals( 0, $result );
|
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 );
|
$blog = get_blog_details( $blog_id );
|
||||||
|
|
||||||
$this->assertEquals( '0', $blog->deleted );
|
$this->assertEquals( '0', $blog->deleted );
|
||||||
$this->assertEquals( $count, $test_action_counter );
|
$this->assertEquals( 1, $test_action_counter );
|
||||||
|
|
||||||
// Same again
|
// The action should fire if the status of 'deleted' stays the same.
|
||||||
$count++;
|
update_blog_status( $blog_id, 'deleted', 0 );
|
||||||
$result = update_blog_status( $blog_id, 'deleted', 0 );
|
|
||||||
$this->assertEquals( 0, $result );
|
|
||||||
$blog = get_blog_details( $blog_id );
|
$blog = get_blog_details( $blog_id );
|
||||||
|
|
||||||
$this->assertEquals( '0', $blog->deleted );
|
$this->assertEquals( '0', $blog->deleted );
|
||||||
$this->assertEquals( $count, $test_action_counter );
|
$this->assertEquals( 2, $test_action_counter );
|
||||||
remove_action( 'make_undelete_blog', array( $this, '_action_counter_cb' ), 10, 1 );
|
|
||||||
|
|
||||||
add_action( 'mature_blog', array( $this, '_action_counter_cb' ), 10, 1 );
|
remove_action( 'make_undelete_blog', array( $this, '_action_counter_cb' ), 10 );
|
||||||
$count++;
|
}
|
||||||
$result = update_blog_status( $blog_id, 'mature', 1 );
|
|
||||||
$this->assertEquals( 1, $result );
|
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 );
|
$blog = get_blog_details( $blog_id );
|
||||||
$this->assertEquals( '1', $blog->mature );
|
|
||||||
$this->assertEquals( $count, $test_action_counter );
|
|
||||||
|
|
||||||
// Same again
|
$this->assertEquals( '1', $blog->mature );
|
||||||
$count++;
|
$this->assertEquals( 1, $test_action_counter );
|
||||||
$result = update_blog_status( $blog_id, 'mature', 1 );
|
|
||||||
$this->assertEquals( 1, $result );
|
// 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 );
|
$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 );
|
$this->assertEquals( '1', $blog->mature );
|
||||||
$count++;
|
$this->assertEquals( 2, $test_action_counter );
|
||||||
$result = update_blog_status( $blog_id, 'mature', 0 );
|
|
||||||
$this->assertEquals( 0, $result );
|
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 );
|
$blog = get_blog_details( $blog_id );
|
||||||
$this->assertEquals( '0', $blog->mature );
|
$this->assertEquals( '0', $blog->mature );
|
||||||
$this->assertEquals( $count, $test_action_counter );
|
$this->assertEquals( 1, $test_action_counter );
|
||||||
|
|
||||||
// Same again
|
// The action should fire if the status of 'mature' stays the same.
|
||||||
$count++;
|
update_blog_status( $blog_id, 'mature', 0 );
|
||||||
$result = update_blog_status( $blog_id, 'mature', 0 );
|
|
||||||
$this->assertEquals( 0, $result );
|
|
||||||
$blog = get_blog_details( $blog_id );
|
$blog = get_blog_details( $blog_id );
|
||||||
|
|
||||||
$this->assertEquals( '0', $blog->mature );
|
$this->assertEquals( '0', $blog->mature );
|
||||||
$this->assertEquals( $count, $test_action_counter );
|
$this->assertEquals( 2, $test_action_counter );
|
||||||
remove_action( 'unmature_blog', array( $this, '_action_counter_cb' ), 10, 1 );
|
|
||||||
|
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 );
|
$blog = get_blog_details( $blog_id );
|
||||||
$this->assertEquals( '0', $blog->public );
|
$this->assertEquals( '0', $blog->public );
|
||||||
$this->assertEquals( $count, $test_action_counter );
|
$this->assertEquals( 1, $test_action_counter );
|
||||||
|
|
||||||
// Same again
|
// The action should fire if the status of 'mature' stays the same.
|
||||||
$count++;
|
update_blog_status( $blog_id, 'public', 0 );
|
||||||
$result = update_blog_status( $blog_id, 'public', 0 );
|
|
||||||
$this->assertEquals( 0, $result );
|
|
||||||
$blog = get_blog_details( $blog_id );
|
$blog = get_blog_details( $blog_id );
|
||||||
|
|
||||||
$this->assertEquals( '0', $blog->public );
|
$this->assertEquals( '0', $blog->public );
|
||||||
$this->assertEquals( $count, $test_action_counter );
|
$this->assertEquals( 2, $test_action_counter );
|
||||||
remove_action( 'update_blog_public', array( $this, '_action_counter_cb' ), 10, 1 );
|
|
||||||
|
|
||||||
add_action( 'update_blog_public', array( $this, '_action_counter_cb' ), 10, 1 );
|
remove_action( 'update_blog_public', array( $this, '_action_counter_cb' ), 10 );
|
||||||
$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 );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user