From 169c32723f861e42b09bb6031bdec1a402851631 Mon Sep 17 00:00:00 2001 From: Felix Arntz Date: Fri, 17 Mar 2017 14:14:14 +0000 Subject: [PATCH] Multisite: Provide unit tests for `wpmu_validate_blog_signup()`. See #39676. git-svn-id: https://develop.svn.wordpress.org/trunk@40294 602fd350-edb4-49c9-b593-d223f7449a82 --- .../multisite/wpmuValidateBlogSignup.php | 94 +++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100755 tests/phpunit/tests/multisite/wpmuValidateBlogSignup.php diff --git a/tests/phpunit/tests/multisite/wpmuValidateBlogSignup.php b/tests/phpunit/tests/multisite/wpmuValidateBlogSignup.php new file mode 100755 index 0000000000..eee18ab119 --- /dev/null +++ b/tests/phpunit/tests/multisite/wpmuValidateBlogSignup.php @@ -0,0 +1,94 @@ +user->create(); + grant_super_admin( self::$super_admin_id ); + + self::$existing_user_id = $factory->user->create( array( 'user_login' => self::$existing_user_login ) ); + + $network = get_network(); + + 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 . '/'; + } + + self::$existing_blog_id = $factory->blog->create( array( + 'domain' => $domain, + 'path' => $path, + 'site_id' => $network->id, + ) ); + } + + public static function wpTearDownAfterClass() { + revoke_super_admin( self::$super_admin_id ); + wpmu_delete_user( self::$super_admin_id ); + + wpmu_delete_user( self::$existing_user_id ); + + wpmu_delete_blog( self::$existing_blog_id, true ); + } + + /** + * @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 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.' ), + ); + + if ( ! is_super_admin() ) { + $data[] = 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; + } + + 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 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() ); + } +} + +endif;