| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Tests\Parser; |
| 4 |
|
| 5 |
use MediaWiki\Parser\Sanitizer; |
| 6 |
use MediaWikiIntegrationTestCase; |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
class SanitizerValidateEmailTest extends MediaWikiIntegrationTestCase { |
| 13 |
|
| 14 |
public static function provideValidEmails() { |
| 15 |
yield 'normal #1' => [ '[email protected]' ]; |
| 16 |
yield 'normal #2' => [ '[email protected]' ]; |
| 17 |
yield 'with uppercase #1' => [ '[email protected]' ]; |
| 18 |
yield 'with uppercase #2' => [ '[email protected]' ]; |
| 19 |
yield 'with uppercase #3' => [ '[email protected]' ]; |
| 20 |
yield 'with uppercase #4' => [ '[email protected]' ]; |
| 21 |
yield 'with plus #1' => [ '[email protected]' ]; |
| 22 |
yield 'with plus #2' => [ '[email protected]' ]; |
| 23 |
yield 'TLD not neeeded #1' => [ "user@localhost" ]; |
| 24 |
yield 'TLD not neeeded #2' => [ "FooBar@localdomain" ]; |
| 25 |
yield 'TLD not neeeded #3' => [ "nobody@mycompany" ]; |
| 26 |
|
| 27 |
yield 'with hythen #1' => [ "[email protected]" ]; |
| 28 |
yield 'with hythen #2' => [ "[email protected]" ]; |
| 29 |
|
| 30 |
yield 'email with dot #1' => [ "user.@localdomain" ]; |
| 31 |
yield 'email with dot #2' => [ ".@localdomain" ]; |
| 32 |
|
| 33 |
yield 'funny characters' => [ "\$user!ex{this}@123.com" ]; |
| 34 |
yield 'numerical TLD' => [ "[email protected]" ]; |
| 35 |
yield 'only one character needed' => [ 'user@a' ]; |
| 36 |
} |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
public function testValidateEmail_valid( string $addr ) { |
| 42 |
$this->assertTrue( Sanitizer::validateEmail( $addr ) ); |
| 43 |
} |
| 44 |
|
| 45 |
public static function provideInvalidEmails() { |
| 46 |
yield 'whitespace before #1' => [ " [email protected]" ]; |
| 47 |
yield 'whitespace before #2' => [ "\t[email protected]" ]; |
| 48 |
yield 'whitespace after #1' => [ "[email protected] " ]; |
| 49 |
yield 'whitespace after #2' => [ "[email protected]\t" ]; |
| 50 |
yield 'with whitespace #1' => [ "User user@host" ]; |
| 51 |
yield 'with whitespace #2' => [ "first last@mycompany" ]; |
| 52 |
yield 'with whitespace #3' => [ "firstlast@my company" ]; |
| 53 |
|
| 54 |
|
| 55 |
yield 'invalid comma #1' => [ "user,[email protected]" ]; |
| 56 |
yield 'invalid comma #2' => [ "userfoo@ex,ample.org" ]; |
| 57 |
|
| 58 |
yield 'domain beginning with dot #1' => [ "user@." ]; |
| 59 |
yield 'domain beginning with dot #2' => [ "[email protected]" ]; |
| 60 |
yield 'domain beginning with dot #3' => [ "user@localdomain." ]; |
| 61 |
yield 'domain beginning with dot #4' => [ ".@a............" ]; |
| 62 |
|
| 63 |
yield 'missing @' => [ 'userà example.com' ]; |
| 64 |
} |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
public function testValidateEmail_invalid( string $addr ) { |
| 70 |
$this->assertFalse( Sanitizer::validateEmail( $addr ) ); |
| 71 |
} |
| 72 |
} |