mirror of
git://develop.git.wordpress.org/
synced 2025-03-15 01:19:51 +01:00
Improve tests for is_email_address_unsafe()
.
* Move to a separate file for better organization and method names. * Use a `dataProvider` when appropriate, for better readability. * Add a test for splitting the banned domain list on line breaks. See #20459, #21730. git-svn-id: https://develop.svn.wordpress.org/trunk@32638 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
7d532968eb
commit
8dced310b1
@ -36,37 +36,6 @@ class Tests_Multisite extends WP_UnitTestCase {
|
||||
$reg_blog = $wpdb->get_col( "SELECT email FROM {$wpdb->registration_log} WHERE {$wpdb->registration_log}.blog_id = 1 AND IP LIKE '" . $ip . "'" );
|
||||
$this->assertEquals( $user->user_email, $reg_blog[ count( $reg_blog )-1 ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 21570
|
||||
*/
|
||||
function test_aggressiveness_of_is_email_address_unsafe() {
|
||||
update_site_option( 'banned_email_domains', array( 'bar.com', 'foo.co' ) );
|
||||
|
||||
foreach ( array( 'test@bar.com', 'test@foo.bar.com', 'test@foo.co', 'test@subdomain.foo.co' ) as $email_address ) {
|
||||
$this->assertTrue( is_email_address_unsafe( $email_address ), "$email_address should be UNSAFE" );
|
||||
}
|
||||
|
||||
foreach ( array( 'test@foobar.com', 'test@foo-bar.com', 'test@foo.com', 'test@subdomain.foo.com' ) as $email_address ) {
|
||||
$this->assertFalse( is_email_address_unsafe( $email_address ), "$email_address should be SAFE" );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 25046
|
||||
*/
|
||||
function test_case_sensitivity_of_is_email_address_unsafe() {
|
||||
update_site_option( 'banned_email_domains', array( 'baR.com', 'Foo.co', 'barfoo.COM', 'BAZ.com' ) );
|
||||
|
||||
foreach ( array( 'test@Bar.com', 'tEst@bar.com', 'test@barFoo.com', 'tEst@foo.bar.com', 'test@baz.Com' ) as $email_address ) {
|
||||
$this->assertTrue( is_email_address_unsafe( $email_address ), "$email_address should be UNSAFE" );
|
||||
}
|
||||
|
||||
foreach ( array( 'test@Foobar.com', 'test@Foo-bar.com', 'tEst@foobar.com', 'test@Subdomain.Foo.com', 'test@fooBAz.com' ) as $email_address ) {
|
||||
$this->assertFalse( is_email_address_unsafe( $email_address ), "$email_address should be SAFE" );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
endif;
|
||||
|
121
tests/phpunit/tests/multisite/isEmailAddressUnsafe.php
Normal file
121
tests/phpunit/tests/multisite/isEmailAddressUnsafe.php
Normal file
@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @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' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @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',
|
||||
),
|
||||
|
||||
|
||||
// 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',
|
||||
),
|
||||
|
||||
// 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',
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user