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