From 93eeb8f1d79dc350ed619460347e5c24d780155a Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Wed, 25 Dec 2019 21:39:46 +0000 Subject: [PATCH] Tests: Update legacy arguments passed to `WP_UnitTest_Factory_For_Blog::create_object()`. This converts the arguments originally meant for `wpmu_create_blog()` to the ones used by `wp_insert_site()`. Follow-up to [47011]. Fixes #47195. git-svn-id: https://develop.svn.wordpress.org/trunk@47013 602fd350-edb4-49c9-b593-d223f7449a82 --- .../class-wp-unittest-factory-for-blog.php | 13 +---- tests/phpunit/tests/multisite.php | 24 +++++++-- tests/phpunit/tests/multisite/bootstrap.php | 30 +++++------ .../tests/multisite/getIdFromBlogname.php | 36 ++++++------- .../phpunit/tests/multisite/getMainSiteId.php | 12 ++--- tests/phpunit/tests/multisite/network.php | 18 +++---- tests/phpunit/tests/multisite/site.php | 18 +++---- tests/phpunit/tests/multisite/siteQuery.php | 40 +++++++------- tests/phpunit/tests/multisite/wpGetSites.php | 22 ++++---- .../multisite/wpmuValidateBlogSignup.php | 6 +-- tests/phpunit/tests/option/multisite.php | 4 +- .../tests/user/getActiveBlogForUser.php | 2 +- tests/phpunit/tests/user/multisite.php | 52 +++++++++---------- 13 files changed, 137 insertions(+), 140 deletions(-) diff --git a/tests/phpunit/includes/factory/class-wp-unittest-factory-for-blog.php b/tests/phpunit/includes/factory/class-wp-unittest-factory-for-blog.php index 424197b835..9ab08ad275 100644 --- a/tests/phpunit/includes/factory/class-wp-unittest-factory-for-blog.php +++ b/tests/phpunit/includes/factory/class-wp-unittest-factory-for-blog.php @@ -33,17 +33,8 @@ class WP_UnitTest_Factory_For_Blog extends WP_UnitTest_Factory_For_Thing { public function create_object( $args ) { global $wpdb; - // Map some arguments for backward compatibility with wpmu_create_blog() previously used here. - if ( ! isset( $args['public'] ) ) { - // Default to public, unless an options array was provided. - $args['public'] = ! isset( $args['meta'] ) ? 1 : 0; - } - - if ( ! isset( $args['user_id'] ) ) { - $args['user_id'] = get_current_user_id(); - } - - if ( isset( $args['site_id'] ) ) { + // Map some arguments for backward compatibility with `wpmu_create_blog()` previously used here. + if ( ! isset( $args['network_id'] ) && isset( $args['site_id'] ) ) { $args['network_id'] = $args['site_id']; unset( $args['site_id'] ); } diff --git a/tests/phpunit/tests/multisite.php b/tests/phpunit/tests/multisite.php index 009c0d4e52..c75b76eea5 100644 --- a/tests/phpunit/tests/multisite.php +++ b/tests/phpunit/tests/multisite.php @@ -43,23 +43,37 @@ if ( is_multisite() ) : $site_ids = array( 'public' => self::factory()->blog->create_many( random_int( 0, 5 ), - array( 'meta' => array( 'public' => 1 ) ) + array( + 'public' => 1, + ) ), 'archived' => self::factory()->blog->create_many( random_int( 0, 5 ), - array( 'meta' => array( 'archived' => 1 ) ) + array( + 'public' => 0, + 'archived' => 1, + ) ), 'mature' => self::factory()->blog->create_many( random_int( 0, 5 ), - array( 'meta' => array( 'mature' => 1 ) ) + array( + 'public' => 0, + 'mature' => 1, + ) ), 'spam' => self::factory()->blog->create_many( random_int( 0, 5 ), - array( 'meta' => array( 'spam' => 1 ) ) + array( + 'public' => 0, + 'spam' => 1, + ) ), 'deleted' => self::factory()->blog->create_many( random_int( 0, 5 ), - array( 'meta' => array( 'deleted' => 1 ) ) + array( + 'public' => 0, + 'deleted' => 1, + ) ), ); diff --git a/tests/phpunit/tests/multisite/bootstrap.php b/tests/phpunit/tests/multisite/bootstrap.php index 99d514e965..9b85114624 100644 --- a/tests/phpunit/tests/multisite/bootstrap.php +++ b/tests/phpunit/tests/multisite/bootstrap.php @@ -55,29 +55,29 @@ if ( is_multisite() ) : self::$site_ids = array( 'wordpress.org/' => array( - 'domain' => 'wordpress.org', - 'path' => '/', - 'site_id' => self::$network_ids['wordpress.org/'], + 'domain' => 'wordpress.org', + 'path' => '/', + 'network_id' => self::$network_ids['wordpress.org/'], ), 'wordpress.org/foo/' => array( - 'domain' => 'wordpress.org', - 'path' => '/foo/', - 'site_id' => self::$network_ids['wordpress.org/'], + 'domain' => 'wordpress.org', + 'path' => '/foo/', + 'network_id' => self::$network_ids['wordpress.org/'], ), 'wordpress.org/foo/bar/' => array( - 'domain' => 'wordpress.org', - 'path' => '/foo/bar/', - 'site_id' => self::$network_ids['wordpress.org/'], + 'domain' => 'wordpress.org', + 'path' => '/foo/bar/', + 'network_id' => self::$network_ids['wordpress.org/'], ), 'make.wordpress.org/' => array( - 'domain' => 'make.wordpress.org', - 'path' => '/', - 'site_id' => self::$network_ids['make.wordpress.org/'], + 'domain' => 'make.wordpress.org', + 'path' => '/', + 'network_id' => self::$network_ids['make.wordpress.org/'], ), 'make.wordpress.org/foo/' => array( - 'domain' => 'make.wordpress.org', - 'path' => '/foo/', - 'site_id' => self::$network_ids['make.wordpress.org/'], + 'domain' => 'make.wordpress.org', + 'path' => '/foo/', + 'network_id' => self::$network_ids['make.wordpress.org/'], ), 'www.w.org/' => array( 'domain' => 'www.w.org', diff --git a/tests/phpunit/tests/multisite/getIdFromBlogname.php b/tests/phpunit/tests/multisite/getIdFromBlogname.php index ded3cc6ff9..1e50110018 100644 --- a/tests/phpunit/tests/multisite/getIdFromBlogname.php +++ b/tests/phpunit/tests/multisite/getIdFromBlogname.php @@ -31,34 +31,34 @@ if ( is_multisite() ) : self::$site_ids = array( 'wordpress.org/' => array( - 'domain' => 'wordpress.org', - 'path' => '/', - 'site_id' => self::$network_ids['wordpress.org/'], + 'domain' => 'wordpress.org', + 'path' => '/', + 'network_id' => self::$network_ids['wordpress.org/'], ), 'foo.wordpress.org/' => array( - 'domain' => 'foo.wordpress.org', - 'path' => '/', - 'site_id' => self::$network_ids['wordpress.org/'], + 'domain' => 'foo.wordpress.org', + 'path' => '/', + 'network_id' => self::$network_ids['wordpress.org/'], ), 'wordpress.org/foo/' => array( - 'domain' => 'wordpress.org', - 'path' => '/foo/', - 'site_id' => self::$network_ids['wordpress.org/'], + 'domain' => 'wordpress.org', + 'path' => '/foo/', + 'network_id' => self::$network_ids['wordpress.org/'], ), 'www.wordpress.net/' => array( - 'domain' => 'www.wordpress.net', - 'path' => '/', - 'site_id' => self::$network_ids['www.wordpress.net/'], + 'domain' => 'www.wordpress.net', + 'path' => '/', + 'network_id' => self::$network_ids['www.wordpress.net/'], ), 'foo.wordpress.net/' => array( - 'domain' => 'foo.wordpress.net', - 'path' => '/', - 'site_id' => self::$network_ids['www.wordpress.net/'], + 'domain' => 'foo.wordpress.net', + 'path' => '/', + 'network_id' => self::$network_ids['www.wordpress.net/'], ), 'www.wordpress.net/foo/' => array( - 'domain' => 'www.wordpress.net', - 'path' => '/foo/', - 'site_id' => self::$network_ids['www.wordpress.net/'], + 'domain' => 'www.wordpress.net', + 'path' => '/foo/', + 'network_id' => self::$network_ids['www.wordpress.net/'], ), ); diff --git a/tests/phpunit/tests/multisite/getMainSiteId.php b/tests/phpunit/tests/multisite/getMainSiteId.php index 56fe53f957..3d0148611f 100644 --- a/tests/phpunit/tests/multisite/getMainSiteId.php +++ b/tests/phpunit/tests/multisite/getMainSiteId.php @@ -35,14 +35,14 @@ if ( is_multisite() ) : 'path' => '/', ), 'wordpress.org/' => array( - 'domain' => 'wordpress.org', - 'path' => '/', - 'site_id' => self::$network_ids['wordpress.org/'], + 'domain' => 'wordpress.org', + 'path' => '/', + 'network_id' => self::$network_ids['wordpress.org/'], ), 'wordpress.org/foo/' => array( - 'domain' => 'wordpress.org', - 'path' => '/foo/', - 'site_id' => self::$network_ids['wordpress.org/'], + 'domain' => 'wordpress.org', + 'path' => '/foo/', + 'network_id' => self::$network_ids['wordpress.org/'], ), ); diff --git a/tests/phpunit/tests/multisite/network.php b/tests/phpunit/tests/multisite/network.php index 9d44116ee8..bfe220638b 100644 --- a/tests/phpunit/tests/multisite/network.php +++ b/tests/phpunit/tests/multisite/network.php @@ -38,19 +38,19 @@ if ( is_multisite() ) : $sites = array( array( - 'domain' => 'wordpress.org', - 'path' => '/', - 'site_id' => self::$different_network_id, + 'domain' => 'wordpress.org', + 'path' => '/', + 'network_id' => self::$different_network_id, ), array( - 'domain' => 'wordpress.org', - 'path' => '/foo/', - 'site_id' => self::$different_network_id, + 'domain' => 'wordpress.org', + 'path' => '/foo/', + 'network_id' => self::$different_network_id, ), array( - 'domain' => 'wordpress.org', - 'path' => '/bar/', - 'site_id' => self::$different_network_id, + 'domain' => 'wordpress.org', + 'path' => '/bar/', + 'network_id' => self::$different_network_id, ), ); diff --git a/tests/phpunit/tests/multisite/site.php b/tests/phpunit/tests/multisite/site.php index c6cb17fa4c..f77d425470 100644 --- a/tests/phpunit/tests/multisite/site.php +++ b/tests/phpunit/tests/multisite/site.php @@ -44,14 +44,14 @@ if ( is_multisite() ) : self::$site_ids = array( 'make.wordpress.org/' => array( - 'domain' => 'make.wordpress.org', - 'path' => '/', - 'site_id' => self::$network_ids['make.wordpress.org/'], + 'domain' => 'make.wordpress.org', + 'path' => '/', + 'network_id' => self::$network_ids['make.wordpress.org/'], ), 'make.wordpress.org/foo/' => array( - 'domain' => 'make.wordpress.org', - 'path' => '/foo/', - 'site_id' => self::$network_ids['make.wordpress.org/'], + 'domain' => 'make.wordpress.org', + 'path' => '/foo/', + 'network_id' => self::$network_ids['make.wordpress.org/'], ), ); @@ -63,9 +63,9 @@ if ( is_multisite() ) : remove_action( 'wp_initialize_site', 'wp_initialize_site', 10 ); self::$uninitialized_site_id = wp_insert_site( array( - 'domain' => 'uninitialized.org', - 'path' => '/', - 'site_id' => self::$network_ids['make.wordpress.org/'], + 'domain' => 'uninitialized.org', + 'path' => '/', + 'network_id' => self::$network_ids['make.wordpress.org/'], ) ); add_action( 'wp_initialize_site', 'wp_initialize_site', 10, 2 ); diff --git a/tests/phpunit/tests/multisite/siteQuery.php b/tests/phpunit/tests/multisite/siteQuery.php index 2eaeb906b9..b3c7e3fb0c 100644 --- a/tests/phpunit/tests/multisite/siteQuery.php +++ b/tests/phpunit/tests/multisite/siteQuery.php @@ -49,29 +49,29 @@ if ( is_multisite() ) : self::$site_ids = array( 'wordpress.org/' => array( - 'domain' => 'wordpress.org', - 'path' => '/', - 'site_id' => self::$network_ids['wordpress.org/'], + 'domain' => 'wordpress.org', + 'path' => '/', + 'network_id' => self::$network_ids['wordpress.org/'], ), 'wordpress.org/foo/' => array( - 'domain' => 'wordpress.org', - 'path' => '/foo/', - 'site_id' => self::$network_ids['wordpress.org/'], + 'domain' => 'wordpress.org', + 'path' => '/foo/', + 'network_id' => self::$network_ids['wordpress.org/'], ), 'wordpress.org/foo/bar/' => array( - 'domain' => 'wordpress.org', - 'path' => '/foo/bar/', - 'site_id' => self::$network_ids['wordpress.org/'], + 'domain' => 'wordpress.org', + 'path' => '/foo/bar/', + 'network_id' => self::$network_ids['wordpress.org/'], ), 'make.wordpress.org/' => array( - 'domain' => 'make.wordpress.org', - 'path' => '/', - 'site_id' => self::$network_ids['make.wordpress.org/'], + 'domain' => 'make.wordpress.org', + 'path' => '/', + 'network_id' => self::$network_ids['make.wordpress.org/'], ), 'make.wordpress.org/foo/' => array( - 'domain' => 'make.wordpress.org', - 'path' => '/foo/', - 'site_id' => self::$network_ids['make.wordpress.org/'], + 'domain' => 'make.wordpress.org', + 'path' => '/foo/', + 'network_id' => self::$network_ids['make.wordpress.org/'], ), 'www.w.org/' => array( 'domain' => 'www.w.org', @@ -86,12 +86,10 @@ if ( is_multisite() ) : 'path' => '/foo/bar/', ), 'www.w.org/make/' => array( - 'domain' => 'www.w.org', - 'path' => '/make/', - 'meta' => array( - 'public' => 1, - 'lang_id' => 1, - ), + 'domain' => 'www.w.org', + 'path' => '/make/', + 'public' => 1, + 'lang_id' => 1, ), ); diff --git a/tests/phpunit/tests/multisite/wpGetSites.php b/tests/phpunit/tests/multisite/wpGetSites.php index ee718f1129..3a068e87e5 100644 --- a/tests/phpunit/tests/multisite/wpGetSites.php +++ b/tests/phpunit/tests/multisite/wpGetSites.php @@ -13,21 +13,21 @@ if ( is_multisite() ) : public static function wpSetUpBeforeClass( $factory ) { self::$site_ids = array( 'w.org/' => array( - 'domain' => 'w.org', - 'path' => '/', - 'site_id' => 2, + 'domain' => 'w.org', + 'path' => '/', + 'network_id' => 2, ), 'wp.org/' => array( - 'domain' => 'wp.org', - 'path' => '/', - 'site_id' => 2, - 'meta' => array( 'public' => 0 ), + 'domain' => 'wp.org', + 'path' => '/', + 'network_id' => 2, + 'public' => 0, ), 'wp.org/foo/' => array( - 'domain' => 'wp.org', - 'path' => '/foo/', - 'site_id' => 1, - 'meta' => array( 'public' => 0 ), + 'domain' => 'wp.org', + 'path' => '/foo/', + 'network_id' => 1, + 'public' => 0, ), 'wp.org/oof/' => array( 'domain' => 'wp.org', diff --git a/tests/phpunit/tests/multisite/wpmuValidateBlogSignup.php b/tests/phpunit/tests/multisite/wpmuValidateBlogSignup.php index a635287b14..42e77a128c 100644 --- a/tests/phpunit/tests/multisite/wpmuValidateBlogSignup.php +++ b/tests/phpunit/tests/multisite/wpmuValidateBlogSignup.php @@ -34,9 +34,9 @@ if ( is_multisite() ) : self::$existing_blog_id = $factory->blog->create( array( - 'domain' => $domain, - 'path' => $path, - 'site_id' => $network->id, + 'domain' => $domain, + 'path' => $path, + 'network_id' => $network->id, ) ); } diff --git a/tests/phpunit/tests/option/multisite.php b/tests/phpunit/tests/option/multisite.php index 6d1d256325..a837053385 100644 --- a/tests/phpunit/tests/option/multisite.php +++ b/tests/phpunit/tests/option/multisite.php @@ -104,9 +104,7 @@ if ( is_multisite() ) : $blog_id = self::factory()->blog->create( array( 'user_id' => $user_id, - 'meta' => array( - 'public' => 1, - ), + 'public' => 1, ) ); $this->assertInternalType( 'integer', $blog_id ); diff --git a/tests/phpunit/tests/user/getActiveBlogForUser.php b/tests/phpunit/tests/user/getActiveBlogForUser.php index c6a04b5ea6..642b5a3daf 100644 --- a/tests/phpunit/tests/user/getActiveBlogForUser.php +++ b/tests/phpunit/tests/user/getActiveBlogForUser.php @@ -83,7 +83,7 @@ if ( is_multisite() ) : $site_id = self::factory()->blog->create( array( 'user_id' => self::$user_id, - 'meta' => array( 'spam' => 1 ), + 'spam' => 1, ) ); diff --git a/tests/phpunit/tests/user/multisite.php b/tests/phpunit/tests/user/multisite.php index 9e31661253..dceee52505 100644 --- a/tests/phpunit/tests/user/multisite.php +++ b/tests/phpunit/tests/user/multisite.php @@ -122,15 +122,12 @@ if ( is_multisite() ) : $this->assertTrue( is_blog_user() ); $this->assertTrue( is_blog_user( get_current_blog_id() ) ); - $blog_ids = array(); + $blog_id = self::factory()->blog->create( array( 'user_id' => get_current_user_id() ) ); - $blog_ids = self::factory()->blog->create_many( 1 ); - foreach ( $blog_ids as $blog_id ) { - $this->assertInternalType( 'int', $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->assertInternalType( 'int', $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 ); } @@ -157,34 +154,33 @@ if ( is_multisite() ) : $this->assertTrue( is_user_member_of_blog( $user1_id ) ); $this->assertTrue( is_user_member_of_blog( $user1_id, $site_id ) ); - $blog_ids = self::factory()->blog->create_many( 1 ); - foreach ( $blog_ids as $blog_id ) { - $this->assertInternalType( 'int', $blog_id ); + $blog_id = self::factory()->blog->create( array( 'user_id' => get_current_user_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 ) ); + $this->assertInternalType( 'int', $blog_id ); - switch_to_blog( $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 ) ); - $this->assertTrue( is_user_member_of_blog( $user1_id ) ); - $this->assertFalse( is_user_member_of_blog( $user2_id ) ); + switch_to_blog( $blog_id ); - // Remove user 1 from blog - $this->assertTrue( remove_user_from_blog( $user1_id, $blog_id ) ); + $this->assertTrue( is_user_member_of_blog( $user1_id ) ); + $this->assertFalse( is_user_member_of_blog( $user2_id ) ); - // Add user 2 to blog - $this->assertTrue( add_user_to_blog( $blog_id, $user2_id, 'subscriber' ) ); + // Remove user 1 from blog + $this->assertTrue( remove_user_from_blog( $user1_id, $blog_id ) ); - $this->assertFalse( is_user_member_of_blog( $user1_id ) ); - $this->assertTrue( is_user_member_of_blog( $user2_id ) ); + // Add user 2 to blog + $this->assertTrue( add_user_to_blog( $blog_id, $user2_id, 'subscriber' ) ); - restore_current_blog(); + $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, $blog_id ) ); - $this->assertTrue( is_user_member_of_blog( $user2_id, $blog_id ) ); - } + 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 ) ); wpmu_delete_user( $user1_id ); $user = new WP_User( $user1_id );