- Timestamp:
- 11/30/2017 11:09:33 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/multisite/wpmuValidateBlogSignup.php
r42200 r42343 3 3 if ( is_multisite() ) : 4 4 5 /**6 * @group multisite7 */8 class Tests_Multisite_WpmuValidateBlogSignup extends WP_UnitTestCase {9 protected static $super_admin_id;5 /** 6 * @group multisite 7 */ 8 class Tests_Multisite_WpmuValidateBlogSignup extends WP_UnitTestCase { 9 protected static $super_admin_id; 10 10 11 protected static $existing_user_login = 'existinguserfoo';12 protected static $existing_user_id;11 protected static $existing_user_login = 'existinguserfoo'; 12 protected static $existing_user_id; 13 13 14 protected static $existing_blog_name = 'existingsitefoo';15 protected static $existing_blog_id;14 protected static $existing_blog_name = 'existingsitefoo'; 15 protected static $existing_blog_id; 16 16 17 protected $minimum_site_name_length = 4;17 protected $minimum_site_name_length = 4; 18 18 19 public static function wpSetUpBeforeClass( $factory ) {20 self::$super_admin_id = $factory->user->create();21 grant_super_admin( self::$super_admin_id );19 public static function wpSetUpBeforeClass( $factory ) { 20 self::$super_admin_id = $factory->user->create(); 21 grant_super_admin( self::$super_admin_id ); 22 22 23 self::$existing_user_id = $factory->user->create( array( 'user_login' => self::$existing_user_login ) );23 self::$existing_user_id = $factory->user->create( array( 'user_login' => self::$existing_user_login ) ); 24 24 25 $network = get_network();25 $network = get_network(); 26 26 27 if ( is_subdomain_install() ) { 28 $domain = self::$existing_blog_name . '.' . preg_replace( '|^www\.|', '', $network->domain ); 29 $path = $network->path; 30 } else { 31 $domain = $network->domain; 32 $path = $network->path . self::$existing_blog_name . '/'; 27 if ( is_subdomain_install() ) { 28 $domain = self::$existing_blog_name . '.' . preg_replace( '|^www\.|', '', $network->domain ); 29 $path = $network->path; 30 } else { 31 $domain = $network->domain; 32 $path = $network->path . self::$existing_blog_name . '/'; 33 } 34 35 self::$existing_blog_id = $factory->blog->create( 36 array( 37 'domain' => $domain, 38 'path' => $path, 39 'site_id' => $network->id, 40 ) 41 ); 33 42 } 34 43 35 self::$existing_blog_id = $factory->blog->create( array( 36 'domain' => $domain, 37 'path' => $path, 38 'site_id' => $network->id, 39 ) ); 40 } 44 public static function wpTearDownAfterClass() { 45 revoke_super_admin( self::$super_admin_id ); 46 wpmu_delete_user( self::$super_admin_id ); 41 47 42 public static function wpTearDownAfterClass() { 43 revoke_super_admin( self::$super_admin_id ); 44 wpmu_delete_user( self::$super_admin_id ); 48 wpmu_delete_user( self::$existing_user_id ); 45 49 46 wpmu_delete_user( self::$existing_user_id ); 47 48 wpmu_delete_blog( self::$existing_blog_id, true ); 49 } 50 51 /** 52 * @dataProvider data_validate_blogname 53 */ 54 public function test_validate_blogname( $blog_name, $error_message ) { 55 $result = wpmu_validate_blog_signup( $blog_name, 'Foo Site Title', get_userdata( self::$super_admin_id ) ); 56 $this->assertContains( 'blogname', $result['errors']->get_error_codes(), $error_message ); 57 } 58 59 public function data_validate_blogname() { 60 $data = array( 61 array( '', 'Site names must not be empty.' ), 62 array( 'foo-hello', 'Site names must not contain hyphens.' ), 63 array( 'foo_hello', 'Site names must not contain underscores.' ), 64 array( 'foo hello', 'Site names must not contain spaces.' ), 65 array( 'FooHello', 'Site names must not contain uppercase letters.' ), 66 array( '12345678', 'Site names must not consist of numbers only.' ), 67 array( self::$existing_blog_name, 'Site names must not collide with an existing site name.' ), 68 array( self::$existing_user_login, 'Site names must not collide with an existing user login.' ), 69 array( 'foo', 'Site names must at least contain 4 characters.' ), 70 ); 71 72 $illegal_names = get_site_option( 'illegal_names' ); 73 if ( ! empty( $illegal_names ) ) { 74 $data[] = array( array_shift( $illegal_names ), 'Illegal site names are not allowed.' ); 75 } else { 76 $data[] = array( 'www', 'Illegal site names are not allowed.' ); 50 wpmu_delete_blog( self::$existing_blog_id, true ); 77 51 } 78 52 79 return $data; 80 } 53 /** 54 * @dataProvider data_validate_blogname 55 */ 56 public function test_validate_blogname( $blog_name, $error_message ) { 57 $result = wpmu_validate_blog_signup( $blog_name, 'Foo Site Title', get_userdata( self::$super_admin_id ) ); 58 $this->assertContains( 'blogname', $result['errors']->get_error_codes(), $error_message ); 59 } 81 60 82 public function test_validate_empty_blog_title() { 83 $result = wpmu_validate_blog_signup( 'uniqueblogname1234', '', get_userdata( self::$super_admin_id ) ); 84 $this->assertContains( 'blog_title', $result['errors']->get_error_codes(), 'Site titles must not be empty.' ); 85 } 61 public function data_validate_blogname() { 62 $data = array( 63 array( '', 'Site names must not be empty.' ), 64 array( 'foo-hello', 'Site names must not contain hyphens.' ), 65 array( 'foo_hello', 'Site names must not contain underscores.' ), 66 array( 'foo hello', 'Site names must not contain spaces.' ), 67 array( 'FooHello', 'Site names must not contain uppercase letters.' ), 68 array( '12345678', 'Site names must not consist of numbers only.' ), 69 array( self::$existing_blog_name, 'Site names must not collide with an existing site name.' ), 70 array( self::$existing_user_login, 'Site names must not collide with an existing user login.' ), 71 array( 'foo', 'Site names must at least contain 4 characters.' ), 72 ); 86 73 87 public function test_validate_blogname_from_same_existing_user() { 88 $result = wpmu_validate_blog_signup( self::$existing_user_login, 'Foo Site Title', get_userdata( self::$existing_user_id ) ); 89 $this->assertEmpty( $result['errors']->get_error_codes() ); 90 } 74 $illegal_names = get_site_option( 'illegal_names' ); 75 if ( ! empty( $illegal_names ) ) { 76 $data[] = array( array_shift( $illegal_names ), 'Illegal site names are not allowed.' ); 77 } else { 78 $data[] = array( 'www', 'Illegal site names are not allowed.' ); 79 } 91 80 92 /** 93 * @ticket 39676 94 * 95 * @dataProvider data_filter_minimum_site_name_length 96 */ 97 public function test_filter_minimum_site_name_length( $site_name, $minimum_length, $expect_error ) { 98 $this->minimum_site_name_length = $minimum_length; 99 add_filter( 'minimum_site_name_length', array( $this, 'filter_minimum_site_name_length' ) ); 81 return $data; 82 } 100 83 101 $result = wpmu_validate_blog_signup( $site_name, 'Site Title', get_userdata( self::$super_admin_id ) ); 84 public function test_validate_empty_blog_title() { 85 $result = wpmu_validate_blog_signup( 'uniqueblogname1234', '', get_userdata( self::$super_admin_id ) ); 86 $this->assertContains( 'blog_title', $result['errors']->get_error_codes(), 'Site titles must not be empty.' ); 87 } 102 88 103 remove_filter( 'minimum_site_name_length', array( $this, 'filter_minimum_site_name_length' ) ); 104 $this->minimum_site_name_length = 4; 89 public function test_validate_blogname_from_same_existing_user() { 90 $result = wpmu_validate_blog_signup( self::$existing_user_login, 'Foo Site Title', get_userdata( self::$existing_user_id ) ); 91 $this->assertEmpty( $result['errors']->get_error_codes() ); 92 } 105 93 106 if ( $expect_error ) { 107 $this->assertContains( 'blogname', $result['errors']->get_error_codes() ); 108 } else { 109 $this->assertEmpty( $result['errors']->get_error_codes() ); 94 /** 95 * @ticket 39676 96 * 97 * @dataProvider data_filter_minimum_site_name_length 98 */ 99 public function test_filter_minimum_site_name_length( $site_name, $minimum_length, $expect_error ) { 100 $this->minimum_site_name_length = $minimum_length; 101 add_filter( 'minimum_site_name_length', array( $this, 'filter_minimum_site_name_length' ) ); 102 103 $result = wpmu_validate_blog_signup( $site_name, 'Site Title', get_userdata( self::$super_admin_id ) ); 104 105 remove_filter( 'minimum_site_name_length', array( $this, 'filter_minimum_site_name_length' ) ); 106 $this->minimum_site_name_length = 4; 107 108 if ( $expect_error ) { 109 $this->assertContains( 'blogname', $result['errors']->get_error_codes() ); 110 } else { 111 $this->assertEmpty( $result['errors']->get_error_codes() ); 112 } 113 } 114 115 public function data_filter_minimum_site_name_length() { 116 return array( 117 array( 'fooo', 5, true ), 118 array( 'foooo', 5, false ), 119 array( 'foo', 4, true ), 120 array( 'fooo', 4, false ), 121 array( 'fo', 3, true ), 122 array( 'foo', 3, false ), 123 ); 124 } 125 126 public function filter_minimum_site_name_length() { 127 return $this->minimum_site_name_length; 110 128 } 111 129 } 112 130 113 public function data_filter_minimum_site_name_length() {114 return array(115 array( 'fooo', 5, true ),116 array( 'foooo', 5, false ),117 array( 'foo', 4, true ),118 array( 'fooo', 4, false ),119 array( 'fo', 3, true ),120 array( 'foo', 3, false ),121 );122 }123 124 public function filter_minimum_site_name_length() {125 return $this->minimum_site_name_length;126 }127 }128 129 131 endif;
Note: See TracChangeset
for help on using the changeset viewer.