Skip to content
Snippets Groups Projects
Commit 2b4287aa authored by Andreas Gohr's avatar Andreas Gohr
Browse files

refomatted mail tests to use data provider

parent 61e35c35
No related branches found
No related tags found
No related merge requests found
<?php
class mail_isvalid extends DokuWikiTest {
class mail_isvalid_test extends DokuWikiTest {
public function provider() {
return array(
// our own tests
array('bugs@php.net', true),
array('~someone@somewhere.com', true),
array('no+body.here@somewhere.com.au', true),
array('username+tag@domain.com', true), // FS#1447
array("rfc2822+allthesechars_#*!'`/-={}are.legal@somewhere.com.au", true),
array('_foo@test.com', true), // FS#1049
array('bugs@php.net1', true), // new ICAN rulez seem to allow this
array('.bugs@php.net1', false),
array('bu..gs@php.net', false),
array('bugs@php..net', false),
array('bugs@.php.net', false),
array('bugs@php.net.', false),
array('bu(g)s@php.net1', false),
array('bu[g]s@php.net1', false),
array('somebody@somewhere.museum', true),
array('somebody@somewhere.travel', true),
array('root@[2010:fb:fdac::311:2101]', true),
array('test@example', true), // we allow local addresses
function test1(){
$tests = array();
// tests from http://code.google.com/p/php-email-address-validation/ below
// our own tests
$tests[] = array('bugs@php.net',true);
$tests[] = array('~someone@somewhere.com',true);
$tests[] = array('no+body.here@somewhere.com.au',true);
$tests[] = array('username+tag@domain.com',true); // FS#1447
$tests[] = array("rfc2822+allthesechars_#*!'`/-={}are.legal@somewhere.com.au",true);
$tests[] = array('_foo@test.com',true); // FS#1049
$tests[] = array('bugs@php.net1',true); // new ICAN rulez seem to allow this
$tests[] = array('.bugs@php.net1',false);
$tests[] = array('bu..gs@php.net',false);
$tests[] = array('bugs@php..net',false);
$tests[] = array('bugs@.php.net',false);
$tests[] = array('bugs@php.net.',false);
$tests[] = array('bu(g)s@php.net1',false);
$tests[] = array('bu[g]s@php.net1',false);
$tests[] = array('somebody@somewhere.museum',true);
$tests[] = array('somebody@somewhere.travel',true);
$tests[] = array('root@[2010:fb:fdac::311:2101]',true);
$tests[] = array('test@example', true); // we allow local addresses
array('test@example.com', true),
array('TEST@example.com', true),
array('1234567890@example.com', true),
array('test+test@example.com', true),
array('test-test@example.com', true),
array('t*est@example.com', true),
array('+1~1+@example.com', true),
array('{_test_}@example.com', true),
array('"[[ test ]]"@example.com', true),
array('test.test@example.com', true),
array('test."test"@example.com', true),
array('"test@test"@example.com', true),
array('test@123.123.123.123', true),
array('test@[123.123.123.123]', true),
array('test@example.example.com', true),
array('test@example.example.example.com', true),
// tests from http://code.google.com/p/php-email-address-validation/ below
$tests[] = array('test@example.com', true);
$tests[] = array('TEST@example.com', true);
$tests[] = array('1234567890@example.com', true);
$tests[] = array('test+test@example.com', true);
$tests[] = array('test-test@example.com', true);
$tests[] = array('t*est@example.com', true);
$tests[] = array('+1~1+@example.com', true);
$tests[] = array('{_test_}@example.com', true);
$tests[] = array('"[[ test ]]"@example.com', true);
$tests[] = array('test.test@example.com', true);
$tests[] = array('test."test"@example.com', true);
$tests[] = array('"test@test"@example.com', true);
$tests[] = array('test@123.123.123.123', true);
$tests[] = array('test@[123.123.123.123]', true);
$tests[] = array('test@example.example.com', true);
$tests[] = array('test@example.example.example.com', true);
$tests[] = array('test.example.com', false);
$tests[] = array('test.@example.com', false);
$tests[] = array('test..test@example.com', false);
$tests[] = array('.test@example.com', false);
$tests[] = array('test@test@example.com', false);
$tests[] = array('test@@example.com', false);
$tests[] = array('-- test --@example.com', false); // No spaces allowed in local part
$tests[] = array('[test]@example.com', false); // Square brackets only allowed within quotes
$tests[] = array('"test\test"@example.com', false); // Quotes cannot contain backslash
$tests[] = array('"test"test"@example.com', false); // Quotes cannot be nested
$tests[] = array('()[]\;:,<>@example.com', false); // Disallowed Characters
$tests[] = array('test@.', false);
$tests[] = array('test@example.', false);
$tests[] = array('test@.org', false);
$tests[] = array('12345678901234567890123456789012345678901234567890123456789012345@example.com', false); // 64 characters is maximum length for local part. This is 65.
$tests[] = array('test@123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012.com', false); // 255 characters is maximum length for domain. This is 256.
$tests[] = array('test@[123.123.123.123', false);
$tests[] = array('test@123.123.123.123]', false);
foreach($tests as $test){
$info = 'Testing '.$test[0];
if($test[1]){
$this->assertTrue((bool) mail_isvalid($test[0]), $info);
}else{
$this->assertFalse((bool) mail_isvalid($test[0]), $info);
}
}
array('test.example.com', false),
array('test.@example.com', false),
array('test..test@example.com', false),
array('.test@example.com', false),
array('test@test@example.com', false),
array('test@@example.com', false),
array('-- test --@example.com', false), // No spaces allowed in local part
array('[test]@example.com', false), // Square brackets only allowed within quotes
array('"test\test"@example.com', false), // Quotes cannot contain backslash
array('"test"test"@example.com', false), // Quotes cannot be nested
array('()[]\;:,<>@example.com', false), // Disallowed Characters
array('test@.', false),
array('test@example.', false),
array('test@.org', false),
array('12345678901234567890123456789012345678901234567890123456789012345@example.com', false), // 64 characters is maximum length for local part. This is 65.
array('test@123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012.com', false), // 255 characters is maximum length for domain. This is 256.
array('test@[123.123.123.123', false),
array('test@123.123.123.123]', false),
);
}
/**
* @dataProvider provider
* @param string $input
* @param bool $success
*/
function test1($input, $success) {
$result = mail_isvalid($input);
$this->assertSame($success, $result);
}
}
//Setup VIM: ex: et ts=4 :
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment