mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-02-18 06:42:44 +00:00
Tests: Remove a custom callback for checking action call count in multisite tests.
Use `MockAction::get_call_count()` instead, for consistency with the rest of the test suite. Follow-up to [24/tests], [99/tests], [1078/tests], [1089/tests], [29916], [30784], [30785], [33253]. See #56793. git-svn-id: https://develop.svn.wordpress.org/trunk@54756 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
79492c6204
commit
399bc757fc
@ -412,14 +412,6 @@ if ( is_multisite() ) :
|
||||
$this->assertEqualsWithDelta( $current_time, strtotime( $blog->last_updated ), 2, 'The dates should be equal' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide a counter to determine that hooks are firing when intended.
|
||||
*/
|
||||
public function action_counter_cb() {
|
||||
global $test_action_counter;
|
||||
$test_action_counter++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test cached data for a site that does not exist and then again after it exists.
|
||||
*
|
||||
@ -465,27 +457,24 @@ if ( is_multisite() ) :
|
||||
}
|
||||
|
||||
public function test_update_blog_status_make_ham_blog_action() {
|
||||
global $test_action_counter;
|
||||
$test_action_counter = 0;
|
||||
$test_action_counter = new MockAction();
|
||||
|
||||
$blog_id = self::factory()->blog->create();
|
||||
update_blog_details( $blog_id, array( 'spam' => 1 ) );
|
||||
|
||||
add_action( 'make_ham_blog', array( $this, 'action_counter_cb' ), 10 );
|
||||
add_action( 'make_ham_blog', array( $test_action_counter, 'action' ) );
|
||||
update_blog_status( $blog_id, 'spam', 0 );
|
||||
$blog = get_site( $blog_id );
|
||||
|
||||
$this->assertSame( '0', $blog->spam );
|
||||
$this->assertSame( 1, $test_action_counter );
|
||||
$this->assertSame( 1, $test_action_counter->get_call_count() );
|
||||
|
||||
// The action should not fire if the status of 'spam' stays the same.
|
||||
update_blog_status( $blog_id, 'spam', 0 );
|
||||
$blog = get_site( $blog_id );
|
||||
|
||||
$this->assertSame( '0', $blog->spam );
|
||||
$this->assertSame( 1, $test_action_counter );
|
||||
|
||||
remove_action( 'make_ham_blog', array( $this, 'action_counter_cb' ), 10 );
|
||||
$this->assertSame( 1, $test_action_counter->get_call_count() );
|
||||
}
|
||||
|
||||
public function test_content_from_spam_blog_is_not_available() {
|
||||
@ -519,189 +508,165 @@ if ( is_multisite() ) :
|
||||
}
|
||||
|
||||
public function test_update_blog_status_make_spam_blog_action() {
|
||||
global $test_action_counter;
|
||||
$test_action_counter = 0;
|
||||
$test_action_counter = new MockAction();
|
||||
|
||||
$blog_id = self::factory()->blog->create();
|
||||
|
||||
add_action( 'make_spam_blog', array( $this, 'action_counter_cb' ), 10 );
|
||||
add_action( 'make_spam_blog', array( $test_action_counter, 'action' ) );
|
||||
update_blog_status( $blog_id, 'spam', 1 );
|
||||
$blog = get_site( $blog_id );
|
||||
|
||||
$this->assertSame( '1', $blog->spam );
|
||||
$this->assertSame( 1, $test_action_counter );
|
||||
$this->assertSame( 1, $test_action_counter->get_call_count() );
|
||||
|
||||
// The action should not fire if the status of 'spam' stays the same.
|
||||
update_blog_status( $blog_id, 'spam', 1 );
|
||||
$blog = get_site( $blog_id );
|
||||
|
||||
$this->assertSame( '1', $blog->spam );
|
||||
$this->assertSame( 1, $test_action_counter );
|
||||
|
||||
remove_action( 'make_spam_blog', array( $this, 'action_counter_cb' ), 10 );
|
||||
$this->assertSame( 1, $test_action_counter->get_call_count() );
|
||||
}
|
||||
|
||||
public function test_update_blog_status_archive_blog_action() {
|
||||
global $test_action_counter;
|
||||
$test_action_counter = 0;
|
||||
$test_action_counter = new MockAction();
|
||||
|
||||
$blog_id = self::factory()->blog->create();
|
||||
|
||||
add_action( 'archive_blog', array( $this, 'action_counter_cb' ), 10 );
|
||||
add_action( 'archive_blog', array( $test_action_counter, 'action' ) );
|
||||
update_blog_status( $blog_id, 'archived', 1 );
|
||||
$blog = get_site( $blog_id );
|
||||
|
||||
$this->assertSame( '1', $blog->archived );
|
||||
$this->assertSame( 1, $test_action_counter );
|
||||
$this->assertSame( 1, $test_action_counter->get_call_count() );
|
||||
|
||||
// The action should not fire if the status of 'archived' stays the same.
|
||||
update_blog_status( $blog_id, 'archived', 1 );
|
||||
$blog = get_site( $blog_id );
|
||||
|
||||
$this->assertSame( '1', $blog->archived );
|
||||
$this->assertSame( 1, $test_action_counter );
|
||||
|
||||
remove_action( 'archive_blog', array( $this, 'action_counter_cb' ), 10 );
|
||||
$this->assertSame( 1, $test_action_counter->get_call_count() );
|
||||
}
|
||||
|
||||
public function test_update_blog_status_unarchive_blog_action() {
|
||||
global $test_action_counter;
|
||||
$test_action_counter = 0;
|
||||
$test_action_counter = new MockAction();
|
||||
|
||||
$blog_id = self::factory()->blog->create();
|
||||
update_blog_details( $blog_id, array( 'archived' => 1 ) );
|
||||
|
||||
add_action( 'unarchive_blog', array( $this, 'action_counter_cb' ), 10 );
|
||||
add_action( 'unarchive_blog', array( $test_action_counter, 'action' ) );
|
||||
update_blog_status( $blog_id, 'archived', 0 );
|
||||
$blog = get_site( $blog_id );
|
||||
|
||||
$this->assertSame( '0', $blog->archived );
|
||||
$this->assertSame( 1, $test_action_counter );
|
||||
$this->assertSame( 1, $test_action_counter->get_call_count() );
|
||||
|
||||
// The action should not fire if the status of 'archived' stays the same.
|
||||
update_blog_status( $blog_id, 'archived', 0 );
|
||||
$blog = get_site( $blog_id );
|
||||
$this->assertSame( '0', $blog->archived );
|
||||
$this->assertSame( 1, $test_action_counter );
|
||||
|
||||
remove_action( 'unarchive_blog', array( $this, 'action_counter_cb' ), 10 );
|
||||
$this->assertSame( 1, $test_action_counter->get_call_count() );
|
||||
}
|
||||
|
||||
public function test_update_blog_status_make_delete_blog_action() {
|
||||
global $test_action_counter;
|
||||
$test_action_counter = 0;
|
||||
$test_action_counter = new MockAction();
|
||||
|
||||
$blog_id = self::factory()->blog->create();
|
||||
|
||||
add_action( 'make_delete_blog', array( $this, 'action_counter_cb' ), 10 );
|
||||
add_action( 'make_delete_blog', array( $test_action_counter, 'action' ) );
|
||||
update_blog_status( $blog_id, 'deleted', 1 );
|
||||
$blog = get_site( $blog_id );
|
||||
|
||||
$this->assertSame( '1', $blog->deleted );
|
||||
$this->assertSame( 1, $test_action_counter );
|
||||
$this->assertSame( 1, $test_action_counter->get_call_count() );
|
||||
|
||||
// The action should not fire if the status of 'deleted' stays the same.
|
||||
update_blog_status( $blog_id, 'deleted', 1 );
|
||||
$blog = get_site( $blog_id );
|
||||
|
||||
$this->assertSame( '1', $blog->deleted );
|
||||
$this->assertSame( 1, $test_action_counter );
|
||||
|
||||
remove_action( 'make_delete_blog', array( $this, 'action_counter_cb' ), 10 );
|
||||
$this->assertSame( 1, $test_action_counter->get_call_count() );
|
||||
}
|
||||
|
||||
public function test_update_blog_status_make_undelete_blog_action() {
|
||||
global $test_action_counter;
|
||||
$test_action_counter = 0;
|
||||
$test_action_counter = new MockAction();
|
||||
|
||||
$blog_id = self::factory()->blog->create();
|
||||
update_blog_details( $blog_id, array( 'deleted' => 1 ) );
|
||||
|
||||
add_action( 'make_undelete_blog', array( $this, 'action_counter_cb' ), 10 );
|
||||
add_action( 'make_undelete_blog', array( $test_action_counter, 'action' ) );
|
||||
update_blog_status( $blog_id, 'deleted', 0 );
|
||||
$blog = get_site( $blog_id );
|
||||
|
||||
$this->assertSame( '0', $blog->deleted );
|
||||
$this->assertSame( 1, $test_action_counter );
|
||||
$this->assertSame( 1, $test_action_counter->get_call_count() );
|
||||
|
||||
// The action should not fire if the status of 'deleted' stays the same.
|
||||
update_blog_status( $blog_id, 'deleted', 0 );
|
||||
$blog = get_site( $blog_id );
|
||||
|
||||
$this->assertSame( '0', $blog->deleted );
|
||||
$this->assertSame( 1, $test_action_counter );
|
||||
|
||||
remove_action( 'make_undelete_blog', array( $this, 'action_counter_cb' ), 10 );
|
||||
$this->assertSame( 1, $test_action_counter->get_call_count() );
|
||||
}
|
||||
|
||||
public function test_update_blog_status_mature_blog_action() {
|
||||
global $test_action_counter;
|
||||
$test_action_counter = 0;
|
||||
$test_action_counter = new MockAction();
|
||||
|
||||
$blog_id = self::factory()->blog->create();
|
||||
|
||||
add_action( 'mature_blog', array( $this, 'action_counter_cb' ), 10 );
|
||||
add_action( 'mature_blog', array( $test_action_counter, 'action' ) );
|
||||
update_blog_status( $blog_id, 'mature', 1 );
|
||||
$blog = get_site( $blog_id );
|
||||
|
||||
$this->assertSame( '1', $blog->mature );
|
||||
$this->assertSame( 1, $test_action_counter );
|
||||
$this->assertSame( 1, $test_action_counter->get_call_count() );
|
||||
|
||||
// The action should not fire if the status of 'mature' stays the same.
|
||||
update_blog_status( $blog_id, 'mature', 1 );
|
||||
$blog = get_site( $blog_id );
|
||||
|
||||
$this->assertSame( '1', $blog->mature );
|
||||
$this->assertSame( 1, $test_action_counter );
|
||||
|
||||
remove_action( 'mature_blog', array( $this, 'action_counter_cb' ), 10 );
|
||||
$this->assertSame( 1, $test_action_counter->get_call_count() );
|
||||
}
|
||||
|
||||
public function test_update_blog_status_unmature_blog_action() {
|
||||
global $test_action_counter;
|
||||
$test_action_counter = 0;
|
||||
$test_action_counter = new MockAction();
|
||||
|
||||
$blog_id = self::factory()->blog->create();
|
||||
update_blog_details( $blog_id, array( 'mature' => 1 ) );
|
||||
|
||||
add_action( 'unmature_blog', array( $this, 'action_counter_cb' ), 10 );
|
||||
add_action( 'unmature_blog', array( $test_action_counter, 'action' ) );
|
||||
update_blog_status( $blog_id, 'mature', 0 );
|
||||
|
||||
$blog = get_site( $blog_id );
|
||||
$this->assertSame( '0', $blog->mature );
|
||||
$this->assertSame( 1, $test_action_counter );
|
||||
$this->assertSame( 1, $test_action_counter->get_call_count() );
|
||||
|
||||
// The action should not fire if the status of 'mature' stays the same.
|
||||
update_blog_status( $blog_id, 'mature', 0 );
|
||||
$blog = get_site( $blog_id );
|
||||
|
||||
$this->assertSame( '0', $blog->mature );
|
||||
$this->assertSame( 1, $test_action_counter );
|
||||
|
||||
remove_action( 'unmature_blog', array( $this, 'action_counter_cb' ), 10 );
|
||||
$this->assertSame( 1, $test_action_counter->get_call_count() );
|
||||
}
|
||||
|
||||
public function test_update_blog_status_update_blog_public_action() {
|
||||
global $test_action_counter;
|
||||
$test_action_counter = 0;
|
||||
$test_action_counter = new MockAction();
|
||||
|
||||
$blog_id = self::factory()->blog->create();
|
||||
|
||||
add_action( 'update_blog_public', array( $this, 'action_counter_cb' ), 10 );
|
||||
add_action( 'update_blog_public', array( $test_action_counter, 'action' ) );
|
||||
update_blog_status( $blog_id, 'public', 0 );
|
||||
|
||||
$blog = get_site( $blog_id );
|
||||
$this->assertSame( '0', $blog->public );
|
||||
$this->assertSame( 1, $test_action_counter );
|
||||
$this->assertSame( 1, $test_action_counter->get_call_count() );
|
||||
|
||||
// The action should not fire if the status of 'mature' stays the same.
|
||||
update_blog_status( $blog_id, 'public', 0 );
|
||||
$blog = get_site( $blog_id );
|
||||
|
||||
$this->assertSame( '0', $blog->public );
|
||||
$this->assertSame( 1, $test_action_counter );
|
||||
|
||||
remove_action( 'update_blog_public', array( $this, 'action_counter_cb' ), 10 );
|
||||
$this->assertSame( 1, $test_action_counter->get_call_count() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -56,8 +56,7 @@ if ( is_multisite() ) :
|
||||
* @dataProvider data_flag_hooks
|
||||
*/
|
||||
public function test_update_blog_details_flag_action( $flag, $flag_value, $hook ) {
|
||||
global $test_action_counter;
|
||||
$test_action_counter = 0;
|
||||
$test_action_counter = new MockAction();
|
||||
|
||||
$blog_id = self::factory()->blog->create();
|
||||
|
||||
@ -66,7 +65,7 @@ if ( is_multisite() ) :
|
||||
update_blog_details( $blog_id, array( $flag => '1' ) );
|
||||
}
|
||||
|
||||
add_action( $hook, array( $this, 'action_counter_cb' ), 10 );
|
||||
add_action( $hook, array( $test_action_counter, 'action' ) );
|
||||
|
||||
update_blog_details( $blog_id, array( $flag => $flag_value ) );
|
||||
$blog = get_site( $blog_id );
|
||||
@ -74,15 +73,13 @@ if ( is_multisite() ) :
|
||||
$this->assertSame( $flag_value, $blog->{$flag} );
|
||||
|
||||
// The hook attached to this flag should have fired once during update_blog_details().
|
||||
$this->assertSame( 1, $test_action_counter );
|
||||
$this->assertSame( 1, $test_action_counter->get_call_count() );
|
||||
|
||||
// Update the site to the exact same flag value for this flag.
|
||||
update_blog_details( $blog_id, array( $flag => $flag_value ) );
|
||||
|
||||
// The hook attached to this flag should not have fired again.
|
||||
$this->assertSame( 1, $test_action_counter );
|
||||
|
||||
remove_action( $hook, array( $this, 'action_counter_cb' ), 10 );
|
||||
$this->assertSame( 1, $test_action_counter->get_call_count() );
|
||||
}
|
||||
|
||||
public function data_flag_hooks() {
|
||||
@ -98,14 +95,6 @@ if ( is_multisite() ) :
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide a counter to determine that hooks are firing when intended.
|
||||
*/
|
||||
public function action_counter_cb() {
|
||||
global $test_action_counter;
|
||||
$test_action_counter++;
|
||||
}
|
||||
|
||||
/**
|
||||
* When the path for a site is updated with update_blog_details(), the final path
|
||||
* should have a leading and trailing slash.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user