summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorSergey Biryukov <sergeybiryukov@git.wordpress.org>2025-04-09 13:29:39 +0000
committerSergey Biryukov <sergeybiryukov@git.wordpress.org>2025-04-09 13:29:39 +0000
commit45cf47811a8adae99897ec4cceaf7fd3acbabe38 (patch)
tree8f37657000bdf5bb05b5fbd5187cf9981f3e5683
parentac648a15245df2261c0782f7e1c618911f392601 (diff)
downloadwordpress-45cf47811a8adae99897ec4cceaf7fd3acbabe38.tar.gz
wordpress-45cf47811a8adae99897ec4cceaf7fd3acbabe38.zip
Tests: Use the `ms-required` group where appropriate.
This replaces the `if ( is_multisite() )` conditional wrapping entire test classes with the `ms-required` group for more consistency across the test suite. Follow-up to [40520]. See #63167. git-svn-id: https://develop.svn.wordpress.org/trunk@60148 602fd350-edb4-49c9-b593-d223f7449a82
-rw-r--r--tests/phpunit/tests/multisite/avoidBlogPagePermalinkCollision.php112
-rw-r--r--tests/phpunit/tests/multisite/bootstrap.php619
-rw-r--r--tests/phpunit/tests/multisite/cleanDirsizeCache.php505
-rw-r--r--tests/phpunit/tests/multisite/forceSslContent.php2
-rw-r--r--tests/phpunit/tests/multisite/getBlogDetails.php388
-rw-r--r--tests/phpunit/tests/multisite/getIdFromBlogname.php235
-rw-r--r--tests/phpunit/tests/multisite/getMainSiteId.php308
-rw-r--r--tests/phpunit/tests/multisite/getSite.php87
-rw-r--r--tests/phpunit/tests/multisite/getSpaceAllowed.php141
-rw-r--r--tests/phpunit/tests/multisite/getSpaceUsed.php140
-rw-r--r--tests/phpunit/tests/multisite/isEmailAddressUnsafe.php248
-rw-r--r--tests/phpunit/tests/multisite/isUploadSpaceAvailable.php145
-rw-r--r--tests/phpunit/tests/multisite/msFilesRewriting.php129
-rw-r--r--tests/phpunit/tests/multisite/network.php1136
-rw-r--r--tests/phpunit/tests/multisite/site.php3809
-rw-r--r--tests/phpunit/tests/multisite/siteDetails.php331
-rw-r--r--tests/phpunit/tests/multisite/siteMeta.php720
-rw-r--r--tests/phpunit/tests/multisite/updateBlogDetails.php212
-rw-r--r--tests/phpunit/tests/multisite/updateBlogStatus.php377
-rw-r--r--tests/phpunit/tests/multisite/updatePostsCount.php86
-rw-r--r--tests/phpunit/tests/multisite/uploadIsUserOverQuota.php229
-rw-r--r--tests/phpunit/tests/multisite/wpCountSites.php115
-rw-r--r--tests/phpunit/tests/multisite/wpGetSites.php242
-rw-r--r--tests/phpunit/tests/multisite/wpInstallDefaults.php114
-rw-r--r--tests/phpunit/tests/multisite/wpMsSitesListTable.php369
-rw-r--r--tests/phpunit/tests/multisite/wpMsThemesListTable.php2
-rw-r--r--tests/phpunit/tests/multisite/wpMsUsersListTable.php2
-rw-r--r--tests/phpunit/tests/multisite/wpNetworkQuery.php1115
-rw-r--r--tests/phpunit/tests/multisite/wpSiteQuery.php2081
-rw-r--r--tests/phpunit/tests/multisite/wpmuLogNewRegistrations.php31
-rw-r--r--tests/phpunit/tests/multisite/wpmuValidateBlogSignup.php258
-rw-r--r--tests/phpunit/tests/multisite/wpmuValidateUserSignup.php438
-rw-r--r--tests/phpunit/tests/option/multisite.php499
-rw-r--r--tests/phpunit/tests/theme/wpThemeGetAllowedFilters.php138
-rw-r--r--tests/phpunit/tests/user/getActiveBlogForUser.php148
-rw-r--r--tests/phpunit/tests/user/multisite.php709
36 files changed, 8075 insertions, 8145 deletions
diff --git a/tests/phpunit/tests/multisite/avoidBlogPagePermalinkCollision.php b/tests/phpunit/tests/multisite/avoidBlogPagePermalinkCollision.php
index 42f226fb22..dc71b6d701 100644
--- a/tests/phpunit/tests/multisite/avoidBlogPagePermalinkCollision.php
+++ b/tests/phpunit/tests/multisite/avoidBlogPagePermalinkCollision.php
@@ -1,69 +1,67 @@
<?php
-if ( is_multisite() ) :
+/**
+ * Tests specific to `avoid_blog_page_permalink_collision()` in multisite.
+ *
+ * @group ms-required
+ * @group multisite
+ * @group post
+ */
+class Tests_Multisite_AvoidBlogPagePermalinkCollision extends WP_UnitTestCase {
+
+ protected static $site_id;
+ protected static $root_page;
+ protected static $child_page;
+ protected static $post_and_blog_path = 'permalink-collision';
/**
- * Tests specific to `avoid_blog_page_permalink_collision()` in multisite.
- *
- * @group multisite
- * @group post
+ * Create a blog and the pages we need to test the collision.
*/
- class Tests_Multisite_AvoidBlogPagePermalinkCollision extends WP_UnitTestCase {
- protected static $site_id;
- protected static $root_page;
- protected static $child_page;
- protected static $post_and_blog_path = 'permalink-collision';
-
- /**
- * Create a blog and the pages we need to test the collision.
- */
- public static function wpSetUpBeforeClass( $factory ) {
- self::$site_id = self::factory()->blog->create(
- array(
- 'path' => '/' . self::$post_and_blog_path,
- )
- );
+ public static function wpSetUpBeforeClass( $factory ) {
+ self::$site_id = self::factory()->blog->create(
+ array(
+ 'path' => '/' . self::$post_and_blog_path,
+ )
+ );
- self::$root_page = self::factory()->post->create_and_get(
- array(
- 'post_type' => 'page',
- 'post_title' => 'Bar',
- 'post_name' => self::$post_and_blog_path,
- )
- );
+ self::$root_page = self::factory()->post->create_and_get(
+ array(
+ 'post_type' => 'page',
+ 'post_title' => 'Bar',
+ 'post_name' => self::$post_and_blog_path,
+ )
+ );
- self::$child_page = self::factory()->post->create_and_get(
- array(
- 'post_parent' => self::$root_page->ID,
- 'post_type' => 'page',
- 'post_title' => 'Bar',
- 'post_name' => self::$post_and_blog_path,
- )
- );
- }
-
- /**
- * Delete blog and pages we created.
- */
- public static function wpTearDownAfterClass() {
- wp_delete_site( self::$site_id );
+ self::$child_page = self::factory()->post->create_and_get(
+ array(
+ 'post_parent' => self::$root_page->ID,
+ 'post_type' => 'page',
+ 'post_title' => 'Bar',
+ 'post_name' => self::$post_and_blog_path,
+ )
+ );
+ }
- wp_delete_post( self::$root_page->ID );
- wp_delete_post( self::$child_page->ID );
- }
+ /**
+ * Delete blog and pages we created.
+ */
+ public static function wpTearDownAfterClass() {
+ wp_delete_site( self::$site_id );
- public function test_avoid_blog_page_permalink_collision_renames_post_name() {
- $this->assertNotSame( self::$post_and_blog_path, self::$root_page->post_name );
- }
+ wp_delete_post( self::$root_page->ID );
+ wp_delete_post( self::$child_page->ID );
+ }
- /**
- * Ensure `avoid_blog_page_permalink_collision()` doesn't rename child pages' post_name.
- *
- * @ticket 51147
- */
- public function test_avoid_blog_page_permalink_collision_doesnt_rename_child_pages() {
- $this->assertSame( self::$post_and_blog_path, self::$child_page->post_name );
- }
+ public function test_avoid_blog_page_permalink_collision_renames_post_name() {
+ $this->assertNotSame( self::$post_and_blog_path, self::$root_page->post_name );
}
-endif;
+ /**
+ * Ensure `avoid_blog_page_permalink_collision()` doesn't rename child pages' post_name.
+ *
+ * @ticket 51147
+ */
+ public function test_avoid_blog_page_permalink_collision_doesnt_rename_child_pages() {
+ $this->assertSame( self::$post_and_blog_path, self::$child_page->post_name );
+ }
+}
diff --git a/tests/phpunit/tests/multisite/bootstrap.php b/tests/phpunit/tests/multisite/bootstrap.php
index 7b09097471..74aa40d812 100644
--- a/tests/phpunit/tests/multisite/bootstrap.php
+++ b/tests/phpunit/tests/multisite/bootstrap.php
@@ -1,344 +1,347 @@
<?php
-if ( is_multisite() ) :
+/**
+ * Tests specific to the bootstrap process of Multisite.
+ *
+ * @group ms-bootstrap
+ * @group ms-required
+ * @group multisite
+ */
+class Tests_Multisite_Bootstrap extends WP_UnitTestCase {
+
+ protected static $network_ids;
+ protected static $site_ids;
+
+ public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
+ self::$network_ids = array(
+ 'wordpress.org/' => array(
+ 'domain' => 'wordpress.org',
+ 'path' => '/',
+ ),
+ 'make.wordpress.org/' => array(
+ 'domain' => 'make.wordpress.org',
+ 'path' => '/',
+ ),
+ 'wordpress.org/one/' => array(
+ 'domain' => 'wordpress.org',
+ 'path' => '/one/',
+ ),
+ 'wordpress.org/one/b/' => array(
+ 'domain' => 'wordpress.org',
+ 'path' => '/one/b/',
+ ),
+ 'wordpress.net/' => array(
+ 'domain' => 'wordpress.net',
+ 'path' => '/',
+ ),
+ 'www.wordpress.net/' => array(
+ 'domain' => 'www.wordpress.net',
+ 'path' => '/',
+ ),
+ 'www.wordpress.net/two/' => array(
+ 'domain' => 'www.wordpress.net',
+ 'path' => '/two/',
+ ),
+ 'wordpress.net/three/' => array(
+ 'domain' => 'wordpress.net',
+ 'path' => '/three/',
+ ),
+ );
+
+ foreach ( self::$network_ids as &$id ) {
+ $id = $factory->network->create( $id );
+ }
+ unset( $id );
+
+ self::$site_ids = array(
+ 'wordpress.org/' => array(
+ 'domain' => 'wordpress.org',
+ 'path' => '/',
+ 'network_id' => self::$network_ids['wordpress.org/'],
+ ),
+ 'wordpress.org/foo/' => array(
+ 'domain' => 'wordpress.org',
+ 'path' => '/foo/',
+ 'network_id' => self::$network_ids['wordpress.org/'],
+ ),
+ 'wordpress.org/foo/bar/' => array(
+ 'domain' => 'wordpress.org',
+ 'path' => '/foo/bar/',
+ 'network_id' => self::$network_ids['wordpress.org/'],
+ ),
+ 'make.wordpress.org/' => array(
+ 'domain' => 'make.wordpress.org',
+ 'path' => '/',
+ 'network_id' => self::$network_ids['make.wordpress.org/'],
+ ),
+ 'make.wordpress.org/foo/' => array(
+ 'domain' => 'make.wordpress.org',
+ 'path' => '/foo/',
+ 'network_id' => self::$network_ids['make.wordpress.org/'],
+ ),
+ 'www.w.org/' => array(
+ 'domain' => 'www.w.org',
+ 'path' => '/',
+ ),
+ 'www.w.org/foo/' => array(
+ 'domain' => 'www.w.org',
+ 'path' => '/foo/',
+ ),
+ 'www.w.org/foo/bar/' => array(
+ 'domain' => 'www.w.org',
+ 'path' => '/foo/bar/',
+ ),
+ );
+
+ foreach ( self::$site_ids as &$id ) {
+ $id = $factory->blog->create( $id );
+ }
+ unset( $id );
+ }
+
+ public static function wpTearDownAfterClass() {
+ global $wpdb;
+
+ foreach ( self::$site_ids as $id ) {
+ wp_delete_site( $id );
+ }
+
+ foreach ( self::$network_ids as $id ) {
+ $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->sitemeta} WHERE site_id = %d", $id ) );
+ $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->site} WHERE id= %d", $id ) );
+ }
+
+ wp_update_network_site_counts();
+ }
/**
- * Tests specific to the bootstrap process of Multisite.
+ * @ticket 27003
+ * @dataProvider data_get_network_by_path
*
- * @group ms-bootstrap
- * @group multisite
+ * @param string $expected_key The array key associated with expected data for the test.
+ * @param string $domain The requested domain.
+ * @param string $path The requested path.
+ * @param string $message The message to pass for failed tests.
*/
- class Tests_Multisite_Bootstrap extends WP_UnitTestCase {
- protected static $network_ids;
- protected static $site_ids;
-
- public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
- self::$network_ids = array(
- 'wordpress.org/' => array(
- 'domain' => 'wordpress.org',
- 'path' => '/',
- ),
- 'make.wordpress.org/' => array(
- 'domain' => 'make.wordpress.org',
- 'path' => '/',
- ),
- 'wordpress.org/one/' => array(
- 'domain' => 'wordpress.org',
- 'path' => '/one/',
- ),
- 'wordpress.org/one/b/' => array(
- 'domain' => 'wordpress.org',
- 'path' => '/one/b/',
- ),
- 'wordpress.net/' => array(
- 'domain' => 'wordpress.net',
- 'path' => '/',
- ),
- 'www.wordpress.net/' => array(
- 'domain' => 'www.wordpress.net',
- 'path' => '/',
- ),
- 'www.wordpress.net/two/' => array(
- 'domain' => 'www.wordpress.net',
- 'path' => '/two/',
- ),
- 'wordpress.net/three/' => array(
- 'domain' => 'wordpress.net',
- 'path' => '/three/',
- ),
- );
-
- foreach ( self::$network_ids as &$id ) {
- $id = $factory->network->create( $id );
- }
- unset( $id );
-
- self::$site_ids = array(
- 'wordpress.org/' => array(
- 'domain' => 'wordpress.org',
- 'path' => '/',
- 'network_id' => self::$network_ids['wordpress.org/'],
- ),
- 'wordpress.org/foo/' => array(
- 'domain' => 'wordpress.org',
- 'path' => '/foo/',
- 'network_id' => self::$network_ids['wordpress.org/'],
- ),
- 'wordpress.org/foo/bar/' => array(
- 'domain' => 'wordpress.org',
- 'path' => '/foo/bar/',
- 'network_id' => self::$network_ids['wordpress.org/'],
- ),
- 'make.wordpress.org/' => array(
- 'domain' => 'make.wordpress.org',
- 'path' => '/',
- 'network_id' => self::$network_ids['make.wordpress.org/'],
- ),
- 'make.wordpress.org/foo/' => array(
- 'domain' => 'make.wordpress.org',
- 'path' => '/foo/',
- 'network_id' => self::$network_ids['make.wordpress.org/'],
- ),
- 'www.w.org/' => array(
- 'domain' => 'www.w.org',
- 'path' => '/',
- ),
- 'www.w.org/foo/' => array(
- 'domain' => 'www.w.org',
- 'path' => '/foo/',
- ),
- 'www.w.org/foo/bar/' => array(
- 'domain' => 'www.w.org',
- 'path' => '/foo/bar/',
- ),
- );
-
- foreach ( self::$site_ids as &$id ) {
- $id = $factory->blog->create( $id );
- }
- unset( $id );
- }
+ public function test_get_network_by_path( $expected_key, $domain, $path, $message ) {
+ $network = get_network_by_path( $domain, $path );
+ $this->assertSame( self::$network_ids[ $expected_key ], $network->id, $message );
+ }
- public static function wpTearDownAfterClass() {
- global $wpdb;
+ public function data_get_network_by_path() {
+ return array(
+ array( 'wordpress.org/', 'wordpress.org', '/', 'A standard domain and path request should work.' ),
+ array( 'wordpress.net/', 'wordpress.net', '/notapath/', 'A missing path on a top level domain should find the correct network.' ),
+ array( 'www.wordpress.net/', 'www.wordpress.net', '/notapath/', 'A missing path should find the correct network.' ),
+ array( 'wordpress.org/one/', 'www.wordpress.org', '/one/', 'Should find the path despite the www.' ),
+ array( 'wordpress.org/one/', 'wordpress.org', '/one/page/', 'A request with two path segments should find the correct network.' ),
+ array( 'wordpress.org/one/b/', 'wordpress.org', '/one/b/', 'A request with two valid path segments should find the correct network.' ),
+ array( 'wordpress.org/', 'site1.wordpress.org', '/one/', 'Should not find path because domains do not match.' ),
+ array( 'wordpress.net/three/', 'wordpress.net', '/three/', 'A network can have a path.' ),
+ array( 'www.wordpress.net/two/', 'www.wordpress.net', '/two/', 'A www network with a path can coexist with a non-www network.' ),
+ array( 'wordpress.net/', 'site1.wordpress.net', '/notapath/', 'An invalid subdomain should find the top level network domain.' ),
+ array( 'wordpress.net/', 'site1.wordpress.net', '/three/', 'An invalid subdomain and path should find the top level network domain.' ),
+ array( 'wordpress.net/', 'x.y.wordpress.net', '/', 'An invalid two level subdomain should find the top level network domain.' ),
+ );
+ }
- foreach ( self::$site_ids as $id ) {
- wp_delete_site( $id );
- }
+ /**
+ * @ticket 37217
+ * @dataProvider data_get_network_by_path_with_zero_path_segments
+ *
+ * @param string $expected_key The array key associated with expected data for the test.
+ * @param string $domain The requested domain.
+ * @param string $path The requested path.
+ * @param string $message The message to pass for failed tests.
+ */
+ public function test_get_network_by_path_with_zero_path_segments( $expected_key, $domain, $path, $message ) {
+ add_filter( 'network_by_path_segments_count', '__return_zero' );
- foreach ( self::$network_ids as $id ) {
- $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->sitemeta} WHERE site_id = %d", $id ) );
- $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->site} WHERE id= %d", $id ) );
- }
+ $network = get_network_by_path( $domain, $path );
- wp_update_network_site_counts();
- }
+ remove_filter( 'network_by_path_segments_count', '__return_zero' );
- /**
- * @ticket 27003
- * @dataProvider data_get_network_by_path
- *
- * @param string $expected_key The array key associated with expected data for the test.
- * @param string $domain The requested domain.
- * @param string $path The requested path.
- * @param string $message The message to pass for failed tests.
- */
- public function test_get_network_by_path( $expected_key, $domain, $path, $message ) {
- $network = get_network_by_path( $domain, $path );
- $this->assertSame( self::$network_ids[ $expected_key ], $network->id, $message );
- }
+ $this->assertSame( self::$network_ids[ $expected_key ], $network->id, $message );
+ }
- public function data_get_network_by_path() {
- return array(
- array( 'wordpress.org/', 'wordpress.org', '/', 'A standard domain and path request should work.' ),
- array( 'wordpress.net/', 'wordpress.net', '/notapath/', 'A missing path on a top level domain should find the correct network.' ),
- array( 'www.wordpress.net/', 'www.wordpress.net', '/notapath/', 'A missing path should find the correct network.' ),
- array( 'wordpress.org/one/', 'www.wordpress.org', '/one/', 'Should find the path despite the www.' ),
- array( 'wordpress.org/one/', 'wordpress.org', '/one/page/', 'A request with two path segments should find the correct network.' ),
- array( 'wordpress.org/one/b/', 'wordpress.org', '/one/b/', 'A request with two valid path segments should find the correct network.' ),
- array( 'wordpress.org/', 'site1.wordpress.org', '/one/', 'Should not find path because domains do not match.' ),
- array( 'wordpress.net/three/', 'wordpress.net', '/three/', 'A network can have a path.' ),
- array( 'www.wordpress.net/two/', 'www.wordpress.net', '/two/', 'A www network with a path can coexist with a non-www network.' ),
- array( 'wordpress.net/', 'site1.wordpress.net', '/notapath/', 'An invalid subdomain should find the top level network domain.' ),
- array( 'wordpress.net/', 'site1.wordpress.net', '/three/', 'An invalid subdomain and path should find the top level network domain.' ),
- array( 'wordpress.net/', 'x.y.wordpress.net', '/', 'An invalid two level subdomain should find the top level network domain.' ),
- );
- }
+ public function data_get_network_by_path_with_zero_path_segments() {
+ return array(
+ array( 'wordpress.org/', 'wordpress.org', '/', 'A standard domain and path request should work.' ),
+ array( 'wordpress.net/', 'wordpress.net', '/notapath/', 'A network matching a top level domain should be found regardless of path.' ),
+ array( 'www.wordpress.net/', 'www.wordpress.net', '/notapath/', 'A network matching a domain should be found regardless of path.' ),
+ array( 'wordpress.org/', 'www.wordpress.org', '/one/', 'Should find the network despite the www and regardless of path.' ),
+ array( 'wordpress.org/', 'site1.wordpress.org', '/one/', 'Should find the network with the corresponding top level domain regardless of path.' ),
+ array( 'www.wordpress.net/', 'www.wordpress.net', '/two/', 'A www network can coexist with a non-www network.' ),
+ array( 'make.wordpress.org/', 'make.wordpress.org', '/notapath/', 'A subdomain network should be found regardless of path.' ),
+ array( 'wordpress.net/', 'x.y.wordpress.net', '/', 'An invalid two level subdomain should find the top level network domain.' ),
+ );
+ }
- /**
- * @ticket 37217
- * @dataProvider data_get_network_by_path_with_zero_path_segments
- *
- * @param string $expected_key The array key associated with expected data for the test.
- * @param string $domain The requested domain.
- * @param string $path The requested path.
- * @param string $message The message to pass for failed tests.
- */
- public function test_get_network_by_path_with_zero_path_segments( $expected_key, $domain, $path, $message ) {
- add_filter( 'network_by_path_segments_count', '__return_zero' );
+ /**
+ * Even if a matching network is available, it should not match if the the filtered
+ * value for network path segments is fewer than the number of paths passed.
+ */
+ public function test_get_network_by_path_with_forced_single_path_segment_returns_single_path_network() {
+ add_filter( 'network_by_path_segments_count', array( $this, 'filter_network_path_segments' ) );
+ $network = get_network_by_path( 'wordpress.org', '/one/b/' );
+ remove_filter( 'network_by_path_segments_count', array( $this, 'filter_network_path_segments' ) );
- $network = get_network_by_path( $domain, $path );
+ $this->assertSame( self::$network_ids['wordpress.org/one/'], $network->id );
+ }
- remove_filter( 'network_by_path_segments_count', '__return_zero' );
+ public function filter_network_path_segments() {
+ return 1;
+ }
- $this->assertSame( self::$network_ids[ $expected_key ], $network->id, $message );
- }
+ /**
+ * @ticket 27003
+ * @ticket 27927
+ * @dataProvider data_get_site_by_path
+ *
+ * @param string $expected_key The array key associated with expected data for the test.
+ * @param string $domain The requested domain.
+ * @param string $path The requested path.
+ * @param int $segments Optional. Number of segments to use in `get_site_by_path()`.
+ */
+ public function test_get_site_by_path( $expected_key, $domain, $path, $segments = null ) {
+ $site = get_site_by_path( $domain, $path, $segments );
- public function data_get_network_by_path_with_zero_path_segments() {
- return array(
- array( 'wordpress.org/', 'wordpress.org', '/', 'A standard domain and path request should work.' ),
- array( 'wordpress.net/', 'wordpress.net', '/notapath/', 'A network matching a top level domain should be found regardless of path.' ),
- array( 'www.wordpress.net/', 'www.wordpress.net', '/notapath/', 'A network matching a domain should be found regardless of path.' ),
- array( 'wordpress.org/', 'www.wordpress.org', '/one/', 'Should find the network despite the www and regardless of path.' ),
- array( 'wordpress.org/', 'site1.wordpress.org', '/one/', 'Should find the network with the corresponding top level domain regardless of path.' ),
- array( 'www.wordpress.net/', 'www.wordpress.net', '/two/', 'A www network can coexist with a non-www network.' ),
- array( 'make.wordpress.org/', 'make.wordpress.org', '/notapath/', 'A subdomain network should be found regardless of path.' ),
- array( 'wordpress.net/', 'x.y.wordpress.net', '/', 'An invalid two level subdomain should find the top level network domain.' ),
- );
+ if ( $expected_key ) {
+ $this->assertEquals( self::$site_ids[ $expected_key ], $site->blog_id );
+ } else {
+ $this->assertFalse( $site );
}
+ }
- /**
- * Even if a matching network is available, it should not match if the the filtered
- * value for network path segments is fewer than the number of paths passed.
- */
- public function test_get_network_by_path_with_forced_single_path_segment_returns_single_path_network() {
- add_filter( 'network_by_path_segments_count', array( $this, 'filter_network_path_segments' ) );
- $network = get_network_by_path( 'wordpress.org', '/one/b/' );
- remove_filter( 'network_by_path_segments_count', array( $this, 'filter_network_path_segments' ) );
+ public function data_get_site_by_path() {
+ return array(
+ array( 'wordpress.org/', 'wordpress.org', '/notapath/' ),
+ array( 'wordpress.org/', 'www.wordpress.org', '/notapath/' ),
+ array( 'wordpress.org/foo/bar/', 'wordpress.org', '/foo/bar/baz/' ),
+ array( 'wordpress.org/foo/bar/', 'www.wordpress.org', '/foo/bar/baz/' ),
+ array( 'wordpress.org/foo/bar/', 'wordpress.org', '/foo/bar/baz/', 3 ),
+ array( 'wordpress.org/foo/bar/', 'www.wordpress.org', '/foo/bar/baz/', 3 ),
+ array( 'wordpress.org/foo/bar/', 'wordpress.org', '/foo/bar/baz/', 2 ),
+ array( 'wordpress.org/foo/bar/', 'www.wordpress.org', '/foo/bar/baz/', 2 ),
+ array( 'wordpress.org/foo/', 'wordpress.org', '/foo/bar/baz/', 1 ),
+ array( 'wordpress.org/foo/', 'www.wordpress.org', '/foo/bar/baz/', 1 ),
+ array( 'wordpress.org/', 'wordpress.org', '/', 0 ),
+ array( 'wordpress.org/', 'www.wordpress.org', '/', 0 ),
+ array( 'make.wordpress.org/foo/', 'make.wordpress.org', '/foo/bar/baz/quz/', 4 ),
+ array( 'make.wordpress.org/foo/', 'www.make.wordpress.org', '/foo/bar/baz/quz/', 4 ),
+ array( 'www.w.org/', 'www.w.org', '/', 0 ),
+ array( 'www.w.org/', 'www.w.org', '/notapath' ),
+ array( 'www.w.org/foo/bar/', 'www.w.org', '/foo/bar/baz/' ),
+ array( 'www.w.org/foo/', 'www.w.org', '/foo/bar/baz/', 1 ),
+
+ // A site installed with www will not be found by the root domain.
+ array( false, 'w.org', '/' ),
+ array( false, 'w.org', '/notapath/' ),
+ array( false, 'w.org', '/foo/bar/baz/' ),
+ array( false, 'w.org', '/foo/bar/baz/', 1 ),
+
+ // A site will not be found by its root domain when an invalid subdomain is requested.
+ array( false, 'invalid.wordpress.org', '/' ),
+ array( false, 'invalid.wordpress.org', '/foo/bar/' ),
+ );
+ }
- $this->assertSame( self::$network_ids['wordpress.org/one/'], $network->id );
- }
+ /**
+ * @ticket 27884
+ * @dataProvider data_multisite_bootstrap
+ *
+ * @param string $site_key The array key associated with the expected site for the test.
+ * @param string $network_key The array key associated with the expected network for the test.
+ * @param string $domain The requested domain.
+ * @param string $path The requested path.
+ */
+ public function test_multisite_bootstrap( $site_key, $network_key, $domain, $path ) {
+ global $current_blog;
- public function filter_network_path_segments() {
- return 1;
- }
+ $expected = array(
+ 'network_id' => self::$network_ids[ $network_key ],
+ 'site_id' => self::$site_ids[ $site_key ],
+ );
- /**
- * @ticket 27003
- * @ticket 27927
- * @dataProvider data_get_site_by_path
- *
- * @param string $expected_key The array key associated with expected data for the test.
- * @param string $domain The requested domain.
- * @param string $path The requested path.
- * @param int $segments Optional. Number of segments to use in `get_site_by_path()`.
- */
- public function test_get_site_by_path( $expected_key, $domain, $path, $segments = null ) {
- $site = get_site_by_path( $domain, $path, $segments );
-
- if ( $expected_key ) {
- $this->assertEquals( self::$site_ids[ $expected_key ], $site->blog_id );
- } else {
- $this->assertFalse( $site );
- }
- }
+ ms_load_current_site_and_network( $domain, $path );
- public function data_get_site_by_path() {
- return array(
- array( 'wordpress.org/', 'wordpress.org', '/notapath/' ),
- array( 'wordpress.org/', 'www.wordpress.org', '/notapath/' ),
- array( 'wordpress.org/foo/bar/', 'wordpress.org', '/foo/bar/baz/' ),
- array( 'wordpress.org/foo/bar/', 'www.wordpress.org', '/foo/bar/baz/' ),
- array( 'wordpress.org/foo/bar/', 'wordpress.org', '/foo/bar/baz/', 3 ),
- array( 'wordpress.org/foo/bar/', 'www.wordpress.org', '/foo/bar/baz/', 3 ),
- array( 'wordpress.org/foo/bar/', 'wordpress.org', '/foo/bar/baz/', 2 ),
- array( 'wordpress.org/foo/bar/', 'www.wordpress.org', '/foo/bar/baz/', 2 ),
- array( 'wordpress.org/foo/', 'wordpress.org', '/foo/bar/baz/', 1 ),
- array( 'wordpress.org/foo/', 'www.wordpress.org', '/foo/bar/baz/', 1 ),
- array( 'wordpress.org/', 'wordpress.org', '/', 0 ),
- array( 'wordpress.org/', 'www.wordpress.org', '/', 0 ),
- array( 'make.wordpress.org/foo/', 'make.wordpress.org', '/foo/bar/baz/quz/', 4 ),
- array( 'make.wordpress.org/foo/', 'www.make.wordpress.org', '/foo/bar/baz/quz/', 4 ),
- array( 'www.w.org/', 'www.w.org', '/', 0 ),
- array( 'www.w.org/', 'www.w.org', '/notapath' ),
- array( 'www.w.org/foo/bar/', 'www.w.org', '/foo/bar/baz/' ),
- array( 'www.w.org/foo/', 'www.w.org', '/foo/bar/baz/', 1 ),
-
- // A site installed with www will not be found by the root domain.
- array( false, 'w.org', '/' ),
- array( false, 'w.org', '/notapath/' ),
- array( false, 'w.org', '/foo/bar/baz/' ),
- array( false, 'w.org', '/foo/bar/baz/', 1 ),
-
- // A site will not be found by its root domain when an invalid subdomain is requested.
- array( false, 'invalid.wordpress.org', '/' ),
- array( false, 'invalid.wordpress.org', '/foo/bar/' ),
- );
- }
+ $actual = array(
+ 'network_id' => $current_blog->site_id,
+ 'site_id' => $current_blog->blog_id,
+ );
- /**
- * @ticket 27884
- * @dataProvider data_multisite_bootstrap
- *
- * @param string $site_key The array key associated with the expected site for the test.
- * @param string $network_key The array key associated with the expected network for the test.
- * @param string $domain The requested domain.
- * @param string $path The requested path.
- */
- public function test_multisite_bootstrap( $site_key, $network_key, $domain, $path ) {
- global $current_blog;
-
- $expected = array(
- 'network_id' => self::$network_ids[ $network_key ],
- 'site_id' => self::$site_ids[ $site_key ],
- );
-
- ms_load_current_site_and_network( $domain, $path );
- $actual = array(
- 'network_id' => $current_blog->site_id,
- 'site_id' => $current_blog->blog_id,
- );
- ms_load_current_site_and_network( WP_TESTS_DOMAIN, '/' );
-
- $this->assertEqualSetsWithIndex( $expected, $actual );
- }
+ ms_load_current_site_and_network( WP_TESTS_DOMAIN, '/' );
- public function data_multisite_bootstrap() {
- return array(
- array( 'wordpress.org/', 'wordpress.org/', 'wordpress.org', '/' ),
- array( 'wordpress.org/', 'wordpress.org/', 'wordpress.org', '/2014/04/23/hello-world/' ),
- array( 'wordpress.org/', 'wordpress.org/', 'wordpress.org', '/sample-page/' ),
- array( 'wordpress.org/', 'wordpress.org/', 'wordpress.org', '/?p=1' ),
- array( 'wordpress.org/', 'wordpress.org/', 'wordpress.org', '/wp-admin/' ),
- array( 'wordpress.org/foo/', 'wordpress.org/', 'wordpress.org', '/foo/' ),
- array( 'wordpress.org/foo/', 'wordpress.org/', 'wordpress.org', '/FOO/' ),
- array( 'wordpress.org/foo/', 'wordpress.org/', 'wordpress.org', '/foo/2014/04/23/hello-world/' ),
- array( 'wordpress.org/foo/', 'wordpress.org/', 'wordpress.org', '/foo/sample-page/' ),
- array( 'wordpress.org/foo/', 'wordpress.org/', 'wordpress.org', '/foo/?p=1' ),
- array( 'wordpress.org/foo/', 'wordpress.org/', 'wordpress.org', '/foo/wp-admin/' ),
- array( 'make.wordpress.org/', 'make.wordpress.org/', 'make.wordpress.org', '/' ),
- array( 'make.wordpress.org/foo/', 'make.wordpress.org/', 'make.wordpress.org', '/foo/' ),
- );
- }
+ $this->assertEqualSetsWithIndex( $expected, $actual );
+ }
- /**
- * @ticket 27884
- */
- public function test_multisite_bootstrap_additional_path_segments() {
- global $current_blog;
+ public function data_multisite_bootstrap() {
+ return array(
+ array( 'wordpress.org/', 'wordpress.org/', 'wordpress.org', '/' ),
+ array( 'wordpress.org/', 'wordpress.org/', 'wordpress.org', '/2014/04/23/hello-world/' ),
+ array( 'wordpress.org/', 'wordpress.org/', 'wordpress.org', '/sample-page/' ),
+ array( 'wordpress.org/', 'wordpress.org/', 'wordpress.org', '/?p=1' ),
+ array( 'wordpress.org/', 'wordpress.org/', 'wordpress.org', '/wp-admin/' ),
+ array( 'wordpress.org/foo/', 'wordpress.org/', 'wordpress.org', '/foo/' ),
+ array( 'wordpress.org/foo/', 'wordpress.org/', 'wordpress.org', '/FOO/' ),
+ array( 'wordpress.org/foo/', 'wordpress.org/', 'wordpress.org', '/foo/2014/04/23/hello-world/' ),
+ array( 'wordpress.org/foo/', 'wordpress.org/', 'wordpress.org', '/foo/sample-page/' ),
+ array( 'wordpress.org/foo/', 'wordpress.org/', 'wordpress.org', '/foo/?p=1' ),
+ array( 'wordpress.org/foo/', 'wordpress.org/', 'wordpress.org', '/foo/wp-admin/' ),
+ array( 'make.wordpress.org/', 'make.wordpress.org/', 'make.wordpress.org', '/' ),
+ array( 'make.wordpress.org/foo/', 'make.wordpress.org/', 'make.wordpress.org', '/foo/' ),
+ );
+ }
- $expected = array(
- 'network_id' => self::$network_ids['wordpress.org/'],
- 'site_id' => self::$site_ids['wordpress.org/foo/bar/'],
- );
- add_filter( 'site_by_path_segments_count', array( $this, 'filter_path_segments_to_two' ) );
- ms_load_current_site_and_network( 'wordpress.org', '/foo/bar/' );
- $actual = array(
- 'network_id' => $current_blog->site_id,
- 'site_id' => $current_blog->blog_id,
- );
- remove_filter( 'site_by_path_segments_count', array( $this, 'filter_path_segments_to_two' ) );
- ms_load_current_site_and_network( WP_TESTS_DOMAIN, '/' );
-
- $this->assertEqualSetsWithIndex( $expected, $actual );
- }
+ /**
+ * @ticket 27884
+ */
+ public function test_multisite_bootstrap_additional_path_segments() {
+ global $current_blog;
- /**
- * @ticket 37053
- */
- public function test_get_site_by_path_returns_wp_site() {
- add_filter( 'pre_get_site_by_path', array( $this, 'filter_pre_get_site_by_path' ), 10, 3 );
+ $expected = array(
+ 'network_id' => self::$network_ids['wordpress.org/'],
+ 'site_id' => self::$site_ids['wordpress.org/foo/bar/'],
+ );
- $site = get_site_by_path( 'example.com', '/foo/' );
+ add_filter( 'site_by_path_segments_count', array( $this, 'filter_path_segments_to_two' ) );
+ ms_load_current_site_and_network( 'wordpress.org', '/foo/bar/' );
- remove_filter( 'pre_get_site_by_path', array( $this, 'filter_pre_get_site_by_path' ), 10 );
+ $actual = array(
+ 'network_id' => $current_blog->site_id,
+ 'site_id' => $current_blog->blog_id,
+ );
- $this->assertInstanceOf( 'WP_Site', $site );
- }
+ remove_filter( 'site_by_path_segments_count', array( $this, 'filter_path_segments_to_two' ) );
+ ms_load_current_site_and_network( WP_TESTS_DOMAIN, '/' );
- public function filter_path_segments_to_two() {
- return 2;
- }
+ $this->assertEqualSetsWithIndex( $expected, $actual );
+ }
- public function filter_pre_get_site_by_path( $site, $domain, $path ) {
- $site = new stdClass();
- $site->blog_id = 100;
- $site->domain = $domain;
- $site->path = $path;
- $site->site_id = 1;
+ /**
+ * @ticket 37053
+ */
+ public function test_get_site_by_path_returns_wp_site() {
+ add_filter( 'pre_get_site_by_path', array( $this, 'filter_pre_get_site_by_path' ), 10, 3 );
- return $site;
- }
+ $site = get_site_by_path( 'example.com', '/foo/' );
+
+ remove_filter( 'pre_get_site_by_path', array( $this, 'filter_pre_get_site_by_path' ), 10 );
+
+ $this->assertInstanceOf( 'WP_Site', $site );
}
-endif;
+ public function filter_path_segments_to_two() {
+ return 2;
+ }
+
+ public function filter_pre_get_site_by_path( $site, $domain, $path ) {
+ $site = new stdClass();
+ $site->blog_id = 100;
+ $site->domain = $domain;
+ $site->path = $path;
+ $site->site_id = 1;
+
+ return $site;
+ }
+}
diff --git a/tests/phpunit/tests/multisite/cleanDirsizeCache.php b/tests/phpunit/tests/multisite/cleanDirsizeCache.php
index df38ee33d1..16ad8fffc0 100644
--- a/tests/phpunit/tests/multisite/cleanDirsizeCache.php
+++ b/tests/phpunit/tests/multisite/cleanDirsizeCache.php
@@ -1,319 +1,316 @@
<?php
-if ( is_multisite() ) :
+/**
+ * Tests specific to the directory size caching in multisite.
+ *
+ * @ticket 19879
+ * @group ms-required
+ * @group multisite
+ */
+class Tests_Multisite_CleanDirsizeCache extends WP_UnitTestCase {
/**
- * Tests specific to the directory size caching in multisite.
+ * Test whether dirsize_cache values are used correctly with a more complex dirsize cache mock.
*
* @ticket 19879
- * @group multisite
*/
- class Tests_Multisite_CleanDirsizeCache extends WP_UnitTestCase {
+ public function test_get_dirsize_cache_in_recurse_dirsize_mock() {
+ $blog_id = self::factory()->blog->create();
+ switch_to_blog( $blog_id );
- /**
- * Test whether dirsize_cache values are used correctly with a more complex dirsize cache mock.
- *
- * @ticket 19879
+ /*
+ * Our comparison of space relies on an initial value of 0. If a previous test has failed
+ * or if the `src` directory already contains a directory with site content, then the initial
+ * expectation will be polluted. We create sites until an empty one is available.
*/
- public function test_get_dirsize_cache_in_recurse_dirsize_mock() {
+ while ( 0 !== get_space_used() ) {
+ restore_current_blog();
$blog_id = self::factory()->blog->create();
switch_to_blog( $blog_id );
-
- /*
- * Our comparison of space relies on an initial value of 0. If a previous test has failed
- * or if the `src` directory already contains a directory with site content, then the initial
- * expectation will be polluted. We create sites until an empty one is available.
- */
- while ( 0 !== get_space_used() ) {
- restore_current_blog();
- $blog_id = self::factory()->blog->create();
- switch_to_blog( $blog_id );
- }
-
- // Clear the dirsize cache.
- delete_transient( 'dirsize_cache' );
-
- // Set the dirsize cache to our mock.
- set_transient( 'dirsize_cache', $this->get_mock_dirsize_cache_for_site( $blog_id ) );
-
- $upload_dir = wp_upload_dir();
-
- // Check recurse_dirsize() against the mock. The cache should match.
- $this->assertSame( 21, recurse_dirsize( $upload_dir['basedir'] . '/2/1' ) );
- $this->assertSame( 22, recurse_dirsize( $upload_dir['basedir'] . '/2/2' ) );
- $this->assertSame( 2, recurse_dirsize( $upload_dir['basedir'] . '/2' ) );
- $this->assertSame( 11, recurse_dirsize( $upload_dir['basedir'] . '/1/1' ) );
- $this->assertSame( 12, recurse_dirsize( $upload_dir['basedir'] . '/1/2' ) );
- $this->assertSame( 13, recurse_dirsize( $upload_dir['basedir'] . '/1/3' ) );
- $this->assertSame( 1, recurse_dirsize( $upload_dir['basedir'] . '/1' ) );
- $this->assertSame( 42, recurse_dirsize( $upload_dir['basedir'] . '/custom_directory' ) );
-
- // No cache match, upload directory should be empty and return 0.
- $this->assertSame( 0, recurse_dirsize( $upload_dir['basedir'] ) );
-
- // No cache match on non existing directory should return false.
- $this->assertFalse( recurse_dirsize( $upload_dir['basedir'] . '/does_not_exist' ) );
-
- // Cleanup.
- $this->remove_added_uploads();
- restore_current_blog();
}
- /**
- * Test whether the dirsize_cache invalidation works given a file path as input.
- *
- * @ticket 19879
+ // Clear the dirsize cache.
+ delete_transient( 'dirsize_cache' );
+
+ // Set the dirsize cache to our mock.
+ set_transient( 'dirsize_cache', $this->get_mock_dirsize_cache_for_site( $blog_id ) );
+
+ $upload_dir = wp_upload_dir();
+
+ // Check recurse_dirsize() against the mock. The cache should match.
+ $this->assertSame( 21, recurse_dirsize( $upload_dir['basedir'] . '/2/1' ) );
+ $this->assertSame( 22, recurse_dirsize( $upload_dir['basedir'] . '/2/2' ) );
+ $this->assertSame( 2, recurse_dirsize( $upload_dir['basedir'] . '/2' ) );
+ $this->assertSame( 11, recurse_dirsize( $upload_dir['basedir'] . '/1/1' ) );
+ $this->assertSame( 12, recurse_dirsize( $upload_dir['basedir'] . '/1/2' ) );
+ $this->assertSame( 13, recurse_dirsize( $upload_dir['basedir'] . '/1/3' ) );
+ $this->assertSame( 1, recurse_dirsize( $upload_dir['basedir'] . '/1' ) );
+ $this->assertSame( 42, recurse_dirsize( $upload_dir['basedir'] . '/custom_directory' ) );
+
+ // No cache match, upload directory should be empty and return 0.
+ $this->assertSame( 0, recurse_dirsize( $upload_dir['basedir'] ) );
+
+ // No cache match on non existing directory should return false.
+ $this->assertFalse( recurse_dirsize( $upload_dir['basedir'] . '/does_not_exist' ) );
+
+ // Cleanup.
+ $this->remove_added_uploads();
+ restore_current_blog();
+ }
+
+ /**
+ * Test whether the dirsize_cache invalidation works given a file path as input.
+ *
+ * @ticket 19879
+ */
+ public function test_clean_dirsize_cache_file_input_mock() {
+ $blog_id = self::factory()->blog->create();
+ switch_to_blog( $blog_id );
+
+ /*
+ * Our comparison of space relies on an initial value of 0. If a previous test has failed
+ * or if the `src` directory already contains a directory with site content, then the initial
+ * expectation will be polluted. We create sites until an empty one is available.
*/
- public function test_clean_dirsize_cache_file_input_mock() {
+ while ( 0 !== get_space_used() ) {
+ restore_current_blog();
$blog_id = self::factory()->blog->create();
switch_to_blog( $blog_id );
+ }
- /*
- * Our comparison of space relies on an initial value of 0. If a previous test has failed
- * or if the `src` directory already contains a directory with site content, then the initial
- * expectation will be polluted. We create sites until an empty one is available.
- */
- while ( 0 !== get_space_used() ) {
- restore_current_blog();
- $blog_id = self::factory()->blog->create();
- switch_to_blog( $blog_id );
- }
+ $upload_dir = wp_upload_dir();
+ $cache_key_prefix = untrailingslashit( $upload_dir['basedir'] );
- $upload_dir = wp_upload_dir();
- $cache_key_prefix = untrailingslashit( $upload_dir['basedir'] );
+ // Clear the dirsize cache.
+ delete_transient( 'dirsize_cache' );
- // Clear the dirsize cache.
- delete_transient( 'dirsize_cache' );
+ // Set the dirsize cache to our mock.
+ set_transient( 'dirsize_cache', $this->get_mock_dirsize_cache_for_site( $blog_id ) );
- // Set the dirsize cache to our mock.
- set_transient( 'dirsize_cache', $this->get_mock_dirsize_cache_for_site( $blog_id ) );
+ $this->assertArrayHasKey( $cache_key_prefix . '/1/1', get_transient( 'dirsize_cache' ) );
+ $this->assertArrayHasKey( $cache_key_prefix . '/2/1', get_transient( 'dirsize_cache' ) );
+ $this->assertArrayHasKey( $cache_key_prefix . '/2', get_transient( 'dirsize_cache' ) );
- $this->assertArrayHasKey( $cache_key_prefix . '/1/1', get_transient( 'dirsize_cache' ) );
- $this->assertArrayHasKey( $cache_key_prefix . '/2/1', get_transient( 'dirsize_cache' ) );
- $this->assertArrayHasKey( $cache_key_prefix . '/2', get_transient( 'dirsize_cache' ) );
+ // Invalidation should also respect the directory tree up.
+ // Should work fine with path to directory OR file.
+ clean_dirsize_cache( $upload_dir['basedir'] . '/2/1/file.dummy' );
- // Invalidation should also respect the directory tree up.
- // Should work fine with path to directory OR file.
- clean_dirsize_cache( $upload_dir['basedir'] . '/2/1/file.dummy' );
+ $this->assertArrayNotHasKey( $cache_key_prefix . '/2/1', get_transient( 'dirsize_cache' ) );
+ $this->assertArrayNotHasKey( $cache_key_prefix . '/2', get_transient( 'dirsize_cache' ) );
- $this->assertArrayNotHasKey( $cache_key_prefix . '/2/1', get_transient( 'dirsize_cache' ) );
- $this->assertArrayNotHasKey( $cache_key_prefix . '/2', get_transient( 'dirsize_cache' ) );
+ // Other cache paths should not be invalidated.
+ $this->assertArrayHasKey( $cache_key_prefix . '/1/1', get_transient( 'dirsize_cache' ) );
- // Other cache paths should not be invalidated.
- $this->assertArrayHasKey( $cache_key_prefix . '/1/1', get_transient( 'dirsize_cache' ) );
+ // Cleanup.
+ $this->remove_added_uploads();
+ restore_current_blog();
+ }
- // Cleanup.
- $this->remove_added_uploads();
- restore_current_blog();
- }
+ /**
+ * Test whether the dirsize_cache invalidation works given a directory path as input.
+ *
+ * @ticket 19879
+ */
+ public function test_clean_dirsize_cache_folder_input_mock() {
+ $blog_id = self::factory()->blog->create();
+ switch_to_blog( $blog_id );
- /**
- * Test whether the dirsize_cache invalidation works given a directory path as input.
- *
- * @ticket 19879
+ /*
+ * Our comparison of space relies on an initial value of 0. If a previous test has failed
+ * or if the `src` directory already contains a directory with site content, then the initial
+ * expectation will be polluted. We create sites until an empty one is available.
*/
- public function test_clean_dirsize_cache_folder_input_mock() {
+ while ( 0 !== get_space_used() ) {
+ restore_current_blog();
$blog_id = self::factory()->blog->create();
switch_to_blog( $blog_id );
+ }
- /*
- * Our comparison of space relies on an initial value of 0. If a previous test has failed
- * or if the `src` directory already contains a directory with site content, then the initial
- * expectation will be polluted. We create sites until an empty one is available.
- */
- while ( 0 !== get_space_used() ) {
- restore_current_blog();
- $blog_id = self::factory()->blog->create();
- switch_to_blog( $blog_id );
- }
+ $upload_dir = wp_upload_dir();
+ $cache_key_prefix = untrailingslashit( $upload_dir['basedir'] );
- $upload_dir = wp_upload_dir();
- $cache_key_prefix = untrailingslashit( $upload_dir['basedir'] );
+ // Clear the dirsize cache.
+ delete_transient( 'dirsize_cache' );
- // Clear the dirsize cache.
- delete_transient( 'dirsize_cache' );
+ // Set the dirsize cache to our mock.
+ set_transient( 'dirsize_cache', $this->get_mock_dirsize_cache_for_site( $blog_id ) );
- // Set the dirsize cache to our mock.
- set_transient( 'dirsize_cache', $this->get_mock_dirsize_cache_for_site( $blog_id ) );
+ $this->assertArrayHasKey( $cache_key_prefix . '/1/1', get_transient( 'dirsize_cache' ) );
+ $this->assertArrayHasKey( $cache_key_prefix . '/2/1', get_transient( 'dirsize_cache' ) );
+ $this->assertArrayHasKey( $cache_key_prefix . '/2', get_transient( 'dirsize_cache' ) );
- $this->assertArrayHasKey( $cache_key_prefix . '/1/1', get_transient( 'dirsize_cache' ) );
- $this->assertArrayHasKey( $cache_key_prefix . '/2/1', get_transient( 'dirsize_cache' ) );
- $this->assertArrayHasKey( $cache_key_prefix . '/2', get_transient( 'dirsize_cache' ) );
+ // Invalidation should also respect the directory tree up.
+ // Should work fine with path to directory OR file.
+ clean_dirsize_cache( $upload_dir['basedir'] . '/2/1' );
- // Invalidation should also respect the directory tree up.
- // Should work fine with path to directory OR file.
- clean_dirsize_cache( $upload_dir['basedir'] . '/2/1' );
+ $this->assertArrayNotHasKey( $cache_key_prefix . '/2/1', get_transient( 'dirsize_cache' ) );
+ $this->assertArrayNotHasKey( $cache_key_prefix . '/2', get_transient( 'dirsize_cache' ) );
- $this->assertArrayNotHasKey( $cache_key_prefix . '/2/1', get_transient( 'dirsize_cache' ) );
- $this->assertArrayNotHasKey( $cache_key_prefix . '/2', get_transient( 'dirsize_cache' ) );
+ // Other cache paths should not be invalidated.
+ $this->assertArrayHasKey( $cache_key_prefix . '/1/1', get_transient( 'dirsize_cache' ) );
- // Other cache paths should not be invalidated.
- $this->assertArrayHasKey( $cache_key_prefix . '/1/1', get_transient( 'dirsize_cache' ) );
+ // Cleanup.
+ $this->remove_added_uploads();
+ restore_current_blog();
+ }
- // Cleanup.
- $this->remove_added_uploads();
- restore_current_blog();
- }
+ /**
+ * Test whether dirsize_cache values are used correctly with a simple real upload.
+ *
+ * @ticket 19879
+ */
+ public function test_get_dirsize_cache_in_recurse_dirsize_upload() {
+ $blog_id = self::factory()->blog->create();
+ switch_to_blog( $blog_id );
- /**
- * Test whether dirsize_cache values are used correctly with a simple real upload.
- *
- * @ticket 19879
+ /*
+ * Our comparison of space relies on an initial value of 0. If a previous test has failed
+ * or if the `src` directory already contains a directory with site content, then the initial
+ * expectation will be polluted. We create sites until an empty one is available.
*/
- public function test_get_dirsize_cache_in_recurse_dirsize_upload() {
+ while ( 0 !== get_space_used() ) {
+ restore_current_blog();
$blog_id = self::factory()->blog->create();
switch_to_blog( $blog_id );
+ }
- /*
- * Our comparison of space relies on an initial value of 0. If a previous test has failed
- * or if the `src` directory already contains a directory with site content, then the initial
- * expectation will be polluted. We create sites until an empty one is available.
- */
- while ( 0 !== get_space_used() ) {
- restore_current_blog();
- $blog_id = self::factory()->blog->create();
- switch_to_blog( $blog_id );
- }
+ // Clear the dirsize cache.
+ delete_transient( 'dirsize_cache' );
- // Clear the dirsize cache.
- delete_transient( 'dirsize_cache' );
+ $upload_dir = wp_upload_dir();
- $upload_dir = wp_upload_dir();
+ $this->assertSame( 0, recurse_dirsize( $upload_dir['path'] ) );
- $this->assertSame( 0, recurse_dirsize( $upload_dir['path'] ) );
+ // Upload a file to the new site using wp_upload_bits().
+ $filename = __FUNCTION__ . '.jpg';
+ $contents = __FUNCTION__ . '_contents';
+ $file = wp_upload_bits( $filename, null, $contents );
- // Upload a file to the new site using wp_upload_bits().
- $filename = __FUNCTION__ . '.jpg';
- $contents = __FUNCTION__ . '_contents';
- $file = wp_upload_bits( $filename, null, $contents );
+ $calc_size = recurse_dirsize( $upload_dir['path'] );
+ $size = filesize( $file['file'] );
+ $this->assertSame( $size, $calc_size );
- $calc_size = recurse_dirsize( $upload_dir['path'] );
- $size = filesize( $file['file'] );
- $this->assertSame( $size, $calc_size );
+ // `dirsize_cache` should now be filled after upload and recurse_dirsize() call.
+ $cache_path = untrailingslashit( $upload_dir['path'] );
+ $this->assertIsArray( get_transient( 'dirsize_cache' ) );
+ $this->assertSame( $size, get_transient( 'dirsize_cache' )[ $cache_path ] );
- // `dirsize_cache` should now be filled after upload and recurse_dirsize() call.
- $cache_path = untrailingslashit( $upload_dir['path'] );
- $this->assertIsArray( get_transient( 'dirsize_cache' ) );
- $this->assertSame( $size, get_transient( 'dirsize_cache' )[ $cache_path ] );
+ // Cleanup.
+ $this->remove_added_uploads();
+ restore_current_blog();
+ }
- // Cleanup.
- $this->remove_added_uploads();
- restore_current_blog();
- }
+ /**
+ * Test whether the filter to calculate space for an existing directory works as expected.
+ *
+ * @ticket 19879
+ */
+ public function test_pre_recurse_dirsize_filter() {
+ add_filter( 'pre_recurse_dirsize', array( $this, 'filter_pre_recurse_dirsize' ) );
- /**
- * Test whether the filter to calculate space for an existing directory works as expected.
- *
- * @ticket 19879
- */
- public function test_pre_recurse_dirsize_filter() {
- add_filter( 'pre_recurse_dirsize', array( $this, 'filter_pre_recurse_dirsize' ) );
+ $upload_dir = wp_upload_dir();
+ $this->assertSame( 1042, recurse_dirsize( $upload_dir['path'] ) );
- $upload_dir = wp_upload_dir();
- $this->assertSame( 1042, recurse_dirsize( $upload_dir['path'] ) );
+ remove_filter( 'pre_recurse_dirsize', array( $this, 'filter_pre_recurse_dirsize' ) );
+ }
- remove_filter( 'pre_recurse_dirsize', array( $this, 'filter_pre_recurse_dirsize' ) );
- }
+ public function filter_pre_recurse_dirsize() {
+ return 1042;
+ }
- public function filter_pre_recurse_dirsize() {
- return 1042;
- }
+ private function get_mock_dirsize_cache_for_site( $site_id ) {
+ $prefix = wp_upload_dir()['basedir'];
+
+ return array(
+ "$prefix/2/2" => 22,
+ "$prefix/2/1" => 21,
+ "$prefix/2" => 2,
+ "$prefix/1/3" => 13,
+ "$prefix/1/2" => 12,
+ "$prefix/1/1" => 11,
+ "$prefix/1" => 1,
+ "$prefix/custom_directory" => 42,
+ );
+ }
- private function get_mock_dirsize_cache_for_site( $site_id ) {
- $prefix = wp_upload_dir()['basedir'];
-
- return array(
- "$prefix/2/2" => 22,
- "$prefix/2/1" => 21,
- "$prefix/2" => 2,
- "$prefix/1/3" => 13,
- "$prefix/1/2" => 12,
- "$prefix/1/1" => 11,
- "$prefix/1" => 1,
- "$prefix/custom_directory" => 42,
- );
- }
+ /*
+ * Test that 5.6+ gracefully handles the old 5.5 transient structure.
+ *
+ * @ticket 51913
+ */
+ public function test_5_5_transient_structure_compat() {
+ $blog_id = self::factory()->blog->create();
+ switch_to_blog( $blog_id );
/*
- * Test that 5.6+ gracefully handles the old 5.5 transient structure.
- *
- * @ticket 51913
+ * Our comparison of space relies on an initial value of 0. If a previous test has failed
+ * or if the `src` directory already contains a directory with site content, then the initial
+ * expectation will be polluted. We create sites until an empty one is available.
*/
- public function test_5_5_transient_structure_compat() {
+ while ( 0 !== get_space_used() ) {
+ restore_current_blog();
$blog_id = self::factory()->blog->create();
switch_to_blog( $blog_id );
+ }
- /*
- * Our comparison of space relies on an initial value of 0. If a previous test has failed
- * or if the `src` directory already contains a directory with site content, then the initial
- * expectation will be polluted. We create sites until an empty one is available.
- */
- while ( 0 !== get_space_used() ) {
- restore_current_blog();
- $blog_id = self::factory()->blog->create();
- switch_to_blog( $blog_id );
- }
-
- // Clear the dirsize cache.
- delete_transient( 'dirsize_cache' );
-
- // Set the dirsize cache to our mock.
- set_transient( 'dirsize_cache', $this->get_mock_5_5_dirsize_cache( $blog_id ) );
-
- $upload_dir = wp_upload_dir();
-
- /*
- * The cached size should be ignored, because it's in the old format. The function
- * will try to fetch a live value, but in this case the folder doesn't actually
- * exist on disk, so the function should fail.
- */
- $this->assertFalse( recurse_dirsize( $upload_dir['basedir'] . '/2/1' ) );
-
- /*
- * Now that it's confirmed that old cached values aren't being returned, create the
- * folder on disk, so that the the rest of the function can be tested.
- */
- wp_mkdir_p( $upload_dir['basedir'] . '/2/1' );
- $filename = $upload_dir['basedir'] . '/2/1/this-needs-to-exist.txt';
- file_put_contents( $filename, 'this file is 21 bytes' );
-
- // Clear the dirsize cache.
- delete_transient( 'dirsize_cache' );
-
- // Set the dirsize cache to our mock.
- set_transient( 'dirsize_cache', $this->get_mock_5_5_dirsize_cache( $blog_id ) );
-
- /*
- * Now that the folder exists, the old cached value should be overwritten
- * with the size, using the current format.
- */
- $this->assertSame( 21, recurse_dirsize( $upload_dir['basedir'] . '/2/1' ) );
- $this->assertSame( 21, get_transient( 'dirsize_cache' )[ $upload_dir['basedir'] . '/2/1' ] );
-
- // No cache match on non existing directory should return false.
- $this->assertFalse( recurse_dirsize( $upload_dir['basedir'] . '/does_not_exist' ) );
-
- // Cleanup.
- $this->remove_added_uploads();
- rmdir( $upload_dir['basedir'] . '/2/1' );
+ // Clear the dirsize cache.
+ delete_transient( 'dirsize_cache' );
- restore_current_blog();
- }
+ // Set the dirsize cache to our mock.
+ set_transient( 'dirsize_cache', $this->get_mock_5_5_dirsize_cache( $blog_id ) );
- private function get_mock_5_5_dirsize_cache( $site_id ) {
- $prefix = untrailingslashit( wp_upload_dir()['basedir'] );
-
- return array(
- "$prefix/2/2" => array( 'size' => 22 ),
- "$prefix/2/1" => array( 'size' => 21 ),
- "$prefix/2" => array( 'size' => 2 ),
- "$prefix/1/3" => array( 'size' => 13 ),
- "$prefix/1/2" => array( 'size' => 12 ),
- "$prefix/1/1" => array( 'size' => 11 ),
- "$prefix/1" => array( 'size' => 1 ),
- "$prefix/custom_directory" => array( 'size' => 42 ),
- );
- }
+ $upload_dir = wp_upload_dir();
+
+ /*
+ * The cached size should be ignored, because it's in the old format. The function
+ * will try to fetch a live value, but in this case the folder doesn't actually
+ * exist on disk, so the function should fail.
+ */
+ $this->assertFalse( recurse_dirsize( $upload_dir['basedir'] . '/2/1' ) );
+
+ /*
+ * Now that it's confirmed that old cached values aren't being returned, create the
+ * folder on disk, so that the the rest of the function can be tested.
+ */
+ wp_mkdir_p( $upload_dir['basedir'] . '/2/1' );
+ $filename = $upload_dir['basedir'] . '/2/1/this-needs-to-exist.txt';
+ file_put_contents( $filename, 'this file is 21 bytes' );
+
+ // Clear the dirsize cache.
+ delete_transient( 'dirsize_cache' );
+
+ // Set the dirsize cache to our mock.
+ set_transient( 'dirsize_cache', $this->get_mock_5_5_dirsize_cache( $blog_id ) );
+
+ /*
+ * Now that the folder exists, the old cached value should be overwritten
+ * with the size, using the current format.
+ */
+ $this->assertSame( 21, recurse_dirsize( $upload_dir['basedir'] . '/2/1' ) );
+ $this->assertSame( 21, get_transient( 'dirsize_cache' )[ $upload_dir['basedir'] . '/2/1' ] );
+
+ // No cache match on non existing directory should return false.
+ $this->assertFalse( recurse_dirsize( $upload_dir['basedir'] . '/does_not_exist' ) );
+
+ // Cleanup.
+ $this->remove_added_uploads();
+ rmdir( $upload_dir['basedir'] . '/2/1' );
+
+ restore_current_blog();
}
-endif;
+ private function get_mock_5_5_dirsize_cache( $site_id ) {
+ $prefix = untrailingslashit( wp_upload_dir()['basedir'] );
+
+ return array(
+ "$prefix/2/2" => array( 'size' => 22 ),
+ "$prefix/2/1" => array( 'size' => 21 ),
+ "$prefix/2" => array( 'size' => 2 ),
+ "$prefix/1/3" => array( 'size' => 13 ),
+ "$prefix/1/2" => array( 'size' => 12 ),
+ "$prefix/1/1" => array( 'size' => 11 ),
+ "$prefix/1" => array( 'size' => 1 ),
+ "$prefix/custom_directory" => array( 'size' => 42 ),
+ );
+ }
+}
diff --git a/tests/phpunit/tests/multisite/forceSslContent.php b/tests/phpunit/tests/multisite/forceSslContent.php
index b701dd013a..78b82ec1c0 100644
--- a/tests/phpunit/tests/multisite/forceSslContent.php
+++ b/tests/phpunit/tests/multisite/forceSslContent.php
@@ -5,8 +5,8 @@
* @since 6.9.0
*
* @group functions
- * @group multisite
* @group ms-required
+ * @group multisite
*
* @covers ::force_ssl_content
*/
diff --git a/tests/phpunit/tests/multisite/getBlogDetails.php b/tests/phpunit/tests/multisite/getBlogDetails.php
index b4c456f082..5a374d43dc 100644
--- a/tests/phpunit/tests/multisite/getBlogDetails.php
+++ b/tests/phpunit/tests/multisite/getBlogDetails.php
@@ -1,235 +1,233 @@
<?php
-if ( is_multisite() ) :
-
- /**
- * @ticket 29845
- * @group ms-site
- * @group multisite
- */
- class Tests_Multisite_GetBlogDetails extends WP_UnitTestCase {
- protected static $network_ids;
- protected static $site_ids;
-
- public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
- self::$site_ids = array(
- WP_TESTS_DOMAIN . '/foo/' => array(
- 'domain' => WP_TESTS_DOMAIN,
- 'path' => '/foo/',
- ),
- 'foo.' . WP_TESTS_DOMAIN . '/' => array(
- 'domain' => 'foo.' . WP_TESTS_DOMAIN,
- 'path' => '/',
- ),
- 'wordpress.org/' => array(
- 'domain' => 'wordpress.org',
- 'path' => '/',
- ),
- );
+/**
+ * @ticket 29845
+ * @group ms-required
+ * @group ms-site
+ * @group multisite
+ */
+class Tests_Multisite_GetBlogDetails extends WP_UnitTestCase {
+
+ protected static $network_ids;
+ protected static $site_ids;
+
+ public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
+ self::$site_ids = array(
+ WP_TESTS_DOMAIN . '/foo/' => array(
+ 'domain' => WP_TESTS_DOMAIN,
+ 'path' => '/foo/',
+ ),
+ 'foo.' . WP_TESTS_DOMAIN . '/' => array(
+ 'domain' => 'foo.' . WP_TESTS_DOMAIN,
+ 'path' => '/',
+ ),
+ 'wordpress.org/' => array(
+ 'domain' => 'wordpress.org',
+ 'path' => '/',
+ ),
+ );
+
+ foreach ( self::$site_ids as &$id ) {
+ $id = $factory->blog->create( $id );
+ }
+ unset( $id );
+ }
- foreach ( self::$site_ids as &$id ) {
- $id = $factory->blog->create( $id );
- }
- unset( $id );
+ public static function wpTearDownAfterClass() {
+ foreach ( self::$site_ids as $id ) {
+ wp_delete_site( $id );
}
- public static function wpTearDownAfterClass() {
- foreach ( self::$site_ids as $id ) {
- wp_delete_site( $id );
- }
+ wp_update_network_site_counts();
+ }
- wp_update_network_site_counts();
- }
+ public function test_get_blog_details_with_no_arguments_returns_current_site() {
+ $site = get_blog_details();
+ $this->assertEquals( get_current_blog_id(), $site->blog_id );
+ }
- public function test_get_blog_details_with_no_arguments_returns_current_site() {
- $site = get_blog_details();
- $this->assertEquals( get_current_blog_id(), $site->blog_id );
+ public function test_get_blog_details_with_site_name_string_subdirectory() {
+ if ( is_subdomain_install() ) {
+ $this->markTestSkipped( 'This test is only valid in a subdirectory configuration.' );
}
- public function test_get_blog_details_with_site_name_string_subdirectory() {
- if ( is_subdomain_install() ) {
- $this->markTestSkipped( 'This test is only valid in a subdirectory configuration.' );
- }
+ $site = get_blog_details( 'foo' );
+ $this->assertEquals( self::$site_ids[ WP_TESTS_DOMAIN . '/foo/' ], $site->blog_id );
+ }
- $site = get_blog_details( 'foo' );
- $this->assertEquals( self::$site_ids[ WP_TESTS_DOMAIN . '/foo/' ], $site->blog_id );
+ public function test_get_blog_details_with_site_name_string_subdomain() {
+ if ( ! is_subdomain_install() ) {
+ $this->markTestSkipped( 'This test is only valid in a subdomain configuration.' );
}
- public function test_get_blog_details_with_site_name_string_subdomain() {
- if ( ! is_subdomain_install() ) {
- $this->markTestSkipped( 'This test is only valid in a subdomain configuration.' );
- }
+ $site = get_blog_details( 'foo' );
+ $this->assertEquals( self::$site_ids[ 'foo.' . WP_TESTS_DOMAIN . '/' ], $site->blog_id );
+ }
- $site = get_blog_details( 'foo' );
- $this->assertEquals( self::$site_ids[ 'foo.' . WP_TESTS_DOMAIN . '/' ], $site->blog_id );
- }
+ public function test_get_blog_details_with_invalid_site_name_string() {
+ $site = get_blog_details( 'invalid' );
+ $this->assertFalse( $site );
+ }
- public function test_get_blog_details_with_invalid_site_name_string() {
- $site = get_blog_details( 'invalid' );
- $this->assertFalse( $site );
- }
+ public function test_get_blog_details_with_site_id_int() {
+ $site = get_blog_details( self::$site_ids['wordpress.org/'] );
+ $this->assertEquals( self::$site_ids['wordpress.org/'], $site->blog_id );
+ }
- public function test_get_blog_details_with_site_id_int() {
- $site = get_blog_details( self::$site_ids['wordpress.org/'] );
- $this->assertEquals( self::$site_ids['wordpress.org/'], $site->blog_id );
- }
+ public function test_get_blog_details_with_invalid_site_id_int() {
+ $site = get_blog_details( 99999 );
+ $this->assertFalse( $site );
+ }
- public function test_get_blog_details_with_invalid_site_id_int() {
- $site = get_blog_details( 99999 );
- $this->assertFalse( $site );
- }
+ public function test_get_blog_details_with_blog_id_in_fields() {
+ $site = get_blog_details( array( 'blog_id' => self::$site_ids['wordpress.org/'] ) );
+ $this->assertEquals( self::$site_ids['wordpress.org/'], $site->blog_id );
+ }
- public function test_get_blog_details_with_blog_id_in_fields() {
- $site = get_blog_details( array( 'blog_id' => self::$site_ids['wordpress.org/'] ) );
- $this->assertEquals( self::$site_ids['wordpress.org/'], $site->blog_id );
- }
+ public function test_get_blog_details_with_invalid_blog_id_in_fields() {
+ $site = get_blog_details( array( 'blog_id' => 88888 ) );
+ $this->assertFalse( $site );
+ }
- public function test_get_blog_details_with_invalid_blog_id_in_fields() {
- $site = get_blog_details( array( 'blog_id' => 88888 ) );
- $this->assertFalse( $site );
- }
+ public function test_get_blog_details_with_domain_and_path_in_fields() {
+ $site = get_blog_details(
+ array(
+ 'domain' => 'wordpress.org',
+ 'path' => '/',
+ )
+ );
+ $this->assertEquals( self::$site_ids['wordpress.org/'], $site->blog_id );
+ }
- public function test_get_blog_details_with_domain_and_path_in_fields() {
- $site = get_blog_details(
- array(
- 'domain' => 'wordpress.org',
- 'path' => '/',
- )
- );
- $this->assertEquals( self::$site_ids['wordpress.org/'], $site->blog_id );
- }
+ public function test_get_blog_details_with_domain_and_invalid_path_in_fields() {
+ $site = get_blog_details(
+ array(
+ 'domain' => 'wordpress.org',
+ 'path' => '/zxy/',
+ )
+ );
+ $this->assertFalse( $site );
+ }
- public function test_get_blog_details_with_domain_and_invalid_path_in_fields() {
- $site = get_blog_details(
- array(
- 'domain' => 'wordpress.org',
- 'path' => '/zxy/',
- )
- );
- $this->assertFalse( $site );
- }
+ public function test_get_blog_details_with_path_and_invalid_domain_in_fields() {
+ $site = get_blog_details(
+ array(
+ 'domain' => 'invalid.org',
+ 'path' => '/foo/',
+ )
+ );
+ $this->assertFalse( $site );
+ }
- public function test_get_blog_details_with_path_and_invalid_domain_in_fields() {
- $site = get_blog_details(
- array(
- 'domain' => 'invalid.org',
- 'path' => '/foo/',
- )
- );
- $this->assertFalse( $site );
+ public function test_get_blog_details_with_only_domain_in_fields_subdomain() {
+ if ( ! is_subdomain_install() ) {
+ $this->markTestSkipped( 'This test is only valid in a subdomain configuration.' );
}
- public function test_get_blog_details_with_only_domain_in_fields_subdomain() {
- if ( ! is_subdomain_install() ) {
- $this->markTestSkipped( 'This test is only valid in a subdomain configuration.' );
- }
+ $site = get_blog_details( array( 'domain' => 'wordpress.org' ) );
+ $this->assertSame( self::$site_ids['wordpress.org/'], $site->blog_id );
+ }
- $site = get_blog_details( array( 'domain' => 'wordpress.org' ) );
- $this->assertSame( self::$site_ids['wordpress.org/'], $site->blog_id );
+ public function test_get_blog_details_with_only_domain_in_fields_subdirectory() {
+ if ( is_subdomain_install() ) {
+ $this->markTestSkipped( 'This test is only valid in a subdirectory configuration.' );
}
- public function test_get_blog_details_with_only_domain_in_fields_subdirectory() {
- if ( is_subdomain_install() ) {
- $this->markTestSkipped( 'This test is only valid in a subdirectory configuration.' );
- }
-
- $site = get_blog_details( array( 'domain' => 'wordpress.org' ) );
- $this->assertFalse( $site );
- }
+ $site = get_blog_details( array( 'domain' => 'wordpress.org' ) );
+ $this->assertFalse( $site );
+ }
- public function test_get_blog_details_with_only_path_in_fields() {
- $site = get_blog_details( array( 'path' => '/foo/' ) );
- $this->assertFalse( $site );
- }
+ public function test_get_blog_details_with_only_path_in_fields() {
+ $site = get_blog_details( array( 'path' => '/foo/' ) );
+ $this->assertFalse( $site );
+ }
- /**
- * @ticket 50391
- */
- public function test_get_blog_details_does_not_switch_to_current_blog() {
- $count = did_action( 'switch_blog' );
+ /**
+ * @ticket 50391
+ */
+ public function test_get_blog_details_does_not_switch_to_current_blog() {
+ $count = did_action( 'switch_blog' );
- get_blog_details();
- $this->assertSame( $count, did_action( 'switch_blog' ) );
- }
+ get_blog_details();
+ $this->assertSame( $count, did_action( 'switch_blog' ) );
+ }
- /**
- * @dataProvider data_get_all
- *
- * @ticket 40228
- */
- public function test_get_blog_details_get_object_vars( $get_all ) {
- $site = get_blog_details(
- array(
- 'domain' => 'wordpress.org',
- 'path' => '/',
- ),
- $get_all
- );
+ /**
+ * @dataProvider data_get_all
+ *
+ * @ticket 40228
+ */
+ public function test_get_blog_details_get_object_vars( $get_all ) {
+ $site = get_blog_details(
+ array(
+ 'domain' => 'wordpress.org',
+ 'path' => '/',
+ ),
+ $get_all
+ );
+
+ $result = array_keys( get_object_vars( $site ) );
+
+ $this->assertSameSets( $this->get_fields( $get_all ), $result );
+ }
- $result = array_keys( get_object_vars( $site ) );
+ /**
+ * @dataProvider data_get_all
+ *
+ * @ticket 40228
+ */
+ public function test_get_blog_details_iterate_over_result( $get_all ) {
+ $site = get_blog_details(
+ array(
+ 'domain' => 'wordpress.org',
+ 'path' => '/',
+ ),
+ $get_all
+ );
- $this->assertSameSets( $this->get_fields( $get_all ), $result );
+ $result = array();
+ foreach ( $site as $key => $value ) {
+ $result[] = $key;
}
- /**
- * @dataProvider data_get_all
- *
- * @ticket 40228
- */
- public function test_get_blog_details_iterate_over_result( $get_all ) {
- $site = get_blog_details(
- array(
- 'domain' => 'wordpress.org',
- 'path' => '/',
- ),
- $get_all
- );
-
- $result = array();
- foreach ( $site as $key => $value ) {
- $result[] = $key;
- }
+ $this->assertSameSets( $this->get_fields( $get_all ), $result );
+ }
- $this->assertSameSets( $this->get_fields( $get_all ), $result );
- }
+ public function data_get_all() {
+ return array(
+ array( false ),
+ array( true ),
+ );
+ }
- public function data_get_all() {
- return array(
- array( false ),
- array( true ),
+ protected function get_fields( $all = false ) {
+ $fields = array(
+ 'blog_id',
+ 'domain',
+ 'path',
+ 'site_id',
+ 'registered',
+ 'last_updated',
+ 'public',
+ 'archived',
+ 'mature',
+ 'spam',
+ 'deleted',
+ 'lang_id',
+ );
+
+ if ( $all ) {
+ $fields = array_merge(
+ $fields,
+ array(
+ 'blogname',
+ 'siteurl',
+ 'post_count',
+ 'home',
+ )
);
}
- protected function get_fields( $all = false ) {
- $fields = array(
- 'blog_id',
- 'domain',
- 'path',
- 'site_id',
- 'registered',
- 'last_updated',
- 'public',
- 'archived',
- 'mature',
- 'spam',
- 'deleted',
- 'lang_id',
- );
-
- if ( $all ) {
- $fields = array_merge(
- $fields,
- array(
- 'blogname',
- 'siteurl',
- 'post_count',
- 'home',
- )
- );
- }
-
- return $fields;
- }
+ return $fields;
}
-
-endif;
+}
diff --git a/tests/phpunit/tests/multisite/getIdFromBlogname.php b/tests/phpunit/tests/multisite/getIdFromBlogname.php
index 63f8ab79e7..d38da764a8 100644
--- a/tests/phpunit/tests/multisite/getIdFromBlogname.php
+++ b/tests/phpunit/tests/multisite/getIdFromBlogname.php
@@ -1,141 +1,140 @@
<?php
-if ( is_multisite() ) :
- /**
- * Test get_id_from_blogname() in multisite.
- *
- * @group blogname
- * @group ms-site
- * @group multisite
- */
- class Tests_Multisite_GetIdFromBlogname extends WP_UnitTestCase {
- protected static $network_ids;
- protected static $site_ids;
-
- public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
- self::$network_ids = array(
- 'wordpress.org/' => array(
- 'domain' => 'wordpress.org',
- 'path' => '/',
- ),
- 'www.wordpress.net/' => array(
- 'domain' => 'www.wordpress.net',
- 'path' => '/',
- ),
- );
-
- foreach ( self::$network_ids as &$id ) {
- $id = $factory->network->create( $id );
- }
- unset( $id );
-
- self::$site_ids = array(
- 'wordpress.org/' => array(
- 'domain' => 'wordpress.org',
- 'path' => '/',
- 'network_id' => self::$network_ids['wordpress.org/'],
- ),
- 'foo.wordpress.org/' => array(
- 'domain' => 'foo.wordpress.org',
- 'path' => '/',
- 'network_id' => self::$network_ids['wordpress.org/'],
- ),
- 'wordpress.org/foo/' => array(
- 'domain' => 'wordpress.org',
- 'path' => '/foo/',
- 'network_id' => self::$network_ids['wordpress.org/'],
- ),
- 'www.wordpress.net/' => array(
- 'domain' => 'www.wordpress.net',
- 'path' => '/',
- 'network_id' => self::$network_ids['www.wordpress.net/'],
- ),
- 'foo.wordpress.net/' => array(
- 'domain' => 'foo.wordpress.net',
- 'path' => '/',
- 'network_id' => self::$network_ids['www.wordpress.net/'],
- ),
- 'www.wordpress.net/foo/' => array(
- 'domain' => 'www.wordpress.net',
- 'path' => '/foo/',
- 'network_id' => self::$network_ids['www.wordpress.net/'],
- ),
- );
-
- foreach ( self::$site_ids as &$id ) {
- $id = $factory->blog->create( $id );
- }
- unset( $id );
+/**
+ * Test get_id_from_blogname() in multisite.
+ *
+ * @group blogname
+ * @group ms-required
+ * @group ms-site
+ * @group multisite
+ */
+class Tests_Multisite_GetIdFromBlogname extends WP_UnitTestCase {
+
+ protected static $network_ids;
+ protected static $site_ids;
+
+ public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
+ self::$network_ids = array(
+ 'wordpress.org/' => array(
+ 'domain' => 'wordpress.org',
+ 'path' => '/',
+ ),
+ 'www.wordpress.net/' => array(
+ 'domain' => 'www.wordpress.net',
+ 'path' => '/',
+ ),
+ );
+
+ foreach ( self::$network_ids as &$id ) {
+ $id = $factory->network->create( $id );
}
+ unset( $id );
+
+ self::$site_ids = array(
+ 'wordpress.org/' => array(
+ 'domain' => 'wordpress.org',
+ 'path' => '/',
+ 'network_id' => self::$network_ids['wordpress.org/'],
+ ),
+ 'foo.wordpress.org/' => array(
+ 'domain' => 'foo.wordpress.org',
+ 'path' => '/',
+ 'network_id' => self::$network_ids['wordpress.org/'],
+ ),
+ 'wordpress.org/foo/' => array(
+ 'domain' => 'wordpress.org',
+ 'path' => '/foo/',
+ 'network_id' => self::$network_ids['wordpress.org/'],
+ ),
+ 'www.wordpress.net/' => array(
+ 'domain' => 'www.wordpress.net',
+ 'path' => '/',
+ 'network_id' => self::$network_ids['www.wordpress.net/'],
+ ),
+ 'foo.wordpress.net/' => array(
+ 'domain' => 'foo.wordpress.net',
+ 'path' => '/',
+ 'network_id' => self::$network_ids['www.wordpress.net/'],
+ ),
+ 'www.wordpress.net/foo/' => array(
+ 'domain' => 'www.wordpress.net',
+ 'path' => '/foo/',
+ 'network_id' => self::$network_ids['www.wordpress.net/'],
+ ),
+ );
+
+ foreach ( self::$site_ids as &$id ) {
+ $id = $factory->blog->create( $id );
+ }
+ unset( $id );
+ }
- public static function wpTearDownAfterClass() {
- global $wpdb;
-
- foreach ( self::$site_ids as $id ) {
- wp_delete_site( $id );
- }
-
- foreach ( self::$network_ids as $id ) {
- $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->sitemeta} WHERE site_id = %d", $id ) );
- $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->site} WHERE id= %d", $id ) );
- }
+ public static function wpTearDownAfterClass() {
+ global $wpdb;
- wp_update_network_site_counts();
+ foreach ( self::$site_ids as $id ) {
+ wp_delete_site( $id );
}
- /**
- * @ticket 34450
- */
- public function test_get_id_from_blogname_no_www() {
- global $current_site;
+ foreach ( self::$network_ids as $id ) {
+ $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->sitemeta} WHERE site_id = %d", $id ) );
+ $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->site} WHERE id= %d", $id ) );
+ }
- $original_network = $current_site;
- $current_site = get_network( self::$network_ids['wordpress.org/'] );
+ wp_update_network_site_counts();
+ }
- if ( is_subdomain_install() ) {
- $expected = self::$site_ids['foo.wordpress.org/'];
- } else {
- $expected = self::$site_ids['wordpress.org/foo/'];
- }
+ /**
+ * @ticket 34450
+ */
+ public function test_get_id_from_blogname_no_www() {
+ global $current_site;
- $result = get_id_from_blogname( 'foo' );
- $current_site = $original_network;
+ $original_network = $current_site;
+ $current_site = get_network( self::$network_ids['wordpress.org/'] );
- $this->assertSame( $expected, $result );
+ if ( is_subdomain_install() ) {
+ $expected = self::$site_ids['foo.wordpress.org/'];
+ } else {
+ $expected = self::$site_ids['wordpress.org/foo/'];
}
- /**
- * @ticket 34450
- */
- public function test_get_id_from_blogname_www() {
- global $current_site;
+ $result = get_id_from_blogname( 'foo' );
+ $current_site = $original_network;
- $original_network = $current_site;
- $current_site = get_network( self::$network_ids['www.wordpress.net/'] );
+ $this->assertSame( $expected, $result );
+ }
- if ( is_subdomain_install() ) {
- $expected = self::$site_ids['foo.wordpress.net/'];
- } else {
- $expected = self::$site_ids['www.wordpress.net/foo/'];
- }
+ /**
+ * @ticket 34450
+ */
+ public function test_get_id_from_blogname_www() {
+ global $current_site;
- $result = get_id_from_blogname( 'foo' );
- $current_site = $original_network;
+ $original_network = $current_site;
+ $current_site = get_network( self::$network_ids['www.wordpress.net/'] );
- $this->assertSame( $expected, $result );
+ if ( is_subdomain_install() ) {
+ $expected = self::$site_ids['foo.wordpress.net/'];
+ } else {
+ $expected = self::$site_ids['www.wordpress.net/foo/'];
}
- public function test_get_id_from_blogname_invalid_slug() {
- global $current_site;
+ $result = get_id_from_blogname( 'foo' );
+ $current_site = $original_network;
- $original_network = $current_site;
- $current_site = get_network( self::$network_ids['wordpress.org/'] );
+ $this->assertSame( $expected, $result );
+ }
- $result = get_id_from_blogname( 'bar' );
- $current_site = $original_network;
+ public function test_get_id_from_blogname_invalid_slug() {
+ global $current_site;
- $this->assertNull( $result );
- }
- }
+ $original_network = $current_site;
+ $current_site = get_network( self::$network_ids['wordpress.org/'] );
-endif;
+ $result = get_id_from_blogname( 'bar' );
+ $current_site = $original_network;
+
+ $this->assertNull( $result );
+ }
+}
diff --git a/tests/phpunit/tests/multisite/getMainSiteId.php b/tests/phpunit/tests/multisite/getMainSiteId.php
index f68c5409e7..e5f44dce41 100644
--- a/tests/phpunit/tests/multisite/getMainSiteId.php
+++ b/tests/phpunit/tests/multisite/getMainSiteId.php
@@ -1,190 +1,188 @@
<?php
-if ( is_multisite() ) :
-
- /**
- * Tests for the get_main_site_id() function.
- *
- * @group ms-site
- * @group multisite
- */
- class Tests_Multisite_GetMainSiteId extends WP_UnitTestCase {
- protected static $network_ids;
- protected static $site_ids;
-
- public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
- self::$network_ids = array(
- 'wordpress.org/' => array(
- 'domain' => 'wordpress.org',
- 'path' => '/',
- ),
- 'wp.org/' => array(
- 'domain' => 'wp.org',
- 'path' => '/',
- ), // A network with no sites.
- );
-
- foreach ( self::$network_ids as &$id ) {
- $id = $factory->network->create( $id );
- }
- unset( $id );
-
- self::$site_ids = array(
- 'www.w.org/' => array(
- 'domain' => 'www.w.org',
- 'path' => '/',
- ),
- 'wordpress.org/' => array(
- 'domain' => 'wordpress.org',
- 'path' => '/',
- 'network_id' => self::$network_ids['wordpress.org/'],
- ),
- 'wordpress.org/foo/' => array(
- 'domain' => 'wordpress.org',
- 'path' => '/foo/',
- 'network_id' => self::$network_ids['wordpress.org/'],
- ),
- );
-
- foreach ( self::$site_ids as &$id ) {
- $id = $factory->blog->create( $id );
- }
- unset( $id );
+/**
+ * Tests for the get_main_site_id() function.
+ *
+ * @group ms-required
+ * @group ms-site
+ * @group multisite
+ */
+class Tests_Multisite_GetMainSiteId extends WP_UnitTestCase {
+
+ protected static $network_ids;
+ protected static $site_ids;
+
+ public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
+ self::$network_ids = array(
+ 'wordpress.org/' => array(
+ 'domain' => 'wordpress.org',
+ 'path' => '/',
+ ),
+ 'wp.org/' => array(
+ 'domain' => 'wp.org',
+ 'path' => '/',
+ ), // A network with no sites.
+ );
+
+ foreach ( self::$network_ids as &$id ) {
+ $id = $factory->network->create( $id );
}
+ unset( $id );
+
+ self::$site_ids = array(
+ 'www.w.org/' => array(
+ 'domain' => 'www.w.org',
+ 'path' => '/',
+ ),
+ 'wordpress.org/' => array(
+ 'domain' => 'wordpress.org',
+ 'path' => '/',
+ 'network_id' => self::$network_ids['wordpress.org/'],
+ ),
+ 'wordpress.org/foo/' => array(
+ 'domain' => 'wordpress.org',
+ 'path' => '/foo/',
+ 'network_id' => self::$network_ids['wordpress.org/'],
+ ),
+ );
+
+ foreach ( self::$site_ids as &$id ) {
+ $id = $factory->blog->create( $id );
+ }
+ unset( $id );
+ }
- public static function wpTearDownAfterClass() {
- foreach ( self::$site_ids as $id ) {
- wp_delete_site( $id );
- }
-
- global $wpdb;
+ public static function wpTearDownAfterClass() {
+ foreach ( self::$site_ids as $id ) {
+ wp_delete_site( $id );
+ }
- foreach ( self::$network_ids as $id ) {
- $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->sitemeta} WHERE site_id = %d", $id ) );
- $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->site} WHERE id= %d", $id ) );
- }
+ global $wpdb;
- wp_update_network_site_counts();
+ foreach ( self::$network_ids as $id ) {
+ $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->sitemeta} WHERE site_id = %d", $id ) );
+ $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->site} WHERE id= %d", $id ) );
}
- /**
- * @ticket 29684
- */
- public function test_get_main_site_id_on_main_site_returns_self() {
- $this->assertSame( get_current_blog_id(), get_main_site_id() );
- }
+ wp_update_network_site_counts();
+ }
- /**
- * @ticket 29684
- */
- public function test_get_main_site_id_returns_main_site_in_switched_context() {
- $main_site_id = get_current_blog_id();
- $other_site_id = self::$site_ids['www.w.org/'];
+ /**
+ * @ticket 29684
+ */
+ public function test_get_main_site_id_on_main_site_returns_self() {
+ $this->assertSame( get_current_blog_id(), get_main_site_id() );
+ }
- switch_to_blog( $other_site_id );
- $result = get_main_site_id();
- restore_current_blog();
+ /**
+ * @ticket 29684
+ */
+ public function test_get_main_site_id_returns_main_site_in_switched_context() {
+ $main_site_id = get_current_blog_id();
+ $other_site_id = self::$site_ids['www.w.org/'];
- $this->assertSame( $main_site_id, $result );
- }
+ switch_to_blog( $other_site_id );
+ $result = get_main_site_id();
+ restore_current_blog();
- /**
- * @ticket 55802
- */
- public function test_get_main_site_id_with_different_network_cache_id() {
- $this->assertSame( self::$site_ids['wordpress.org/'], get_main_site_id( self::$network_ids['wordpress.org/'] ), 'Main blog id needs to match blog id of wordpress.org/' );
- $this->assertSame( self::$site_ids['wordpress.org/'], (int) get_network_option( self::$network_ids['wordpress.org/'], 'main_site' ), 'Network option needs to match blog id of wordpress.org/' );
+ $this->assertSame( $main_site_id, $result );
+ }
- $this->assertSame( 0, get_main_site_id( self::$network_ids['wp.org/'] ), 'Main blog id should not be found' );
- $this->assertSame( 0, (int) get_network_option( self::$network_ids['wp.org/'], 'main_site' ), 'Network option should not be found' );
- }
+ /**
+ * @ticket 55802
+ */
+ public function test_get_main_site_id_with_different_network_cache_id() {
+ $this->assertSame( self::$site_ids['wordpress.org/'], get_main_site_id( self::$network_ids['wordpress.org/'] ), 'Main blog id needs to match blog id of wordpress.org/' );
+ $this->assertSame( self::$site_ids['wordpress.org/'], (int) get_network_option( self::$network_ids['wordpress.org/'], 'main_site' ), 'Network option needs to match blog id of wordpress.org/' );
- /**
- * @ticket 29684
- */
- public function test_get_main_site_id_with_different_network_returns_correct_id() {
- $this->assertSame( self::$site_ids['wordpress.org/'], get_main_site_id( self::$network_ids['wordpress.org/'] ) );
- }
+ $this->assertSame( 0, get_main_site_id( self::$network_ids['wp.org/'] ), 'Main blog id should not be found' );
+ $this->assertSame( 0, (int) get_network_option( self::$network_ids['wp.org/'], 'main_site' ), 'Network option should not be found' );
+ }
- /**
- * @ticket 29684
- */
- public function test_get_main_site_id_on_network_without_site_returns_0() {
- $this->assertSame( 0, get_main_site_id( self::$network_ids['wp.org/'] ) );
- }
+ /**
+ * @ticket 29684
+ */
+ public function test_get_main_site_id_with_different_network_returns_correct_id() {
+ $this->assertSame( self::$site_ids['wordpress.org/'], get_main_site_id( self::$network_ids['wordpress.org/'] ) );
+ }
- /**
- * @ticket 29684
- */
- public function test_get_main_site_id_on_invalid_network_returns_0() {
- $this->assertSame( 0, get_main_site_id( 333 ) );
- }
+ /**
+ * @ticket 29684
+ */
+ public function test_get_main_site_id_on_network_without_site_returns_0() {
+ $this->assertSame( 0, get_main_site_id( self::$network_ids['wp.org/'] ) );
+ }
- /**
- * @ticket 29684
- */
- public function test_get_main_site_id_filtered() {
- add_filter( 'pre_get_main_site_id', array( $this, 'filter_get_main_site_id' ) );
- $result = get_main_site_id();
+ /**
+ * @ticket 29684
+ */
+ public function test_get_main_site_id_on_invalid_network_returns_0() {
+ $this->assertSame( 0, get_main_site_id( 333 ) );
+ }
- $this->assertSame( 333, $result );
- }
+ /**
+ * @ticket 29684
+ */
+ public function test_get_main_site_id_filtered() {
+ add_filter( 'pre_get_main_site_id', array( $this, 'filter_get_main_site_id' ) );
+ $result = get_main_site_id();
- public function filter_get_main_site_id() {
- return 333;
- }
+ $this->assertSame( 333, $result );
+ }
- /**
- * @ticket 29684
- */
- public function test_get_main_site_id_filtered_depending_on_network() {
- add_filter( 'pre_get_main_site_id', array( $this, 'filter_get_main_site_id_depending_on_network' ), 10, 2 );
- $result = get_main_site_id( self::$network_ids['wordpress.org/'] );
+ public function filter_get_main_site_id() {
+ return 333;
+ }
- $this->assertSame( 333, $result );
- }
+ /**
+ * @ticket 29684
+ */
+ public function test_get_main_site_id_filtered_depending_on_network() {
+ add_filter( 'pre_get_main_site_id', array( $this, 'filter_get_main_site_id_depending_on_network' ), 10, 2 );
+ $result = get_main_site_id( self::$network_ids['wordpress.org/'] );
- public function filter_get_main_site_id_depending_on_network( $main_site_id, $network ) {
- // Override main site ID for a specific network for the test.
- if ( $network->id === (int) self::$network_ids['wordpress.org/'] ) {
- return 333;
- }
+ $this->assertSame( 333, $result );
+ }
- return $main_site_id;
+ public function filter_get_main_site_id_depending_on_network( $main_site_id, $network ) {
+ // Override main site ID for a specific network for the test.
+ if ( $network->id === (int) self::$network_ids['wordpress.org/'] ) {
+ return 333;
}
- /**
- * @ticket 41936
- */
- public function test_get_main_site_id_with_property_value() {
- global $current_site;
+ return $main_site_id;
+ }
- $original_main_site_id = $current_site->blog_id;
- $current_site->blog_id = '123';
+ /**
+ * @ticket 41936
+ */
+ public function test_get_main_site_id_with_property_value() {
+ global $current_site;
- $result = get_main_site_id();
+ $original_main_site_id = $current_site->blog_id;
+ $current_site->blog_id = '123';
- $current_site->blog_id = $original_main_site_id;
+ $result = get_main_site_id();
- $this->assertSame( 123, $result );
- }
+ $current_site->blog_id = $original_main_site_id;
- /**
- * @ticket 41936
- */
- public function test_get_main_site_id_filtered_with_property_value() {
- global $current_site;
+ $this->assertSame( 123, $result );
+ }
+
+ /**
+ * @ticket 41936
+ */
+ public function test_get_main_site_id_filtered_with_property_value() {
+ global $current_site;
- $original_main_site_id = $current_site->blog_id;
- $current_site->blog_id = '123';
+ $original_main_site_id = $current_site->blog_id;
+ $current_site->blog_id = '123';
- add_filter( 'pre_get_main_site_id', array( $this, 'filter_get_main_site_id' ) );
- $result = get_main_site_id();
+ add_filter( 'pre_get_main_site_id', array( $this, 'filter_get_main_site_id' ) );
+ $result = get_main_site_id();
- $current_site->blog_id = $original_main_site_id;
+ $current_site->blog_id = $original_main_site_id;
- $this->assertSame( 333, $result );
- }
+ $this->assertSame( 333, $result );
}
-
-endif;
+}
diff --git a/tests/phpunit/tests/multisite/getSite.php b/tests/phpunit/tests/multisite/getSite.php
index c87f99649c..4b02113275 100644
--- a/tests/phpunit/tests/multisite/getSite.php
+++ b/tests/phpunit/tests/multisite/getSite.php
@@ -1,52 +1,51 @@
<?php
-if ( is_multisite() ) :
- /**
- * Test get_site() wrapper of WP_Site in multisite.
- *
- * @group ms-site
- * @group multisite
- */
- class Tests_Multisite_GetSite extends WP_UnitTestCase {
- protected static $site_ids;
-
- public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
- self::$site_ids = array(
- 'wordpress.org/' => array(
- 'domain' => 'wordpress.org',
- 'path' => '/',
- ),
- 'wordpress.org/foo/' => array(
- 'domain' => 'wordpress.org',
- 'path' => '/foo/',
- ),
- 'wordpress.org/foo/bar/' => array(
- 'domain' => 'wordpress.org',
- 'path' => '/foo/bar/',
- ),
- );
-
- foreach ( self::$site_ids as &$id ) {
- $id = $factory->blog->create( $id );
- }
- unset( $id );
+/**
+ * Test get_site() wrapper of WP_Site in multisite.
+ *
+ * @group ms-required
+ * @group ms-site
+ * @group multisite
+ */
+class Tests_Multisite_GetSite extends WP_UnitTestCase {
+
+ protected static $site_ids;
+
+ public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
+ self::$site_ids = array(
+ 'wordpress.org/' => array(
+ 'domain' => 'wordpress.org',
+ 'path' => '/',
+ ),
+ 'wordpress.org/foo/' => array(
+ 'domain' => 'wordpress.org',
+ 'path' => '/foo/',
+ ),
+ 'wordpress.org/foo/bar/' => array(
+ 'domain' => 'wordpress.org',
+ 'path' => '/foo/bar/',
+ ),
+ );
+
+ foreach ( self::$site_ids as &$id ) {
+ $id = $factory->blog->create( $id );
}
+ unset( $id );
+ }
- public static function wpTearDownAfterClass() {
- foreach ( self::$site_ids as $id ) {
- wp_delete_site( $id );
- }
-
- wp_update_network_site_counts();
+ public static function wpTearDownAfterClass() {
+ foreach ( self::$site_ids as $id ) {
+ wp_delete_site( $id );
}
- public function test_get_site_in_switched_state_returns_switched_site() {
- switch_to_blog( self::$site_ids['wordpress.org/foo/'] );
- $site = get_site();
- restore_current_blog();
-
- $this->assertSame( self::$site_ids['wordpress.org/foo/'], $site->id );
- }
+ wp_update_network_site_counts();
}
-endif;
+ public function test_get_site_in_switched_state_returns_switched_site() {
+ switch_to_blog( self::$site_ids['wordpress.org/foo/'] );
+ $site = get_site();
+ restore_current_blog();
+
+ $this->assertSame( self::$site_ids['wordpress.org/foo/'], $site->id );
+ }
+}
diff --git a/tests/phpunit/tests/multisite/getSpaceAllowed.php b/tests/phpunit/tests/multisite/getSpaceAllowed.php
index 5e87fc0087..132f39c98d 100644
--- a/tests/phpunit/tests/multisite/getSpaceAllowed.php
+++ b/tests/phpunit/tests/multisite/getSpaceAllowed.php
@@ -1,88 +1,85 @@
<?php
-if ( is_multisite() ) :
+/**
+ * Tests specific to `get_space_allowed()` in multisite.
+ *
+ * @group ms-required
+ * @group multisite
+ */
+class Tests_Multisite_GetSpaceAllowed extends WP_UnitTestCase {
/**
- * Tests specific to `get_space_allowed()` in multisite.
- *
- * @group multisite
+ * When no option exists for the site or the network, a fallback of
+ * 100 is expected.
*/
- class Tests_Multisite_GetSpaceAllowed extends WP_UnitTestCase {
-
- /**
- * When no option exists for the site or the network, a fallback of
- * 100 is expected.
- */
- public function test_get_space_allowed_default() {
- delete_option( 'blog_upload_space' );
- delete_site_option( 'blog_upload_space' );
-
- $this->assertSame( 100, get_space_allowed() );
- }
-
- /**
- * If an individual site's option is not available, the default network
- * level option is used as a fallback.
- */
- public function test_get_space_allowed_no_site_option_fallback_to_network_option() {
- delete_site_option( 'blog_upload_space' );
- update_site_option( 'blog_upload_space', 200 );
+ public function test_get_space_allowed_default() {
+ delete_option( 'blog_upload_space' );
+ delete_site_option( 'blog_upload_space' );
- $this->assertSame( 200, get_space_allowed() );
- }
-
- /**
- * @dataProvider data_blog_upload_space
- *
- * @param mixed $site_option Option to assign to the site's `blog_upload_space`.
- * @param mixed $network_option Option to assign to the network's `blog_upload_space`.
- * @param int $expected Expected return value.
- */
- public function test_get_space_allowed( $site_option, $network_option, $expected ) {
- update_option( 'blog_upload_space', $site_option );
- update_site_option( 'blog_upload_space', $network_option );
-
- $this->assertSame( $expected, get_space_allowed() );
- }
+ $this->assertSame( 100, get_space_allowed() );
+ }
- public function data_blog_upload_space() {
- return array(
- // A valid site option will be preferred over a network option.
- array( 111, 200, 111 ),
- array( -1, 200, -1 ),
- array( 222, 0, 222 ),
+ /**
+ * If an individual site's option is not available, the default network
+ * level option is used as a fallback.
+ */
+ public function test_get_space_allowed_no_site_option_fallback_to_network_option() {
+ delete_site_option( 'blog_upload_space' );
+ update_site_option( 'blog_upload_space', 200 );
- // Non-numeric site options should result in a fallback to the network option.
- array( '', 333, 333 ),
- array( false, 444, 444 ),
- array( 'NAN', 555, 555 ),
- array( false, -10, -10 ),
+ $this->assertSame( 200, get_space_allowed() );
+ }
- // If neither network or site options are valid, fallback to the default.
- array( false, false, 100 ),
- array( 'NAN', 'NAN', 100 ),
+ /**
+ * @dataProvider data_blog_upload_space
+ *
+ * @param mixed $site_option Option to assign to the site's `blog_upload_space`.
+ * @param mixed $network_option Option to assign to the network's `blog_upload_space`.
+ * @param int $expected Expected return value.
+ */
+ public function test_get_space_allowed( $site_option, $network_option, $expected ) {
+ update_option( 'blog_upload_space', $site_option );
+ update_site_option( 'blog_upload_space', $network_option );
- // These effectively disable uploads.
- array( 0, 666, 0 ),
- array( false, 0, 0 ),
- array( 'NAN', 0, 0 ),
- );
- }
+ $this->assertSame( $expected, get_space_allowed() );
+ }
- public function test_get_space_allowed_filtered() {
- update_option( 'blog_upload_space', 777 );
- update_site_option( 'blog_upload_space', 888 );
+ public function data_blog_upload_space() {
+ return array(
+ // A valid site option will be preferred over a network option.
+ array( 111, 200, 111 ),
+ array( -1, 200, -1 ),
+ array( 222, 0, 222 ),
+
+ // Non-numeric site options should result in a fallback to the network option.
+ array( '', 333, 333 ),
+ array( false, 444, 444 ),
+ array( 'NAN', 555, 555 ),
+ array( false, -10, -10 ),
+
+ // If neither network or site options are valid, fallback to the default.
+ array( false, false, 100 ),
+ array( 'NAN', 'NAN', 100 ),
+
+ // These effectively disable uploads.
+ array( 0, 666, 0 ),
+ array( false, 0, 0 ),
+ array( 'NAN', 0, 0 ),
+ );
+ }
- add_filter( 'get_space_allowed', array( $this, '_filter_space_allowed' ) );
- $space_allowed = get_space_allowed();
- remove_filter( 'get_space_allowed', array( $this, '_filter_space_allowed' ) );
+ public function test_get_space_allowed_filtered() {
+ update_option( 'blog_upload_space', 777 );
+ update_site_option( 'blog_upload_space', 888 );
- $this->assertSame( 999, $space_allowed );
- }
+ add_filter( 'get_space_allowed', array( $this, '_filter_space_allowed' ) );
+ $space_allowed = get_space_allowed();
+ remove_filter( 'get_space_allowed', array( $this, '_filter_space_allowed' ) );
- public function _filter_space_allowed() {
- return 999;
- }
+ $this->assertSame( 999, $space_allowed );
}
-endif;
+ public function _filter_space_allowed() {
+ return 999;
+ }
+}
diff --git a/tests/phpunit/tests/multisite/getSpaceUsed.php b/tests/phpunit/tests/multisite/getSpaceUsed.php
index ac5aec6904..bd7916bc5b 100644
--- a/tests/phpunit/tests/multisite/getSpaceUsed.php
+++ b/tests/phpunit/tests/multisite/getSpaceUsed.php
@@ -1,91 +1,89 @@
<?php
-if ( is_multisite() ) :
+/**
+ * @group ms-required
+ * @group multisite
+ * @covers ::get_space_used
+ */
+class Tests_Multisite_GetSpaceUsed extends WP_UnitTestCase {
+
+ public function test_get_space_used_switched_site() {
+ $blog_id = self::factory()->blog->create();
+ switch_to_blog( $blog_id );
+
+ // Our comparison of space relies on an initial value of 0. If a previous test has failed or if the
+ // src directory already contains a content directory with site content, then the initial expectation
+ // will be polluted. We create sites until an empty one is available.
+ while ( 0 !== get_space_used() ) {
+ restore_current_blog();
+ $blog_id = self::factory()->blog->create();
+ switch_to_blog( $blog_id );
+ }
+
+ // Upload a file to the new site.
+ $filename = __FUNCTION__ . '.jpg';
+ $contents = __FUNCTION__ . '_contents';
+ $file = wp_upload_bits( $filename, null, $contents );
+
+ // get_space_used() is measures in MB, get the size of the new file in MB.
+ $size = filesize( $file['file'] ) / 1024 / 1024;
+
+ delete_transient( 'dirsize_cache' );
+
+ $this->assertSame( $size, get_space_used() );
+ $upload_dir = wp_upload_dir();
+ $this->remove_added_uploads();
+ $this->delete_folders( $upload_dir['basedir'] );
+ restore_current_blog();
+ }
/**
- * @group multisite
- * @covers ::get_space_used
+ * Directories of sub sites on a network should not count against the same spaced used total for
+ * the main site.
*/
- class Tests_Multisite_GetSpaceUsed extends WP_UnitTestCase {
+ public function test_get_space_used_main_site() {
+ $space_used = get_space_used();
- public function test_get_space_used_switched_site() {
- $blog_id = self::factory()->blog->create();
- switch_to_blog( $blog_id );
+ $blog_id = self::factory()->blog->create();
+ switch_to_blog( $blog_id );
- // Our comparison of space relies on an initial value of 0. If a previous test has failed or if the
- // src directory already contains a content directory with site content, then the initial expectation
- // will be polluted. We create sites until an empty one is available.
- while ( 0 !== get_space_used() ) {
- restore_current_blog();
- $blog_id = self::factory()->blog->create();
- switch_to_blog( $blog_id );
- }
-
- // Upload a file to the new site.
- $filename = __FUNCTION__ . '.jpg';
- $contents = __FUNCTION__ . '_contents';
- $file = wp_upload_bits( $filename, null, $contents );
-
- // get_space_used() is measures in MB, get the size of the new file in MB.
- $size = filesize( $file['file'] ) / 1024 / 1024;
-
- delete_transient( 'dirsize_cache' );
-
- $this->assertSame( $size, get_space_used() );
- $upload_dir = wp_upload_dir();
- $this->remove_added_uploads();
- $this->delete_folders( $upload_dir['basedir'] );
+ // We don't rely on an initial value of 0 for space used, but should have a clean space available
+ // so that we can remove any uploaded files and directories without concern of a conflict with
+ // existing content directories in src.
+ while ( 0 !== get_space_used() ) {
restore_current_blog();
- }
-
- /**
- * Directories of sub sites on a network should not count against the same spaced used total for
- * the main site.
- */
- public function test_get_space_used_main_site() {
- $space_used = get_space_used();
-
$blog_id = self::factory()->blog->create();
switch_to_blog( $blog_id );
+ }
- // We don't rely on an initial value of 0 for space used, but should have a clean space available
- // so that we can remove any uploaded files and directories without concern of a conflict with
- // existing content directories in src.
- while ( 0 !== get_space_used() ) {
- restore_current_blog();
- $blog_id = self::factory()->blog->create();
- switch_to_blog( $blog_id );
- }
-
- // Upload a file to the new site.
- $filename = __FUNCTION__ . '.jpg';
- $contents = __FUNCTION__ . '_contents';
- wp_upload_bits( $filename, null, $contents );
+ // Upload a file to the new site.
+ $filename = __FUNCTION__ . '.jpg';
+ $contents = __FUNCTION__ . '_contents';
+ wp_upload_bits( $filename, null, $contents );
- restore_current_blog();
+ restore_current_blog();
- delete_transient( 'dirsize_cache' );
+ delete_transient( 'dirsize_cache' );
- $this->assertSame( $space_used, get_space_used() );
+ $this->assertSame( $space_used, get_space_used() );
- // Switch back to the new site to remove the uploaded file.
- switch_to_blog( $blog_id );
- $upload_dir = wp_upload_dir();
- $this->remove_added_uploads();
- $this->delete_folders( $upload_dir['basedir'] );
- restore_current_blog();
- }
+ // Switch back to the new site to remove the uploaded file.
+ switch_to_blog( $blog_id );
+ $upload_dir = wp_upload_dir();
+ $this->remove_added_uploads();
+ $this->delete_folders( $upload_dir['basedir'] );
+ restore_current_blog();
+ }
- public function test_get_space_used_pre_get_spaced_used_filter() {
- add_filter( 'pre_get_space_used', array( $this, 'filter_space_used' ) );
+ public function test_get_space_used_pre_get_spaced_used_filter() {
+ add_filter( 'pre_get_space_used', array( $this, 'filter_space_used' ) );
- $this->assertSame( 300, get_space_used() );
+ $this->assertSame( 300, get_space_used() );
- remove_filter( 'pre_get_space_used', array( $this, 'filter_space_used' ) );
- }
+ remove_filter( 'pre_get_space_used', array( $this, 'filter_space_used' ) );
+ }
- public function filter_space_used() {
- return 300;
- }
+ public function filter_space_used() {
+ return 300;
}
-endif;
+}
diff --git a/tests/phpunit/tests/multisite/isEmailAddressUnsafe.php b/tests/phpunit/tests/multisite/isEmailAddressUnsafe.php
index 93724a84ae..38d17d9ed0 100644
--- a/tests/phpunit/tests/multisite/isEmailAddressUnsafe.php
+++ b/tests/phpunit/tests/multisite/isEmailAddressUnsafe.php
@@ -1,140 +1,138 @@
<?php
-if ( is_multisite() ) :
+/**
+ * @group ms-required
+ * @group multisite
+ */
+class Tests_Multisite_IsEmailAddressUnsafe extends WP_UnitTestCase {
+
+ public function test_string_domain_list_should_be_split_on_line_breaks() {
+ update_site_option( 'banned_email_domains', "foo.com\nbar.org\nbaz.gov" );
+ $this->assertTrue( is_email_address_unsafe( 'foo@bar.org' ) );
+ $this->assertFalse( is_email_address_unsafe( 'foo@example.org' ) );
+ }
/**
- * @group multisite
+ * @dataProvider data_unsafe
+ * @ticket 25046
+ * @ticket 21570
*/
- class Tests_Multisite_IsEmailAddressUnsafe extends WP_UnitTestCase {
- public function test_string_domain_list_should_be_split_on_line_breaks() {
- update_site_option( 'banned_email_domains', "foo.com\nbar.org\nbaz.gov" );
- $this->assertTrue( is_email_address_unsafe( 'foo@bar.org' ) );
- $this->assertFalse( is_email_address_unsafe( 'foo@example.org' ) );
- }
-
- /**
- * @dataProvider data_unsafe
- * @ticket 25046
- * @ticket 21570
- */
- public function test_unsafe_emails( $banned, $email ) {
- update_site_option( 'banned_email_domains', $banned );
- $this->assertTrue( is_email_address_unsafe( $email ) );
- }
+ public function test_unsafe_emails( $banned, $email ) {
+ update_site_option( 'banned_email_domains', $banned );
+ $this->assertTrue( is_email_address_unsafe( $email ) );
+ }
- /**
- * @dataProvider data_safe
- * @ticket 25046
- * @ticket 21570
- */
- public function test_safe_emails( $banned, $email ) {
- update_site_option( 'banned_email_domains', $banned );
- $this->assertFalse( is_email_address_unsafe( $email ) );
- }
+ /**
+ * @dataProvider data_safe
+ * @ticket 25046
+ * @ticket 21570
+ */
+ public function test_safe_emails( $banned, $email ) {
+ update_site_option( 'banned_email_domains', $banned );
+ $this->assertFalse( is_email_address_unsafe( $email ) );
+ }
- public function data_unsafe() {
- return array(
- // 25046
- 'case_insensitive_1' => array(
- array( 'baR.com' ),
- 'test@Bar.com',
- ),
- 'case_insensitive_2' => array(
- array( 'baR.com' ),
- 'tEst@bar.com',
- ),
- 'case_insensitive_3' => array(
- array( 'barfoo.COM' ),
- 'test@barFoo.com',
- ),
- 'case_insensitive_4' => array(
- array( 'baR.com' ),
- 'tEst@foo.bar.com',
- ),
- 'case_insensitive_5' => array(
- array( 'BAZ.com' ),
- 'test@baz.Com',
- ),
+ public function data_unsafe() {
+ return array(
+ // 25046
+ 'case_insensitive_1' => array(
+ array( 'baR.com' ),
+ 'test@Bar.com',
+ ),
+ 'case_insensitive_2' => array(
+ array( 'baR.com' ),
+ 'tEst@bar.com',
+ ),
+ 'case_insensitive_3' => array(
+ array( 'barfoo.COM' ),
+ 'test@barFoo.com',
+ ),
+ 'case_insensitive_4' => array(
+ array( 'baR.com' ),
+ 'tEst@foo.bar.com',
+ ),
+ 'case_insensitive_5' => array(
+ array( 'BAZ.com' ),
+ 'test@baz.Com',
+ ),
- // 21570
- array(
- array( 'bar.com', 'foo.co' ),
- 'test@bar.com',
- ),
- 'subdomain_1' => array(
- array( 'bar.com', 'foo.co' ),
- 'test@foo.bar.com',
- ),
- array(
- array( 'bar.com', 'foo.co' ),
- 'test@foo.co',
- ),
- 'subdomain_2' => array(
- array( 'bar.com', 'foo.co' ),
- 'test@subdomain.foo.co',
- ),
- );
- }
+ // 21570
+ array(
+ array( 'bar.com', 'foo.co' ),
+ 'test@bar.com',
+ ),
+ 'subdomain_1' => array(
+ array( 'bar.com', 'foo.co' ),
+ 'test@foo.bar.com',
+ ),
+ array(
+ array( 'bar.com', 'foo.co' ),
+ 'test@foo.co',
+ ),
+ 'subdomain_2' => array(
+ array( 'bar.com', 'foo.co' ),
+ 'test@subdomain.foo.co',
+ ),
+ );
+ }
- public function data_safe() {
- return array(
- // 25046
- array(
- array( 'baR.com', 'Foo.co', 'barfoo.COM', 'BAZ.com' ),
- 'test@Foobar.com',
- ),
- array(
- array( 'baR.com', 'Foo.co', 'barfoo.COM', 'BAZ.com' ),
- 'test@Foo-bar.com',
- ),
- array(
- array( 'baR.com', 'Foo.co', 'barfoo.COM', 'BAZ.com' ),
- 'tEst@foobar.com',
- ),
- array(
- array( 'baR.com', 'Foo.co', 'barfoo.COM', 'BAZ.com' ),
- 'test@Subdomain.Foo.com',
- ),
- array(
- array( 'baR.com', 'Foo.co', 'barfoo.COM', 'BAZ.com' ),
- 'test@feeBAz.com',
- ),
+ public function data_safe() {
+ return array(
+ // 25046
+ array(
+ array( 'baR.com', 'Foo.co', 'barfoo.COM', 'BAZ.com' ),
+ 'test@Foobar.com',
+ ),
+ array(
+ array( 'baR.com', 'Foo.co', 'barfoo.COM', 'BAZ.com' ),
+ 'test@Foo-bar.com',
+ ),
+ array(
+ array( 'baR.com', 'Foo.co', 'barfoo.COM', 'BAZ.com' ),
+ 'tEst@foobar.com',
+ ),
+ array(
+ array( 'baR.com', 'Foo.co', 'barfoo.COM', 'BAZ.com' ),
+ 'test@Subdomain.Foo.com',
+ ),
+ array(
+ array( 'baR.com', 'Foo.co', 'barfoo.COM', 'BAZ.com' ),
+ 'test@feeBAz.com',
+ ),
- // 21570
- array(
- array( 'bar.com', 'foo.co' ),
- 'test@foobar.com',
- ),
- array(
- array( 'bar.com', 'foo.co' ),
- 'test@foo-bar.com',
- ),
- array(
- array( 'bar.com', 'foo.co' ),
- 'test@foo.com',
- ),
- array(
- array( 'bar.com', 'foo.co' ),
- 'test@subdomain.foo.com',
- ),
- );
- }
+ // 21570
+ array(
+ array( 'bar.com', 'foo.co' ),
+ 'test@foobar.com',
+ ),
+ array(
+ array( 'bar.com', 'foo.co' ),
+ 'test@foo-bar.com',
+ ),
+ array(
+ array( 'bar.com', 'foo.co' ),
+ 'test@foo.com',
+ ),
+ array(
+ array( 'bar.com', 'foo.co' ),
+ 'test@subdomain.foo.com',
+ ),
+ );
+ }
- public function test_email_with_only_top_level_domain_returns_safe() {
- update_site_option( 'banned_email_domains', 'bar.com' );
- $safe = is_email_address_unsafe( 'email@localhost' );
- delete_site_option( 'banned_email_domains' );
+ public function test_email_with_only_top_level_domain_returns_safe() {
+ update_site_option( 'banned_email_domains', 'bar.com' );
+ $safe = is_email_address_unsafe( 'email@localhost' );
+ delete_site_option( 'banned_email_domains' );
- $this->assertFalse( $safe );
- }
+ $this->assertFalse( $safe );
+ }
- public function test_invalid_email_without_domain_returns_safe() {
- update_site_option( 'banned_email_domains', 'bar.com' );
- $safe = is_email_address_unsafe( 'invalid-email' );
- delete_site_option( 'bar.com' );
+ public function test_invalid_email_without_domain_returns_safe() {
+ update_site_option( 'banned_email_domains', 'bar.com' );
+ $safe = is_email_address_unsafe( 'invalid-email' );
+ delete_site_option( 'bar.com' );
- $this->assertFalse( $safe );
- }
+ $this->assertFalse( $safe );
}
-
-endif;
+}
diff --git a/tests/phpunit/tests/multisite/isUploadSpaceAvailable.php b/tests/phpunit/tests/multisite/isUploadSpaceAvailable.php
index e2a11e0578..62c9dc6c97 100644
--- a/tests/phpunit/tests/multisite/isUploadSpaceAvailable.php
+++ b/tests/phpunit/tests/multisite/isUploadSpaceAvailable.php
@@ -1,99 +1,96 @@
<?php
-if ( is_multisite() ) :
+/**
+ * Tests specific to `is_upload_space_available()` in multisite.
+ *
+ * These tests filter `pre_get_space_used` so that we can ignore the local
+ * environment. Tests for `get_space_used()` are handled elsewhere.
+ *
+ * @group ms-required
+ * @group multisite
+ */
+class Tests_Multisite_IsUploadSpaceAvailable extends WP_UnitTestCase {
+
+ public function set_up() {
+ parent::set_up();
+ update_site_option( 'upload_space_check_disabled', false );
+ }
/**
- * Tests specific to `is_upload_space_available()` in multisite.
- *
- * These tests filter `pre_get_space_used` so that we can ignore the local
- * environment. Tests for `get_space_used()` are handled elsewhere.
- *
- * @group multisite
+ * A default of 100MB is used when no `blog_upload_space` option
+ * exists at the site or network level.
*/
- class Tests_Multisite_IsUploadSpaceAvailable extends WP_UnitTestCase {
-
- public function set_up() {
- parent::set_up();
- update_site_option( 'upload_space_check_disabled', false );
- }
-
- /**
- * A default of 100MB is used when no `blog_upload_space` option
- * exists at the site or network level.
- */
- public function test_is_upload_space_available_default() {
- delete_option( 'blog_upload_space' );
- delete_site_option( 'blog_upload_space' );
-
- add_filter( 'pre_get_space_used', array( $this, 'filter_space_used_small' ) );
- $available = is_upload_space_available();
- remove_filter( 'pre_get_space_used', array( $this, 'filter_space_used_small' ) );
+ public function test_is_upload_space_available_default() {
+ delete_option( 'blog_upload_space' );
+ delete_site_option( 'blog_upload_space' );
- $this->assertTrue( $available );
- }
+ add_filter( 'pre_get_space_used', array( $this, 'filter_space_used_small' ) );
+ $available = is_upload_space_available();
+ remove_filter( 'pre_get_space_used', array( $this, 'filter_space_used_small' ) );
- public function test_is_upload_space_available_check_disabled() {
- update_site_option( 'blog_upload_space', 10 );
- update_site_option( 'upload_space_check_disabled', true );
+ $this->assertTrue( $available );
+ }
- add_filter( 'pre_get_space_used', array( $this, 'filter_space_used_large' ) );
- $available = is_upload_space_available();
- remove_filter( 'pre_get_space_used', array( $this, 'filter_space_used_large' ) );
+ public function test_is_upload_space_available_check_disabled() {
+ update_site_option( 'blog_upload_space', 10 );
+ update_site_option( 'upload_space_check_disabled', true );
- $this->assertTrue( $available );
- }
+ add_filter( 'pre_get_space_used', array( $this, 'filter_space_used_large' ) );
+ $available = is_upload_space_available();
+ remove_filter( 'pre_get_space_used', array( $this, 'filter_space_used_large' ) );
- public function test_is_upload_space_available_space_used_is_less_then_allowed() {
- update_option( 'blog_upload_space', 350 );
+ $this->assertTrue( $available );
+ }
- add_filter( 'pre_get_space_used', array( $this, 'filter_space_used_small' ) );
- $available = is_upload_space_available();
- remove_filter( 'pre_get_space_used', array( $this, 'filter_space_used_small' ) );
+ public function test_is_upload_space_available_space_used_is_less_then_allowed() {
+ update_option( 'blog_upload_space', 350 );
- $this->assertTrue( $available );
- }
+ add_filter( 'pre_get_space_used', array( $this, 'filter_space_used_small' ) );
+ $available = is_upload_space_available();
+ remove_filter( 'pre_get_space_used', array( $this, 'filter_space_used_small' ) );
- public function test_is_upload_space_available_space_used_is_more_than_allowed() {
- update_option( 'blog_upload_space', 350 );
+ $this->assertTrue( $available );
+ }
- add_filter( 'pre_get_space_used', array( $this, 'filter_space_used_large' ) );
- $available = is_upload_space_available();
- remove_filter( 'pre_get_space_used', array( $this, 'filter_space_used_large' ) );
+ public function test_is_upload_space_available_space_used_is_more_than_allowed() {
+ update_option( 'blog_upload_space', 350 );
- $this->assertFalse( $available );
- }
+ add_filter( 'pre_get_space_used', array( $this, 'filter_space_used_large' ) );
+ $available = is_upload_space_available();
+ remove_filter( 'pre_get_space_used', array( $this, 'filter_space_used_large' ) );
- /**
- * More comprehensive testing a 0 condition is handled in the tests
- * for `get_space_allowed()`. We cover one scenario here.
- */
- public function test_is_upload_space_available_upload_space_0_defaults_to_100() {
- update_option( 'blog_upload_space', 0 );
+ $this->assertFalse( $available );
+ }
- add_filter( 'pre_get_space_used', array( $this, 'filter_space_used_small' ) );
- $available = is_upload_space_available();
- remove_filter( 'pre_get_space_used', array( $this, 'filter_space_used_small' ) );
+ /**
+ * More comprehensive testing a 0 condition is handled in the tests
+ * for `get_space_allowed()`. We cover one scenario here.
+ */
+ public function test_is_upload_space_available_upload_space_0_defaults_to_100() {
+ update_option( 'blog_upload_space', 0 );
- $this->assertFalse( $available );
- }
+ add_filter( 'pre_get_space_used', array( $this, 'filter_space_used_small' ) );
+ $available = is_upload_space_available();
+ remove_filter( 'pre_get_space_used', array( $this, 'filter_space_used_small' ) );
- public function test_is_upload_space_available_upload_space_negative() {
- update_site_option( 'blog_upload_space', -1 );
+ $this->assertFalse( $available );
+ }
- add_filter( 'pre_get_space_used', array( $this, 'filter_space_used_small' ) );
- $available = is_upload_space_available();
- remove_filter( 'pre_get_space_used', array( $this, 'filter_space_used_small' ) );
+ public function test_is_upload_space_available_upload_space_negative() {
+ update_site_option( 'blog_upload_space', -1 );
- $this->assertFalse( $available );
- }
+ add_filter( 'pre_get_space_used', array( $this, 'filter_space_used_small' ) );
+ $available = is_upload_space_available();
+ remove_filter( 'pre_get_space_used', array( $this, 'filter_space_used_small' ) );
- public function filter_space_used_large() {
- return 10000000;
- }
+ $this->assertFalse( $available );
+ }
- public function filter_space_used_small() {
- return 10;
- }
+ public function filter_space_used_large() {
+ return 10000000;
}
-endif;
+ public function filter_space_used_small() {
+ return 10;
+ }
+}
diff --git a/tests/phpunit/tests/multisite/msFilesRewriting.php b/tests/phpunit/tests/multisite/msFilesRewriting.php
index 7d469769ba..92b8e60118 100644
--- a/tests/phpunit/tests/multisite/msFilesRewriting.php
+++ b/tests/phpunit/tests/multisite/msFilesRewriting.php
@@ -1,80 +1,77 @@
<?php
-if ( is_multisite() ) :
+/**
+ * Tests specific to the ms_files_rewriting option in multisite.
+ *
+ * The ms-files group tag must be used for these tests to run as the constants
+ * set in ms_upload_constants() conflict with a non ms-files configuration.
+ *
+ * @group ms-files
+ * @group ms-required
+ * @group multisite
+ */
+class Tests_Multisite_msFilesRewriting extends WP_UnitTestCase {
+
+ public function set_up() {
+ parent::set_up();
+ update_site_option( 'ms_files_rewriting', 1 );
+ ms_upload_constants();
+ }
+
+ public function test_switch_upload_dir() {
+ $this->assertTrue( is_main_site() );
+
+ $site = get_current_site();
+ $date = date_format( date_create( 'now' ), 'Y/m' );
+
+ $user_id = self::factory()->user->create( array( 'role' => 'administrator' ) );
+ $blog_id2 = self::factory()->blog->create( array( 'user_id' => $user_id ) );
+ $info = wp_upload_dir();
+ $this->assertSame( 'http://' . $site->domain . '/wp-content/uploads/' . $date, $info['url'] );
+ $this->assertSame( ABSPATH . 'wp-content/uploads/' . $date, $info['path'] );
+ $this->assertSame( '/' . $date, $info['subdir'] );
+ $this->assertFalse( $info['error'] );
+
+ switch_to_blog( $blog_id2 );
+ $info2 = wp_upload_dir();
+ $this->assertNotEquals( $info, $info2 );
+ $this->assertSame( get_option( 'siteurl' ) . '/wp-content/blogs.dir/' . get_current_blog_id() . '/files/' . $date, $info2['url'] );
+ $this->assertSame( ABSPATH . 'wp-content/blogs.dir/' . get_current_blog_id() . '/files/' . $date, $info2['path'] );
+ $this->assertSame( '/' . $date, $info2['subdir'] );
+ $this->assertFalse( $info2['error'] );
+ restore_current_blog();
+ }
/**
- * Tests specific to the ms_files_rewriting option in multisite.
- *
- * The ms-files group tag must be used for these tests to run as the constants
- * set in ms_upload_constants() conflict with a non ms-files configuration.
- *
- * @group ms-files
- * @group multisite
+ * When a site is deleted with wpmu_delete_blog(), only the files associated with
+ * that site should be removed. When wpmu_delete_blog() is run a second time, nothing
+ * should change with upload directories.
*/
- class Tests_Multisite_msFilesRewriting extends WP_UnitTestCase {
-
- public function set_up() {
- parent::set_up();
- update_site_option( 'ms_files_rewriting', 1 );
- ms_upload_constants();
- }
-
- public function test_switch_upload_dir() {
- $this->assertTrue( is_main_site() );
+ public function test_upload_directories_after_multiple_wpmu_delete_blog_with_ms_files() {
+ $filename = __FUNCTION__ . '.jpg';
+ $contents = __FUNCTION__ . '_contents';
- $site = get_current_site();
- $date = date_format( date_create( 'now' ), 'Y/m' );
+ // Upload a file to the main site on the network.
+ $file1 = wp_upload_bits( $filename, null, $contents );
- $user_id = self::factory()->user->create( array( 'role' => 'administrator' ) );
- $blog_id2 = self::factory()->blog->create( array( 'user_id' => $user_id ) );
- $info = wp_upload_dir();
- $this->assertSame( 'http://' . $site->domain . '/wp-content/uploads/' . $date, $info['url'] );
- $this->assertSame( ABSPATH . 'wp-content/uploads/' . $date, $info['path'] );
- $this->assertSame( '/' . $date, $info['subdir'] );
- $this->assertFalse( $info['error'] );
+ $blog_id = self::factory()->blog->create();
- switch_to_blog( $blog_id2 );
- $info2 = wp_upload_dir();
- $this->assertNotEquals( $info, $info2 );
- $this->assertSame( get_option( 'siteurl' ) . '/wp-content/blogs.dir/' . get_current_blog_id() . '/files/' . $date, $info2['url'] );
- $this->assertSame( ABSPATH . 'wp-content/blogs.dir/' . get_current_blog_id() . '/files/' . $date, $info2['path'] );
- $this->assertSame( '/' . $date, $info2['subdir'] );
- $this->assertFalse( $info2['error'] );
- restore_current_blog();
- }
+ switch_to_blog( $blog_id );
+ $file2 = wp_upload_bits( $filename, null, $contents );
+ restore_current_blog();
- /**
- * When a site is deleted with wpmu_delete_blog(), only the files associated with
- * that site should be removed. When wpmu_delete_blog() is run a second time, nothing
- * should change with upload directories.
- */
- public function test_upload_directories_after_multiple_wpmu_delete_blog_with_ms_files() {
- $filename = __FUNCTION__ . '.jpg';
- $contents = __FUNCTION__ . '_contents';
+ wpmu_delete_blog( $blog_id, true );
- // Upload a file to the main site on the network.
- $file1 = wp_upload_bits( $filename, null, $contents );
+ // The file on the main site should still exist. The file on the deleted site should not.
+ $this->assertFileExists( $file1['file'] );
+ $this->assertFileDoesNotExist( $file2['file'] );
- $blog_id = self::factory()->blog->create();
+ wpmu_delete_blog( $blog_id, true );
- switch_to_blog( $blog_id );
- $file2 = wp_upload_bits( $filename, null, $contents );
- restore_current_blog();
+ // The file on the main site should still exist. The file on the deleted site should not.
+ $this->assertFileExists( $file1['file'] );
+ $this->assertFileDoesNotExist( $file2['file'] );
- wpmu_delete_blog( $blog_id, true );
-
- // The file on the main site should still exist. The file on the deleted site should not.
- $this->assertFileExists( $file1['file'] );
- $this->assertFileDoesNotExist( $file2['file'] );
-
- wpmu_delete_blog( $blog_id, true );
-
- // The file on the main site should still exist. The file on the deleted site should not.
- $this->assertFileExists( $file1['file'] );
- $this->assertFileDoesNotExist( $file2['file'] );
-
- unlink( $file1['file'] );
- }
+ unlink( $file1['file'] );
}
-
-endif;
+}
diff --git a/tests/phpunit/tests/multisite/network.php b/tests/phpunit/tests/multisite/network.php
index 71e80383f2..3a5babfe0c 100644
--- a/tests/phpunit/tests/multisite/network.php
+++ b/tests/phpunit/tests/multisite/network.php
@@ -1,694 +1,692 @@
<?php
-if ( is_multisite() ) :
+/**
+ * Tests specific to networks in multisite.
+ *
+ * @group ms-network
+ * @group ms-required
+ * @group multisite
+ */
+class Tests_Multisite_Network extends WP_UnitTestCase {
+
+ protected $plugin_hook_count = 0;
+
+ protected static $different_network_id;
+ protected static $different_site_ids = array();
+
+ public function tear_down() {
+ global $current_site;
+ $current_site->id = 1;
+ parent::tear_down();
+ }
+
+ public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
+ self::$different_network_id = $factory->network->create(
+ array(
+ 'domain' => 'wordpress.org',
+ 'path' => '/',
+ )
+ );
+
+ $sites = array(
+ array(
+ 'domain' => 'wordpress.org',
+ 'path' => '/',
+ 'network_id' => self::$different_network_id,
+ ),
+ array(
+ 'domain' => 'wordpress.org',
+ 'path' => '/foo/',
+ 'network_id' => self::$different_network_id,
+ ),
+ array(
+ 'domain' => 'wordpress.org',
+ 'path' => '/bar/',
+ 'network_id' => self::$different_network_id,
+ ),
+ );
+
+ foreach ( $sites as $site ) {
+ self::$different_site_ids[] = $factory->blog->create( $site );
+ }
+ }
+
+ public static function wpTearDownAfterClass() {
+ global $wpdb;
+
+ foreach ( self::$different_site_ids as $id ) {
+ wp_delete_site( $id );
+ }
+
+ $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->sitemeta} WHERE site_id = %d", self::$different_network_id ) );
+ $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->site} WHERE id= %d", self::$different_network_id ) );
+
+ wp_update_network_site_counts();
+ }
/**
- * Tests specific to networks in multisite.
- *
- * @group ms-network
- * @group multisite
+ * By default, only one network exists and has a network ID of 1.
*/
- class Tests_Multisite_Network extends WP_UnitTestCase {
- protected $plugin_hook_count = 0;
+ public function test_get_main_network_id_default() {
+ $this->assertSame( 1, get_main_network_id() );
+ }
- protected static $different_network_id;
- protected static $different_site_ids = array();
+ /**
+ * If a second network is created, network ID 1 should still be returned
+ * as the main network ID.
+ */
+ public function test_get_main_network_id_two_networks() {
+ self::factory()->network->create();
- public function tear_down() {
- global $current_site;
- $current_site->id = 1;
- parent::tear_down();
- }
+ $this->assertSame( 1, get_main_network_id() );
+ }
- public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
- self::$different_network_id = $factory->network->create(
- array(
- 'domain' => 'wordpress.org',
- 'path' => '/',
- )
- );
-
- $sites = array(
- array(
- 'domain' => 'wordpress.org',
- 'path' => '/',
- 'network_id' => self::$different_network_id,
- ),
- array(
- 'domain' => 'wordpress.org',
- 'path' => '/foo/',
- 'network_id' => self::$different_network_id,
- ),
- array(
- 'domain' => 'wordpress.org',
- 'path' => '/bar/',
- 'network_id' => self::$different_network_id,
- ),
- );
-
- foreach ( $sites as $site ) {
- self::$different_site_ids[] = $factory->blog->create( $site );
- }
- }
+ /**
+ * When the `$current_site` global is populated with another network, the
+ * main network should still return as 1.
+ */
+ public function test_get_main_network_id_after_network_switch() {
+ global $current_site;
- public static function wpTearDownAfterClass() {
- global $wpdb;
+ $id = self::factory()->network->create();
- foreach ( self::$different_site_ids as $id ) {
- wp_delete_site( $id );
- }
+ $current_site->id = (int) $id;
- $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->sitemeta} WHERE site_id = %d", self::$different_network_id ) );
- $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->site} WHERE id= %d", self::$different_network_id ) );
+ $this->assertSame( 1, get_main_network_id() );
+ }
- wp_update_network_site_counts();
- }
+ /**
+ * When the first network is removed, the next should return as the main
+ * network ID.
+ *
+ * @todo In the future, we'll have a smarter way of deleting a network. For now,
+ * fake the process with UPDATE queries.
+ */
+ public function test_get_main_network_id_after_network_delete() {
+ global $wpdb, $current_site;
- /**
- * By default, only one network exists and has a network ID of 1.
- */
- public function test_get_main_network_id_default() {
- $this->assertSame( 1, get_main_network_id() );
- }
+ $temp_id = self::$different_network_id + 1;
- /**
- * If a second network is created, network ID 1 should still be returned
- * as the main network ID.
- */
- public function test_get_main_network_id_two_networks() {
- self::factory()->network->create();
+ $current_site->id = (int) self::$different_network_id;
+ $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->site} SET id=%d WHERE id=1", $temp_id ) );
+ $main_network_id = get_main_network_id();
+ $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->site} SET id=1 WHERE id=%d", $temp_id ) );
- $this->assertSame( 1, get_main_network_id() );
- }
+ $this->assertSame( self::$different_network_id, $main_network_id );
+ }
- /**
- * When the `$current_site` global is populated with another network, the
- * main network should still return as 1.
- */
- public function test_get_main_network_id_after_network_switch() {
- global $current_site;
+ public function test_get_main_network_id_filtered() {
+ add_filter( 'get_main_network_id', array( $this, 'get_main_network_id' ) );
+ $this->assertSame( 3, get_main_network_id() );
+ remove_filter( 'get_main_network_id', array( $this, 'get_main_network_id' ) );
+ }
- $id = self::factory()->network->create();
+ public function get_main_network_id() {
+ return 3;
+ }
- $current_site->id = (int) $id;
+ /**
+ * Tests that the `WP_Network::$id` property is an integer.
+ *
+ * @ticket 37050
+ *
+ * @covers WP_Network::__get
+ */
+ public function test_wp_network_object_id_property_is_int() {
+ $id = self::factory()->network->create();
- $this->assertSame( 1, get_main_network_id() );
- }
+ $network = WP_Network::get_instance( $id );
- /**
- * When the first network is removed, the next should return as the main
- * network ID.
- *
- * @todo In the future, we'll have a smarter way of deleting a network. For now,
- * fake the process with UPDATE queries.
- */
- public function test_get_main_network_id_after_network_delete() {
- global $wpdb, $current_site;
+ $this->assertSame( (int) $id, $network->id );
+ }
- $temp_id = self::$different_network_id + 1;
+ /**
+ * Tests that the `WP_Network::$id` property is stored as an integer.
+ *
+ * Uses reflection to access the private property.
+ * Differs from using the public getter method, which casts to an integer.
+ *
+ * @ticket 62035
+ *
+ * @covers WP_Network::__construct
+ */
+ public function test_wp_network_object_id_property_stored_as_int() {
+ $id = self::factory()->network->create();
- $current_site->id = (int) self::$different_network_id;
- $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->site} SET id=%d WHERE id=1", $temp_id ) );
- $main_network_id = get_main_network_id();
- $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->site} SET id=1 WHERE id=%d", $temp_id ) );
+ $network = WP_Network::get_instance( $id );
- $this->assertSame( self::$different_network_id, $main_network_id );
- }
+ $reflection = new ReflectionObject( $network );
+ $property = $reflection->getProperty( 'id' );
+ $property->setAccessible( true );
- public function test_get_main_network_id_filtered() {
- add_filter( 'get_main_network_id', array( $this, 'get_main_network_id' ) );
- $this->assertSame( 3, get_main_network_id() );
- remove_filter( 'get_main_network_id', array( $this, 'get_main_network_id' ) );
- }
+ $this->assertSame( (int) $id, $property->getValue( $network ) );
+ }
- public function get_main_network_id() {
- return 3;
- }
+ /**
+ * Tests that the `WP_Network::$blog_id` property is a string.
+ *
+ * @ticket 62035
+ *
+ * @covers WP_Network::__get
+ */
+ public function test_wp_network_object_blog_id_property_is_int() {
+ $id = self::factory()->network->create();
- /**
- * Tests that the `WP_Network::$id` property is an integer.
- *
- * @ticket 37050
- *
- * @covers WP_Network::__get
- */
- public function test_wp_network_object_id_property_is_int() {
- $id = self::factory()->network->create();
+ $network = WP_Network::get_instance( $id );
- $network = WP_Network::get_instance( $id );
+ $this->assertIsString( $network->blog_id );
+ }
- $this->assertSame( (int) $id, $network->id );
- }
+ /**
+ * Tests that the `WP_Network::$blog_id` property is stored as a string.
+ *
+ * Uses reflection to access the private property.
+ * Differs from using the public getter method, which casts to a string.
+ *
+ * @ticket 62035
+ *
+ * @covers WP_Network::__construct
+ */
+ public function test_wp_network_object_blog_id_property_stored_as_string() {
+ $id = self::factory()->network->create();
- /**
- * Tests that the `WP_Network::$id` property is stored as an integer.
- *
- * Uses reflection to access the private property.
- * Differs from using the public getter method, which casts to an integer.
- *
- * @ticket 62035
- *
- * @covers WP_Network::__construct
- */
- public function test_wp_network_object_id_property_stored_as_int() {
- $id = self::factory()->network->create();
-
- $network = WP_Network::get_instance( $id );
-
- $reflection = new ReflectionObject( $network );
- $property = $reflection->getProperty( 'id' );
- $property->setAccessible( true );
-
- $this->assertSame( (int) $id, $property->getValue( $network ) );
- }
+ $network = WP_Network::get_instance( $id );
- /**
- * Tests that the `WP_Network::$blog_id` property is a string.
- *
- * @ticket 62035
- *
- * @covers WP_Network::__get
- */
- public function test_wp_network_object_blog_id_property_is_int() {
- $id = self::factory()->network->create();
+ $reflection = new ReflectionObject( $network );
+ $property = $reflection->getProperty( 'blog_id' );
+ $property->setAccessible( true );
- $network = WP_Network::get_instance( $id );
+ $this->assertIsString( $property->getValue( $network ) );
+ }
- $this->assertIsString( $network->blog_id );
- }
+ /**
+ * @ticket 22917
+ */
+ public function test_get_blog_count_no_filter_applied() {
+ wp_update_network_counts();
+ $site_count_start = get_blog_count();
+
+ $site_ids = self::factory()->blog->create_many( 1 );
+ $actual = (int) get_blog_count(); // Count only updated when cron runs, so should be unchanged.
- /**
- * Tests that the `WP_Network::$blog_id` property is stored as a string.
- *
- * Uses reflection to access the private property.
- * Differs from using the public getter method, which casts to a string.
- *
- * @ticket 62035
- *
- * @covers WP_Network::__construct
- */
- public function test_wp_network_object_blog_id_property_stored_as_string() {
- $id = self::factory()->network->create();
-
- $network = WP_Network::get_instance( $id );
-
- $reflection = new ReflectionObject( $network );
- $property = $reflection->getProperty( 'blog_id' );
- $property->setAccessible( true );
-
- $this->assertIsString( $property->getValue( $network ) );
+ foreach ( $site_ids as $site_id ) {
+ wp_delete_site( $site_id );
}
+ wp_update_network_counts();
- /**
- * @ticket 22917
- */
- public function test_get_blog_count_no_filter_applied() {
- wp_update_network_counts();
- $site_count_start = get_blog_count();
+ $this->assertSame( $site_count_start + 1, $actual );
+ }
- $site_ids = self::factory()->blog->create_many( 1 );
- $actual = (int) get_blog_count(); // Count only updated when cron runs, so should be unchanged.
+ /**
+ * @ticket 22917
+ */
+ public function test_get_blog_count_enable_live_network_counts_false() {
+ wp_update_network_counts();
+ $site_count_start = get_blog_count();
- foreach ( $site_ids as $site_id ) {
- wp_delete_site( $site_id );
- }
- wp_update_network_counts();
+ add_filter( 'enable_live_network_counts', '__return_false' );
+ $site_ids = self::factory()->blog->create_many( 1 );
+ $actual = (int) get_blog_count(); // Count only updated when cron runs, so should be unchanged.
+ remove_filter( 'enable_live_network_counts', '__return_false' );
- $this->assertSame( $site_count_start + 1, $actual );
+ foreach ( $site_ids as $site_id ) {
+ wp_delete_site( $site_id );
}
+ wp_update_network_counts();
- /**
- * @ticket 22917
- */
- public function test_get_blog_count_enable_live_network_counts_false() {
- wp_update_network_counts();
- $site_count_start = get_blog_count();
+ $this->assertEquals( $site_count_start, $actual );
+ }
- add_filter( 'enable_live_network_counts', '__return_false' );
- $site_ids = self::factory()->blog->create_many( 1 );
- $actual = (int) get_blog_count(); // Count only updated when cron runs, so should be unchanged.
- remove_filter( 'enable_live_network_counts', '__return_false' );
+ /**
+ * @ticket 22917
+ */
+ public function test_get_blog_count_enabled_live_network_counts_true() {
+ wp_update_network_counts();
+ $site_count_start = get_blog_count();
- foreach ( $site_ids as $site_id ) {
- wp_delete_site( $site_id );
- }
- wp_update_network_counts();
+ add_filter( 'enable_live_network_counts', '__return_true' );
+ $site_ids = self::factory()->blog->create_many( 1 );
+ $actual = get_blog_count();
+ remove_filter( 'enable_live_network_counts', '__return_true' );
- $this->assertEquals( $site_count_start, $actual );
+ foreach ( $site_ids as $site_id ) {
+ wp_delete_site( $site_id );
}
+ wp_update_network_counts();
- /**
- * @ticket 22917
- */
- public function test_get_blog_count_enabled_live_network_counts_true() {
- wp_update_network_counts();
- $site_count_start = get_blog_count();
+ $this->assertSame( $site_count_start + 1, $actual );
+ }
- add_filter( 'enable_live_network_counts', '__return_true' );
- $site_ids = self::factory()->blog->create_many( 1 );
- $actual = get_blog_count();
- remove_filter( 'enable_live_network_counts', '__return_true' );
+ /**
+ * @ticket 37865
+ */
+ public function test_get_blog_count_on_different_network() {
+ wp_update_network_site_counts( self::$different_network_id );
- foreach ( $site_ids as $site_id ) {
- wp_delete_site( $site_id );
- }
- wp_update_network_counts();
+ $site_count = get_blog_count( self::$different_network_id );
- $this->assertSame( $site_count_start + 1, $actual );
- }
+ $this->assertEquals( count( self::$different_site_ids ), $site_count );
+ }
- /**
- * @ticket 37865
- */
- public function test_get_blog_count_on_different_network() {
- wp_update_network_site_counts( self::$different_network_id );
+ public function test_active_network_plugins() {
+ $path = 'hello.php';
- $site_count = get_blog_count( self::$different_network_id );
+ // Local activate, should be invisible for the network.
+ activate_plugin( $path ); // Enable the plugin for the current site.
+ $active_plugins = wp_get_active_network_plugins();
+ $this->assertSame( array(), $active_plugins );
- $this->assertEquals( count( self::$different_site_ids ), $site_count );
- }
+ add_action( 'deactivated_plugin', array( $this, 'helper_deactivate_hook' ) );
- public function test_active_network_plugins() {
- $path = 'hello.php';
+ // Activate the plugin sitewide.
+ activate_plugin( $path, '', true ); // Enable the plugin for all sites in the network.
+ $active_plugins = wp_get_active_network_plugins();
+ $this->assertSame( array( WP_PLUGIN_DIR . '/hello.php' ), $active_plugins );
- // Local activate, should be invisible for the network.
- activate_plugin( $path ); // Enable the plugin for the current site.
- $active_plugins = wp_get_active_network_plugins();
- $this->assertSame( array(), $active_plugins );
+ // Deactivate the plugin.
+ deactivate_plugins( $path );
+ $active_plugins = wp_get_active_network_plugins();
+ $this->assertSame( array(), $active_plugins );
- add_action( 'deactivated_plugin', array( $this, 'helper_deactivate_hook' ) );
+ $this->assertSame( 1, $this->plugin_hook_count ); // Testing actions and silent mode.
- // Activate the plugin sitewide.
- activate_plugin( $path, '', true ); // Enable the plugin for all sites in the network.
- $active_plugins = wp_get_active_network_plugins();
- $this->assertSame( array( WP_PLUGIN_DIR . '/hello.php' ), $active_plugins );
+ activate_plugin( $path, '', true ); // Enable the plugin for all sites in the network.
+ deactivate_plugins( $path, true ); // Silent mode.
- // Deactivate the plugin.
- deactivate_plugins( $path );
- $active_plugins = wp_get_active_network_plugins();
- $this->assertSame( array(), $active_plugins );
+ $this->assertSame( 1, $this->plugin_hook_count ); // Testing actions and silent mode.
+ }
- $this->assertSame( 1, $this->plugin_hook_count ); // Testing actions and silent mode.
+ /**
+ * @ticket 28651
+ */
+ public function test_duplicate_network_active_plugin() {
+ $path = 'hello.php';
+ $mock = new MockAction();
+ add_action( 'activate_' . $path, array( $mock, 'action' ) );
+
+ // Should activate on the first try.
+ activate_plugin( $path, '', true ); // Enable the plugin for all sites in the network.
+ $active_plugins = wp_get_active_network_plugins();
+ $this->assertCount( 1, $active_plugins );
+ $this->assertSame( 1, $mock->get_call_count() );
+
+ // Should do nothing on the second try.
+ activate_plugin( $path, '', true ); // Enable the plugin for all sites in the network.
+ $active_plugins = wp_get_active_network_plugins();
+ $this->assertCount( 1, $active_plugins );
+ $this->assertSame( 1, $mock->get_call_count() );
+
+ remove_action( 'activate_' . $path, array( $mock, 'action' ) );
+ }
- activate_plugin( $path, '', true ); // Enable the plugin for all sites in the network.
- deactivate_plugins( $path, true ); // Silent mode.
+ public function test_is_plugin_active_for_network_true() {
+ activate_plugin( 'hello.php', '', true );
+ $this->assertTrue( is_plugin_active_for_network( 'hello.php' ) );
+ }
- $this->assertSame( 1, $this->plugin_hook_count ); // Testing actions and silent mode.
- }
+ public function test_is_plugin_active_for_network_false() {
+ deactivate_plugins( 'hello.php', false, true );
+ $this->assertFalse( is_plugin_active_for_network( 'hello.php' ) );
+ }
- /**
- * @ticket 28651
- */
- public function test_duplicate_network_active_plugin() {
- $path = 'hello.php';
- $mock = new MockAction();
- add_action( 'activate_' . $path, array( $mock, 'action' ) );
-
- // Should activate on the first try.
- activate_plugin( $path, '', true ); // Enable the plugin for all sites in the network.
- $active_plugins = wp_get_active_network_plugins();
- $this->assertCount( 1, $active_plugins );
- $this->assertSame( 1, $mock->get_call_count() );
-
- // Should do nothing on the second try.
- activate_plugin( $path, '', true ); // Enable the plugin for all sites in the network.
- $active_plugins = wp_get_active_network_plugins();
- $this->assertCount( 1, $active_plugins );
- $this->assertSame( 1, $mock->get_call_count() );
-
- remove_action( 'activate_' . $path, array( $mock, 'action' ) );
- }
+ public function helper_deactivate_hook() {
+ ++$this->plugin_hook_count;
+ }
- public function test_is_plugin_active_for_network_true() {
- activate_plugin( 'hello.php', '', true );
- $this->assertTrue( is_plugin_active_for_network( 'hello.php' ) );
- }
+ public function test_wp_schedule_update_network_counts() {
+ $this->assertFalse( wp_next_scheduled( 'update_network_counts' ) );
- public function test_is_plugin_active_for_network_false() {
- deactivate_plugins( 'hello.php', false, true );
- $this->assertFalse( is_plugin_active_for_network( 'hello.php' ) );
- }
+ // We can't use wp_schedule_update_network_counts() because WP_INSTALLING is set.
+ wp_schedule_event( time(), 'twicedaily', 'update_network_counts' );
- public function helper_deactivate_hook() {
- ++$this->plugin_hook_count;
- }
+ $this->assertIsInt( wp_next_scheduled( 'update_network_counts' ) );
+ }
+
+ /**
+ * @expectedDeprecated get_dashboard_blog
+ */
+ public function test_get_dashboard_blog() {
+ // If there is no dashboard blog set, current blog is used.
+ $dashboard_blog = get_dashboard_blog();
+ $this->assertEquals( 1, $dashboard_blog->blog_id );
+
+ $user_id = self::factory()->user->create( array( 'role' => 'administrator' ) );
+ $blog_id = self::factory()->blog->create( array( 'user_id' => $user_id ) );
+ $this->assertIsInt( $blog_id );
+
+ // Set the dashboard blog to another one.
+ update_site_option( 'dashboard_blog', $blog_id );
+ $dashboard_blog = get_dashboard_blog();
+ $this->assertEquals( $blog_id, $dashboard_blog->blog_id );
+ }
- public function test_wp_schedule_update_network_counts() {
- $this->assertFalse( wp_next_scheduled( 'update_network_counts' ) );
+ /**
+ * @ticket 37528
+ */
+ public function test_wp_update_network_site_counts() {
+ update_network_option( null, 'blog_count', 40 );
+
+ $expected = get_sites(
+ array(
+ 'network_id' => get_current_network_id(),
+ 'spam' => 0,
+ 'deleted' => 0,
+ 'archived' => 0,
+ 'count' => true,
+ )
+ );
+
+ wp_update_network_site_counts();
+
+ $result = get_blog_count();
+ $this->assertSame( $expected, $result );
+ }
- // We can't use wp_schedule_update_network_counts() because WP_INSTALLING is set.
- wp_schedule_event( time(), 'twicedaily', 'update_network_counts' );
+ /**
+ * @ticket 37528
+ */
+ public function test_wp_update_network_site_counts_on_different_network() {
+ update_network_option( self::$different_network_id, 'blog_count', 40 );
- $this->assertIsInt( wp_next_scheduled( 'update_network_counts' ) );
- }
+ wp_update_network_site_counts( self::$different_network_id );
- /**
- * @expectedDeprecated get_dashboard_blog
- */
- public function test_get_dashboard_blog() {
- // If there is no dashboard blog set, current blog is used.
- $dashboard_blog = get_dashboard_blog();
- $this->assertEquals( 1, $dashboard_blog->blog_id );
-
- $user_id = self::factory()->user->create( array( 'role' => 'administrator' ) );
- $blog_id = self::factory()->blog->create( array( 'user_id' => $user_id ) );
- $this->assertIsInt( $blog_id );
-
- // Set the dashboard blog to another one.
- update_site_option( 'dashboard_blog', $blog_id );
- $dashboard_blog = get_dashboard_blog();
- $this->assertEquals( $blog_id, $dashboard_blog->blog_id );
- }
+ $result = get_blog_count( self::$different_network_id );
+ $this->assertSame( 3, $result );
+ }
- /**
- * @ticket 37528
- */
- public function test_wp_update_network_site_counts() {
- update_network_option( null, 'blog_count', 40 );
-
- $expected = get_sites(
- array(
- 'network_id' => get_current_network_id(),
- 'spam' => 0,
- 'deleted' => 0,
- 'archived' => 0,
- 'count' => true,
- )
- );
-
- wp_update_network_site_counts();
-
- $result = get_blog_count();
- $this->assertSame( $expected, $result );
- }
+ /**
+ * @ticket 40349
+ */
+ public function test_wp_update_network_user_counts() {
+ global $wpdb;
- /**
- * @ticket 37528
- */
- public function test_wp_update_network_site_counts_on_different_network() {
- update_network_option( self::$different_network_id, 'blog_count', 40 );
+ update_network_option( null, 'user_count', 40 );
- wp_update_network_site_counts( self::$different_network_id );
+ $expected = (int) $wpdb->get_var( "SELECT COUNT(ID) as c FROM $wpdb->users WHERE spam = '0' AND deleted = '0'" );
- $result = get_blog_count( self::$different_network_id );
- $this->assertSame( 3, $result );
- }
+ wp_update_network_user_counts();
- /**
- * @ticket 40349
- */
- public function test_wp_update_network_user_counts() {
- global $wpdb;
+ $result = get_user_count();
+ $this->assertSame( $expected, $result );
+ }
- update_network_option( null, 'user_count', 40 );
+ /**
+ * @ticket 40349
+ */
+ public function test_wp_update_network_user_counts_on_different_network() {
+ global $wpdb;
- $expected = (int) $wpdb->get_var( "SELECT COUNT(ID) as c FROM $wpdb->users WHERE spam = '0' AND deleted = '0'" );
+ update_network_option( self::$different_network_id, 'user_count', 40 );
- wp_update_network_user_counts();
+ $expected = (int) $wpdb->get_var( "SELECT COUNT(ID) as c FROM $wpdb->users WHERE spam = '0' AND deleted = '0'" );
- $result = get_user_count();
- $this->assertSame( $expected, $result );
- }
+ wp_update_network_user_counts( self::$different_network_id );
- /**
- * @ticket 40349
- */
- public function test_wp_update_network_user_counts_on_different_network() {
- global $wpdb;
+ $result = get_user_count( self::$different_network_id );
+ $this->assertSame( $expected, $result );
+ }
- update_network_option( self::$different_network_id, 'user_count', 40 );
+ /**
+ * @ticket 40386
+ */
+ public function test_wp_update_network_counts() {
+ delete_network_option( null, 'blog_count' );
+ delete_network_option( null, 'user_count' );
- $expected = (int) $wpdb->get_var( "SELECT COUNT(ID) as c FROM $wpdb->users WHERE spam = '0' AND deleted = '0'" );
+ wp_update_network_counts();
- wp_update_network_user_counts( self::$different_network_id );
+ $site_count = (int) get_blog_count();
+ $user_count = (int) get_user_count();
- $result = get_user_count( self::$different_network_id );
- $this->assertSame( $expected, $result );
- }
+ $this->assertGreaterThan( 0, $site_count );
+ $this->assertGreaterThan( 0, $user_count );
+ }
- /**
- * @ticket 40386
- */
- public function test_wp_update_network_counts() {
- delete_network_option( null, 'blog_count' );
- delete_network_option( null, 'user_count' );
+ /**
+ * @ticket 40386
+ */
+ public function test_wp_update_network_counts_on_different_network() {
+ delete_network_option( self::$different_network_id, 'blog_count' );
+ delete_network_option( self::$different_network_id, 'user_count' );
- wp_update_network_counts();
+ wp_update_network_counts( self::$different_network_id );
- $site_count = (int) get_blog_count();
- $user_count = (int) get_user_count();
+ $site_count = (int) get_blog_count( self::$different_network_id );
+ $user_count = (int) get_user_count( self::$different_network_id );
- $this->assertGreaterThan( 0, $site_count );
- $this->assertGreaterThan( 0, $user_count );
- }
+ $this->assertGreaterThan( 0, $site_count );
+ $this->assertGreaterThan( 0, $user_count );
+ }
- /**
- * @ticket 40386
- */
- public function test_wp_update_network_counts_on_different_network() {
- delete_network_option( self::$different_network_id, 'blog_count' );
- delete_network_option( self::$different_network_id, 'user_count' );
+ /**
+ * Test the default behavior of upload_size_limit_filter.
+ * If any default option is changed, the function returns the min value between the
+ * parameter passed and the `fileupload_maxk` site option (1500Kb by default)
+ *
+ * @ticket 55926
+ */
+ public function test_upload_size_limit_filter() {
+ $return = upload_size_limit_filter( 1499 * KB_IN_BYTES );
+ $this->assertSame( 1499 * KB_IN_BYTES, $return );
+ $return = upload_size_limit_filter( 1501 * KB_IN_BYTES );
+ $this->assertSame( 1500 * KB_IN_BYTES, $return );
+ }
- wp_update_network_counts( self::$different_network_id );
+ /**
+ * Test if upload_size_limit_filter behaves as expected when the `fileupload_maxk` is 0 or an empty string.
+ *
+ * @ticket 55926
+ * @dataProvider data_upload_size_limit_filter_empty_fileupload_maxk
+ */
+ public function test_upload_size_limit_filter_empty_fileupload_maxk( $callable_set_fileupload_maxk ) {
+ add_filter( 'site_option_fileupload_maxk', $callable_set_fileupload_maxk );
+ $return = upload_size_limit_filter( 1500 );
+ $this->assertSame( 0, $return );
+ }
- $site_count = (int) get_blog_count( self::$different_network_id );
- $user_count = (int) get_user_count( self::$different_network_id );
+ /**
+ * @ticket 55926
+ */
+ public function data_upload_size_limit_filter_empty_fileupload_maxk() {
+ return array(
+ array( '__return_zero' ),
+ array( '__return_empty_string' ),
+ );
+ }
- $this->assertGreaterThan( 0, $site_count );
- $this->assertGreaterThan( 0, $user_count );
- }
+ /**
+ * When upload_space_check is enabled, the space allowed is also considered by `upload_size_limit_filter`.
+ *
+ * @ticket 55926
+ */
+ public function test_upload_size_limit_filter_when_upload_space_check_enabled() {
+ add_filter( 'get_space_allowed', '__return_zero' );
+ add_filter( 'site_option_upload_space_check_disabled', '__return_false' );
+ $return = upload_size_limit_filter( 100 );
+ $this->assertSame( 0, $return );
+ }
- /**
- * Test the default behavior of upload_size_limit_filter.
- * If any default option is changed, the function returns the min value between the
- * parameter passed and the `fileupload_maxk` site option (1500Kb by default)
- *
- * @ticket 55926
- */
- public function test_upload_size_limit_filter() {
- $return = upload_size_limit_filter( 1499 * KB_IN_BYTES );
- $this->assertSame( 1499 * KB_IN_BYTES, $return );
- $return = upload_size_limit_filter( 1501 * KB_IN_BYTES );
- $this->assertSame( 1500 * KB_IN_BYTES, $return );
- }
+ /**
+ * @ticket 40489
+ * @dataProvider data_wp_is_large_network
+ */
+ public function test_wp_is_large_network( $using, $count, $expected, $different_network ) {
+ $network_id = $different_network ? self::$different_network_id : null;
+ $network_option = 'users' === $using ? 'user_count' : 'blog_count';
- /**
- * Test if upload_size_limit_filter behaves as expected when the `fileupload_maxk` is 0 or an empty string.
- *
- * @ticket 55926
- * @dataProvider data_upload_size_limit_filter_empty_fileupload_maxk
- */
- public function test_upload_size_limit_filter_empty_fileupload_maxk( $callable_set_fileupload_maxk ) {
- add_filter( 'site_option_fileupload_maxk', $callable_set_fileupload_maxk );
- $return = upload_size_limit_filter( 1500 );
- $this->assertSame( 0, $return );
- }
+ update_network_option( $network_id, $network_option, $count );
- /**
- * @ticket 55926
- */
- public function data_upload_size_limit_filter_empty_fileupload_maxk() {
- return array(
- array( '__return_zero' ),
- array( '__return_empty_string' ),
- );
+ $result = wp_is_large_network( $using, $network_id );
+ if ( $expected ) {
+ $this->assertTrue( $result );
+ } else {
+ $this->assertFalse( $result );
}
+ }
- /**
- * When upload_space_check is enabled, the space allowed is also considered by `upload_size_limit_filter`.
- *
- * @ticket 55926
- */
- public function test_upload_size_limit_filter_when_upload_space_check_enabled() {
- add_filter( 'get_space_allowed', '__return_zero' );
- add_filter( 'site_option_upload_space_check_disabled', '__return_false' );
- $return = upload_size_limit_filter( 100 );
- $this->assertSame( 0, $return );
- }
+ public function data_wp_is_large_network() {
+ return array(
+ array( 'sites', 10000, false, false ),
+ array( 'sites', 10001, true, false ),
+ array( 'users', 10000, false, false ),
+ array( 'users', 10001, true, false ),
+ array( 'sites', 10000, false, true ),
+ array( 'sites', 10001, true, true ),
+ array( 'users', 10000, false, true ),
+ array( 'users', 10001, true, true ),
+ );
+ }
- /**
- * @ticket 40489
- * @dataProvider data_wp_is_large_network
- */
- public function test_wp_is_large_network( $using, $count, $expected, $different_network ) {
- $network_id = $different_network ? self::$different_network_id : null;
- $network_option = 'users' === $using ? 'user_count' : 'blog_count';
-
- update_network_option( $network_id, $network_option, $count );
-
- $result = wp_is_large_network( $using, $network_id );
- if ( $expected ) {
- $this->assertTrue( $result );
- } else {
- $this->assertFalse( $result );
- }
- }
+ /**
+ * @ticket 40489
+ * @dataProvider data_wp_is_large_network_filtered_by_component
+ */
+ public function test_wp_is_large_network_filtered_by_component( $using, $count, $expected, $different_network ) {
+ $network_id = $different_network ? self::$different_network_id : null;
+ $network_option = 'users' === $using ? 'user_count' : 'blog_count';
- public function data_wp_is_large_network() {
- return array(
- array( 'sites', 10000, false, false ),
- array( 'sites', 10001, true, false ),
- array( 'users', 10000, false, false ),
- array( 'users', 10001, true, false ),
- array( 'sites', 10000, false, true ),
- array( 'sites', 10001, true, true ),
- array( 'users', 10000, false, true ),
- array( 'users', 10001, true, true ),
- );
- }
+ update_network_option( $network_id, $network_option, $count );
- /**
- * @ticket 40489
- * @dataProvider data_wp_is_large_network_filtered_by_component
- */
- public function test_wp_is_large_network_filtered_by_component( $using, $count, $expected, $different_network ) {
- $network_id = $different_network ? self::$different_network_id : null;
- $network_option = 'users' === $using ? 'user_count' : 'blog_count';
-
- update_network_option( $network_id, $network_option, $count );
-
- add_filter( 'wp_is_large_network', array( $this, 'filter_wp_is_large_network_for_users' ), 10, 3 );
- $result = wp_is_large_network( $using, $network_id );
- remove_filter( 'wp_is_large_network', array( $this, 'filter_wp_is_large_network_for_users' ), 10 );
-
- if ( $expected ) {
- $this->assertTrue( $result );
- } else {
- $this->assertFalse( $result );
- }
- }
+ add_filter( 'wp_is_large_network', array( $this, 'filter_wp_is_large_network_for_users' ), 10, 3 );
+ $result = wp_is_large_network( $using, $network_id );
+ remove_filter( 'wp_is_large_network', array( $this, 'filter_wp_is_large_network_for_users' ), 10 );
- public function data_wp_is_large_network_filtered_by_component() {
- return array(
- array( 'sites', 10000, false, false ),
- array( 'sites', 10001, true, false ),
- array( 'users', 1000, false, false ),
- array( 'users', 1001, true, false ),
- array( 'sites', 10000, false, true ),
- array( 'sites', 10001, true, true ),
- array( 'users', 1000, false, true ),
- array( 'users', 1001, true, true ),
- );
+ if ( $expected ) {
+ $this->assertTrue( $result );
+ } else {
+ $this->assertFalse( $result );
}
+ }
- public function filter_wp_is_large_network_for_users( $is_large_network, $using, $count ) {
- if ( 'users' === $using ) {
- return $count > 1000;
- }
+ public function data_wp_is_large_network_filtered_by_component() {
+ return array(
+ array( 'sites', 10000, false, false ),
+ array( 'sites', 10001, true, false ),
+ array( 'users', 1000, false, false ),
+ array( 'users', 1001, true, false ),
+ array( 'sites', 10000, false, true ),
+ array( 'sites', 10001, true, true ),
+ array( 'users', 1000, false, true ),
+ array( 'users', 1001, true, true ),
+ );
+ }
- return $is_large_network;
+ public function filter_wp_is_large_network_for_users( $is_large_network, $using, $count ) {
+ if ( 'users' === $using ) {
+ return $count > 1000;
}
- /**
- * @ticket 40489
- * @dataProvider data_wp_is_large_network_filtered_by_network
- */
- public function test_wp_is_large_network_filtered_by_network( $using, $count, $expected, $different_network ) {
- $network_id = $different_network ? self::$different_network_id : null;
- $network_option = 'users' === $using ? 'user_count' : 'blog_count';
-
- update_network_option( $network_id, $network_option, $count );
-
- add_filter( 'wp_is_large_network', array( $this, 'filter_wp_is_large_network_on_different_network' ), 10, 4 );
- $result = wp_is_large_network( $using, $network_id );
- remove_filter( 'wp_is_large_network', array( $this, 'filter_wp_is_large_network_on_different_network' ), 10 );
-
- if ( $expected ) {
- $this->assertTrue( $result );
- } else {
- $this->assertFalse( $result );
- }
- }
+ return $is_large_network;
+ }
- public function data_wp_is_large_network_filtered_by_network() {
- return array(
- array( 'sites', 10000, false, false ),
- array( 'sites', 10001, true, false ),
- array( 'users', 10000, false, false ),
- array( 'users', 10001, true, false ),
- array( 'sites', 1000, false, true ),
- array( 'sites', 1001, true, true ),
- array( 'users', 1000, false, true ),
- array( 'users', 1001, true, true ),
- );
+ /**
+ * @ticket 40489
+ * @dataProvider data_wp_is_large_network_filtered_by_network
+ */
+ public function test_wp_is_large_network_filtered_by_network( $using, $count, $expected, $different_network ) {
+ $network_id = $different_network ? self::$different_network_id : null;
+ $network_option = 'users' === $using ? 'user_count' : 'blog_count';
+
+ update_network_option( $network_id, $network_option, $count );
+
+ add_filter( 'wp_is_large_network', array( $this, 'filter_wp_is_large_network_on_different_network' ), 10, 4 );
+ $result = wp_is_large_network( $using, $network_id );
+ remove_filter( 'wp_is_large_network', array( $this, 'filter_wp_is_large_network_on_different_network' ), 10 );
+
+ if ( $expected ) {
+ $this->assertTrue( $result );
+ } else {
+ $this->assertFalse( $result );
}
+ }
- public function filter_wp_is_large_network_on_different_network( $is_large_network, $using, $count, $network_id ) {
- if ( $network_id === (int) self::$different_network_id ) {
- return $count > 1000;
- }
+ public function data_wp_is_large_network_filtered_by_network() {
+ return array(
+ array( 'sites', 10000, false, false ),
+ array( 'sites', 10001, true, false ),
+ array( 'users', 10000, false, false ),
+ array( 'users', 10001, true, false ),
+ array( 'sites', 1000, false, true ),
+ array( 'sites', 1001, true, true ),
+ array( 'users', 1000, false, true ),
+ array( 'users', 1001, true, true ),
+ );
+ }
- return $is_large_network;
+ public function filter_wp_is_large_network_on_different_network( $is_large_network, $using, $count, $network_id ) {
+ if ( $network_id === (int) self::$different_network_id ) {
+ return $count > 1000;
}
- /**
- * @ticket 38699
- */
- public function test_wpmu_create_blog_updates_correct_network_site_count() {
- global $wpdb;
+ return $is_large_network;
+ }
- $original_count = get_blog_count( self::$different_network_id );
+ /**
+ * @ticket 38699
+ */
+ public function test_wpmu_create_blog_updates_correct_network_site_count() {
+ global $wpdb;
- $suppress = $wpdb->suppress_errors();
- $site_id = wpmu_create_blog( 'example.org', '/', '', 1, array(), self::$different_network_id );
- $wpdb->suppress_errors( $suppress );
+ $original_count = get_blog_count( self::$different_network_id );
- $result = get_blog_count( self::$different_network_id );
+ $suppress = $wpdb->suppress_errors();
+ $site_id = wpmu_create_blog( 'example.org', '/', '', 1, array(), self::$different_network_id );
+ $wpdb->suppress_errors( $suppress );
- wpmu_delete_blog( $site_id, true );
+ $result = get_blog_count( self::$different_network_id );
- $this->assertSame( $original_count + 1, $result );
- }
+ wpmu_delete_blog( $site_id, true );
- /**
- * @ticket 29684
- */
- public function test_network_blog_id_set() {
- $network = get_network( self::$different_network_id );
+ $this->assertSame( $original_count + 1, $result );
+ }
- $this->assertSame( (string) self::$different_site_ids[0], $network->blog_id );
- }
+ /**
+ * @ticket 29684
+ */
+ public function test_network_blog_id_set() {
+ $network = get_network( self::$different_network_id );
- /**
- * @ticket 42251
- */
- public function test_get_network_not_found_cache() {
- $new_network_id = $this->_get_next_network_id();
- $this->assertNull( get_network( $new_network_id ) );
+ $this->assertSame( (string) self::$different_site_ids[0], $network->blog_id );
+ }
- $num_queries = get_num_queries();
- $this->assertNull( get_network( $new_network_id ) );
- $this->assertSame( $num_queries, get_num_queries() );
- }
+ /**
+ * @ticket 42251
+ */
+ public function test_get_network_not_found_cache() {
+ $new_network_id = $this->_get_next_network_id();
+ $this->assertNull( get_network( $new_network_id ) );
- /**
- * @ticket 42251
- */
- public function test_get_network_not_found_cache_clear() {
- $new_network_id = $this->_get_next_network_id();
- $this->assertNull( get_network( $new_network_id ) );
+ $num_queries = get_num_queries();
+ $this->assertNull( get_network( $new_network_id ) );
+ $this->assertSame( $num_queries, get_num_queries() );
+ }
- $new_network = self::factory()->network->create_and_get();
+ /**
+ * @ticket 42251
+ */
+ public function test_get_network_not_found_cache_clear() {
+ $new_network_id = $this->_get_next_network_id();
+ $this->assertNull( get_network( $new_network_id ) );
- // Double-check we got the ID of the new network correct.
- $this->assertSame( $new_network_id, $new_network->id );
+ $new_network = self::factory()->network->create_and_get();
- // Verify that if we fetch the network now, it's no longer false.
- $fetched_network = get_network( $new_network_id );
- $this->assertInstanceOf( 'WP_Network', $fetched_network );
- $this->assertSame( $new_network_id, $fetched_network->id );
- }
+ // Double-check we got the ID of the new network correct.
+ $this->assertSame( $new_network_id, $new_network->id );
- /**
- * Gets the ID of the site with the highest ID.
- * @return int
- */
- protected function _get_next_network_id() {
- global $wpdb;
- // Create an extra network, just to make sure we know the ID of the following one.
- static::factory()->network->create();
- return (int) $wpdb->get_var( 'SELECT id FROM ' . $wpdb->site . ' ORDER BY id DESC LIMIT 1' ) + 1;
- }
+ // Verify that if we fetch the network now, it's no longer false.
+ $fetched_network = get_network( $new_network_id );
+ $this->assertInstanceOf( 'WP_Network', $fetched_network );
+ $this->assertSame( $new_network_id, $fetched_network->id );
}
-endif;
+ /**
+ * Gets the ID of the site with the highest ID.
+ * @return int
+ */
+ protected function _get_next_network_id() {
+ global $wpdb;
+ // Create an extra network, just to make sure we know the ID of the following one.
+ static::factory()->network->create();
+ return (int) $wpdb->get_var( 'SELECT id FROM ' . $wpdb->site . ' ORDER BY id DESC LIMIT 1' ) + 1;
+ }
+}
diff --git a/tests/phpunit/tests/multisite/site.php b/tests/phpunit/tests/multisite/site.php
index 097f5fb6e2..920a76f6a7 100644
--- a/tests/phpunit/tests/multisite/site.php
+++ b/tests/phpunit/tests/multisite/site.php
@@ -1,2311 +1,2308 @@
<?php
-if ( is_multisite() ) :
+/**
+ * Tests specific to sites in multisite.
+ *
+ * @group ms-required
+ * @group ms-site
+ * @group multisite
+ */
+class Tests_Multisite_Site extends WP_UnitTestCase {
+ protected $suppress = false;
+ protected $site_status_hooks = array();
+ protected $wp_initialize_site_args = array();
+ protected $wp_initialize_site_meta = array();
+ protected static $network_ids;
+ protected static $site_ids;
+ protected static $uninitialized_site_id;
+
+ public function set_up() {
+ global $wpdb;
+ parent::set_up();
+ $this->suppress = $wpdb->suppress_errors();
+ }
- /**
- * Tests specific to sites in multisite.
- *
- * @group ms-site
- * @group multisite
- */
- class Tests_Multisite_Site extends WP_UnitTestCase {
- protected $suppress = false;
- protected $site_status_hooks = array();
- protected $wp_initialize_site_args = array();
- protected $wp_initialize_site_meta = array();
- protected static $network_ids;
- protected static $site_ids;
- protected static $uninitialized_site_id;
-
- public function set_up() {
- global $wpdb;
- parent::set_up();
- $this->suppress = $wpdb->suppress_errors();
- }
+ public function tear_down() {
+ global $wpdb;
+ $wpdb->suppress_errors( $this->suppress );
+ parent::tear_down();
+ }
- public function tear_down() {
- global $wpdb;
- $wpdb->suppress_errors( $this->suppress );
- parent::tear_down();
- }
+ public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
+ self::$network_ids = array(
+ 'make.wordpress.org/' => array(
+ 'domain' => 'make.wordpress.org',
+ 'path' => '/',
+ ),
+ );
+
+ foreach ( self::$network_ids as &$id ) {
+ $id = $factory->network->create( $id );
+ }
+ unset( $id );
+
+ self::$site_ids = array(
+ 'make.wordpress.org/' => array(
+ 'domain' => 'make.wordpress.org',
+ 'path' => '/',
+ 'network_id' => self::$network_ids['make.wordpress.org/'],
+ ),
+ 'make.wordpress.org/foo/' => array(
+ 'domain' => 'make.wordpress.org',
+ 'path' => '/foo/',
+ 'network_id' => self::$network_ids['make.wordpress.org/'],
+ ),
+ );
+
+ foreach ( self::$site_ids as &$id ) {
+ $id = $factory->blog->create( $id );
+ }
+ unset( $id );
+
+ remove_action( 'wp_initialize_site', 'wp_initialize_site', 10 );
+ self::$uninitialized_site_id = wp_insert_site(
+ array(
+ 'domain' => 'uninitialized.org',
+ 'path' => '/',
+ 'network_id' => self::$network_ids['make.wordpress.org/'],
+ )
+ );
+ add_action( 'wp_initialize_site', 'wp_initialize_site', 10, 2 );
+ }
- public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
- self::$network_ids = array(
- 'make.wordpress.org/' => array(
- 'domain' => 'make.wordpress.org',
- 'path' => '/',
- ),
- );
+ public static function wpTearDownAfterClass() {
+ global $wpdb;
- foreach ( self::$network_ids as &$id ) {
- $id = $factory->network->create( $id );
- }
- unset( $id );
+ remove_action( 'wp_uninitialize_site', 'wp_uninitialize_site', 10 );
+ wp_delete_site( self::$uninitialized_site_id );
+ add_action( 'wp_uninitialize_site', 'wp_uninitialize_site', 10, 1 );
- self::$site_ids = array(
- 'make.wordpress.org/' => array(
- 'domain' => 'make.wordpress.org',
- 'path' => '/',
- 'network_id' => self::$network_ids['make.wordpress.org/'],
- ),
- 'make.wordpress.org/foo/' => array(
- 'domain' => 'make.wordpress.org',
- 'path' => '/foo/',
- 'network_id' => self::$network_ids['make.wordpress.org/'],
- ),
- );
-
- foreach ( self::$site_ids as &$id ) {
- $id = $factory->blog->create( $id );
- }
- unset( $id );
-
- remove_action( 'wp_initialize_site', 'wp_initialize_site', 10 );
- self::$uninitialized_site_id = wp_insert_site(
- array(
- 'domain' => 'uninitialized.org',
- 'path' => '/',
- 'network_id' => self::$network_ids['make.wordpress.org/'],
- )
- );
- add_action( 'wp_initialize_site', 'wp_initialize_site', 10, 2 );
+ foreach ( self::$site_ids as $id ) {
+ wp_delete_site( $id );
}
- public static function wpTearDownAfterClass() {
- global $wpdb;
-
- remove_action( 'wp_uninitialize_site', 'wp_uninitialize_site', 10 );
- wp_delete_site( self::$uninitialized_site_id );
- add_action( 'wp_uninitialize_site', 'wp_uninitialize_site', 10, 1 );
-
- foreach ( self::$site_ids as $id ) {
- wp_delete_site( $id );
- }
-
- foreach ( self::$network_ids as $id ) {
- $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->sitemeta} WHERE site_id = %d", $id ) );
- $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->site} WHERE id= %d", $id ) );
- }
+ foreach ( self::$network_ids as $id ) {
+ $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->sitemeta} WHERE site_id = %d", $id ) );
+ $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->site} WHERE id= %d", $id ) );
}
+ }
- public function test_switch_restore_blog() {
- global $_wp_switched_stack, $wpdb;
-
- $this->assertSame( array(), $_wp_switched_stack );
- $this->assertFalse( ms_is_switched() );
- $current_blog_id = get_current_blog_id();
- $this->assertIsInt( $current_blog_id );
-
- wp_cache_set( 'switch-test', $current_blog_id, 'switch-test' );
- $this->assertSame( $current_blog_id, wp_cache_get( 'switch-test', 'switch-test' ) );
-
- $blog_id = self::factory()->blog->create();
-
- $cap_key = wp_get_current_user()->cap_key;
- switch_to_blog( $blog_id );
- $this->assertNotEquals( $cap_key, wp_get_current_user()->cap_key );
- $this->assertSame( array( $current_blog_id ), $_wp_switched_stack );
- $this->assertTrue( ms_is_switched() );
- $this->assertSame( $blog_id, $wpdb->blogid );
- $this->assertFalse( wp_cache_get( 'switch-test', 'switch-test' ) );
- wp_cache_set( 'switch-test', $blog_id, 'switch-test' );
- $this->assertSame( $blog_id, wp_cache_get( 'switch-test', 'switch-test' ) );
-
- switch_to_blog( $blog_id );
- $this->assertSame( array( $current_blog_id, $blog_id ), $_wp_switched_stack );
- $this->assertTrue( ms_is_switched() );
- $this->assertSame( $blog_id, $wpdb->blogid );
- $this->assertSame( $blog_id, wp_cache_get( 'switch-test', 'switch-test' ) );
-
- restore_current_blog();
- $this->assertSame( array( $current_blog_id ), $_wp_switched_stack );
- $this->assertTrue( ms_is_switched() );
- $this->assertSame( $blog_id, $wpdb->blogid );
- $this->assertSame( $blog_id, wp_cache_get( 'switch-test', 'switch-test' ) );
-
- restore_current_blog();
- $this->assertSame( $cap_key, wp_get_current_user()->cap_key );
- $this->assertSame( $current_blog_id, get_current_blog_id() );
- $this->assertSame( array(), $_wp_switched_stack );
- $this->assertFalse( ms_is_switched() );
- $this->assertSame( $current_blog_id, wp_cache_get( 'switch-test', 'switch-test' ) );
-
- $this->assertFalse( restore_current_blog() );
- }
+ public function test_switch_restore_blog() {
+ global $_wp_switched_stack, $wpdb;
+
+ $this->assertSame( array(), $_wp_switched_stack );
+ $this->assertFalse( ms_is_switched() );
+ $current_blog_id = get_current_blog_id();
+ $this->assertIsInt( $current_blog_id );
+
+ wp_cache_set( 'switch-test', $current_blog_id, 'switch-test' );
+ $this->assertSame( $current_blog_id, wp_cache_get( 'switch-test', 'switch-test' ) );
+
+ $blog_id = self::factory()->blog->create();
+
+ $cap_key = wp_get_current_user()->cap_key;
+ switch_to_blog( $blog_id );
+ $this->assertNotEquals( $cap_key, wp_get_current_user()->cap_key );
+ $this->assertSame( array( $current_blog_id ), $_wp_switched_stack );
+ $this->assertTrue( ms_is_switched() );
+ $this->assertSame( $blog_id, $wpdb->blogid );
+ $this->assertFalse( wp_cache_get( 'switch-test', 'switch-test' ) );
+ wp_cache_set( 'switch-test', $blog_id, 'switch-test' );
+ $this->assertSame( $blog_id, wp_cache_get( 'switch-test', 'switch-test' ) );
+
+ switch_to_blog( $blog_id );
+ $this->assertSame( array( $current_blog_id, $blog_id ), $_wp_switched_stack );
+ $this->assertTrue( ms_is_switched() );
+ $this->assertSame( $blog_id, $wpdb->blogid );
+ $this->assertSame( $blog_id, wp_cache_get( 'switch-test', 'switch-test' ) );
+
+ restore_current_blog();
+ $this->assertSame( array( $current_blog_id ), $_wp_switched_stack );
+ $this->assertTrue( ms_is_switched() );
+ $this->assertSame( $blog_id, $wpdb->blogid );
+ $this->assertSame( $blog_id, wp_cache_get( 'switch-test', 'switch-test' ) );
+
+ restore_current_blog();
+ $this->assertSame( $cap_key, wp_get_current_user()->cap_key );
+ $this->assertSame( $current_blog_id, get_current_blog_id() );
+ $this->assertSame( array(), $_wp_switched_stack );
+ $this->assertFalse( ms_is_switched() );
+ $this->assertSame( $current_blog_id, wp_cache_get( 'switch-test', 'switch-test' ) );
+
+ $this->assertFalse( restore_current_blog() );
+ }
- /**
- * Test the cache keys and database tables setup through the creation of a site.
- */
- public function test_created_site_details() {
- global $wpdb;
+ /**
+ * Test the cache keys and database tables setup through the creation of a site.
+ */
+ public function test_created_site_details() {
+ global $wpdb;
- $blog_id = self::factory()->blog->create();
+ $blog_id = self::factory()->blog->create();
- $this->assertIsInt( $blog_id );
- $prefix = $wpdb->get_blog_prefix( $blog_id );
+ $this->assertIsInt( $blog_id );
+ $prefix = $wpdb->get_blog_prefix( $blog_id );
- // $get_all = false, only retrieve details from the blogs table.
- $details = get_blog_details( $blog_id, false );
+ // $get_all = false, only retrieve details from the blogs table.
+ $details = get_blog_details( $blog_id, false );
- // Combine domain and path for a site specific cache key.
- $key = md5( $details->domain . $details->path );
+ // Combine domain and path for a site specific cache key.
+ $key = md5( $details->domain . $details->path );
- $this->assertEquals( $details, wp_cache_get( $blog_id . 'short', 'blog-details' ) );
+ $this->assertEquals( $details, wp_cache_get( $blog_id . 'short', 'blog-details' ) );
- // get_blogaddress_by_name().
- $this->assertSame( 'http://' . $details->domain . $details->path, get_blogaddress_by_name( trim( $details->path, '/' ) ) );
+ // get_blogaddress_by_name().
+ $this->assertSame( 'http://' . $details->domain . $details->path, get_blogaddress_by_name( trim( $details->path, '/' ) ) );
- // These are empty until get_blog_details() is called with $get_all = true.
- $this->assertFalse( wp_cache_get( $blog_id, 'blog-details' ) );
- $this->assertFalse( wp_cache_get( $key, 'blog-lookup' ) );
+ // These are empty until get_blog_details() is called with $get_all = true.
+ $this->assertFalse( wp_cache_get( $blog_id, 'blog-details' ) );
+ $this->assertFalse( wp_cache_get( $key, 'blog-lookup' ) );
- // $get_all = true, populate the full blog-details cache and the blog slug lookup cache.
- $details = get_blog_details( $blog_id, true );
- $this->assertEquals( $details, wp_cache_get( $blog_id, 'blog-details' ) );
- $this->assertEquals( $details, wp_cache_get( $key, 'blog-lookup' ) );
+ // $get_all = true, populate the full blog-details cache and the blog slug lookup cache.
+ $details = get_blog_details( $blog_id, true );
+ $this->assertEquals( $details, wp_cache_get( $blog_id, 'blog-details' ) );
+ $this->assertEquals( $details, wp_cache_get( $key, 'blog-lookup' ) );
- // Check existence of each database table for the created site.
- foreach ( $wpdb->tables( 'blog', false ) as $table ) {
- $suppress = $wpdb->suppress_errors();
+ // Check existence of each database table for the created site.
+ foreach ( $wpdb->tables( 'blog', false ) as $table ) {
+ $suppress = $wpdb->suppress_errors();
- // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
- $table_fields = $wpdb->get_results( "DESCRIBE $prefix$table;" );
+ // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
+ $table_fields = $wpdb->get_results( "DESCRIBE $prefix$table;" );
- $wpdb->suppress_errors( $suppress );
+ $wpdb->suppress_errors( $suppress );
- // The table should exist.
- $this->assertNotEmpty( $table_fields );
+ // The table should exist.
+ $this->assertNotEmpty( $table_fields );
- // And the table should not be empty, unless commentmeta, termmeta, or links.
- // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
- $result = $wpdb->get_results( "SELECT * FROM $prefix$table LIMIT 1" );
+ // And the table should not be empty, unless commentmeta, termmeta, or links.
+ // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
+ $result = $wpdb->get_results( "SELECT * FROM $prefix$table LIMIT 1" );
- if ( 'commentmeta' === $table || 'termmeta' === $table || 'links' === $table ) {
- $this->assertEmpty( $result );
- } else {
- $this->assertNotEmpty( $result );
- }
+ if ( 'commentmeta' === $table || 'termmeta' === $table || 'links' === $table ) {
+ $this->assertEmpty( $result );
+ } else {
+ $this->assertNotEmpty( $result );
}
-
- // Update the blog count cache to use get_blog_count().
- wp_update_network_counts();
- $this->assertSame( 2, (int) get_blog_count() );
}
- public function test_site_caches_should_invalidate_when_invalidation_is_not_suspended() {
- $site_id = self::factory()->blog->create();
+ // Update the blog count cache to use get_blog_count().
+ wp_update_network_counts();
+ $this->assertSame( 2, (int) get_blog_count() );
+ }
- $details = get_site( $site_id );
+ public function test_site_caches_should_invalidate_when_invalidation_is_not_suspended() {
+ $site_id = self::factory()->blog->create();
- $suspend = wp_suspend_cache_invalidation( false );
- update_blog_details( $site_id, array( 'path' => '/a-non-random-test-path/' ) );
- $new_details = get_site( $site_id );
- wp_suspend_cache_invalidation( $suspend );
+ $details = get_site( $site_id );
- $this->assertNotEquals( $details->path, $new_details->path );
- }
+ $suspend = wp_suspend_cache_invalidation( false );
+ update_blog_details( $site_id, array( 'path' => '/a-non-random-test-path/' ) );
+ $new_details = get_site( $site_id );
+ wp_suspend_cache_invalidation( $suspend );
- public function test_site_caches_should_not_invalidate_when_invalidation_is_suspended() {
- $site_id = self::factory()->blog->create();
+ $this->assertNotEquals( $details->path, $new_details->path );
+ }
- $details = get_site( $site_id );
+ public function test_site_caches_should_not_invalidate_when_invalidation_is_suspended() {
+ $site_id = self::factory()->blog->create();
- $suspend = wp_suspend_cache_invalidation();
- update_blog_details( $site_id, array( 'path' => '/a-non-random-test-path/' ) );
- $new_details = get_site( $site_id );
- wp_suspend_cache_invalidation( $suspend );
+ $details = get_site( $site_id );
- $this->assertSame( $details->path, $new_details->path );
- }
+ $suspend = wp_suspend_cache_invalidation();
+ update_blog_details( $site_id, array( 'path' => '/a-non-random-test-path/' ) );
+ $new_details = get_site( $site_id );
+ wp_suspend_cache_invalidation( $suspend );
- /**
- * When a site is flagged as 'deleted', its data should be cleared from cache.
- */
- public function test_data_in_cache_after_wpmu_delete_blog_drop_false() {
- $blog_id = self::factory()->blog->create();
+ $this->assertSame( $details->path, $new_details->path );
+ }
- $details = get_blog_details( $blog_id, false );
- $key = md5( $details->domain . $details->path );
+ /**
+ * When a site is flagged as 'deleted', its data should be cleared from cache.
+ */
+ public function test_data_in_cache_after_wpmu_delete_blog_drop_false() {
+ $blog_id = self::factory()->blog->create();
- // Delete the site without forcing a table drop.
- wpmu_delete_blog( $blog_id, false );
+ $details = get_blog_details( $blog_id, false );
+ $key = md5( $details->domain . $details->path );
- $this->assertFalse( wp_cache_get( $blog_id, 'blog-details' ) );
- $this->assertFalse( wp_cache_get( $blog_id . 'short', 'blog-details' ) );
- $this->assertFalse( wp_cache_get( $key, 'blog-lookup' ) );
- $this->assertFalse( wp_cache_get( $key, 'blog-id-cache' ) );
- }
+ // Delete the site without forcing a table drop.
+ wpmu_delete_blog( $blog_id, false );
- /**
- * When a site is flagged as 'deleted', its data should remain in the database.
- */
- public function test_data_in_tables_after_wpmu_delete_blog_drop_false() {
- global $wpdb;
+ $this->assertFalse( wp_cache_get( $blog_id, 'blog-details' ) );
+ $this->assertFalse( wp_cache_get( $blog_id . 'short', 'blog-details' ) );
+ $this->assertFalse( wp_cache_get( $key, 'blog-lookup' ) );
+ $this->assertFalse( wp_cache_get( $key, 'blog-id-cache' ) );
+ }
- $blog_id = self::factory()->blog->create();
+ /**
+ * When a site is flagged as 'deleted', its data should remain in the database.
+ */
+ public function test_data_in_tables_after_wpmu_delete_blog_drop_false() {
+ global $wpdb;
- // Delete the site without forcing a table drop.
- wpmu_delete_blog( $blog_id, false );
+ $blog_id = self::factory()->blog->create();
- $prefix = $wpdb->get_blog_prefix( $blog_id );
- foreach ( $wpdb->tables( 'blog', false ) as $table ) {
- $suppress = $wpdb->suppress_errors();
+ // Delete the site without forcing a table drop.
+ wpmu_delete_blog( $blog_id, false );
- // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
- $table_fields = $wpdb->get_results( "DESCRIBE $prefix$table;" );
+ $prefix = $wpdb->get_blog_prefix( $blog_id );
+ foreach ( $wpdb->tables( 'blog', false ) as $table ) {
+ $suppress = $wpdb->suppress_errors();
- $wpdb->suppress_errors( $suppress );
- $this->assertNotEmpty( $table_fields, $prefix . $table );
- }
+ // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
+ $table_fields = $wpdb->get_results( "DESCRIBE $prefix$table;" );
+
+ $wpdb->suppress_errors( $suppress );
+ $this->assertNotEmpty( $table_fields, $prefix . $table );
}
+ }
- /**
- * When a site is fully deleted, its data should be cleared from cache.
- */
- public function test_data_in_cache_after_wpmu_delete_blog_drop_true() {
- $blog_id = self::factory()->blog->create();
+ /**
+ * When a site is fully deleted, its data should be cleared from cache.
+ */
+ public function test_data_in_cache_after_wpmu_delete_blog_drop_true() {
+ $blog_id = self::factory()->blog->create();
- $details = get_blog_details( $blog_id, false );
- $key = md5( $details->domain . $details->path );
+ $details = get_blog_details( $blog_id, false );
+ $key = md5( $details->domain . $details->path );
- // Delete the site and force a table drop.
- wpmu_delete_blog( $blog_id, true );
+ // Delete the site and force a table drop.
+ wpmu_delete_blog( $blog_id, true );
- $this->assertFalse( wp_cache_get( $blog_id, 'blog-details' ) );
- $this->assertFalse( wp_cache_get( $blog_id . 'short', 'blog-details' ) );
- $this->assertFalse( wp_cache_get( $key, 'blog-lookup' ) );
- $this->assertFalse( wp_cache_get( $key, 'blog-id-cache' ) );
- }
+ $this->assertFalse( wp_cache_get( $blog_id, 'blog-details' ) );
+ $this->assertFalse( wp_cache_get( $blog_id . 'short', 'blog-details' ) );
+ $this->assertFalse( wp_cache_get( $key, 'blog-lookup' ) );
+ $this->assertFalse( wp_cache_get( $key, 'blog-id-cache' ) );
+ }
- /**
- * When a site is fully deleted, its data should be removed from the database.
- */
- public function test_data_in_tables_after_wpmu_delete_blog_drop_true() {
- global $wpdb;
+ /**
+ * When a site is fully deleted, its data should be removed from the database.
+ */
+ public function test_data_in_tables_after_wpmu_delete_blog_drop_true() {
+ global $wpdb;
- $blog_id = self::factory()->blog->create();
+ $blog_id = self::factory()->blog->create();
- // Delete the site and force a table drop.
- wpmu_delete_blog( $blog_id, true );
+ // Delete the site and force a table drop.
+ wpmu_delete_blog( $blog_id, true );
- $prefix = $wpdb->get_blog_prefix( $blog_id );
- foreach ( $wpdb->tables( 'blog', false ) as $table ) {
- $suppress = $wpdb->suppress_errors();
+ $prefix = $wpdb->get_blog_prefix( $blog_id );
+ foreach ( $wpdb->tables( 'blog', false ) as $table ) {
+ $suppress = $wpdb->suppress_errors();
- // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
- $table_fields = $wpdb->get_results( "DESCRIBE $prefix$table;" );
+ // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
+ $table_fields = $wpdb->get_results( "DESCRIBE $prefix$table;" );
- $wpdb->suppress_errors( $suppress );
- $this->assertEmpty( $table_fields );
- }
+ $wpdb->suppress_errors( $suppress );
+ $this->assertEmpty( $table_fields );
}
+ }
- /**
- * When the main site of a network is fully deleted, its data should be cleared from cache.
- */
- public function test_data_in_cache_after_wpmu_delete_blog_main_site_drop_true() {
- $blog_id = 1; // The main site in our test suite has an ID of 1.
+ /**
+ * When the main site of a network is fully deleted, its data should be cleared from cache.
+ */
+ public function test_data_in_cache_after_wpmu_delete_blog_main_site_drop_true() {
+ $blog_id = 1; // The main site in our test suite has an ID of 1.
- $details = get_blog_details( $blog_id, false );
- $key = md5( $details->domain . $details->path );
+ $details = get_blog_details( $blog_id, false );
+ $key = md5( $details->domain . $details->path );
- // Delete the site and force a table drop.
- wpmu_delete_blog( $blog_id, true );
+ // Delete the site and force a table drop.
+ wpmu_delete_blog( $blog_id, true );
- $this->assertFalse( wp_cache_get( $blog_id, 'blog-details' ) );
- $this->assertFalse( wp_cache_get( $blog_id . 'short', 'blog-details' ) );
- $this->assertFalse( wp_cache_get( $key, 'blog-lookup' ) );
- $this->assertFalse( wp_cache_get( $key, 'blog-id-cache' ) );
- }
+ $this->assertFalse( wp_cache_get( $blog_id, 'blog-details' ) );
+ $this->assertFalse( wp_cache_get( $blog_id . 'short', 'blog-details' ) );
+ $this->assertFalse( wp_cache_get( $key, 'blog-lookup' ) );
+ $this->assertFalse( wp_cache_get( $key, 'blog-id-cache' ) );
+ }
- /**
- * When the main site of a network is fully deleted, its data should remain in the database.
- */
- public function test_data_in_tables_after_wpmu_delete_blog_main_site_drop_true() {
- global $wpdb;
+ /**
+ * When the main site of a network is fully deleted, its data should remain in the database.
+ */
+ public function test_data_in_tables_after_wpmu_delete_blog_main_site_drop_true() {
+ global $wpdb;
- $blog_id = 1; // The main site in our test suite has an ID of 1.
+ $blog_id = 1; // The main site in our test suite has an ID of 1.
- // Delete the site and force a table drop.
- wpmu_delete_blog( $blog_id, true );
+ // Delete the site and force a table drop.
+ wpmu_delete_blog( $blog_id, true );
- $prefix = $wpdb->get_blog_prefix( $blog_id );
- foreach ( $wpdb->tables( 'blog', false ) as $table ) {
- $suppress = $wpdb->suppress_errors();
+ $prefix = $wpdb->get_blog_prefix( $blog_id );
+ foreach ( $wpdb->tables( 'blog', false ) as $table ) {
+ $suppress = $wpdb->suppress_errors();
- // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
- $table_fields = $wpdb->get_results( "DESCRIBE $prefix$table;" );
+ // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
+ $table_fields = $wpdb->get_results( "DESCRIBE $prefix$table;" );
- $wpdb->suppress_errors( $suppress );
- $this->assertNotEmpty( $table_fields, $prefix . $table );
- }
+ $wpdb->suppress_errors( $suppress );
+ $this->assertNotEmpty( $table_fields, $prefix . $table );
}
+ }
- /**
- * The site count of a network should change when a site is flagged as 'deleted'.
- */
- public function test_network_count_after_wpmu_delete_blog_drop_false() {
- $blog_id = self::factory()->blog->create();
-
- // Delete the site without forcing a table drop.
- wpmu_delete_blog( $blog_id, false );
+ /**
+ * The site count of a network should change when a site is flagged as 'deleted'.
+ */
+ public function test_network_count_after_wpmu_delete_blog_drop_false() {
+ $blog_id = self::factory()->blog->create();
- // Update the blog count cache to use get_blog_count().
- wp_update_network_counts();
- $this->assertSame( 1, get_blog_count() );
- }
+ // Delete the site without forcing a table drop.
+ wpmu_delete_blog( $blog_id, false );
- /**
- * The site count of a network should change when a site is fully deleted.
- */
- public function test_blog_count_after_wpmu_delete_blog_drop_true() {
- $blog_id = self::factory()->blog->create();
+ // Update the blog count cache to use get_blog_count().
+ wp_update_network_counts();
+ $this->assertSame( 1, get_blog_count() );
+ }
- // Delete the site and force a table drop.
- wpmu_delete_blog( $blog_id, true );
+ /**
+ * The site count of a network should change when a site is fully deleted.
+ */
+ public function test_blog_count_after_wpmu_delete_blog_drop_true() {
+ $blog_id = self::factory()->blog->create();
- // Update the blog count cache to use get_blog_count().
- wp_update_network_counts();
- $this->assertSame( 1, get_blog_count() );
- }
+ // Delete the site and force a table drop.
+ wpmu_delete_blog( $blog_id, true );
- /**
- * When a site is deleted with wpmu_delete_blog(), only the files associated with
- * that site should be removed. When wpmu_delete_blog() is run a second time, nothing
- * should change with upload directories.
- */
- public function test_upload_directories_after_multiple_wpmu_delete_blog() {
- $filename = __FUNCTION__ . '.jpg';
- $contents = __FUNCTION__ . '_contents';
+ // Update the blog count cache to use get_blog_count().
+ wp_update_network_counts();
+ $this->assertSame( 1, get_blog_count() );
+ }
- // Upload a file to the main site on the network.
- $file1 = wp_upload_bits( $filename, null, $contents );
+ /**
+ * When a site is deleted with wpmu_delete_blog(), only the files associated with
+ * that site should be removed. When wpmu_delete_blog() is run a second time, nothing
+ * should change with upload directories.
+ */
+ public function test_upload_directories_after_multiple_wpmu_delete_blog() {
+ $filename = __FUNCTION__ . '.jpg';
+ $contents = __FUNCTION__ . '_contents';
- $blog_id = self::factory()->blog->create();
+ // Upload a file to the main site on the network.
+ $file1 = wp_upload_bits( $filename, null, $contents );
- switch_to_blog( $blog_id );
- $file2 = wp_upload_bits( $filename, null, $contents );
- restore_current_blog();
+ $blog_id = self::factory()->blog->create();
- wpmu_delete_blog( $blog_id, true );
+ switch_to_blog( $blog_id );
+ $file2 = wp_upload_bits( $filename, null, $contents );
+ restore_current_blog();
- // The file on the main site should still exist. The file on the deleted site should not.
- $this->assertFileExists( $file1['file'] );
- $this->assertFileDoesNotExist( $file2['file'] );
+ wpmu_delete_blog( $blog_id, true );
- wpmu_delete_blog( $blog_id, true );
+ // The file on the main site should still exist. The file on the deleted site should not.
+ $this->assertFileExists( $file1['file'] );
+ $this->assertFileDoesNotExist( $file2['file'] );
- // The file on the main site should still exist. The file on the deleted site should not.
- $this->assertFileExists( $file1['file'] );
- $this->assertFileDoesNotExist( $file2['file'] );
+ wpmu_delete_blog( $blog_id, true );
- unlink( $file1['file'] );
- }
+ // The file on the main site should still exist. The file on the deleted site should not.
+ $this->assertFileExists( $file1['file'] );
+ $this->assertFileDoesNotExist( $file2['file'] );
- public function test_wpmu_update_blogs_date() {
- global $wpdb;
+ unlink( $file1['file'] );
+ }
- wpmu_update_blogs_date();
+ public function test_wpmu_update_blogs_date() {
+ global $wpdb;
- $blog = get_site( get_current_blog_id() );
- $current_time = time();
+ wpmu_update_blogs_date();
- // Compare the update time with the current time, allow delta < 2.
- $this->assertEqualsWithDelta( $current_time, strtotime( $blog->last_updated ), 2, 'The dates should be equal' );
- }
+ $blog = get_site( get_current_blog_id() );
+ $current_time = time();
- /**
- * Test cached data for a site that does not exist and then again after it exists.
- *
- * @ticket 23405
- */
- public function test_get_blog_details_when_site_does_not_exist() {
- // Create an unused site so that we can then assume an invalid site ID.
- $blog_id = self::factory()->blog->create();
- ++$blog_id;
+ // Compare the update time with the current time, allow delta < 2.
+ $this->assertEqualsWithDelta( $current_time, strtotime( $blog->last_updated ), 2, 'The dates should be equal' );
+ }
- // Prime the cache for an invalid site.
- get_blog_details( $blog_id );
+ /**
+ * Test cached data for a site that does not exist and then again after it exists.
+ *
+ * @ticket 23405
+ */
+ public function test_get_blog_details_when_site_does_not_exist() {
+ // Create an unused site so that we can then assume an invalid site ID.
+ $blog_id = self::factory()->blog->create();
+ ++$blog_id;
- // When the cache is primed with an invalid site, the value is set to -1.
- $this->assertSame( -1, wp_cache_get( $blog_id, 'blog-details' ) );
+ // Prime the cache for an invalid site.
+ get_blog_details( $blog_id );
- // Create a site in the invalid site's place.
- self::factory()->blog->create();
+ // When the cache is primed with an invalid site, the value is set to -1.
+ $this->assertSame( -1, wp_cache_get( $blog_id, 'blog-details' ) );
- // When a new site is created, its cache is cleared through refresh_blog_details.
- $this->assertFalse( wp_cache_get( $blog_id, 'blog-details' ) );
+ // Create a site in the invalid site's place.
+ self::factory()->blog->create();
- $blog = get_blog_details( $blog_id );
+ // When a new site is created, its cache is cleared through refresh_blog_details.
+ $this->assertFalse( wp_cache_get( $blog_id, 'blog-details' ) );
- // When the cache is refreshed, it should now equal the site data.
- $this->assertEquals( $blog, wp_cache_get( $blog_id, 'blog-details' ) );
- }
+ $blog = get_blog_details( $blog_id );
- /**
- * @ticket 26410
- */
- public function test_blog_details_cache_invalidation() {
- update_option( 'blogname', 'foo' );
- $details = get_site( get_current_blog_id() );
- $this->assertSame( 'foo', $details->blogname );
-
- update_option( 'blogname', 'bar' );
- $details = get_site( get_current_blog_id() );
- $this->assertSame( 'bar', $details->blogname );
- }
+ // When the cache is refreshed, it should now equal the site data.
+ $this->assertEquals( $blog, wp_cache_get( $blog_id, 'blog-details' ) );
+ }
- /**
- * Test the original and cached responses for a created and then deleted site when
- * the blog ID is requested through get_blog_id_from_url().
- */
- public function test_get_blog_id_from_url() {
- $blog_id = self::factory()->blog->create();
- $details = get_site( $blog_id );
- $key = md5( $details->domain . $details->path );
-
- // Test the original response and cached response for the newly created site.
- $this->assertSame( $blog_id, get_blog_id_from_url( $details->domain, $details->path ) );
- $this->assertSame( $blog_id, wp_cache_get( $key, 'blog-id-cache' ) );
- }
+ /**
+ * @ticket 26410
+ */
+ public function test_blog_details_cache_invalidation() {
+ update_option( 'blogname', 'foo' );
+ $details = get_site( get_current_blog_id() );
+ $this->assertSame( 'foo', $details->blogname );
+
+ update_option( 'blogname', 'bar' );
+ $details = get_site( get_current_blog_id() );
+ $this->assertSame( 'bar', $details->blogname );
+ }
- /**
- * Test the case insensitivity of the site lookup.
- */
- public function test_get_blog_id_from_url_is_case_insensitive() {
- $blog_id = self::factory()->blog->create(
- array(
- 'domain' => 'example.com',
- 'path' => '/xyz',
- )
- );
- $details = get_site( $blog_id );
+ /**
+ * Test the original and cached responses for a created and then deleted site when
+ * the blog ID is requested through get_blog_id_from_url().
+ */
+ public function test_get_blog_id_from_url() {
+ $blog_id = self::factory()->blog->create();
+ $details = get_site( $blog_id );
+ $key = md5( $details->domain . $details->path );
+
+ // Test the original response and cached response for the newly created site.
+ $this->assertSame( $blog_id, get_blog_id_from_url( $details->domain, $details->path ) );
+ $this->assertSame( $blog_id, wp_cache_get( $key, 'blog-id-cache' ) );
+ }
- $this->assertSame( $blog_id, get_blog_id_from_url( strtoupper( $details->domain ), strtoupper( $details->path ) ) );
- }
+ /**
+ * Test the case insensitivity of the site lookup.
+ */
+ public function test_get_blog_id_from_url_is_case_insensitive() {
+ $blog_id = self::factory()->blog->create(
+ array(
+ 'domain' => 'example.com',
+ 'path' => '/xyz',
+ )
+ );
+ $details = get_site( $blog_id );
+
+ $this->assertSame( $blog_id, get_blog_id_from_url( strtoupper( $details->domain ), strtoupper( $details->path ) ) );
+ }
- /**
- * Test the first and cached responses for a site that does not exist.
- */
- public function test_get_blog_id_from_url_that_does_not_exist() {
- $blog_id = self::factory()->blog->create( array( 'path' => '/xyz' ) );
- $details = get_site( $blog_id );
+ /**
+ * Test the first and cached responses for a site that does not exist.
+ */
+ public function test_get_blog_id_from_url_that_does_not_exist() {
+ $blog_id = self::factory()->blog->create( array( 'path' => '/xyz' ) );
+ $details = get_site( $blog_id );
- $this->assertSame( 0, get_blog_id_from_url( $details->domain, 'foo' ) );
- $this->assertSame( -1, wp_cache_get( md5( $details->domain . 'foo' ), 'blog-id-cache' ) );
- }
+ $this->assertSame( 0, get_blog_id_from_url( $details->domain, 'foo' ) );
+ $this->assertSame( -1, wp_cache_get( md5( $details->domain . 'foo' ), 'blog-id-cache' ) );
+ }
- /**
- * A blog ID is still available if only the `deleted` flag is set for a site. The same
- * behavior would be expected if passing `false` explicitly to `wpmu_delete_blog()`.
- */
- public function test_get_blog_id_from_url_with_deleted_flag() {
- $blog_id = self::factory()->blog->create();
- $details = get_site( $blog_id );
- $key = md5( $details->domain . $details->path );
- wpmu_delete_blog( $blog_id );
-
- $this->assertSame( $blog_id, get_blog_id_from_url( $details->domain, $details->path ) );
- $this->assertSame( $blog_id, wp_cache_get( $key, 'blog-id-cache' ) );
- }
+ /**
+ * A blog ID is still available if only the `deleted` flag is set for a site. The same
+ * behavior would be expected if passing `false` explicitly to `wpmu_delete_blog()`.
+ */
+ public function test_get_blog_id_from_url_with_deleted_flag() {
+ $blog_id = self::factory()->blog->create();
+ $details = get_site( $blog_id );
+ $key = md5( $details->domain . $details->path );
+ wpmu_delete_blog( $blog_id );
+
+ $this->assertSame( $blog_id, get_blog_id_from_url( $details->domain, $details->path ) );
+ $this->assertSame( $blog_id, wp_cache_get( $key, 'blog-id-cache' ) );
+ }
- /**
- * When deleted with the drop parameter as true, the cache will first be false, then set to
- * -1 after an attempt at `get_blog_id_from_url()` is made.
- */
- public function test_get_blog_id_from_url_after_dropped() {
- $blog_id = self::factory()->blog->create();
- $details = get_site( $blog_id );
- $key = md5( $details->domain . $details->path );
- wpmu_delete_blog( $blog_id, true );
-
- $this->assertFalse( wp_cache_get( $key, 'blog-id-cache' ) );
- $this->assertSame( 0, get_blog_id_from_url( $details->domain, $details->path ) );
- $this->assertSame( -1, wp_cache_get( $key, 'blog-id-cache' ) );
- }
+ /**
+ * When deleted with the drop parameter as true, the cache will first be false, then set to
+ * -1 after an attempt at `get_blog_id_from_url()` is made.
+ */
+ public function test_get_blog_id_from_url_after_dropped() {
+ $blog_id = self::factory()->blog->create();
+ $details = get_site( $blog_id );
+ $key = md5( $details->domain . $details->path );
+ wpmu_delete_blog( $blog_id, true );
+
+ $this->assertFalse( wp_cache_get( $key, 'blog-id-cache' ) );
+ $this->assertSame( 0, get_blog_id_from_url( $details->domain, $details->path ) );
+ $this->assertSame( -1, wp_cache_get( $key, 'blog-id-cache' ) );
+ }
- /**
- * Test with default parameter of site_id as null.
- */
- public function test_is_main_site() {
- $this->assertTrue( is_main_site() );
- }
+ /**
+ * Test with default parameter of site_id as null.
+ */
+ public function test_is_main_site() {
+ $this->assertTrue( is_main_site() );
+ }
- /**
- * Test with a site id of get_current_blog_id(), which should be the same as the
- * default parameter tested above.
- */
- public function test_current_blog_id_is_main_site() {
- $this->assertTrue( is_main_site( get_current_blog_id() ) );
- }
+ /**
+ * Test with a site id of get_current_blog_id(), which should be the same as the
+ * default parameter tested above.
+ */
+ public function test_current_blog_id_is_main_site() {
+ $this->assertTrue( is_main_site( get_current_blog_id() ) );
+ }
- /**
- * Test with a site ID other than the main site to ensure a false response.
- */
- public function test_is_main_site_is_false_with_other_blog_id() {
- $blog_id = self::factory()->blog->create();
+ /**
+ * Test with a site ID other than the main site to ensure a false response.
+ */
+ public function test_is_main_site_is_false_with_other_blog_id() {
+ $blog_id = self::factory()->blog->create();
- $this->assertFalse( is_main_site( $blog_id ) );
- }
+ $this->assertFalse( is_main_site( $blog_id ) );
+ }
- /**
- * Test with no passed ID after switching to another site ID.
- */
- public function test_is_main_site_is_false_after_switch_to_blog() {
- $blog_id = self::factory()->blog->create();
- switch_to_blog( $blog_id );
+ /**
+ * Test with no passed ID after switching to another site ID.
+ */
+ public function test_is_main_site_is_false_after_switch_to_blog() {
+ $blog_id = self::factory()->blog->create();
+ switch_to_blog( $blog_id );
- $this->assertFalse( is_main_site() );
+ $this->assertFalse( is_main_site() );
- restore_current_blog();
- }
+ restore_current_blog();
+ }
- public function test_switch_upload_dir() {
- $this->assertTrue( is_main_site() );
-
- $site = get_current_site();
- $date = date_format( date_create( 'now' ), 'Y/m' );
-
- $info = wp_upload_dir();
- $this->assertSame( 'http://' . $site->domain . '/wp-content/uploads/' . $date, $info['url'] );
- $this->assertSame( ABSPATH . 'wp-content/uploads/' . $date, $info['path'] );
- $this->assertSame( '/' . $date, $info['subdir'] );
- $this->assertFalse( $info['error'] );
-
- $blog_id = self::factory()->blog->create();
-
- switch_to_blog( $blog_id );
- $info = wp_upload_dir();
- $this->assertSame( 'http://' . $site->domain . '/wp-content/uploads/sites/' . get_current_blog_id() . '/' . $date, $info['url'] );
- $this->assertSame( ABSPATH . 'wp-content/uploads/sites/' . get_current_blog_id() . '/' . $date, $info['path'] );
- $this->assertSame( '/' . $date, $info['subdir'] );
- $this->assertFalse( $info['error'] );
- restore_current_blog();
-
- $info = wp_upload_dir();
- $this->assertSame( 'http://' . $site->domain . '/wp-content/uploads/' . $date, $info['url'] );
- $this->assertSame( ABSPATH . 'wp-content/uploads/' . $date, $info['path'] );
- $this->assertSame( '/' . $date, $info['subdir'] );
- $this->assertFalse( $info['error'] );
- }
+ public function test_switch_upload_dir() {
+ $this->assertTrue( is_main_site() );
+
+ $site = get_current_site();
+ $date = date_format( date_create( 'now' ), 'Y/m' );
+
+ $info = wp_upload_dir();
+ $this->assertSame( 'http://' . $site->domain . '/wp-content/uploads/' . $date, $info['url'] );
+ $this->assertSame( ABSPATH . 'wp-content/uploads/' . $date, $info['path'] );
+ $this->assertSame( '/' . $date, $info['subdir'] );
+ $this->assertFalse( $info['error'] );
+
+ $blog_id = self::factory()->blog->create();
+
+ switch_to_blog( $blog_id );
+ $info = wp_upload_dir();
+ $this->assertSame( 'http://' . $site->domain . '/wp-content/uploads/sites/' . get_current_blog_id() . '/' . $date, $info['url'] );
+ $this->assertSame( ABSPATH . 'wp-content/uploads/sites/' . get_current_blog_id() . '/' . $date, $info['path'] );
+ $this->assertSame( '/' . $date, $info['subdir'] );
+ $this->assertFalse( $info['error'] );
+ restore_current_blog();
+
+ $info = wp_upload_dir();
+ $this->assertSame( 'http://' . $site->domain . '/wp-content/uploads/' . $date, $info['url'] );
+ $this->assertSame( ABSPATH . 'wp-content/uploads/' . $date, $info['path'] );
+ $this->assertSame( '/' . $date, $info['subdir'] );
+ $this->assertFalse( $info['error'] );
+ }
- /**
- * Test the primary purpose of get_blog_post(), to retrieve a post from
- * another site on the network.
- */
- public function test_get_blog_post_from_another_site_on_network() {
- $blog_id = self::factory()->blog->create();
- $post_id = self::factory()->post->create(); // Create a post on the primary site, ID 1.
- $post = get_post( $post_id );
- switch_to_blog( $blog_id );
+ /**
+ * Test the primary purpose of get_blog_post(), to retrieve a post from
+ * another site on the network.
+ */
+ public function test_get_blog_post_from_another_site_on_network() {
+ $blog_id = self::factory()->blog->create();
+ $post_id = self::factory()->post->create(); // Create a post on the primary site, ID 1.
+ $post = get_post( $post_id );
+ switch_to_blog( $blog_id );
- // The post created and retrieved on the main site should match the one retrieved "remotely".
- $this->assertEquals( $post, get_blog_post( 1, $post_id ) );
+ // The post created and retrieved on the main site should match the one retrieved "remotely".
+ $this->assertEquals( $post, get_blog_post( 1, $post_id ) );
- restore_current_blog();
- }
+ restore_current_blog();
+ }
- /**
- * If get_blog_post() is used on the same site, it should still work.
- */
- public function test_get_blog_post_from_same_site() {
- $post_id = self::factory()->post->create();
+ /**
+ * If get_blog_post() is used on the same site, it should still work.
+ */
+ public function test_get_blog_post_from_same_site() {
+ $post_id = self::factory()->post->create();
- $this->assertEquals( get_blog_post( 1, $post_id ), get_post( $post_id ) );
- }
+ $this->assertEquals( get_blog_post( 1, $post_id ), get_post( $post_id ) );
+ }
- /**
- * A null response should be returned if an invalid post is requested.
- */
- public function test_get_blog_post_invalid_returns_null() {
- $this->assertNull( get_blog_post( 1, 999999 ) );
- }
+ /**
+ * A null response should be returned if an invalid post is requested.
+ */
+ public function test_get_blog_post_invalid_returns_null() {
+ $this->assertNull( get_blog_post( 1, 999999 ) );
+ }
- /**
- * Added as a callback to the domain_exists filter to provide manual results for
- * the testing of the filter and for a test which does not need the database.
- */
- public function domain_exists_cb( $exists, $domain, $path, $site_id ) {
- if ( 'foo' === $domain && 'bar/' === $path ) {
- return 1234;
- } else {
- return null;
- }
+ /**
+ * Added as a callback to the domain_exists filter to provide manual results for
+ * the testing of the filter and for a test which does not need the database.
+ */
+ public function domain_exists_cb( $exists, $domain, $path, $site_id ) {
+ if ( 'foo' === $domain && 'bar/' === $path ) {
+ return 1234;
+ } else {
+ return null;
}
+ }
- public function test_domain_exists_with_default_site_id() {
- $details = get_site( 1 );
-
- $this->assertSame( 1, domain_exists( $details->domain, $details->path ) );
- }
+ public function test_domain_exists_with_default_site_id() {
+ $details = get_site( 1 );
- public function test_domain_exists_with_specified_site_id() {
- $details = get_site( 1 );
+ $this->assertSame( 1, domain_exists( $details->domain, $details->path ) );
+ }
- $this->assertSame( 1, domain_exists( $details->domain, $details->path, $details->site_id ) );
- }
+ public function test_domain_exists_with_specified_site_id() {
+ $details = get_site( 1 );
- /**
- * When the domain is valid, but the resulting site does not belong to the specified network,
- * it is marked as not existing.
- */
- public function test_domain_does_not_exist_with_invalid_site_id() {
- $details = get_site( 1 );
+ $this->assertSame( 1, domain_exists( $details->domain, $details->path, $details->site_id ) );
+ }
- $this->assertNull( domain_exists( $details->domain, $details->path, 999 ) );
- }
+ /**
+ * When the domain is valid, but the resulting site does not belong to the specified network,
+ * it is marked as not existing.
+ */
+ public function test_domain_does_not_exist_with_invalid_site_id() {
+ $details = get_site( 1 );
- public function test_invalid_domain_does_not_exist_with_default_site_id() {
- $this->assertNull( domain_exists( 'foo', 'bar' ) );
- }
+ $this->assertNull( domain_exists( $details->domain, $details->path, 999 ) );
+ }
- public function test_domain_filtered_to_exist() {
- add_filter( 'domain_exists', array( $this, 'domain_exists_cb' ), 10, 4 );
- $exists = domain_exists( 'foo', 'bar' );
- remove_filter( 'domain_exists', array( $this, 'domain_exists_cb' ), 10, 4 );
- $this->assertSame( 1234, $exists );
- }
+ public function test_invalid_domain_does_not_exist_with_default_site_id() {
+ $this->assertNull( domain_exists( 'foo', 'bar' ) );
+ }
- /**
- * When a path is passed to domain_exists, it is immediately trailing slashed. A path
- * value with or without the slash should result in the same return value.
- */
- public function test_slashed_path_in_domain_exists() {
- add_filter( 'domain_exists', array( $this, 'domain_exists_cb' ), 10, 4 );
- $exists1 = domain_exists( 'foo', 'bar' );
- $exists2 = domain_exists( 'foo', 'bar/' );
- remove_filter( 'domain_exists', array( $this, 'domain_exists_cb' ), 10, 4 );
-
- // Make sure the same result is returned with or without a trailing slash.
- $this->assertSame( $exists1, $exists2 );
- }
+ public function test_domain_filtered_to_exist() {
+ add_filter( 'domain_exists', array( $this, 'domain_exists_cb' ), 10, 4 );
+ $exists = domain_exists( 'foo', 'bar' );
+ remove_filter( 'domain_exists', array( $this, 'domain_exists_cb' ), 10, 4 );
+ $this->assertSame( 1234, $exists );
+ }
- /**
- * Tests returning an address for a given valid ID.
- */
- public function test_get_blogaddress_by_id_with_valid_id() {
- $blogaddress = get_blogaddress_by_id( 1 );
- $this->assertSame( 'http://' . WP_TESTS_DOMAIN . '/', $blogaddress );
- }
+ /**
+ * When a path is passed to domain_exists, it is immediately trailing slashed. A path
+ * value with or without the slash should result in the same return value.
+ */
+ public function test_slashed_path_in_domain_exists() {
+ add_filter( 'domain_exists', array( $this, 'domain_exists_cb' ), 10, 4 );
+ $exists1 = domain_exists( 'foo', 'bar' );
+ $exists2 = domain_exists( 'foo', 'bar/' );
+ remove_filter( 'domain_exists', array( $this, 'domain_exists_cb' ), 10, 4 );
+
+ // Make sure the same result is returned with or without a trailing slash.
+ $this->assertSame( $exists1, $exists2 );
+ }
- /**
- * Tests returning an empty string for a non-existing ID.
- */
- public function test_get_blogaddress_by_id_with_invalid_id() {
- $blogaddress = get_blogaddress_by_id( PHP_INT_MAX );
- $this->assertSame( '', $blogaddress );
- }
+ /**
+ * Tests returning an address for a given valid ID.
+ */
+ public function test_get_blogaddress_by_id_with_valid_id() {
+ $blogaddress = get_blogaddress_by_id( 1 );
+ $this->assertSame( 'http://' . WP_TESTS_DOMAIN . '/', $blogaddress );
+ }
- /**
- * @ticket 14867
- */
- public function test_get_blogaddress_by_id_scheme_reflects_blog_scheme() {
- $blog = self::factory()->blog->create();
+ /**
+ * Tests returning an empty string for a non-existing ID.
+ */
+ public function test_get_blogaddress_by_id_with_invalid_id() {
+ $blogaddress = get_blogaddress_by_id( PHP_INT_MAX );
+ $this->assertSame( '', $blogaddress );
+ }
- $this->assertSame( 'http', parse_url( get_blogaddress_by_id( $blog ), PHP_URL_SCHEME ) );
+ /**
+ * @ticket 14867
+ */
+ public function test_get_blogaddress_by_id_scheme_reflects_blog_scheme() {
+ $blog = self::factory()->blog->create();
- update_blog_option( $blog, 'home', set_url_scheme( get_blog_option( $blog, 'home' ), 'https' ) );
+ $this->assertSame( 'http', parse_url( get_blogaddress_by_id( $blog ), PHP_URL_SCHEME ) );
- $this->assertSame( 'https', parse_url( get_blogaddress_by_id( $blog ), PHP_URL_SCHEME ) );
- }
+ update_blog_option( $blog, 'home', set_url_scheme( get_blog_option( $blog, 'home' ), 'https' ) );
- /**
- * @ticket 14867
- */
- public function test_get_blogaddress_by_id_scheme_is_unaffected_by_request() {
- $blog = self::factory()->blog->create();
+ $this->assertSame( 'https', parse_url( get_blogaddress_by_id( $blog ), PHP_URL_SCHEME ) );
+ }
- $this->assertFalse( is_ssl() );
- $this->assertSame( 'http', parse_url( get_blogaddress_by_id( $blog ), PHP_URL_SCHEME ) );
+ /**
+ * @ticket 14867
+ */
+ public function test_get_blogaddress_by_id_scheme_is_unaffected_by_request() {
+ $blog = self::factory()->blog->create();
- $_SERVER['HTTPS'] = 'on';
+ $this->assertFalse( is_ssl() );
+ $this->assertSame( 'http', parse_url( get_blogaddress_by_id( $blog ), PHP_URL_SCHEME ) );
- $is_ssl = is_ssl();
- $address = parse_url( get_blogaddress_by_id( $blog ), PHP_URL_SCHEME );
+ $_SERVER['HTTPS'] = 'on';
- $this->assertTrue( $is_ssl );
- $this->assertSame( 'http', $address );
- }
+ $is_ssl = is_ssl();
+ $address = parse_url( get_blogaddress_by_id( $blog ), PHP_URL_SCHEME );
- /**
- * @ticket 33620
- * @dataProvider data_new_blog_url_schemes
- */
- public function test_new_blog_url_schemes( $home_scheme, $siteurl_scheme, $force_ssl_admin ) {
- $current_site = get_current_site();
-
- $home = get_option( 'home' );
- $siteurl = get_site_option( 'siteurl' );
- $admin = force_ssl_admin();
-
- // Setup:
- update_option( 'home', set_url_scheme( $home, $home_scheme ) );
- update_site_option( 'siteurl', set_url_scheme( $siteurl, $siteurl_scheme ) );
- force_ssl_admin( $force_ssl_admin );
-
- // Install:
- $new = wpmu_create_blog( $current_site->domain, '/new-blog/', 'New Blog', get_current_user_id() );
-
- // Reset:
- update_option( 'home', $home );
- update_site_option( 'siteurl', $siteurl );
- force_ssl_admin( $admin );
-
- // Assert:
- $this->assertNotWPError( $new );
- $this->assertSame( $home_scheme, parse_url( get_blog_option( $new, 'home' ), PHP_URL_SCHEME ) );
- $this->assertSame( $siteurl_scheme, parse_url( get_blog_option( $new, 'siteurl' ), PHP_URL_SCHEME ) );
- }
+ $this->assertTrue( $is_ssl );
+ $this->assertSame( 'http', $address );
+ }
- public function data_new_blog_url_schemes() {
- return array(
- array(
- 'https',
- 'https',
- false,
- ),
- array(
- 'http',
- 'https',
- false,
- ),
- array(
- 'https',
- 'http',
- false,
- ),
- array(
- 'http',
- 'http',
- false,
- ),
- array(
- 'http',
- 'http',
- true,
- ),
- );
- }
+ /**
+ * @ticket 33620
+ * @dataProvider data_new_blog_url_schemes
+ */
+ public function test_new_blog_url_schemes( $home_scheme, $siteurl_scheme, $force_ssl_admin ) {
+ $current_site = get_current_site();
+
+ $home = get_option( 'home' );
+ $siteurl = get_site_option( 'siteurl' );
+ $admin = force_ssl_admin();
+
+ // Setup:
+ update_option( 'home', set_url_scheme( $home, $home_scheme ) );
+ update_site_option( 'siteurl', set_url_scheme( $siteurl, $siteurl_scheme ) );
+ force_ssl_admin( $force_ssl_admin );
+
+ // Install:
+ $new = wpmu_create_blog( $current_site->domain, '/new-blog/', 'New Blog', get_current_user_id() );
+
+ // Reset:
+ update_option( 'home', $home );
+ update_site_option( 'siteurl', $siteurl );
+ force_ssl_admin( $admin );
+
+ // Assert:
+ $this->assertNotWPError( $new );
+ $this->assertSame( $home_scheme, parse_url( get_blog_option( $new, 'home' ), PHP_URL_SCHEME ) );
+ $this->assertSame( $siteurl_scheme, parse_url( get_blog_option( $new, 'siteurl' ), PHP_URL_SCHEME ) );
+ }
- /**
- * @ticket 36918
- */
- public function test_new_blog_locale() {
- $current_site = get_current_site();
+ public function data_new_blog_url_schemes() {
+ return array(
+ array(
+ 'https',
+ 'https',
+ false,
+ ),
+ array(
+ 'http',
+ 'https',
+ false,
+ ),
+ array(
+ 'https',
+ 'http',
+ false,
+ ),
+ array(
+ 'http',
+ 'http',
+ false,
+ ),
+ array(
+ 'http',
+ 'http',
+ true,
+ ),
+ );
+ }
- add_filter( 'sanitize_option_WPLANG', array( $this, 'filter_allow_unavailable_languages' ), 10, 3 );
- update_site_option( 'WPLANG', 'de_DE' );
- remove_filter( 'sanitize_option_WPLANG', array( $this, 'filter_allow_unavailable_languages' ), 10 );
+ /**
+ * @ticket 36918
+ */
+ public function test_new_blog_locale() {
+ $current_site = get_current_site();
- // No locale, use default locale.
- add_filter( 'sanitize_option_WPLANG', array( $this, 'filter_allow_unavailable_languages' ), 10, 3 );
- $blog_id = wpmu_create_blog( $current_site->domain, '/de-de/', 'New Blog', get_current_user_id() );
- remove_filter( 'sanitize_option_WPLANG', array( $this, 'filter_allow_unavailable_languages' ), 10 );
+ add_filter( 'sanitize_option_WPLANG', array( $this, 'filter_allow_unavailable_languages' ), 10, 3 );
+ update_site_option( 'WPLANG', 'de_DE' );
+ remove_filter( 'sanitize_option_WPLANG', array( $this, 'filter_allow_unavailable_languages' ), 10 );
- $this->assertNotWPError( $blog_id );
- $this->assertSame( 'de_DE', get_blog_option( $blog_id, 'WPLANG' ) );
+ // No locale, use default locale.
+ add_filter( 'sanitize_option_WPLANG', array( $this, 'filter_allow_unavailable_languages' ), 10, 3 );
+ $blog_id = wpmu_create_blog( $current_site->domain, '/de-de/', 'New Blog', get_current_user_id() );
+ remove_filter( 'sanitize_option_WPLANG', array( $this, 'filter_allow_unavailable_languages' ), 10 );
- // Custom locale.
- add_filter( 'sanitize_option_WPLANG', array( $this, 'filter_allow_unavailable_languages' ), 10, 3 );
- $blog_id = wpmu_create_blog( $current_site->domain, '/es-es/', 'New Blog', get_current_user_id(), array( 'WPLANG' => 'es_ES' ) );
- remove_filter( 'sanitize_option_WPLANG', array( $this, 'filter_allow_unavailable_languages' ), 10 );
+ $this->assertNotWPError( $blog_id );
+ $this->assertSame( 'de_DE', get_blog_option( $blog_id, 'WPLANG' ) );
- $this->assertNotWPError( $blog_id );
- $this->assertSame( 'es_ES', get_blog_option( $blog_id, 'WPLANG' ) );
+ // Custom locale.
+ add_filter( 'sanitize_option_WPLANG', array( $this, 'filter_allow_unavailable_languages' ), 10, 3 );
+ $blog_id = wpmu_create_blog( $current_site->domain, '/es-es/', 'New Blog', get_current_user_id(), array( 'WPLANG' => 'es_ES' ) );
+ remove_filter( 'sanitize_option_WPLANG', array( $this, 'filter_allow_unavailable_languages' ), 10 );
- // en_US locale.
- add_filter( 'sanitize_option_WPLANG', array( $this, 'filter_allow_unavailable_languages' ), 10, 3 );
- $blog_id = wpmu_create_blog( $current_site->domain, '/en-us/', 'New Blog', get_current_user_id(), array( 'WPLANG' => '' ) );
- remove_filter( 'sanitize_option_WPLANG', array( $this, 'filter_allow_unavailable_languages' ), 10 );
+ $this->assertNotWPError( $blog_id );
+ $this->assertSame( 'es_ES', get_blog_option( $blog_id, 'WPLANG' ) );
- $this->assertNotWPError( $blog_id );
- $this->assertSame( '', get_blog_option( $blog_id, 'WPLANG' ) );
- }
+ // en_US locale.
+ add_filter( 'sanitize_option_WPLANG', array( $this, 'filter_allow_unavailable_languages' ), 10, 3 );
+ $blog_id = wpmu_create_blog( $current_site->domain, '/en-us/', 'New Blog', get_current_user_id(), array( 'WPLANG' => '' ) );
+ remove_filter( 'sanitize_option_WPLANG', array( $this, 'filter_allow_unavailable_languages' ), 10 );
- /**
- * @ticket 40503
- */
- public function test_different_network_language() {
- $network = get_network( self::$network_ids['make.wordpress.org/'] );
+ $this->assertNotWPError( $blog_id );
+ $this->assertSame( '', get_blog_option( $blog_id, 'WPLANG' ) );
+ }
- add_filter( 'sanitize_option_WPLANG', array( $this, 'filter_allow_unavailable_languages' ), 10, 3 );
+ /**
+ * @ticket 40503
+ */
+ public function test_different_network_language() {
+ $network = get_network( self::$network_ids['make.wordpress.org/'] );
- update_network_option( self::$network_ids['make.wordpress.org/'], 'WPLANG', 'wibble' );
- $blog_id = wpmu_create_blog( $network->domain, '/de-de/', 'New Blog', get_current_user_id(), array(), $network->id );
+ add_filter( 'sanitize_option_WPLANG', array( $this, 'filter_allow_unavailable_languages' ), 10, 3 );
- remove_filter( 'sanitize_option_WPLANG', array( $this, 'filter_allow_unavailable_languages' ), 10 );
+ update_network_option( self::$network_ids['make.wordpress.org/'], 'WPLANG', 'wibble' );
+ $blog_id = wpmu_create_blog( $network->domain, '/de-de/', 'New Blog', get_current_user_id(), array(), $network->id );
- $this->assertSame( get_network_option( self::$network_ids['make.wordpress.org/'], 'WPLANG' ), get_blog_option( $blog_id, 'WPLANG' ) );
- }
+ remove_filter( 'sanitize_option_WPLANG', array( $this, 'filter_allow_unavailable_languages' ), 10 );
- /**
- * Allows to set the WPLANG option to any language.
- *
- * @param string $value The sanitized option value.
- * @param string $option The option name.
- * @param string $original_value The original value passed to the function.
- * @return string The original value.
- */
- public function filter_allow_unavailable_languages( $value, $option, $original_value ) {
- return $original_value;
- }
+ $this->assertSame( get_network_option( self::$network_ids['make.wordpress.org/'], 'WPLANG' ), get_blog_option( $blog_id, 'WPLANG' ) );
+ }
- /**
- * @ticket 29684
- */
- public function test_is_main_site_different_network() {
- $this->assertTrue( is_main_site( self::$site_ids['make.wordpress.org/'], self::$network_ids['make.wordpress.org/'] ) );
- }
+ /**
+ * Allows to set the WPLANG option to any language.
+ *
+ * @param string $value The sanitized option value.
+ * @param string $option The option name.
+ * @param string $original_value The original value passed to the function.
+ * @return string The original value.
+ */
+ public function filter_allow_unavailable_languages( $value, $option, $original_value ) {
+ return $original_value;
+ }
- /**
- * @ticket 29684
- */
- public function test_is_main_site_different_network_random_site() {
- $this->assertFalse( is_main_site( self::$site_ids['make.wordpress.org/foo/'], self::$network_ids['make.wordpress.org/'] ) );
- }
+ /**
+ * @ticket 29684
+ */
+ public function test_is_main_site_different_network() {
+ $this->assertTrue( is_main_site( self::$site_ids['make.wordpress.org/'], self::$network_ids['make.wordpress.org/'] ) );
+ }
- /**
- * @ticket 40201
- * @dataProvider data_get_site_caches
- */
- public function test_clean_blog_cache( $key, $group ) {
- $site = get_site( self::$site_ids['make.wordpress.org/'] );
+ /**
+ * @ticket 29684
+ */
+ public function test_is_main_site_different_network_random_site() {
+ $this->assertFalse( is_main_site( self::$site_ids['make.wordpress.org/foo/'], self::$network_ids['make.wordpress.org/'] ) );
+ }
- $replacements = array(
- '%blog_id%' => $site->blog_id,
- '%domain%' => $site->domain,
- '%path%' => $site->path,
- '%domain_path_key%' => md5( $site->domain . $site->path ),
- );
+ /**
+ * @ticket 40201
+ * @dataProvider data_get_site_caches
+ */
+ public function test_clean_blog_cache( $key, $group ) {
+ $site = get_site( self::$site_ids['make.wordpress.org/'] );
- $key = str_replace( array_keys( $replacements ), array_values( $replacements ), $key );
+ $replacements = array(
+ '%blog_id%' => $site->blog_id,
+ '%domain%' => $site->domain,
+ '%path%' => $site->path,
+ '%domain_path_key%' => md5( $site->domain . $site->path ),
+ );
- if ( 'sites' === $group ) { // This needs to be actual data for get_site() lookups.
- wp_cache_set( $key, (object) $site->to_array(), $group );
- } else {
- wp_cache_set( $key, 'something', $group );
- }
+ $key = str_replace( array_keys( $replacements ), array_values( $replacements ), $key );
- clean_blog_cache( $site );
- $this->assertFalse( wp_cache_get( $key, $group ) );
+ if ( 'sites' === $group ) { // This needs to be actual data for get_site() lookups.
+ wp_cache_set( $key, (object) $site->to_array(), $group );
+ } else {
+ wp_cache_set( $key, 'something', $group );
}
- /**
- * @ticket 40201
- * @dataProvider data_get_site_caches
- */
- public function test_clean_blog_cache_with_id( $key, $group ) {
- $site = get_site( self::$site_ids['make.wordpress.org/'] );
+ clean_blog_cache( $site );
+ $this->assertFalse( wp_cache_get( $key, $group ) );
+ }
- $replacements = array(
- '%blog_id%' => $site->blog_id,
- '%domain%' => $site->domain,
- '%path%' => $site->path,
- '%domain_path_key%' => md5( $site->domain . $site->path ),
- );
+ /**
+ * @ticket 40201
+ * @dataProvider data_get_site_caches
+ */
+ public function test_clean_blog_cache_with_id( $key, $group ) {
+ $site = get_site( self::$site_ids['make.wordpress.org/'] );
- $key = str_replace( array_keys( $replacements ), array_values( $replacements ), $key );
+ $replacements = array(
+ '%blog_id%' => $site->blog_id,
+ '%domain%' => $site->domain,
+ '%path%' => $site->path,
+ '%domain_path_key%' => md5( $site->domain . $site->path ),
+ );
- if ( 'sites' === $group ) { // This needs to be actual data for get_site() lookups.
- wp_cache_set( $key, (object) $site->to_array(), $group );
- } else {
- wp_cache_set( $key, 'something', $group );
- }
+ $key = str_replace( array_keys( $replacements ), array_values( $replacements ), $key );
- clean_blog_cache( $site->blog_id );
- $this->assertFalse( wp_cache_get( $key, $group ) );
+ if ( 'sites' === $group ) { // This needs to be actual data for get_site() lookups.
+ wp_cache_set( $key, (object) $site->to_array(), $group );
+ } else {
+ wp_cache_set( $key, 'something', $group );
}
- /**
- * @ticket 40201
- */
- public function test_clean_blog_cache_resets_last_changed() {
- $site = get_site( self::$site_ids['make.wordpress.org/'] );
+ clean_blog_cache( $site->blog_id );
+ $this->assertFalse( wp_cache_get( $key, $group ) );
+ }
- wp_cache_delete( 'last_changed', 'sites' );
+ /**
+ * @ticket 40201
+ */
+ public function test_clean_blog_cache_resets_last_changed() {
+ $site = get_site( self::$site_ids['make.wordpress.org/'] );
- clean_blog_cache( $site );
- $this->assertNotFalse( wp_cache_get( 'last_changed', 'sites' ) );
- }
+ wp_cache_delete( 'last_changed', 'sites' );
- /**
- * @ticket 40201
- */
- public function test_clean_blog_cache_fires_action() {
- $site = get_site( self::$site_ids['make.wordpress.org/'] );
+ clean_blog_cache( $site );
+ $this->assertNotFalse( wp_cache_get( 'last_changed', 'sites' ) );
+ }
- $old_count = did_action( 'clean_site_cache' );
+ /**
+ * @ticket 40201
+ */
+ public function test_clean_blog_cache_fires_action() {
+ $site = get_site( self::$site_ids['make.wordpress.org/'] );
- clean_blog_cache( $site );
- $this->assertSame( $old_count + 1, did_action( 'clean_site_cache' ) );
- }
+ $old_count = did_action( 'clean_site_cache' );
- /**
- * @ticket 40201
- */
- public function test_clean_blog_cache_bails_on_suspend_cache_invalidation() {
- $site = get_site( self::$site_ids['make.wordpress.org/'] );
+ clean_blog_cache( $site );
+ $this->assertSame( $old_count + 1, did_action( 'clean_site_cache' ) );
+ }
- $old_count = did_action( 'clean_site_cache' );
+ /**
+ * @ticket 40201
+ */
+ public function test_clean_blog_cache_bails_on_suspend_cache_invalidation() {
+ $site = get_site( self::$site_ids['make.wordpress.org/'] );
- $suspend = wp_suspend_cache_invalidation();
- clean_blog_cache( $site );
- wp_suspend_cache_invalidation( $suspend );
- $this->assertSame( $old_count, did_action( 'clean_site_cache' ) );
- }
+ $old_count = did_action( 'clean_site_cache' );
- /**
- * @ticket 40201
- */
- public function test_clean_blog_cache_bails_on_empty_input() {
- $old_count = did_action( 'clean_site_cache' );
+ $suspend = wp_suspend_cache_invalidation();
+ clean_blog_cache( $site );
+ wp_suspend_cache_invalidation( $suspend );
+ $this->assertSame( $old_count, did_action( 'clean_site_cache' ) );
+ }
- clean_blog_cache( null );
- $this->assertSame( $old_count, did_action( 'clean_site_cache' ) );
- }
+ /**
+ * @ticket 40201
+ */
+ public function test_clean_blog_cache_bails_on_empty_input() {
+ $old_count = did_action( 'clean_site_cache' );
- /**
- * @ticket 40201
- */
- public function test_clean_blog_cache_bails_on_non_numeric_input() {
- $old_count = did_action( 'clean_site_cache' );
+ clean_blog_cache( null );
+ $this->assertSame( $old_count, did_action( 'clean_site_cache' ) );
+ }
- clean_blog_cache( 'something' );
- $this->assertSame( $old_count, did_action( 'clean_site_cache' ) );
- }
+ /**
+ * @ticket 40201
+ */
+ public function test_clean_blog_cache_bails_on_non_numeric_input() {
+ $old_count = did_action( 'clean_site_cache' );
- /**
- * @ticket 40201
- */
- public function test_clean_blog_cache_works_with_deleted_site() {
- $site_id = 12345;
+ clean_blog_cache( 'something' );
+ $this->assertSame( $old_count, did_action( 'clean_site_cache' ) );
+ }
- wp_cache_set( $site_id, 'something', 'site-details' );
+ /**
+ * @ticket 40201
+ */
+ public function test_clean_blog_cache_works_with_deleted_site() {
+ $site_id = 12345;
- clean_blog_cache( $site_id );
- $this->assertFalse( wp_cache_get( $site_id, 'site-details' ) );
- }
+ wp_cache_set( $site_id, 'something', 'site-details' );
- /**
- * @ticket 40201
- * @dataProvider data_get_site_caches
- */
- public function test_refresh_blog_details( $key, $group ) {
- $site = get_site( self::$site_ids['make.wordpress.org/'] );
+ clean_blog_cache( $site_id );
+ $this->assertFalse( wp_cache_get( $site_id, 'site-details' ) );
+ }
- $replacements = array(
- '%blog_id%' => $site->blog_id,
- '%domain%' => $site->domain,
- '%path%' => $site->path,
- '%domain_path_key%' => md5( $site->domain . $site->path ),
- );
+ /**
+ * @ticket 40201
+ * @dataProvider data_get_site_caches
+ */
+ public function test_refresh_blog_details( $key, $group ) {
+ $site = get_site( self::$site_ids['make.wordpress.org/'] );
- $key = str_replace( array_keys( $replacements ), array_values( $replacements ), $key );
+ $replacements = array(
+ '%blog_id%' => $site->blog_id,
+ '%domain%' => $site->domain,
+ '%path%' => $site->path,
+ '%domain_path_key%' => md5( $site->domain . $site->path ),
+ );
- if ( 'sites' === $group ) { // This needs to be actual data for get_site() lookups.
- wp_cache_set( $key, (object) $site->to_array(), $group );
- } else {
- wp_cache_set( $key, 'something', $group );
- }
+ $key = str_replace( array_keys( $replacements ), array_values( $replacements ), $key );
- refresh_blog_details( $site->blog_id );
- $this->assertFalse( wp_cache_get( $key, $group ) );
+ if ( 'sites' === $group ) { // This needs to be actual data for get_site() lookups.
+ wp_cache_set( $key, (object) $site->to_array(), $group );
+ } else {
+ wp_cache_set( $key, 'something', $group );
}
- /**
- * @ticket 40201
- */
- public function test_refresh_blog_details_works_with_deleted_site() {
- $site_id = 12345;
+ refresh_blog_details( $site->blog_id );
+ $this->assertFalse( wp_cache_get( $key, $group ) );
+ }
+
+ /**
+ * @ticket 40201
+ */
+ public function test_refresh_blog_details_works_with_deleted_site() {
+ $site_id = 12345;
- wp_cache_set( $site_id, 'something', 'site-details' );
+ wp_cache_set( $site_id, 'something', 'site-details' );
- refresh_blog_details( $site_id );
- $this->assertFalse( wp_cache_get( $site_id, 'site-details' ) );
- }
+ refresh_blog_details( $site_id );
+ $this->assertFalse( wp_cache_get( $site_id, 'site-details' ) );
+ }
- /**
- * @ticket 40201
- */
- public function test_refresh_blog_details_uses_current_site_as_default() {
- $site_id = get_current_blog_id();
+ /**
+ * @ticket 40201
+ */
+ public function test_refresh_blog_details_uses_current_site_as_default() {
+ $site_id = get_current_blog_id();
- wp_cache_set( $site_id, 'something', 'site-details' );
+ wp_cache_set( $site_id, 'something', 'site-details' );
- refresh_blog_details();
- $this->assertFalse( wp_cache_get( $site_id, 'site-details' ) );
- }
+ refresh_blog_details();
+ $this->assertFalse( wp_cache_get( $site_id, 'site-details' ) );
+ }
- public function data_get_site_caches() {
- return array(
- array( '%blog_id%', 'sites' ),
- array( '%blog_id%', 'site-details' ),
- array( '%blog_id%', 'blog-details' ),
- array( '%blog_id%' . 'short', 'blog-details' ),
- array( '%domain_path_key%', 'blog-lookup' ),
- array( '%domain_path_key%', 'blog-id-cache' ),
- );
- }
+ public function data_get_site_caches() {
+ return array(
+ array( '%blog_id%', 'sites' ),
+ array( '%blog_id%', 'site-details' ),
+ array( '%blog_id%', 'blog-details' ),
+ array( '%blog_id%' . 'short', 'blog-details' ),
+ array( '%domain_path_key%', 'blog-lookup' ),
+ array( '%domain_path_key%', 'blog-id-cache' ),
+ );
+ }
- /**
- * @ticket 40364
- * @dataProvider data_wp_insert_site
- */
- public function test_wp_insert_site( $site_data, $expected_data ) {
- remove_action( 'wp_initialize_site', 'wp_initialize_site', 10 );
- $site_id = wp_insert_site( $site_data );
+ /**
+ * @ticket 40364
+ * @dataProvider data_wp_insert_site
+ */
+ public function test_wp_insert_site( $site_data, $expected_data ) {
+ remove_action( 'wp_initialize_site', 'wp_initialize_site', 10 );
+ $site_id = wp_insert_site( $site_data );
- $this->assertIsInt( $site_id );
+ $this->assertIsInt( $site_id );
- $site = get_site( $site_id );
- foreach ( $expected_data as $key => $value ) {
- $this->assertEquals( $value, $site->$key );
- }
+ $site = get_site( $site_id );
+ foreach ( $expected_data as $key => $value ) {
+ $this->assertEquals( $value, $site->$key );
}
+ }
- public function data_wp_insert_site() {
- return array(
+ public function data_wp_insert_site() {
+ return array(
+ array(
array(
- array(
- 'domain' => 'example.com',
- ),
- array(
- 'domain' => 'example.com',
- 'path' => '/',
- 'network_id' => 1,
- 'public' => 1,
- 'archived' => 0,
- 'mature' => 0,
- 'spam' => 0,
- 'deleted' => 0,
- 'lang_id' => 0,
- ),
+ 'domain' => 'example.com',
),
array(
- array(
- 'domain' => 'example.com',
- 'path' => '/foo',
- 'network_id' => 2,
- ),
- array(
- 'domain' => 'example.com',
- 'path' => '/foo/',
- 'network_id' => 2,
- ),
+ 'domain' => 'example.com',
+ 'path' => '/',
+ 'network_id' => 1,
+ 'public' => 1,
+ 'archived' => 0,
+ 'mature' => 0,
+ 'spam' => 0,
+ 'deleted' => 0,
+ 'lang_id' => 0,
),
+ ),
+ array(
array(
- array(
- 'domain' => 'example.com',
- 'path' => '/bar/',
- 'site_id' => 2,
- ),
- array(
- 'domain' => 'example.com',
- 'path' => '/bar/',
- 'network_id' => 2,
- ),
+ 'domain' => 'example.com',
+ 'path' => '/foo',
+ 'network_id' => 2,
),
array(
- array(
- 'domain' => 'example.com',
- 'path' => '/bar/',
- 'site_id' => 2,
- 'network_id' => 3,
- ),
- array(
- 'domain' => 'example.com',
- 'path' => '/bar/',
- 'network_id' => 3,
- ),
+ 'domain' => 'example.com',
+ 'path' => '/foo/',
+ 'network_id' => 2,
),
+ ),
+ array(
array(
- array(
- 'domain' => 'example.com',
- 'path' => 'foobar',
- 'public' => 0,
- 'archived' => 1,
- 'mature' => 1,
- 'spam' => 1,
- 'deleted' => 1,
- 'lang_id' => 1,
- ),
- array(
- 'domain' => 'example.com',
- 'path' => '/foobar/',
- 'public' => 0,
- 'archived' => 1,
- 'mature' => 1,
- 'spam' => 1,
- 'deleted' => 1,
- 'lang_id' => 1,
- ),
+ 'domain' => 'example.com',
+ 'path' => '/bar/',
+ 'site_id' => 2,
),
array(
- array(
- 'domain' => 'example.com:8888',
- ),
- array(
- 'domain' => 'example.com:8888',
- 'path' => '/',
- 'network_id' => 1,
- 'public' => 1,
- 'archived' => 0,
- 'mature' => 0,
- 'spam' => 0,
- 'deleted' => 0,
- 'lang_id' => 0,
- ),
+ 'domain' => 'example.com',
+ 'path' => '/bar/',
+ 'network_id' => 2,
),
- );
- }
+ ),
+ array(
+ array(
+ 'domain' => 'example.com',
+ 'path' => '/bar/',
+ 'site_id' => 2,
+ 'network_id' => 3,
+ ),
+ array(
+ 'domain' => 'example.com',
+ 'path' => '/bar/',
+ 'network_id' => 3,
+ ),
+ ),
+ array(
+ array(
+ 'domain' => 'example.com',
+ 'path' => 'foobar',
+ 'public' => 0,
+ 'archived' => 1,
+ 'mature' => 1,
+ 'spam' => 1,
+ 'deleted' => 1,
+ 'lang_id' => 1,
+ ),
+ array(
+ 'domain' => 'example.com',
+ 'path' => '/foobar/',
+ 'public' => 0,
+ 'archived' => 1,
+ 'mature' => 1,
+ 'spam' => 1,
+ 'deleted' => 1,
+ 'lang_id' => 1,
+ ),
+ ),
+ array(
+ array(
+ 'domain' => 'example.com:8888',
+ ),
+ array(
+ 'domain' => 'example.com:8888',
+ 'path' => '/',
+ 'network_id' => 1,
+ 'public' => 1,
+ 'archived' => 0,
+ 'mature' => 0,
+ 'spam' => 0,
+ 'deleted' => 0,
+ 'lang_id' => 0,
+ ),
+ ),
+ );
+ }
- /**
- * @ticket 50324
- */
- public function test_wp_insert_site_with_clean_site_cache() {
- remove_action( 'wp_initialize_site', 'wp_initialize_site', 10 );
+ /**
+ * @ticket 50324
+ */
+ public function test_wp_insert_site_with_clean_site_cache() {
+ remove_action( 'wp_initialize_site', 'wp_initialize_site', 10 );
- add_action( 'clean_site_cache', array( $this, 'action_database_insert_on_clean_site_cache' ) );
+ add_action( 'clean_site_cache', array( $this, 'action_database_insert_on_clean_site_cache' ) );
- $site_id = wp_insert_site(
- array(
- 'domain' => 'valid-domain.com',
- 'path' => '/valid-path/',
- 'network_id' => 1,
- )
- );
+ $site_id = wp_insert_site(
+ array(
+ 'domain' => 'valid-domain.com',
+ 'path' => '/valid-path/',
+ 'network_id' => 1,
+ )
+ );
- remove_action( 'clean_site_cache', array( $this, 'action_database_insert_on_clean_site_cache' ) );
+ remove_action( 'clean_site_cache', array( $this, 'action_database_insert_on_clean_site_cache' ) );
- $this->assertIsInt( $site_id );
- }
+ $this->assertIsInt( $site_id );
+ }
- public function action_database_insert_on_clean_site_cache() {
- update_site_option( 'database_write_test.' . time(), true );
- }
+ public function action_database_insert_on_clean_site_cache() {
+ update_site_option( 'database_write_test.' . time(), true );
+ }
- /**
- * @ticket 40364
- */
- public function test_wp_insert_site_empty_domain() {
- remove_action( 'wp_initialize_site', 'wp_initialize_site', 10 );
- $site_id = wp_insert_site( array( 'public' => 0 ) );
+ /**
+ * @ticket 40364
+ */
+ public function test_wp_insert_site_empty_domain() {
+ remove_action( 'wp_initialize_site', 'wp_initialize_site', 10 );
+ $site_id = wp_insert_site( array( 'public' => 0 ) );
- $this->assertWPError( $site_id );
- $this->assertSame( 'site_empty_domain', $site_id->get_error_code() );
- }
+ $this->assertWPError( $site_id );
+ $this->assertSame( 'site_empty_domain', $site_id->get_error_code() );
+ }
- /**
- * @ticket 40364
- * @dataProvider data_wp_update_site
- */
- public function test_wp_update_site( $site_data, $expected_data ) {
- $site_id = self::factory()->blog->create();
+ /**
+ * @ticket 40364
+ * @dataProvider data_wp_update_site
+ */
+ public function test_wp_update_site( $site_data, $expected_data ) {
+ $site_id = self::factory()->blog->create();
- $old_site = get_site( $site_id );
+ $old_site = get_site( $site_id );
- $result = wp_update_site( $site_id, $site_data );
+ $result = wp_update_site( $site_id, $site_data );
- $this->assertSame( $site_id, $result );
+ $this->assertSame( $site_id, $result );
- $new_site = get_site( $site_id );
- foreach ( $new_site->to_array() as $key => $value ) {
- if ( isset( $expected_data[ $key ] ) ) {
- $this->assertEquals( $expected_data[ $key ], $value );
- } elseif ( 'last_updated' === $key ) {
- $this->assertLessThanOrEqual( $value, $old_site->last_updated );
- } else {
- $this->assertSame( $old_site->$key, $value );
- }
+ $new_site = get_site( $site_id );
+ foreach ( $new_site->to_array() as $key => $value ) {
+ if ( isset( $expected_data[ $key ] ) ) {
+ $this->assertEquals( $expected_data[ $key ], $value );
+ } elseif ( 'last_updated' === $key ) {
+ $this->assertLessThanOrEqual( $value, $old_site->last_updated );
+ } else {
+ $this->assertSame( $old_site->$key, $value );
}
}
+ }
- public function data_wp_update_site() {
- return array(
+ public function data_wp_update_site() {
+ return array(
+ array(
array(
- array(
- 'domain' => 'example.com',
- 'network_id' => 2,
- ),
- array(
- 'domain' => 'example.com',
- 'site_id' => 2,
- ),
+ 'domain' => 'example.com',
+ 'network_id' => 2,
),
array(
- array(
- 'path' => 'foo',
- ),
- array(
- 'path' => '/foo/',
- ),
+ 'domain' => 'example.com',
+ 'site_id' => 2,
),
+ ),
+ array(
array(
- array(
- 'public' => 0,
- 'archived' => 1,
- 'mature' => 1,
- 'spam' => 1,
- 'deleted' => 1,
- 'lang_id' => 1,
- ),
- array(
- 'public' => 0,
- 'archived' => 1,
- 'mature' => 1,
- 'spam' => 1,
- 'deleted' => 1,
- 'lang_id' => 1,
- ),
+ 'path' => 'foo',
),
array(
- array(
- 'domain' => 'example.com:8888',
- 'network_id' => 2,
- ),
- array(
- 'domain' => 'example.com:8888',
- 'site_id' => 2,
- ),
+ 'path' => '/foo/',
),
- );
- }
+ ),
+ array(
+ array(
+ 'public' => 0,
+ 'archived' => 1,
+ 'mature' => 1,
+ 'spam' => 1,
+ 'deleted' => 1,
+ 'lang_id' => 1,
+ ),
+ array(
+ 'public' => 0,
+ 'archived' => 1,
+ 'mature' => 1,
+ 'spam' => 1,
+ 'deleted' => 1,
+ 'lang_id' => 1,
+ ),
+ ),
+ array(
+ array(
+ 'domain' => 'example.com:8888',
+ 'network_id' => 2,
+ ),
+ array(
+ 'domain' => 'example.com:8888',
+ 'site_id' => 2,
+ ),
+ ),
+ );
+ }
- /**
- * @ticket 40364
- */
- public function test_wp_update_site_empty_domain() {
- $site_id = self::factory()->blog->create();
+ /**
+ * @ticket 40364
+ */
+ public function test_wp_update_site_empty_domain() {
+ $site_id = self::factory()->blog->create();
- $result = wp_update_site( $site_id, array( 'domain' => '' ) );
+ $result = wp_update_site( $site_id, array( 'domain' => '' ) );
- $this->assertWPError( $result );
- $this->assertSame( 'site_empty_domain', $result->get_error_code() );
- }
+ $this->assertWPError( $result );
+ $this->assertSame( 'site_empty_domain', $result->get_error_code() );
+ }
- /**
- * @ticket 40364
- */
- public function test_wp_update_site_invalid_id() {
- $result = wp_update_site( 444444, array( 'domain' => 'example.com' ) );
+ /**
+ * @ticket 40364
+ */
+ public function test_wp_update_site_invalid_id() {
+ $result = wp_update_site( 444444, array( 'domain' => 'example.com' ) );
- $this->assertWPError( $result );
- $this->assertSame( 'site_not_exist', $result->get_error_code() );
- }
+ $this->assertWPError( $result );
+ $this->assertSame( 'site_not_exist', $result->get_error_code() );
+ }
- /**
- * @ticket 40364
- */
- public function test_wp_update_site_cleans_cache() {
- $site_id = self::factory()->blog->create();
- $site1 = get_site( $site_id );
+ /**
+ * @ticket 40364
+ */
+ public function test_wp_update_site_cleans_cache() {
+ $site_id = self::factory()->blog->create();
+ $site1 = get_site( $site_id );
- $result = wp_update_site( $site_id, array( 'public' => 0 ) );
- $site2 = get_site( $site_id );
+ $result = wp_update_site( $site_id, array( 'public' => 0 ) );
+ $site2 = get_site( $site_id );
- $result = wp_update_site( $site_id, array( 'public' => 1 ) );
- $site3 = get_site( $site_id );
+ $result = wp_update_site( $site_id, array( 'public' => 1 ) );
+ $site3 = get_site( $site_id );
- $this->assertSame( '1', $site1->public );
- $this->assertSame( '0', $site2->public );
- $this->assertSame( '1', $site3->public );
- }
+ $this->assertSame( '1', $site1->public );
+ $this->assertSame( '0', $site2->public );
+ $this->assertSame( '1', $site3->public );
+ }
- /**
- * @ticket 40364
- */
- public function test_wp_delete_site() {
- $site_id = self::factory()->blog->create();
+ /**
+ * @ticket 40364
+ */
+ public function test_wp_delete_site() {
+ $site_id = self::factory()->blog->create();
- $site = get_site( $site_id );
+ $site = get_site( $site_id );
- $result = wp_delete_site( $site_id );
+ $result = wp_delete_site( $site_id );
- $this->assertInstanceOf( 'WP_Site', $result );
- $this->assertSame( $result->to_array(), $site->to_array() );
- }
+ $this->assertInstanceOf( 'WP_Site', $result );
+ $this->assertSame( $result->to_array(), $site->to_array() );
+ }
- /**
- * @ticket 40364
- */
- public function test_wp_delete_site_invalid_id() {
- $result = wp_delete_site( 444444 );
+ /**
+ * @ticket 40364
+ */
+ public function test_wp_delete_site_invalid_id() {
+ $result = wp_delete_site( 444444 );
- $this->assertWPError( $result );
- $this->assertSame( 'site_not_exist', $result->get_error_code() );
- }
+ $this->assertWPError( $result );
+ $this->assertSame( 'site_not_exist', $result->get_error_code() );
+ }
- /**
- * @ticket 41333
- */
- public function test_wp_delete_site_validate_site_deletion_action() {
- add_action( 'wp_validate_site_deletion', array( $this, 'action_wp_validate_site_deletion_prevent_deletion' ) );
- $result = wp_delete_site( self::$site_ids['make.wordpress.org/'] );
- $this->assertWPError( $result );
- $this->assertSame( 'action_does_not_like_deletion', $result->get_error_code() );
- }
+ /**
+ * @ticket 41333
+ */
+ public function test_wp_delete_site_validate_site_deletion_action() {
+ add_action( 'wp_validate_site_deletion', array( $this, 'action_wp_validate_site_deletion_prevent_deletion' ) );
+ $result = wp_delete_site( self::$site_ids['make.wordpress.org/'] );
+ $this->assertWPError( $result );
+ $this->assertSame( 'action_does_not_like_deletion', $result->get_error_code() );
+ }
- public function action_wp_validate_site_deletion_prevent_deletion( $errors ) {
- $errors->add( 'action_does_not_like_deletion', 'You cannot delete this site because the action does not like it.' );
- }
+ public function action_wp_validate_site_deletion_prevent_deletion( $errors ) {
+ $errors->add( 'action_does_not_like_deletion', 'You cannot delete this site because the action does not like it.' );
+ }
- /**
- * @ticket 40364
- * @dataProvider data_wp_normalize_site_data
- */
- public function test_wp_normalize_site_data( $data, $expected ) {
- $result = wp_normalize_site_data( $data );
+ /**
+ * @ticket 40364
+ * @dataProvider data_wp_normalize_site_data
+ */
+ public function test_wp_normalize_site_data( $data, $expected ) {
+ $result = wp_normalize_site_data( $data );
- $this->assertSameSetsWithIndex( $expected, $result );
- }
+ $this->assertSameSetsWithIndex( $expected, $result );
+ }
- public function data_wp_normalize_site_data() {
- return array(
+ public function data_wp_normalize_site_data() {
+ return array(
+ array(
array(
- array(
- 'network_id' => '4',
- ),
- array(
- 'network_id' => 4,
- ),
+ 'network_id' => '4',
),
array(
- array(
- 'domain' => 'invalid domain .com',
- 'path' => 'foo',
- ),
- array(
- 'domain' => 'invaliddomain.com',
- 'path' => '/foo/',
- ),
+ 'network_id' => 4,
),
+ ),
+ array(
array(
- array(
- 'domain' => '<yet>/another-invalid-domain.com',
- ),
- array(
- 'domain' => 'yetanother-invalid-domain.com',
- ),
+ 'domain' => 'invalid domain .com',
+ 'path' => 'foo',
),
array(
- array(
- 'domain' => 'with-port.com:8888',
- ),
- array(
- 'domain' => 'with-port.com:8888',
- ),
+ 'domain' => 'invaliddomain.com',
+ 'path' => '/foo/',
),
+ ),
+ array(
array(
- array(
- 'domain' => 'subdomain.with-port.com:8888',
- ),
- array(
- 'domain' => 'subdomain.with-port.com:8888',
- ),
+ 'domain' => '<yet>/another-invalid-domain.com',
),
array(
- array(
- 'path' => '',
- ),
- array(
- 'path' => '/',
- ),
+ 'domain' => 'yetanother-invalid-domain.com',
),
+ ),
+ array(
array(
- array(
- 'public' => '0',
- 'archived' => '1',
- 'mature' => '1',
- 'spam' => true,
- 'deleted' => true,
- ),
- array(
- 'public' => 0,
- 'archived' => 1,
- 'mature' => 1,
- 'spam' => 1,
- 'deleted' => 1,
- ),
+ 'domain' => 'with-port.com:8888',
),
array(
- array(
- 'registered' => '',
- 'last_updated' => '',
- ),
- array(),
+ 'domain' => 'with-port.com:8888',
),
+ ),
+ array(
array(
- array(
- 'registered' => '0000-00-00 00:00:00',
- 'last_updated' => '0000-00-00 00:00:00',
- ),
- array(),
+ 'domain' => 'subdomain.with-port.com:8888',
),
- );
- }
+ array(
+ 'domain' => 'subdomain.with-port.com:8888',
+ ),
+ ),
+ array(
+ array(
+ 'path' => '',
+ ),
+ array(
+ 'path' => '/',
+ ),
+ ),
+ array(
+ array(
+ 'public' => '0',
+ 'archived' => '1',
+ 'mature' => '1',
+ 'spam' => true,
+ 'deleted' => true,
+ ),
+ array(
+ 'public' => 0,
+ 'archived' => 1,
+ 'mature' => 1,
+ 'spam' => 1,
+ 'deleted' => 1,
+ ),
+ ),
+ array(
+ array(
+ 'registered' => '',
+ 'last_updated' => '',
+ ),
+ array(),
+ ),
+ array(
+ array(
+ 'registered' => '0000-00-00 00:00:00',
+ 'last_updated' => '0000-00-00 00:00:00',
+ ),
+ array(),
+ ),
+ );
+ }
- /**
- * @ticket 40364
- * @dataProvider data_wp_validate_site_data
- */
- public function test_wp_validate_site_data( $data, $expected_errors ) {
- $result = new WP_Error();
- wp_validate_site_data( $result, $data );
+ /**
+ * @ticket 40364
+ * @dataProvider data_wp_validate_site_data
+ */
+ public function test_wp_validate_site_data( $data, $expected_errors ) {
+ $result = new WP_Error();
+ wp_validate_site_data( $result, $data );
- if ( empty( $expected_errors ) ) {
- $this->assertEmpty( $result->errors );
- } else {
- $this->assertSameSets( $expected_errors, array_keys( $result->errors ) );
- }
+ if ( empty( $expected_errors ) ) {
+ $this->assertEmpty( $result->errors );
+ } else {
+ $this->assertSameSets( $expected_errors, array_keys( $result->errors ) );
}
+ }
- public function data_wp_validate_site_data() {
- $date = current_time( 'mysql', true );
+ public function data_wp_validate_site_data() {
+ $date = current_time( 'mysql', true );
- return array(
+ return array(
+ array(
array(
- array(
- 'domain' => 'example-site.com',
- 'path' => '/',
- 'network_id' => 1,
- 'registered' => $date,
- 'last_updated' => $date,
- ),
- array(),
+ 'domain' => 'example-site.com',
+ 'path' => '/',
+ 'network_id' => 1,
+ 'registered' => $date,
+ 'last_updated' => $date,
),
+ array(),
+ ),
+ array(
array(
- array(
- 'path' => '/',
- 'network_id' => 1,
- 'registered' => $date,
- 'last_updated' => $date,
- ),
- array( 'site_empty_domain' ),
+ 'path' => '/',
+ 'network_id' => 1,
+ 'registered' => $date,
+ 'last_updated' => $date,
),
+ array( 'site_empty_domain' ),
+ ),
+ array(
array(
- array(
- 'domain' => 'example-site.com',
- 'network_id' => 1,
- 'registered' => $date,
- 'last_updated' => $date,
- ),
- array( 'site_empty_path' ),
+ 'domain' => 'example-site.com',
+ 'network_id' => 1,
+ 'registered' => $date,
+ 'last_updated' => $date,
),
+ array( 'site_empty_path' ),
+ ),
+ array(
array(
- array(
- 'domain' => 'example-site.com',
- 'path' => '/',
- 'registered' => $date,
- 'last_updated' => $date,
- ),
- array( 'site_empty_network_id' ),
+ 'domain' => 'example-site.com',
+ 'path' => '/',
+ 'registered' => $date,
+ 'last_updated' => $date,
),
+ array( 'site_empty_network_id' ),
+ ),
+ array(
array(
- array(
- 'domain' => get_site()->domain,
- 'path' => get_site()->path,
- 'network_id' => get_site()->network_id,
- 'registered' => $date,
- 'last_updated' => $date,
- ),
- array( 'site_taken' ),
+ 'domain' => get_site()->domain,
+ 'path' => get_site()->path,
+ 'network_id' => get_site()->network_id,
+ 'registered' => $date,
+ 'last_updated' => $date,
),
+ array( 'site_taken' ),
+ ),
+ array(
array(
- array(
- 'domain' => 'valid-domain.com',
- 'path' => '/valid-path/',
- 'network_id' => 1,
- 'registered' => '',
- 'last_updated' => $date,
- ),
- array( 'site_empty_registered' ),
+ 'domain' => 'valid-domain.com',
+ 'path' => '/valid-path/',
+ 'network_id' => 1,
+ 'registered' => '',
+ 'last_updated' => $date,
),
+ array( 'site_empty_registered' ),
+ ),
+ array(
array(
- array(
- 'domain' => 'valid-domain.com',
- 'path' => '/valid-path/',
- 'network_id' => 1,
- 'registered' => $date,
- 'last_updated' => '',
- ),
- array( 'site_empty_last_updated' ),
+ 'domain' => 'valid-domain.com',
+ 'path' => '/valid-path/',
+ 'network_id' => 1,
+ 'registered' => $date,
+ 'last_updated' => '',
),
+ array( 'site_empty_last_updated' ),
+ ),
+ array(
array(
- array(
- 'domain' => 'valid-domain.com',
- 'path' => '/valid-path/',
- 'network_id' => 1,
- 'registered' => '2000-13-32 25:25:61',
- 'last_updated' => $date,
- ),
- array( 'site_invalid_registered' ),
+ 'domain' => 'valid-domain.com',
+ 'path' => '/valid-path/',
+ 'network_id' => 1,
+ 'registered' => '2000-13-32 25:25:61',
+ 'last_updated' => $date,
),
+ array( 'site_invalid_registered' ),
+ ),
+ array(
array(
- array(
- 'domain' => 'valid-domain.com',
- 'path' => '/valid-path/',
- 'network_id' => 1,
- 'registered' => $date,
- 'last_updated' => '2000-13-32 25:25:61',
- ),
- array( 'site_invalid_last_updated' ),
+ 'domain' => 'valid-domain.com',
+ 'path' => '/valid-path/',
+ 'network_id' => 1,
+ 'registered' => $date,
+ 'last_updated' => '2000-13-32 25:25:61',
),
+ array( 'site_invalid_last_updated' ),
+ ),
+ array(
array(
- array(
- 'domain' => 'valid-domain.com',
- 'path' => '/valid-path/',
- 'network_id' => 1,
- 'registered' => '0000-00-00 00:00:00',
- 'last_updated' => $date,
- ),
- array(),
+ 'domain' => 'valid-domain.com',
+ 'path' => '/valid-path/',
+ 'network_id' => 1,
+ 'registered' => '0000-00-00 00:00:00',
+ 'last_updated' => $date,
),
+ array(),
+ ),
+ array(
array(
- array(
- 'domain' => 'valid-domain.com',
- 'path' => '/valid-path/',
- 'network_id' => 1,
- 'registered' => $date,
- 'last_updated' => '0000-00-00 00:00:00',
- ),
- array(),
+ 'domain' => 'valid-domain.com',
+ 'path' => '/valid-path/',
+ 'network_id' => 1,
+ 'registered' => $date,
+ 'last_updated' => '0000-00-00 00:00:00',
),
- );
- }
+ array(),
+ ),
+ );
+ }
- /**
- * @ticket 40364
- */
- public function test_site_dates_are_gmt() {
- $first_date = current_time( 'mysql', true );
+ /**
+ * @ticket 40364
+ */
+ public function test_site_dates_are_gmt() {
+ $first_date = current_time( 'mysql', true );
+
+ remove_action( 'wp_initialize_site', 'wp_initialize_site', 10 );
+ $site_id = wp_insert_site(
+ array(
+ 'domain' => 'valid-domain.com',
+ 'path' => '/valid-path/',
+ 'network_id' => 1,
+ )
+ );
+ $this->assertIsInt( $site_id );
+
+ $site = get_site( $site_id );
+ $this->assertEqualsWithDelta( strtotime( $first_date ), strtotime( $site->registered ), 2, 'The dates should be equal' );
+ $this->assertEqualsWithDelta( strtotime( $first_date ), strtotime( $site->last_updated ), 2, 'The dates should be equal' );
+
+ $second_date = current_time( 'mysql', true );
+ $site_id = wp_update_site( $site_id, array() );
+ $this->assertIsInt( $site_id );
+
+ $site = get_site( $site_id );
+ $this->assertEqualsWithDelta( strtotime( $first_date ), strtotime( $site->registered ), 2, 'The dates should be equal' );
+ $this->assertEqualsWithDelta( strtotime( $second_date ), strtotime( $site->last_updated ), 2, 'The dates should be equal' );
+ }
- remove_action( 'wp_initialize_site', 'wp_initialize_site', 10 );
- $site_id = wp_insert_site(
- array(
- 'domain' => 'valid-domain.com',
- 'path' => '/valid-path/',
- 'network_id' => 1,
- )
- );
- $this->assertIsInt( $site_id );
+ /**
+ * @ticket 40364
+ */
+ public function test_wp_delete_site_cleans_cache() {
+ $site_id = self::factory()->blog->create();
- $site = get_site( $site_id );
- $this->assertEqualsWithDelta( strtotime( $first_date ), strtotime( $site->registered ), 2, 'The dates should be equal' );
- $this->assertEqualsWithDelta( strtotime( $first_date ), strtotime( $site->last_updated ), 2, 'The dates should be equal' );
+ get_site( $site_id );
- $second_date = current_time( 'mysql', true );
- $site_id = wp_update_site( $site_id, array() );
- $this->assertIsInt( $site_id );
+ wp_delete_site( $site_id );
- $site = get_site( $site_id );
- $this->assertEqualsWithDelta( strtotime( $first_date ), strtotime( $site->registered ), 2, 'The dates should be equal' );
- $this->assertEqualsWithDelta( strtotime( $second_date ), strtotime( $site->last_updated ), 2, 'The dates should be equal' );
- }
+ $this->assertNull( get_site( $site_id ) );
+ }
- /**
- * @ticket 40364
- */
- public function test_wp_delete_site_cleans_cache() {
- $site_id = self::factory()->blog->create();
+ /**
+ * @ticket 40364
+ */
+ public function test_wp_update_site_cleans_old_cache_on_domain_change() {
+ $old_domain = 'old.wordpress.org';
+ $new_domain = 'new.wordpress.org';
+
+ $site = self::factory()->blog->create_and_get(
+ array(
+ 'domain' => $old_domain,
+ 'path' => '/',
+ )
+ );
+
+ // Populate the caches.
+ get_blog_details(
+ array(
+ 'domain' => $old_domain,
+ 'path' => '/',
+ )
+ );
+ get_blog_id_from_url( $old_domain, '/' );
+ get_blog_details(
+ array(
+ 'domain' => $new_domain,
+ 'path' => '/',
+ )
+ );
+ get_blog_id_from_url( $new_domain, '/' );
+
+ wp_update_site(
+ $site->id,
+ array(
+ 'domain' => $new_domain,
+ )
+ );
+
+ $domain_path_key_old = md5( $old_domain . '/' );
+ $domain_path_key_new = md5( $new_domain . '/' );
+
+ // Ensure all respective cache values are empty.
+ $result = array(
+ wp_cache_get( $domain_path_key_old, 'blog-lookup' ),
+ wp_cache_get( $domain_path_key_old, 'blog-id-cache' ),
+ wp_cache_get( 'current_blog_' . $old_domain, 'site-options' ),
+ wp_cache_get( 'current_blog_' . $old_domain . '/', 'site-options' ),
+ wp_cache_get( $domain_path_key_new, 'blog-lookup' ),
+ wp_cache_get( $domain_path_key_new, 'blog-id-cache' ),
+ wp_cache_get( 'current_blog_' . $new_domain, 'site-options' ),
+ wp_cache_get( 'current_blog_' . $new_domain . '/', 'site-options' ),
+ );
+
+ $this->assertEmpty( array_filter( $result ) );
+ }
+
+ /**
+ * @ticket 40364
+ */
+ public function test_wp_update_site_cleans_old_cache_on_path_change() {
+ $old_path = '/foo/';
+ $new_path = '/bar/';
+
+ $site = self::factory()->blog->create_and_get(
+ array(
+ 'domain' => 'test.wordpress.org',
+ 'path' => $old_path,
+ )
+ );
+
+ // Populate the caches.
+ get_blog_details(
+ array(
+ 'domain' => 'test.wordpress.org',
+ 'path' => $old_path,
+ )
+ );
+ get_blog_id_from_url( 'test.wordpress.org', $old_path );
+ get_blog_details(
+ array(
+ 'domain' => 'test.wordpress.org',
+ 'path' => $new_path,
+ )
+ );
+ get_blog_id_from_url( 'test.wordpress.org', $new_path );
+
+ wp_update_site(
+ $site->id,
+ array(
+ 'path' => $new_path,
+ )
+ );
+
+ $domain_path_key_old = md5( 'test.wordpress.org' . $old_path );
+ $domain_path_key_new = md5( 'test.wordpress.org' . $new_path );
+
+ // Ensure all respective cache values are empty.
+ $result = array(
+ wp_cache_get( $domain_path_key_old, 'blog-lookup' ),
+ wp_cache_get( $domain_path_key_old, 'blog-id-cache' ),
+ wp_cache_get( 'current_blog_test.wordpress.org' . $old_path, 'site-options' ),
+ wp_cache_get( $domain_path_key_new, 'blog-lookup' ),
+ wp_cache_get( $domain_path_key_new, 'blog-id-cache' ),
+ wp_cache_get( 'current_blog_test.wordpress.org' . $new_path, 'site-options' ),
+ );
+
+ $this->assertEmpty( array_filter( $result ) );
+ }
- get_site( $site_id );
+ /**
+ * @ticket 40364
+ * @dataProvider data_site_status_hook_triggers
+ */
+ public function test_site_status_hook_triggers( $insert_site_data, $expected_insert_hooks, $update_site_data, $expected_update_hooks ) {
+ // First: Insert a site.
+ $this->listen_to_site_status_hooks();
- wp_delete_site( $site_id );
+ $site_data = array_merge(
+ array(
+ 'domain' => 'example-site.com',
+ 'path' => '/',
+ ),
+ $insert_site_data
+ );
- $this->assertNull( get_site( $site_id ) );
- }
+ $site_id = wp_insert_site( $site_data );
- /**
- * @ticket 40364
- */
- public function test_wp_update_site_cleans_old_cache_on_domain_change() {
- $old_domain = 'old.wordpress.org';
- $new_domain = 'new.wordpress.org';
+ $insert_expected = array_fill_keys( $expected_insert_hooks, $site_id );
+ $insert_result = $this->get_listen_to_site_status_hooks_result();
- $site = self::factory()->blog->create_and_get(
- array(
- 'domain' => $old_domain,
- 'path' => '/',
- )
- );
+ // Second: Update that site.
+ $this->listen_to_site_status_hooks();
- // Populate the caches.
- get_blog_details(
- array(
- 'domain' => $old_domain,
- 'path' => '/',
- )
- );
- get_blog_id_from_url( $old_domain, '/' );
- get_blog_details(
- array(
- 'domain' => $new_domain,
- 'path' => '/',
- )
- );
- get_blog_id_from_url( $new_domain, '/' );
-
- wp_update_site(
- $site->id,
- array(
- 'domain' => $new_domain,
- )
- );
-
- $domain_path_key_old = md5( $old_domain . '/' );
- $domain_path_key_new = md5( $new_domain . '/' );
-
- // Ensure all respective cache values are empty.
- $result = array(
- wp_cache_get( $domain_path_key_old, 'blog-lookup' ),
- wp_cache_get( $domain_path_key_old, 'blog-id-cache' ),
- wp_cache_get( 'current_blog_' . $old_domain, 'site-options' ),
- wp_cache_get( 'current_blog_' . $old_domain . '/', 'site-options' ),
- wp_cache_get( $domain_path_key_new, 'blog-lookup' ),
- wp_cache_get( $domain_path_key_new, 'blog-id-cache' ),
- wp_cache_get( 'current_blog_' . $new_domain, 'site-options' ),
- wp_cache_get( 'current_blog_' . $new_domain . '/', 'site-options' ),
- );
-
- $this->assertEmpty( array_filter( $result ) );
- }
+ wp_update_site( $site_id, $update_site_data );
- /**
- * @ticket 40364
- */
- public function test_wp_update_site_cleans_old_cache_on_path_change() {
- $old_path = '/foo/';
- $new_path = '/bar/';
-
- $site = self::factory()->blog->create_and_get(
- array(
- 'domain' => 'test.wordpress.org',
- 'path' => $old_path,
- )
- );
-
- // Populate the caches.
- get_blog_details(
- array(
- 'domain' => 'test.wordpress.org',
- 'path' => $old_path,
- )
- );
- get_blog_id_from_url( 'test.wordpress.org', $old_path );
- get_blog_details(
- array(
- 'domain' => 'test.wordpress.org',
- 'path' => $new_path,
- )
- );
- get_blog_id_from_url( 'test.wordpress.org', $new_path );
-
- wp_update_site(
- $site->id,
- array(
- 'path' => $new_path,
- )
- );
-
- $domain_path_key_old = md5( 'test.wordpress.org' . $old_path );
- $domain_path_key_new = md5( 'test.wordpress.org' . $new_path );
-
- // Ensure all respective cache values are empty.
- $result = array(
- wp_cache_get( $domain_path_key_old, 'blog-lookup' ),
- wp_cache_get( $domain_path_key_old, 'blog-id-cache' ),
- wp_cache_get( 'current_blog_test.wordpress.org' . $old_path, 'site-options' ),
- wp_cache_get( $domain_path_key_new, 'blog-lookup' ),
- wp_cache_get( $domain_path_key_new, 'blog-id-cache' ),
- wp_cache_get( 'current_blog_test.wordpress.org' . $new_path, 'site-options' ),
- );
-
- $this->assertEmpty( array_filter( $result ) );
- }
+ $update_expected = array_fill_keys( $expected_update_hooks, $site_id );
+ $update_result = $this->get_listen_to_site_status_hooks_result();
- /**
- * @ticket 40364
- * @dataProvider data_site_status_hook_triggers
- */
- public function test_site_status_hook_triggers( $insert_site_data, $expected_insert_hooks, $update_site_data, $expected_update_hooks ) {
- // First: Insert a site.
- $this->listen_to_site_status_hooks();
+ // Check both insert and update results.
+ $this->assertSameSetsWithIndex( $insert_expected, $insert_result );
+ $this->assertSameSetsWithIndex( $update_expected, $update_result );
+ }
- $site_data = array_merge(
+ public function data_site_status_hook_triggers() {
+ return array(
+ array(
array(
- 'domain' => 'example-site.com',
- 'path' => '/',
+ 'public' => 1,
+ 'archived' => 1,
+ 'mature' => 1,
+ 'spam' => 1,
+ 'deleted' => 1,
),
- $insert_site_data
- );
-
- $site_id = wp_insert_site( $site_data );
-
- $insert_expected = array_fill_keys( $expected_insert_hooks, $site_id );
- $insert_result = $this->get_listen_to_site_status_hooks_result();
-
- // Second: Update that site.
- $this->listen_to_site_status_hooks();
-
- wp_update_site( $site_id, $update_site_data );
-
- $update_expected = array_fill_keys( $expected_update_hooks, $site_id );
- $update_result = $this->get_listen_to_site_status_hooks_result();
-
- // Check both insert and update results.
- $this->assertSameSetsWithIndex( $insert_expected, $insert_result );
- $this->assertSameSetsWithIndex( $update_expected, $update_result );
- }
-
- public function data_site_status_hook_triggers() {
- return array(
array(
- array(
- 'public' => 1,
- 'archived' => 1,
- 'mature' => 1,
- 'spam' => 1,
- 'deleted' => 1,
- ),
- array(
- 'archive_blog',
- 'mature_blog',
- 'make_spam_blog',
- 'make_delete_blog',
- ),
- array(
- 'public' => 0,
- 'archived' => 0,
- 'mature' => 0,
- 'spam' => 0,
- 'deleted' => 0,
- ),
- array(
- 'update_blog_public',
- 'unarchive_blog',
- 'unmature_blog',
- 'make_ham_blog',
- 'make_undelete_blog',
- ),
+ 'archive_blog',
+ 'mature_blog',
+ 'make_spam_blog',
+ 'make_delete_blog',
),
array(
- array(
- 'public' => 0,
- 'archived' => 0,
- 'mature' => 0,
- 'spam' => 0,
- 'deleted' => 0,
- ),
- array(
- 'update_blog_public',
- ),
- array(
- 'public' => 1,
- 'archived' => 1,
- 'mature' => 1,
- 'spam' => 1,
- 'deleted' => 1,
- ),
- array(
- 'update_blog_public',
- 'archive_blog',
- 'mature_blog',
- 'make_spam_blog',
- 'make_delete_blog',
- ),
+ 'public' => 0,
+ 'archived' => 0,
+ 'mature' => 0,
+ 'spam' => 0,
+ 'deleted' => 0,
),
array(
- array(
- 'public' => 0,
- 'archived' => 0,
- 'mature' => 1,
- 'spam' => 1,
- 'deleted' => 1,
- ),
- array(
- 'update_blog_public',
- 'mature_blog',
- 'make_spam_blog',
- 'make_delete_blog',
- ),
- array(
- 'public' => 0,
- 'archived' => 1,
- 'mature' => 1,
- 'spam' => 1,
- 'deleted' => 0,
- ),
- array(
- 'archive_blog',
- 'make_undelete_blog',
- ),
+ 'update_blog_public',
+ 'unarchive_blog',
+ 'unmature_blog',
+ 'make_ham_blog',
+ 'make_undelete_blog',
),
- );
- }
+ ),
+ array(
+ array(
+ 'public' => 0,
+ 'archived' => 0,
+ 'mature' => 0,
+ 'spam' => 0,
+ 'deleted' => 0,
+ ),
+ array(
+ 'update_blog_public',
+ ),
+ array(
+ 'public' => 1,
+ 'archived' => 1,
+ 'mature' => 1,
+ 'spam' => 1,
+ 'deleted' => 1,
+ ),
+ array(
+ 'update_blog_public',
+ 'archive_blog',
+ 'mature_blog',
+ 'make_spam_blog',
+ 'make_delete_blog',
+ ),
+ ),
+ array(
+ array(
+ 'public' => 0,
+ 'archived' => 0,
+ 'mature' => 1,
+ 'spam' => 1,
+ 'deleted' => 1,
+ ),
+ array(
+ 'update_blog_public',
+ 'mature_blog',
+ 'make_spam_blog',
+ 'make_delete_blog',
+ ),
+ array(
+ 'public' => 0,
+ 'archived' => 1,
+ 'mature' => 1,
+ 'spam' => 1,
+ 'deleted' => 0,
+ ),
+ array(
+ 'archive_blog',
+ 'make_undelete_blog',
+ ),
+ ),
+ );
+ }
- private function listen_to_site_status_hooks() {
- $this->site_status_hooks = array();
-
- $hooknames = array(
- 'make_spam_blog',
- 'make_ham_blog',
- 'mature_blog',
- 'unmature_blog',
- 'archive_blog',
- 'unarchive_blog',
- 'make_delete_blog',
- 'make_undelete_blog',
- 'update_blog_public',
- );
-
- foreach ( $hooknames as $hookname ) {
- add_action( $hookname, array( $this, 'action_site_status_hook' ), 10, 1 );
- }
- }
+ private function listen_to_site_status_hooks() {
+ $this->site_status_hooks = array();
- private function get_listen_to_site_status_hooks_result() {
- $hooknames = array(
- 'make_spam_blog',
- 'make_ham_blog',
- 'mature_blog',
- 'unmature_blog',
- 'archive_blog',
- 'unarchive_blog',
- 'make_delete_blog',
- 'make_undelete_blog',
- 'update_blog_public',
- );
-
- foreach ( $hooknames as $hookname ) {
- remove_action( $hookname, array( $this, 'action_site_status_hook' ), 10 );
- }
+ $hooknames = array(
+ 'make_spam_blog',
+ 'make_ham_blog',
+ 'mature_blog',
+ 'unmature_blog',
+ 'archive_blog',
+ 'unarchive_blog',
+ 'make_delete_blog',
+ 'make_undelete_blog',
+ 'update_blog_public',
+ );
- return $this->site_status_hooks;
+ foreach ( $hooknames as $hookname ) {
+ add_action( $hookname, array( $this, 'action_site_status_hook' ), 10, 1 );
}
+ }
+
+ private function get_listen_to_site_status_hooks_result() {
+ $hooknames = array(
+ 'make_spam_blog',
+ 'make_ham_blog',
+ 'mature_blog',
+ 'unmature_blog',
+ 'archive_blog',
+ 'unarchive_blog',
+ 'make_delete_blog',
+ 'make_undelete_blog',
+ 'update_blog_public',
+ );
- public function action_site_status_hook( $site_id ) {
- $this->site_status_hooks[ current_action() ] = $site_id;
+ foreach ( $hooknames as $hookname ) {
+ remove_action( $hookname, array( $this, 'action_site_status_hook' ), 10 );
}
- /**
- * @ticket 41333
- * @dataProvider data_wp_initialize_site
- */
- public function test_wp_initialize_site( $args, $expected_options, $expected_meta ) {
- $result = wp_initialize_site( self::$uninitialized_site_id, $args );
+ return $this->site_status_hooks;
+ }
- switch_to_blog( self::$uninitialized_site_id );
+ public function action_site_status_hook( $site_id ) {
+ $this->site_status_hooks[ current_action() ] = $site_id;
+ }
- $options = array();
- foreach ( $expected_options as $option => $value ) {
- $options[ $option ] = get_option( $option );
- }
+ /**
+ * @ticket 41333
+ * @dataProvider data_wp_initialize_site
+ */
+ public function test_wp_initialize_site( $args, $expected_options, $expected_meta ) {
+ $result = wp_initialize_site( self::$uninitialized_site_id, $args );
- $meta = array();
- foreach ( $expected_meta as $meta_key => $value ) {
- $meta[ $meta_key ] = get_site_meta( self::$uninitialized_site_id, $meta_key, true );
- }
+ switch_to_blog( self::$uninitialized_site_id );
+
+ $options = array();
+ foreach ( $expected_options as $option => $value ) {
+ $options[ $option ] = get_option( $option );
+ }
- restore_current_blog();
+ $meta = array();
+ foreach ( $expected_meta as $meta_key => $value ) {
+ $meta[ $meta_key ] = get_site_meta( self::$uninitialized_site_id, $meta_key, true );
+ }
- $initialized = wp_is_site_initialized( self::$uninitialized_site_id );
+ restore_current_blog();
- wp_uninitialize_site( self::$uninitialized_site_id );
+ $initialized = wp_is_site_initialized( self::$uninitialized_site_id );
- $this->assertTrue( $result );
- $this->assertTrue( $initialized );
- $this->assertSame( $expected_options, $options );
- $this->assertSame( $expected_meta, $meta );
- }
+ wp_uninitialize_site( self::$uninitialized_site_id );
- public function data_wp_initialize_site() {
- return array(
+ $this->assertTrue( $result );
+ $this->assertTrue( $initialized );
+ $this->assertSame( $expected_options, $options );
+ $this->assertSame( $expected_meta, $meta );
+ }
+
+ public function data_wp_initialize_site() {
+ return array(
+ array(
+ array(),
array(
- array(),
- array(
- 'home' => 'http://uninitialized.org',
- 'siteurl' => 'http://uninitialized.org',
- 'admin_email' => '',
- 'blog_public' => '1',
- ),
- array(),
- ),
- array(
- array(
- 'options' => array(
- 'home' => 'https://uninitialized.org',
- 'siteurl' => 'https://uninitialized.org',
- 'key' => 'value',
- ),
- 'meta' => array(
- 'key1' => 'value1',
- 'key2' => 'value2',
- ),
- ),
- array(
+ 'home' => 'http://uninitialized.org',
+ 'siteurl' => 'http://uninitialized.org',
+ 'admin_email' => '',
+ 'blog_public' => '1',
+ ),
+ array(),
+ ),
+ array(
+ array(
+ 'options' => array(
'home' => 'https://uninitialized.org',
'siteurl' => 'https://uninitialized.org',
'key' => 'value',
),
- array(
+ 'meta' => array(
'key1' => 'value1',
'key2' => 'value2',
- 'key3' => '',
),
),
array(
- array(
- 'title' => 'My New Site',
- 'options' => array(
- 'blogdescription' => 'Just My New Site',
- ),
- ),
- array(
- 'blogname' => 'My New Site',
+ 'home' => 'https://uninitialized.org',
+ 'siteurl' => 'https://uninitialized.org',
+ 'key' => 'value',
+ ),
+ array(
+ 'key1' => 'value1',
+ 'key2' => 'value2',
+ 'key3' => '',
+ ),
+ ),
+ array(
+ array(
+ 'title' => 'My New Site',
+ 'options' => array(
'blogdescription' => 'Just My New Site',
),
- array(),
),
- );
- }
-
- /**
- * @ticket 41333
- */
- public function test_wp_initialize_site_user_roles() {
- global $wpdb;
-
- $result = wp_initialize_site( self::$uninitialized_site_id, array() );
-
- switch_to_blog( self::$uninitialized_site_id );
- $table_prefix = $wpdb->get_blog_prefix( self::$uninitialized_site_id );
- $roles = get_option( $table_prefix . 'user_roles' );
- restore_current_blog();
-
- wp_uninitialize_site( self::$uninitialized_site_id );
-
- $this->assertTrue( $result );
- $this->assertSameSets(
array(
- 'administrator',
- 'editor',
- 'author',
- 'contributor',
- 'subscriber',
+ 'blogname' => 'My New Site',
+ 'blogdescription' => 'Just My New Site',
),
- array_keys( $roles )
- );
- }
-
- /**
- * @ticket 41333
- */
- public function test_wp_initialize_site_user_is_admin() {
- $result = wp_initialize_site( self::$uninitialized_site_id, array( 'user_id' => 1 ) );
+ array(),
+ ),
+ );
+ }
- switch_to_blog( self::$uninitialized_site_id );
- $user_is_admin = user_can( 1, 'manage_options' );
- $admin_email = get_option( 'admin_email' );
- restore_current_blog();
+ /**
+ * @ticket 41333
+ */
+ public function test_wp_initialize_site_user_roles() {
+ global $wpdb;
+
+ $result = wp_initialize_site( self::$uninitialized_site_id, array() );
+
+ switch_to_blog( self::$uninitialized_site_id );
+ $table_prefix = $wpdb->get_blog_prefix( self::$uninitialized_site_id );
+ $roles = get_option( $table_prefix . 'user_roles' );
+ restore_current_blog();
+
+ wp_uninitialize_site( self::$uninitialized_site_id );
+
+ $this->assertTrue( $result );
+ $this->assertSameSets(
+ array(
+ 'administrator',
+ 'editor',
+ 'author',
+ 'contributor',
+ 'subscriber',
+ ),
+ array_keys( $roles )
+ );
+ }
- wp_uninitialize_site( self::$uninitialized_site_id );
+ /**
+ * @ticket 41333
+ */
+ public function test_wp_initialize_site_user_is_admin() {
+ $result = wp_initialize_site( self::$uninitialized_site_id, array( 'user_id' => 1 ) );
- $this->assertTrue( $result );
- $this->assertTrue( $user_is_admin );
- $this->assertSame( get_userdata( 1 )->user_email, $admin_email );
- }
+ switch_to_blog( self::$uninitialized_site_id );
+ $user_is_admin = user_can( 1, 'manage_options' );
+ $admin_email = get_option( 'admin_email' );
+ restore_current_blog();
- /**
- * @ticket 41333
- */
- public function test_wp_initialize_site_args_filter() {
- add_filter( 'wp_initialize_site_args', array( $this, 'filter_wp_initialize_site_args' ), 10, 3 );
- $result = wp_initialize_site( self::$uninitialized_site_id, array( 'title' => 'My Site' ) );
+ wp_uninitialize_site( self::$uninitialized_site_id );
- switch_to_blog( self::$uninitialized_site_id );
- $site_title = get_option( 'blogname' );
- restore_current_blog();
+ $this->assertTrue( $result );
+ $this->assertTrue( $user_is_admin );
+ $this->assertSame( get_userdata( 1 )->user_email, $admin_email );
+ }
- wp_uninitialize_site( self::$uninitialized_site_id );
+ /**
+ * @ticket 41333
+ */
+ public function test_wp_initialize_site_args_filter() {
+ add_filter( 'wp_initialize_site_args', array( $this, 'filter_wp_initialize_site_args' ), 10, 3 );
+ $result = wp_initialize_site( self::$uninitialized_site_id, array( 'title' => 'My Site' ) );
- $this->assertSame(
- sprintf( 'My Site %1$d in Network %2$d', self::$uninitialized_site_id, get_site( self::$uninitialized_site_id )->network_id ),
- $site_title
- );
- }
+ switch_to_blog( self::$uninitialized_site_id );
+ $site_title = get_option( 'blogname' );
+ restore_current_blog();
- public function filter_wp_initialize_site_args( $args, $site, $network ) {
- $args['title'] = sprintf( 'My Site %1$d in Network %2$d', $site->id, $network->id );
+ wp_uninitialize_site( self::$uninitialized_site_id );
- return $args;
- }
+ $this->assertSame(
+ sprintf( 'My Site %1$d in Network %2$d', self::$uninitialized_site_id, get_site( self::$uninitialized_site_id )->network_id ),
+ $site_title
+ );
+ }
- /**
- * @ticket 41333
- */
- public function test_wp_initialize_site_empty_id() {
- $result = wp_initialize_site( 0 );
- $this->assertWPError( $result );
- $this->assertSame( 'site_empty_id', $result->get_error_code() );
- }
+ public function filter_wp_initialize_site_args( $args, $site, $network ) {
+ $args['title'] = sprintf( 'My Site %1$d in Network %2$d', $site->id, $network->id );
- /**
- * @ticket 41333
- */
- public function test_wp_initialize_site_invalid_id() {
- $result = wp_initialize_site( 123 );
- $this->assertWPError( $result );
- $this->assertSame( 'site_invalid_id', $result->get_error_code() );
- }
+ return $args;
+ }
- /**
- * @ticket 41333
- */
- public function test_wp_initialize_site_already_initialized() {
- $result = wp_initialize_site( get_current_blog_id() );
- $this->assertWPError( $result );
- $this->assertSame( 'site_already_initialized', $result->get_error_code() );
- }
+ /**
+ * @ticket 41333
+ */
+ public function test_wp_initialize_site_empty_id() {
+ $result = wp_initialize_site( 0 );
+ $this->assertWPError( $result );
+ $this->assertSame( 'site_empty_id', $result->get_error_code() );
+ }
- /**
- * @ticket 41333
- */
- public function test_wp_uninitialize_site() {
- $site_id = self::factory()->blog->create();
+ /**
+ * @ticket 41333
+ */
+ public function test_wp_initialize_site_invalid_id() {
+ $result = wp_initialize_site( 123 );
+ $this->assertWPError( $result );
+ $this->assertSame( 'site_invalid_id', $result->get_error_code() );
+ }
- $result = wp_uninitialize_site( $site_id );
- $this->assertTrue( $result );
- $this->assertFalse( wp_is_site_initialized( $site_id ) );
- }
+ /**
+ * @ticket 41333
+ */
+ public function test_wp_initialize_site_already_initialized() {
+ $result = wp_initialize_site( get_current_blog_id() );
+ $this->assertWPError( $result );
+ $this->assertSame( 'site_already_initialized', $result->get_error_code() );
+ }
- /**
- * @ticket 41333
- */
- public function test_wp_uninitialize_site_empty_id() {
- $result = wp_uninitialize_site( 0 );
- $this->assertWPError( $result );
- $this->assertSame( 'site_empty_id', $result->get_error_code() );
- }
+ /**
+ * @ticket 41333
+ */
+ public function test_wp_uninitialize_site() {
+ $site_id = self::factory()->blog->create();
- /**
- * @ticket 41333
- */
- public function test_wp_uninitialize_site_invalid_id() {
- $result = wp_uninitialize_site( 123 );
- $this->assertWPError( $result );
- $this->assertSame( 'site_invalid_id', $result->get_error_code() );
- }
+ $result = wp_uninitialize_site( $site_id );
+ $this->assertTrue( $result );
+ $this->assertFalse( wp_is_site_initialized( $site_id ) );
+ }
- /**
- * @ticket 41333
- */
- public function test_wp_uninitialize_site_already_uninitialized() {
- $result = wp_uninitialize_site( self::$uninitialized_site_id );
- $this->assertWPError( $result );
- $this->assertSame( 'site_already_uninitialized', $result->get_error_code() );
- }
+ /**
+ * @ticket 41333
+ */
+ public function test_wp_uninitialize_site_empty_id() {
+ $result = wp_uninitialize_site( 0 );
+ $this->assertWPError( $result );
+ $this->assertSame( 'site_empty_id', $result->get_error_code() );
+ }
- /**
- * @ticket 41333
- */
- public function test_wp_is_site_initialized() {
- $this->assertTrue( wp_is_site_initialized( get_current_blog_id() ) );
- $this->assertFalse( wp_is_site_initialized( self::$uninitialized_site_id ) );
- }
+ /**
+ * @ticket 41333
+ */
+ public function test_wp_uninitialize_site_invalid_id() {
+ $result = wp_uninitialize_site( 123 );
+ $this->assertWPError( $result );
+ $this->assertSame( 'site_invalid_id', $result->get_error_code() );
+ }
- /**
- * @ticket 41333
- */
- public function test_wp_is_site_initialized_prefilter() {
- add_filter( 'pre_wp_is_site_initialized', '__return_false' );
- $this->assertFalse( wp_is_site_initialized( get_current_blog_id() ) );
+ /**
+ * @ticket 41333
+ */
+ public function test_wp_uninitialize_site_already_uninitialized() {
+ $result = wp_uninitialize_site( self::$uninitialized_site_id );
+ $this->assertWPError( $result );
+ $this->assertSame( 'site_already_uninitialized', $result->get_error_code() );
+ }
- add_filter( 'pre_wp_is_site_initialized', '__return_true' );
- $this->assertTrue( wp_is_site_initialized( self::$uninitialized_site_id ) );
- }
+ /**
+ * @ticket 41333
+ */
+ public function test_wp_is_site_initialized() {
+ $this->assertTrue( wp_is_site_initialized( get_current_blog_id() ) );
+ $this->assertFalse( wp_is_site_initialized( self::$uninitialized_site_id ) );
+ }
- /**
- * @ticket 41333
- */
- public function test_wp_insert_site_forwards_args_to_wp_initialize_site() {
- $args = array(
- 'user_id' => 1,
- 'title' => 'My Site',
- 'options' => array( 'option1' => 'value1' ),
- 'meta' => array( 'meta1' => 'value1' ),
- );
-
- add_filter( 'wp_initialize_site_args', array( $this, 'filter_wp_initialize_site_args_catch_args' ) );
- $site_id = wp_insert_site(
- array_merge(
- array(
- 'domain' => 'testsite.org',
- 'path' => '/',
- ),
- $args
- )
- );
+ /**
+ * @ticket 41333
+ */
+ public function test_wp_is_site_initialized_prefilter() {
+ add_filter( 'pre_wp_is_site_initialized', '__return_false' );
+ $this->assertFalse( wp_is_site_initialized( get_current_blog_id() ) );
- $passed_args = $this->wp_initialize_site_args;
- $this->wp_initialize_site_args = null;
+ add_filter( 'pre_wp_is_site_initialized', '__return_true' );
+ $this->assertTrue( wp_is_site_initialized( self::$uninitialized_site_id ) );
+ }
- $this->assertSameSetsWithIndex( $args, $passed_args );
- }
+ /**
+ * @ticket 41333
+ */
+ public function test_wp_insert_site_forwards_args_to_wp_initialize_site() {
+ $args = array(
+ 'user_id' => 1,
+ 'title' => 'My Site',
+ 'options' => array( 'option1' => 'value1' ),
+ 'meta' => array( 'meta1' => 'value1' ),
+ );
+
+ add_filter( 'wp_initialize_site_args', array( $this, 'filter_wp_initialize_site_args_catch_args' ) );
+ $site_id = wp_insert_site(
+ array_merge(
+ array(
+ 'domain' => 'testsite.org',
+ 'path' => '/',
+ ),
+ $args
+ )
+ );
- public function filter_wp_initialize_site_args_catch_args( $args ) {
- $this->wp_initialize_site_args = $args;
+ $passed_args = $this->wp_initialize_site_args;
+ $this->wp_initialize_site_args = null;
- return $args;
- }
+ $this->assertSameSetsWithIndex( $args, $passed_args );
+ }
- /**
- * @ticket 46125
- */
- public function test_wpmu_create_blog_cache_cleanup_backward_compatible() {
- add_action( 'populate_options', array( $this, 'populate_options_callback' ) );
+ public function filter_wp_initialize_site_args_catch_args( $args ) {
+ $this->wp_initialize_site_args = $args;
- $blog_id = wpmu_create_blog( 'testsite1.example.org', '/test', 'test', 1, array( 'public' => 1 ), 2 );
+ return $args;
+ }
- /*
- * Should not hit blog_details cache initialized in $this->populate_options_callback triggered during
- * populate_options callback's call of get_blog_details.
- */
- $this->assertSame( 'http://testsite1.example.org/test', get_blog_details( $blog_id )->siteurl );
- $this->assertSame( 'http://testsite1.example.org/test', get_site( $blog_id )->siteurl );
+ /**
+ * @ticket 46125
+ */
+ public function test_wpmu_create_blog_cache_cleanup_backward_compatible() {
+ add_action( 'populate_options', array( $this, 'populate_options_callback' ) );
- remove_action( 'populate_options', array( $this, 'populate_options_callback' ) );
- }
+ $blog_id = wpmu_create_blog( 'testsite1.example.org', '/test', 'test', 1, array( 'public' => 1 ), 2 );
- /**
- * Populate options callback to warm cache for blog-details / site-details cache group
+ /*
+ * Should not hit blog_details cache initialized in $this->populate_options_callback triggered during
+ * populate_options callback's call of get_blog_details.
*/
- public function populate_options_callback() {
- // Cache blog details.
- $blog_id = get_current_blog_id();
- get_blog_details( $blog_id );
- get_site( $blog_id )->siteurl;
- // Set siteurl.
- update_option( 'siteurl', 'http://testsite1.example.org/test' );
- }
+ $this->assertSame( 'http://testsite1.example.org/test', get_blog_details( $blog_id )->siteurl );
+ $this->assertSame( 'http://testsite1.example.org/test', get_site( $blog_id )->siteurl );
- /**
- * Tests whether all expected meta are provided in deprecated `wpmu_new_blog` action.
- *
- * @dataProvider data_wpmu_new_blog_action_backward_compatible
- *
- * @ticket 46351
- */
- public function test_wpmu_new_blog_action_backward_compatible( $meta, $expected_meta ) {
- // We are testing deprecated hook. Register it to expected deprecated notices.
- $this->setExpectedDeprecated( 'wpmu_new_blog' );
- add_action( 'wpmu_new_blog', array( $this, 'wpmu_new_blog_callback' ), 10, 6 );
+ remove_action( 'populate_options', array( $this, 'populate_options_callback' ) );
+ }
+
+ /**
+ * Populate options callback to warm cache for blog-details / site-details cache group
+ */
+ public function populate_options_callback() {
+ // Cache blog details.
+ $blog_id = get_current_blog_id();
+ get_blog_details( $blog_id );
+ get_site( $blog_id )->siteurl;
+ // Set siteurl.
+ update_option( 'siteurl', 'http://testsite1.example.org/test' );
+ }
+
+ /**
+ * Tests whether all expected meta are provided in deprecated `wpmu_new_blog` action.
+ *
+ * @dataProvider data_wpmu_new_blog_action_backward_compatible
+ *
+ * @ticket 46351
+ */
+ public function test_wpmu_new_blog_action_backward_compatible( $meta, $expected_meta ) {
+ // We are testing deprecated hook. Register it to expected deprecated notices.
+ $this->setExpectedDeprecated( 'wpmu_new_blog' );
+ add_action( 'wpmu_new_blog', array( $this, 'wpmu_new_blog_callback' ), 10, 6 );
- wpmu_create_blog( 'testsite1.example.org', '/new-blog/', 'New Blog', get_current_user_id(), $meta, 1 );
+ wpmu_create_blog( 'testsite1.example.org', '/new-blog/', 'New Blog', get_current_user_id(), $meta, 1 );
- $this->assertSameSetsWithIndex( $expected_meta, $this->wp_initialize_site_meta );
+ $this->assertSameSetsWithIndex( $expected_meta, $this->wp_initialize_site_meta );
- $this->wp_initialize_site_meta = array();
- }
+ $this->wp_initialize_site_meta = array();
+ }
- /**
- * @ticket 42251
- */
- public function test_get_site_not_found_cache() {
- $new_site_id = $this->_get_next_site_id();
- $this->assertNull( get_site( $new_site_id ) );
+ /**
+ * @ticket 42251
+ */
+ public function test_get_site_not_found_cache() {
+ $new_site_id = $this->_get_next_site_id();
+ $this->assertNull( get_site( $new_site_id ) );
- $num_queries = get_num_queries();
- $this->assertNull( get_site( $new_site_id ) );
- $this->assertSame( $num_queries, get_num_queries() );
- }
+ $num_queries = get_num_queries();
+ $this->assertNull( get_site( $new_site_id ) );
+ $this->assertSame( $num_queries, get_num_queries() );
+ }
- /**
- * @ticket 42251
- */
- public function test_get_site_not_found_cache_clear() {
- $new_site_id = $this->_get_next_site_id();
- $this->assertNull( get_site( $new_site_id ) );
+ /**
+ * @ticket 42251
+ */
+ public function test_get_site_not_found_cache_clear() {
+ $new_site_id = $this->_get_next_site_id();
+ $this->assertNull( get_site( $new_site_id ) );
- $new_site = self::factory()->blog->create_and_get();
+ $new_site = self::factory()->blog->create_and_get();
- // Double-check we got the ID of the new site correct.
- $this->assertEquals( $new_site_id, $new_site->blog_id );
+ // Double-check we got the ID of the new site correct.
+ $this->assertEquals( $new_site_id, $new_site->blog_id );
- // Verify that if we fetch the site now, it's no longer false.
- $fetched_site = get_site( $new_site_id );
- $this->assertInstanceOf( 'WP_Site', $fetched_site );
- $this->assertEquals( $new_site_id, $fetched_site->blog_id );
- }
+ // Verify that if we fetch the site now, it's no longer false.
+ $fetched_site = get_site( $new_site_id );
+ $this->assertInstanceOf( 'WP_Site', $fetched_site );
+ $this->assertEquals( $new_site_id, $fetched_site->blog_id );
+ }
- /**
- * Gets the ID of the next site that will get inserted
- * @return int
- */
- protected function _get_next_site_id() {
- global $wpdb;
- // Create an entry.
- static::factory()->blog->create();
- // Get the ID after it.
- return (int) $wpdb->get_var( 'SELECT blog_id FROM ' . $wpdb->blogs . ' ORDER BY blog_ID DESC LIMIT 1' ) + 1;
- }
+ /**
+ * Gets the ID of the next site that will get inserted
+ * @return int
+ */
+ protected function _get_next_site_id() {
+ global $wpdb;
+ // Create an entry.
+ static::factory()->blog->create();
+ // Get the ID after it.
+ return (int) $wpdb->get_var( 'SELECT blog_id FROM ' . $wpdb->blogs . ' ORDER BY blog_ID DESC LIMIT 1' ) + 1;
+ }
- /**
- * Capture the $meta value passed to the wpmu_new_blog action and compare it.
- */
- public function wpmu_new_blog_callback( $blog_id, $user_id, $domain, $path, $network_id, $meta ) {
- $this->wp_initialize_site_meta = $meta;
- }
+ /**
+ * Capture the $meta value passed to the wpmu_new_blog action and compare it.
+ */
+ public function wpmu_new_blog_callback( $blog_id, $user_id, $domain, $path, $network_id, $meta ) {
+ $this->wp_initialize_site_meta = $meta;
+ }
- public function data_wpmu_new_blog_action_backward_compatible() {
- return array(
- 'default values' => array(
- array(),
- array(
- 'public' => 0, // `public` is one of the default metas in `wpmu_create_blog()' function prior to WordPress 5.1.0.
- 'WPLANG' => 'en_US', // WPLANG is another default meta in `wpmu_create_blog()` function prior to WordPress 5.1.0.
- ),
+ public function data_wpmu_new_blog_action_backward_compatible() {
+ return array(
+ 'default values' => array(
+ array(),
+ array(
+ 'public' => 0, // `public` is one of the default metas in `wpmu_create_blog()' function prior to WordPress 5.1.0.
+ 'WPLANG' => 'en_US', // WPLANG is another default meta in `wpmu_create_blog()` function prior to WordPress 5.1.0.
),
- 'public site' => array(
- array(
- 'public' => 1,
- ),
- array(
- 'public' => 1,
- 'WPLANG' => 'en_US',
- ),
+ ),
+ 'public site' => array(
+ array(
+ 'public' => 1,
),
- 'allowed_keys' => array(
- array(
- 'public' => -1,
- 'archived' => 0,
- 'mature' => 0,
- 'spam' => 0,
- 'deleted' => 0,
- 'lang_id' => 11,
+ array(
+ 'public' => 1,
+ 'WPLANG' => 'en_US',
+ ),
+ ),
+ 'allowed_keys' => array(
+ array(
+ 'public' => -1,
+ 'archived' => 0,
+ 'mature' => 0,
+ 'spam' => 0,
+ 'deleted' => 0,
+ 'lang_id' => 11,
- ),
- array(
- 'public' => -1,
- 'WPLANG' => 'en_US',
- 'archived' => 0,
- 'mature' => 0,
- 'spam' => 0,
- 'deleted' => 0,
- 'lang_id' => 11,
- ),
),
- 'extra meta key' => array(
- array(
- 'foo' => 'bar',
- ),
- array(
- 'public' => 0,
- 'foo' => 'bar',
- 'WPLANG' => 'en_US',
- ),
+ array(
+ 'public' => -1,
+ 'WPLANG' => 'en_US',
+ 'archived' => 0,
+ 'mature' => 0,
+ 'spam' => 0,
+ 'deleted' => 0,
+ 'lang_id' => 11,
),
- );
- }
+ ),
+ 'extra meta key' => array(
+ array(
+ 'foo' => 'bar',
+ ),
+ array(
+ 'public' => 0,
+ 'foo' => 'bar',
+ 'WPLANG' => 'en_US',
+ ),
+ ),
+ );
}
-
-endif;
+}
diff --git a/tests/phpunit/tests/multisite/siteDetails.php b/tests/phpunit/tests/multisite/siteDetails.php
index d8eb84382b..d892fa6500 100644
--- a/tests/phpunit/tests/multisite/siteDetails.php
+++ b/tests/phpunit/tests/multisite/siteDetails.php
@@ -1,192 +1,191 @@
<?php
-if ( is_multisite() ) :
+/**
+ * Test 'site_details' functionality.
+ *
+ * @group ms-required
+ * @group ms-site
+ * @group multisite
+ */
+class Tests_Multisite_SiteDetails extends WP_UnitTestCase {
+
+ /**
+ * @dataProvider data_allowed_options
+ *
+ * @ticket 40063
+ */
+ public function test_update_allowed_option_deletes_site_details_cache( $allowed_option, $temporary_value ) {
+ $site = get_site();
+
+ $original_value = $site->$allowed_option;
+ update_option( $allowed_option, $temporary_value );
+
+ $cached_result = wp_cache_get( $site->id, 'site-details' );
+
+ /* Reset to original value. */
+ update_option( $allowed_option, $original_value );
+
+ $this->assertFalse( $cached_result );
+ }
+
+ /**
+ * @dataProvider data_allowed_options
+ *
+ * @ticket 40063
+ */
+ public function test_update_allowed_option_deletes_blog_details_cache( $allowed_option, $temporary_value ) {
+ $blog_details = get_blog_details();
+
+ $original_value = $blog_details->$allowed_option;
+ update_option( $allowed_option, $temporary_value );
+
+ $cached_result = wp_cache_get( $blog_details->id, 'blog-details' );
+
+ /* Reset to original value. */
+ update_option( $allowed_option, $original_value );
+
+ $this->assertFalse( $cached_result );
+ }
+
+ /**
+ * @dataProvider data_allowed_options
+ *
+ * @ticket 40063
+ */
+ public function test_update_allowed_option_does_not_delete_site_cache( $allowed_option, $temporary_value ) {
+ $site = get_site();
+
+ $original_value = $site->$allowed_option;
+ update_option( $allowed_option, $temporary_value );
+
+ $cached_result = wp_cache_get( $site->id, 'sites' );
+
+ /* Reset to original value. */
+ update_option( $allowed_option, $original_value );
+
+ $this->assertNotFalse( $cached_result );
+ }
+
/**
- * Test 'site_details' functionality.
+ * @dataProvider data_allowed_options
*
- * @group ms-site
- * @group multisite
+ * @ticket 40063
*/
- class Tests_Multisite_SiteDetails extends WP_UnitTestCase {
- /**
- * @dataProvider data_allowed_options
- *
- * @ticket 40063
- */
- public function test_update_allowed_option_deletes_site_details_cache( $allowed_option, $temporary_value ) {
- $site = get_site();
-
- $original_value = $site->$allowed_option;
- update_option( $allowed_option, $temporary_value );
-
- $cached_result = wp_cache_get( $site->id, 'site-details' );
+ public function test_update_allowed_option_does_not_delete_short_blog_details_cache( $allowed_option, $temporary_value ) {
+ $blog_details = get_blog_details( null, false );
- /* Reset to original value. */
- update_option( $allowed_option, $original_value );
+ $original_value = get_option( $allowed_option );
+ update_option( $allowed_option, $temporary_value );
- $this->assertFalse( $cached_result );
- }
+ $cached_result = wp_cache_get( $blog_details->id . 'short', 'blog-details' );
- /**
- * @dataProvider data_allowed_options
- *
- * @ticket 40063
- */
- public function test_update_allowed_option_deletes_blog_details_cache( $allowed_option, $temporary_value ) {
- $blog_details = get_blog_details();
+ /* Reset to original value. */
+ update_option( $allowed_option, $original_value );
- $original_value = $blog_details->$allowed_option;
- update_option( $allowed_option, $temporary_value );
+ $this->assertNotFalse( $cached_result );
+ }
+
+ /**
+ * @dataProvider data_allowed_options
+ *
+ * @ticket 40063
+ */
+ public function test_update_allowed_option_does_not_update_sites_last_changed( $allowed_option, $temporary_value ) {
+ $last_changed = wp_cache_get_last_changed( 'sites' );
+
+ $original_value = get_option( $allowed_option );
+ update_option( $allowed_option, $temporary_value );
+
+ $new_last_changed = wp_cache_get_last_changed( 'sites' );
+
+ /* Reset to original value. */
+ update_option( $allowed_option, $original_value );
+
+ $this->assertSame( $new_last_changed, $last_changed );
+ }
+
+ public function data_allowed_options() {
+ return array(
+ array( 'blogname', 'Custom Site' ),
+ array( 'home', 'http://custom-site-url.org' ),
+ array( 'siteurl', 'http://custom-site-url.org' ),
+ array( 'post_count', '4' ),
+ );
+ }
+
+ /**
+ * @ticket 40063
+ */
+ public function test_update_random_blog_option_does_not_delete_cache() {
+ $site = get_site();
- $cached_result = wp_cache_get( $blog_details->id, 'blog-details' );
+ update_option( 'foobar_option', 'foobar_value' );
+ $cached_result = wp_cache_get( $site->id, 'sites' );
- /* Reset to original value. */
- update_option( $allowed_option, $original_value );
+ delete_option( 'foobar_option' );
- $this->assertFalse( $cached_result );
- }
+ $this->assertNotFalse( $cached_result );
+ }
- /**
- * @dataProvider data_allowed_options
- *
- * @ticket 40063
- */
- public function test_update_allowed_option_does_not_delete_site_cache( $allowed_option, $temporary_value ) {
- $site = get_site();
+ /**
+ * @ticket 40247
+ */
+ public function test_site_details_cached_including_false_values() {
+ $id = self::factory()->blog->create();
- $original_value = $site->$allowed_option;
- update_option( $allowed_option, $temporary_value );
+ $site = get_site( $id );
- $cached_result = wp_cache_get( $site->id, 'sites' );
+ // Trigger retrieving site details (post_count is not set on new sites).
+ $post_count = $site->post_count;
- /* Reset to original value. */
- update_option( $allowed_option, $original_value );
+ $cached_details = wp_cache_get( $site->id, 'site-details' );
- $this->assertNotFalse( $cached_result );
- }
+ wp_delete_site( $id );
+ wp_update_network_site_counts();
- /**
- * @dataProvider data_allowed_options
- *
- * @ticket 40063
- */
- public function test_update_allowed_option_does_not_delete_short_blog_details_cache( $allowed_option, $temporary_value ) {
- $blog_details = get_blog_details( null, false );
+ $this->assertNotFalse( $cached_details );
+ }
+
+ public function test_site_details_filter_with_blogname() {
+ add_filter( 'site_details', array( $this, '_filter_site_details_blogname' ) );
+ $site = get_site();
+ $blogname = $site->blogname;
+ remove_filter( 'site_details', array( $this, '_filter_site_details_blogname' ) );
- $original_value = get_option( $allowed_option );
- update_option( $allowed_option, $temporary_value );
-
- $cached_result = wp_cache_get( $blog_details->id . 'short', 'blog-details' );
-
- /* Reset to original value. */
- update_option( $allowed_option, $original_value );
-
- $this->assertNotFalse( $cached_result );
- }
-
- /**
- * @dataProvider data_allowed_options
- *
- * @ticket 40063
- */
- public function test_update_allowed_option_does_not_update_sites_last_changed( $allowed_option, $temporary_value ) {
- $last_changed = wp_cache_get_last_changed( 'sites' );
-
- $original_value = get_option( $allowed_option );
- update_option( $allowed_option, $temporary_value );
-
- $new_last_changed = wp_cache_get_last_changed( 'sites' );
-
- /* Reset to original value. */
- update_option( $allowed_option, $original_value );
-
- $this->assertSame( $new_last_changed, $last_changed );
- }
-
- public function data_allowed_options() {
- return array(
- array( 'blogname', 'Custom Site' ),
- array( 'home', 'http://custom-site-url.org' ),
- array( 'siteurl', 'http://custom-site-url.org' ),
- array( 'post_count', '4' ),
- );
- }
-
- /**
- * @ticket 40063
- */
- public function test_update_random_blog_option_does_not_delete_cache() {
- $site = get_site();
+ $this->assertSame( 'Foo Bar', $blogname );
+ }
- update_option( 'foobar_option', 'foobar_value' );
- $cached_result = wp_cache_get( $site->id, 'sites' );
+ public function _filter_site_details_blogname( $details ) {
+ $details->blogname = 'Foo Bar';
+ return $details;
+ }
- delete_option( 'foobar_option' );
-
- $this->assertNotFalse( $cached_result );
- }
-
- /**
- * @ticket 40247
- */
- public function test_site_details_cached_including_false_values() {
- $id = self::factory()->blog->create();
-
- $site = get_site( $id );
+ /**
+ * @ticket 40458
+ */
+ public function test_site_details_filter_with_custom_value_isetter() {
+ add_filter( 'site_details', array( $this, '_filter_site_details_custom_value' ) );
+ $site = get_site();
+ $custom_value_isset = isset( $site->custom_value );
+ remove_filter( 'site_details', array( $this, '_filter_site_details_custom_value' ) );
- // Trigger retrieving site details (post_count is not set on new sites).
- $post_count = $site->post_count;
+ $this->assertTrue( $custom_value_isset );
+ }
- $cached_details = wp_cache_get( $site->id, 'site-details' );
-
- wp_delete_site( $id );
- wp_update_network_site_counts();
-
- $this->assertNotFalse( $cached_details );
- }
-
- public function test_site_details_filter_with_blogname() {
- add_filter( 'site_details', array( $this, '_filter_site_details_blogname' ) );
- $site = get_site();
- $blogname = $site->blogname;
- remove_filter( 'site_details', array( $this, '_filter_site_details_blogname' ) );
-
- $this->assertSame( 'Foo Bar', $blogname );
- }
+ /**
+ * @ticket 40458
+ */
+ public function test_site_details_filter_with_custom_value_getter() {
+ add_filter( 'site_details', array( $this, '_filter_site_details_custom_value' ) );
+ $site = get_site();
+ $custom_value = $site->custom_value;
+ remove_filter( 'site_details', array( $this, '_filter_site_details_custom_value' ) );
- public function _filter_site_details_blogname( $details ) {
- $details->blogname = 'Foo Bar';
- return $details;
- }
-
- /**
- * @ticket 40458
- */
- public function test_site_details_filter_with_custom_value_isetter() {
- add_filter( 'site_details', array( $this, '_filter_site_details_custom_value' ) );
- $site = get_site();
- $custom_value_isset = isset( $site->custom_value );
- remove_filter( 'site_details', array( $this, '_filter_site_details_custom_value' ) );
-
- $this->assertTrue( $custom_value_isset );
- }
-
- /**
- * @ticket 40458
- */
- public function test_site_details_filter_with_custom_value_getter() {
- add_filter( 'site_details', array( $this, '_filter_site_details_custom_value' ) );
- $site = get_site();
- $custom_value = $site->custom_value;
- remove_filter( 'site_details', array( $this, '_filter_site_details_custom_value' ) );
-
- $this->assertSame( 'foo', $custom_value );
- }
-
- public function _filter_site_details_custom_value( $details ) {
- $details->custom_value = 'foo';
- return $details;
- }
+ $this->assertSame( 'foo', $custom_value );
}
-endif;
+ public function _filter_site_details_custom_value( $details ) {
+ $details->custom_value = 'foo';
+ return $details;
+ }
+}
diff --git a/tests/phpunit/tests/multisite/siteMeta.php b/tests/phpunit/tests/multisite/siteMeta.php
index ad59c75e34..066068b415 100644
--- a/tests/phpunit/tests/multisite/siteMeta.php
+++ b/tests/phpunit/tests/multisite/siteMeta.php
@@ -1,474 +1,472 @@
<?php
-if ( is_multisite() ) :
+/**
+ * @group ms-required
+ * @group ms-site
+ * @group multisite
+ * @group meta
+ * @ticket 37923
+ */
+class Tests_Multisite_SiteMeta extends WP_UnitTestCase {
+
+ protected static $site_id;
+ protected static $site_id2;
+ protected static $flag_was_set;
+
+ public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
+ self::$site_id = $factory->blog->create(
+ array(
+ 'domain' => 'wordpress.org',
+ 'path' => '/',
+ )
+ );
+ self::$site_id2 = $factory->blog->create(
+ array(
+ 'domain' => 'wordpress.org',
+ 'path' => '/foo/',
+ )
+ );
+
+ // Populate the main network flag as necessary.
+ self::$flag_was_set = true;
+ if ( false === get_network_option( get_main_network_id(), 'site_meta_supported', false ) ) {
+ self::$flag_was_set = false;
+ is_site_meta_supported();
+ }
+ }
- /**
- * @group ms-site
- * @group multisite
- * @group meta
- * @ticket 37923
- */
- class Tests_Multisite_SiteMeta extends WP_UnitTestCase {
- protected static $site_id;
- protected static $site_id2;
- protected static $flag_was_set;
-
- public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
- self::$site_id = $factory->blog->create(
- array(
- 'domain' => 'wordpress.org',
- 'path' => '/',
- )
- );
- self::$site_id2 = $factory->blog->create(
- array(
- 'domain' => 'wordpress.org',
- 'path' => '/foo/',
- )
- );
-
- // Populate the main network flag as necessary.
- self::$flag_was_set = true;
- if ( false === get_network_option( get_main_network_id(), 'site_meta_supported', false ) ) {
- self::$flag_was_set = false;
- is_site_meta_supported();
- }
+ public static function wpTearDownAfterClass() {
+ // Delete the possibly previously populated main network flag.
+ if ( ! self::$flag_was_set ) {
+ delete_network_option( get_main_network_id(), 'site_meta_supported' );
}
- public static function wpTearDownAfterClass() {
- // Delete the possibly previously populated main network flag.
- if ( ! self::$flag_was_set ) {
- delete_network_option( get_main_network_id(), 'site_meta_supported' );
- }
+ wp_delete_site( self::$site_id );
+ wp_delete_site( self::$site_id2 );
- wp_delete_site( self::$site_id );
- wp_delete_site( self::$site_id2 );
+ wp_update_network_site_counts();
+ }
- wp_update_network_site_counts();
- }
+ public function test_is_site_meta_supported() {
+ $this->assertTrue( is_site_meta_supported() );
+ }
- public function test_is_site_meta_supported() {
- $this->assertTrue( is_site_meta_supported() );
- }
+ public function test_is_site_meta_supported_filtered() {
+ add_filter( 'pre_site_option_site_meta_supported', '__return_zero' );
+ $this->assertFalse( is_site_meta_supported() );
+ }
- public function test_is_site_meta_supported_filtered() {
- add_filter( 'pre_site_option_site_meta_supported', '__return_zero' );
- $this->assertFalse( is_site_meta_supported() );
+ public function test_add() {
+ if ( ! is_site_meta_supported() ) {
+ $this->markTestSkipped( 'Test only runs with the blogmeta database table installed.' );
}
- public function test_add() {
- if ( ! is_site_meta_supported() ) {
- $this->markTestSkipped( 'Test only runs with the blogmeta database table installed.' );
- }
+ $this->assertNotEmpty( add_site_meta( self::$site_id, 'foo', 'bar' ) );
+ $this->assertSame( 'bar', get_site_meta( self::$site_id, 'foo', true ) );
+ }
- $this->assertNotEmpty( add_site_meta( self::$site_id, 'foo', 'bar' ) );
- $this->assertSame( 'bar', get_site_meta( self::$site_id, 'foo', true ) );
+ public function test_add_unique() {
+ if ( ! is_site_meta_supported() ) {
+ $this->markTestSkipped( 'Test only runs with the blogmeta database table installed.' );
}
- public function test_add_unique() {
- if ( ! is_site_meta_supported() ) {
- $this->markTestSkipped( 'Test only runs with the blogmeta database table installed.' );
- }
+ $this->assertNotEmpty( add_site_meta( self::$site_id, 'foo', 'bar' ) );
+ $this->assertFalse( add_site_meta( self::$site_id, 'foo', 'bar', true ) );
+ }
- $this->assertNotEmpty( add_site_meta( self::$site_id, 'foo', 'bar' ) );
- $this->assertFalse( add_site_meta( self::$site_id, 'foo', 'bar', true ) );
+ public function test_delete() {
+ if ( ! is_site_meta_supported() ) {
+ $this->markTestSkipped( 'Test only runs with the blogmeta database table installed.' );
}
- public function test_delete() {
- if ( ! is_site_meta_supported() ) {
- $this->markTestSkipped( 'Test only runs with the blogmeta database table installed.' );
- }
+ add_site_meta( self::$site_id, 'foo', 'bar' );
- add_site_meta( self::$site_id, 'foo', 'bar' );
+ $this->assertTrue( delete_site_meta( self::$site_id, 'foo' ) );
+ $this->assertEmpty( get_site_meta( self::$site_id, 'foo', true ) );
+ }
- $this->assertTrue( delete_site_meta( self::$site_id, 'foo' ) );
- $this->assertEmpty( get_site_meta( self::$site_id, 'foo', true ) );
+ public function test_delete_with_invalid_meta_key_should_return_false() {
+ if ( ! is_site_meta_supported() ) {
+ $this->markTestSkipped( 'Test only runs with the blogmeta database table installed.' );
}
- public function test_delete_with_invalid_meta_key_should_return_false() {
- if ( ! is_site_meta_supported() ) {
- $this->markTestSkipped( 'Test only runs with the blogmeta database table installed.' );
- }
+ $this->assertFalse( delete_site_meta( self::$site_id, 'foo' ) );
+ }
- $this->assertFalse( delete_site_meta( self::$site_id, 'foo' ) );
+ public function test_delete_should_respect_meta_value() {
+ if ( ! is_site_meta_supported() ) {
+ $this->markTestSkipped( 'Test only runs with the blogmeta database table installed.' );
}
- public function test_delete_should_respect_meta_value() {
- if ( ! is_site_meta_supported() ) {
- $this->markTestSkipped( 'Test only runs with the blogmeta database table installed.' );
- }
+ add_site_meta( self::$site_id, 'foo', 'bar' );
+ add_site_meta( self::$site_id, 'foo', 'baz' );
- add_site_meta( self::$site_id, 'foo', 'bar' );
- add_site_meta( self::$site_id, 'foo', 'baz' );
+ $this->assertTrue( delete_site_meta( self::$site_id, 'foo', 'bar' ) );
- $this->assertTrue( delete_site_meta( self::$site_id, 'foo', 'bar' ) );
+ $metas = get_site_meta( self::$site_id, 'foo' );
+ $this->assertSame( array( 'baz' ), $metas );
+ }
- $metas = get_site_meta( self::$site_id, 'foo' );
- $this->assertSame( array( 'baz' ), $metas );
+ public function test_get_with_no_key_should_fetch_all_keys() {
+ if ( ! is_site_meta_supported() ) {
+ $this->markTestSkipped( 'Test only runs with the blogmeta database table installed.' );
}
- public function test_get_with_no_key_should_fetch_all_keys() {
- if ( ! is_site_meta_supported() ) {
- $this->markTestSkipped( 'Test only runs with the blogmeta database table installed.' );
- }
+ add_site_meta( self::$site_id, 'foo', 'bar' );
+ add_site_meta( self::$site_id, 'foo1', 'baz' );
- add_site_meta( self::$site_id, 'foo', 'bar' );
- add_site_meta( self::$site_id, 'foo1', 'baz' );
+ $found = get_site_meta( self::$site_id );
+ $expected = array(
+ 'foo' => array( 'bar' ),
+ 'foo1' => array( 'baz' ),
+ );
- $found = get_site_meta( self::$site_id );
- $expected = array(
- 'foo' => array( 'bar' ),
- 'foo1' => array( 'baz' ),
- );
+ $this->assertSameSets( $expected, $found );
+ }
- $this->assertSameSets( $expected, $found );
+ public function test_get_with_key_should_fetch_all_for_key() {
+ if ( ! is_site_meta_supported() ) {
+ $this->markTestSkipped( 'Test only runs with the blogmeta database table installed.' );
}
- public function test_get_with_key_should_fetch_all_for_key() {
- if ( ! is_site_meta_supported() ) {
- $this->markTestSkipped( 'Test only runs with the blogmeta database table installed.' );
- }
+ add_site_meta( self::$site_id, 'foo', 'bar' );
+ add_site_meta( self::$site_id, 'foo', 'baz' );
+ add_site_meta( self::$site_id, 'foo1', 'baz' );
- add_site_meta( self::$site_id, 'foo', 'bar' );
- add_site_meta( self::$site_id, 'foo', 'baz' );
- add_site_meta( self::$site_id, 'foo1', 'baz' );
+ $found = get_site_meta( self::$site_id, 'foo' );
+ $expected = array( 'bar', 'baz' );
- $found = get_site_meta( self::$site_id, 'foo' );
- $expected = array( 'bar', 'baz' );
+ $this->assertSameSets( $expected, $found );
+ }
- $this->assertSameSets( $expected, $found );
+ public function test_get_should_respect_single_true() {
+ if ( ! is_site_meta_supported() ) {
+ $this->markTestSkipped( 'Test only runs with the blogmeta database table installed.' );
}
- public function test_get_should_respect_single_true() {
- if ( ! is_site_meta_supported() ) {
- $this->markTestSkipped( 'Test only runs with the blogmeta database table installed.' );
- }
+ add_site_meta( self::$site_id, 'foo', 'bar' );
+ add_site_meta( self::$site_id, 'foo', 'baz' );
- add_site_meta( self::$site_id, 'foo', 'bar' );
- add_site_meta( self::$site_id, 'foo', 'baz' );
+ $found = get_site_meta( self::$site_id, 'foo', true );
+ $this->assertSame( 'bar', $found );
+ }
- $found = get_site_meta( self::$site_id, 'foo', true );
- $this->assertSame( 'bar', $found );
+ public function test_update_should_pass_to_add_when_no_value_exists_for_key() {
+ if ( ! is_site_meta_supported() ) {
+ $this->markTestSkipped( 'Test only runs with the blogmeta database table installed.' );
}
- public function test_update_should_pass_to_add_when_no_value_exists_for_key() {
- if ( ! is_site_meta_supported() ) {
- $this->markTestSkipped( 'Test only runs with the blogmeta database table installed.' );
- }
+ $actual = update_site_meta( self::$site_id, 'foo', 'bar' );
+ $this->assertIsInt( $actual );
+ $this->assertNotEmpty( $actual );
- $actual = update_site_meta( self::$site_id, 'foo', 'bar' );
- $this->assertIsInt( $actual );
- $this->assertNotEmpty( $actual );
+ $meta = get_site_meta( self::$site_id, 'foo', true );
+ $this->assertSame( 'bar', $meta );
+ }
- $meta = get_site_meta( self::$site_id, 'foo', true );
- $this->assertSame( 'bar', $meta );
+ public function test_update_should_return_true_when_updating_existing_value_for_key() {
+ if ( ! is_site_meta_supported() ) {
+ $this->markTestSkipped( 'Test only runs with the blogmeta database table installed.' );
}
- public function test_update_should_return_true_when_updating_existing_value_for_key() {
- if ( ! is_site_meta_supported() ) {
- $this->markTestSkipped( 'Test only runs with the blogmeta database table installed.' );
- }
+ add_site_meta( self::$site_id, 'foo', 'bar' );
- add_site_meta( self::$site_id, 'foo', 'bar' );
+ $actual = update_site_meta( self::$site_id, 'foo', 'baz' );
+ $this->assertTrue( $actual );
- $actual = update_site_meta( self::$site_id, 'foo', 'baz' );
- $this->assertTrue( $actual );
+ $meta = get_site_meta( self::$site_id, 'foo', true );
+ $this->assertSame( 'baz', $meta );
+ }
- $meta = get_site_meta( self::$site_id, 'foo', true );
- $this->assertSame( 'baz', $meta );
+ public function test_delete_by_key() {
+ if ( ! is_site_meta_supported() ) {
+ $this->markTestSkipped( 'Test only runs with the blogmeta database table installed.' );
}
- public function test_delete_by_key() {
- if ( ! is_site_meta_supported() ) {
- $this->markTestSkipped( 'Test only runs with the blogmeta database table installed.' );
- }
+ add_site_meta( self::$site_id, 'unique_delete_by_key', 'value', true );
+ add_site_meta( self::$site_id2, 'unique_delete_by_key', 'value', true );
- add_site_meta( self::$site_id, 'unique_delete_by_key', 'value', true );
- add_site_meta( self::$site_id2, 'unique_delete_by_key', 'value', true );
+ $this->assertSame( 'value', get_site_meta( self::$site_id, 'unique_delete_by_key', true ) );
+ $this->assertSame( 'value', get_site_meta( self::$site_id2, 'unique_delete_by_key', true ) );
- $this->assertSame( 'value', get_site_meta( self::$site_id, 'unique_delete_by_key', true ) );
- $this->assertSame( 'value', get_site_meta( self::$site_id2, 'unique_delete_by_key', true ) );
+ $this->assertTrue( delete_site_meta_by_key( 'unique_delete_by_key' ) );
- $this->assertTrue( delete_site_meta_by_key( 'unique_delete_by_key' ) );
+ $this->assertSame( '', get_site_meta( self::$site_id, 'unique_delete_by_key', true ) );
+ $this->assertSame( '', get_site_meta( self::$site_id2, 'unique_delete_by_key', true ) );
+ }
- $this->assertSame( '', get_site_meta( self::$site_id, 'unique_delete_by_key', true ) );
- $this->assertSame( '', get_site_meta( self::$site_id2, 'unique_delete_by_key', true ) );
+ public function test_site_meta_should_be_deleted_when_site_is_deleted() {
+ if ( ! is_site_meta_supported() ) {
+ $this->markTestSkipped( 'Test only runs with the blogmeta database table installed.' );
}
- public function test_site_meta_should_be_deleted_when_site_is_deleted() {
- if ( ! is_site_meta_supported() ) {
- $this->markTestSkipped( 'Test only runs with the blogmeta database table installed.' );
- }
+ $site_id = self::factory()->blog->create(
+ array(
+ 'domain' => 'foo.org',
+ 'path' => '/',
+ )
+ );
- $site_id = self::factory()->blog->create(
- array(
- 'domain' => 'foo.org',
- 'path' => '/',
- )
- );
+ add_site_meta( $site_id, 'foo', 'bar' );
+ add_site_meta( $site_id, 'foo1', 'bar' );
- add_site_meta( $site_id, 'foo', 'bar' );
- add_site_meta( $site_id, 'foo1', 'bar' );
+ $this->assertSame( 'bar', get_site_meta( $site_id, 'foo', true ) );
+ $this->assertSame( 'bar', get_site_meta( $site_id, 'foo1', true ) );
- $this->assertSame( 'bar', get_site_meta( $site_id, 'foo', true ) );
- $this->assertSame( 'bar', get_site_meta( $site_id, 'foo1', true ) );
+ wp_delete_site( $site_id );
- wp_delete_site( $site_id );
+ $this->assertSame( '', get_site_meta( $site_id, 'foo', true ) );
+ $this->assertSame( '', get_site_meta( $site_id, 'foo1', true ) );
+ }
- $this->assertSame( '', get_site_meta( $site_id, 'foo', true ) );
- $this->assertSame( '', get_site_meta( $site_id, 'foo1', true ) );
+ public function test_update_site_meta_cache() {
+ if ( ! is_site_meta_supported() ) {
+ $this->markTestSkipped( 'Test only runs with the blogmeta database table installed.' );
}
- public function test_update_site_meta_cache() {
- if ( ! is_site_meta_supported() ) {
- $this->markTestSkipped( 'Test only runs with the blogmeta database table installed.' );
- }
+ update_site_meta( self::$site_id, 'foo', 'bar' );
+ update_sitemeta_cache( array( self::$site_id ) );
- update_site_meta( self::$site_id, 'foo', 'bar' );
- update_sitemeta_cache( array( self::$site_id ) );
+ $num_queries = get_num_queries();
+ get_site_meta( self::$site_id, 'foo', true );
+ $this->assertSame( $num_queries, get_num_queries() );
+ }
- $num_queries = get_num_queries();
- get_site_meta( self::$site_id, 'foo', true );
- $this->assertSame( $num_queries, get_num_queries() );
+ public function test_query_update_site_meta_cache_true() {
+ if ( ! is_site_meta_supported() ) {
+ $this->markTestSkipped( 'Test only runs with the blogmeta database table installed.' );
}
- public function test_query_update_site_meta_cache_true() {
- if ( ! is_site_meta_supported() ) {
- $this->markTestSkipped( 'Test only runs with the blogmeta database table installed.' );
- }
+ update_site_meta( self::$site_id, 'foo', 'bar' );
- update_site_meta( self::$site_id, 'foo', 'bar' );
+ // Do not include 'update_site_meta_cache' as true as its the default.
+ new WP_Site_Query(
+ array(
+ 'ID' => self::$site_id,
+ )
+ );
- // Do not include 'update_site_meta_cache' as true as its the default.
- new WP_Site_Query(
- array(
- 'ID' => self::$site_id,
- )
- );
+ $num_queries = get_num_queries();
+ get_site_meta( self::$site_id, 'foo', true );
+ $this->assertSame( 1, get_num_queries() - $num_queries );
+ }
- $num_queries = get_num_queries();
- get_site_meta( self::$site_id, 'foo', true );
- $this->assertSame( 1, get_num_queries() - $num_queries );
+ /**
+ * @ticket 58185
+ */
+ public function test_lazy_load_site_meta() {
+ if ( ! is_site_meta_supported() ) {
+ $this->markTestSkipped( 'Test only runs with the blogmeta database table installed.' );
}
- /**
- * @ticket 58185
- */
- public function test_lazy_load_site_meta() {
- if ( ! is_site_meta_supported() ) {
- $this->markTestSkipped( 'Test only runs with the blogmeta database table installed.' );
- }
+ $filter = new MockAction();
+ add_filter( 'update_blog_metadata_cache', array( $filter, 'filter' ), 10, 2 );
- $filter = new MockAction();
- add_filter( 'update_blog_metadata_cache', array( $filter, 'filter' ), 10, 2 );
+ $q = new WP_Site_Query(
+ array(
+ 'ID' => self::$site_id,
+ )
+ );
- $q = new WP_Site_Query(
- array(
- 'ID' => self::$site_id,
- )
- );
+ $this->assertSameSets( array( (string) self::$site_id ), wp_list_pluck( $q->sites, 'blog_id' ), 'Site query should return the first test site' );
- $this->assertSameSets( array( (string) self::$site_id ), wp_list_pluck( $q->sites, 'blog_id' ), 'Site query should return the first test site' );
+ $q = new WP_Site_Query(
+ array(
+ 'ID' => self::$site_id2,
+ )
+ );
- $q = new WP_Site_Query(
- array(
- 'ID' => self::$site_id2,
- )
- );
+ $this->assertSameSets( array( (string) self::$site_id2 ), wp_list_pluck( $q->sites, 'blog_id' ), 'Site query should return the second test site' );
- $this->assertSameSets( array( (string) self::$site_id2 ), wp_list_pluck( $q->sites, 'blog_id' ), 'Site query should return the second test site' );
+ get_site_meta( self::$site_id2 );
- get_site_meta( self::$site_id2 );
+ $args = $filter->get_args();
+ $first = reset( $args );
+ $site_ids = end( $first );
+ $this->assertSameSets( $site_ids, array( self::$site_id, self::$site_id2 ), 'This should have two site\'s meta' );
+ }
- $args = $filter->get_args();
- $first = reset( $args );
- $site_ids = end( $first );
- $this->assertSameSets( $site_ids, array( self::$site_id, self::$site_id2 ), 'This should have two site\'s meta' );
+ /**
+ * @ticket 58185
+ */
+ public function test_lazy_load_site_meta_fields_id() {
+ if ( ! is_site_meta_supported() ) {
+ $this->markTestSkipped( 'Test only runs with the blogmeta database table installed.' );
}
- /**
- * @ticket 58185
- */
- public function test_lazy_load_site_meta_fields_id() {
- if ( ! is_site_meta_supported() ) {
- $this->markTestSkipped( 'Test only runs with the blogmeta database table installed.' );
- }
-
- $filter = new MockAction();
- add_filter( 'update_blog_metadata_cache', array( $filter, 'filter' ), 10, 2 );
-
- $q = new WP_Site_Query(
- array(
- 'ID' => self::$site_id,
- 'fields' => 'ids',
- )
- );
-
- $this->assertSameSets( array( self::$site_id ), $q->sites, 'Site query should return the first test site' );
-
- $q = new WP_Site_Query(
- array(
- 'ID' => self::$site_id2,
- 'fields' => 'ids',
- )
- );
-
- $this->assertSameSets( array( self::$site_id2 ), $q->sites, 'Site query should return the second test site' );
-
- get_site_meta( self::$site_id2 );
-
- $args = $filter->get_args();
- $first = reset( $args );
- $site_ids = end( $first );
- $this->assertSameSets( $site_ids, array( self::$site_id, self::$site_id2 ), 'This should have two sites meta' );
+ $filter = new MockAction();
+ add_filter( 'update_blog_metadata_cache', array( $filter, 'filter' ), 10, 2 );
+
+ $q = new WP_Site_Query(
+ array(
+ 'ID' => self::$site_id,
+ 'fields' => 'ids',
+ )
+ );
+
+ $this->assertSameSets( array( self::$site_id ), $q->sites, 'Site query should return the first test site' );
+
+ $q = new WP_Site_Query(
+ array(
+ 'ID' => self::$site_id2,
+ 'fields' => 'ids',
+ )
+ );
+
+ $this->assertSameSets( array( self::$site_id2 ), $q->sites, 'Site query should return the second test site' );
+
+ get_site_meta( self::$site_id2 );
+
+ $args = $filter->get_args();
+ $first = reset( $args );
+ $site_ids = end( $first );
+ $this->assertSameSets( $site_ids, array( self::$site_id, self::$site_id2 ), 'This should have two sites meta' );
+ }
+
+ public function test_query_update_site_meta_cache_false() {
+ if ( ! is_site_meta_supported() ) {
+ $this->markTestSkipped( 'Test only runs with the blogmeta database table installed.' );
}
- public function test_query_update_site_meta_cache_false() {
- if ( ! is_site_meta_supported() ) {
- $this->markTestSkipped( 'Test only runs with the blogmeta database table installed.' );
- }
+ update_site_meta( self::$site_id, 'foo', 'bar' );
- update_site_meta( self::$site_id, 'foo', 'bar' );
+ new WP_Site_Query(
+ array(
+ 'ID' => self::$site_id,
+ 'update_site_meta_cache' => false,
+ )
+ );
- new WP_Site_Query(
- array(
- 'ID' => self::$site_id,
- 'update_site_meta_cache' => false,
- )
- );
+ $num_queries = get_num_queries();
+ get_site_meta( self::$site_id, 'foo', true );
+ $this->assertSame( 1, get_num_queries() - $num_queries );
+ }
- $num_queries = get_num_queries();
- get_site_meta( self::$site_id, 'foo', true );
- $this->assertSame( 1, get_num_queries() - $num_queries );
+ /**
+ * @ticket 40229
+ */
+ public function test_add_site_meta_should_bust_get_sites_cache() {
+ if ( ! is_site_meta_supported() ) {
+ $this->markTestSkipped( 'Test only runs with the blogmeta database table installed.' );
}
- /**
- * @ticket 40229
- */
- public function test_add_site_meta_should_bust_get_sites_cache() {
- if ( ! is_site_meta_supported() ) {
- $this->markTestSkipped( 'Test only runs with the blogmeta database table installed.' );
- }
-
- add_site_meta( self::$site_id, 'foo', 'bar' );
-
- // Prime cache.
- $found = get_sites(
- array(
- 'fields' => 'ids',
- 'meta_query' => array(
- array(
- 'key' => 'foo',
- 'value' => 'bar',
- ),
+ add_site_meta( self::$site_id, 'foo', 'bar' );
+
+ // Prime cache.
+ $found = get_sites(
+ array(
+ 'fields' => 'ids',
+ 'meta_query' => array(
+ array(
+ 'key' => 'foo',
+ 'value' => 'bar',
),
- )
- );
+ ),
+ )
+ );
- $this->assertSameSets( array( self::$site_id ), $found );
+ $this->assertSameSets( array( self::$site_id ), $found );
- add_site_meta( self::$site_id2, 'foo', 'bar' );
+ add_site_meta( self::$site_id2, 'foo', 'bar' );
- $found = get_sites(
- array(
- 'fields' => 'ids',
- 'meta_query' => array(
- array(
- 'key' => 'foo',
- 'value' => 'bar',
- ),
+ $found = get_sites(
+ array(
+ 'fields' => 'ids',
+ 'meta_query' => array(
+ array(
+ 'key' => 'foo',
+ 'value' => 'bar',
),
- )
- );
+ ),
+ )
+ );
+
+ $this->assertSameSets( array( self::$site_id, self::$site_id2 ), $found );
+ }
- $this->assertSameSets( array( self::$site_id, self::$site_id2 ), $found );
+ /**
+ * @ticket 40229
+ */
+ public function test_update_site_meta_should_bust_get_sites_cache() {
+ if ( ! is_site_meta_supported() ) {
+ $this->markTestSkipped( 'Test only runs with the blogmeta database table installed.' );
}
- /**
- * @ticket 40229
- */
- public function test_update_site_meta_should_bust_get_sites_cache() {
- if ( ! is_site_meta_supported() ) {
- $this->markTestSkipped( 'Test only runs with the blogmeta database table installed.' );
- }
-
- add_site_meta( self::$site_id, 'foo', 'bar' );
- add_site_meta( self::$site_id2, 'foo', 'baz' );
-
- // Prime cache.
- $found = get_sites(
- array(
- 'fields' => 'ids',
- 'meta_query' => array(
- array(
- 'key' => 'foo',
- 'value' => 'bar',
- ),
+ add_site_meta( self::$site_id, 'foo', 'bar' );
+ add_site_meta( self::$site_id2, 'foo', 'baz' );
+
+ // Prime cache.
+ $found = get_sites(
+ array(
+ 'fields' => 'ids',
+ 'meta_query' => array(
+ array(
+ 'key' => 'foo',
+ 'value' => 'bar',
),
- )
- );
+ ),
+ )
+ );
- $this->assertSameSets( array( self::$site_id ), $found );
+ $this->assertSameSets( array( self::$site_id ), $found );
- update_site_meta( self::$site_id2, 'foo', 'bar' );
+ update_site_meta( self::$site_id2, 'foo', 'bar' );
- $found = get_sites(
- array(
- 'fields' => 'ids',
- 'meta_query' => array(
- array(
- 'key' => 'foo',
- 'value' => 'bar',
- ),
+ $found = get_sites(
+ array(
+ 'fields' => 'ids',
+ 'meta_query' => array(
+ array(
+ 'key' => 'foo',
+ 'value' => 'bar',
),
- )
- );
+ ),
+ )
+ );
- $this->assertSameSets( array( self::$site_id, self::$site_id2 ), $found );
+ $this->assertSameSets( array( self::$site_id, self::$site_id2 ), $found );
+ }
+
+ /**
+ * @ticket 40229
+ */
+ public function test_delete_site_meta_should_bust_get_sites_cache() {
+ if ( ! is_site_meta_supported() ) {
+ $this->markTestSkipped( 'Test only runs with the blogmeta database table installed.' );
}
- /**
- * @ticket 40229
- */
- public function test_delete_site_meta_should_bust_get_sites_cache() {
- if ( ! is_site_meta_supported() ) {
- $this->markTestSkipped( 'Test only runs with the blogmeta database table installed.' );
- }
-
- add_site_meta( self::$site_id, 'foo', 'bar' );
- add_site_meta( self::$site_id2, 'foo', 'bar' );
-
- // Prime cache.
- $found = get_sites(
- array(
- 'fields' => 'ids',
- 'meta_query' => array(
- array(
- 'key' => 'foo',
- 'value' => 'bar',
- ),
+ add_site_meta( self::$site_id, 'foo', 'bar' );
+ add_site_meta( self::$site_id2, 'foo', 'bar' );
+
+ // Prime cache.
+ $found = get_sites(
+ array(
+ 'fields' => 'ids',
+ 'meta_query' => array(
+ array(
+ 'key' => 'foo',
+ 'value' => 'bar',
),
- )
- );
+ ),
+ )
+ );
- $this->assertSameSets( array( self::$site_id, self::$site_id2 ), $found );
+ $this->assertSameSets( array( self::$site_id, self::$site_id2 ), $found );
- delete_site_meta( self::$site_id2, 'foo', 'bar' );
+ delete_site_meta( self::$site_id2, 'foo', 'bar' );
- $found = get_sites(
- array(
- 'fields' => 'ids',
- 'meta_query' => array(
- array(
- 'key' => 'foo',
- 'value' => 'bar',
- ),
+ $found = get_sites(
+ array(
+ 'fields' => 'ids',
+ 'meta_query' => array(
+ array(
+ 'key' => 'foo',
+ 'value' => 'bar',
),
- )
- );
+ ),
+ )
+ );
- $this->assertSameSets( array( self::$site_id ), $found );
- }
+ $this->assertSameSets( array( self::$site_id ), $found );
}
-
-endif;
+}
diff --git a/tests/phpunit/tests/multisite/updateBlogDetails.php b/tests/phpunit/tests/multisite/updateBlogDetails.php
index d53c2f8c2b..8800e66818 100644
--- a/tests/phpunit/tests/multisite/updateBlogDetails.php
+++ b/tests/phpunit/tests/multisite/updateBlogDetails.php
@@ -1,131 +1,129 @@
<?php
-if ( is_multisite() ) :
+/**
+ * @group ms-required
+ * @group ms-site
+ * @group multisite
+ */
+class Tests_Multisite_UpdateBlogDetails extends WP_UnitTestCase {
/**
- * @group ms-site
- * @group multisite
+ * If `update_blog_details()` is called with any kind of empty arguments, it
+ * should return false.
*/
- class Tests_Multisite_UpdateBlogDetails extends WP_UnitTestCase {
-
- /**
- * If `update_blog_details()` is called with any kind of empty arguments, it
- * should return false.
- */
- public function test_update_blog_details_with_empty_args() {
- $result = update_blog_details( 1, array() );
- $this->assertFalse( $result );
- }
+ public 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.
- */
- public function test_update_blog_details_invalid_blog_id() {
- $result = update_blog_details( 999, array( 'domain' => 'example.com' ) );
- $this->assertFalse( $result );
- }
+ /**
+ * If the ID passed is not that of a current site, we should expect false.
+ */
+ public function test_update_blog_details_invalid_blog_id() {
+ $result = update_blog_details( 999, array( 'domain' => 'example.com' ) );
+ $this->assertFalse( $result );
+ }
- public function test_update_blog_details() {
- $blog_id = self::factory()->blog->create();
+ public function test_update_blog_details() {
+ $blog_id = self::factory()->blog->create();
- $result = update_blog_details(
- $blog_id,
- array(
- 'domain' => 'example.com',
- 'path' => 'my_path/',
- )
- );
+ $result = update_blog_details(
+ $blog_id,
+ array(
+ 'domain' => 'example.com',
+ 'path' => 'my_path/',
+ )
+ );
- $this->assertTrue( $result );
+ $this->assertTrue( $result );
- $blog = get_site( $blog_id );
+ $blog = get_site( $blog_id );
- $this->assertSame( 'example.com', $blog->domain );
- $this->assertSame( '/my_path/', $blog->path );
- $this->assertSame( '0', $blog->spam );
- }
+ $this->assertSame( 'example.com', $blog->domain );
+ $this->assertSame( '/my_path/', $blog->path );
+ $this->assertSame( '0', $blog->spam );
+ }
- /**
- * Test each of the actions that should fire in update_blog_details() depending on
- * the flag and flag value being set. Each action should fire once and should not
- * fire if a flag is already set for the given flag value.
- *
- * @param string $flag The name of the flag being set or unset on a site.
- * @param string $flag_value '0' or '1'. The value of the flag being set.
- * @param string $action The hook expected to fire for the flag name and flag combination.
- *
- * @dataProvider data_flag_hooks
- */
- public function test_update_blog_details_flag_action( $flag, $flag_value, $hook ) {
- $test_action_counter = new MockAction();
+ /**
+ * Test each of the actions that should fire in update_blog_details() depending on
+ * the flag and flag value being set. Each action should fire once and should not
+ * fire if a flag is already set for the given flag value.
+ *
+ * @param string $flag The name of the flag being set or unset on a site.
+ * @param string $flag_value '0' or '1'. The value of the flag being set.
+ * @param string $action The hook expected to fire for the flag name and flag combination.
+ *
+ * @dataProvider data_flag_hooks
+ */
+ public function test_update_blog_details_flag_action( $flag, $flag_value, $hook ) {
+ $test_action_counter = new MockAction();
- $blog_id = self::factory()->blog->create();
+ $blog_id = self::factory()->blog->create();
- // Set an initial value of '1' for the flag when '0' is the flag value being tested.
- if ( '0' === $flag_value ) {
- update_blog_details( $blog_id, array( $flag => '1' ) );
- }
+ // Set an initial value of '1' for the flag when '0' is the flag value being tested.
+ if ( '0' === $flag_value ) {
+ update_blog_details( $blog_id, array( $flag => '1' ) );
+ }
- add_action( $hook, array( $test_action_counter, 'action' ) );
+ add_action( $hook, array( $test_action_counter, 'action' ) );
- update_blog_details( $blog_id, array( $flag => $flag_value ) );
- $blog = get_site( $blog_id );
+ update_blog_details( $blog_id, array( $flag => $flag_value ) );
+ $blog = get_site( $blog_id );
- $this->assertSame( $flag_value, $blog->{$flag} );
+ $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->get_call_count() );
+ // The hook attached to this flag should have fired once during update_blog_details().
+ $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 ) );
+ // 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->get_call_count() );
- }
+ // The hook attached to this flag should not have fired again.
+ $this->assertSame( 1, $test_action_counter->get_call_count() );
+ }
- public function data_flag_hooks() {
- return array(
- array( 'spam', '0', 'make_ham_blog' ),
- array( 'spam', '1', 'make_spam_blog' ),
- array( 'archived', '1', 'archive_blog' ),
- array( 'archived', '0', 'unarchive_blog' ),
- array( 'deleted', '1', 'make_delete_blog' ),
- array( 'deleted', '0', 'make_undelete_blog' ),
- array( 'mature', '1', 'mature_blog' ),
- array( 'mature', '0', 'unmature_blog' ),
- );
- }
+ public function data_flag_hooks() {
+ return array(
+ array( 'spam', '0', 'make_ham_blog' ),
+ array( 'spam', '1', 'make_spam_blog' ),
+ array( 'archived', '1', 'archive_blog' ),
+ array( 'archived', '0', 'unarchive_blog' ),
+ array( 'deleted', '1', 'make_delete_blog' ),
+ array( 'deleted', '0', 'make_undelete_blog' ),
+ array( 'mature', '1', 'mature_blog' ),
+ array( 'mature', '0', 'unmature_blog' ),
+ );
+ }
- /**
- * When the path for a site is updated with update_blog_details(), the final path
- * should have a leading and trailing slash.
- *
- * @dataProvider data_single_directory_path
- */
- public function test_update_blog_details_single_directory_path( $path, $expected ) {
- update_blog_details( 1, array( 'path' => $path ) );
- $site = get_site( 1 );
-
- $this->assertSame( $expected, $site->path );
- }
+ /**
+ * When the path for a site is updated with update_blog_details(), the final path
+ * should have a leading and trailing slash.
+ *
+ * @dataProvider data_single_directory_path
+ */
+ public function test_update_blog_details_single_directory_path( $path, $expected ) {
+ update_blog_details( 1, array( 'path' => $path ) );
+ $site = get_site( 1 );
- public function data_single_directory_path() {
- return array(
- array( 'my_path', '/my_path/' ),
- array( 'my_path//', '/my_path/' ),
- array( '//my_path', '/my_path/' ),
- array( 'my_path/', '/my_path/' ),
- array( '/my_path', '/my_path/' ),
- array( '/my_path/', '/my_path/' ),
-
- array( 'multiple/dirs', '/multiple/dirs/' ),
- array( '/multiple/dirs', '/multiple/dirs/' ),
- array( 'multiple/dirs/', '/multiple/dirs/' ),
- array( '/multiple/dirs/', '/multiple/dirs/' ),
-
- // update_blog_details() does not resolve multiple slashes in the middle of a path string.
- array( 'multiple///dirs', '/multiple///dirs/' ),
- );
- }
+ $this->assertSame( $expected, $site->path );
+ }
+
+ public function data_single_directory_path() {
+ return array(
+ array( 'my_path', '/my_path/' ),
+ array( 'my_path//', '/my_path/' ),
+ array( '//my_path', '/my_path/' ),
+ array( 'my_path/', '/my_path/' ),
+ array( '/my_path', '/my_path/' ),
+ array( '/my_path/', '/my_path/' ),
+
+ array( 'multiple/dirs', '/multiple/dirs/' ),
+ array( '/multiple/dirs', '/multiple/dirs/' ),
+ array( 'multiple/dirs/', '/multiple/dirs/' ),
+ array( '/multiple/dirs/', '/multiple/dirs/' ),
+
+ // update_blog_details() does not resolve multiple slashes in the middle of a path string.
+ array( 'multiple///dirs', '/multiple///dirs/' ),
+ );
}
-endif;
+}
diff --git a/tests/phpunit/tests/multisite/updateBlogStatus.php b/tests/phpunit/tests/multisite/updateBlogStatus.php
index 02854ca219..069eddd984 100644
--- a/tests/phpunit/tests/multisite/updateBlogStatus.php
+++ b/tests/phpunit/tests/multisite/updateBlogStatus.php
@@ -1,244 +1,241 @@
<?php
-if ( is_multisite() ) :
+/**
+ * @group ms-required
+ * @group ms-site
+ * @group multisite
+ */
+class Tests_Multisite_UpdateBlogStatus extends WP_UnitTestCase {
/**
- * @group ms-site
- * @group multisite
+ * Updating a field returns the same value that was passed.
*/
- class Tests_Multisite_UpdateBlogStatus extends WP_UnitTestCase {
-
- /**
- * Updating a field returns the same value that was passed.
- */
- public function test_update_blog_status() {
- $result = update_blog_status( 1, 'spam', 0 );
- $this->assertSame( 0, $result );
- }
-
- /**
- * Updating an invalid field returns the same value that was passed.
- */
- public function test_update_blog_status_invalid_status() {
- $result = update_blog_status( 1, 'doesnotexist', 'invalid' );
- $this->assertSame( 'invalid', $result );
- }
-
- public function test_update_blog_status_make_ham_blog_action() {
- $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( $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->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->get_call_count() );
- }
-
- /**
- * @group external-http
- */
- public function test_content_from_spam_blog_is_not_available() {
- $spam_blog_id = self::factory()->blog->create();
- switch_to_blog( $spam_blog_id );
- $post_data = array(
- 'post_title' => 'Hello World!',
- 'post_content' => 'Hello world content',
- );
- $post_id = self::factory()->post->create( $post_data );
- $post = get_post( $post_id );
- $spam_permalink = site_url() . '/?p=' . $post->ID;
- $spam_embed_url = get_post_embed_url( $post_id );
-
- restore_current_blog();
- $this->assertNotEmpty( $spam_permalink );
- $this->assertSame( $post_data['post_title'], $post->post_title );
+ public function test_update_blog_status() {
+ $result = update_blog_status( 1, 'spam', 0 );
+ $this->assertSame( 0, $result );
+ }
- update_blog_status( $spam_blog_id, 'spam', 1 );
-
- $post_id = self::factory()->post->create(
- array(
- 'post_content' => "\n $spam_permalink \n",
- )
- );
- $post = get_post( $post_id );
- $content = apply_filters( 'the_content', $post->post_content );
-
- $this->assertStringNotContainsString( $post_data['post_title'], $content );
- $this->assertStringNotContainsString( "src=\"{$spam_embed_url}#?", $content );
- }
-
- public function test_update_blog_status_make_spam_blog_action() {
- $test_action_counter = new MockAction();
+ /**
+ * Updating an invalid field returns the same value that was passed.
+ */
+ public function test_update_blog_status_invalid_status() {
+ $result = update_blog_status( 1, 'doesnotexist', 'invalid' );
+ $this->assertSame( 'invalid', $result );
+ }
- $blog_id = self::factory()->blog->create();
+ public function test_update_blog_status_make_ham_blog_action() {
+ $test_action_counter = new MockAction();
- add_action( 'make_spam_blog', array( $test_action_counter, 'action' ) );
- update_blog_status( $blog_id, 'spam', 1 );
- $blog = get_site( $blog_id );
+ $blog_id = self::factory()->blog->create();
+ update_blog_details( $blog_id, array( 'spam' => 1 ) );
- $this->assertSame( '1', $blog->spam );
- $this->assertSame( 1, $test_action_counter->get_call_count() );
+ add_action( 'make_ham_blog', array( $test_action_counter, 'action' ) );
+ update_blog_status( $blog_id, 'spam', 0 );
+ $blog = get_site( $blog_id );
- // 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( '0', $blog->spam );
+ $this->assertSame( 1, $test_action_counter->get_call_count() );
- $this->assertSame( '1', $blog->spam );
- $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 );
- public function test_update_blog_status_archive_blog_action() {
- $test_action_counter = new MockAction();
+ $this->assertSame( '0', $blog->spam );
+ $this->assertSame( 1, $test_action_counter->get_call_count() );
+ }
- $blog_id = self::factory()->blog->create();
+ /**
+ * @group external-http
+ */
+ public function test_content_from_spam_blog_is_not_available() {
+ $spam_blog_id = self::factory()->blog->create();
+ switch_to_blog( $spam_blog_id );
+ $post_data = array(
+ 'post_title' => 'Hello World!',
+ 'post_content' => 'Hello world content',
+ );
+ $post_id = self::factory()->post->create( $post_data );
+ $post = get_post( $post_id );
+ $spam_permalink = site_url() . '/?p=' . $post->ID;
+ $spam_embed_url = get_post_embed_url( $post_id );
+
+ restore_current_blog();
+ $this->assertNotEmpty( $spam_permalink );
+ $this->assertSame( $post_data['post_title'], $post->post_title );
+
+ update_blog_status( $spam_blog_id, 'spam', 1 );
+
+ $post_id = self::factory()->post->create(
+ array(
+ 'post_content' => "\n $spam_permalink \n",
+ )
+ );
+ $post = get_post( $post_id );
+ $content = apply_filters( 'the_content', $post->post_content );
+
+ $this->assertStringNotContainsString( $post_data['post_title'], $content );
+ $this->assertStringNotContainsString( "src=\"{$spam_embed_url}#?", $content );
+ }
+
+ public function test_update_blog_status_make_spam_blog_action() {
+ $test_action_counter = new MockAction();
- add_action( 'archive_blog', array( $test_action_counter, 'action' ) );
- update_blog_status( $blog_id, 'archived', 1 );
- $blog = get_site( $blog_id );
+ $blog_id = self::factory()->blog->create();
- $this->assertSame( '1', $blog->archived );
- $this->assertSame( 1, $test_action_counter->get_call_count() );
+ add_action( 'make_spam_blog', array( $test_action_counter, 'action' ) );
+ update_blog_status( $blog_id, 'spam', 1 );
+ $blog = get_site( $blog_id );
- // 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->spam );
+ $this->assertSame( 1, $test_action_counter->get_call_count() );
- $this->assertSame( '1', $blog->archived );
- $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->get_call_count() );
+ }
- public function test_update_blog_status_unarchive_blog_action() {
- $test_action_counter = new MockAction();
+ public function test_update_blog_status_archive_blog_action() {
+ $test_action_counter = new MockAction();
- $blog_id = self::factory()->blog->create();
- update_blog_details( $blog_id, array( 'archived' => 1 ) );
+ $blog_id = self::factory()->blog->create();
- add_action( 'unarchive_blog', array( $test_action_counter, 'action' ) );
- update_blog_status( $blog_id, 'archived', 0 );
- $blog = get_site( $blog_id );
+ add_action( 'archive_blog', array( $test_action_counter, 'action' ) );
+ update_blog_status( $blog_id, 'archived', 1 );
+ $blog = get_site( $blog_id );
- $this->assertSame( '0', $blog->archived );
- $this->assertSame( 1, $test_action_counter->get_call_count() );
+ $this->assertSame( '1', $blog->archived );
+ $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->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 );
- public function test_update_blog_status_make_delete_blog_action() {
- $test_action_counter = new MockAction();
+ $this->assertSame( '1', $blog->archived );
+ $this->assertSame( 1, $test_action_counter->get_call_count() );
+ }
- $blog_id = self::factory()->blog->create();
+ public function test_update_blog_status_unarchive_blog_action() {
+ $test_action_counter = new MockAction();
- add_action( 'make_delete_blog', array( $test_action_counter, 'action' ) );
- update_blog_status( $blog_id, 'deleted', 1 );
- $blog = get_site( $blog_id );
+ $blog_id = self::factory()->blog->create();
+ update_blog_details( $blog_id, array( 'archived' => 1 ) );
- $this->assertSame( '1', $blog->deleted );
- $this->assertSame( 1, $test_action_counter->get_call_count() );
+ add_action( 'unarchive_blog', array( $test_action_counter, 'action' ) );
+ update_blog_status( $blog_id, 'archived', 0 );
+ $blog = get_site( $blog_id );
- // 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( '0', $blog->archived );
+ $this->assertSame( 1, $test_action_counter->get_call_count() );
- $this->assertSame( '1', $blog->deleted );
- $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->get_call_count() );
+ }
- public function test_update_blog_status_make_undelete_blog_action() {
- $test_action_counter = new MockAction();
+ public function test_update_blog_status_make_delete_blog_action() {
+ $test_action_counter = new MockAction();
- $blog_id = self::factory()->blog->create();
- update_blog_details( $blog_id, array( 'deleted' => 1 ) );
+ $blog_id = self::factory()->blog->create();
- add_action( 'make_undelete_blog', array( $test_action_counter, 'action' ) );
- update_blog_status( $blog_id, 'deleted', 0 );
- $blog = get_site( $blog_id );
+ add_action( 'make_delete_blog', array( $test_action_counter, 'action' ) );
+ update_blog_status( $blog_id, 'deleted', 1 );
+ $blog = get_site( $blog_id );
- $this->assertSame( '0', $blog->deleted );
- $this->assertSame( 1, $test_action_counter->get_call_count() );
+ $this->assertSame( '1', $blog->deleted );
+ $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 );
+ // 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( '0', $blog->deleted );
- $this->assertSame( 1, $test_action_counter->get_call_count() );
- }
+ $this->assertSame( '1', $blog->deleted );
+ $this->assertSame( 1, $test_action_counter->get_call_count() );
+ }
- public function test_update_blog_status_mature_blog_action() {
- $test_action_counter = new MockAction();
+ public function test_update_blog_status_make_undelete_blog_action() {
+ $test_action_counter = new MockAction();
- $blog_id = self::factory()->blog->create();
+ $blog_id = self::factory()->blog->create();
+ update_blog_details( $blog_id, array( 'deleted' => 1 ) );
- add_action( 'mature_blog', array( $test_action_counter, 'action' ) );
- update_blog_status( $blog_id, 'mature', 1 );
- $blog = get_site( $blog_id );
+ add_action( 'make_undelete_blog', array( $test_action_counter, 'action' ) );
+ update_blog_status( $blog_id, 'deleted', 0 );
+ $blog = get_site( $blog_id );
- $this->assertSame( '1', $blog->mature );
- $this->assertSame( 1, $test_action_counter->get_call_count() );
+ $this->assertSame( '0', $blog->deleted );
+ $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 );
+ // 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( '1', $blog->mature );
- $this->assertSame( 1, $test_action_counter->get_call_count() );
- }
+ $this->assertSame( '0', $blog->deleted );
+ $this->assertSame( 1, $test_action_counter->get_call_count() );
+ }
- public function test_update_blog_status_unmature_blog_action() {
- $test_action_counter = new MockAction();
+ public function test_update_blog_status_mature_blog_action() {
+ $test_action_counter = new MockAction();
- $blog_id = self::factory()->blog->create();
- update_blog_details( $blog_id, array( 'mature' => 1 ) );
+ $blog_id = self::factory()->blog->create();
- add_action( 'unmature_blog', array( $test_action_counter, 'action' ) );
- update_blog_status( $blog_id, 'mature', 0 );
+ add_action( 'mature_blog', array( $test_action_counter, 'action' ) );
+ update_blog_status( $blog_id, 'mature', 1 );
+ $blog = get_site( $blog_id );
- $blog = get_site( $blog_id );
- $this->assertSame( '0', $blog->mature );
- $this->assertSame( 1, $test_action_counter->get_call_count() );
+ $this->assertSame( '1', $blog->mature );
+ $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 );
+ // 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( '0', $blog->mature );
- $this->assertSame( 1, $test_action_counter->get_call_count() );
- }
+ $this->assertSame( '1', $blog->mature );
+ $this->assertSame( 1, $test_action_counter->get_call_count() );
+ }
- public function test_update_blog_status_update_blog_public_action() {
- $test_action_counter = new MockAction();
+ public function test_update_blog_status_unmature_blog_action() {
+ $test_action_counter = new MockAction();
- $blog_id = self::factory()->blog->create();
+ $blog_id = self::factory()->blog->create();
+ update_blog_details( $blog_id, array( 'mature' => 1 ) );
- add_action( 'update_blog_public', array( $test_action_counter, 'action' ) );
- update_blog_status( $blog_id, 'public', 0 );
+ 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->public );
- $this->assertSame( 1, $test_action_counter->get_call_count() );
+ $blog = get_site( $blog_id );
+ $this->assertSame( '0', $blog->mature );
+ $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 );
+ // 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->public );
- $this->assertSame( 1, $test_action_counter->get_call_count() );
- }
+ $this->assertSame( '0', $blog->mature );
+ $this->assertSame( 1, $test_action_counter->get_call_count() );
}
-endif;
+ public function test_update_blog_status_update_blog_public_action() {
+ $test_action_counter = new MockAction();
+
+ $blog_id = self::factory()->blog->create();
+
+ 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->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->get_call_count() );
+ }
+}
diff --git a/tests/phpunit/tests/multisite/updatePostsCount.php b/tests/phpunit/tests/multisite/updatePostsCount.php
index bf3fcb879f..08f79c11ec 100644
--- a/tests/phpunit/tests/multisite/updatePostsCount.php
+++ b/tests/phpunit/tests/multisite/updatePostsCount.php
@@ -1,59 +1,57 @@
<?php
-if ( is_multisite() ) :
+/**
+ * Test that update_posts_count() gets called via default filters on multisite.
+ *
+ * @group ms-required
+ * @group ms-site
+ * @group multisite
+ *
+ * @covers ::update_posts_count
+ */
+class Tests_Multisite_UpdatePostsCount extends WP_UnitTestCase {
+
/**
- * Test that update_posts_count() gets called via default filters on multisite.
+ * Tests that posts count is updated correctly when posts are added or deleted.
*
- * @group ms-site
- * @group multisite
+ * @ticket 27952
+ * @ticket 53443
*
- * @covers ::update_posts_count
+ * @covers ::_update_posts_count_on_transition_post_status
+ * @covers ::_update_posts_count_on_delete
*/
- class Tests_Multisite_UpdatePostsCount extends WP_UnitTestCase {
-
- /**
- * Tests that posts count is updated correctly when posts are added or deleted.
- *
- * @ticket 27952
- * @ticket 53443
- *
- * @covers ::_update_posts_count_on_transition_post_status
- * @covers ::_update_posts_count_on_delete
- */
- public function test_update_posts_count() {
- $blog_id = self::factory()->blog->create();
- switch_to_blog( $blog_id );
+ public function test_update_posts_count() {
+ $blog_id = self::factory()->blog->create();
+ switch_to_blog( $blog_id );
- $original_post_count = (int) get_site()->post_count;
+ $original_post_count = (int) get_site()->post_count;
- $post_id = self::factory()->post->create();
+ $post_id = self::factory()->post->create();
- $post_count_after_creating = get_site()->post_count;
+ $post_count_after_creating = get_site()->post_count;
- wp_delete_post( $post_id, true );
+ wp_delete_post( $post_id, true );
- $post_count_after_deleting = get_site()->post_count;
+ $post_count_after_deleting = get_site()->post_count;
- restore_current_blog();
+ restore_current_blog();
- /*
- * Check that posts count is updated when a post is created:
- * add_action( 'transition_post_status', '_update_posts_count_on_transition_post_status', 10, 3 );
- *
- * Check that _update_posts_count_on_transition_post_status() is called on that filter,
- * which then calls update_posts_count() to update the count.
- */
- $this->assertSame( $original_post_count + 1, $post_count_after_creating, 'Post count should be incremented by 1.' );
+ /*
+ * Check that posts count is updated when a post is created:
+ * add_action( 'transition_post_status', '_update_posts_count_on_transition_post_status', 10, 3 );
+ *
+ * Check that _update_posts_count_on_transition_post_status() is called on that filter,
+ * which then calls update_posts_count() to update the count.
+ */
+ $this->assertSame( $original_post_count + 1, $post_count_after_creating, 'Post count should be incremented by 1.' );
- /*
- * Check that posts count is updated when a post is deleted:
- * add_action( 'after_delete_post', '_update_posts_count_on_delete', 10, 2 );
- *
- * Check that _update_posts_count_on_delete() is called on that filter,
- * which then calls update_posts_count() to update the count.
- */
- $this->assertSame( $original_post_count, $post_count_after_deleting, 'Post count should match the original count.' );
- }
+ /*
+ * Check that posts count is updated when a post is deleted:
+ * add_action( 'after_delete_post', '_update_posts_count_on_delete', 10, 2 );
+ *
+ * Check that _update_posts_count_on_delete() is called on that filter,
+ * which then calls update_posts_count() to update the count.
+ */
+ $this->assertSame( $original_post_count, $post_count_after_deleting, 'Post count should match the original count.' );
}
-
-endif;
+}
diff --git a/tests/phpunit/tests/multisite/uploadIsUserOverQuota.php b/tests/phpunit/tests/multisite/uploadIsUserOverQuota.php
index 5b08569091..bf94aa0d42 100644
--- a/tests/phpunit/tests/multisite/uploadIsUserOverQuota.php
+++ b/tests/phpunit/tests/multisite/uploadIsUserOverQuota.php
@@ -1,123 +1,120 @@
<?php
-if ( is_multisite() ) :
+/**
+ * Tests specific to `upload_is_user_over_quota()` in multisite.
+ *
+ * These tests filter `get_space_allowed` and `pre_get_space_used` in
+ * most cases as those are tested elsewhere.
+ *
+ * @group ms-required
+ * @group multisite
+ */
+class Tests_Multisite_UploadIsUserOverQuota extends WP_UnitTestCase {
+
+ public function set_up() {
+ parent::set_up();
+ update_site_option( 'upload_space_check_disabled', false );
+ }
+
+ public function test_upload_is_user_over_quota_allowed_0_used_5() {
+ add_filter( 'get_space_allowed', '__return_zero' );
+ add_filter( 'pre_get_space_used', array( $this, '_filter_space_5' ) );
+ $result = upload_is_user_over_quota( false );
+ remove_filter( 'get_space_allowed', '__return_zero' );
+ remove_filter( 'pre_get_space_used', array( $this, '_filter_space_5' ) );
+
+ $this->assertTrue( $result );
+ }
+
+ public function test_upload_is_user_over_quota_allowed_0_used_0() {
+ add_filter( 'get_space_allowed', '__return_zero' );
+ add_filter( 'pre_get_space_used', '__return_zero' );
+ $result = upload_is_user_over_quota( false );
+ remove_filter( 'get_space_allowed', '__return_zero' );
+ remove_filter( 'pre_get_space_used', '__return_zero' );
+
+ $this->assertFalse( $result );
+ }
+
+ public function test_upload_is_user_over_quota_allowed_0_used_100() {
+ add_filter( 'get_space_allowed', '__return_zero' );
+ add_filter( 'pre_get_space_used', array( $this, '_filter_space_100' ) );
+ $result = upload_is_user_over_quota( false );
+ remove_filter( 'get_space_allowed', '__return_zero' );
+ remove_filter( 'pre_get_space_used', array( $this, '_filter_space_100' ) );
+
+ $this->assertTrue( $result );
+ }
+
+ public function test_upload_is_user_over_quota_allowed_100_used_0() {
+ add_filter( 'get_space_allowed', array( $this, '_filter_space_100' ) );
+ add_filter( 'pre_get_space_used', '__return_zero' );
+ $result = upload_is_user_over_quota( false );
+ remove_filter( 'get_space_allowed', array( $this, '_filter_space_100' ) );
+ remove_filter( 'pre_get_space_used', '__return_zero' );
+
+ $this->assertFalse( $result );
+ }
+
+ public function test_upload_is_user_over_quota_allowed_100_used_100() {
+ add_filter( 'get_space_allowed', array( $this, '_filter_space_100' ) );
+ add_filter( 'pre_get_space_used', array( $this, '_filter_space_100' ) );
+ $result = upload_is_user_over_quota( false );
+ remove_filter( 'get_space_allowed', array( $this, '_filter_space_100' ) );
+ remove_filter( 'pre_get_space_used', array( $this, '_filter_space_100' ) );
+
+ $this->assertFalse( $result );
+ }
+
+ public function test_upload_is_user_over_quota_allowed_100_used_200() {
+ add_filter( 'get_space_allowed', array( $this, '_filter_space_100' ) );
+ add_filter( 'pre_get_space_used', array( $this, '_filter_space_200' ) );
+ $result = upload_is_user_over_quota( false );
+ remove_filter( 'get_space_allowed', array( $this, '_filter_space_100' ) );
+ remove_filter( 'pre_get_space_used', array( $this, '_filter_space_200' ) );
+
+ $this->assertTrue( $result );
+ }
+
+ public function test_upload_is_user_over_quota_allowed_negative_used_100() {
+ add_filter( 'get_space_allowed', array( $this, '_filter_space_negative' ) );
+ add_filter( 'pre_get_space_used', array( $this, '_filter_space_100' ) );
+ $result = upload_is_user_over_quota( false );
+ remove_filter( 'get_space_allowed', array( $this, '_filter_space_negative' ) );
+ remove_filter( 'pre_get_space_used', array( $this, '_filter_space_100' ) );
+
+ $this->assertTrue( $result );
+ }
/**
- * Tests specific to `upload_is_user_over_quota()` in multisite.
- *
- * These tests filter `get_space_allowed` and `pre_get_space_used` in
- * most cases as those are tested elsewhere.
- *
- * @group multisite
+ * When the upload space check is disabled, using more than the available
+ * quota is allowed.
*/
- class Tests_Multisite_UploadIsUserOverQuota extends WP_UnitTestCase {
-
- public function set_up() {
- parent::set_up();
- update_site_option( 'upload_space_check_disabled', false );
- }
-
- public function test_upload_is_user_over_quota_allowed_0_used_5() {
- add_filter( 'get_space_allowed', '__return_zero' );
- add_filter( 'pre_get_space_used', array( $this, '_filter_space_5' ) );
- $result = upload_is_user_over_quota( false );
- remove_filter( 'get_space_allowed', '__return_zero' );
- remove_filter( 'pre_get_space_used', array( $this, '_filter_space_5' ) );
-
- $this->assertTrue( $result );
- }
-
- public function test_upload_is_user_over_quota_allowed_0_used_0() {
- add_filter( 'get_space_allowed', '__return_zero' );
- add_filter( 'pre_get_space_used', '__return_zero' );
- $result = upload_is_user_over_quota( false );
- remove_filter( 'get_space_allowed', '__return_zero' );
- remove_filter( 'pre_get_space_used', '__return_zero' );
-
- $this->assertFalse( $result );
- }
-
- public function test_upload_is_user_over_quota_allowed_0_used_100() {
- add_filter( 'get_space_allowed', '__return_zero' );
- add_filter( 'pre_get_space_used', array( $this, '_filter_space_100' ) );
- $result = upload_is_user_over_quota( false );
- remove_filter( 'get_space_allowed', '__return_zero' );
- remove_filter( 'pre_get_space_used', array( $this, '_filter_space_100' ) );
-
- $this->assertTrue( $result );
- }
-
- public function test_upload_is_user_over_quota_allowed_100_used_0() {
- add_filter( 'get_space_allowed', array( $this, '_filter_space_100' ) );
- add_filter( 'pre_get_space_used', '__return_zero' );
- $result = upload_is_user_over_quota( false );
- remove_filter( 'get_space_allowed', array( $this, '_filter_space_100' ) );
- remove_filter( 'pre_get_space_used', '__return_zero' );
-
- $this->assertFalse( $result );
- }
-
- public function test_upload_is_user_over_quota_allowed_100_used_100() {
- add_filter( 'get_space_allowed', array( $this, '_filter_space_100' ) );
- add_filter( 'pre_get_space_used', array( $this, '_filter_space_100' ) );
- $result = upload_is_user_over_quota( false );
- remove_filter( 'get_space_allowed', array( $this, '_filter_space_100' ) );
- remove_filter( 'pre_get_space_used', array( $this, '_filter_space_100' ) );
-
- $this->assertFalse( $result );
- }
-
- public function test_upload_is_user_over_quota_allowed_100_used_200() {
- add_filter( 'get_space_allowed', array( $this, '_filter_space_100' ) );
- add_filter( 'pre_get_space_used', array( $this, '_filter_space_200' ) );
- $result = upload_is_user_over_quota( false );
- remove_filter( 'get_space_allowed', array( $this, '_filter_space_100' ) );
- remove_filter( 'pre_get_space_used', array( $this, '_filter_space_200' ) );
-
- $this->assertTrue( $result );
- }
-
- public function test_upload_is_user_over_quota_allowed_negative_used_100() {
- add_filter( 'get_space_allowed', array( $this, '_filter_space_negative' ) );
- add_filter( 'pre_get_space_used', array( $this, '_filter_space_100' ) );
- $result = upload_is_user_over_quota( false );
- remove_filter( 'get_space_allowed', array( $this, '_filter_space_negative' ) );
- remove_filter( 'pre_get_space_used', array( $this, '_filter_space_100' ) );
-
- $this->assertTrue( $result );
- }
-
- /**
- * When the upload space check is disabled, using more than the available
- * quota is allowed.
- */
- public function test_upload_is_user_over_check_disabled() {
- update_site_option( 'upload_space_check_disabled', true );
-
- add_filter( 'get_space_allowed', array( $this, '_filter_space_100' ) );
- add_filter( 'pre_get_space_used', array( $this, '_filter_space_200' ) );
- $result = upload_is_user_over_quota( false );
- remove_filter( 'get_space_allowed', array( $this, '_filter_space_100' ) );
- remove_filter( 'pre_get_space_used', array( $this, '_filter_space_200' ) );
-
- $this->assertFalse( $result );
- }
-
- public function _filter_space_5() {
- return 5;
- }
-
- public function _filter_space_100() {
- return 100;
- }
-
- public function _filter_space_200() {
- return 200;
- }
-
- public function _filter_space_negative() {
- return -1;
- }
+ public function test_upload_is_user_over_check_disabled() {
+ update_site_option( 'upload_space_check_disabled', true );
+
+ add_filter( 'get_space_allowed', array( $this, '_filter_space_100' ) );
+ add_filter( 'pre_get_space_used', array( $this, '_filter_space_200' ) );
+ $result = upload_is_user_over_quota( false );
+ remove_filter( 'get_space_allowed', array( $this, '_filter_space_100' ) );
+ remove_filter( 'pre_get_space_used', array( $this, '_filter_space_200' ) );
+
+ $this->assertFalse( $result );
}
-endif;
+ public function _filter_space_5() {
+ return 5;
+ }
+
+ public function _filter_space_100() {
+ return 100;
+ }
+
+ public function _filter_space_200() {
+ return 200;
+ }
+
+ public function _filter_space_negative() {
+ return -1;
+ }
+}
diff --git a/tests/phpunit/tests/multisite/wpCountSites.php b/tests/phpunit/tests/multisite/wpCountSites.php
index 6755cc1208..618c8dd127 100644
--- a/tests/phpunit/tests/multisite/wpCountSites.php
+++ b/tests/phpunit/tests/multisite/wpCountSites.php
@@ -1,68 +1,65 @@
<?php
-if ( is_multisite() ) :
+/**
+ * @group ms-required
+ * @group ms-site
+ * @group multisite
+ */
+class Tests_Multisite_wpCountSites extends WP_UnitTestCase {
/**
- * @group ms-site
- * @group multisite
+ * @ticket 37392
*/
- class Tests_Multisite_wpCountSites extends WP_UnitTestCase {
+ public function test_wp_count_sites() {
+ // Create a random number of sites with each status.
+ $site_ids = array(
+ 'public' => self::factory()->blog->create_many(
+ random_int( 0, 5 ),
+ array(
+ 'public' => 1,
+ )
+ ),
+ 'archived' => self::factory()->blog->create_many(
+ random_int( 0, 5 ),
+ array(
+ 'public' => 0,
+ 'archived' => 1,
+ )
+ ),
+ 'mature' => self::factory()->blog->create_many(
+ random_int( 0, 5 ),
+ array(
+ 'public' => 0,
+ 'mature' => 1,
+ )
+ ),
+ 'spam' => self::factory()->blog->create_many(
+ random_int( 0, 5 ),
+ array(
+ 'public' => 0,
+ 'spam' => 1,
+ )
+ ),
+ 'deleted' => self::factory()->blog->create_many(
+ random_int( 0, 5 ),
+ array(
+ 'public' => 0,
+ 'deleted' => 1,
+ )
+ ),
+ );
- /**
- * @ticket 37392
- */
- public function test_wp_count_sites() {
- // Create a random number of sites with each status.
- $site_ids = array(
- 'public' => self::factory()->blog->create_many(
- random_int( 0, 5 ),
- array(
- 'public' => 1,
- )
- ),
- 'archived' => self::factory()->blog->create_many(
- random_int( 0, 5 ),
- array(
- 'public' => 0,
- 'archived' => 1,
- )
- ),
- 'mature' => self::factory()->blog->create_many(
- random_int( 0, 5 ),
- array(
- 'public' => 0,
- 'mature' => 1,
- )
- ),
- 'spam' => self::factory()->blog->create_many(
- random_int( 0, 5 ),
- array(
- 'public' => 0,
- 'spam' => 1,
- )
- ),
- 'deleted' => self::factory()->blog->create_many(
- random_int( 0, 5 ),
- array(
- 'public' => 0,
- 'deleted' => 1,
- )
- ),
- );
+ $counts = wp_count_sites();
- $counts = wp_count_sites();
+ $counts_by_status = array_map( 'count', $site_ids );
+ $expected = array_merge(
+ array( 'all' => array_sum( $counts_by_status ) ),
+ $counts_by_status
+ );
+ // Add 1 to all & public for the main site.
+ $expected['all'] += 1;
+ $expected['public'] += 1;
- $counts_by_status = array_map( 'count', $site_ids );
- $expected = array_merge(
- array( 'all' => array_sum( $counts_by_status ) ),
- $counts_by_status
- );
- // Add 1 to all & public for the main site.
- $expected['all'] += 1;
- $expected['public'] += 1;
-
- $this->assertSame( $expected, $counts );
- }
+ $this->assertSame( $expected, $counts );
}
-
-endif;
+}
diff --git a/tests/phpunit/tests/multisite/wpGetSites.php b/tests/phpunit/tests/multisite/wpGetSites.php
index 1abcb59515..4213b394fa 100644
--- a/tests/phpunit/tests/multisite/wpGetSites.php
+++ b/tests/phpunit/tests/multisite/wpGetSites.php
@@ -1,147 +1,143 @@
<?php
-if ( is_multisite() ) :
+/**
+ * @group ms-required
+ * @group ms-site
+ * @group multisite
+ */
+class Tests_Multisite_wpGetSites extends WP_UnitTestCase {
+ protected static $site_ids;
- /**
- * @group wp-get-site
- * @group ms-site
- * @group multisite
- */
- class Tests_Multisite_wpGetSites extends WP_UnitTestCase {
- protected static $site_ids;
-
- public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
- self::$site_ids = array(
- 'w.org/' => array(
- 'domain' => 'w.org',
- 'path' => '/',
- 'network_id' => 2,
- ),
- 'wp.org/' => array(
- 'domain' => 'wp.org',
- 'path' => '/',
- 'network_id' => 2,
- 'public' => 0,
- ),
- 'wp.org/foo/' => array(
- 'domain' => 'wp.org',
- 'path' => '/foo/',
- 'network_id' => 1,
- 'public' => 0,
- ),
- 'wp.org/oof/' => array(
- 'domain' => 'wp.org',
- 'path' => '/oof/',
- ),
- );
+ public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
+ self::$site_ids = array(
+ 'w.org/' => array(
+ 'domain' => 'w.org',
+ 'path' => '/',
+ 'network_id' => 2,
+ ),
+ 'wp.org/' => array(
+ 'domain' => 'wp.org',
+ 'path' => '/',
+ 'network_id' => 2,
+ 'public' => 0,
+ ),
+ 'wp.org/foo/' => array(
+ 'domain' => 'wp.org',
+ 'path' => '/foo/',
+ 'network_id' => 1,
+ 'public' => 0,
+ ),
+ 'wp.org/oof/' => array(
+ 'domain' => 'wp.org',
+ 'path' => '/oof/',
+ ),
+ );
- foreach ( self::$site_ids as &$id ) {
- $id = $factory->blog->create( $id );
- }
- unset( $id );
+ foreach ( self::$site_ids as &$id ) {
+ $id = $factory->blog->create( $id );
}
+ unset( $id );
+ }
- public static function wpTearDownAfterClass() {
- foreach ( self::$site_ids as $id ) {
- wp_delete_site( $id );
- }
-
- wp_update_network_site_counts();
+ public static function wpTearDownAfterClass() {
+ foreach ( self::$site_ids as $id ) {
+ wp_delete_site( $id );
}
- /**
- * @expectedDeprecated wp_get_sites
- */
- public function test_wp_get_sites_site_is_expected_array() {
+ wp_update_network_site_counts();
+ }
- $keys = array(
- 'blog_id',
- 'site_id',
- 'domain',
- 'path',
- 'registered',
- 'last_updated',
- 'public',
- 'archived',
- 'mature',
- 'spam',
- 'deleted',
- 'lang_id',
- );
- $sites = wp_get_sites();
+ /**
+ * @expectedDeprecated wp_get_sites
+ */
+ public function test_wp_get_sites_site_is_expected_array() {
- $missing_keys = array_diff_key( array_flip( $keys ), $sites[0] );
+ $keys = array(
+ 'blog_id',
+ 'site_id',
+ 'domain',
+ 'path',
+ 'registered',
+ 'last_updated',
+ 'public',
+ 'archived',
+ 'mature',
+ 'spam',
+ 'deleted',
+ 'lang_id',
+ );
+ $sites = wp_get_sites();
- $this->assertSame( array(), $missing_keys, 'Keys are missing from site arrays.' );
- }
+ $missing_keys = array_diff_key( array_flip( $keys ), $sites[0] );
- /**
- * @expectedDeprecated wp_get_sites
- * @dataProvider data_wp_get_sites
- *
- * @param $expected
- * @param $args
- * @param $error
- */
- public function test_wp_get_sites( $expected, $args, $error ) {
- $this->assertCount( $expected, wp_get_sites( $args ), $error );
- }
+ $this->assertSame( array(), $missing_keys, 'Keys are missing from site arrays.' );
+ }
+
+ /**
+ * @expectedDeprecated wp_get_sites
+ * @dataProvider data_wp_get_sites
+ *
+ * @param $expected
+ * @param $args
+ * @param $error
+ */
+ public function test_wp_get_sites( $expected, $args, $error ) {
+ $this->assertCount( $expected, wp_get_sites( $args ), $error );
+ }
- /**
- * @return array
- */
- public function data_wp_get_sites() {
- return array(
- array( 3, array(), 'Default arguments should return all sites from the current network.' ),
- array( 0, array( 'network_id' => 999 ), 'No sites should match a query with an invalid network ID.' ),
- array( 5, array( 'network_id' => null ), 'A network ID of null should return all sites on all networks.' ),
- array( 2, array( 'network_id' => 2 ), 'Only sites on a specified network ID should be returned.' ),
- array( 5, array( 'network_id' => array( 1, 2 ) ), 'If multiple network IDs are specified, sites from both should be returned.' ),
+ /**
+ * @return array
+ */
+ public function data_wp_get_sites() {
+ return array(
+ array( 3, array(), 'Default arguments should return all sites from the current network.' ),
+ array( 0, array( 'network_id' => 999 ), 'No sites should match a query with an invalid network ID.' ),
+ array( 5, array( 'network_id' => null ), 'A network ID of null should return all sites on all networks.' ),
+ array( 2, array( 'network_id' => 2 ), 'Only sites on a specified network ID should be returned.' ),
+ array( 5, array( 'network_id' => array( 1, 2 ) ), 'If multiple network IDs are specified, sites from both should be returned.' ),
+ array(
+ 3,
array(
- 3,
- array(
- 'public' => 1,
- 'network_id' => null,
- ),
- 'Public sites on all networks.',
+ 'public' => 1,
+ 'network_id' => null,
),
+ 'Public sites on all networks.',
+ ),
+ array(
+ 2,
array(
- 2,
- array(
- 'public' => 0,
- 'network_id' => null,
- ),
- 'Non public sites on all networks.',
+ 'public' => 0,
+ 'network_id' => null,
),
+ 'Non public sites on all networks.',
+ ),
+ array(
+ 2,
array(
- 2,
- array(
- 'public' => 1,
- 'network_id' => 1,
- ),
- 'Public sites on a single network.',
+ 'public' => 1,
+ 'network_id' => 1,
),
+ 'Public sites on a single network.',
+ ),
+ array(
+ 1,
array(
- 1,
- array(
- 'public' => 1,
- 'network_id' => 2,
- ),
- 'Public sites on a second network.',
+ 'public' => 1,
+ 'network_id' => 2,
),
- array( 2, array( 'limit' => 2 ), 'Provide only a limit argument.' ),
+ 'Public sites on a second network.',
+ ),
+ array( 2, array( 'limit' => 2 ), 'Provide only a limit argument.' ),
+ array(
+ 1,
array(
- 1,
- array(
- 'limit' => 2,
- 'offset' => 2,
- ),
- 'Provide both limit and offset arguments.',
+ 'limit' => 2,
+ 'offset' => 2,
),
- array( 2, array( 'offset' => 1 ), 'Provide only an offset argument.' ),
- array( 0, array( 'offset' => 20 ), 'Expect 0 sites when using an offset larger than the total number of sites.' ),
- );
- }
+ 'Provide both limit and offset arguments.',
+ ),
+ array( 2, array( 'offset' => 1 ), 'Provide only an offset argument.' ),
+ array( 0, array( 'offset' => 20 ), 'Expect 0 sites when using an offset larger than the total number of sites.' ),
+ );
}
-
-endif;
+}
diff --git a/tests/phpunit/tests/multisite/wpInstallDefaults.php b/tests/phpunit/tests/multisite/wpInstallDefaults.php
index cb05566a37..e3ba444a55 100644
--- a/tests/phpunit/tests/multisite/wpInstallDefaults.php
+++ b/tests/phpunit/tests/multisite/wpInstallDefaults.php
@@ -1,84 +1,82 @@
<?php
-if ( is_multisite() ) :
+/**
+ * Saving network settings without altering starter content ( first page, post, and comment ) shouldn't affect
+ * the way it is added to new sites.
+ *
+ * @group ms-required
+ * @group ms-site
+ * @group multisite
+ */
+class Tests_Multisite_wpInstallDefaults extends WP_UnitTestCase {
/**
- * Saving network settings without altering starter content ( first page, post, and comment ) shouldn't affect
- * the way it is added to new sites.
- *
- * @group ms-site
- * @group multisite
+ * @ticket 40036
*/
- class Tests_Multisite_wpInstallDefaults extends WP_UnitTestCase {
- /**
- * @ticket 40036
- */
- public function test_option_should_not_be_empty_by_default() {
- $blog_id = self::factory()->blog->create();
+ public function test_option_should_not_be_empty_by_default() {
+ $blog_id = self::factory()->blog->create();
- switch_to_blog( $blog_id );
+ switch_to_blog( $blog_id );
- $first_page = get_page_by_path( '/sample-page' );
- $first_comment = get_comments();
+ $first_page = get_page_by_path( '/sample-page' );
+ $first_comment = get_comments();
- restore_current_blog();
+ restore_current_blog();
- wp_delete_site( $blog_id );
+ wp_delete_site( $blog_id );
- $this->assertNotEmpty( $first_page->post_content );
- $this->assertNotEmpty( $first_comment[0]->comment_content );
- }
+ $this->assertNotEmpty( $first_page->post_content );
+ $this->assertNotEmpty( $first_comment[0]->comment_content );
+ }
- /**
- * @ticket 40036
+ /**
+ * @ticket 40036
+ */
+ public function test_empty_option_should_fall_back_to_default() {
+ /*
+ * Update first_page / first_comment options,
+ * just like what happens when the network settings page is saved
*/
- public function test_empty_option_should_fall_back_to_default() {
- /*
- * Update first_page / first_comment options,
- * just like what happens when the network settings page is saved
- */
- update_site_option( 'first_page', '' );
- update_site_option( 'first_comment', '' );
+ update_site_option( 'first_page', '' );
+ update_site_option( 'first_comment', '' );
- $blog_id = self::factory()->blog->create();
+ $blog_id = self::factory()->blog->create();
- switch_to_blog( $blog_id );
+ switch_to_blog( $blog_id );
- $first_page = get_page_by_path( '/sample-page' );
- $first_comment = get_comments();
+ $first_page = get_page_by_path( '/sample-page' );
+ $first_comment = get_comments();
- restore_current_blog();
+ restore_current_blog();
- wp_delete_site( $blog_id );
+ wp_delete_site( $blog_id );
- $this->assertNotEmpty( $first_page->post_content );
- $this->assertNotEmpty( $first_comment[0]->comment_content );
- }
+ $this->assertNotEmpty( $first_page->post_content );
+ $this->assertNotEmpty( $first_comment[0]->comment_content );
+ }
- /**
- * @ticket 40036
+ /**
+ * @ticket 40036
+ */
+ public function test_non_default_option_values() {
+ /*
+ * Update first_page / first_comment options,
+ * just like what happens when the network settings page is saved
*/
- public function test_non_default_option_values() {
- /*
- * Update first_page / first_comment options,
- * just like what happens when the network settings page is saved
- */
- update_site_option( 'first_page', 'Some page content' );
- update_site_option( 'first_comment', 'Some comment content' );
+ update_site_option( 'first_page', 'Some page content' );
+ update_site_option( 'first_comment', 'Some comment content' );
- $blog_id = self::factory()->blog->create();
+ $blog_id = self::factory()->blog->create();
- switch_to_blog( $blog_id );
+ switch_to_blog( $blog_id );
- $first_page = get_page_by_path( '/sample-page' );
- $first_comment = get_comments();
+ $first_page = get_page_by_path( '/sample-page' );
+ $first_comment = get_comments();
- restore_current_blog();
+ restore_current_blog();
- wp_delete_site( $blog_id );
+ wp_delete_site( $blog_id );
- $this->assertSame( 'Some page content', $first_page->post_content );
- $this->assertSame( 'Some comment content', $first_comment[0]->comment_content );
- }
+ $this->assertSame( 'Some page content', $first_page->post_content );
+ $this->assertSame( 'Some comment content', $first_comment[0]->comment_content );
}
-
-endif;
+}
diff --git a/tests/phpunit/tests/multisite/wpMsSitesListTable.php b/tests/phpunit/tests/multisite/wpMsSitesListTable.php
index 559f7412f4..e485cd3bbe 100644
--- a/tests/phpunit/tests/multisite/wpMsSitesListTable.php
+++ b/tests/phpunit/tests/multisite/wpMsSitesListTable.php
@@ -1,246 +1,245 @@
<?php
-if ( is_multisite() ) :
+/**
+ * @group admin
+ * @group ms-required
+ * @group network-admin
+ */
+class Tests_Multisite_wpMsSitesListTable extends WP_UnitTestCase {
+
+ protected static $site_ids;
/**
- * @group admin
- * @group network-admin
+ * @var WP_MS_Sites_List_Table
*/
- class Tests_Multisite_wpMsSitesListTable extends WP_UnitTestCase {
- protected static $site_ids;
+ public $table = false;
- /**
- * @var WP_MS_Sites_List_Table
- */
- public $table = false;
+ public function set_up() {
+ parent::set_up();
+ $this->table = _get_list_table( 'WP_MS_Sites_List_Table', array( 'screen' => 'ms-sites' ) );
+ }
- public function set_up() {
- parent::set_up();
- $this->table = _get_list_table( 'WP_MS_Sites_List_Table', array( 'screen' => 'ms-sites' ) );
+ public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
+ self::$site_ids = array(
+ 'wordpress.org/' => array(
+ 'domain' => 'wordpress.org',
+ 'path' => '/',
+ ),
+ 'wordpress.org/foo/' => array(
+ 'domain' => 'wordpress.org',
+ 'path' => '/foo/',
+ ),
+ 'wordpress.org/foo/bar/' => array(
+ 'domain' => 'wordpress.org',
+ 'path' => '/foo/bar/',
+ ),
+ 'wordpress.org/afoo/' => array(
+ 'domain' => 'wordpress.org',
+ 'path' => '/afoo/',
+ ),
+ 'make.wordpress.org/' => array(
+ 'domain' => 'make.wordpress.org',
+ 'path' => '/',
+ ),
+ 'make.wordpress.org/foo/' => array(
+ 'domain' => 'make.wordpress.org',
+ 'path' => '/foo/',
+ ),
+ 'www.w.org/' => array(
+ 'domain' => 'www.w.org',
+ 'path' => '/',
+ ),
+ 'www.w.org/foo/' => array(
+ 'domain' => 'www.w.org',
+ 'path' => '/foo/',
+ ),
+ 'www.w.org/foo/bar/' => array(
+ 'domain' => 'www.w.org',
+ 'path' => '/foo/bar/',
+ ),
+ 'test.example.org/' => array(
+ 'domain' => 'test.example.org',
+ 'path' => '/',
+ ),
+ 'test2.example.org/' => array(
+ 'domain' => 'test2.example.org',
+ 'path' => '/',
+ ),
+ 'test3.example.org/zig/' => array(
+ 'domain' => 'test3.example.org',
+ 'path' => '/zig/',
+ ),
+ 'atest.example.org/' => array(
+ 'domain' => 'atest.example.org',
+ 'path' => '/',
+ ),
+ );
+
+ foreach ( self::$site_ids as &$id ) {
+ $id = $factory->blog->create( $id );
}
+ unset( $id );
+ }
- public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
- self::$site_ids = array(
- 'wordpress.org/' => array(
- 'domain' => 'wordpress.org',
- 'path' => '/',
- ),
- 'wordpress.org/foo/' => array(
- 'domain' => 'wordpress.org',
- 'path' => '/foo/',
- ),
- 'wordpress.org/foo/bar/' => array(
- 'domain' => 'wordpress.org',
- 'path' => '/foo/bar/',
- ),
- 'wordpress.org/afoo/' => array(
- 'domain' => 'wordpress.org',
- 'path' => '/afoo/',
- ),
- 'make.wordpress.org/' => array(
- 'domain' => 'make.wordpress.org',
- 'path' => '/',
- ),
- 'make.wordpress.org/foo/' => array(
- 'domain' => 'make.wordpress.org',
- 'path' => '/foo/',
- ),
- 'www.w.org/' => array(
- 'domain' => 'www.w.org',
- 'path' => '/',
- ),
- 'www.w.org/foo/' => array(
- 'domain' => 'www.w.org',
- 'path' => '/foo/',
- ),
- 'www.w.org/foo/bar/' => array(
- 'domain' => 'www.w.org',
- 'path' => '/foo/bar/',
- ),
- 'test.example.org/' => array(
- 'domain' => 'test.example.org',
- 'path' => '/',
- ),
- 'test2.example.org/' => array(
- 'domain' => 'test2.example.org',
- 'path' => '/',
- ),
- 'test3.example.org/zig/' => array(
- 'domain' => 'test3.example.org',
- 'path' => '/zig/',
- ),
- 'atest.example.org/' => array(
- 'domain' => 'atest.example.org',
- 'path' => '/',
- ),
- );
-
- foreach ( self::$site_ids as &$id ) {
- $id = $factory->blog->create( $id );
- }
- unset( $id );
+ public static function wpTearDownAfterClass() {
+ foreach ( self::$site_ids as $site_id ) {
+ wp_delete_site( $site_id );
}
+ }
- public static function wpTearDownAfterClass() {
- foreach ( self::$site_ids as $site_id ) {
- wp_delete_site( $site_id );
- }
- }
+ public function test_ms_sites_list_table_default_items() {
+ $this->table->prepare_items();
- public function test_ms_sites_list_table_default_items() {
- $this->table->prepare_items();
+ $items = wp_list_pluck( $this->table->items, 'blog_id' );
+ $items = array_map( 'intval', $items );
- $items = wp_list_pluck( $this->table->items, 'blog_id' );
- $items = array_map( 'intval', $items );
+ $this->assertSameSets( array( 1 ) + self::$site_ids, $items );
+ }
- $this->assertSameSets( array( 1 ) + self::$site_ids, $items );
+ public function test_ms_sites_list_table_subdirectory_path_search_items() {
+ if ( is_subdomain_install() ) {
+ $this->markTestSkipped( 'Path search is not available for subdomain configurations.' );
}
- public function test_ms_sites_list_table_subdirectory_path_search_items() {
- if ( is_subdomain_install() ) {
- $this->markTestSkipped( 'Path search is not available for subdomain configurations.' );
- }
+ $_REQUEST['s'] = 'foo';
- $_REQUEST['s'] = 'foo';
+ $this->table->prepare_items();
- $this->table->prepare_items();
+ $items = wp_list_pluck( $this->table->items, 'blog_id' );
+ $items = array_map( 'intval', $items );
- $items = wp_list_pluck( $this->table->items, 'blog_id' );
- $items = array_map( 'intval', $items );
+ unset( $_REQUEST['s'] );
- unset( $_REQUEST['s'] );
+ $expected = array(
+ self::$site_ids['wordpress.org/foo/'],
+ self::$site_ids['wordpress.org/foo/bar/'],
+ self::$site_ids['wordpress.org/afoo/'],
+ self::$site_ids['make.wordpress.org/foo/'],
+ self::$site_ids['www.w.org/foo/'],
+ self::$site_ids['www.w.org/foo/bar/'],
+ );
- $expected = array(
- self::$site_ids['wordpress.org/foo/'],
- self::$site_ids['wordpress.org/foo/bar/'],
- self::$site_ids['wordpress.org/afoo/'],
- self::$site_ids['make.wordpress.org/foo/'],
- self::$site_ids['www.w.org/foo/'],
- self::$site_ids['www.w.org/foo/bar/'],
- );
+ $this->assertSameSets( $expected, $items );
+ }
- $this->assertSameSets( $expected, $items );
+ public function test_ms_sites_list_table_subdirectory_multiple_path_search_items() {
+ if ( is_subdomain_install() ) {
+ $this->markTestSkipped( 'Path search is not available for subdomain configurations.' );
}
- public function test_ms_sites_list_table_subdirectory_multiple_path_search_items() {
- if ( is_subdomain_install() ) {
- $this->markTestSkipped( 'Path search is not available for subdomain configurations.' );
- }
+ $_REQUEST['s'] = 'foo/bar';
- $_REQUEST['s'] = 'foo/bar';
+ $this->table->prepare_items();
- $this->table->prepare_items();
+ $items = wp_list_pluck( $this->table->items, 'blog_id' );
+ $items = array_map( 'intval', $items );
- $items = wp_list_pluck( $this->table->items, 'blog_id' );
- $items = array_map( 'intval', $items );
+ unset( $_REQUEST['s'] );
- unset( $_REQUEST['s'] );
+ $expected = array(
+ self::$site_ids['wordpress.org/foo/bar/'],
+ self::$site_ids['www.w.org/foo/bar/'],
+ );
- $expected = array(
- self::$site_ids['wordpress.org/foo/bar/'],
- self::$site_ids['www.w.org/foo/bar/'],
- );
+ $this->assertSameSets( $expected, $items );
+ }
- $this->assertSameSets( $expected, $items );
- }
+ public function test_ms_sites_list_table_invalid_path_search_items() {
+ $_REQUEST['s'] = 'foobar';
- public function test_ms_sites_list_table_invalid_path_search_items() {
- $_REQUEST['s'] = 'foobar';
+ $this->table->prepare_items();
- $this->table->prepare_items();
+ $items = wp_list_pluck( $this->table->items, 'blog_id' );
+ $items = array_map( 'intval', $items );
- $items = wp_list_pluck( $this->table->items, 'blog_id' );
- $items = array_map( 'intval', $items );
+ unset( $_REQUEST['s'] );
- unset( $_REQUEST['s'] );
+ $this->assertEmpty( $items );
+ }
- $this->assertEmpty( $items );
+ public function test_ms_sites_list_table_subdomain_domain_search_items() {
+ if ( ! is_subdomain_install() ) {
+ $this->markTestSkipped( 'Domain search is not available for subdirectory configurations.' );
}
- public function test_ms_sites_list_table_subdomain_domain_search_items() {
- if ( ! is_subdomain_install() ) {
- $this->markTestSkipped( 'Domain search is not available for subdirectory configurations.' );
- }
+ $_REQUEST['s'] = 'test';
- $_REQUEST['s'] = 'test';
+ $this->table->prepare_items();
- $this->table->prepare_items();
+ $items = wp_list_pluck( $this->table->items, 'blog_id' );
+ $items = array_map( 'intval', $items );
- $items = wp_list_pluck( $this->table->items, 'blog_id' );
- $items = array_map( 'intval', $items );
+ unset( $_REQUEST['s'] );
- unset( $_REQUEST['s'] );
+ $expected = array(
+ self::$site_ids['test.example.org/'],
+ self::$site_ids['test2.example.org/'],
+ self::$site_ids['test3.example.org/zig/'],
+ self::$site_ids['atest.example.org/'],
+ );
- $expected = array(
- self::$site_ids['test.example.org/'],
- self::$site_ids['test2.example.org/'],
- self::$site_ids['test3.example.org/zig/'],
- self::$site_ids['atest.example.org/'],
- );
+ $this->assertSameSets( $expected, $items );
+ }
- $this->assertSameSets( $expected, $items );
+ public function test_ms_sites_list_table_subdomain_domain_search_items_with_trailing_wildcard() {
+ if ( ! is_subdomain_install() ) {
+ $this->markTestSkipped( 'Domain search is not available for subdirectory configurations.' );
}
- public function test_ms_sites_list_table_subdomain_domain_search_items_with_trailing_wildcard() {
- if ( ! is_subdomain_install() ) {
- $this->markTestSkipped( 'Domain search is not available for subdirectory configurations.' );
- }
+ $_REQUEST['s'] = 'test*';
- $_REQUEST['s'] = 'test*';
+ $this->table->prepare_items();
- $this->table->prepare_items();
+ $items = wp_list_pluck( $this->table->items, 'blog_id' );
+ $items = array_map( 'intval', $items );
- $items = wp_list_pluck( $this->table->items, 'blog_id' );
- $items = array_map( 'intval', $items );
+ unset( $_REQUEST['s'] );
- unset( $_REQUEST['s'] );
+ $expected = array(
+ self::$site_ids['test.example.org/'],
+ self::$site_ids['test2.example.org/'],
+ self::$site_ids['test3.example.org/zig/'],
+ self::$site_ids['atest.example.org/'],
+ );
- $expected = array(
- self::$site_ids['test.example.org/'],
- self::$site_ids['test2.example.org/'],
- self::$site_ids['test3.example.org/zig/'],
- self::$site_ids['atest.example.org/'],
- );
+ $this->assertSameSets( $expected, $items );
+ }
- $this->assertSameSets( $expected, $items );
+ public function test_ms_sites_list_table_subdirectory_path_search_items_with_trailing_wildcard() {
+ if ( is_subdomain_install() ) {
+ $this->markTestSkipped( 'Path search is not available for subdomain configurations.' );
}
- public function test_ms_sites_list_table_subdirectory_path_search_items_with_trailing_wildcard() {
- if ( is_subdomain_install() ) {
- $this->markTestSkipped( 'Path search is not available for subdomain configurations.' );
- }
+ $_REQUEST['s'] = 'fo*';
- $_REQUEST['s'] = 'fo*';
+ $this->table->prepare_items();
- $this->table->prepare_items();
+ $items = wp_list_pluck( $this->table->items, 'blog_id' );
+ $items = array_map( 'intval', $items );
- $items = wp_list_pluck( $this->table->items, 'blog_id' );
- $items = array_map( 'intval', $items );
+ unset( $_REQUEST['s'] );
- unset( $_REQUEST['s'] );
+ $expected = array(
+ self::$site_ids['wordpress.org/foo/'],
+ self::$site_ids['wordpress.org/foo/bar/'],
+ self::$site_ids['wordpress.org/afoo/'],
+ self::$site_ids['make.wordpress.org/foo/'],
+ self::$site_ids['www.w.org/foo/'],
+ self::$site_ids['www.w.org/foo/bar/'],
+ );
- $expected = array(
- self::$site_ids['wordpress.org/foo/'],
- self::$site_ids['wordpress.org/foo/bar/'],
- self::$site_ids['wordpress.org/afoo/'],
- self::$site_ids['make.wordpress.org/foo/'],
- self::$site_ids['www.w.org/foo/'],
- self::$site_ids['www.w.org/foo/bar/'],
- );
-
- $this->assertSameSets( $expected, $items );
- }
+ $this->assertSameSets( $expected, $items );
+ }
- /**
- * @ticket 42066
- */
- public function test_get_views_should_return_views_by_default() {
- $expected = array(
- 'all' => '<a href="sites.php" class="current" aria-current="page">All <span class="count">(14)</span></a>',
- 'public' => '<a href="sites.php?status=public">Public <span class="count">(14)</span></a>',
- );
+ /**
+ * @ticket 42066
+ */
+ public function test_get_views_should_return_views_by_default() {
+ $expected = array(
+ 'all' => '<a href="sites.php" class="current" aria-current="page">All <span class="count">(14)</span></a>',
+ 'public' => '<a href="sites.php?status=public">Public <span class="count">(14)</span></a>',
+ );
- $this->assertSame( $expected, $this->table->get_views() );
- }
+ $this->assertSame( $expected, $this->table->get_views() );
}
-endif;
+}
diff --git a/tests/phpunit/tests/multisite/wpMsThemesListTable.php b/tests/phpunit/tests/multisite/wpMsThemesListTable.php
index b02df1a740..d53cd0117a 100644
--- a/tests/phpunit/tests/multisite/wpMsThemesListTable.php
+++ b/tests/phpunit/tests/multisite/wpMsThemesListTable.php
@@ -1,8 +1,8 @@
<?php
/**
- * @group ms-required
* @group admin
+ * @group ms-required
* @group network-admin
*
* @covers WP_MS_Themes_List_Table
diff --git a/tests/phpunit/tests/multisite/wpMsUsersListTable.php b/tests/phpunit/tests/multisite/wpMsUsersListTable.php
index 11f4d847f2..b918edc4cf 100644
--- a/tests/phpunit/tests/multisite/wpMsUsersListTable.php
+++ b/tests/phpunit/tests/multisite/wpMsUsersListTable.php
@@ -2,8 +2,8 @@
/**
* @group admin
- * @group network-admin
* @group ms-required
+ * @group network-admin
*
* @covers WP_MS_Users_List_Table
*/
diff --git a/tests/phpunit/tests/multisite/wpNetworkQuery.php b/tests/phpunit/tests/multisite/wpNetworkQuery.php
index cb346e6649..92f881419e 100644
--- a/tests/phpunit/tests/multisite/wpNetworkQuery.php
+++ b/tests/phpunit/tests/multisite/wpNetworkQuery.php
@@ -1,630 +1,627 @@
<?php
-if ( is_multisite() ) :
-
- /**
- * Test network query functionality in multisite.
- *
- * @group ms-network
- * @group ms-network-query
- * @group multisite
- */
- class Tests_Multisite_wpNetworkQuery extends WP_UnitTestCase {
- protected static $network_ids;
-
- public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
- self::$network_ids = array(
- 'wordpress.org/' => array(
- 'domain' => 'wordpress.org',
- 'path' => '/',
- ),
- 'make.wordpress.org/' => array(
- 'domain' => 'make.wordpress.org',
- 'path' => '/',
- ),
- 'www.wordpress.net/' => array(
- 'domain' => 'www.wordpress.net',
- 'path' => '/',
- ),
- 'www.w.org/foo/' => array(
- 'domain' => 'www.w.org',
- 'path' => '/foo/',
- ),
- );
-
- foreach ( self::$network_ids as &$id ) {
- $id = $factory->network->create( $id );
- }
- unset( $id );
- }
+/**
+ * Test network query functionality in multisite.
+ *
+ * @group ms-network
+ * @group ms-network-query
+ * @group ms-required
+ * @group multisite
+ */
+class Tests_Multisite_wpNetworkQuery extends WP_UnitTestCase {
+ protected static $network_ids;
+
+ public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
+ self::$network_ids = array(
+ 'wordpress.org/' => array(
+ 'domain' => 'wordpress.org',
+ 'path' => '/',
+ ),
+ 'make.wordpress.org/' => array(
+ 'domain' => 'make.wordpress.org',
+ 'path' => '/',
+ ),
+ 'www.wordpress.net/' => array(
+ 'domain' => 'www.wordpress.net',
+ 'path' => '/',
+ ),
+ 'www.w.org/foo/' => array(
+ 'domain' => 'www.w.org',
+ 'path' => '/foo/',
+ ),
+ );
+
+ foreach ( self::$network_ids as &$id ) {
+ $id = $factory->network->create( $id );
+ }
+ unset( $id );
+ }
- public static function wpTearDownAfterClass() {
- global $wpdb;
+ public static function wpTearDownAfterClass() {
+ global $wpdb;
- foreach ( self::$network_ids as $id ) {
- $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->sitemeta} WHERE site_id = %d", $id ) );
- $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->site} WHERE id= %d", $id ) );
- }
+ foreach ( self::$network_ids as $id ) {
+ $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->sitemeta} WHERE site_id = %d", $id ) );
+ $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->site} WHERE id= %d", $id ) );
}
+ }
- public function test_wp_network_query_by_number() {
- $q = new WP_Network_Query();
- $found = $q->query(
- array(
- 'fields' => 'ids',
- 'number' => 3,
- )
- );
-
- $this->assertCount( 3, $found );
- }
+ public function test_wp_network_query_by_number() {
+ $q = new WP_Network_Query();
+ $found = $q->query(
+ array(
+ 'fields' => 'ids',
+ 'number' => 3,
+ )
+ );
- public function test_wp_network_query_by_network__in_with_order() {
- $expected = array( self::$network_ids['wordpress.org/'], self::$network_ids['make.wordpress.org/'] );
-
- $q = new WP_Network_Query();
- $found = $q->query(
- array(
- 'fields' => 'ids',
- 'network__in' => $expected,
- 'order' => 'ASC',
- )
- );
-
- $this->assertSame( $expected, $found );
-
- $found = $q->query(
- array(
- 'fields' => 'ids',
- 'network__in' => $expected,
- 'order' => 'DESC',
- )
- );
-
- $this->assertSame( array_reverse( $expected ), $found );
- }
+ $this->assertCount( 3, $found );
+ }
- public function test_wp_network_query_by_network__in_with_single_id() {
- $expected = array( self::$network_ids['wordpress.org/'] );
+ public function test_wp_network_query_by_network__in_with_order() {
+ $expected = array( self::$network_ids['wordpress.org/'], self::$network_ids['make.wordpress.org/'] );
+
+ $q = new WP_Network_Query();
+ $found = $q->query(
+ array(
+ 'fields' => 'ids',
+ 'network__in' => $expected,
+ 'order' => 'ASC',
+ )
+ );
+
+ $this->assertSame( $expected, $found );
+
+ $found = $q->query(
+ array(
+ 'fields' => 'ids',
+ 'network__in' => $expected,
+ 'order' => 'DESC',
+ )
+ );
+
+ $this->assertSame( array_reverse( $expected ), $found );
+ }
- $q = new WP_Network_Query();
- $found = $q->query(
- array(
- 'fields' => 'ids',
- 'network__in' => $expected,
- )
- );
+ public function test_wp_network_query_by_network__in_with_single_id() {
+ $expected = array( self::$network_ids['wordpress.org/'] );
- $this->assertSameSets( $expected, $found );
- }
+ $q = new WP_Network_Query();
+ $found = $q->query(
+ array(
+ 'fields' => 'ids',
+ 'network__in' => $expected,
+ )
+ );
- public function test_wp_network_query_by_network__in_with_multiple_ids() {
- $expected = array( self::$network_ids['wordpress.org/'], self::$network_ids['www.wordpress.net/'] );
+ $this->assertSameSets( $expected, $found );
+ }
- $q = new WP_Network_Query();
- $found = $q->query(
- array(
- 'fields' => 'ids',
- 'network__in' => $expected,
- )
- );
+ public function test_wp_network_query_by_network__in_with_multiple_ids() {
+ $expected = array( self::$network_ids['wordpress.org/'], self::$network_ids['www.wordpress.net/'] );
- $this->assertSameSets( $expected, $found );
- }
+ $q = new WP_Network_Query();
+ $found = $q->query(
+ array(
+ 'fields' => 'ids',
+ 'network__in' => $expected,
+ )
+ );
- public function test_wp_network_query_by_network__in_and_count_with_multiple_ids() {
- $expected = array( self::$network_ids['wordpress.org/'], self::$network_ids['make.wordpress.org/'] );
+ $this->assertSameSets( $expected, $found );
+ }
- $q = new WP_Network_Query();
- $found = $q->query(
- array(
- 'fields' => 'ids',
- 'count' => true,
- 'network__in' => $expected,
- )
- );
+ public function test_wp_network_query_by_network__in_and_count_with_multiple_ids() {
+ $expected = array( self::$network_ids['wordpress.org/'], self::$network_ids['make.wordpress.org/'] );
- $this->assertSame( 2, $found );
- }
+ $q = new WP_Network_Query();
+ $found = $q->query(
+ array(
+ 'fields' => 'ids',
+ 'count' => true,
+ 'network__in' => $expected,
+ )
+ );
- public function test_wp_network_query_by_network__not_in_with_single_id() {
- $excluded = array( self::$network_ids['wordpress.org/'] );
- $expected = array_diff( self::$network_ids, $excluded );
+ $this->assertSame( 2, $found );
+ }
- // Exclude main network since we don't have control over it here.
- $excluded[] = 1;
+ public function test_wp_network_query_by_network__not_in_with_single_id() {
+ $excluded = array( self::$network_ids['wordpress.org/'] );
+ $expected = array_diff( self::$network_ids, $excluded );
- $q = new WP_Network_Query();
- $found = $q->query(
- array(
- 'fields' => 'ids',
- 'network__not_in' => $excluded,
- )
- );
+ // Exclude main network since we don't have control over it here.
+ $excluded[] = 1;
- $this->assertSameSets( $expected, $found );
- }
+ $q = new WP_Network_Query();
+ $found = $q->query(
+ array(
+ 'fields' => 'ids',
+ 'network__not_in' => $excluded,
+ )
+ );
- public function test_wp_network_query_by_network__not_in_with_multiple_ids() {
- $excluded = array( self::$network_ids['wordpress.org/'], self::$network_ids['www.w.org/foo/'] );
- $expected = array_diff( self::$network_ids, $excluded );
+ $this->assertSameSets( $expected, $found );
+ }
- // Exclude main network since we don't have control over it here.
- $excluded[] = 1;
+ public function test_wp_network_query_by_network__not_in_with_multiple_ids() {
+ $excluded = array( self::$network_ids['wordpress.org/'], self::$network_ids['www.w.org/foo/'] );
+ $expected = array_diff( self::$network_ids, $excluded );
- $q = new WP_Network_Query();
- $found = $q->query(
- array(
- 'fields' => 'ids',
- 'network__not_in' => $excluded,
- )
- );
+ // Exclude main network since we don't have control over it here.
+ $excluded[] = 1;
- $this->assertSameSets( $expected, $found );
- }
+ $q = new WP_Network_Query();
+ $found = $q->query(
+ array(
+ 'fields' => 'ids',
+ 'network__not_in' => $excluded,
+ )
+ );
- public function test_wp_network_query_by_domain() {
- $q = new WP_Network_Query();
- $found = $q->query(
- array(
- 'fields' => 'ids',
- 'domain' => 'www.w.org',
- )
- );
+ $this->assertSameSets( $expected, $found );
+ }
- $expected = array(
- self::$network_ids['www.w.org/foo/'],
- );
+ public function test_wp_network_query_by_domain() {
+ $q = new WP_Network_Query();
+ $found = $q->query(
+ array(
+ 'fields' => 'ids',
+ 'domain' => 'www.w.org',
+ )
+ );
- $this->assertSameSets( $expected, $found );
- }
+ $expected = array(
+ self::$network_ids['www.w.org/foo/'],
+ );
- public function test_wp_network_query_by_domain__in_with_single_domain() {
- $q = new WP_Network_Query();
- $found = $q->query(
- array(
- 'fields' => 'ids',
- 'domain__in' => array( 'make.wordpress.org' ),
- )
- );
+ $this->assertSameSets( $expected, $found );
+ }
- $expected = array(
- self::$network_ids['make.wordpress.org/'],
- );
+ public function test_wp_network_query_by_domain__in_with_single_domain() {
+ $q = new WP_Network_Query();
+ $found = $q->query(
+ array(
+ 'fields' => 'ids',
+ 'domain__in' => array( 'make.wordpress.org' ),
+ )
+ );
- $this->assertSameSets( $expected, $found );
- }
+ $expected = array(
+ self::$network_ids['make.wordpress.org/'],
+ );
- public function test_wp_network_query_by_domain__in_with_multiple_domains() {
- $q = new WP_Network_Query();
- $found = $q->query(
- array(
- 'fields' => 'ids',
- 'domain__in' => array( 'wordpress.org', 'make.wordpress.org' ),
- )
- );
-
- $expected = array(
- self::$network_ids['wordpress.org/'],
- self::$network_ids['make.wordpress.org/'],
- );
-
- $this->assertSameSets( $expected, $found );
- }
+ $this->assertSameSets( $expected, $found );
+ }
- public function test_wp_network_query_by_domain__in_with_multiple_domains_and_number() {
- $q = new WP_Network_Query();
- $found = $q->query(
- array(
- 'fields' => 'ids',
- 'number' => 1,
- 'domain__in' => array( 'wordpress.org', 'make.wordpress.org' ),
- )
- );
-
- $expected = array(
- self::$network_ids['wordpress.org/'],
- );
-
- $this->assertSameSets( $expected, $found );
- }
+ public function test_wp_network_query_by_domain__in_with_multiple_domains() {
+ $q = new WP_Network_Query();
+ $found = $q->query(
+ array(
+ 'fields' => 'ids',
+ 'domain__in' => array( 'wordpress.org', 'make.wordpress.org' ),
+ )
+ );
+
+ $expected = array(
+ self::$network_ids['wordpress.org/'],
+ self::$network_ids['make.wordpress.org/'],
+ );
+
+ $this->assertSameSets( $expected, $found );
+ }
- public function test_wp_network_query_by_domain__in_with_multiple_domains_and_number_and_offset() {
- $q = new WP_Network_Query();
- $found = $q->query(
- array(
- 'fields' => 'ids',
- 'number' => 1,
- 'offset' => 1,
- 'domain__in' => array( 'wordpress.org', 'make.wordpress.org' ),
- )
- );
-
- $expected = array(
- self::$network_ids['make.wordpress.org/'],
- );
-
- $this->assertSameSets( $expected, $found );
- }
+ public function test_wp_network_query_by_domain__in_with_multiple_domains_and_number() {
+ $q = new WP_Network_Query();
+ $found = $q->query(
+ array(
+ 'fields' => 'ids',
+ 'number' => 1,
+ 'domain__in' => array( 'wordpress.org', 'make.wordpress.org' ),
+ )
+ );
+
+ $expected = array(
+ self::$network_ids['wordpress.org/'],
+ );
+
+ $this->assertSameSets( $expected, $found );
+ }
- public function test_wp_network_query_by_domain__not_in_with_single_domain() {
- $q = new WP_Network_Query();
- $found = $q->query(
- array(
- 'fields' => 'ids',
- 'domain__not_in' => array( 'www.w.org' ),
- )
- );
-
- $expected = array(
- get_current_site()->id, // Account for the initial network added by the test suite.
- self::$network_ids['wordpress.org/'],
- self::$network_ids['make.wordpress.org/'],
- self::$network_ids['www.wordpress.net/'],
- );
-
- $this->assertSameSets( $expected, $found );
- }
+ public function test_wp_network_query_by_domain__in_with_multiple_domains_and_number_and_offset() {
+ $q = new WP_Network_Query();
+ $found = $q->query(
+ array(
+ 'fields' => 'ids',
+ 'number' => 1,
+ 'offset' => 1,
+ 'domain__in' => array( 'wordpress.org', 'make.wordpress.org' ),
+ )
+ );
+
+ $expected = array(
+ self::$network_ids['make.wordpress.org/'],
+ );
+
+ $this->assertSameSets( $expected, $found );
+ }
- public function test_wp_network_query_by_domain__not_in_with_multiple_domains() {
- $q = new WP_Network_Query();
- $found = $q->query(
- array(
- 'fields' => 'ids',
- 'domain__not_in' => array( 'wordpress.org', 'www.w.org' ),
- )
- );
-
- $expected = array(
- get_current_site()->id, // Account for the initial network added by the test suite.
- self::$network_ids['make.wordpress.org/'],
- self::$network_ids['www.wordpress.net/'],
- );
-
- $this->assertSameSets( $expected, $found );
- }
+ public function test_wp_network_query_by_domain__not_in_with_single_domain() {
+ $q = new WP_Network_Query();
+ $found = $q->query(
+ array(
+ 'fields' => 'ids',
+ 'domain__not_in' => array( 'www.w.org' ),
+ )
+ );
+
+ $expected = array(
+ get_current_site()->id, // Account for the initial network added by the test suite.
+ self::$network_ids['wordpress.org/'],
+ self::$network_ids['make.wordpress.org/'],
+ self::$network_ids['www.wordpress.net/'],
+ );
+
+ $this->assertSameSets( $expected, $found );
+ }
- public function test_wp_network_query_by_domain__not_in_with_multiple_domains_and_number() {
- $q = new WP_Network_Query();
- $found = $q->query(
- array(
- 'fields' => 'ids',
- 'number' => 2,
- 'domain__not_in' => array( 'wordpress.org', 'www.w.org' ),
- )
- );
-
- $expected = array(
- get_current_site()->id, // Account for the initial network added by the test suite.
- self::$network_ids['make.wordpress.org/'],
- );
-
- $this->assertSameSets( $expected, $found );
- }
+ public function test_wp_network_query_by_domain__not_in_with_multiple_domains() {
+ $q = new WP_Network_Query();
+ $found = $q->query(
+ array(
+ 'fields' => 'ids',
+ 'domain__not_in' => array( 'wordpress.org', 'www.w.org' ),
+ )
+ );
+
+ $expected = array(
+ get_current_site()->id, // Account for the initial network added by the test suite.
+ self::$network_ids['make.wordpress.org/'],
+ self::$network_ids['www.wordpress.net/'],
+ );
+
+ $this->assertSameSets( $expected, $found );
+ }
- public function test_wp_network_query_by_domain__not_in_with_multiple_domains_and_number_and_offset() {
- $q = new WP_Network_Query();
- $found = $q->query(
- array(
- 'fields' => 'ids',
- 'number' => 2,
- 'offset' => 1,
- 'domain__not_in' => array( 'wordpress.org', 'www.w.org' ),
- )
- );
-
- $expected = array(
- self::$network_ids['make.wordpress.org/'],
- self::$network_ids['www.wordpress.net/'],
- );
-
- $this->assertSameSets( $expected, $found );
- }
+ public function test_wp_network_query_by_domain__not_in_with_multiple_domains_and_number() {
+ $q = new WP_Network_Query();
+ $found = $q->query(
+ array(
+ 'fields' => 'ids',
+ 'number' => 2,
+ 'domain__not_in' => array( 'wordpress.org', 'www.w.org' ),
+ )
+ );
+
+ $expected = array(
+ get_current_site()->id, // Account for the initial network added by the test suite.
+ self::$network_ids['make.wordpress.org/'],
+ );
+
+ $this->assertSameSets( $expected, $found );
+ }
- public function test_wp_network_query_by_path_with_expected_results() {
- $q = new WP_Network_Query();
- $found = $q->query(
- array(
- 'fields' => 'ids',
- 'path' => '/',
- 'network__not_in' => get_current_site()->id, // Exclude the initial network added by the test suite.
- )
- );
-
- $expected = array(
- self::$network_ids['wordpress.org/'],
- self::$network_ids['make.wordpress.org/'],
- self::$network_ids['www.wordpress.net/'],
- );
-
- $this->assertSameSets( $expected, $found );
- }
+ public function test_wp_network_query_by_domain__not_in_with_multiple_domains_and_number_and_offset() {
+ $q = new WP_Network_Query();
+ $found = $q->query(
+ array(
+ 'fields' => 'ids',
+ 'number' => 2,
+ 'offset' => 1,
+ 'domain__not_in' => array( 'wordpress.org', 'www.w.org' ),
+ )
+ );
+
+ $expected = array(
+ self::$network_ids['make.wordpress.org/'],
+ self::$network_ids['www.wordpress.net/'],
+ );
+
+ $this->assertSameSets( $expected, $found );
+ }
- public function test_wp_network_query_by_path_and_number_and_offset_with_expected_results() {
- $q = new WP_Network_Query();
- $found = $q->query(
- array(
- 'fields' => 'ids',
- 'number' => 1,
- 'offset' => 2,
- 'path' => '/',
- 'network__not_in' => get_current_site()->id, // Exclude the initial network added by the test suite.
- )
- );
-
- $expected = array(
- self::$network_ids['www.wordpress.net/'],
- );
-
- $this->assertSameSets( $expected, $found );
- }
+ public function test_wp_network_query_by_path_with_expected_results() {
+ $q = new WP_Network_Query();
+ $found = $q->query(
+ array(
+ 'fields' => 'ids',
+ 'path' => '/',
+ 'network__not_in' => get_current_site()->id, // Exclude the initial network added by the test suite.
+ )
+ );
+
+ $expected = array(
+ self::$network_ids['wordpress.org/'],
+ self::$network_ids['make.wordpress.org/'],
+ self::$network_ids['www.wordpress.net/'],
+ );
+
+ $this->assertSameSets( $expected, $found );
+ }
- public function test_wp_network_query_by_path_with_no_expected_results() {
- $q = new WP_Network_Query();
- $found = $q->query(
- array(
- 'fields' => 'ids',
- 'path' => '/bar/',
- )
- );
+ public function test_wp_network_query_by_path_and_number_and_offset_with_expected_results() {
+ $q = new WP_Network_Query();
+ $found = $q->query(
+ array(
+ 'fields' => 'ids',
+ 'number' => 1,
+ 'offset' => 2,
+ 'path' => '/',
+ 'network__not_in' => get_current_site()->id, // Exclude the initial network added by the test suite.
+ )
+ );
+
+ $expected = array(
+ self::$network_ids['www.wordpress.net/'],
+ );
+
+ $this->assertSameSets( $expected, $found );
+ }
- $this->assertEmpty( $found );
- }
+ public function test_wp_network_query_by_path_with_no_expected_results() {
+ $q = new WP_Network_Query();
+ $found = $q->query(
+ array(
+ 'fields' => 'ids',
+ 'path' => '/bar/',
+ )
+ );
- public function test_wp_network_query_by_search_with_text_in_domain() {
- $q = new WP_Network_Query();
- $found = $q->query(
- array(
- 'fields' => 'ids',
- 'search' => 'ww.word',
- )
- );
+ $this->assertEmpty( $found );
+ }
- $expected = array(
- self::$network_ids['www.wordpress.net/'],
- );
+ public function test_wp_network_query_by_search_with_text_in_domain() {
+ $q = new WP_Network_Query();
+ $found = $q->query(
+ array(
+ 'fields' => 'ids',
+ 'search' => 'ww.word',
+ )
+ );
- $this->assertSameSets( $expected, $found );
- }
+ $expected = array(
+ self::$network_ids['www.wordpress.net/'],
+ );
- public function test_wp_network_query_by_search_with_text_in_path() {
- $q = new WP_Network_Query();
- $found = $q->query(
- array(
- 'fields' => 'ids',
- 'search' => 'foo',
- )
- );
+ $this->assertSameSets( $expected, $found );
+ }
- $expected = array(
- self::$network_ids['www.w.org/foo/'],
- );
+ public function test_wp_network_query_by_search_with_text_in_path() {
+ $q = new WP_Network_Query();
+ $found = $q->query(
+ array(
+ 'fields' => 'ids',
+ 'search' => 'foo',
+ )
+ );
- $this->assertSameSets( $expected, $found );
- }
+ $expected = array(
+ self::$network_ids['www.w.org/foo/'],
+ );
- public function test_wp_network_query_by_path_order_by_domain_desc() {
- $q = new WP_Network_Query();
- $found = $q->query(
- array(
- 'fields' => 'ids',
- 'path' => '/',
- 'network__not_in' => get_current_site()->id, // Exclude the initial network added by the test suite.
- 'order' => 'DESC',
- 'orderby' => 'domain',
- )
- );
-
- $expected = array(
- self::$network_ids['www.wordpress.net/'],
- self::$network_ids['wordpress.org/'],
- self::$network_ids['make.wordpress.org/'],
- );
-
- $this->assertSame( $expected, $found );
- }
+ $this->assertSameSets( $expected, $found );
+ }
- /**
- * @ticket 41347
- */
- public function test_wp_network_query_cache_with_different_fields_no_count() {
- $q = new WP_Network_Query();
- $query_1 = $q->query(
- array(
- 'fields' => 'all',
- 'number' => 3,
- 'order' => 'ASC',
- )
- );
- $number_of_queries = get_num_queries();
-
- $query_2 = $q->query(
- array(
- 'fields' => 'ids',
- 'number' => 3,
- 'order' => 'ASC',
- )
- );
-
- $this->assertSame( $number_of_queries, get_num_queries() );
- }
+ public function test_wp_network_query_by_path_order_by_domain_desc() {
+ $q = new WP_Network_Query();
+ $found = $q->query(
+ array(
+ 'fields' => 'ids',
+ 'path' => '/',
+ 'network__not_in' => get_current_site()->id, // Exclude the initial network added by the test suite.
+ 'order' => 'DESC',
+ 'orderby' => 'domain',
+ )
+ );
+
+ $expected = array(
+ self::$network_ids['www.wordpress.net/'],
+ self::$network_ids['wordpress.org/'],
+ self::$network_ids['make.wordpress.org/'],
+ );
+
+ $this->assertSame( $expected, $found );
+ }
- /**
- * @ticket 41347
- */
- public function test_wp_network_query_cache_with_different_fields_active_count() {
- $q = new WP_Network_Query();
-
- $query_1 = $q->query(
- array(
- 'fields' => 'all',
- 'number' => 3,
- 'order' => 'ASC',
- 'count' => true,
- )
- );
- $number_of_queries = get_num_queries();
-
- $query_2 = $q->query(
- array(
- 'fields' => 'ids',
- 'number' => 3,
- 'order' => 'ASC',
- 'count' => true,
- )
- );
- $this->assertSame( $number_of_queries, get_num_queries() );
- }
+ /**
+ * @ticket 41347
+ */
+ public function test_wp_network_query_cache_with_different_fields_no_count() {
+ $q = new WP_Network_Query();
+ $query_1 = $q->query(
+ array(
+ 'fields' => 'all',
+ 'number' => 3,
+ 'order' => 'ASC',
+ )
+ );
+ $number_of_queries = get_num_queries();
+
+ $query_2 = $q->query(
+ array(
+ 'fields' => 'ids',
+ 'number' => 3,
+ 'order' => 'ASC',
+ )
+ );
+
+ $this->assertSame( $number_of_queries, get_num_queries() );
+ }
- /**
- * @ticket 41347
- */
- public function test_wp_network_query_cache_with_same_fields_different_count() {
- $q = new WP_Network_Query();
-
- $query_1 = $q->query(
- array(
- 'fields' => 'ids',
- 'number' => 3,
- 'order' => 'ASC',
- )
- );
-
- $number_of_queries = get_num_queries();
-
- $query_2 = $q->query(
- array(
- 'fields' => 'ids',
- 'number' => 3,
- 'order' => 'ASC',
- 'count' => true,
- )
- );
- $this->assertSame( $number_of_queries + 1, get_num_queries() );
- }
+ /**
+ * @ticket 41347
+ */
+ public function test_wp_network_query_cache_with_different_fields_active_count() {
+ $q = new WP_Network_Query();
+
+ $query_1 = $q->query(
+ array(
+ 'fields' => 'all',
+ 'number' => 3,
+ 'order' => 'ASC',
+ 'count' => true,
+ )
+ );
+ $number_of_queries = get_num_queries();
+
+ $query_2 = $q->query(
+ array(
+ 'fields' => 'ids',
+ 'number' => 3,
+ 'order' => 'ASC',
+ 'count' => true,
+ )
+ );
+ $this->assertSame( $number_of_queries, get_num_queries() );
+ }
- /**
- * @ticket 55461
- */
- public function test_wp_network_query_cache_with_same_fields_same_cache_field() {
- $q = new WP_Network_Query();
- $query_1 = $q->query(
- array(
- 'fields' => 'all',
- 'number' => 3,
- 'order' => 'ASC',
- 'update_network_cache' => true,
- )
- );
- $number_of_queries = get_num_queries();
-
- $query_2 = $q->query(
- array(
- 'fields' => 'all',
- 'number' => 3,
- 'order' => 'ASC',
- 'update_network_cache' => true,
- )
- );
-
- $this->assertSame( $number_of_queries, get_num_queries() );
- }
+ /**
+ * @ticket 41347
+ */
+ public function test_wp_network_query_cache_with_same_fields_different_count() {
+ $q = new WP_Network_Query();
+
+ $query_1 = $q->query(
+ array(
+ 'fields' => 'ids',
+ 'number' => 3,
+ 'order' => 'ASC',
+ )
+ );
+
+ $number_of_queries = get_num_queries();
+
+ $query_2 = $q->query(
+ array(
+ 'fields' => 'ids',
+ 'number' => 3,
+ 'order' => 'ASC',
+ 'count' => true,
+ )
+ );
+ $this->assertSame( $number_of_queries + 1, get_num_queries() );
+ }
- /**
- * @ticket 55461
- */
- public function test_wp_network_query_cache_with_same_fields_different_cache_field() {
- $q = new WP_Network_Query();
- $query_1 = $q->query(
- array(
- 'fields' => 'all',
- 'number' => 3,
- 'order' => 'ASC',
- 'update_network_cache' => true,
- )
- );
- $number_of_queries = get_num_queries();
-
- $query_2 = $q->query(
- array(
- 'fields' => 'all',
- 'number' => 3,
- 'order' => 'ASC',
- 'update_network_cache' => false,
- )
- );
-
- $this->assertSame( $number_of_queries, get_num_queries() );
- }
+ /**
+ * @ticket 55461
+ */
+ public function test_wp_network_query_cache_with_same_fields_same_cache_field() {
+ $q = new WP_Network_Query();
+ $query_1 = $q->query(
+ array(
+ 'fields' => 'all',
+ 'number' => 3,
+ 'order' => 'ASC',
+ 'update_network_cache' => true,
+ )
+ );
+ $number_of_queries = get_num_queries();
+
+ $query_2 = $q->query(
+ array(
+ 'fields' => 'all',
+ 'number' => 3,
+ 'order' => 'ASC',
+ 'update_network_cache' => true,
+ )
+ );
+
+ $this->assertSame( $number_of_queries, get_num_queries() );
+ }
- /**
- * @ticket 45749
- * @ticket 47599
- */
- public function test_networks_pre_query_filter_should_bypass_database_query() {
- add_filter( 'networks_pre_query', array( __CLASS__, 'filter_networks_pre_query' ), 10, 2 );
+ /**
+ * @ticket 55461
+ */
+ public function test_wp_network_query_cache_with_same_fields_different_cache_field() {
+ $q = new WP_Network_Query();
+ $query_1 = $q->query(
+ array(
+ 'fields' => 'all',
+ 'number' => 3,
+ 'order' => 'ASC',
+ 'update_network_cache' => true,
+ )
+ );
+ $number_of_queries = get_num_queries();
+
+ $query_2 = $q->query(
+ array(
+ 'fields' => 'all',
+ 'number' => 3,
+ 'order' => 'ASC',
+ 'update_network_cache' => false,
+ )
+ );
+
+ $this->assertSame( $number_of_queries, get_num_queries() );
+ }
- $num_queries = get_num_queries();
+ /**
+ * @ticket 45749
+ * @ticket 47599
+ */
+ public function test_networks_pre_query_filter_should_bypass_database_query() {
+ add_filter( 'networks_pre_query', array( __CLASS__, 'filter_networks_pre_query' ), 10, 2 );
- $q = new WP_Network_Query();
- $results = $q->query( array() );
+ $num_queries = get_num_queries();
- remove_filter( 'networks_pre_query', array( __CLASS__, 'filter_networks_pre_query' ), 10, 2 );
+ $q = new WP_Network_Query();
+ $results = $q->query( array() );
- // Make sure no queries were executed.
- $this->assertSame( $num_queries, get_num_queries() );
+ remove_filter( 'networks_pre_query', array( __CLASS__, 'filter_networks_pre_query' ), 10, 2 );
- // We manually inserted a non-existing site and overrode the results with it.
- $this->assertSame( array( 555 ), $results );
+ // Make sure no queries were executed.
+ $this->assertSame( $num_queries, get_num_queries() );
- // Make sure manually setting found_networks doesn't get overwritten.
- $this->assertSame( 1, $q->found_networks );
- }
+ // We manually inserted a non-existing site and overrode the results with it.
+ $this->assertSame( array( 555 ), $results );
- public static function filter_networks_pre_query( $networks, $query ) {
- $query->found_networks = 1;
+ // Make sure manually setting found_networks doesn't get overwritten.
+ $this->assertSame( 1, $q->found_networks );
+ }
- return array( 555 );
- }
+ public static function filter_networks_pre_query( $networks, $query ) {
+ $query->found_networks = 1;
- /**
- * @ticket 51333
- */
- public function test_networks_pre_query_filter_should_set_networks_property() {
- add_filter( 'networks_pre_query', array( __CLASS__, 'filter_networks_pre_query_and_set_networks' ), 10, 2 );
+ return array( 555 );
+ }
- $q = new WP_Network_Query();
- $results = $q->query( array() );
+ /**
+ * @ticket 51333
+ */
+ public function test_networks_pre_query_filter_should_set_networks_property() {
+ add_filter( 'networks_pre_query', array( __CLASS__, 'filter_networks_pre_query_and_set_networks' ), 10, 2 );
- remove_filter( 'networks_pre_query', array( __CLASS__, 'filter_networks_pre_query_and_set_networks' ), 10 );
+ $q = new WP_Network_Query();
+ $results = $q->query( array() );
- // Make sure the networks property is the same as the results.
- $this->assertSame( $results, $q->networks );
+ remove_filter( 'networks_pre_query', array( __CLASS__, 'filter_networks_pre_query_and_set_networks' ), 10 );
- // Make sure the network domain is `wordpress.org`.
- $this->assertSame( 'wordpress.org', $q->networks[0]->domain );
- }
+ // Make sure the networks property is the same as the results.
+ $this->assertSame( $results, $q->networks );
- public static function filter_networks_pre_query_and_set_networks( $networks, $query ) {
- return array( get_network( self::$network_ids['wordpress.org/'] ) );
- }
+ // Make sure the network domain is `wordpress.org`.
+ $this->assertSame( 'wordpress.org', $q->networks[0]->domain );
+ }
- /**
- * @ticket 56841
- */
- public function test_wp_network_query_does_not_have_leading_whitespace() {
- $q = new WP_Network_Query();
- $q->query(
- array(
- 'fields' => 'all',
- 'number' => 3,
- 'order' => 'ASC',
- 'update_network_cache' => true,
- )
- );
-
- $this->assertSame( ltrim( $q->request ), $q->request, 'The query has leading whitespace' );
- }
+ public static function filter_networks_pre_query_and_set_networks( $networks, $query ) {
+ return array( get_network( self::$network_ids['wordpress.org/'] ) );
}
-endif;
+ /**
+ * @ticket 56841
+ */
+ public function test_wp_network_query_does_not_have_leading_whitespace() {
+ $q = new WP_Network_Query();
+ $q->query(
+ array(
+ 'fields' => 'all',
+ 'number' => 3,
+ 'order' => 'ASC',
+ 'update_network_cache' => true,
+ )
+ );
+
+ $this->assertSame( ltrim( $q->request ), $q->request, 'The query has leading whitespace' );
+ }
+}
diff --git a/tests/phpunit/tests/multisite/wpSiteQuery.php b/tests/phpunit/tests/multisite/wpSiteQuery.php
index d22faeecb3..0bca5818fe 100644
--- a/tests/phpunit/tests/multisite/wpSiteQuery.php
+++ b/tests/phpunit/tests/multisite/wpSiteQuery.php
@@ -1,1187 +1,1184 @@
<?php
-if ( is_multisite() ) :
-
- /**
- * Test site query functionality in multisite.
- *
- * @group ms-site
- * @group multisite
- */
- class Tests_Multisite_wpSiteQuery extends WP_UnitTestCase {
- protected static $network_ids;
- protected static $site_ids;
-
- public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
- self::$network_ids = array(
- 'wordpress.org/' => array(
- 'domain' => 'wordpress.org',
- 'path' => '/',
- ),
- 'make.wordpress.org/' => array(
- 'domain' => 'make.wordpress.org',
- 'path' => '/',
- ),
- 'www.wordpress.net/' => array(
- 'domain' => 'www.wordpress.net',
- 'path' => '/',
- ),
- );
-
- foreach ( self::$network_ids as &$id ) {
- $id = $factory->network->create( $id );
- }
- unset( $id );
-
- self::$site_ids = array(
- 'wordpress.org/' => array(
- 'domain' => 'wordpress.org',
- 'path' => '/',
- 'network_id' => self::$network_ids['wordpress.org/'],
- ),
- 'wordpress.org/foo/' => array(
- 'domain' => 'wordpress.org',
- 'path' => '/foo/',
- 'network_id' => self::$network_ids['wordpress.org/'],
- ),
- 'wordpress.org/foo/bar/' => array(
- 'domain' => 'wordpress.org',
- 'path' => '/foo/bar/',
- 'network_id' => self::$network_ids['wordpress.org/'],
- ),
- 'make.wordpress.org/' => array(
- 'domain' => 'make.wordpress.org',
- 'path' => '/',
- 'network_id' => self::$network_ids['make.wordpress.org/'],
- ),
- 'make.wordpress.org/foo/' => array(
- 'domain' => 'make.wordpress.org',
- 'path' => '/foo/',
- 'network_id' => self::$network_ids['make.wordpress.org/'],
- ),
- 'www.w.org/' => array(
- 'domain' => 'www.w.org',
- 'path' => '/',
- ),
- 'www.w.org/foo/' => array(
- 'domain' => 'www.w.org',
- 'path' => '/foo/',
- ),
- 'www.w.org/foo/bar/' => array(
- 'domain' => 'www.w.org',
- 'path' => '/foo/bar/',
- ),
- 'www.w.org/make/' => array(
- 'domain' => 'www.w.org',
- 'path' => '/make/',
- 'public' => 1,
- 'lang_id' => 1,
- ),
- );
-
- foreach ( self::$site_ids as &$id ) {
- $id = $factory->blog->create( $id );
- }
- unset( $id );
+/**
+ * Test site query functionality in multisite.
+ *
+ * @group ms-required
+ * @group ms-site
+ * @group multisite
+ */
+class Tests_Multisite_wpSiteQuery extends WP_UnitTestCase {
+ protected static $network_ids;
+ protected static $site_ids;
+
+ public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
+ self::$network_ids = array(
+ 'wordpress.org/' => array(
+ 'domain' => 'wordpress.org',
+ 'path' => '/',
+ ),
+ 'make.wordpress.org/' => array(
+ 'domain' => 'make.wordpress.org',
+ 'path' => '/',
+ ),
+ 'www.wordpress.net/' => array(
+ 'domain' => 'www.wordpress.net',
+ 'path' => '/',
+ ),
+ );
+
+ foreach ( self::$network_ids as &$id ) {
+ $id = $factory->network->create( $id );
}
-
- public static function wpTearDownAfterClass() {
- global $wpdb;
-
- foreach ( self::$site_ids as $id ) {
- wp_delete_site( $id );
- }
-
- foreach ( self::$network_ids as $id ) {
- $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->sitemeta} WHERE site_id = %d", $id ) );
- $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->site} WHERE id= %d", $id ) );
- }
-
- wp_update_network_site_counts();
+ unset( $id );
+
+ self::$site_ids = array(
+ 'wordpress.org/' => array(
+ 'domain' => 'wordpress.org',
+ 'path' => '/',
+ 'network_id' => self::$network_ids['wordpress.org/'],
+ ),
+ 'wordpress.org/foo/' => array(
+ 'domain' => 'wordpress.org',
+ 'path' => '/foo/',
+ 'network_id' => self::$network_ids['wordpress.org/'],
+ ),
+ 'wordpress.org/foo/bar/' => array(
+ 'domain' => 'wordpress.org',
+ 'path' => '/foo/bar/',
+ 'network_id' => self::$network_ids['wordpress.org/'],
+ ),
+ 'make.wordpress.org/' => array(
+ 'domain' => 'make.wordpress.org',
+ 'path' => '/',
+ 'network_id' => self::$network_ids['make.wordpress.org/'],
+ ),
+ 'make.wordpress.org/foo/' => array(
+ 'domain' => 'make.wordpress.org',
+ 'path' => '/foo/',
+ 'network_id' => self::$network_ids['make.wordpress.org/'],
+ ),
+ 'www.w.org/' => array(
+ 'domain' => 'www.w.org',
+ 'path' => '/',
+ ),
+ 'www.w.org/foo/' => array(
+ 'domain' => 'www.w.org',
+ 'path' => '/foo/',
+ ),
+ 'www.w.org/foo/bar/' => array(
+ 'domain' => 'www.w.org',
+ 'path' => '/foo/bar/',
+ ),
+ 'www.w.org/make/' => array(
+ 'domain' => 'www.w.org',
+ 'path' => '/make/',
+ 'public' => 1,
+ 'lang_id' => 1,
+ ),
+ );
+
+ foreach ( self::$site_ids as &$id ) {
+ $id = $factory->blog->create( $id );
}
+ unset( $id );
+ }
- public function test_wp_site_query_by_ID() {
- $q = new WP_Site_Query();
- $found = $q->query(
- array(
- 'fields' => 'ids',
- 'ID' => self::$site_ids['www.w.org/'],
- )
- );
+ public static function wpTearDownAfterClass() {
+ global $wpdb;
- $this->assertSameSets( array( self::$site_ids['www.w.org/'] ), $found );
+ foreach ( self::$site_ids as $id ) {
+ wp_delete_site( $id );
}
- public function test_wp_site_query_by_number() {
- $q = new WP_Site_Query();
- $found = $q->query(
- array(
- 'fields' => 'ids',
- 'number' => 3,
- )
- );
-
- $this->assertCount( 3, $found );
+ foreach ( self::$network_ids as $id ) {
+ $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->sitemeta} WHERE site_id = %d", $id ) );
+ $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->site} WHERE id= %d", $id ) );
}
- public function test_wp_site_query_by_site__in_with_single_id() {
- $expected = array( self::$site_ids['wordpress.org/foo/'] );
-
- $q = new WP_Site_Query();
- $found = $q->query(
- array(
- 'fields' => 'ids',
- 'site__in' => $expected,
- )
- );
-
- $this->assertSameSets( $expected, $found );
- }
-
- public function test_wp_site_query_by_site__in_with_multiple_ids() {
- $expected = array( self::$site_ids['wordpress.org/'], self::$site_ids['wordpress.org/foo/'] );
-
- $q = new WP_Site_Query();
- $found = $q->query(
- array(
- 'fields' => 'ids',
- 'site__in' => $expected,
- )
- );
+ wp_update_network_site_counts();
+ }
- $this->assertSameSets( $expected, $found );
- }
+ public function test_wp_site_query_by_ID() {
+ $q = new WP_Site_Query();
+ $found = $q->query(
+ array(
+ 'fields' => 'ids',
+ 'ID' => self::$site_ids['www.w.org/'],
+ )
+ );
- /**
- * Test the `count` query var
- */
- public function test_wp_site_query_by_site__in_and_count_with_multiple_ids() {
- $expected = array( self::$site_ids['wordpress.org/'], self::$site_ids['wordpress.org/foo/'] );
+ $this->assertSameSets( array( self::$site_ids['www.w.org/'] ), $found );
+ }
- $q = new WP_Site_Query();
- $found = $q->query(
- array(
- 'fields' => 'ids',
- 'count' => true,
- 'site__in' => $expected,
- )
- );
+ public function test_wp_site_query_by_number() {
+ $q = new WP_Site_Query();
+ $found = $q->query(
+ array(
+ 'fields' => 'ids',
+ 'number' => 3,
+ )
+ );
- $this->assertSame( 2, $found );
- }
+ $this->assertCount( 3, $found );
+ }
- public function test_wp_site_query_by_site__not_in_with_single_id() {
- $excluded = array( self::$site_ids['wordpress.org/foo/'] );
- $expected = array_diff( self::$site_ids, $excluded );
+ public function test_wp_site_query_by_site__in_with_single_id() {
+ $expected = array( self::$site_ids['wordpress.org/foo/'] );
- // Exclude main site since we don't have control over it here.
- $excluded[] = 1;
+ $q = new WP_Site_Query();
+ $found = $q->query(
+ array(
+ 'fields' => 'ids',
+ 'site__in' => $expected,
+ )
+ );
- $q = new WP_Site_Query();
- $found = $q->query(
- array(
- 'fields' => 'ids',
- 'site__not_in' => $excluded,
- )
- );
+ $this->assertSameSets( $expected, $found );
+ }
- $this->assertSameSets( $expected, $found );
- }
+ public function test_wp_site_query_by_site__in_with_multiple_ids() {
+ $expected = array( self::$site_ids['wordpress.org/'], self::$site_ids['wordpress.org/foo/'] );
- public function test_wp_site_query_by_site__not_in_with_multiple_ids() {
- $excluded = array( self::$site_ids['wordpress.org/'], self::$site_ids['wordpress.org/foo/'] );
- $expected = array_diff( self::$site_ids, $excluded );
+ $q = new WP_Site_Query();
+ $found = $q->query(
+ array(
+ 'fields' => 'ids',
+ 'site__in' => $expected,
+ )
+ );
- // Exclude main site since we don't have control over it here.
- $excluded[] = 1;
+ $this->assertSameSets( $expected, $found );
+ }
- $q = new WP_Site_Query();
- $found = $q->query(
- array(
- 'fields' => 'ids',
- 'site__not_in' => $excluded,
- )
- );
+ /**
+ * Test the `count` query var
+ */
+ public function test_wp_site_query_by_site__in_and_count_with_multiple_ids() {
+ $expected = array( self::$site_ids['wordpress.org/'], self::$site_ids['wordpress.org/foo/'] );
+
+ $q = new WP_Site_Query();
+ $found = $q->query(
+ array(
+ 'fields' => 'ids',
+ 'count' => true,
+ 'site__in' => $expected,
+ )
+ );
+
+ $this->assertSame( 2, $found );
+ }
- $this->assertSameSets( $expected, $found );
- }
+ public function test_wp_site_query_by_site__not_in_with_single_id() {
+ $excluded = array( self::$site_ids['wordpress.org/foo/'] );
+ $expected = array_diff( self::$site_ids, $excluded );
- public function test_wp_site_query_by_network_id_with_order() {
- $q = new WP_Site_Query();
- $found = $q->query(
- array(
- 'fields' => 'ids',
- 'network_id' => self::$network_ids['wordpress.org/'],
- 'number' => 3,
- 'order' => 'ASC',
- )
- );
-
- $expected = array(
- self::$site_ids['wordpress.org/'],
- self::$site_ids['wordpress.org/foo/'],
- self::$site_ids['wordpress.org/foo/bar/'],
- );
+ // Exclude main site since we don't have control over it here.
+ $excluded[] = 1;
- $this->assertSame( $expected, $found );
+ $q = new WP_Site_Query();
+ $found = $q->query(
+ array(
+ 'fields' => 'ids',
+ 'site__not_in' => $excluded,
+ )
+ );
- $found = $q->query(
- array(
- 'fields' => 'ids',
- 'network_id' => self::$network_ids['wordpress.org/'],
- 'number' => 3,
- 'order' => 'DESC',
- )
- );
-
- $this->assertSame( array_reverse( $expected ), $found );
- }
+ $this->assertSameSets( $expected, $found );
+ }
- public function test_wp_site_query_by_network_id_with_existing_sites() {
- $q = new WP_Site_Query();
- $found = $q->query(
- array(
- 'fields' => 'ids',
- 'network_id' => self::$network_ids['make.wordpress.org/'],
- )
- );
+ public function test_wp_site_query_by_site__not_in_with_multiple_ids() {
+ $excluded = array( self::$site_ids['wordpress.org/'], self::$site_ids['wordpress.org/foo/'] );
+ $expected = array_diff( self::$site_ids, $excluded );
- $expected = array(
- self::$site_ids['make.wordpress.org/'],
- self::$site_ids['make.wordpress.org/foo/'],
- );
+ // Exclude main site since we don't have control over it here.
+ $excluded[] = 1;
- $this->assertSameSets( $expected, $found );
- }
+ $q = new WP_Site_Query();
+ $found = $q->query(
+ array(
+ 'fields' => 'ids',
+ 'site__not_in' => $excluded,
+ )
+ );
- public function test_wp_site_query_by_network_id_with_no_existing_sites() {
- $q = new WP_Site_Query();
- $found = $q->query(
- array(
- 'fields' => 'ids',
- 'network_id' => self::$network_ids['www.wordpress.net/'],
- )
- );
+ $this->assertSameSets( $expected, $found );
+ }
- $this->assertEmpty( $found );
- }
+ public function test_wp_site_query_by_network_id_with_order() {
+ $q = new WP_Site_Query();
+ $found = $q->query(
+ array(
+ 'fields' => 'ids',
+ 'network_id' => self::$network_ids['wordpress.org/'],
+ 'number' => 3,
+ 'order' => 'ASC',
+ )
+ );
+
+ $expected = array(
+ self::$site_ids['wordpress.org/'],
+ self::$site_ids['wordpress.org/foo/'],
+ self::$site_ids['wordpress.org/foo/bar/'],
+ );
+
+ $this->assertSame( $expected, $found );
+
+ $found = $q->query(
+ array(
+ 'fields' => 'ids',
+ 'network_id' => self::$network_ids['wordpress.org/'],
+ 'number' => 3,
+ 'order' => 'DESC',
+ )
+ );
+
+ $this->assertSame( array_reverse( $expected ), $found );
+ }
- public function test_wp_site_query_by_domain() {
- $q = new WP_Site_Query();
- $found = $q->query(
- array(
- 'fields' => 'ids',
- 'domain' => 'www.w.org',
- )
- );
-
- $expected = array(
- self::$site_ids['www.w.org/'],
- self::$site_ids['www.w.org/foo/'],
- self::$site_ids['www.w.org/foo/bar/'],
- self::$site_ids['www.w.org/make/'],
- );
+ public function test_wp_site_query_by_network_id_with_existing_sites() {
+ $q = new WP_Site_Query();
+ $found = $q->query(
+ array(
+ 'fields' => 'ids',
+ 'network_id' => self::$network_ids['make.wordpress.org/'],
+ )
+ );
+
+ $expected = array(
+ self::$site_ids['make.wordpress.org/'],
+ self::$site_ids['make.wordpress.org/foo/'],
+ );
+
+ $this->assertSameSets( $expected, $found );
+ }
- $this->assertSameSets( $expected, $found );
- }
+ public function test_wp_site_query_by_network_id_with_no_existing_sites() {
+ $q = new WP_Site_Query();
+ $found = $q->query(
+ array(
+ 'fields' => 'ids',
+ 'network_id' => self::$network_ids['www.wordpress.net/'],
+ )
+ );
- public function test_wp_site_query_by_domain_and_offset() {
- $q = new WP_Site_Query();
- $found = $q->query(
- array(
- 'fields' => 'ids',
- 'domain' => 'www.w.org',
- 'offset' => 1,
- )
- );
-
- $expected = array(
- self::$site_ids['www.w.org/foo/'],
- self::$site_ids['www.w.org/foo/bar/'],
- self::$site_ids['www.w.org/make/'],
- );
+ $this->assertEmpty( $found );
+ }
- $this->assertSameSets( $expected, $found );
- }
+ public function test_wp_site_query_by_domain() {
+ $q = new WP_Site_Query();
+ $found = $q->query(
+ array(
+ 'fields' => 'ids',
+ 'domain' => 'www.w.org',
+ )
+ );
+
+ $expected = array(
+ self::$site_ids['www.w.org/'],
+ self::$site_ids['www.w.org/foo/'],
+ self::$site_ids['www.w.org/foo/bar/'],
+ self::$site_ids['www.w.org/make/'],
+ );
+
+ $this->assertSameSets( $expected, $found );
+ }
- public function test_wp_site_query_by_domain_and_number_and_offset() {
- $q = new WP_Site_Query();
- $found = $q->query(
- array(
- 'fields' => 'ids',
- 'domain' => 'www.w.org',
- 'number' => 2,
- 'offset' => 1,
- )
- );
-
- $expected = array(
- self::$site_ids['www.w.org/foo/'],
- self::$site_ids['www.w.org/foo/bar/'],
- );
+ public function test_wp_site_query_by_domain_and_offset() {
+ $q = new WP_Site_Query();
+ $found = $q->query(
+ array(
+ 'fields' => 'ids',
+ 'domain' => 'www.w.org',
+ 'offset' => 1,
+ )
+ );
+
+ $expected = array(
+ self::$site_ids['www.w.org/foo/'],
+ self::$site_ids['www.w.org/foo/bar/'],
+ self::$site_ids['www.w.org/make/'],
+ );
+
+ $this->assertSameSets( $expected, $found );
+ }
- $this->assertSameSets( $expected, $found );
- }
+ public function test_wp_site_query_by_domain_and_number_and_offset() {
+ $q = new WP_Site_Query();
+ $found = $q->query(
+ array(
+ 'fields' => 'ids',
+ 'domain' => 'www.w.org',
+ 'number' => 2,
+ 'offset' => 1,
+ )
+ );
+
+ $expected = array(
+ self::$site_ids['www.w.org/foo/'],
+ self::$site_ids['www.w.org/foo/bar/'],
+ );
+
+ $this->assertSameSets( $expected, $found );
+ }
- public function test_wp_site_query_by_domain__in_with_single_domain() {
- $q = new WP_Site_Query();
- $found = $q->query(
- array(
- 'fields' => 'ids',
- 'domain__in' => array( 'make.wordpress.org' ),
- )
- );
+ public function test_wp_site_query_by_domain__in_with_single_domain() {
+ $q = new WP_Site_Query();
+ $found = $q->query(
+ array(
+ 'fields' => 'ids',
+ 'domain__in' => array( 'make.wordpress.org' ),
+ )
+ );
+
+ $expected = array(
+ self::$site_ids['make.wordpress.org/'],
+ self::$site_ids['make.wordpress.org/foo/'],
+ );
+
+ $this->assertSameSets( $expected, $found );
+ }
- $expected = array(
- self::$site_ids['make.wordpress.org/'],
- self::$site_ids['make.wordpress.org/foo/'],
- );
+ public function test_wp_site_query_by_domain__in_with_multiple_domains() {
+ $q = new WP_Site_Query();
+ $found = $q->query(
+ array(
+ 'fields' => 'ids',
+ 'domain__in' => array( 'wordpress.org', 'make.wordpress.org' ),
+ )
+ );
+
+ $expected = array(
+ self::$site_ids['wordpress.org/'],
+ self::$site_ids['wordpress.org/foo/'],
+ self::$site_ids['wordpress.org/foo/bar/'],
+ self::$site_ids['make.wordpress.org/'],
+ self::$site_ids['make.wordpress.org/foo/'],
+ );
+
+ $this->assertSameSets( $expected, $found );
+ }
- $this->assertSameSets( $expected, $found );
- }
+ public function test_wp_site_query_by_domain__not_in_with_single_domain() {
+ $q = new WP_Site_Query();
+ $found = $q->query(
+ array(
+ 'fields' => 'ids',
+ 'domain__not_in' => array( 'www.w.org' ),
+ )
+ );
+
+ $expected = array(
+ get_current_blog_id(), // Account for the initial site added by the test suite.
+ self::$site_ids['wordpress.org/'],
+ self::$site_ids['wordpress.org/foo/'],
+ self::$site_ids['wordpress.org/foo/bar/'],
+ self::$site_ids['make.wordpress.org/'],
+ self::$site_ids['make.wordpress.org/foo/'],
+ );
+
+ $this->assertSameSets( $expected, $found );
+ }
- public function test_wp_site_query_by_domain__in_with_multiple_domains() {
- $q = new WP_Site_Query();
- $found = $q->query(
- array(
- 'fields' => 'ids',
- 'domain__in' => array( 'wordpress.org', 'make.wordpress.org' ),
- )
- );
-
- $expected = array(
- self::$site_ids['wordpress.org/'],
- self::$site_ids['wordpress.org/foo/'],
- self::$site_ids['wordpress.org/foo/bar/'],
- self::$site_ids['make.wordpress.org/'],
- self::$site_ids['make.wordpress.org/foo/'],
- );
+ public function test_wp_site_query_by_domain__not_in_with_multiple_domains() {
+ $q = new WP_Site_Query();
+ $found = $q->query(
+ array(
+ 'fields' => 'ids',
+ 'domain__not_in' => array( 'wordpress.org', 'www.w.org' ),
+ )
+ );
+
+ $expected = array(
+ get_current_blog_id(), // Account for the initial site added by the test suite.
+ self::$site_ids['make.wordpress.org/'],
+ self::$site_ids['make.wordpress.org/foo/'],
+ );
+
+ $this->assertSameSets( $expected, $found );
+ }
- $this->assertSameSets( $expected, $found );
- }
+ public function test_wp_site_query_by_path_with_expected_results() {
+ $q = new WP_Site_Query();
+ $found = $q->query(
+ array(
+ 'fields' => 'ids',
+ 'path' => '/foo/bar/',
+ )
+ );
+
+ $expected = array(
+ self::$site_ids['wordpress.org/foo/bar/'],
+ self::$site_ids['www.w.org/foo/bar/'],
+ );
+
+ $this->assertSameSets( $expected, $found );
+ }
- public function test_wp_site_query_by_domain__not_in_with_single_domain() {
- $q = new WP_Site_Query();
- $found = $q->query(
- array(
- 'fields' => 'ids',
- 'domain__not_in' => array( 'www.w.org' ),
- )
- );
-
- $expected = array(
- get_current_blog_id(), // Account for the initial site added by the test suite.
- self::$site_ids['wordpress.org/'],
- self::$site_ids['wordpress.org/foo/'],
- self::$site_ids['wordpress.org/foo/bar/'],
- self::$site_ids['make.wordpress.org/'],
- self::$site_ids['make.wordpress.org/foo/'],
- );
+ public function test_wp_site_query_by_path_with_no_expected_results() {
+ $q = new WP_Site_Query();
+ $found = $q->query(
+ array(
+ 'fields' => 'ids',
+ 'path' => '/foo/bar/foo/',
+ )
+ );
- $this->assertSameSets( $expected, $found );
- }
+ $this->assertEmpty( $found );
+ }
- public function test_wp_site_query_by_domain__not_in_with_multiple_domains() {
- $q = new WP_Site_Query();
- $found = $q->query(
- array(
- 'fields' => 'ids',
- 'domain__not_in' => array( 'wordpress.org', 'www.w.org' ),
- )
- );
+ // archived, mature, spam, deleted, public.
- $expected = array(
- get_current_blog_id(), // Account for the initial site added by the test suite.
- self::$site_ids['make.wordpress.org/'],
- self::$site_ids['make.wordpress.org/foo/'],
- );
+ public function test_wp_site_query_by_archived() {
+ $q = new WP_Site_Query();
+ $found = $q->query(
+ array(
+ 'fields' => 'ids',
+ // Exclude main site since we don't have control over it here.
+ 'site__not_in' => array( 1 ),
+ 'archived' => '0',
+ )
+ );
- $this->assertSameSets( $expected, $found );
- }
+ $this->assertSameSets( array_values( self::$site_ids ), $found );
+ }
- public function test_wp_site_query_by_path_with_expected_results() {
- $q = new WP_Site_Query();
- $found = $q->query(
- array(
- 'fields' => 'ids',
- 'path' => '/foo/bar/',
- )
- );
+ public function test_wp_site_query_by_mature() {
+ $q = new WP_Site_Query();
+ $found = $q->query(
+ array(
+ 'fields' => 'ids',
+ // Exclude main site since we don't have control over it here.
+ 'site__not_in' => array( 1 ),
+ 'mature' => '0',
+ )
+ );
+
+ $this->assertSameSets( array_values( self::$site_ids ), $found );
+ }
- $expected = array(
- self::$site_ids['wordpress.org/foo/bar/'],
- self::$site_ids['www.w.org/foo/bar/'],
- );
+ public function test_wp_site_query_by_spam() {
+ $q = new WP_Site_Query();
+ $found = $q->query(
+ array(
+ 'fields' => 'ids',
+ // Exclude main site since we don't have control over it here.
+ 'site__not_in' => array( 1 ),
+ 'spam' => '0',
+ )
+ );
+
+ $this->assertSameSets( array_values( self::$site_ids ), $found );
+ }
- $this->assertSameSets( $expected, $found );
- }
+ public function test_wp_site_query_by_deleted() {
+ $q = new WP_Site_Query();
+ $found = $q->query(
+ array(
+ 'fields' => 'ids',
+ // Exclude main site since we don't have control over it here.
+ 'site__not_in' => array( 1 ),
+ 'deleted' => '0',
+ )
+ );
+
+ $this->assertSameSets( array_values( self::$site_ids ), $found );
+ }
- public function test_wp_site_query_by_path_with_no_expected_results() {
- $q = new WP_Site_Query();
- $found = $q->query(
- array(
- 'fields' => 'ids',
- 'path' => '/foo/bar/foo/',
- )
- );
+ public function test_wp_site_query_by_deleted_with_no_results() {
+ $q = new WP_Site_Query();
+ $found = $q->query(
+ array(
+ 'fields' => 'ids',
+ 'deleted' => '1',
+ )
+ );
- $this->assertEmpty( $found );
- }
+ $this->assertEmpty( $found );
+ }
- // archived, mature, spam, deleted, public.
+ public function test_wp_site_query_by_public() {
+ $q = new WP_Site_Query();
+ $found = $q->query(
+ array(
+ 'fields' => 'ids',
+ // Exclude main site since we don't have control over it here.
+ 'site__not_in' => array( 1 ),
+ 'public' => '1',
+ )
+ );
+
+ $this->assertSameSets( array_values( self::$site_ids ), $found );
+ }
- public function test_wp_site_query_by_archived() {
- $q = new WP_Site_Query();
- $found = $q->query(
- array(
- 'fields' => 'ids',
- // Exclude main site since we don't have control over it here.
- 'site__not_in' => array( 1 ),
- 'archived' => '0',
- )
- );
-
- $this->assertSameSets( array_values( self::$site_ids ), $found );
- }
+ public function test_wp_site_query_by_lang_id_with_zero() {
+ $q = new WP_Site_Query();
+ $found = $q->query(
+ array(
+ 'fields' => 'ids',
+ // Exclude main site since we don't have control over it here.
+ 'site__not_in' => array( 1 ),
+ 'lang_id' => 0,
+ )
+ );
+
+ $this->assertSameSets( array_diff( array_values( self::$site_ids ), array( self::$site_ids['www.w.org/make/'] ) ), $found );
+ }
- public function test_wp_site_query_by_mature() {
- $q = new WP_Site_Query();
- $found = $q->query(
- array(
- 'fields' => 'ids',
- // Exclude main site since we don't have control over it here.
- 'site__not_in' => array( 1 ),
- 'mature' => '0',
- )
- );
-
- $this->assertSameSets( array_values( self::$site_ids ), $found );
- }
+ public function test_wp_site_query_by_lang_id() {
+ $q = new WP_Site_Query();
+ $found = $q->query(
+ array(
+ 'fields' => 'ids',
+ 'lang_id' => 1,
+ )
+ );
- public function test_wp_site_query_by_spam() {
- $q = new WP_Site_Query();
- $found = $q->query(
- array(
- 'fields' => 'ids',
- // Exclude main site since we don't have control over it here.
- 'site__not_in' => array( 1 ),
- 'spam' => '0',
- )
- );
-
- $this->assertSameSets( array_values( self::$site_ids ), $found );
- }
+ $expected = array(
+ self::$site_ids['www.w.org/make/'],
+ );
- public function test_wp_site_query_by_deleted() {
- $q = new WP_Site_Query();
- $found = $q->query(
- array(
- 'fields' => 'ids',
- // Exclude main site since we don't have control over it here.
- 'site__not_in' => array( 1 ),
- 'deleted' => '0',
- )
- );
-
- $this->assertSameSets( array_values( self::$site_ids ), $found );
- }
+ $this->assertSameSets( $expected, $found );
+ }
- public function test_wp_site_query_by_deleted_with_no_results() {
- $q = new WP_Site_Query();
- $found = $q->query(
- array(
- 'fields' => 'ids',
- 'deleted' => '1',
- )
- );
+ public function test_wp_site_query_by_lang_id_with_no_results() {
+ $q = new WP_Site_Query();
+ $found = $q->query(
+ array(
+ 'fields' => 'ids',
+ 'lang_id' => 2,
+ )
+ );
- $this->assertEmpty( $found );
- }
+ $this->assertEmpty( $found );
+ }
- public function test_wp_site_query_by_public() {
- $q = new WP_Site_Query();
- $found = $q->query(
- array(
- 'fields' => 'ids',
- // Exclude main site since we don't have control over it here.
- 'site__not_in' => array( 1 ),
- 'public' => '1',
- )
- );
-
- $this->assertSameSets( array_values( self::$site_ids ), $found );
- }
+ public function test_wp_site_query_by_lang__in() {
+ $q = new WP_Site_Query();
+ $found = $q->query(
+ array(
+ 'fields' => 'ids',
+ 'lang__in' => array( 1 ),
+ )
+ );
- public function test_wp_site_query_by_lang_id_with_zero() {
- $q = new WP_Site_Query();
- $found = $q->query(
- array(
- 'fields' => 'ids',
- // Exclude main site since we don't have control over it here.
- 'site__not_in' => array( 1 ),
- 'lang_id' => 0,
- )
- );
-
- $this->assertSameSets( array_diff( array_values( self::$site_ids ), array( self::$site_ids['www.w.org/make/'] ) ), $found );
- }
+ $expected = array(
+ self::$site_ids['www.w.org/make/'],
+ );
- public function test_wp_site_query_by_lang_id() {
- $q = new WP_Site_Query();
- $found = $q->query(
- array(
- 'fields' => 'ids',
- 'lang_id' => 1,
- )
- );
+ $this->assertSameSets( $expected, $found );
+ }
- $expected = array(
- self::$site_ids['www.w.org/make/'],
- );
+ public function test_wp_site_query_by_lang__in_with_multiple_ids() {
+ $q = new WP_Site_Query();
+ $found = $q->query(
+ array(
+ 'fields' => 'ids',
+ // Exclude main site since we don't have control over it here.
+ 'site__not_in' => array( 1 ),
+ 'lang__in' => array( 0, 1 ),
+ )
+ );
+
+ $this->assertSameSets( array_values( self::$site_ids ), $found );
+ }
- $this->assertSameSets( $expected, $found );
- }
+ public function test_wp_site_query_by_lang__not_in() {
+ $q = new WP_Site_Query();
+ $found = $q->query(
+ array(
+ 'fields' => 'ids',
+ 'lang__not_in' => array( 0 ),
+ )
+ );
- public function test_wp_site_query_by_lang_id_with_no_results() {
- $q = new WP_Site_Query();
- $found = $q->query(
- array(
- 'fields' => 'ids',
- 'lang_id' => 2,
- )
- );
+ $expected = array(
+ self::$site_ids['www.w.org/make/'],
+ );
- $this->assertEmpty( $found );
- }
+ $this->assertSameSets( $expected, $found );
+ }
- public function test_wp_site_query_by_lang__in() {
- $q = new WP_Site_Query();
- $found = $q->query(
- array(
- 'fields' => 'ids',
- 'lang__in' => array( 1 ),
- )
- );
+ public function test_wp_site_query_by_lang__not_in_with_multiple_ids() {
+ $q = new WP_Site_Query();
+ $found = $q->query(
+ array(
+ 'fields' => 'ids',
+ 'lang__not_in' => array( 0, 1 ),
+ )
+ );
- $expected = array(
- self::$site_ids['www.w.org/make/'],
- );
+ $this->assertEmpty( $found );
+ }
- $this->assertSameSets( $expected, $found );
- }
+ public function test_wp_site_query_by_search_with_text_in_domain() {
+ $q = new WP_Site_Query();
+ $found = $q->query(
+ array(
+ 'fields' => 'ids',
+ 'search' => 'ke.wordp',
+ )
+ );
+
+ $expected = array(
+ self::$site_ids['make.wordpress.org/'],
+ self::$site_ids['make.wordpress.org/foo/'],
+ );
+
+ $this->assertSameSets( $expected, $found );
+ }
- public function test_wp_site_query_by_lang__in_with_multiple_ids() {
- $q = new WP_Site_Query();
- $found = $q->query(
- array(
- 'fields' => 'ids',
- // Exclude main site since we don't have control over it here.
- 'site__not_in' => array( 1 ),
- 'lang__in' => array( 0, 1 ),
- )
- );
-
- $this->assertSameSets( array_values( self::$site_ids ), $found );
- }
+ public function test_wp_site_query_by_search_with_text_in_path() {
+ $q = new WP_Site_Query();
+ $found = $q->query(
+ array(
+ 'fields' => 'ids',
+ 'search' => 'foo',
+ )
+ );
+
+ $expected = array(
+ self::$site_ids['wordpress.org/foo/'],
+ self::$site_ids['wordpress.org/foo/bar/'],
+ self::$site_ids['make.wordpress.org/foo/'],
+ self::$site_ids['www.w.org/foo/'],
+ self::$site_ids['www.w.org/foo/bar/'],
+ );
+
+ $this->assertSameSets( $expected, $found );
+ }
- public function test_wp_site_query_by_lang__not_in() {
- $q = new WP_Site_Query();
- $found = $q->query(
- array(
- 'fields' => 'ids',
- 'lang__not_in' => array( 0 ),
- )
- );
+ public function test_wp_site_query_by_search_with_text_in_path_and_domain() {
+ $q = new WP_Site_Query();
+ $found = $q->query(
+ array(
+ 'fields' => 'ids',
+ 'search' => 'make',
+ )
+ );
+
+ $expected = array(
+ self::$site_ids['make.wordpress.org/'],
+ self::$site_ids['make.wordpress.org/foo/'],
+ self::$site_ids['www.w.org/make/'],
+ );
+
+ $this->assertSameSets( $expected, $found );
+ }
- $expected = array(
- self::$site_ids['www.w.org/make/'],
- );
+ public function test_wp_site_query_by_search_with_text_in_path_and_domain_order_by_domain_desc() {
+ $q = new WP_Site_Query();
+ $found = $q->query(
+ array(
+ 'fields' => 'ids',
+ 'search' => 'make',
+ 'order' => 'DESC',
+ 'orderby' => 'domain',
+ )
+ );
+
+ $expected = array(
+ self::$site_ids['www.w.org/make/'],
+ self::$site_ids['make.wordpress.org/'],
+ self::$site_ids['make.wordpress.org/foo/'],
+ );
+
+ $this->assertSame( $expected, $found );
+ }
- $this->assertSameSets( $expected, $found );
- }
+ public function test_wp_site_query_by_search_with_text_in_path_exclude_domain_from_search() {
+ $q = new WP_Site_Query();
+ $found = $q->query(
+ array(
+ 'fields' => 'ids',
+ 'search' => 'make',
+ 'search_columns' => array( 'path' ),
+ )
+ );
+
+ $expected = array(
+ self::$site_ids['www.w.org/make/'],
+ );
+
+ $this->assertSame( $expected, $found );
+ }
- public function test_wp_site_query_by_lang__not_in_with_multiple_ids() {
- $q = new WP_Site_Query();
- $found = $q->query(
- array(
- 'fields' => 'ids',
- 'lang__not_in' => array( 0, 1 ),
- )
- );
+ public function test_wp_site_query_by_search_with_text_in_domain_exclude_path_from_search() {
+ $q = new WP_Site_Query();
+ $found = $q->query(
+ array(
+ 'fields' => 'ids',
+ 'search' => 'make',
+ 'search_columns' => array( 'domain' ),
+ )
+ );
+
+ $expected = array(
+ self::$site_ids['make.wordpress.org/'],
+ self::$site_ids['make.wordpress.org/foo/'],
+ );
+
+ $this->assertSame( $expected, $found );
+ }
- $this->assertEmpty( $found );
- }
+ public function test_wp_site_query_by_search_with_wildcard_in_text() {
+ $q = new WP_Site_Query();
+ $found = $q->query(
+ array(
+ 'fields' => 'ids',
+ 'search' => 'm*ke',
+ )
+ );
+
+ $expected = array(
+ self::$site_ids['www.w.org/make/'],
+ self::$site_ids['make.wordpress.org/'],
+ self::$site_ids['make.wordpress.org/foo/'],
+ );
+
+ $this->assertSameSets( $expected, $found );
+ }
- public function test_wp_site_query_by_search_with_text_in_domain() {
- $q = new WP_Site_Query();
- $found = $q->query(
- array(
- 'fields' => 'ids',
- 'search' => 'ke.wordp',
- )
- );
+ public function test_wp_site_query_by_search_with_wildcard_in_text_exclude_path_from_search() {
+ $q = new WP_Site_Query();
+ $found = $q->query(
+ array(
+ 'fields' => 'ids',
+ 'search' => 'm*ke',
+ 'search_columns' => array( 'domain' ),
+ )
+ );
+
+ $expected = array(
+ self::$site_ids['make.wordpress.org/'],
+ self::$site_ids['make.wordpress.org/foo/'],
+ );
+
+ $this->assertSameSets( $expected, $found );
+ }
- $expected = array(
- self::$site_ids['make.wordpress.org/'],
- self::$site_ids['make.wordpress.org/foo/'],
- );
+ public function test_wp_site_query_by_search_with_wildcard_in_text_exclude_domain_from_search() {
+ $q = new WP_Site_Query();
+ $found = $q->query(
+ array(
+ 'fields' => 'ids',
+ 'search' => 'm*ke',
+ 'search_columns' => array( 'path' ),
+ )
+ );
+
+ $expected = array(
+ self::$site_ids['www.w.org/make/'],
+ );
+
+ $this->assertSameSets( $expected, $found );
+ }
- $this->assertSameSets( $expected, $found );
- }
+ /**
+ * @ticket 41197
+ */
+ public function test_wp_site_query_cache_with_different_fields_no_count() {
+ $q = new WP_Site_Query();
+ $query_1 = $q->query(
+ array(
+ 'fields' => 'all',
+ 'network_id' => self::$network_ids['wordpress.org/'],
+ 'number' => 3,
+ 'order' => 'ASC',
+ )
+ );
+ $number_of_queries = get_num_queries();
+
+ $query_2 = $q->query(
+ array(
+ 'fields' => 'ids',
+ 'network_id' => self::$network_ids['wordpress.org/'],
+ 'number' => 3,
+ 'order' => 'ASC',
+ )
+ );
+
+ $this->assertSame( $number_of_queries, get_num_queries() );
+ }
- public function test_wp_site_query_by_search_with_text_in_path() {
- $q = new WP_Site_Query();
- $found = $q->query(
- array(
- 'fields' => 'ids',
- 'search' => 'foo',
- )
- );
-
- $expected = array(
- self::$site_ids['wordpress.org/foo/'],
- self::$site_ids['wordpress.org/foo/bar/'],
- self::$site_ids['make.wordpress.org/foo/'],
- self::$site_ids['www.w.org/foo/'],
- self::$site_ids['www.w.org/foo/bar/'],
- );
+ /**
+ * @ticket 41197
+ */
+ public function test_wp_site_query_cache_with_different_fields_active_count() {
+ $q = new WP_Site_Query();
+
+ $query_1 = $q->query(
+ array(
+ 'fields' => 'all',
+ 'network_id' => self::$network_ids['wordpress.org/'],
+ 'number' => 3,
+ 'order' => 'ASC',
+ 'count' => true,
+ )
+ );
+ $number_of_queries = get_num_queries();
+
+ $query_2 = $q->query(
+ array(
+ 'fields' => 'ids',
+ 'network_id' => self::$network_ids['wordpress.org/'],
+ 'number' => 3,
+ 'order' => 'ASC',
+ 'count' => true,
+ )
+ );
+ $this->assertSame( $number_of_queries, get_num_queries() );
+ }
- $this->assertSameSets( $expected, $found );
- }
+ /**
+ * @ticket 41197
+ */
+ public function test_wp_site_query_cache_with_same_fields_different_count() {
+ $q = new WP_Site_Query();
+
+ $query_1 = $q->query(
+ array(
+ 'fields' => 'ids',
+ 'network_id' => self::$network_ids['wordpress.org/'],
+ 'number' => 3,
+ 'order' => 'ASC',
+ )
+ );
+
+ $number_of_queries = get_num_queries();
+
+ $query_2 = $q->query(
+ array(
+ 'fields' => 'ids',
+ 'network_id' => self::$network_ids['wordpress.org/'],
+ 'number' => 3,
+ 'order' => 'ASC',
+ 'count' => true,
+ )
+ );
+ $this->assertSame( $number_of_queries + 1, get_num_queries() );
+ }
- public function test_wp_site_query_by_search_with_text_in_path_and_domain() {
- $q = new WP_Site_Query();
- $found = $q->query(
- array(
- 'fields' => 'ids',
- 'search' => 'make',
- )
- );
+ /**
+ * @ticket 55462
+ */
+ public function test_wp_site_query_cache_with_same_fields_same_cache_fields() {
+ $q = new WP_Site_Query();
+
+ $query_1 = $q->query(
+ array(
+ 'fields' => 'ids',
+ 'network_id' => self::$network_ids['wordpress.org/'],
+ 'number' => 3,
+ 'order' => 'ASC',
+ 'update_site_cache' => true,
+ 'update_site_meta_cache' => true,
+ )
+ );
+
+ $number_of_queries = get_num_queries();
+
+ $query_2 = $q->query(
+ array(
+ 'fields' => 'ids',
+ 'network_id' => self::$network_ids['wordpress.org/'],
+ 'number' => 3,
+ 'order' => 'ASC',
+ 'update_site_cache' => true,
+ 'update_site_meta_cache' => true,
+ )
+ );
+ $this->assertSame( $number_of_queries, get_num_queries() );
+ }
- $expected = array(
- self::$site_ids['make.wordpress.org/'],
- self::$site_ids['make.wordpress.org/foo/'],
- self::$site_ids['www.w.org/make/'],
- );
+ /**
+ * @ticket 55462
+ */
+ public function test_wp_site_query_cache_with_same_fields_different_cache_fields() {
+ $q = new WP_Site_Query();
+
+ $query_1 = $q->query(
+ array(
+ 'fields' => 'ids',
+ 'network_id' => self::$network_ids['wordpress.org/'],
+ 'number' => 3,
+ 'order' => 'ASC',
+ 'update_site_cache' => true,
+ 'update_site_meta_cache' => true,
+ )
+ );
+
+ $number_of_queries = get_num_queries();
+
+ $query_2 = $q->query(
+ array(
+ 'fields' => 'ids',
+ 'network_id' => self::$network_ids['wordpress.org/'],
+ 'number' => 3,
+ 'order' => 'ASC',
+ 'update_site_cache' => false,
+ 'update_site_meta_cache' => false,
+ )
+ );
+ $this->assertSame( $number_of_queries, get_num_queries() );
+ }
- $this->assertSameSets( $expected, $found );
+ /**
+ * @ticket 40229
+ * @dataProvider data_wp_site_query_meta_query
+ */
+ public function test_wp_site_query_meta_query( $query, $expected, $strict ) {
+ if ( ! is_site_meta_supported() ) {
+ $this->markTestSkipped( 'Test only runs with the blogmeta database table installed.' );
}
- public function test_wp_site_query_by_search_with_text_in_path_and_domain_order_by_domain_desc() {
- $q = new WP_Site_Query();
- $found = $q->query(
- array(
- 'fields' => 'ids',
- 'search' => 'make',
- 'order' => 'DESC',
- 'orderby' => 'domain',
- )
- );
-
- $expected = array(
- self::$site_ids['www.w.org/make/'],
- self::$site_ids['make.wordpress.org/'],
- self::$site_ids['make.wordpress.org/foo/'],
- );
+ add_site_meta( self::$site_ids['wordpress.org/'], 'foo', 'foo' );
+ add_site_meta( self::$site_ids['wordpress.org/foo/'], 'foo', 'bar' );
+ add_site_meta( self::$site_ids['wordpress.org/foo/bar/'], 'foo', 'baz' );
+ add_site_meta( self::$site_ids['make.wordpress.org/'], 'bar', 'baz' );
+ add_site_meta( self::$site_ids['wordpress.org/'], 'numberfoo', 1 );
+ add_site_meta( self::$site_ids['wordpress.org/foo/'], 'numberfoo', 2 );
- $this->assertSame( $expected, $found );
- }
+ $query['fields'] = 'ids';
- public function test_wp_site_query_by_search_with_text_in_path_exclude_domain_from_search() {
- $q = new WP_Site_Query();
- $found = $q->query(
- array(
- 'fields' => 'ids',
- 'search' => 'make',
- 'search_columns' => array( 'path' ),
- )
- );
-
- $expected = array(
- self::$site_ids['www.w.org/make/'],
- );
+ $q = new WP_Site_Query();
+ $found = $q->query( $query );
- $this->assertSame( $expected, $found );
+ foreach ( $expected as $index => $domain_path ) {
+ $expected[ $index ] = self::$site_ids[ $domain_path ];
}
- public function test_wp_site_query_by_search_with_text_in_domain_exclude_path_from_search() {
- $q = new WP_Site_Query();
- $found = $q->query(
- array(
- 'fields' => 'ids',
- 'search' => 'make',
- 'search_columns' => array( 'domain' ),
- )
- );
-
- $expected = array(
- self::$site_ids['make.wordpress.org/'],
- self::$site_ids['make.wordpress.org/foo/'],
- );
-
+ if ( $strict ) {
$this->assertSame( $expected, $found );
- }
-
- public function test_wp_site_query_by_search_with_wildcard_in_text() {
- $q = new WP_Site_Query();
- $found = $q->query(
- array(
- 'fields' => 'ids',
- 'search' => 'm*ke',
- )
- );
-
- $expected = array(
- self::$site_ids['www.w.org/make/'],
- self::$site_ids['make.wordpress.org/'],
- self::$site_ids['make.wordpress.org/foo/'],
- );
-
- $this->assertSameSets( $expected, $found );
- }
-
- public function test_wp_site_query_by_search_with_wildcard_in_text_exclude_path_from_search() {
- $q = new WP_Site_Query();
- $found = $q->query(
- array(
- 'fields' => 'ids',
- 'search' => 'm*ke',
- 'search_columns' => array( 'domain' ),
- )
- );
-
- $expected = array(
- self::$site_ids['make.wordpress.org/'],
- self::$site_ids['make.wordpress.org/foo/'],
- );
-
+ } else {
$this->assertSameSets( $expected, $found );
}
+ }
- public function test_wp_site_query_by_search_with_wildcard_in_text_exclude_domain_from_search() {
- $q = new WP_Site_Query();
- $found = $q->query(
+ public function data_wp_site_query_meta_query() {
+ return array(
+ array(
array(
- 'fields' => 'ids',
- 'search' => 'm*ke',
- 'search_columns' => array( 'path' ),
- )
- );
-
- $expected = array(
- self::$site_ids['www.w.org/make/'],
- );
-
- $this->assertSameSets( $expected, $found );
- }
-
- /**
- * @ticket 41197
- */
- public function test_wp_site_query_cache_with_different_fields_no_count() {
- $q = new WP_Site_Query();
- $query_1 = $q->query(
+ 'meta_key' => 'foo',
+ ),
array(
- 'fields' => 'all',
- 'network_id' => self::$network_ids['wordpress.org/'],
- 'number' => 3,
- 'order' => 'ASC',
- )
- );
- $number_of_queries = get_num_queries();
-
- $query_2 = $q->query(
+ 'wordpress.org/',
+ 'wordpress.org/foo/',
+ 'wordpress.org/foo/bar/',
+ ),
+ false,
+ ),
+ array(
array(
- 'fields' => 'ids',
- 'network_id' => self::$network_ids['wordpress.org/'],
- 'number' => 3,
- 'order' => 'ASC',
- )
- );
-
- $this->assertSame( $number_of_queries, get_num_queries() );
- }
-
- /**
- * @ticket 41197
- */
- public function test_wp_site_query_cache_with_different_fields_active_count() {
- $q = new WP_Site_Query();
-
- $query_1 = $q->query(
+ 'meta_key' => 'foo',
+ 'meta_value' => 'bar',
+ ),
array(
- 'fields' => 'all',
- 'network_id' => self::$network_ids['wordpress.org/'],
- 'number' => 3,
- 'order' => 'ASC',
- 'count' => true,
- )
- );
- $number_of_queries = get_num_queries();
-
- $query_2 = $q->query(
+ 'wordpress.org/foo/',
+ ),
+ false,
+ ),
+ array(
array(
- 'fields' => 'ids',
- 'network_id' => self::$network_ids['wordpress.org/'],
- 'number' => 3,
- 'order' => 'ASC',
- 'count' => true,
- )
- );
- $this->assertSame( $number_of_queries, get_num_queries() );
- }
-
- /**
- * @ticket 41197
- */
- public function test_wp_site_query_cache_with_same_fields_different_count() {
- $q = new WP_Site_Query();
-
- $query_1 = $q->query(
+ 'meta_key' => 'foo',
+ 'meta_value' => array( 'bar', 'baz' ),
+ 'meta_compare' => 'IN',
+ ),
array(
- 'fields' => 'ids',
- 'network_id' => self::$network_ids['wordpress.org/'],
- 'number' => 3,
- 'order' => 'ASC',
- )
- );
-
- $number_of_queries = get_num_queries();
-
- $query_2 = $q->query(
+ 'wordpress.org/foo/',
+ 'wordpress.org/foo/bar/',
+ ),
+ false,
+ ),
+ array(
array(
- 'fields' => 'ids',
- 'network_id' => self::$network_ids['wordpress.org/'],
- 'number' => 3,
- 'order' => 'ASC',
- 'count' => true,
- )
- );
- $this->assertSame( $number_of_queries + 1, get_num_queries() );
- }
-
- /**
- * @ticket 55462
- */
- public function test_wp_site_query_cache_with_same_fields_same_cache_fields() {
- $q = new WP_Site_Query();
-
- $query_1 = $q->query(
+ 'meta_query' => array(
+ array(
+ 'key' => 'foo',
+ 'value' => 'bar',
+ ),
+ array(
+ 'key' => 'numberfoo',
+ 'value' => 2,
+ 'type' => 'NUMERIC',
+ ),
+ ),
+ ),
array(
- 'fields' => 'ids',
- 'network_id' => self::$network_ids['wordpress.org/'],
- 'number' => 3,
- 'order' => 'ASC',
- 'update_site_cache' => true,
- 'update_site_meta_cache' => true,
- )
- );
-
- $number_of_queries = get_num_queries();
-
- $query_2 = $q->query(
+ 'wordpress.org/foo/',
+ ),
+ false,
+ ),
+ array(
array(
- 'fields' => 'ids',
- 'network_id' => self::$network_ids['wordpress.org/'],
- 'number' => 3,
- 'order' => 'ASC',
- 'update_site_cache' => true,
- 'update_site_meta_cache' => true,
- )
- );
- $this->assertSame( $number_of_queries, get_num_queries() );
- }
-
- /**
- * @ticket 55462
- */
- public function test_wp_site_query_cache_with_same_fields_different_cache_fields() {
- $q = new WP_Site_Query();
-
- $query_1 = $q->query(
+ 'meta_key' => 'foo',
+ 'orderby' => 'meta_value',
+ 'order' => 'ASC',
+ ),
array(
- 'fields' => 'ids',
- 'network_id' => self::$network_ids['wordpress.org/'],
- 'number' => 3,
- 'order' => 'ASC',
- 'update_site_cache' => true,
- 'update_site_meta_cache' => true,
- )
- );
-
- $number_of_queries = get_num_queries();
-
- $query_2 = $q->query(
+ 'wordpress.org/foo/',
+ 'wordpress.org/foo/bar/',
+ 'wordpress.org/',
+ ),
+ true,
+ ),
+ array(
array(
- 'fields' => 'ids',
- 'network_id' => self::$network_ids['wordpress.org/'],
- 'number' => 3,
- 'order' => 'ASC',
- 'update_site_cache' => false,
- 'update_site_meta_cache' => false,
- )
- );
- $this->assertSame( $number_of_queries, get_num_queries() );
- }
-
- /**
- * @ticket 40229
- * @dataProvider data_wp_site_query_meta_query
- */
- public function test_wp_site_query_meta_query( $query, $expected, $strict ) {
- if ( ! is_site_meta_supported() ) {
- $this->markTestSkipped( 'Test only runs with the blogmeta database table installed.' );
- }
-
- add_site_meta( self::$site_ids['wordpress.org/'], 'foo', 'foo' );
- add_site_meta( self::$site_ids['wordpress.org/foo/'], 'foo', 'bar' );
- add_site_meta( self::$site_ids['wordpress.org/foo/bar/'], 'foo', 'baz' );
- add_site_meta( self::$site_ids['make.wordpress.org/'], 'bar', 'baz' );
- add_site_meta( self::$site_ids['wordpress.org/'], 'numberfoo', 1 );
- add_site_meta( self::$site_ids['wordpress.org/foo/'], 'numberfoo', 2 );
-
- $query['fields'] = 'ids';
-
- $q = new WP_Site_Query();
- $found = $q->query( $query );
-
- foreach ( $expected as $index => $domain_path ) {
- $expected[ $index ] = self::$site_ids[ $domain_path ];
- }
-
- if ( $strict ) {
- $this->assertSame( $expected, $found );
- } else {
- $this->assertSameSets( $expected, $found );
- }
- }
-
- public function data_wp_site_query_meta_query() {
- return array(
+ 'meta_key' => 'foo',
+ 'orderby' => 'foo',
+ 'order' => 'ASC',
+ ),
array(
- array(
- 'meta_key' => 'foo',
- ),
- array(
- 'wordpress.org/',
- 'wordpress.org/foo/',
- 'wordpress.org/foo/bar/',
- ),
- false,
+ 'wordpress.org/foo/',
+ 'wordpress.org/foo/bar/',
+ 'wordpress.org/',
),
+ true,
+ ),
+ array(
array(
- array(
- 'meta_key' => 'foo',
- 'meta_value' => 'bar',
- ),
- array(
- 'wordpress.org/foo/',
- ),
- false,
+ 'meta_key' => 'numberfoo',
+ 'orderby' => 'meta_value_num',
+ 'order' => 'DESC',
),
array(
- array(
- 'meta_key' => 'foo',
- 'meta_value' => array( 'bar', 'baz' ),
- 'meta_compare' => 'IN',
- ),
- array(
- 'wordpress.org/foo/',
- 'wordpress.org/foo/bar/',
- ),
- false,
+ 'wordpress.org/foo/',
+ 'wordpress.org/',
),
+ true,
+ ),
+ array(
array(
- array(
- 'meta_query' => array(
- array(
- 'key' => 'foo',
- 'value' => 'bar',
- ),
- array(
- 'key' => 'numberfoo',
- 'value' => 2,
- 'type' => 'NUMERIC',
- ),
+ 'meta_query' => array(
+ array(
+ 'key' => 'foo',
+ 'value' => array( 'foo', 'bar' ),
+ 'compare' => 'IN',
+ ),
+ array(
+ 'key' => 'numberfoo',
),
),
- array(
- 'wordpress.org/foo/',
- ),
- false,
+ 'orderby' => array( 'meta_value' => 'ASC' ),
),
array(
- array(
- 'meta_key' => 'foo',
- 'orderby' => 'meta_value',
- 'order' => 'ASC',
- ),
- array(
- 'wordpress.org/foo/',
- 'wordpress.org/foo/bar/',
- 'wordpress.org/',
- ),
- true,
+ 'wordpress.org/foo/',
+ 'wordpress.org/',
),
+ true,
+ ),
+ array(
array(
- array(
- 'meta_key' => 'foo',
- 'orderby' => 'foo',
- 'order' => 'ASC',
- ),
- array(
- 'wordpress.org/foo/',
- 'wordpress.org/foo/bar/',
- 'wordpress.org/',
+ 'meta_query' => array(
+ array(
+ 'key' => 'foo',
+ 'value' => array( 'foo', 'bar' ),
+ 'compare' => 'IN',
+ ),
+ array(
+ 'key' => 'numberfoo',
+ ),
),
- true,
+ 'orderby' => array( 'foo' => 'ASC' ),
),
array(
- array(
- 'meta_key' => 'numberfoo',
- 'orderby' => 'meta_value_num',
- 'order' => 'DESC',
- ),
- array(
- 'wordpress.org/foo/',
- 'wordpress.org/',
- ),
- true,
+ 'wordpress.org/foo/',
+ 'wordpress.org/',
),
+ true,
+ ),
+ array(
array(
- array(
- 'meta_query' => array(
- array(
- 'key' => 'foo',
- 'value' => array( 'foo', 'bar' ),
- 'compare' => 'IN',
- ),
- array(
- 'key' => 'numberfoo',
- ),
+ 'meta_query' => array(
+ array(
+ 'key' => 'foo',
+ 'value' => array( 'foo', 'bar' ),
+ 'compare' => 'IN',
),
- 'orderby' => array( 'meta_value' => 'ASC' ),
- ),
- array(
- 'wordpress.org/foo/',
- 'wordpress.org/',
- ),
- true,
- ),
- array(
- array(
- 'meta_query' => array(
- array(
- 'key' => 'foo',
- 'value' => array( 'foo', 'bar' ),
- 'compare' => 'IN',
- ),
- array(
- 'key' => 'numberfoo',
- ),
+ 'my_subquery' => array(
+ 'key' => 'numberfoo',
),
- 'orderby' => array( 'foo' => 'ASC' ),
- ),
- array(
- 'wordpress.org/foo/',
- 'wordpress.org/',
),
- true,
+ 'orderby' => array( 'my_subquery' => 'DESC' ),
),
array(
- array(
- 'meta_query' => array(
- array(
- 'key' => 'foo',
- 'value' => array( 'foo', 'bar' ),
- 'compare' => 'IN',
- ),
- 'my_subquery' => array(
- 'key' => 'numberfoo',
- ),
- ),
- 'orderby' => array( 'my_subquery' => 'DESC' ),
- ),
- array(
- 'wordpress.org/foo/',
- 'wordpress.org/',
- ),
- true,
+ 'wordpress.org/foo/',
+ 'wordpress.org/',
),
- );
- }
-
- /**
- * @ticket 45749
- * @ticket 47599
- */
- public function test_sites_pre_query_filter_should_bypass_database_query() {
- add_filter( 'sites_pre_query', array( __CLASS__, 'filter_sites_pre_query' ), 10, 2 );
-
- $num_queries = get_num_queries();
+ true,
+ ),
+ );
+ }
- $q = new WP_Site_Query();
- $results = $q->query( array() );
+ /**
+ * @ticket 45749
+ * @ticket 47599
+ */
+ public function test_sites_pre_query_filter_should_bypass_database_query() {
+ add_filter( 'sites_pre_query', array( __CLASS__, 'filter_sites_pre_query' ), 10, 2 );
- remove_filter( 'sites_pre_query', array( __CLASS__, 'filter_sites_pre_query' ), 10, 2 );
+ $num_queries = get_num_queries();
- // Make sure no queries were executed.
- $this->assertSame( $num_queries, get_num_queries() );
+ $q = new WP_Site_Query();
+ $results = $q->query( array() );
- // We manually inserted a non-existing site and overrode the results with it.
- $this->assertSame( array( 555 ), $results );
+ remove_filter( 'sites_pre_query', array( __CLASS__, 'filter_sites_pre_query' ), 10, 2 );
- // Make sure manually setting found_sites doesn't get overwritten.
- $this->assertSame( 1, $q->found_sites );
- }
+ // Make sure no queries were executed.
+ $this->assertSame( $num_queries, get_num_queries() );
- public static function filter_sites_pre_query( $sites, $query ) {
- $query->found_sites = 1;
+ // We manually inserted a non-existing site and overrode the results with it.
+ $this->assertSame( array( 555 ), $results );
- return array( 555 );
- }
+ // Make sure manually setting found_sites doesn't get overwritten.
+ $this->assertSame( 1, $q->found_sites );
+ }
- /**
- * @ticket 51333
- */
- public function test_sites_pre_query_filter_should_set_sites_property() {
- add_filter( 'sites_pre_query', array( __CLASS__, 'filter_sites_pre_query_and_set_sites' ), 10, 2 );
+ public static function filter_sites_pre_query( $sites, $query ) {
+ $query->found_sites = 1;
- $q = new WP_Site_Query();
- $results = $q->query( array() );
+ return array( 555 );
+ }
- remove_filter( 'sites_pre_query', array( __CLASS__, 'filter_sites_pre_query_and_set_sites' ), 10 );
+ /**
+ * @ticket 51333
+ */
+ public function test_sites_pre_query_filter_should_set_sites_property() {
+ add_filter( 'sites_pre_query', array( __CLASS__, 'filter_sites_pre_query_and_set_sites' ), 10, 2 );
- // Make sure the sites property is the same as the results.
- $this->assertSame( $results, $q->sites );
+ $q = new WP_Site_Query();
+ $results = $q->query( array() );
- // Make sure the site domain is `wordpress.org`.
- $this->assertSame( 'wordpress.org', $q->sites[0]->domain );
- }
+ remove_filter( 'sites_pre_query', array( __CLASS__, 'filter_sites_pre_query_and_set_sites' ), 10 );
- public static function filter_sites_pre_query_and_set_sites( $sites, $query ) {
- return array( get_site( self::$site_ids['wordpress.org/'] ) );
- }
+ // Make sure the sites property is the same as the results.
+ $this->assertSame( $results, $q->sites );
- /**
- * @ticket 56841
- */
- public function test_wp_site_query_does_not_have_leading_whitespace() {
- $q = new WP_Site_Query();
+ // Make sure the site domain is `wordpress.org`.
+ $this->assertSame( 'wordpress.org', $q->sites[0]->domain );
+ }
- $q->query(
- array(
- 'fields' => 'ids',
- 'network_id' => self::$network_ids['wordpress.org/'],
- 'number' => 3,
- 'order' => 'ASC',
- 'update_site_cache' => true,
- 'update_site_meta_cache' => true,
- )
- );
-
- $this->assertSame( ltrim( $q->request ), $q->request, 'The query has leading whitespace' );
- }
+ public static function filter_sites_pre_query_and_set_sites( $sites, $query ) {
+ return array( get_site( self::$site_ids['wordpress.org/'] ) );
}
-endif;
+ /**
+ * @ticket 56841
+ */
+ public function test_wp_site_query_does_not_have_leading_whitespace() {
+ $q = new WP_Site_Query();
+
+ $q->query(
+ array(
+ 'fields' => 'ids',
+ 'network_id' => self::$network_ids['wordpress.org/'],
+ 'number' => 3,
+ 'order' => 'ASC',
+ 'update_site_cache' => true,
+ 'update_site_meta_cache' => true,
+ )
+ );
+
+ $this->assertSame( ltrim( $q->request ), $q->request, 'The query has leading whitespace' );
+ }
+}
diff --git a/tests/phpunit/tests/multisite/wpmuLogNewRegistrations.php b/tests/phpunit/tests/multisite/wpmuLogNewRegistrations.php
index 069aab14f5..56a0915b93 100644
--- a/tests/phpunit/tests/multisite/wpmuLogNewRegistrations.php
+++ b/tests/phpunit/tests/multisite/wpmuLogNewRegistrations.php
@@ -1,24 +1,21 @@
<?php
-if ( is_multisite() ) :
+/**
+ * @group ms-required
+ * @group multisite
+ */
+class Tests_Multisite_wpmuLogNewRegistrations extends WP_UnitTestCase {
- /**
- * @group multisite
- */
- class Tests_Multisite_wpmuLogNewRegistrations extends WP_UnitTestCase {
+ public function test_wpmu_log_new_registrations() {
+ global $wpdb;
- public function test_wpmu_log_new_registrations() {
- global $wpdb;
+ $user = new WP_User( 1 );
+ $ip = preg_replace( '/[^0-9., ]/', '', $_SERVER['REMOTE_ADDR'] );
- $user = new WP_User( 1 );
- $ip = preg_replace( '/[^0-9., ]/', '', $_SERVER['REMOTE_ADDR'] );
+ wpmu_log_new_registrations( 1, 1 );
- wpmu_log_new_registrations( 1, 1 );
-
- // Currently there is no wrapper function for the registration_log.
- $reg_blog = $wpdb->get_col( $wpdb->prepare( "SELECT email FROM {$wpdb->registration_log} WHERE {$wpdb->registration_log}.blog_id = 1 AND IP LIKE %s", $ip ) );
- $this->assertSame( $user->user_email, $reg_blog[ count( $reg_blog ) - 1 ] );
- }
+ // Currently there is no wrapper function for the registration_log.
+ $reg_blog = $wpdb->get_col( $wpdb->prepare( "SELECT email FROM {$wpdb->registration_log} WHERE {$wpdb->registration_log}.blog_id = 1 AND IP LIKE %s", $ip ) );
+ $this->assertSame( $user->user_email, $reg_blog[ count( $reg_blog ) - 1 ] );
}
-
-endif;
+}
diff --git a/tests/phpunit/tests/multisite/wpmuValidateBlogSignup.php b/tests/phpunit/tests/multisite/wpmuValidateBlogSignup.php
index fc5c5fe445..47b1676dcf 100644
--- a/tests/phpunit/tests/multisite/wpmuValidateBlogSignup.php
+++ b/tests/phpunit/tests/multisite/wpmuValidateBlogSignup.php
@@ -1,161 +1,159 @@
<?php
-if ( is_multisite() ) :
+/**
+ * @group ms-required
+ * @group multisite
+ */
+class Tests_Multisite_wpmuValidateBlogSignup extends WP_UnitTestCase {
- /**
- * @group multisite
- */
- class Tests_Multisite_wpmuValidateBlogSignup extends WP_UnitTestCase {
- protected static $super_admin_id;
-
- protected static $existing_user_login = 'existinguserfoo';
- protected static $existing_user_id;
+ protected static $super_admin_id;
- protected static $existing_blog_name = 'existingsitefoo';
- protected static $existing_blog_id;
+ protected static $existing_user_login = 'existinguserfoo';
+ protected static $existing_user_id;
- protected $minimum_site_name_length = 4;
+ protected static $existing_blog_name = 'existingsitefoo';
+ protected static $existing_blog_id;
- public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
- self::$super_admin_id = $factory->user->create();
- grant_super_admin( self::$super_admin_id );
+ protected $minimum_site_name_length = 4;
- self::$existing_user_id = $factory->user->create( array( 'user_login' => self::$existing_user_login ) );
+ public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
+ self::$super_admin_id = $factory->user->create();
+ grant_super_admin( self::$super_admin_id );
- $network = get_network();
+ self::$existing_user_id = $factory->user->create( array( 'user_login' => self::$existing_user_login ) );
- if ( is_subdomain_install() ) {
- $domain = self::$existing_blog_name . '.' . preg_replace( '|^www\.|', '', $network->domain );
- $path = $network->path;
- } else {
- $domain = $network->domain;
- $path = $network->path . self::$existing_blog_name . '/';
- }
+ $network = get_network();
- self::$existing_blog_id = $factory->blog->create(
- array(
- 'domain' => $domain,
- 'path' => $path,
- 'network_id' => $network->id,
- )
- );
+ if ( is_subdomain_install() ) {
+ $domain = self::$existing_blog_name . '.' . preg_replace( '|^www\.|', '', $network->domain );
+ $path = $network->path;
+ } else {
+ $domain = $network->domain;
+ $path = $network->path . self::$existing_blog_name . '/';
}
- public static function wpTearDownAfterClass() {
- revoke_super_admin( self::$super_admin_id );
- wpmu_delete_user( self::$super_admin_id );
+ self::$existing_blog_id = $factory->blog->create(
+ array(
+ 'domain' => $domain,
+ 'path' => $path,
+ 'network_id' => $network->id,
+ )
+ );
+ }
- wpmu_delete_user( self::$existing_user_id );
+ public static function wpTearDownAfterClass() {
+ revoke_super_admin( self::$super_admin_id );
+ wpmu_delete_user( self::$super_admin_id );
- wp_delete_site( self::$existing_blog_id );
- }
+ wpmu_delete_user( self::$existing_user_id );
- /**
- * @dataProvider data_validate_blogname
- */
- public function test_validate_blogname( $blog_name, $error_message ) {
- $result = wpmu_validate_blog_signup( $blog_name, 'Foo Site Title', get_userdata( self::$super_admin_id ) );
- $this->assertContains( 'blogname', $result['errors']->get_error_codes(), $error_message );
- }
+ wp_delete_site( self::$existing_blog_id );
+ }
- public function data_validate_blogname() {
- $data = array(
- array( '', 'Site names must not be empty.' ),
- array( 'foo-hello', 'Site names must not contain hyphens.' ),
- array( 'foo_hello', 'Site names must not contain underscores.' ),
- array( 'foo hello', 'Site names must not contain spaces.' ),
- array( 'FooHello', 'Site names must not contain uppercase letters.' ),
- array( '12345678', 'Site names must not consist of numbers only.' ),
- array( self::$existing_blog_name, 'Site names must not collide with an existing site name.' ),
- array( self::$existing_user_login, 'Site names must not collide with an existing user login.' ),
- array( 'foo', 'Site names must at least contain 4 characters.' ),
- );
-
- $illegal_names = get_site_option( 'illegal_names' );
- if ( ! empty( $illegal_names ) ) {
- $data[] = array( array_shift( $illegal_names ), 'Illegal site names are not allowed.' );
- } else {
- $data[] = array( 'www', 'Illegal site names are not allowed.' );
- }
-
- return $data;
- }
+ /**
+ * @dataProvider data_validate_blogname
+ */
+ public function test_validate_blogname( $blog_name, $error_message ) {
+ $result = wpmu_validate_blog_signup( $blog_name, 'Foo Site Title', get_userdata( self::$super_admin_id ) );
+ $this->assertContains( 'blogname', $result['errors']->get_error_codes(), $error_message );
+ }
- public function test_validate_empty_blog_title() {
- $result = wpmu_validate_blog_signup( 'uniqueblogname1234', '', get_userdata( self::$super_admin_id ) );
- $this->assertContains( 'blog_title', $result['errors']->get_error_codes(), 'Site titles must not be empty.' );
+ public function data_validate_blogname() {
+ $data = array(
+ array( '', 'Site names must not be empty.' ),
+ array( 'foo-hello', 'Site names must not contain hyphens.' ),
+ array( 'foo_hello', 'Site names must not contain underscores.' ),
+ array( 'foo hello', 'Site names must not contain spaces.' ),
+ array( 'FooHello', 'Site names must not contain uppercase letters.' ),
+ array( '12345678', 'Site names must not consist of numbers only.' ),
+ array( self::$existing_blog_name, 'Site names must not collide with an existing site name.' ),
+ array( self::$existing_user_login, 'Site names must not collide with an existing user login.' ),
+ array( 'foo', 'Site names must at least contain 4 characters.' ),
+ );
+
+ $illegal_names = get_site_option( 'illegal_names' );
+ if ( ! empty( $illegal_names ) ) {
+ $data[] = array( array_shift( $illegal_names ), 'Illegal site names are not allowed.' );
+ } else {
+ $data[] = array( 'www', 'Illegal site names are not allowed.' );
}
- public function test_validate_blogname_from_same_existing_user() {
- $result = wpmu_validate_blog_signup( self::$existing_user_login, 'Foo Site Title', get_userdata( self::$existing_user_id ) );
- $this->assertEmpty( $result['errors']->get_error_codes() );
- }
+ return $data;
+ }
- /**
- * @ticket 39676
- *
- * @dataProvider data_filter_minimum_site_name_length
- */
- public function test_filter_minimum_site_name_length( $site_name, $minimum_length, $expect_error ) {
- $this->minimum_site_name_length = $minimum_length;
- add_filter( 'minimum_site_name_length', array( $this, 'filter_minimum_site_name_length' ) );
-
- $result = wpmu_validate_blog_signup( $site_name, 'Site Title', get_userdata( self::$super_admin_id ) );
-
- remove_filter( 'minimum_site_name_length', array( $this, 'filter_minimum_site_name_length' ) );
- $this->minimum_site_name_length = 4;
-
- if ( $expect_error ) {
- $this->assertContains( 'blogname', $result['errors']->get_error_codes() );
- } else {
- $this->assertEmpty( $result['errors']->get_error_codes() );
- }
- }
+ public function test_validate_empty_blog_title() {
+ $result = wpmu_validate_blog_signup( 'uniqueblogname1234', '', get_userdata( self::$super_admin_id ) );
+ $this->assertContains( 'blog_title', $result['errors']->get_error_codes(), 'Site titles must not be empty.' );
+ }
- public function data_filter_minimum_site_name_length() {
- return array(
- array( 'fooo', 5, true ),
- array( 'foooo', 5, false ),
- array( 'foo', 4, true ),
- array( 'fooo', 4, false ),
- array( 'fo', 3, true ),
- array( 'foo', 3, false ),
- );
- }
+ public function test_validate_blogname_from_same_existing_user() {
+ $result = wpmu_validate_blog_signup( self::$existing_user_login, 'Foo Site Title', get_userdata( self::$existing_user_id ) );
+ $this->assertEmpty( $result['errors']->get_error_codes() );
+ }
- public function filter_minimum_site_name_length() {
- return $this->minimum_site_name_length;
- }
+ /**
+ * @ticket 39676
+ *
+ * @dataProvider data_filter_minimum_site_name_length
+ */
+ public function test_filter_minimum_site_name_length( $site_name, $minimum_length, $expect_error ) {
+ $this->minimum_site_name_length = $minimum_length;
+ add_filter( 'minimum_site_name_length', array( $this, 'filter_minimum_site_name_length' ) );
- /**
- * @ticket 43667
- */
- public function test_signup_nonce_check() {
- $original_php_self = $_SERVER['PHP_SELF'];
- $_SERVER['PHP_SELF'] = '/wp-signup.php';
- $_POST['signup_form_id'] = 'blog-signup-form';
- $_POST['_signup_form'] = wp_create_nonce( 'signup_form_' . $_POST['signup_form_id'] );
+ $result = wpmu_validate_blog_signup( $site_name, 'Site Title', get_userdata( self::$super_admin_id ) );
- $valid = wpmu_validate_blog_signup( 'my-nonce-site', 'Site Title', get_userdata( self::$super_admin_id ) );
- $_SERVER['PHP_SELF'] = $original_php_self;
+ remove_filter( 'minimum_site_name_length', array( $this, 'filter_minimum_site_name_length' ) );
+ $this->minimum_site_name_length = 4;
- $this->assertNotContains( 'invalid_nonce', $valid['errors']->get_error_codes() );
+ if ( $expect_error ) {
+ $this->assertContains( 'blogname', $result['errors']->get_error_codes() );
+ } else {
+ $this->assertEmpty( $result['errors']->get_error_codes() );
}
+ }
- /**
- * @ticket 43667
- */
- public function test_signup_nonce_check_invalid() {
- $original_php_self = $_SERVER['PHP_SELF'];
- $_SERVER['PHP_SELF'] = '/wp-signup.php';
- $_POST['signup_form_id'] = 'blog-signup-form';
- $_POST['_signup_form'] = wp_create_nonce( 'invalid' );
+ public function data_filter_minimum_site_name_length() {
+ return array(
+ array( 'fooo', 5, true ),
+ array( 'foooo', 5, false ),
+ array( 'foo', 4, true ),
+ array( 'fooo', 4, false ),
+ array( 'fo', 3, true ),
+ array( 'foo', 3, false ),
+ );
+ }
- $valid = wpmu_validate_blog_signup( 'my-nonce-site', 'Site Title', get_userdata( self::$super_admin_id ) );
- $_SERVER['PHP_SELF'] = $original_php_self;
+ public function filter_minimum_site_name_length() {
+ return $this->minimum_site_name_length;
+ }
- $this->assertContains( 'invalid_nonce', $valid['errors']->get_error_codes() );
- }
+ /**
+ * @ticket 43667
+ */
+ public function test_signup_nonce_check() {
+ $original_php_self = $_SERVER['PHP_SELF'];
+ $_SERVER['PHP_SELF'] = '/wp-signup.php';
+ $_POST['signup_form_id'] = 'blog-signup-form';
+ $_POST['_signup_form'] = wp_create_nonce( 'signup_form_' . $_POST['signup_form_id'] );
+
+ $valid = wpmu_validate_blog_signup( 'my-nonce-site', 'Site Title', get_userdata( self::$super_admin_id ) );
+ $_SERVER['PHP_SELF'] = $original_php_self;
+
+ $this->assertNotContains( 'invalid_nonce', $valid['errors']->get_error_codes() );
}
-endif;
+ /**
+ * @ticket 43667
+ */
+ public function test_signup_nonce_check_invalid() {
+ $original_php_self = $_SERVER['PHP_SELF'];
+ $_SERVER['PHP_SELF'] = '/wp-signup.php';
+ $_POST['signup_form_id'] = 'blog-signup-form';
+ $_POST['_signup_form'] = wp_create_nonce( 'invalid' );
+
+ $valid = wpmu_validate_blog_signup( 'my-nonce-site', 'Site Title', get_userdata( self::$super_admin_id ) );
+ $_SERVER['PHP_SELF'] = $original_php_self;
+
+ $this->assertContains( 'invalid_nonce', $valid['errors']->get_error_codes() );
+ }
+}
diff --git a/tests/phpunit/tests/multisite/wpmuValidateUserSignup.php b/tests/phpunit/tests/multisite/wpmuValidateUserSignup.php
index a3409a54a8..377e6f9118 100644
--- a/tests/phpunit/tests/multisite/wpmuValidateUserSignup.php
+++ b/tests/phpunit/tests/multisite/wpmuValidateUserSignup.php
@@ -1,273 +1,271 @@
<?php
-if ( is_multisite() ) :
+/**
+ * @group ms-required
+ * @group multisite
+ */
+class Tests_Multisite_wpmuValidateUserSignup extends WP_UnitTestCase {
/**
- * @group multisite
+ * @dataProvider data_user_name
*/
- class Tests_Multisite_wpmuValidateUserSignup extends WP_UnitTestCase {
- /**
- * @dataProvider data_user_name
- */
- public function test_user_name( $user_name, $error_message ) {
- $v = wpmu_validate_user_signup( $user_name, 'foo@example.com' );
- $this->assertContains( 'user_name', $v['errors']->get_error_codes(), $error_message );
- }
-
- public function data_user_name() {
- return array(
- array( 'contains spaces', 'User names with spaces are not allowed.' ),
- array( 'ContainsCaps', 'User names with capital letters are not allowed.' ),
- array( 'contains_underscores', 'User names with underscores are not allowed.' ),
- array( 'contains%^*()junk', 'User names with non-alphanumeric characters are not allowed.' ),
- array( '', 'Empty user names are not allowed.' ),
- array( 'foo', 'User names of 3 characters are not allowed.' ),
- array( 'fo', 'User names of 2 characters are not allowed.' ),
- array( 'f', 'User names of 1 characters are not allowed.' ),
- array( 'f', 'User names of 1 characters are not allowed.' ),
- array( '12345', 'User names consisting only of numbers are not allowed.' ),
- array( 'thisusernamecontainsenoughcharacterstobelongerthan60characters', 'User names longer than 60 characters are not allowed.' ),
- );
- }
+ public function test_user_name( $user_name, $error_message ) {
+ $v = wpmu_validate_user_signup( $user_name, 'foo@example.com' );
+ $this->assertContains( 'user_name', $v['errors']->get_error_codes(), $error_message );
+ }
- public function test_should_fail_for_illegal_names() {
- $illegal = array( 'foo123', 'bar123' );
- update_site_option( 'illegal_names', $illegal );
+ public function data_user_name() {
+ return array(
+ array( 'contains spaces', 'User names with spaces are not allowed.' ),
+ array( 'ContainsCaps', 'User names with capital letters are not allowed.' ),
+ array( 'contains_underscores', 'User names with underscores are not allowed.' ),
+ array( 'contains%^*()junk', 'User names with non-alphanumeric characters are not allowed.' ),
+ array( '', 'Empty user names are not allowed.' ),
+ array( 'foo', 'User names of 3 characters are not allowed.' ),
+ array( 'fo', 'User names of 2 characters are not allowed.' ),
+ array( 'f', 'User names of 1 characters are not allowed.' ),
+ array( 'f', 'User names of 1 characters are not allowed.' ),
+ array( '12345', 'User names consisting only of numbers are not allowed.' ),
+ array( 'thisusernamecontainsenoughcharacterstobelongerthan60characters', 'User names longer than 60 characters are not allowed.' ),
+ );
+ }
- foreach ( $illegal as $i ) {
- $v = wpmu_validate_user_signup( $i, 'foo@example.com' );
- $this->assertContains( 'user_name', $v['errors']->get_error_codes() );
- }
- }
+ public function test_should_fail_for_illegal_names() {
+ $illegal = array( 'foo123', 'bar123' );
+ update_site_option( 'illegal_names', $illegal );
- public function test_should_fail_for_unsafe_email_address() {
- add_filter( 'is_email_address_unsafe', '__return_true' );
- $v = wpmu_validate_user_signup( 'foo123', 'foo@example.com' );
- $this->assertContains( 'user_email', $v['errors']->get_error_codes() );
- remove_filter( 'is_email_address_unsafe', '__return_true' );
+ foreach ( $illegal as $i ) {
+ $v = wpmu_validate_user_signup( $i, 'foo@example.com' );
+ $this->assertContains( 'user_name', $v['errors']->get_error_codes() );
}
+ }
- public function test_should_fail_for_invalid_email_address() {
- add_filter( 'is_email', '__return_false' );
- $v = wpmu_validate_user_signup( 'foo123', 'foo@example.com' );
- $this->assertContains( 'user_email', $v['errors']->get_error_codes() );
- remove_filter( 'is_email', '__return_false' );
- }
+ public function test_should_fail_for_unsafe_email_address() {
+ add_filter( 'is_email_address_unsafe', '__return_true' );
+ $v = wpmu_validate_user_signup( 'foo123', 'foo@example.com' );
+ $this->assertContains( 'user_email', $v['errors']->get_error_codes() );
+ remove_filter( 'is_email_address_unsafe', '__return_true' );
+ }
- public function test_should_fail_for_emails_from_disallowed_domains() {
- $domains = array( 'foo.com', 'bar.org' );
- update_site_option( 'limited_email_domains', $domains );
+ public function test_should_fail_for_invalid_email_address() {
+ add_filter( 'is_email', '__return_false' );
+ $v = wpmu_validate_user_signup( 'foo123', 'foo@example.com' );
+ $this->assertContains( 'user_email', $v['errors']->get_error_codes() );
+ remove_filter( 'is_email', '__return_false' );
+ }
- $v = wpmu_validate_user_signup( 'foo123', 'foo@example.com' );
- $this->assertContains( 'user_email', $v['errors']->get_error_codes() );
- }
+ public function test_should_fail_for_emails_from_disallowed_domains() {
+ $domains = array( 'foo.com', 'bar.org' );
+ update_site_option( 'limited_email_domains', $domains );
- public function test_should_not_fail_for_emails_from_allowed_domains_with_mixed_case() {
- $domains = array( 'foo.com', 'bar.org' );
- update_site_option( 'limited_email_domains', $domains );
+ $v = wpmu_validate_user_signup( 'foo123', 'foo@example.com' );
+ $this->assertContains( 'user_email', $v['errors']->get_error_codes() );
+ }
- $v = wpmu_validate_user_signup( 'foo123', 'foo@BAR.org' );
- $this->assertNotContains( 'user_email', $v['errors']->get_error_codes() );
- }
+ public function test_should_not_fail_for_emails_from_allowed_domains_with_mixed_case() {
+ $domains = array( 'foo.com', 'bar.org' );
+ update_site_option( 'limited_email_domains', $domains );
- public function test_should_fail_for_existing_user_name() {
- $u = self::factory()->user->create( array( 'user_login' => 'foo123' ) );
- $v = wpmu_validate_user_signup( 'foo123', 'foo@example.com' );
- $this->assertContains( 'user_name', $v['errors']->get_error_codes() );
- }
+ $v = wpmu_validate_user_signup( 'foo123', 'foo@BAR.org' );
+ $this->assertNotContains( 'user_email', $v['errors']->get_error_codes() );
+ }
- public function test_should_fail_for_existing_user_email() {
- $u = self::factory()->user->create( array( 'user_email' => 'foo@example.com' ) );
- $v = wpmu_validate_user_signup( 'foo123', 'foo@example.com' );
- $this->assertContains( 'user_email', $v['errors']->get_error_codes() );
- }
+ public function test_should_fail_for_existing_user_name() {
+ $u = self::factory()->user->create( array( 'user_login' => 'foo123' ) );
+ $v = wpmu_validate_user_signup( 'foo123', 'foo@example.com' );
+ $this->assertContains( 'user_name', $v['errors']->get_error_codes() );
+ }
- public function test_should_fail_for_existing_signup_with_same_username() {
- // Don't send notifications.
- add_filter( 'wpmu_signup_user_notification', '__return_false' );
- wpmu_signup_user( 'foo123', 'foo@example.com' );
- remove_filter( 'wpmu_signup_user_notification', '__return_false' );
+ public function test_should_fail_for_existing_user_email() {
+ $u = self::factory()->user->create( array( 'user_email' => 'foo@example.com' ) );
+ $v = wpmu_validate_user_signup( 'foo123', 'foo@example.com' );
+ $this->assertContains( 'user_email', $v['errors']->get_error_codes() );
+ }
- $v = wpmu_validate_user_signup( 'foo123', 'foo2@example.com' );
- $this->assertContains( 'user_name', $v['errors']->get_error_codes() );
- }
+ public function test_should_fail_for_existing_signup_with_same_username() {
+ // Don't send notifications.
+ add_filter( 'wpmu_signup_user_notification', '__return_false' );
+ wpmu_signup_user( 'foo123', 'foo@example.com' );
+ remove_filter( 'wpmu_signup_user_notification', '__return_false' );
- public function test_should_not_fail_for_existing_signup_with_same_username_if_signup_is_old() {
- // Don't send notifications.
- add_filter( 'wpmu_signup_user_notification', '__return_false' );
- wpmu_signup_user( 'foo123', 'foo@example.com' );
- remove_filter( 'wpmu_signup_user_notification', '__return_false' );
+ $v = wpmu_validate_user_signup( 'foo123', 'foo2@example.com' );
+ $this->assertContains( 'user_name', $v['errors']->get_error_codes() );
+ }
- global $wpdb;
- $date = gmdate( 'Y-m-d H:i:s', time() - ( 2 * DAY_IN_SECONDS ) - 60 );
- $wpdb->update( $wpdb->signups, array( 'registered' => $date ), array( 'user_login' => 'foo123' ) );
+ public function test_should_not_fail_for_existing_signup_with_same_username_if_signup_is_old() {
+ // Don't send notifications.
+ add_filter( 'wpmu_signup_user_notification', '__return_false' );
+ wpmu_signup_user( 'foo123', 'foo@example.com' );
+ remove_filter( 'wpmu_signup_user_notification', '__return_false' );
- $v = wpmu_validate_user_signup( 'foo123', 'foo2@example.com' );
- $this->assertNotContains( 'user_name', $v['errors']->get_error_codes() );
- }
+ global $wpdb;
+ $date = gmdate( 'Y-m-d H:i:s', time() - ( 2 * DAY_IN_SECONDS ) - 60 );
+ $wpdb->update( $wpdb->signups, array( 'registered' => $date ), array( 'user_login' => 'foo123' ) );
- public function test_should_fail_for_existing_signup_with_same_email() {
- // Don't send notifications.
- add_filter( 'wpmu_signup_user_notification', '__return_false' );
- wpmu_signup_user( 'foo123', 'foo@example.com' );
- remove_filter( 'wpmu_signup_user_notification', '__return_false' );
+ $v = wpmu_validate_user_signup( 'foo123', 'foo2@example.com' );
+ $this->assertNotContains( 'user_name', $v['errors']->get_error_codes() );
+ }
- $v = wpmu_validate_user_signup( 'foo2', 'foo@example.com' );
- $this->assertContains( 'user_email', $v['errors']->get_error_codes() );
- }
+ public function test_should_fail_for_existing_signup_with_same_email() {
+ // Don't send notifications.
+ add_filter( 'wpmu_signup_user_notification', '__return_false' );
+ wpmu_signup_user( 'foo123', 'foo@example.com' );
+ remove_filter( 'wpmu_signup_user_notification', '__return_false' );
- public function test_should_not_fail_for_existing_signup_with_same_email_if_signup_is_old() {
- // Don't send notifications.
- add_filter( 'wpmu_signup_user_notification', '__return_false' );
- wpmu_signup_user( 'foo123', 'foo@example.com' );
- remove_filter( 'wpmu_signup_user_notification', '__return_false' );
+ $v = wpmu_validate_user_signup( 'foo2', 'foo@example.com' );
+ $this->assertContains( 'user_email', $v['errors']->get_error_codes() );
+ }
- global $wpdb;
- $date = gmdate( 'Y-m-d H:i:s', time() - ( 2 * DAY_IN_SECONDS ) - 60 );
- $wpdb->update( $wpdb->signups, array( 'registered' => $date ), array( 'user_login' => 'foo123' ) );
+ public function test_should_not_fail_for_existing_signup_with_same_email_if_signup_is_old() {
+ // Don't send notifications.
+ add_filter( 'wpmu_signup_user_notification', '__return_false' );
+ wpmu_signup_user( 'foo123', 'foo@example.com' );
+ remove_filter( 'wpmu_signup_user_notification', '__return_false' );
- $v = wpmu_validate_user_signup( 'foo2', 'foo2@example.com' );
- $this->assertNotContains( 'user_email', $v['errors']->get_error_codes() );
- }
+ global $wpdb;
+ $date = gmdate( 'Y-m-d H:i:s', time() - ( 2 * DAY_IN_SECONDS ) - 60 );
+ $wpdb->update( $wpdb->signups, array( 'registered' => $date ), array( 'user_login' => 'foo123' ) );
- /**
- * @ticket 43232
- */
- public function test_should_not_fail_for_data_used_by_a_deleted_user() {
- global $wpdb;
+ $v = wpmu_validate_user_signup( 'foo2', 'foo2@example.com' );
+ $this->assertNotContains( 'user_email', $v['errors']->get_error_codes() );
+ }
- // Don't send notifications.
- add_filter( 'wpmu_signup_user_notification', '__return_false' );
- add_filter( 'wpmu_welcome_user_notification', '__return_false' );
+ /**
+ * @ticket 43232
+ */
+ public function test_should_not_fail_for_data_used_by_a_deleted_user() {
+ global $wpdb;
- // Signup, activate and delete new user.
- wpmu_signup_user( 'foo123', 'foo@example.com' );
- $key = $wpdb->get_var( "SELECT activation_key FROM $wpdb->signups WHERE user_login = 'foo123'" );
- $user = wpmu_activate_signup( $key );
- wpmu_delete_user( $user['user_id'] );
+ // Don't send notifications.
+ add_filter( 'wpmu_signup_user_notification', '__return_false' );
+ add_filter( 'wpmu_welcome_user_notification', '__return_false' );
- $valid = wpmu_validate_user_signup( 'foo123', 'foo2@example.com' );
+ // Signup, activate and delete new user.
+ wpmu_signup_user( 'foo123', 'foo@example.com' );
+ $key = $wpdb->get_var( "SELECT activation_key FROM $wpdb->signups WHERE user_login = 'foo123'" );
+ $user = wpmu_activate_signup( $key );
+ wpmu_delete_user( $user['user_id'] );
- remove_filter( 'wpmu_signup_user_notification', '__return_false' );
- remove_filter( 'wpmu_signup_user_notification', '__return_false' );
+ $valid = wpmu_validate_user_signup( 'foo123', 'foo2@example.com' );
- $this->assertNotContains( 'user_name', $valid['errors']->get_error_codes() );
- $this->assertNotContains( 'user_email', $valid['errors']->get_error_codes() );
- }
+ remove_filter( 'wpmu_signup_user_notification', '__return_false' );
+ remove_filter( 'wpmu_signup_user_notification', '__return_false' );
- public function test_invalid_email_address_with_no_banned_domains_results_in_error() {
- $valid = wpmu_validate_user_signup( 'validusername', 'invalid-email' );
+ $this->assertNotContains( 'user_name', $valid['errors']->get_error_codes() );
+ $this->assertNotContains( 'user_email', $valid['errors']->get_error_codes() );
+ }
- $this->assertContains( 'user_email', $valid['errors']->get_error_codes() );
- }
+ public function test_invalid_email_address_with_no_banned_domains_results_in_error() {
+ $valid = wpmu_validate_user_signup( 'validusername', 'invalid-email' );
- public function test_invalid_email_address_with_banned_domains_results_in_error() {
- update_site_option( 'banned_email_domains', 'bar.com' );
- $valid = wpmu_validate_user_signup( 'validusername', 'invalid-email' );
- delete_site_option( 'banned_email_domains' );
+ $this->assertContains( 'user_email', $valid['errors']->get_error_codes() );
+ }
- $this->assertContains( 'user_email', $valid['errors']->get_error_codes() );
- }
+ public function test_invalid_email_address_with_banned_domains_results_in_error() {
+ update_site_option( 'banned_email_domains', 'bar.com' );
+ $valid = wpmu_validate_user_signup( 'validusername', 'invalid-email' );
+ delete_site_option( 'banned_email_domains' );
- public function test_incomplete_email_address_with_no_banned_domains_results_in_error() {
- $valid = wpmu_validate_user_signup( 'validusername', 'incomplete@email' );
+ $this->assertContains( 'user_email', $valid['errors']->get_error_codes() );
+ }
- $this->assertContains( 'user_email', $valid['errors']->get_error_codes() );
- }
+ public function test_incomplete_email_address_with_no_banned_domains_results_in_error() {
+ $valid = wpmu_validate_user_signup( 'validusername', 'incomplete@email' );
- public function test_valid_email_address_matching_banned_domain_results_in_error() {
- update_site_option( 'banned_email_domains', 'bar.com' );
- $valid = wpmu_validate_user_signup( 'validusername', 'email@bar.com' );
- delete_site_option( 'banned_email_domains' );
+ $this->assertContains( 'user_email', $valid['errors']->get_error_codes() );
+ }
- $this->assertContains( 'user_email', $valid['errors']->get_error_codes() );
- }
+ public function test_valid_email_address_matching_banned_domain_results_in_error() {
+ update_site_option( 'banned_email_domains', 'bar.com' );
+ $valid = wpmu_validate_user_signup( 'validusername', 'email@bar.com' );
+ delete_site_option( 'banned_email_domains' );
- public function test_valid_email_address_not_matching_banned_domain_returns_in_success() {
- update_site_option( 'banned_email_domains', 'bar.com' );
- $valid = wpmu_validate_user_signup( 'validusername', 'email@example.com' );
- delete_site_option( 'banned_email_domains' );
+ $this->assertContains( 'user_email', $valid['errors']->get_error_codes() );
+ }
- $this->assertNotContains( 'user_email', $valid['errors']->get_error_codes() );
- }
+ public function test_valid_email_address_not_matching_banned_domain_returns_in_success() {
+ update_site_option( 'banned_email_domains', 'bar.com' );
+ $valid = wpmu_validate_user_signup( 'validusername', 'email@example.com' );
+ delete_site_option( 'banned_email_domains' );
- /**
- * @ticket 43667
- */
- public function test_signup_nonce_check() {
- $original_php_self = $_SERVER['PHP_SELF'];
- $_SERVER['PHP_SELF'] = '/wp-signup.php';
- $_POST['signup_form_id'] = 'user-signup-form';
- $_POST['_signup_form'] = wp_create_nonce( 'signup_form_' . $_POST['signup_form_id'] );
+ $this->assertNotContains( 'user_email', $valid['errors']->get_error_codes() );
+ }
- $valid = wpmu_validate_user_signup( 'validusername', 'email@example.com' );
- $_SERVER['PHP_SELF'] = $original_php_self;
+ /**
+ * @ticket 43667
+ */
+ public function test_signup_nonce_check() {
+ $original_php_self = $_SERVER['PHP_SELF'];
+ $_SERVER['PHP_SELF'] = '/wp-signup.php';
+ $_POST['signup_form_id'] = 'user-signup-form';
+ $_POST['_signup_form'] = wp_create_nonce( 'signup_form_' . $_POST['signup_form_id'] );
- $this->assertNotContains( 'invalid_nonce', $valid['errors']->get_error_codes() );
- }
+ $valid = wpmu_validate_user_signup( 'validusername', 'email@example.com' );
+ $_SERVER['PHP_SELF'] = $original_php_self;
- /**
- * @ticket 43667
- */
- public function test_signup_nonce_check_invalid() {
- $original_php_self = $_SERVER['PHP_SELF'];
- $_SERVER['PHP_SELF'] = '/wp-signup.php';
- $_POST['signup_form_id'] = 'user-signup-form';
- $_POST['_signup_form'] = wp_create_nonce( 'invalid' );
+ $this->assertNotContains( 'invalid_nonce', $valid['errors']->get_error_codes() );
+ }
- $valid = wpmu_validate_user_signup( 'validusername', 'email@example.com' );
- $_SERVER['PHP_SELF'] = $original_php_self;
+ /**
+ * @ticket 43667
+ */
+ public function test_signup_nonce_check_invalid() {
+ $original_php_self = $_SERVER['PHP_SELF'];
+ $_SERVER['PHP_SELF'] = '/wp-signup.php';
+ $_POST['signup_form_id'] = 'user-signup-form';
+ $_POST['_signup_form'] = wp_create_nonce( 'invalid' );
- $this->assertContains( 'invalid_nonce', $valid['errors']->get_error_codes() );
- }
+ $valid = wpmu_validate_user_signup( 'validusername', 'email@example.com' );
+ $_SERVER['PHP_SELF'] = $original_php_self;
- /**
- * Ensure that wp_ensure_editable_role does not throw an exception when the role is editable.
- *
- * @ticket 43251
- *
- * @covers ::wp_ensure_editable_role
- */
- public function test_wp_ensure_editable_role_allows_editable_roles() {
- $role = get_role( 'editor' );
- $this->assertInstanceOf( 'WP_Role', $role, 'The editor role should exist.' );
- $this->assertNull( wp_ensure_editable_role( 'editor' ), 'The editor role should be editable.' );
- }
+ $this->assertContains( 'invalid_nonce', $valid['errors']->get_error_codes() );
+ }
- /**
- * Ensure that wp_ensure_editable_role throws an exception for non-existent roles.
- *
- * @ticket 43251
- *
- * @covers ::wp_ensure_editable_role
- */
- public function test_wp_ensure_editable_role_does_not_allow_non_existent_role() {
- $this->expectException( 'WPDieException' );
- $role = get_role( 'non-existent-role' );
- $this->assertNotInstanceOf( 'WP_Role', $role, 'The non-existent-role role should not exist.' );
- wp_ensure_editable_role( 'non-existent-role' );
- }
+ /**
+ * Ensure that wp_ensure_editable_role does not throw an exception when the role is editable.
+ *
+ * @ticket 43251
+ *
+ * @covers ::wp_ensure_editable_role
+ */
+ public function test_wp_ensure_editable_role_allows_editable_roles() {
+ $role = get_role( 'editor' );
+ $this->assertInstanceOf( 'WP_Role', $role, 'The editor role should exist.' );
+ $this->assertNull( wp_ensure_editable_role( 'editor' ), 'The editor role should be editable.' );
+ }
- /**
- * Ensure that wp_ensure_editable_role throws an exception for roles that are not editable.
- *
- * @ticket 43251
- *
- * @covers ::wp_ensure_editable_role
- */
- public function test_wp_ensure_editable_role_does_not_allow_uneditable_roles() {
- add_filter(
- 'editable_roles',
- function ( $roles ) {
- unset( $roles['editor'] );
- return $roles;
- }
- );
- $this->expectException( 'WPDieException' );
- $role = get_role( 'editor' );
- $this->assertInstanceOf( 'WP_Role', $role, 'The editor role should exist.' );
- wp_ensure_editable_role( 'editor' );
- }
+ /**
+ * Ensure that wp_ensure_editable_role throws an exception for non-existent roles.
+ *
+ * @ticket 43251
+ *
+ * @covers ::wp_ensure_editable_role
+ */
+ public function test_wp_ensure_editable_role_does_not_allow_non_existent_role() {
+ $this->expectException( 'WPDieException' );
+ $role = get_role( 'non-existent-role' );
+ $this->assertNotInstanceOf( 'WP_Role', $role, 'The non-existent-role role should not exist.' );
+ wp_ensure_editable_role( 'non-existent-role' );
}
-endif;
+ /**
+ * Ensure that wp_ensure_editable_role throws an exception for roles that are not editable.
+ *
+ * @ticket 43251
+ *
+ * @covers ::wp_ensure_editable_role
+ */
+ public function test_wp_ensure_editable_role_does_not_allow_uneditable_roles() {
+ add_filter(
+ 'editable_roles',
+ function ( $roles ) {
+ unset( $roles['editor'] );
+ return $roles;
+ }
+ );
+ $this->expectException( 'WPDieException' );
+ $role = get_role( 'editor' );
+ $this->assertInstanceOf( 'WP_Role', $role, 'The editor role should exist.' );
+ wp_ensure_editable_role( 'editor' );
+ }
+}
diff --git a/tests/phpunit/tests/option/multisite.php b/tests/phpunit/tests/option/multisite.php
index 98c28fbf50..3cec77f167 100644
--- a/tests/phpunit/tests/option/multisite.php
+++ b/tests/phpunit/tests/option/multisite.php
@@ -1,259 +1,256 @@
<?php
-if ( is_multisite() ) :
+/**
+ * Tests specific to network and site options in Multisite.
+ *
+ * @group option
+ * @group ms-option
+ * @group ms-required
+ * @group multisite
+ */
+class Tests_Option_Multisite extends WP_UnitTestCase {
+
+ /**
+ * @covers ::get_blog_option
+ * @covers ::get_option
+ * @covers ::add_blog_option
+ * @covers ::update_blog_option
+ * @covers ::delete_blog_option
+ */
+ public function test_from_same_site() {
+ $key = __FUNCTION__ . '_1';
+ $key2 = __FUNCTION__ . '_2';
+ $value = __FUNCTION__ . '_val1';
+ $value2 = __FUNCTION__ . '_val2';
+
+ $this->assertFalse( get_blog_option( 1, 'doesnotexist' ) );
+ $this->assertFalse( get_option( 'doesnotexist' ) ); // Check get_option().
+
+ $this->assertTrue( add_blog_option( 1, $key, $value ) );
+ // Assert all values of $blog_id that means the current or main blog (the same here).
+ $this->assertSame( $value, get_blog_option( 1, $key ) );
+ $this->assertSame( $value, get_blog_option( null, $key ) );
+ $this->assertSame( $value, get_blog_option( '1', $key ) );
+ $this->assertSame( $value, get_option( $key ) ); // Check get_option().
+
+ $this->assertFalse( add_blog_option( 1, $key, $value ) ); // Already exists.
+ $this->assertFalse( update_blog_option( 1, $key, $value ) ); // Value is the same.
+ $this->assertTrue( update_blog_option( 1, $key, $value2 ) );
+ $this->assertSame( $value2, get_blog_option( 1, $key ) );
+ $this->assertSame( $value2, get_option( $key ) ); // Check get_option().
+ $this->assertFalse( add_blog_option( 1, $key, $value ) );
+ $this->assertSame( $value2, get_blog_option( 1, $key ) );
+ $this->assertSame( $value2, get_option( $key ) ); // Check get_option().
+
+ $this->assertTrue( delete_blog_option( 1, $key ) );
+ $this->assertFalse( get_blog_option( 1, $key ) );
+ $this->assertFalse( get_option( $key ) ); // Check get_option().
+ $this->assertFalse( delete_blog_option( 1, $key ) );
+ $this->assertTrue( update_blog_option( 1, $key2, $value2 ) );
+ $this->assertSame( $value2, get_blog_option( 1, $key2 ) );
+ $this->assertSame( $value2, get_option( $key2 ) ); // Check get_option().
+ $this->assertTrue( delete_blog_option( 1, $key2 ) );
+ $this->assertFalse( get_blog_option( 1, $key2 ) );
+ $this->assertFalse( get_option( $key2 ) ); // Check get_option().
+ }
+
+ /**
+ * @covers ::get_blog_option
+ * @covers ::get_option
+ * @covers ::add_blog_option
+ * @covers ::update_blog_option
+ * @covers ::delete_blog_option
+ */
+ public function test_from_same_site_with_null_blog_id() {
+ $key = __FUNCTION__ . '_1';
+ $key2 = __FUNCTION__ . '_2';
+ $value = __FUNCTION__ . '_val1';
+ $value2 = __FUNCTION__ . '_val2';
+
+ $this->assertFalse( get_blog_option( null, 'doesnotexist' ) );
+ $this->assertFalse( get_option( 'doesnotexist' ) ); // Check get_option().
+
+ $this->assertTrue( add_blog_option( null, $key, $value ) );
+ // Assert all values of $blog_id that means the current or main blog (the same here).
+ $this->assertSame( $value, get_blog_option( null, $key ) );
+ $this->assertSame( $value, get_blog_option( null, $key ) );
+ $this->assertSame( $value, get_option( $key ) ); // Check get_option().
+
+ $this->assertFalse( add_blog_option( null, $key, $value ) ); // Already exists.
+ $this->assertFalse( update_blog_option( null, $key, $value ) ); // Value is the same.
+ $this->assertTrue( update_blog_option( null, $key, $value2 ) );
+ $this->assertSame( $value2, get_blog_option( null, $key ) );
+ $this->assertSame( $value2, get_option( $key ) ); // Check get_option().
+ $this->assertFalse( add_blog_option( null, $key, $value ) );
+ $this->assertSame( $value2, get_blog_option( null, $key ) );
+ $this->assertSame( $value2, get_option( $key ) ); // Check get_option().
+
+ $this->assertTrue( delete_blog_option( null, $key ) );
+ $this->assertFalse( get_blog_option( null, $key ) );
+ $this->assertFalse( get_option( $key ) ); // Check get_option().
+ $this->assertFalse( delete_blog_option( null, $key ) );
+ $this->assertTrue( update_blog_option( null, $key2, $value2 ) );
+ $this->assertSame( $value2, get_blog_option( null, $key2 ) );
+ $this->assertSame( $value2, get_option( $key2 ) ); // Check get_option().
+ $this->assertTrue( delete_blog_option( null, $key2 ) );
+ $this->assertFalse( get_blog_option( null, $key2 ) );
+ $this->assertFalse( get_option( $key2 ) ); // Check get_option().
+ }
+
+ /**
+ * @covers ::get_blog_option
+ * @covers ::get_option
+ * @covers ::add_blog_option
+ * @covers ::update_blog_option
+ * @covers ::delete_blog_option
+ */
+ public function test_with_another_site() {
+ $user_id = self::factory()->user->create();
+ $this->assertIsInt( $user_id );
+
+ $blog_id = self::factory()->blog->create(
+ array(
+ 'user_id' => $user_id,
+ 'public' => 1,
+ )
+ );
+ $this->assertIsInt( $blog_id );
+
+ $key = __FUNCTION__ . '_key1';
+ $key2 = __FUNCTION__ . '_key2';
+ $value = __FUNCTION__ . '_val1';
+ $value2 = __FUNCTION__ . '_val2';
+
+ $this->assertFalse( get_blog_option( $blog_id, 'doesnotexist' ) );
+ // $this->assertFalse( get_option( 'doesnotexist' ) ); // Check get_option().
+
+ $this->assertTrue( add_blog_option( $blog_id, $key, $value ) );
+ // Assert all values of $blog_id that means the current or main blog (the same here).
+ $this->assertSame( $value, get_blog_option( $blog_id, $key ) );
+ $this->assertSame( $value, get_blog_option( (string) $blog_id, $key ) );
+ // $this->assertSame( $value, get_option( $key ) ); // Check get_option().
+
+ $this->assertFalse( add_blog_option( $blog_id, $key, $value ) ); // Already exists.
+ $this->assertFalse( update_blog_option( $blog_id, $key, $value ) ); // Value is the same.
+ $this->assertTrue( update_blog_option( $blog_id, $key, $value2 ) );
+ $this->assertSame( $value2, get_blog_option( $blog_id, $key ) );
+ // $this->assertSame( $value2, get_option( $key ) ); // Check get_option().
+ $this->assertFalse( add_blog_option( $blog_id, $key, $value ) );
+ $this->assertSame( $value2, get_blog_option( $blog_id, $key ) );
+ // $this->assertSame( $value2, get_option( $key ) ); // Check get_option().
+
+ $this->assertTrue( delete_blog_option( $blog_id, $key ) );
+ $this->assertFalse( get_blog_option( $blog_id, $key ) );
+ // $this->assertFalse( get_option( $key ) ); // Check get_option().
+ $this->assertFalse( delete_blog_option( $blog_id, $key ) );
+ $this->assertTrue( update_blog_option( $blog_id, $key2, $value2 ) );
+ $this->assertSame( $value2, get_blog_option( $blog_id, $key2 ) );
+ // $this->assertSame( $value2, get_option( $key2 ) ); // Check get_option().
+ $this->assertTrue( delete_blog_option( $blog_id, $key2 ) );
+ $this->assertFalse( get_blog_option( $blog_id, $key2 ) );
+ // $this->assertFalse( get_option( $key2 ) ); // Check get_option().
+ }
/**
- * Tests specific to network and site options in Multisite.
- *
- * @group option
- * @group ms-option
* @group multisite
+ *
+ * @covers ::get_site_option
*/
- class Tests_Option_Multisite extends WP_UnitTestCase {
-
- /**
- * @covers ::get_blog_option
- * @covers ::get_option
- * @covers ::add_blog_option
- * @covers ::update_blog_option
- * @covers ::delete_blog_option
- */
- public function test_from_same_site() {
- $key = __FUNCTION__ . '_1';
- $key2 = __FUNCTION__ . '_2';
- $value = __FUNCTION__ . '_val1';
- $value2 = __FUNCTION__ . '_val2';
-
- $this->assertFalse( get_blog_option( 1, 'doesnotexist' ) );
- $this->assertFalse( get_option( 'doesnotexist' ) ); // Check get_option().
-
- $this->assertTrue( add_blog_option( 1, $key, $value ) );
- // Assert all values of $blog_id that means the current or main blog (the same here).
- $this->assertSame( $value, get_blog_option( 1, $key ) );
- $this->assertSame( $value, get_blog_option( null, $key ) );
- $this->assertSame( $value, get_blog_option( '1', $key ) );
- $this->assertSame( $value, get_option( $key ) ); // Check get_option().
-
- $this->assertFalse( add_blog_option( 1, $key, $value ) ); // Already exists.
- $this->assertFalse( update_blog_option( 1, $key, $value ) ); // Value is the same.
- $this->assertTrue( update_blog_option( 1, $key, $value2 ) );
- $this->assertSame( $value2, get_blog_option( 1, $key ) );
- $this->assertSame( $value2, get_option( $key ) ); // Check get_option().
- $this->assertFalse( add_blog_option( 1, $key, $value ) );
- $this->assertSame( $value2, get_blog_option( 1, $key ) );
- $this->assertSame( $value2, get_option( $key ) ); // Check get_option().
-
- $this->assertTrue( delete_blog_option( 1, $key ) );
- $this->assertFalse( get_blog_option( 1, $key ) );
- $this->assertFalse( get_option( $key ) ); // Check get_option().
- $this->assertFalse( delete_blog_option( 1, $key ) );
- $this->assertTrue( update_blog_option( 1, $key2, $value2 ) );
- $this->assertSame( $value2, get_blog_option( 1, $key2 ) );
- $this->assertSame( $value2, get_option( $key2 ) ); // Check get_option().
- $this->assertTrue( delete_blog_option( 1, $key2 ) );
- $this->assertFalse( get_blog_option( 1, $key2 ) );
- $this->assertFalse( get_option( $key2 ) ); // Check get_option().
- }
-
- /**
- * @covers ::get_blog_option
- * @covers ::get_option
- * @covers ::add_blog_option
- * @covers ::update_blog_option
- * @covers ::delete_blog_option
- */
- public function test_from_same_site_with_null_blog_id() {
- $key = __FUNCTION__ . '_1';
- $key2 = __FUNCTION__ . '_2';
- $value = __FUNCTION__ . '_val1';
- $value2 = __FUNCTION__ . '_val2';
-
- $this->assertFalse( get_blog_option( null, 'doesnotexist' ) );
- $this->assertFalse( get_option( 'doesnotexist' ) ); // Check get_option().
-
- $this->assertTrue( add_blog_option( null, $key, $value ) );
- // Assert all values of $blog_id that means the current or main blog (the same here).
- $this->assertSame( $value, get_blog_option( null, $key ) );
- $this->assertSame( $value, get_blog_option( null, $key ) );
- $this->assertSame( $value, get_option( $key ) ); // Check get_option().
-
- $this->assertFalse( add_blog_option( null, $key, $value ) ); // Already exists.
- $this->assertFalse( update_blog_option( null, $key, $value ) ); // Value is the same.
- $this->assertTrue( update_blog_option( null, $key, $value2 ) );
- $this->assertSame( $value2, get_blog_option( null, $key ) );
- $this->assertSame( $value2, get_option( $key ) ); // Check get_option().
- $this->assertFalse( add_blog_option( null, $key, $value ) );
- $this->assertSame( $value2, get_blog_option( null, $key ) );
- $this->assertSame( $value2, get_option( $key ) ); // Check get_option().
-
- $this->assertTrue( delete_blog_option( null, $key ) );
- $this->assertFalse( get_blog_option( null, $key ) );
- $this->assertFalse( get_option( $key ) ); // Check get_option().
- $this->assertFalse( delete_blog_option( null, $key ) );
- $this->assertTrue( update_blog_option( null, $key2, $value2 ) );
- $this->assertSame( $value2, get_blog_option( null, $key2 ) );
- $this->assertSame( $value2, get_option( $key2 ) ); // Check get_option().
- $this->assertTrue( delete_blog_option( null, $key2 ) );
- $this->assertFalse( get_blog_option( null, $key2 ) );
- $this->assertFalse( get_option( $key2 ) ); // Check get_option().
- }
-
- /**
- * @covers ::get_blog_option
- * @covers ::get_option
- * @covers ::add_blog_option
- * @covers ::update_blog_option
- * @covers ::delete_blog_option
- */
- public function test_with_another_site() {
- $user_id = self::factory()->user->create();
- $this->assertIsInt( $user_id );
-
- $blog_id = self::factory()->blog->create(
- array(
- 'user_id' => $user_id,
- 'public' => 1,
- )
- );
- $this->assertIsInt( $blog_id );
-
- $key = __FUNCTION__ . '_key1';
- $key2 = __FUNCTION__ . '_key2';
- $value = __FUNCTION__ . '_val1';
- $value2 = __FUNCTION__ . '_val2';
-
- $this->assertFalse( get_blog_option( $blog_id, 'doesnotexist' ) );
- // $this->assertFalse( get_option( 'doesnotexist' ) ); // Check get_option().
-
- $this->assertTrue( add_blog_option( $blog_id, $key, $value ) );
- // Assert all values of $blog_id that means the current or main blog (the same here).
- $this->assertSame( $value, get_blog_option( $blog_id, $key ) );
- $this->assertSame( $value, get_blog_option( (string) $blog_id, $key ) );
- // $this->assertSame( $value, get_option( $key ) ); // Check get_option().
-
- $this->assertFalse( add_blog_option( $blog_id, $key, $value ) ); // Already exists.
- $this->assertFalse( update_blog_option( $blog_id, $key, $value ) ); // Value is the same.
- $this->assertTrue( update_blog_option( $blog_id, $key, $value2 ) );
- $this->assertSame( $value2, get_blog_option( $blog_id, $key ) );
- // $this->assertSame( $value2, get_option( $key ) ); // Check get_option().
- $this->assertFalse( add_blog_option( $blog_id, $key, $value ) );
- $this->assertSame( $value2, get_blog_option( $blog_id, $key ) );
- // $this->assertSame( $value2, get_option( $key ) ); // Check get_option().
-
- $this->assertTrue( delete_blog_option( $blog_id, $key ) );
- $this->assertFalse( get_blog_option( $blog_id, $key ) );
- // $this->assertFalse( get_option( $key ) ); // Check get_option().
- $this->assertFalse( delete_blog_option( $blog_id, $key ) );
- $this->assertTrue( update_blog_option( $blog_id, $key2, $value2 ) );
- $this->assertSame( $value2, get_blog_option( $blog_id, $key2 ) );
- // $this->assertSame( $value2, get_option( $key2 ) ); // Check get_option().
- $this->assertTrue( delete_blog_option( $blog_id, $key2 ) );
- $this->assertFalse( get_blog_option( $blog_id, $key2 ) );
- // $this->assertFalse( get_option( $key2 ) ); // Check get_option().
- }
-
- /**
- * @group multisite
- *
- * @covers ::get_site_option
- */
- public function test_site_notoptions() {
- $network_id = get_current_network_id();
- $notoptions_key = "{$network_id}:notoptions";
-
- $_notoptions = wp_cache_get( 'notoptions', 'site-options' );
- $this->assertEmpty( $_notoptions );
- $_notoptions1 = wp_cache_get( $notoptions_key, 'site-options' );
- $this->assertEmpty( $_notoptions1 );
-
- get_site_option( 'burrito' );
-
- $notoptions = wp_cache_get( 'notoptions', 'site-options' );
- $this->assertEmpty( $notoptions );
- $notoptions1 = wp_cache_get( $notoptions_key, 'site-options' );
- $this->assertNotEmpty( $notoptions1 );
- }
-
- /**
- * @covers ::users_can_register_signup_filter
- * @covers ::get_site_option
- */
- public function test_users_can_register_signup_filter() {
-
- get_site_option( 'registration' );
- $this->assertFalse( users_can_register_signup_filter() );
-
- update_site_option( 'registration', 'all' );
- $this->assertTrue( users_can_register_signup_filter() );
-
- update_site_option( 'registration', 'user' );
- $this->assertTrue( users_can_register_signup_filter() );
-
- update_site_option( 'registration', 'none' );
- $this->assertFalse( users_can_register_signup_filter() );
- }
-
- /**
- * @dataProvider data_illegal_names
- *
- * @covers ::update_site_option
- * @covers ::get_site_option
- */
- public function test_sanitize_network_option_illegal_names( $option_value, $sanitized_option_value ) {
- update_site_option( 'illegal_names', $option_value );
- $this->assertSame( $sanitized_option_value, get_site_option( 'illegal_names' ) );
- }
-
- public function data_illegal_names() {
- return array(
- array( array( '', 'Woo', '' ), array( 'Woo' ) ),
- array( 'foo bar', array( 'foo', 'bar' ) ),
- array( array(), '' ),
- );
- }
-
- /**
- * @dataProvider data_email_domains
- *
- * @param $option_value
- * @param $sanitized_option_value
- *
- * @covers ::update_site_option
- * @covers ::get_site_option
- */
- public function test_sanitize_network_option_limited_email_domains( $option_value, $sanitized_option_value ) {
- update_site_option( 'limited_email_domains', $option_value );
- $this->assertSame( $sanitized_option_value, get_site_option( 'limited_email_domains' ) );
- }
-
- /**
- * @dataProvider data_email_domains
- *
- * @param $option_value
- * @param $sanitized_option_value
- *
- * @covers ::update_site_option
- * @covers ::get_site_option
- */
- public function test_sanitize_network_option_banned_email_domains( $option_value, $sanitized_option_value ) {
- update_site_option( 'banned_email_domains', $option_value );
- $this->assertSame( $sanitized_option_value, get_site_option( 'banned_email_domains' ) );
- }
-
- public function data_email_domains() {
- return array(
- array( array( 'woo', '', 'boo.com', 'foo.net.biz..' ), array( 'woo', 'boo.com' ) ),
- array( "foo\nbar", array( 'foo', 'bar' ) ),
- array( "foo\n\nbar", array( 'foo', 'bar' ) ),
- array( "\nfoo\nbar\n", array( 'foo', 'bar' ) ),
- array( "foo\nfoo.net.biz..", array( 'foo' ) ),
- array( "foo\nfoo.net.biz..\nbar.com", array( 'foo', 'bar.com' ) ),
- array( 'foo.', array( 'foo.' ) ),
- array( '.foo', array( '.foo' ) ),
- array( 'foo^net', '' ),
- array( array(), '' ),
- );
- }
+ public function test_site_notoptions() {
+ $network_id = get_current_network_id();
+ $notoptions_key = "{$network_id}:notoptions";
+
+ $_notoptions = wp_cache_get( 'notoptions', 'site-options' );
+ $this->assertEmpty( $_notoptions );
+ $_notoptions1 = wp_cache_get( $notoptions_key, 'site-options' );
+ $this->assertEmpty( $_notoptions1 );
+
+ get_site_option( 'burrito' );
+
+ $notoptions = wp_cache_get( 'notoptions', 'site-options' );
+ $this->assertEmpty( $notoptions );
+ $notoptions1 = wp_cache_get( $notoptions_key, 'site-options' );
+ $this->assertNotEmpty( $notoptions1 );
}
-endif;
+ /**
+ * @covers ::users_can_register_signup_filter
+ * @covers ::get_site_option
+ */
+ public function test_users_can_register_signup_filter() {
+
+ get_site_option( 'registration' );
+ $this->assertFalse( users_can_register_signup_filter() );
+
+ update_site_option( 'registration', 'all' );
+ $this->assertTrue( users_can_register_signup_filter() );
+
+ update_site_option( 'registration', 'user' );
+ $this->assertTrue( users_can_register_signup_filter() );
+
+ update_site_option( 'registration', 'none' );
+ $this->assertFalse( users_can_register_signup_filter() );
+ }
+
+ /**
+ * @dataProvider data_illegal_names
+ *
+ * @covers ::update_site_option
+ * @covers ::get_site_option
+ */
+ public function test_sanitize_network_option_illegal_names( $option_value, $sanitized_option_value ) {
+ update_site_option( 'illegal_names', $option_value );
+ $this->assertSame( $sanitized_option_value, get_site_option( 'illegal_names' ) );
+ }
+
+ public function data_illegal_names() {
+ return array(
+ array( array( '', 'Woo', '' ), array( 'Woo' ) ),
+ array( 'foo bar', array( 'foo', 'bar' ) ),
+ array( array(), '' ),
+ );
+ }
+
+ /**
+ * @dataProvider data_email_domains
+ *
+ * @param $option_value
+ * @param $sanitized_option_value
+ *
+ * @covers ::update_site_option
+ * @covers ::get_site_option
+ */
+ public function test_sanitize_network_option_limited_email_domains( $option_value, $sanitized_option_value ) {
+ update_site_option( 'limited_email_domains', $option_value );
+ $this->assertSame( $sanitized_option_value, get_site_option( 'limited_email_domains' ) );
+ }
+
+ /**
+ * @dataProvider data_email_domains
+ *
+ * @param $option_value
+ * @param $sanitized_option_value
+ *
+ * @covers ::update_site_option
+ * @covers ::get_site_option
+ */
+ public function test_sanitize_network_option_banned_email_domains( $option_value, $sanitized_option_value ) {
+ update_site_option( 'banned_email_domains', $option_value );
+ $this->assertSame( $sanitized_option_value, get_site_option( 'banned_email_domains' ) );
+ }
+
+ public function data_email_domains() {
+ return array(
+ array( array( 'woo', '', 'boo.com', 'foo.net.biz..' ), array( 'woo', 'boo.com' ) ),
+ array( "foo\nbar", array( 'foo', 'bar' ) ),
+ array( "foo\n\nbar", array( 'foo', 'bar' ) ),
+ array( "\nfoo\nbar\n", array( 'foo', 'bar' ) ),
+ array( "foo\nfoo.net.biz..", array( 'foo' ) ),
+ array( "foo\nfoo.net.biz..\nbar.com", array( 'foo', 'bar.com' ) ),
+ array( 'foo.', array( 'foo.' ) ),
+ array( '.foo', array( '.foo' ) ),
+ array( 'foo^net', '' ),
+ array( array(), '' ),
+ );
+ }
+}
diff --git a/tests/phpunit/tests/theme/wpThemeGetAllowedFilters.php b/tests/phpunit/tests/theme/wpThemeGetAllowedFilters.php
index 8af704a7d2..9f5d71c687 100644
--- a/tests/phpunit/tests/theme/wpThemeGetAllowedFilters.php
+++ b/tests/phpunit/tests/theme/wpThemeGetAllowedFilters.php
@@ -1,99 +1,99 @@
<?php
-if ( is_multisite() ) :
+
+/**
+ * Tests specific to the filtering of `WP_Theme::get_allowed()` and related functions.
+ *
+ * @group ms-required
+ * @group multisite
+ * @group themes
+ */
+class Tests_Theme_wpThemeGetAllowedFilters extends WP_UnitTestCase {
/**
- * Tests specific to the filtering of `WP_Theme::get_allowed()` and related functions.
- *
- * @group themes
- * @group multisite
+ * @var array List of themes allowed before filters are applied.
*/
- class Tests_Theme_wpThemeGetAllowedFilters extends WP_UnitTestCase {
- /**
- * @var array List of themes allowed before filters are applied.
- */
- protected $default_allowed;
+ protected $default_allowed;
- protected $filter_network_allowed_themes_args;
+ protected $filter_network_allowed_themes_args;
- public function test_network_allowed_themes_filter_sends_blog_id() {
- $blog_id = 1;
+ public function test_network_allowed_themes_filter_sends_blog_id() {
+ $blog_id = 1;
- add_filter( 'network_allowed_themes', array( $this, 'filter_network_allowed_themes' ), 10, 2 );
- WP_Theme::get_allowed( $blog_id );
- remove_filter( 'network_allowed_themes', array( $this, 'filter_network_allowed_themes' ) );
+ add_filter( 'network_allowed_themes', array( $this, 'filter_network_allowed_themes' ), 10, 2 );
+ WP_Theme::get_allowed( $blog_id );
+ remove_filter( 'network_allowed_themes', array( $this, 'filter_network_allowed_themes' ) );
- $this->assertCount( 2, $this->filter_network_allowed_themes_args );
- $this->assertSame( $blog_id, $this->filter_network_allowed_themes_args[1] );
- }
+ $this->assertCount( 2, $this->filter_network_allowed_themes_args );
+ $this->assertSame( $blog_id, $this->filter_network_allowed_themes_args[1] );
+ }
- /**
- * Test the `allowed_themes` filter, which filters themes allowed on a network.
- */
- public function test_wp_theme_get_allowed_with_allowed_themes_filter() {
- $blog_id = 1;
+ /**
+ * Test the `allowed_themes` filter, which filters themes allowed on a network.
+ */
+ public function test_wp_theme_get_allowed_with_allowed_themes_filter() {
+ $blog_id = 1;
- $this->default_allowed = WP_Theme::get_allowed( $blog_id );
+ $this->default_allowed = WP_Theme::get_allowed( $blog_id );
- add_filter( 'allowed_themes', array( $this, 'filter_allowed_themes' ), 10 );
- $allowed = WP_Theme::get_allowed( $blog_id );
- remove_filter( 'allowed_themes', array( $this, 'filter_allowed_themes' ), 10 );
+ add_filter( 'allowed_themes', array( $this, 'filter_allowed_themes' ), 10 );
+ $allowed = WP_Theme::get_allowed( $blog_id );
+ remove_filter( 'allowed_themes', array( $this, 'filter_allowed_themes' ), 10 );
- $expected = $this->default_allowed + array( 'allow-on-network' => true );
+ $expected = $this->default_allowed + array( 'allow-on-network' => true );
- $this->assertSame( $expected, $allowed );
- }
+ $this->assertSame( $expected, $allowed );
+ }
- /**
- * Test the `network_allowed_themes` filter, which filters allowed themes on the network and provides `$blog_id`.
- */
- public function test_wp_theme_get_allowed_with_network_allowed_themes_filter() {
- $blog_id = 1;
+ /**
+ * Test the `network_allowed_themes` filter, which filters allowed themes on the network and provides `$blog_id`.
+ */
+ public function test_wp_theme_get_allowed_with_network_allowed_themes_filter() {
+ $blog_id = 1;
- $this->default_allowed = WP_Theme::get_allowed( $blog_id );
+ $this->default_allowed = WP_Theme::get_allowed( $blog_id );
- add_filter( 'network_allowed_themes', array( $this, 'filter_network_allowed_themes' ), 10, 2 );
- $allowed = WP_Theme::get_allowed( $blog_id );
- remove_filter( 'network_allowed_themes', array( $this, 'filter_network_allowed_themes' ), 10 );
+ add_filter( 'network_allowed_themes', array( $this, 'filter_network_allowed_themes' ), 10, 2 );
+ $allowed = WP_Theme::get_allowed( $blog_id );
+ remove_filter( 'network_allowed_themes', array( $this, 'filter_network_allowed_themes' ), 10 );
- $expected = $this->default_allowed + array( 'network-allowed-theme' => true );
+ $expected = $this->default_allowed + array( 'network-allowed-theme' => true );
- $this->assertSame( $expected, $allowed );
- }
+ $this->assertSame( $expected, $allowed );
+ }
- /**
- * Test the `site_allowed_themes` filter, which filters allowed themes for a site and provides `$blog_id`.
- */
- public function test_wp_theme_get_allowed_with_site_allowed_themes_filter() {
- $blog_id = 1;
+ /**
+ * Test the `site_allowed_themes` filter, which filters allowed themes for a site and provides `$blog_id`.
+ */
+ public function test_wp_theme_get_allowed_with_site_allowed_themes_filter() {
+ $blog_id = 1;
- $this->default_allowed = WP_Theme::get_allowed( $blog_id );
+ $this->default_allowed = WP_Theme::get_allowed( $blog_id );
- add_filter( 'site_allowed_themes', array( $this, 'filter_site_allowed_themes' ), 10, 2 );
- $allowed = WP_Theme::get_allowed( $blog_id );
- remove_filter( 'site_allowed_themes', array( $this, 'filter_site_allowed_themes' ), 10 );
+ add_filter( 'site_allowed_themes', array( $this, 'filter_site_allowed_themes' ), 10, 2 );
+ $allowed = WP_Theme::get_allowed( $blog_id );
+ remove_filter( 'site_allowed_themes', array( $this, 'filter_site_allowed_themes' ), 10 );
- $expected = $this->default_allowed + array( 'site-allowed-theme' => true );
+ $expected = $this->default_allowed + array( 'site-allowed-theme' => true );
- $this->assertSame( $expected, $allowed );
- }
+ $this->assertSame( $expected, $allowed );
+ }
- public function filter_allowed_themes( $allowed_themes ) {
- $allowed_themes['allow-on-network'] = true;
+ public function filter_allowed_themes( $allowed_themes ) {
+ $allowed_themes['allow-on-network'] = true;
- return $allowed_themes;
- }
+ return $allowed_themes;
+ }
- public function filter_network_allowed_themes( $allowed_themes, $blog_id ) {
- $this->filter_network_allowed_themes_args = func_get_args();
+ public function filter_network_allowed_themes( $allowed_themes, $blog_id ) {
+ $this->filter_network_allowed_themes_args = func_get_args();
- $allowed_themes['network-allowed-theme'] = true;
+ $allowed_themes['network-allowed-theme'] = true;
- return $allowed_themes;
- }
+ return $allowed_themes;
+ }
- public function filter_site_allowed_themes( $allowed_themes, $blog_id ) {
- $allowed_themes['site-allowed-theme'] = true;
+ public function filter_site_allowed_themes( $allowed_themes, $blog_id ) {
+ $allowed_themes['site-allowed-theme'] = true;
- return $allowed_themes;
- }
+ return $allowed_themes;
}
-endif;
+}
diff --git a/tests/phpunit/tests/user/getActiveBlogForUser.php b/tests/phpunit/tests/user/getActiveBlogForUser.php
index 423d71927c..ef3e5e6eff 100644
--- a/tests/phpunit/tests/user/getActiveBlogForUser.php
+++ b/tests/phpunit/tests/user/getActiveBlogForUser.php
@@ -1,101 +1,99 @@
<?php
-if ( is_multisite() ) :
-
- /**
- * Tests specific to users in multisite.
- *
- * @group user
- * @group ms-user
- * @group multisite
- */
- class Tests_User_GetActiveBlogForUser extends WP_UnitTestCase {
- public static $user_id = false;
-
- public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
- self::$user_id = $factory->user->create();
- }
+/**
+ * Tests specific to users in multisite.
+ *
+ * @group user
+ * @group ms-required
+ * @group ms-user
+ * @group multisite
+ */
+class Tests_User_GetActiveBlogForUser extends WP_UnitTestCase {
+
+ public static $user_id = false;
+
+ public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
+ self::$user_id = $factory->user->create();
+ }
- public static function wpTearDownAfterClass() {
- wpmu_delete_user( self::$user_id );
+ public static function wpTearDownAfterClass() {
+ wpmu_delete_user( self::$user_id );
- global $wp_rewrite;
- $wp_rewrite->init();
- }
+ global $wp_rewrite;
+ $wp_rewrite->init();
+ }
- /**
- * @ticket 38355
- */
- public function test_get_active_blog_for_user_with_no_sites() {
- $current_site_id = get_current_blog_id();
+ /**
+ * @ticket 38355
+ */
+ public function test_get_active_blog_for_user_with_no_sites() {
+ $current_site_id = get_current_blog_id();
- remove_user_from_blog( self::$user_id, $current_site_id );
+ remove_user_from_blog( self::$user_id, $current_site_id );
- $result = get_active_blog_for_user( self::$user_id );
+ $result = get_active_blog_for_user( self::$user_id );
- $this->assertNull( $result );
- }
+ $this->assertNull( $result );
+ }
- /**
- * @ticket 38355
- */
- public function test_get_active_blog_for_user_with_primary_site() {
- $site_id_one = self::factory()->blog->create( array( 'user_id' => self::$user_id ) );
- $site_id_two = self::factory()->blog->create( array( 'user_id' => self::$user_id ) );
+ /**
+ * @ticket 38355
+ */
+ public function test_get_active_blog_for_user_with_primary_site() {
+ $site_id_one = self::factory()->blog->create( array( 'user_id' => self::$user_id ) );
+ $site_id_two = self::factory()->blog->create( array( 'user_id' => self::$user_id ) );
- $sites = get_blogs_of_user( self::$user_id );
- $site_ids = array_keys( $sites );
- $primary_site_id = $site_ids[1];
+ $sites = get_blogs_of_user( self::$user_id );
+ $site_ids = array_keys( $sites );
+ $primary_site_id = $site_ids[1];
- update_user_meta( self::$user_id, 'primary_blog', $primary_site_id );
+ update_user_meta( self::$user_id, 'primary_blog', $primary_site_id );
- $result = get_active_blog_for_user( self::$user_id );
+ $result = get_active_blog_for_user( self::$user_id );
- wp_delete_site( $site_id_one );
- wp_delete_site( $site_id_two );
+ wp_delete_site( $site_id_one );
+ wp_delete_site( $site_id_two );
- $this->assertSame( $primary_site_id, $result->id );
- }
+ $this->assertSame( $primary_site_id, $result->id );
+ }
- /**
- * @ticket 38355
- */
- public function test_get_active_blog_for_user_without_primary_site() {
- $sites = get_blogs_of_user( self::$user_id );
- $site_ids = array_keys( $sites );
- $primary_site_id = $site_ids[0];
+ /**
+ * @ticket 38355
+ */
+ public function test_get_active_blog_for_user_without_primary_site() {
+ $sites = get_blogs_of_user( self::$user_id );
+ $site_ids = array_keys( $sites );
+ $primary_site_id = $site_ids[0];
- delete_user_meta( self::$user_id, 'primary_blog' );
+ delete_user_meta( self::$user_id, 'primary_blog' );
- $result = get_active_blog_for_user( self::$user_id );
+ $result = get_active_blog_for_user( self::$user_id );
- wp_delete_site( $primary_site_id );
+ wp_delete_site( $primary_site_id );
- $this->assertSame( $primary_site_id, $result->id );
- }
+ $this->assertSame( $primary_site_id, $result->id );
+ }
- /**
- * @ticket 38355
- */
- public function test_get_active_blog_for_user_with_spam_site() {
- $current_site_id = get_current_blog_id();
+ /**
+ * @ticket 38355
+ */
+ public function test_get_active_blog_for_user_with_spam_site() {
+ $current_site_id = get_current_blog_id();
- $site_id = self::factory()->blog->create(
- array(
- 'user_id' => self::$user_id,
- 'spam' => 1,
- )
- );
+ $site_id = self::factory()->blog->create(
+ array(
+ 'user_id' => self::$user_id,
+ 'spam' => 1,
+ )
+ );
- add_user_to_blog( $site_id, self::$user_id, 'subscriber' );
- update_user_meta( self::$user_id, 'primary_blog', $site_id );
+ add_user_to_blog( $site_id, self::$user_id, 'subscriber' );
+ update_user_meta( self::$user_id, 'primary_blog', $site_id );
- $result = get_active_blog_for_user( self::$user_id );
+ $result = get_active_blog_for_user( self::$user_id );
- wp_delete_site( $site_id );
+ wp_delete_site( $site_id );
- $this->assertSame( $current_site_id, $result->id );
- }
+ $this->assertSame( $current_site_id, $result->id );
}
-
-endif;
+}
diff --git a/tests/phpunit/tests/user/multisite.php b/tests/phpunit/tests/user/multisite.php
index 08d08bbe75..878492b664 100644
--- a/tests/phpunit/tests/user/multisite.php
+++ b/tests/phpunit/tests/user/multisite.php
@@ -1,453 +1,450 @@
<?php
-if ( is_multisite() ) :
+/**
+ * Tests specific to users in multisite.
+ *
+ * @group user
+ * @group ms-required
+ * @group ms-user
+ * @group multisite
+ */
+class Tests_User_Multisite extends WP_UnitTestCase {
- /**
- * Tests specific to users in multisite.
- *
- * @group user
- * @group ms-user
- * @group multisite
- */
- class Tests_User_Multisite extends WP_UnitTestCase {
+ public function test_remove_user_from_blog() {
+ $user1 = self::factory()->user->create_and_get();
+ $user2 = self::factory()->user->create_and_get();
- public function test_remove_user_from_blog() {
- $user1 = self::factory()->user->create_and_get();
- $user2 = self::factory()->user->create_and_get();
+ $post_id = self::factory()->post->create( array( 'post_author' => $user1->ID ) );
- $post_id = self::factory()->post->create( array( 'post_author' => $user1->ID ) );
+ remove_user_from_blog( $user1->ID, 1, $user2->ID );
- remove_user_from_blog( $user1->ID, 1, $user2->ID );
+ $post = get_post( $post_id );
- $post = get_post( $post_id );
+ $this->assertNotEquals( $user1->ID, $post->post_author );
+ $this->assertEquals( $user2->ID, $post->post_author );
+ }
- $this->assertNotEquals( $user1->ID, $post->post_author );
- $this->assertEquals( $user2->ID, $post->post_author );
+ /**
+ * Test the returned data from get_blogs_of_user()
+ */
+ public function test_get_blogs_of_user() {
+ $user1_id = self::factory()->user->create( array( 'role' => 'administrator' ) );
+
+ // Maintain a list of 6 total sites and include the primary network site.
+ $blog_ids = self::factory()->blog->create_many( 5, array( 'user_id' => $user1_id ) );
+ $blog_ids = array_merge( array( 1 ), $blog_ids );
+
+ // All sites are new and not marked as spam, archived, or deleted.
+ $blog_ids_of_user = array_keys( get_blogs_of_user( $user1_id ) );
+
+ // User should be a member of the created sites and the network's initial site.
+ $this->assertSame( $blog_ids, $blog_ids_of_user );
+
+ $this->assertTrue( remove_user_from_blog( $user1_id, $blog_ids[0] ) );
+ $this->assertTrue( remove_user_from_blog( $user1_id, $blog_ids[2] ) );
+ $this->assertTrue( remove_user_from_blog( $user1_id, $blog_ids[4] ) );
+
+ unset( $blog_ids[0] );
+ unset( $blog_ids[2] );
+ unset( $blog_ids[4] );
+ sort( $blog_ids );
+
+ $blogs_of_user = get_blogs_of_user( $user1_id, false );
+
+ // The user should still be a member of all remaining sites.
+ $blog_ids_of_user = array_keys( $blogs_of_user );
+ $this->assertSame( $blog_ids, $blog_ids_of_user );
+
+ // Each site retrieved should match the expected structure.
+ foreach ( $blogs_of_user as $blog_id => $blog ) {
+ $this->assertSame( $blog_id, $blog->userblog_id );
+ $this->assertObjectHasProperty( 'userblog_id', $blog );
+ $this->assertObjectHasProperty( 'blogname', $blog );
+ $this->assertObjectHasProperty( 'domain', $blog );
+ $this->assertObjectHasProperty( 'path', $blog );
+ $this->assertObjectHasProperty( 'site_id', $blog );
+ $this->assertObjectHasProperty( 'siteurl', $blog );
+ $this->assertObjectHasProperty( 'archived', $blog );
+ $this->assertObjectHasProperty( 'spam', $blog );
+ $this->assertObjectHasProperty( 'deleted', $blog );
}
- /**
- * Test the returned data from get_blogs_of_user()
- */
- public function test_get_blogs_of_user() {
- $user1_id = self::factory()->user->create( array( 'role' => 'administrator' ) );
-
- // Maintain a list of 6 total sites and include the primary network site.
- $blog_ids = self::factory()->blog->create_many( 5, array( 'user_id' => $user1_id ) );
- $blog_ids = array_merge( array( 1 ), $blog_ids );
-
- // All sites are new and not marked as spam, archived, or deleted.
- $blog_ids_of_user = array_keys( get_blogs_of_user( $user1_id ) );
-
- // User should be a member of the created sites and the network's initial site.
- $this->assertSame( $blog_ids, $blog_ids_of_user );
-
- $this->assertTrue( remove_user_from_blog( $user1_id, $blog_ids[0] ) );
- $this->assertTrue( remove_user_from_blog( $user1_id, $blog_ids[2] ) );
- $this->assertTrue( remove_user_from_blog( $user1_id, $blog_ids[4] ) );
-
- unset( $blog_ids[0] );
- unset( $blog_ids[2] );
- unset( $blog_ids[4] );
- sort( $blog_ids );
-
- $blogs_of_user = get_blogs_of_user( $user1_id, false );
-
- // The user should still be a member of all remaining sites.
- $blog_ids_of_user = array_keys( $blogs_of_user );
- $this->assertSame( $blog_ids, $blog_ids_of_user );
-
- // Each site retrieved should match the expected structure.
- foreach ( $blogs_of_user as $blog_id => $blog ) {
- $this->assertSame( $blog_id, $blog->userblog_id );
- $this->assertObjectHasProperty( 'userblog_id', $blog );
- $this->assertObjectHasProperty( 'blogname', $blog );
- $this->assertObjectHasProperty( 'domain', $blog );
- $this->assertObjectHasProperty( 'path', $blog );
- $this->assertObjectHasProperty( 'site_id', $blog );
- $this->assertObjectHasProperty( 'siteurl', $blog );
- $this->assertObjectHasProperty( 'archived', $blog );
- $this->assertObjectHasProperty( 'spam', $blog );
- $this->assertObjectHasProperty( 'deleted', $blog );
- }
-
- // Mark each remaining site as spam, archived, and deleted.
- update_blog_details( $blog_ids[0], array( 'spam' => 1 ) );
- update_blog_details( $blog_ids[1], array( 'archived' => 1 ) );
- update_blog_details( $blog_ids[2], array( 'deleted' => 1 ) );
-
- // Passing true as the second parameter should retrieve ALL sites, even if marked.
- $blogs_of_user = get_blogs_of_user( $user1_id, true );
- $blog_ids_of_user = array_keys( $blogs_of_user );
- $this->assertSame( $blog_ids, $blog_ids_of_user );
-
- // Check if sites are flagged as expected.
- $this->assertEquals( 1, $blogs_of_user[ $blog_ids[0] ]->spam );
- $this->assertEquals( 1, $blogs_of_user[ $blog_ids[1] ]->archived );
- $this->assertEquals( 1, $blogs_of_user[ $blog_ids[2] ]->deleted );
-
- unset( $blog_ids[0] );
- unset( $blog_ids[1] );
- unset( $blog_ids[2] );
- sort( $blog_ids );
-
- // Passing false (the default) as the second parameter should retrieve only good sites.
- $blog_ids_of_user = array_keys( get_blogs_of_user( $user1_id, false ) );
- $this->assertSame( $blog_ids, $blog_ids_of_user );
- }
+ // Mark each remaining site as spam, archived, and deleted.
+ update_blog_details( $blog_ids[0], array( 'spam' => 1 ) );
+ update_blog_details( $blog_ids[1], array( 'archived' => 1 ) );
+ update_blog_details( $blog_ids[2], array( 'deleted' => 1 ) );
+
+ // Passing true as the second parameter should retrieve ALL sites, even if marked.
+ $blogs_of_user = get_blogs_of_user( $user1_id, true );
+ $blog_ids_of_user = array_keys( $blogs_of_user );
+ $this->assertSame( $blog_ids, $blog_ids_of_user );
+
+ // Check if sites are flagged as expected.
+ $this->assertEquals( 1, $blogs_of_user[ $blog_ids[0] ]->spam );
+ $this->assertEquals( 1, $blogs_of_user[ $blog_ids[1] ]->archived );
+ $this->assertEquals( 1, $blogs_of_user[ $blog_ids[2] ]->deleted );
+
+ unset( $blog_ids[0] );
+ unset( $blog_ids[1] );
+ unset( $blog_ids[2] );
+ sort( $blog_ids );
+
+ // Passing false (the default) as the second parameter should retrieve only good sites.
+ $blog_ids_of_user = array_keys( get_blogs_of_user( $user1_id, false ) );
+ $this->assertSame( $blog_ids, $blog_ids_of_user );
+ }
- /**
- * @expectedDeprecated is_blog_user
- */
- public function test_is_blog_user() {
- global $wpdb;
+ /**
+ * @expectedDeprecated is_blog_user
+ */
+ public function test_is_blog_user() {
+ global $wpdb;
- $user1_id = self::factory()->user->create( array( 'role' => 'administrator' ) );
+ $user1_id = self::factory()->user->create( array( 'role' => 'administrator' ) );
- $old_current = get_current_user_id();
- wp_set_current_user( $user1_id );
+ $old_current = get_current_user_id();
+ wp_set_current_user( $user1_id );
- $this->assertTrue( is_blog_user() );
- $this->assertTrue( is_blog_user( get_current_blog_id() ) );
+ $this->assertTrue( is_blog_user() );
+ $this->assertTrue( is_blog_user( get_current_blog_id() ) );
- $blog_id = self::factory()->blog->create( array( 'user_id' => get_current_user_id() ) );
+ $blog_id = self::factory()->blog->create( array( 'user_id' => get_current_user_id() ) );
- $this->assertIsInt( $blog_id );
- $this->assertTrue( is_blog_user( $blog_id ) );
- $this->assertTrue( remove_user_from_blog( $user1_id, $blog_id ) );
- $this->assertFalse( is_blog_user( $blog_id ) );
+ $this->assertIsInt( $blog_id );
+ $this->assertTrue( is_blog_user( $blog_id ) );
+ $this->assertTrue( remove_user_from_blog( $user1_id, $blog_id ) );
+ $this->assertFalse( is_blog_user( $blog_id ) );
- wp_set_current_user( $old_current );
- }
+ wp_set_current_user( $old_current );
+ }
- public function test_is_user_member_of_blog() {
- global $wpdb;
+ public function test_is_user_member_of_blog() {
+ global $wpdb;
- $user1_id = self::factory()->user->create( array( 'role' => 'administrator' ) );
- $user2_id = self::factory()->user->create( array( 'role' => 'administrator' ) );
+ $user1_id = self::factory()->user->create( array( 'role' => 'administrator' ) );
+ $user2_id = self::factory()->user->create( array( 'role' => 'administrator' ) );
- $old_current = get_current_user_id();
+ $old_current = get_current_user_id();
- $this->assertSame( 0, $old_current );
+ $this->assertSame( 0, $old_current );
- // Test for "get current user" when not logged in.
- $this->assertFalse( is_user_member_of_blog() );
+ // Test for "get current user" when not logged in.
+ $this->assertFalse( is_user_member_of_blog() );
- wp_set_current_user( $user1_id );
- $site_id = get_current_blog_id();
+ wp_set_current_user( $user1_id );
+ $site_id = get_current_blog_id();
- $this->assertTrue( is_user_member_of_blog() );
- $this->assertTrue( is_user_member_of_blog( 0, 0 ) );
- $this->assertTrue( is_user_member_of_blog( 0, $site_id ) );
- $this->assertTrue( is_user_member_of_blog( $user1_id ) );
- $this->assertTrue( is_user_member_of_blog( $user1_id, $site_id ) );
+ $this->assertTrue( is_user_member_of_blog() );
+ $this->assertTrue( is_user_member_of_blog( 0, 0 ) );
+ $this->assertTrue( is_user_member_of_blog( 0, $site_id ) );
+ $this->assertTrue( is_user_member_of_blog( $user1_id ) );
+ $this->assertTrue( is_user_member_of_blog( $user1_id, $site_id ) );
- $blog_id = self::factory()->blog->create( array( 'user_id' => get_current_user_id() ) );
+ $blog_id = self::factory()->blog->create( array( 'user_id' => get_current_user_id() ) );
- $this->assertIsInt( $blog_id );
+ $this->assertIsInt( $blog_id );
- // Current user gets added to new blogs.
- $this->assertTrue( is_user_member_of_blog( $user1_id, $blog_id ) );
- // Other users should not.
- $this->assertFalse( is_user_member_of_blog( $user2_id, $blog_id ) );
+ // Current user gets added to new blogs.
+ $this->assertTrue( is_user_member_of_blog( $user1_id, $blog_id ) );
+ // Other users should not.
+ $this->assertFalse( is_user_member_of_blog( $user2_id, $blog_id ) );
- switch_to_blog( $blog_id );
+ switch_to_blog( $blog_id );
- $this->assertTrue( is_user_member_of_blog( $user1_id ) );
- $this->assertFalse( is_user_member_of_blog( $user2_id ) );
+ $this->assertTrue( is_user_member_of_blog( $user1_id ) );
+ $this->assertFalse( is_user_member_of_blog( $user2_id ) );
- // Remove user 1 from blog.
- $this->assertTrue( remove_user_from_blog( $user1_id, $blog_id ) );
+ // Remove user 1 from blog.
+ $this->assertTrue( remove_user_from_blog( $user1_id, $blog_id ) );
- // Add user 2 to blog.
- $this->assertTrue( add_user_to_blog( $blog_id, $user2_id, 'subscriber' ) );
+ // Add user 2 to blog.
+ $this->assertTrue( add_user_to_blog( $blog_id, $user2_id, 'subscriber' ) );
- $this->assertFalse( is_user_member_of_blog( $user1_id ) );
- $this->assertTrue( is_user_member_of_blog( $user2_id ) );
+ $this->assertFalse( is_user_member_of_blog( $user1_id ) );
+ $this->assertTrue( is_user_member_of_blog( $user2_id ) );
- restore_current_blog();
+ restore_current_blog();
- $this->assertFalse( is_user_member_of_blog( $user1_id, $blog_id ) );
- $this->assertTrue( is_user_member_of_blog( $user2_id, $blog_id ) );
+ $this->assertFalse( is_user_member_of_blog( $user1_id, $blog_id ) );
+ $this->assertTrue( is_user_member_of_blog( $user2_id, $blog_id ) );
- wpmu_delete_user( $user1_id );
- $user = new WP_User( $user1_id );
- $this->assertFalse( $user->exists() );
- $this->assertFalse( is_user_member_of_blog( $user1_id ) );
+ wpmu_delete_user( $user1_id );
+ $user = new WP_User( $user1_id );
+ $this->assertFalse( $user->exists() );
+ $this->assertFalse( is_user_member_of_blog( $user1_id ) );
- wp_set_current_user( $old_current );
- }
+ wp_set_current_user( $old_current );
+ }
- /**
- * @ticket 23192
- */
- public function test_is_user_spammy() {
- $user_id = self::factory()->user->create(
- array(
- 'role' => 'author',
- 'user_login' => 'testuser1',
- )
- );
-
- $spam_username = (string) $user_id;
- $spam_user_id = self::factory()->user->create(
- array(
- 'role' => 'author',
- 'user_login' => $spam_username,
- )
- );
- wp_update_user(
- array(
- 'ID' => $spam_user_id,
- 'spam' => '1',
- )
- );
-
- $this->assertTrue( is_user_spammy( $spam_username ) );
- $this->assertFalse( is_user_spammy( 'testuser1' ) );
- }
+ /**
+ * @ticket 23192
+ */
+ public function test_is_user_spammy() {
+ $user_id = self::factory()->user->create(
+ array(
+ 'role' => 'author',
+ 'user_login' => 'testuser1',
+ )
+ );
+
+ $spam_username = (string) $user_id;
+ $spam_user_id = self::factory()->user->create(
+ array(
+ 'role' => 'author',
+ 'user_login' => $spam_username,
+ )
+ );
+ wp_update_user(
+ array(
+ 'ID' => $spam_user_id,
+ 'spam' => '1',
+ )
+ );
+
+ $this->assertTrue( is_user_spammy( $spam_username ) );
+ $this->assertFalse( is_user_spammy( 'testuser1' ) );
+ }
+
+ /**
+ * @ticket 20601
+ */
+ public function test_user_member_of_blog() {
+ global $wp_rewrite;
- /**
- * @ticket 20601
- */
- public function test_user_member_of_blog() {
- global $wp_rewrite;
+ self::factory()->blog->create();
+ $user_id = self::factory()->user->create();
+ self::factory()->blog->create( array( 'user_id' => $user_id ) );
- self::factory()->blog->create();
- $user_id = self::factory()->user->create();
- self::factory()->blog->create( array( 'user_id' => $user_id ) );
+ $blogs = get_blogs_of_user( $user_id );
+ $this->assertCount( 2, $blogs );
+ $first = reset( $blogs )->userblog_id;
+ remove_user_from_blog( $user_id, $first );
- $blogs = get_blogs_of_user( $user_id );
- $this->assertCount( 2, $blogs );
- $first = reset( $blogs )->userblog_id;
- remove_user_from_blog( $user_id, $first );
+ $blogs = get_blogs_of_user( $user_id );
+ $second = reset( $blogs )->userblog_id;
+ $this->assertCount( 1, $blogs );
- $blogs = get_blogs_of_user( $user_id );
- $second = reset( $blogs )->userblog_id;
- $this->assertCount( 1, $blogs );
+ switch_to_blog( $first );
+ $wp_rewrite->init();
- switch_to_blog( $first );
- $wp_rewrite->init();
+ $this->go_to( get_author_posts_url( $user_id ) );
+ $this->assertQueryTrue( 'is_404' );
- $this->go_to( get_author_posts_url( $user_id ) );
- $this->assertQueryTrue( 'is_404' );
+ switch_to_blog( $second );
+ $wp_rewrite->init();
- switch_to_blog( $second );
- $wp_rewrite->init();
+ $this->go_to( get_author_posts_url( $user_id ) );
+ $this->assertQueryTrue( 'is_author', 'is_archive' );
- $this->go_to( get_author_posts_url( $user_id ) );
- $this->assertQueryTrue( 'is_author', 'is_archive' );
+ add_user_to_blog( $first, $user_id, 'administrator' );
+ $blogs = get_blogs_of_user( $user_id );
+ $this->assertCount( 2, $blogs );
- add_user_to_blog( $first, $user_id, 'administrator' );
- $blogs = get_blogs_of_user( $user_id );
- $this->assertCount( 2, $blogs );
+ switch_to_blog( $first );
+ $wp_rewrite->init();
- switch_to_blog( $first );
- $wp_rewrite->init();
+ $this->go_to( get_author_posts_url( $user_id ) );
+ $this->assertQueryTrue( 'is_author', 'is_archive' );
+ }
- $this->go_to( get_author_posts_url( $user_id ) );
- $this->assertQueryTrue( 'is_author', 'is_archive' );
+ public function test_revoked_super_admin_can_be_deleted() {
+ if ( isset( $GLOBALS['super_admins'] ) ) {
+ $old_global = $GLOBALS['super_admins'];
+ unset( $GLOBALS['super_admins'] );
}
- public function test_revoked_super_admin_can_be_deleted() {
- if ( isset( $GLOBALS['super_admins'] ) ) {
- $old_global = $GLOBALS['super_admins'];
- unset( $GLOBALS['super_admins'] );
- }
+ $user_id = self::factory()->user->create();
+ grant_super_admin( $user_id );
+ revoke_super_admin( $user_id );
- $user_id = self::factory()->user->create();
- grant_super_admin( $user_id );
- revoke_super_admin( $user_id );
+ $this->assertTrue( wpmu_delete_user( $user_id ) );
- $this->assertTrue( wpmu_delete_user( $user_id ) );
+ if ( isset( $old_global ) ) {
+ $GLOBALS['super_admins'] = $old_global;
+ }
+ }
- if ( isset( $old_global ) ) {
- $GLOBALS['super_admins'] = $old_global;
- }
+ public function test_revoked_super_admin_is_deleted() {
+ if ( isset( $GLOBALS['super_admins'] ) ) {
+ $old_global = $GLOBALS['super_admins'];
+ unset( $GLOBALS['super_admins'] );
}
- public function test_revoked_super_admin_is_deleted() {
- if ( isset( $GLOBALS['super_admins'] ) ) {
- $old_global = $GLOBALS['super_admins'];
- unset( $GLOBALS['super_admins'] );
- }
+ $user_id = self::factory()->user->create();
+ grant_super_admin( $user_id );
+ revoke_super_admin( $user_id );
+ wpmu_delete_user( $user_id );
+ $user = new WP_User( $user_id );
- $user_id = self::factory()->user->create();
- grant_super_admin( $user_id );
- revoke_super_admin( $user_id );
- wpmu_delete_user( $user_id );
- $user = new WP_User( $user_id );
+ $this->assertFalse( $user->exists(), 'WP_User->exists' );
- $this->assertFalse( $user->exists(), 'WP_User->exists' );
+ if ( isset( $old_global ) ) {
+ $GLOBALS['super_admins'] = $old_global;
+ }
+ }
- if ( isset( $old_global ) ) {
- $GLOBALS['super_admins'] = $old_global;
- }
+ public function test_super_admin_cannot_be_deleted() {
+ if ( isset( $GLOBALS['super_admins'] ) ) {
+ $old_global = $GLOBALS['super_admins'];
+ unset( $GLOBALS['super_admins'] );
}
- public function test_super_admin_cannot_be_deleted() {
- if ( isset( $GLOBALS['super_admins'] ) ) {
- $old_global = $GLOBALS['super_admins'];
- unset( $GLOBALS['super_admins'] );
- }
+ $user_id = self::factory()->user->create();
+ grant_super_admin( $user_id );
- $user_id = self::factory()->user->create();
- grant_super_admin( $user_id );
+ $this->assertFalse( wpmu_delete_user( $user_id ) );
- $this->assertFalse( wpmu_delete_user( $user_id ) );
+ if ( isset( $old_global ) ) {
+ $GLOBALS['super_admins'] = $old_global;
+ }
+ }
- if ( isset( $old_global ) ) {
- $GLOBALS['super_admins'] = $old_global;
- }
+ /**
+ * @ticket 27205
+ */
+ public function test_granting_super_admins() {
+ if ( isset( $GLOBALS['super_admins'] ) ) {
+ $old_global = $GLOBALS['super_admins'];
+ unset( $GLOBALS['super_admins'] );
}
- /**
- * @ticket 27205
- */
- public function test_granting_super_admins() {
- if ( isset( $GLOBALS['super_admins'] ) ) {
- $old_global = $GLOBALS['super_admins'];
- unset( $GLOBALS['super_admins'] );
- }
-
- $user_id = self::factory()->user->create();
-
- $this->assertFalse( is_super_admin( $user_id ) );
- $this->assertFalse( revoke_super_admin( $user_id ) );
- $this->assertTrue( grant_super_admin( $user_id ) );
- $this->assertTrue( is_super_admin( $user_id ) );
- $this->assertFalse( grant_super_admin( $user_id ) );
- $this->assertTrue( revoke_super_admin( $user_id ) );
-
- // None of these operations should set the $super_admins global.
- $this->assertFalse( isset( $GLOBALS['super_admins'] ) );
-
- // Try with two users.
- $second_user = self::factory()->user->create();
- $this->assertTrue( grant_super_admin( $user_id ) );
- $this->assertTrue( grant_super_admin( $second_user ) );
- $this->assertTrue( is_super_admin( $second_user ) );
- $this->assertTrue( is_super_admin( $user_id ) );
- $this->assertTrue( revoke_super_admin( $user_id ) );
- $this->assertTrue( revoke_super_admin( $second_user ) );
-
- if ( isset( $old_global ) ) {
- $GLOBALS['super_admins'] = $old_global;
- }
+ $user_id = self::factory()->user->create();
+
+ $this->assertFalse( is_super_admin( $user_id ) );
+ $this->assertFalse( revoke_super_admin( $user_id ) );
+ $this->assertTrue( grant_super_admin( $user_id ) );
+ $this->assertTrue( is_super_admin( $user_id ) );
+ $this->assertFalse( grant_super_admin( $user_id ) );
+ $this->assertTrue( revoke_super_admin( $user_id ) );
+
+ // None of these operations should set the $super_admins global.
+ $this->assertFalse( isset( $GLOBALS['super_admins'] ) );
+
+ // Try with two users.
+ $second_user = self::factory()->user->create();
+ $this->assertTrue( grant_super_admin( $user_id ) );
+ $this->assertTrue( grant_super_admin( $second_user ) );
+ $this->assertTrue( is_super_admin( $second_user ) );
+ $this->assertTrue( is_super_admin( $user_id ) );
+ $this->assertTrue( revoke_super_admin( $user_id ) );
+ $this->assertTrue( revoke_super_admin( $second_user ) );
+
+ if ( isset( $old_global ) ) {
+ $GLOBALS['super_admins'] = $old_global;
}
+ }
- public function test_numeric_string_user_id() {
- $u = self::factory()->user->create();
+ public function test_numeric_string_user_id() {
+ $u = self::factory()->user->create();
- $u_string = (string) $u;
- $this->assertTrue( wpmu_delete_user( $u_string ) );
- $this->assertFalse( get_user_by( 'id', $u ) );
- }
+ $u_string = (string) $u;
+ $this->assertTrue( wpmu_delete_user( $u_string ) );
+ $this->assertFalse( get_user_by( 'id', $u ) );
+ }
- /**
- * @ticket 33800
- */
- public function test_should_return_false_for_non_numeric_string_user_id() {
- $this->assertFalse( wpmu_delete_user( 'abcde' ) );
- }
+ /**
+ * @ticket 33800
+ */
+ public function test_should_return_false_for_non_numeric_string_user_id() {
+ $this->assertFalse( wpmu_delete_user( 'abcde' ) );
+ }
- /**
- * @ticket 33800
- */
- public function test_should_return_false_for_object_user_id() {
- $u_obj = self::factory()->user->create_and_get();
- $this->assertFalse( wpmu_delete_user( $u_obj ) );
- $this->assertSame( $u_obj->ID, username_exists( $u_obj->user_login ) );
- }
+ /**
+ * @ticket 33800
+ */
+ public function test_should_return_false_for_object_user_id() {
+ $u_obj = self::factory()->user->create_and_get();
+ $this->assertFalse( wpmu_delete_user( $u_obj ) );
+ $this->assertSame( $u_obj->ID, username_exists( $u_obj->user_login ) );
+ }
- /**
- * @ticket 38356
- */
- public function test_add_user_to_blog_subscriber() {
- $site_id = self::factory()->blog->create();
- $user_id = self::factory()->user->create();
+ /**
+ * @ticket 38356
+ */
+ public function test_add_user_to_blog_subscriber() {
+ $site_id = self::factory()->blog->create();
+ $user_id = self::factory()->user->create();
- add_user_to_blog( $site_id, $user_id, 'subscriber' );
+ add_user_to_blog( $site_id, $user_id, 'subscriber' );
- switch_to_blog( $site_id );
- $user = get_user_by( 'id', $user_id );
- restore_current_blog();
+ switch_to_blog( $site_id );
+ $user = get_user_by( 'id', $user_id );
+ restore_current_blog();
- wp_delete_site( $site_id );
- wpmu_delete_user( $user_id );
+ wp_delete_site( $site_id );
+ wpmu_delete_user( $user_id );
- $this->assertContains( 'subscriber', $user->roles );
- }
+ $this->assertContains( 'subscriber', $user->roles );
+ }
- /**
- * @ticket 38356
- */
- public function test_add_user_to_blog_invalid_user() {
- global $wpdb;
+ /**
+ * @ticket 38356
+ */
+ public function test_add_user_to_blog_invalid_user() {
+ global $wpdb;
- $site_id = self::factory()->blog->create();
+ $site_id = self::factory()->blog->create();
- $suppress = $wpdb->suppress_errors();
- $result = add_user_to_blog( 73622, $site_id, 'subscriber' );
- $wpdb->suppress_errors( $suppress );
+ $suppress = $wpdb->suppress_errors();
+ $result = add_user_to_blog( 73622, $site_id, 'subscriber' );
+ $wpdb->suppress_errors( $suppress );
- wp_delete_site( $site_id );
+ wp_delete_site( $site_id );
- $this->assertWPError( $result );
- }
+ $this->assertWPError( $result );
+ }
- /**
- * @ticket 41101
- */
- public function test_should_fail_can_add_user_to_blog_filter() {
- $site_id = self::factory()->blog->create();
- $user_id = self::factory()->user->create();
+ /**
+ * @ticket 41101
+ */
+ public function test_should_fail_can_add_user_to_blog_filter() {
+ $site_id = self::factory()->blog->create();
+ $user_id = self::factory()->user->create();
- add_filter( 'can_add_user_to_blog', '__return_false' );
- $result = add_user_to_blog( $site_id, $user_id, 'subscriber' );
+ add_filter( 'can_add_user_to_blog', '__return_false' );
+ $result = add_user_to_blog( $site_id, $user_id, 'subscriber' );
- $this->assertWPError( $result );
- }
+ $this->assertWPError( $result );
+ }
- /**
- * @ticket 41101
- */
- public function test_should_succeed_can_add_user_to_blog_filter() {
- $site_id = self::factory()->blog->create();
- $user_id = self::factory()->user->create();
+ /**
+ * @ticket 41101
+ */
+ public function test_should_succeed_can_add_user_to_blog_filter() {
+ $site_id = self::factory()->blog->create();
+ $user_id = self::factory()->user->create();
- add_filter( 'can_add_user_to_blog', '__return_true' );
- $result = add_user_to_blog( $site_id, $user_id, 'subscriber' );
+ add_filter( 'can_add_user_to_blog', '__return_true' );
+ $result = add_user_to_blog( $site_id, $user_id, 'subscriber' );
- $this->assertTrue( $result );
- }
+ $this->assertTrue( $result );
+ }
- /**
- * @ticket 23016
- */
- public function test_wp_roles_global_is_reset() {
- global $wp_roles;
- $role = 'test_global_is_reset';
- $role_name = 'Test Global Is Reset';
- $blog_id = self::factory()->blog->create();
+ /**
+ * @ticket 23016
+ */
+ public function test_wp_roles_global_is_reset() {
+ global $wp_roles;
+ $role = 'test_global_is_reset';
+ $role_name = 'Test Global Is Reset';
+ $blog_id = self::factory()->blog->create();
- $wp_roles->add_role( $role, $role_name, array() );
+ $wp_roles->add_role( $role, $role_name, array() );
- $this->assertNotEmpty( $wp_roles->get_role( $role ) );
+ $this->assertNotEmpty( $wp_roles->get_role( $role ) );
- switch_to_blog( $blog_id );
+ switch_to_blog( $blog_id );
- $this->assertEmpty( $wp_roles->get_role( $role ) );
+ $this->assertEmpty( $wp_roles->get_role( $role ) );
- $wp_roles->add_role( $role, $role_name, array() );
+ $wp_roles->add_role( $role, $role_name, array() );
- $this->assertNotEmpty( $wp_roles->get_role( $role ) );
+ $this->assertNotEmpty( $wp_roles->get_role( $role ) );
- restore_current_blog();
+ restore_current_blog();
- $this->assertNotEmpty( $wp_roles->get_role( $role ) );
+ $this->assertNotEmpty( $wp_roles->get_role( $role ) );
- $wp_roles->remove_role( $role );
- }
+ $wp_roles->remove_role( $role );
}
-
-endif;
+}