Changeset 62225
- Timestamp:
- 04/11/2026 02:22:15 PM (6 months ago)
- Location:
- trunk/tests/phpunit/tests/formatting
- Files:
-
- 2 added
- 1 edited
-
antispambot.php (added)
-
isEmail.php (modified) (4 diffs)
-
sanitizeEmail.php (added)
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/formatting/isEmail.php
r61451 r62225 1 1 <?php 2 3 2 /** 3 * Tests for the is_email() function. 4 * 4 5 * @group formatting 5 6 * … … 7 8 */ 8 9 class Tests_Formatting_IsEmail extends WP_UnitTestCase { 9 10 10 /** 11 * @dataProvider valid_email_provider 11 * Ensures that valid emails are returned unchanged. 12 * 13 * @ticket 31992 14 * 15 * @dataProvider data_valid_email_provider 16 * 17 * @param string $email Valid email address. 12 18 */ 13 19 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." ); 20 $this->assertSame( 21 $email, 22 is_email( $email ), 23 'Should return the given email address unchanged when valid.' 24 ); 15 25 } 16 26 17 27 /** 18 * Data provider for valid email addresses.28 * Data provider. 19 29 * 20 * @return array30 * @return Generator 21 31 */ 22 public static function valid_email_provider() {32 public static function data_valid_email_provider() { 23 33 $valid_emails = array( 24 34 'bob@example.com', 25 35 'phil@example.info', 36 'phil@TLA.example', 26 37 'ace@204.32.222.14', 27 38 'kevin@many.subdomains.make.a.happy.man.edu', 28 39 'a@b.co', 29 40 'bill+ted@example.com', 41 '..@example.com', 30 42 ); 31 43 … … 36 48 37 49 /** 38 * @dataProvider invalid_email_provider 50 * Ensures that unrecognized email addresses are rejected. 51 * 52 * @ticket 31992 53 * 54 * @dataProvider data_invalid_email_provider 55 * 56 * @param string $email Invalid or unrecognized-to-WordPress email address. 39 57 */ 40 58 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." ); 59 $this->assertFalse( 60 is_email( $email ), 61 'Should have rejected the email as invalid.' 62 ); 42 63 } 43 64 44 65 /** 45 * Data provider for invalid email addresses.66 * Data provider. 46 67 * 47 * @return array68 * @return Generator 48 69 */ 49 public static function invalid_email_provider() {70 public static function data_invalid_email_provider() { 50 71 $invalid_emails = array( 51 72 'khaaaaaaaaaaaaaaan!', … … 55 76 'bob@your mom', 56 77 'a@b.c', 78 '" "@b.c', 79 '"@"@b.c', 80 'a@route.org@b.c', 81 'h(aj@couc.ou', // bad comment. 82 'hi@', 83 'hi@hi@couc.ou', // double @. 84 85 /* 86 * The next address is not deliverable as described, 87 * SMTP servers should strip the (ab), so it is very 88 * likely a source of confusion or a typo. 89 * Best rejected. 90 */ 91 '(ab)cd@couc.ou', 92 93 /* 94 * The next address is not globally deliverable, 95 * so it may work with PHPMailer and break with 96 * mail sending services. Best not allow users 97 * to paint themselves into that corner. This also 98 * avoids security problems like those that were 99 * used to probe the WordPress server's local 100 * network. 101 */ 102 'toto@to', 103 104 /* 105 * Several addresses are best rejected because 106 * we don't want to allow sending to fe80::, 192.168 107 * and other special addresses; that too might 108 * be used to probe the WordPress server's local 109 * network. 110 */ 111 'to@[2001:db8::1]', 112 'to@[IPv6:2001:db8::1]', 113 'to@[192.168.1.1]', 114 115 /* 116 * Ill-formed UTF-8 byte sequences must be rejected. 117 * A lone continuation byte (0x80) is not valid UTF-8 118 * whether it appears in the local part or the domain. 119 */ 120 "a\x80b@example.com", // invalid UTF-8 in local part. 121 "abc@\x80.org", // invalid UTF-8 in domain subdomain. 57 122 ); 58 123
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)