Use a dataProvider for network option sanitization tests.
Cleans up tests for sanitization of `illegal_names`, `illegal_email_domains`, and `banned_email_domains` network options. Fixes #32517. git-svn-id: https://develop.svn.wordpress.org/trunk@32634 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
abd407a9ea
commit
c12e7d763c
@ -182,30 +182,56 @@ class Tests_Multisite_Option extends WP_UnitTestCase {
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 21552
|
||||
* @ticket 23418
|
||||
* @dataProvider data_illegal_names
|
||||
*/
|
||||
function test_sanitize_ms_options() {
|
||||
update_site_option( 'illegal_names', array( '', 'Woo', '' ) );
|
||||
update_site_option( 'limited_email_domains', array( 'woo', '', 'boo.com', 'foo.net.biz..' ) );
|
||||
update_site_option( 'banned_email_domains', array( 'woo', '', 'boo.com', 'foo.net.biz..' ) );
|
||||
function test_sanitize_network_option_illegal_names( $option_value, $sanitized_option_value ) {
|
||||
update_site_option( 'illegal_names', $option_value );
|
||||
$this->assertEquals( $sanitized_option_value, get_site_option( 'illegal_names' ) );
|
||||
}
|
||||
|
||||
$this->assertEquals( array( 'Woo' ), get_site_option( 'illegal_names' ) );
|
||||
$this->assertEquals( array( 'woo', 'boo.com' ), get_site_option( 'limited_email_domains' ) );
|
||||
$this->assertEquals( array( 'woo', 'boo.com' ), get_site_option( 'banned_email_domains' ) );
|
||||
function data_illegal_names() {
|
||||
return array(
|
||||
array( array( '', 'Woo', '' ), array( 'Woo' ) ),
|
||||
array( 'foo bar', array( 'foo', 'bar' ) ),
|
||||
array( array(), '' ),
|
||||
);
|
||||
}
|
||||
|
||||
update_site_option( 'illegal_names', 'foo bar' );
|
||||
update_site_option( 'limited_email_domains', "foo\nbar" );
|
||||
update_site_option( 'banned_email_domains', "foo\nbar" );
|
||||
/**
|
||||
* @dataProvider data_email_domains
|
||||
*
|
||||
* @param $option_value
|
||||
* @param $sanitized_option_value
|
||||
*/
|
||||
function test_sanitize_network_option_limited_email_domains( $option_value, $sanitized_option_value ) {
|
||||
update_site_option( 'limited_email_domains', $option_value );
|
||||
$this->assertEquals( $sanitized_option_value, get_site_option( 'limited_email_domains' ) );
|
||||
}
|
||||
|
||||
$this->assertEquals( array( 'foo', 'bar' ), get_site_option( 'illegal_names' ) );
|
||||
$this->assertEquals( array( 'foo', 'bar' ), get_site_option( 'limited_email_domains' ) );
|
||||
$this->assertEquals( array( 'foo', 'bar' ), get_site_option( 'banned_email_domains' ) );
|
||||
/**
|
||||
* @dataProvider data_email_domains
|
||||
*
|
||||
* @param $option_value
|
||||
* @param $sanitized_option_value
|
||||
*/
|
||||
function test_sanitize_network_option_banned_email_domains( $option_value, $sanitized_option_value ) {
|
||||
update_site_option( 'banned_email_domains', $option_value );
|
||||
$this->assertEquals( $sanitized_option_value, get_site_option( 'banned_email_domains' ) );
|
||||
}
|
||||
|
||||
foreach ( array( 'illegal_names', 'limited_email_domains', 'banned_email_domains' ) as $option ) {
|
||||
update_site_option( $option, array() );
|
||||
$this->assertSame( '', get_site_option( $option ) );
|
||||
}
|
||||
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(), '' ),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user