From e3e828c60833f9e5e9e04a4c9bb3e41ddc3c0aaf Mon Sep 17 00:00:00 2001 From: Jeremy Felt Date: Tue, 14 Jul 2015 05:49:28 +0000 Subject: [PATCH] Tests: Move `update_blog_details()` tests to their own file. Reduce some of the clutter in `tests/multisite/site.php` and introduce `tests/multisite/updateBlogDetails.php`. Tests moved over are verbatum at this point. See #32988. git-svn-id: https://develop.svn.wordpress.org/trunk@33253 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/multisite/site.php | 295 ---------------- .../tests/multisite/updateBlogDetails.php | 314 ++++++++++++++++++ 2 files changed, 314 insertions(+), 295 deletions(-) create mode 100644 tests/phpunit/tests/multisite/updateBlogDetails.php diff --git a/tests/phpunit/tests/multisite/site.php b/tests/phpunit/tests/multisite/site.php index 0c124d4554..4e5298d43d 100644 --- a/tests/phpunit/tests/multisite/site.php +++ b/tests/phpunit/tests/multisite/site.php @@ -316,224 +316,6 @@ class Tests_Multisite_Site extends WP_UnitTestCase { $this->assertLessThan( 2, $time_difference ); } - /** - * If `update_blog_details()` is called with any kind of empty arguments, it - * should return false. - */ - function test_update_blog_details_with_empty_args() { - $result = update_blog_details( 1, array() ); - $this->assertFalse( $result ); - } - - /** - * If the ID passed is not that of a current site, we should expect false. - */ - function test_update_blog_details_invalid_blog_id() { - $result = update_blog_details( 999, array( 'domain' => 'example.com' ) ); - $this->assertFalse( $result ); - } - - function test_update_blog_details() { - $blog_id = $this->factory->blog->create(); - - $result = update_blog_details( $blog_id, array( 'domain' => 'example.com', 'path' => 'my_path/' ) ); - - $this->assertTrue( $result ); - - $blog = get_blog_details( $blog_id ); - - $this->assertEquals( 'example.com', $blog->domain ); - $this->assertEquals( '/my_path/', $blog->path ); - $this->assertEquals( '0', $blog->spam ); - } - - function test_update_blog_details_make_ham_blog_action() { - global $test_action_counter; - $test_action_counter = 0; - - $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_details( $blog_id, array( 'spam' => 0 ) ); - $blog = get_blog_details( $blog_id ); - - $this->assertEquals( '0', $blog->spam ); - $this->assertEquals( 1, $test_action_counter ); - - // The action should not fire if the status of 'spam' stays the same. - update_blog_details( $blog_id, array( 'spam' => 0 ) ); - $blog = get_blog_details( $blog_id ); - - $this->assertEquals( '0', $blog->spam ); - $this->assertEquals( 1, $test_action_counter ); - - remove_action( 'make_ham_blog', array( $this, '_action_counter_cb' ), 10 ); - } - - function test_update_blog_details_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_details( $blog_id, array( 'spam' => 1 ) ); - $blog = get_blog_details( $blog_id ); - - $this->assertEquals( '1', $blog->spam ); - $this->assertEquals( 1, $test_action_counter ); - - // The action should not fire if the status of 'spam' stays the same. - update_blog_details( $blog_id, array( 'spam' => 1 ) ); - $blog = get_blog_details( $blog_id ); - - $this->assertEquals( '1', $blog->spam ); - $this->assertEquals( 1, $test_action_counter ); - - remove_action( 'make_spam_blog', array( $this, '_action_counter_cb' ), 10 ); - } - - function test_update_blog_details_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_details( $blog_id, array( 'archived' => 1 ) ); - $blog = get_blog_details( $blog_id ); - - $this->assertEquals( '1', $blog->archived ); - $this->assertEquals( 1, $test_action_counter ); - - // The action should not fire if the status of 'archived' stays the same. - update_blog_details( $blog_id, array( 'archived' => 1 ) ); - $blog = get_blog_details( $blog_id ); - - $this->assertEquals( '1', $blog->archived ); - $this->assertEquals( 1, $test_action_counter ); - - remove_action( 'archive_blog', array( $this, '_action_counter_cb' ), 10 ); - } - - function test_update_blog_details_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_details( $blog_id, array( 'archived' => 0 ) ); - $blog = get_blog_details( $blog_id ); - - $this->assertEquals( '0', $blog->archived ); - $this->assertEquals( 1, $test_action_counter ); - - // The action should not fire if the status of 'archived' stays the same. - update_blog_details( $blog_id, array( 'archived' => 0 ) ); - $blog = get_blog_details( $blog_id ); - $this->assertEquals( '0', $blog->archived ); - $this->assertEquals( 1, $test_action_counter ); - - remove_action( 'unarchive_blog', array( $this, '_action_counter_cb' ), 10 ); - } - - function test_update_blog_details_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_details( $blog_id, array( 'deleted' => 1 ) ); - $blog = get_blog_details( $blog_id ); - - $this->assertEquals( '1', $blog->deleted ); - $this->assertEquals( 1, $test_action_counter ); - - // The action should not fire if the status of 'deleted' stays the same. - update_blog_details( $blog_id, array( 'deleted' => 1 ) ); - $blog = get_blog_details( $blog_id ); - - $this->assertEquals( '1', $blog->deleted ); - $this->assertEquals( 1, $test_action_counter ); - - remove_action( 'make_delete_blog', array( $this, '_action_counter_cb' ), 10 ); - } - - function test_update_blog_details_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_details( $blog_id, array( 'deleted' => 0 ) ); - $blog = get_blog_details( $blog_id ); - - $this->assertEquals( '0', $blog->deleted ); - $this->assertEquals( 1, $test_action_counter ); - - // The action should not fire if the status of 'deleted' stays the same. - update_blog_details( $blog_id, array( 'deleted' => 0 ) ); - $blog = get_blog_details( $blog_id ); - - $this->assertEquals( '0', $blog->deleted ); - $this->assertEquals( 1, $test_action_counter ); - - remove_action( 'make_undelete_blog', array( $this, '_action_counter_cb' ), 10 ); - } - - function test_update_blog_details_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_details( $blog_id, array( 'mature' => 1 ) ); - $blog = get_blog_details( $blog_id ); - - $this->assertEquals( '1', $blog->mature ); - $this->assertEquals( 1, $test_action_counter ); - - // The action should not fire if the status of 'mature' stays the same. - update_blog_details( $blog_id, array( 'mature' => 1 ) ); - $blog = get_blog_details( $blog_id ); - - $this->assertEquals( '1', $blog->mature ); - $this->assertEquals( 1, $test_action_counter ); - - remove_action( 'mature_blog', array( $this, '_action_counter_cb' ), 10 ); - } - - function test_update_blog_details_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_details( $blog_id, array( 'mature' => 0 ) ); - - $blog = get_blog_details( $blog_id ); - $this->assertEquals( '0', $blog->mature ); - $this->assertEquals( 1, $test_action_counter ); - - // The action should not fire if the status of 'mature' stays the same. - update_blog_details( $blog_id, array( 'mature' => 0 ) ); - $blog = get_blog_details( $blog_id ); - - $this->assertEquals( '0', $blog->mature ); - $this->assertEquals( 1, $test_action_counter ); - - remove_action( 'unmature_blog', array( $this, '_action_counter_cb' ), 10 ); - } - /** * Provide a counter to determine that hooks are firing when intended. */ @@ -542,83 +324,6 @@ class Tests_Multisite_Site extends WP_UnitTestCase { $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. When multiple directories - * are part of the path, only one slash should separate each directory. - * - * @ticket 18117 - */ - function test_update_blog_details_single_path_no_slashes() { - update_blog_details( 1, array( 'path' => 'my_path' ) ); - $blog = get_blog_details( 1 ); - $this->assertEquals( '/my_path/', $blog->path ); - } - - function test_update_blog_details_single_path_double_trailing_slashes() { - update_blog_details( 1, array( 'path' => 'my_path//' ) ); - $blog = get_blog_details( 1 ); - $this->assertEquals( '/my_path/', $blog->path ); - } - - function test_update_blog_details_single_path_double_leading_slashes() { - update_blog_details( 1, array( 'path' => '//my_path' ) ); - $blog = get_blog_details( 1 ); - $this->assertEquals( '/my_path/', $blog->path ); - } - - function test_update_blog_details_single_path_single_trailing_slash() { - update_blog_details( 1, array( 'path' => 'my_path/' ) ); - $blog = get_blog_details( 1 ); - $this->assertEquals( '/my_path/', $blog->path ); - } - - function test_update_blog_details_single_path_single_leading_slashes() { - update_blog_details( 1, array( 'path' => '/my_path' ) ); - $blog = get_blog_details( 1 ); - $this->assertEquals( '/my_path/', $blog->path ); - } - - function test_update_blog_details_single_path_both_slashes() { - update_blog_details( 1, array( 'path' => '/my_path/' ) ); - $blog = get_blog_details( 1 ); - $this->assertEquals( '/my_path/', $blog->path ); - } - - function test_update_blog_details_multiple_paths_no_slashes() { - update_blog_details( 1, array( 'path' => 'multiple/dirs' ) ); - $blog = get_blog_details( 1 ); - $this->assertEquals( '/multiple/dirs/', $blog->path ); - } - - /** - * `update_blog_details()` does not resolve multiple slashes in the - * middle of a path string. - */ - function test_update_blog_details_multiple_paths_middle_slashes() { - update_blog_details( 1, array( 'path' => 'multiple///dirs' ) ); - $blog = get_blog_details( 1 ); - $this->assertEquals( '/multiple///dirs/', $blog->path ); - } - - function test_update_blog_details_multiple_paths_leading_slash() { - update_blog_details( 1, array( 'path' => '/multiple/dirs' ) ); - $blog = get_blog_details( 1 ); - $this->assertEquals( '/multiple/dirs/', $blog->path ); - } - - function test_update_blog_details_multiple_paths_trailing_slash() { - update_blog_details( 1, array( 'path' => 'multiple/dirs/' ) ); - $blog = get_blog_details( 1 ); - $this->assertEquals( '/multiple/dirs/', $blog->path ); - } - - function test_update_blog_details_multiple_paths_both_slashes() { - update_blog_details( 1, array( 'path' => '/multiple/dirs/' ) ); - $blog = get_blog_details( 1 ); - $this->assertEquals( '/multiple/dirs/', $blog->path ); - } - /** * Test cached data for a site that does not exist and then again after it exists. * diff --git a/tests/phpunit/tests/multisite/updateBlogDetails.php b/tests/phpunit/tests/multisite/updateBlogDetails.php new file mode 100644 index 0000000000..4e5c40e349 --- /dev/null +++ b/tests/phpunit/tests/multisite/updateBlogDetails.php @@ -0,0 +1,314 @@ +assertFalse( $result ); + } + + /** + * If the ID passed is not that of a current site, we should expect false. + */ + function test_update_blog_details_invalid_blog_id() { + $result = update_blog_details( 999, array( 'domain' => 'example.com' ) ); + $this->assertFalse( $result ); + } + + function test_update_blog_details() { + $blog_id = $this->factory->blog->create(); + + $result = update_blog_details( $blog_id, array( 'domain' => 'example.com', 'path' => 'my_path/' ) ); + + $this->assertTrue( $result ); + + $blog = get_blog_details( $blog_id ); + + $this->assertEquals( 'example.com', $blog->domain ); + $this->assertEquals( '/my_path/', $blog->path ); + $this->assertEquals( '0', $blog->spam ); + } + + function test_update_blog_details_make_ham_blog_action() { + global $test_action_counter; + $test_action_counter = 0; + + $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_details( $blog_id, array( 'spam' => 0 ) ); + $blog = get_blog_details( $blog_id ); + + $this->assertEquals( '0', $blog->spam ); + $this->assertEquals( 1, $test_action_counter ); + + // The action should not fire if the status of 'spam' stays the same. + update_blog_details( $blog_id, array( 'spam' => 0 ) ); + $blog = get_blog_details( $blog_id ); + + $this->assertEquals( '0', $blog->spam ); + $this->assertEquals( 1, $test_action_counter ); + + remove_action( 'make_ham_blog', array( $this, '_action_counter_cb' ), 10 ); + } + + function test_update_blog_details_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_details( $blog_id, array( 'spam' => 1 ) ); + $blog = get_blog_details( $blog_id ); + + $this->assertEquals( '1', $blog->spam ); + $this->assertEquals( 1, $test_action_counter ); + + // The action should not fire if the status of 'spam' stays the same. + update_blog_details( $blog_id, array( 'spam' => 1 ) ); + $blog = get_blog_details( $blog_id ); + + $this->assertEquals( '1', $blog->spam ); + $this->assertEquals( 1, $test_action_counter ); + + remove_action( 'make_spam_blog', array( $this, '_action_counter_cb' ), 10 ); + } + + function test_update_blog_details_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_details( $blog_id, array( 'archived' => 1 ) ); + $blog = get_blog_details( $blog_id ); + + $this->assertEquals( '1', $blog->archived ); + $this->assertEquals( 1, $test_action_counter ); + + // The action should not fire if the status of 'archived' stays the same. + update_blog_details( $blog_id, array( 'archived' => 1 ) ); + $blog = get_blog_details( $blog_id ); + + $this->assertEquals( '1', $blog->archived ); + $this->assertEquals( 1, $test_action_counter ); + + remove_action( 'archive_blog', array( $this, '_action_counter_cb' ), 10 ); + } + + function test_update_blog_details_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_details( $blog_id, array( 'archived' => 0 ) ); + $blog = get_blog_details( $blog_id ); + + $this->assertEquals( '0', $blog->archived ); + $this->assertEquals( 1, $test_action_counter ); + + // The action should not fire if the status of 'archived' stays the same. + update_blog_details( $blog_id, array( 'archived' => 0 ) ); + $blog = get_blog_details( $blog_id ); + $this->assertEquals( '0', $blog->archived ); + $this->assertEquals( 1, $test_action_counter ); + + remove_action( 'unarchive_blog', array( $this, '_action_counter_cb' ), 10 ); + } + + function test_update_blog_details_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_details( $blog_id, array( 'deleted' => 1 ) ); + $blog = get_blog_details( $blog_id ); + + $this->assertEquals( '1', $blog->deleted ); + $this->assertEquals( 1, $test_action_counter ); + + // The action should not fire if the status of 'deleted' stays the same. + update_blog_details( $blog_id, array( 'deleted' => 1 ) ); + $blog = get_blog_details( $blog_id ); + + $this->assertEquals( '1', $blog->deleted ); + $this->assertEquals( 1, $test_action_counter ); + + remove_action( 'make_delete_blog', array( $this, '_action_counter_cb' ), 10 ); + } + + function test_update_blog_details_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_details( $blog_id, array( 'deleted' => 0 ) ); + $blog = get_blog_details( $blog_id ); + + $this->assertEquals( '0', $blog->deleted ); + $this->assertEquals( 1, $test_action_counter ); + + // The action should not fire if the status of 'deleted' stays the same. + update_blog_details( $blog_id, array( 'deleted' => 0 ) ); + $blog = get_blog_details( $blog_id ); + + $this->assertEquals( '0', $blog->deleted ); + $this->assertEquals( 1, $test_action_counter ); + + remove_action( 'make_undelete_blog', array( $this, '_action_counter_cb' ), 10 ); + } + + function test_update_blog_details_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_details( $blog_id, array( 'mature' => 1 ) ); + $blog = get_blog_details( $blog_id ); + + $this->assertEquals( '1', $blog->mature ); + $this->assertEquals( 1, $test_action_counter ); + + // The action should not fire if the status of 'mature' stays the same. + update_blog_details( $blog_id, array( 'mature' => 1 ) ); + $blog = get_blog_details( $blog_id ); + + $this->assertEquals( '1', $blog->mature ); + $this->assertEquals( 1, $test_action_counter ); + + remove_action( 'mature_blog', array( $this, '_action_counter_cb' ), 10 ); + } + + function test_update_blog_details_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_details( $blog_id, array( 'mature' => 0 ) ); + + $blog = get_blog_details( $blog_id ); + $this->assertEquals( '0', $blog->mature ); + $this->assertEquals( 1, $test_action_counter ); + + // The action should not fire if the status of 'mature' stays the same. + update_blog_details( $blog_id, array( 'mature' => 0 ) ); + $blog = get_blog_details( $blog_id ); + + $this->assertEquals( '0', $blog->mature ); + $this->assertEquals( 1, $test_action_counter ); + + remove_action( 'unmature_blog', array( $this, '_action_counter_cb' ), 10 ); + } + + /** + * Provide a counter to determine that hooks are firing when intended. + */ + 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. When multiple directories + * are part of the path, only one slash should separate each directory. + * + * @ticket 18117 + */ + function test_update_blog_details_single_path_no_slashes() { + update_blog_details( 1, array( 'path' => 'my_path' ) ); + $blog = get_blog_details( 1 ); + $this->assertEquals( '/my_path/', $blog->path ); + } + + function test_update_blog_details_single_path_double_trailing_slashes() { + update_blog_details( 1, array( 'path' => 'my_path//' ) ); + $blog = get_blog_details( 1 ); + $this->assertEquals( '/my_path/', $blog->path ); + } + + function test_update_blog_details_single_path_double_leading_slashes() { + update_blog_details( 1, array( 'path' => '//my_path' ) ); + $blog = get_blog_details( 1 ); + $this->assertEquals( '/my_path/', $blog->path ); + } + + function test_update_blog_details_single_path_single_trailing_slash() { + update_blog_details( 1, array( 'path' => 'my_path/' ) ); + $blog = get_blog_details( 1 ); + $this->assertEquals( '/my_path/', $blog->path ); + } + + function test_update_blog_details_single_path_single_leading_slashes() { + update_blog_details( 1, array( 'path' => '/my_path' ) ); + $blog = get_blog_details( 1 ); + $this->assertEquals( '/my_path/', $blog->path ); + } + + function test_update_blog_details_single_path_both_slashes() { + update_blog_details( 1, array( 'path' => '/my_path/' ) ); + $blog = get_blog_details( 1 ); + $this->assertEquals( '/my_path/', $blog->path ); + } + + function test_update_blog_details_multiple_paths_no_slashes() { + update_blog_details( 1, array( 'path' => 'multiple/dirs' ) ); + $blog = get_blog_details( 1 ); + $this->assertEquals( '/multiple/dirs/', $blog->path ); + } + + /** + * `update_blog_details()` does not resolve multiple slashes in the + * middle of a path string. + */ + function test_update_blog_details_multiple_paths_middle_slashes() { + update_blog_details( 1, array( 'path' => 'multiple///dirs' ) ); + $blog = get_blog_details( 1 ); + $this->assertEquals( '/multiple///dirs/', $blog->path ); + } + + function test_update_blog_details_multiple_paths_leading_slash() { + update_blog_details( 1, array( 'path' => '/multiple/dirs' ) ); + $blog = get_blog_details( 1 ); + $this->assertEquals( '/multiple/dirs/', $blog->path ); + } + + function test_update_blog_details_multiple_paths_trailing_slash() { + update_blog_details( 1, array( 'path' => 'multiple/dirs/' ) ); + $blog = get_blog_details( 1 ); + $this->assertEquals( '/multiple/dirs/', $blog->path ); + } + + function test_update_blog_details_multiple_paths_both_slashes() { + update_blog_details( 1, array( 'path' => '/multiple/dirs/' ) ); + $blog = get_blog_details( 1 ); + $this->assertEquals( '/multiple/dirs/', $blog->path ); + } + +} +endif; \ No newline at end of file