Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F4098608
SanitizerValidateEmailTest.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
SanitizerValidateEmailTest.php
View Options
<?php
namespace
MediaWiki\Tests\Parser
;
use
MediaWiki\Parser\Sanitizer
;
use
MediaWikiIntegrationTestCase
;
/**
* @covers \MediaWiki\Parser\Sanitizer::validateEmail
* @todo should be made a pure unit test once ::validateEmail is migrated to proper DI
*/
class
SanitizerValidateEmailTest
extends
MediaWikiIntegrationTestCase
{
public
static
function
provideValidEmails
()
{
yield
'normal #1'
=>
[
'user@example.com'
];
yield
'normal #2'
=>
[
'user@example.museum'
];
yield
'with uppercase #1'
=>
[
'USER@example.com'
];
yield
'with uppercase #2'
=>
[
'user@EXAMPLE.COM'
];
yield
'with uppercase #3'
=>
[
'user@Example.com'
];
yield
'with uppercase #4'
=>
[
'USER@eXAMPLE.com'
];
yield
'with plus #1'
=>
[
'user+sub@example.com'
];
yield
'with plus #2'
=>
[
'user+@example.com'
];
yield
'TLD not neeeded #1'
=>
[
"user@localhost"
];
yield
'TLD not neeeded #2'
=>
[
"FooBar@localdomain"
];
yield
'TLD not neeeded #3'
=>
[
"nobody@mycompany"
];
yield
'with hythen #1'
=>
[
"user-foo@example.org"
];
yield
'with hythen #2'
=>
[
"userfoo@ex-ample.org"
];
yield
'email with dot #1'
=>
[
"user.@localdomain"
];
yield
'email with dot #2'
=>
[
".@localdomain"
];
yield
'funny characters'
=>
[
"
\$
user!ex{this}@123.com"
];
yield
'numerical TLD'
=>
[
"user@example.1234"
];
yield
'only one character needed'
=>
[
'user@a'
];
}
/**
* @dataProvider provideValidEmails
*/
public
function
testValidateEmail_valid
(
string
$addr
)
{
$this
->
assertTrue
(
Sanitizer
::
validateEmail
(
$addr
)
);
}
public
static
function
provideInvalidEmails
()
{
yield
'whitespace before #1'
=>
[
" user@host.com"
];
yield
'whitespace before #2'
=>
[
"
\t
user@host.com"
];
yield
'whitespace after #1'
=>
[
"user@host.com "
];
yield
'whitespace after #2'
=>
[
"user@host.com
\t
"
];
yield
'with whitespace #1'
=>
[
"User user@host"
];
yield
'with whitespace #2'
=>
[
"first last@mycompany"
];
yield
'with whitespace #3'
=>
[
"firstlast@my company"
];
// T28948 : comma were matched by an incorrect regexp range
yield
'invalid comma #1'
=>
[
"user,foo@example.org"
];
yield
'invalid comma #2'
=>
[
"userfoo@ex,ample.org"
];
yield
'domain beginning with dot #1'
=>
[
"user@."
];
yield
'domain beginning with dot #2'
=>
[
"user@.localdomain"
];
yield
'domain beginning with dot #3'
=>
[
"user@localdomain."
];
yield
'domain beginning with dot #4'
=>
[
".@a............"
];
yield
'missing @'
=>
[
'userà example.com'
];
}
/**
* @dataProvider provideInvalidEmails
*/
public
function
testValidateEmail_invalid
(
string
$addr
)
{
$this
->
assertFalse
(
Sanitizer
::
validateEmail
(
$addr
)
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Tue, Aug 18, 15:26 (3 w, 5 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
c5/34/717672a3847799a15e1ae9d79be4
Default Alt Text
SanitizerValidateEmailTest.php (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment