Skip to content

Commit 5a53b94

Browse files
Tests: Refactor is_email() tests to use a data provider.
Follow-up to [121/tests], [401/tests]. Props salcode, geekofshire, swissspidy, iseulde, miqrogroove, SergeyBiryukov. Fixes #31313. git-svn-id: https://develop.svn.wordpress.org/trunk@61451 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 425bc36 commit 5a53b94

File tree

1 file changed

+35
-8
lines changed

1 file changed

+35
-8
lines changed

tests/phpunit/tests/formatting/isEmail.php

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,58 @@
66
* @covers ::is_email
77
*/
88
class Tests_Formatting_IsEmail extends WP_UnitTestCase {
9-
public function test_returns_the_email_address_if_it_is_valid() {
10-
$data = array(
9+
10+
/**
11+
* @dataProvider valid_email_provider
12+
*/
13+
public function test_returns_the_email_address_if_it_is_valid( $email ) {
14+
$this->assertSame( $email, is_email( $email ), "is_email() should return the email address for $email." );
15+
}
16+
17+
/**
18+
* Data provider for valid email addresses.
19+
*
20+
* @return array
21+
*/
22+
public static function valid_email_provider() {
23+
$valid_emails = array(
1124
1225
1326
1427
1528
1629
1730
);
18-
foreach ( $data as $datum ) {
19-
$this->assertSame( $datum, is_email( $datum ), $datum );
31+
32+
foreach ( $valid_emails as $email ) {
33+
yield $email => array( $email );
2034
}
2135
}
2236

23-
public function test_returns_false_if_given_an_invalid_email_address() {
24-
$data = array(
37+
/**
38+
* @dataProvider invalid_email_provider
39+
*/
40+
public function test_returns_false_if_given_an_invalid_email_address( $email ) {
41+
$this->assertFalse( is_email( $email ), "is_email() should return false for $email." );
42+
}
43+
44+
/**
45+
* Data provider for invalid email addresses.
46+
*
47+
* @return array
48+
*/
49+
public static function invalid_email_provider() {
50+
$invalid_emails = array(
2551
'khaaaaaaaaaaaaaaan!',
2652
'http://bob.example.com/',
2753
"sif i'd give u it, spamer!1",
2854
'com.exampleNOSPAMbob',
2955
'bob@your mom',
3056
3157
);
32-
foreach ( $data as $datum ) {
33-
$this->assertFalse( is_email( $datum ), $datum );
58+
59+
foreach ( $invalid_emails as $email ) {
60+
yield $email => array( $email );
3461
}
3562
}
3663
}

0 commit comments

Comments
 (0)