summaryrefslogtreecommitdiff
path: root/_test
diff options
context:
space:
mode:
authorAndreas Gohr <andi@splitbrain.org>2008-10-07 23:14:09 +0200
committerAndreas Gohr <andi@splitbrain.org>2008-10-07 23:14:09 +0200
commit98c44df4102c7df2385f5cee0dcc7d1ba2e823ff (patch)
tree07e0330b2edbd2b1c4e9ea512a45c2d120162611 /_test
parenta14197f130933e5df7499d4531ce7b0c2dad0306 (diff)
downloadrpg-98c44df4102c7df2385f5cee0dcc7d1ba2e823ff.tar.gz
rpg-98c44df4102c7df2385f5cee0dcc7d1ba2e823ff.tar.bz2
added more test cases for email checking - 44 passes, 7 fails
darcs-hash:20081007211409-7ad00-d64410ecef91ac4f35ad84fcb98097e8b3d211dc.gz
Diffstat (limited to '_test')
-rw-r--r--_test/cases/inc/mail_isvalid.test.php55
1 files changed, 53 insertions, 2 deletions
diff --git a/_test/cases/inc/mail_isvalid.test.php b/_test/cases/inc/mail_isvalid.test.php
index 7b152ff68..120764e08 100644
--- a/_test/cases/inc/mail_isvalid.test.php
+++ b/_test/cases/inc/mail_isvalid.test.php
@@ -6,12 +6,15 @@ class mail_isvalid extends UnitTestCase {
function test1(){
- // we test multiple cases here - format: string, repl, additional, test
$tests = array();
+
+ // 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',false);
$tests[] = array('.bugs@php.net1',false);
$tests[] = array('bu..gs@php.net',false);
@@ -23,8 +26,56 @@ class mail_isvalid extends UnitTestCase {
$tests[] = array('somebody@somewhere.museum',true);
$tests[] = array('somebody@somewhere.travel',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@example', false);
+ $tests[] = array('test@[123.123.123.123', false);
+ $tests[] = array('test@123.123.123.123]', false);
+
+
foreach($tests as $test){
- $this->assertEqual($test[0].'('.mail_isvalid($test[0]).')',$test[0].'('.(int)$test[1].')');
+ $info = 'Testing '.$test[0];
+ $this->signal('failinfo',$info);
+
+ if($test[1]){
+ $this->assertTrue((bool) mail_isvalid($test[0]));
+ }else{
+ $this->assertFalse((bool) mail_isvalid($test[0]));
+ }
}
}