xref: /dokuwiki/_test/tests/inc/mail_isvalid.test.php (revision ab090718d52f2360b769f039b1bf5f496f23097f)
1<?php
2
3class mail_isvalid extends DokuWikiTest {
4
5
6    function test1(){
7        $tests   = array();
8
9        // our own tests
10        $tests[] = array('bugs@php.net',true);
11        $tests[] = array('~someone@somewhere.com',true);
12        $tests[] = array('no+body.here@somewhere.com.au',true);
13        $tests[] = array('username+tag@domain.com',true); // FS#1447
14        $tests[] = array("rfc2822+allthesechars_#*!'`/-={}are.legal@somewhere.com.au",true);
15        $tests[] = array('_foo@test.com',true); // FS#1049
16        $tests[] = array('bugs@php.net1',true); // new ICAN rulez seem to allow this
17        $tests[] = array('.bugs@php.net1',false);
18        $tests[] = array('bu..gs@php.net',false);
19        $tests[] = array('bugs@php..net',false);
20        $tests[] = array('bugs@.php.net',false);
21        $tests[] = array('bugs@php.net.',false);
22        $tests[] = array('bu(g)s@php.net1',false);
23        $tests[] = array('bu[g]s@php.net1',false);
24        $tests[] = array('somebody@somewhere.museum',true);
25        $tests[] = array('somebody@somewhere.travel',true);
26        $tests[] = array('root@[2010:fb:fdac::311:2101]',true);
27        $tests[] = array('test@example', true); // we allow local addresses
28
29        // tests from http://code.google.com/p/php-email-address-validation/ below
30
31        $tests[] = array('test@example.com', true);
32        $tests[] = array('TEST@example.com', true);
33        $tests[] = array('1234567890@example.com', true);
34        $tests[] = array('test+test@example.com', true);
35        $tests[] = array('test-test@example.com', true);
36        $tests[] = array('t*est@example.com', true);
37        $tests[] = array('+1~1+@example.com', true);
38        $tests[] = array('{_test_}@example.com', true);
39        $tests[] = array('"[[ test ]]"@example.com', true);
40        $tests[] = array('test.test@example.com', true);
41        $tests[] = array('test."test"@example.com', true);
42        $tests[] = array('"test@test"@example.com', true);
43        $tests[] = array('test@123.123.123.123', true);
44        $tests[] = array('test@[123.123.123.123]', true);
45        $tests[] = array('test@example.example.com', true);
46        $tests[] = array('test@example.example.example.com', true);
47
48        $tests[] = array('test.example.com', false);
49        $tests[] = array('test.@example.com', false);
50        $tests[] = array('test..test@example.com', false);
51        $tests[] = array('.test@example.com', false);
52        $tests[] = array('test@test@example.com', false);
53        $tests[] = array('test@@example.com', false);
54        $tests[] = array('-- test --@example.com', false); // No spaces allowed in local part
55        $tests[] = array('[test]@example.com', false); // Square brackets only allowed within quotes
56        $tests[] = array('"test\test"@example.com', false); // Quotes cannot contain backslash
57        $tests[] = array('"test"test"@example.com', false); // Quotes cannot be nested
58        $tests[] = array('()[]\;:,<>@example.com', false); // Disallowed Characters
59        $tests[] = array('test@.', false);
60        $tests[] = array('test@example.', false);
61        $tests[] = array('test@.org', false);
62        $tests[] = array('12345678901234567890123456789012345678901234567890123456789012345@example.com', false); // 64 characters is maximum length for local part. This is 65.
63        $tests[] = array('test@123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012.com', false); // 255 characters is maximum length for domain. This is 256.
64        $tests[] = array('test@[123.123.123.123', false);
65        $tests[] = array('test@123.123.123.123]', false);
66
67
68        foreach($tests as $test){
69            $info = 'Testing '.$test[0];
70
71            if($test[1]){
72                $this->assertTrue((bool) mail_isvalid($test[0]), $info);
73            }else{
74                $this->assertFalse((bool) mail_isvalid($test[0]), $info);
75            }
76        }
77    }
78
79}
80//Setup VIM: ex: et ts=4 :
81