summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--_testing/README2
-rw-r--r--_testing/unittests/inc/mail_isvalid.test.php82
-rw-r--r--_testing/unittests/inc/mail_quoted_printable_encode.test.php44
3 files changed, 127 insertions, 1 deletions
diff --git a/_testing/README b/_testing/README
index 45bc03f6f..7150da5a4 100644
--- a/_testing/README
+++ b/_testing/README
@@ -22,4 +22,4 @@ Bad tests are tests that do not run out of the box.
* inc/form_form
* inc/html_hilight (runkit)
* inc/indexer_idx_indexlengths
- * \ No newline at end of file
+ * inc/mail_send
diff --git a/_testing/unittests/inc/mail_isvalid.test.php b/_testing/unittests/inc/mail_isvalid.test.php
new file mode 100644
index 000000000..e4eaf8d78
--- /dev/null
+++ b/_testing/unittests/inc/mail_isvalid.test.php
@@ -0,0 +1,82 @@
+<?php
+// use no mbstring help here
+require_once DOKU_INC.'inc/init.php';
+
+class mail_isvalid extends PHPUnit_Framework_TestCase {
+
+
+ function test1(){
+ $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',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
+
+ // 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);
+ }
+ }
+ }
+
+}
+//Setup VIM: ex: et ts=4 :
diff --git a/_testing/unittests/inc/mail_quoted_printable_encode.test.php b/_testing/unittests/inc/mail_quoted_printable_encode.test.php
new file mode 100644
index 000000000..8228d007b
--- /dev/null
+++ b/_testing/unittests/inc/mail_quoted_printable_encode.test.php
@@ -0,0 +1,44 @@
+<?php
+
+require_once DOKU_INC.'inc/mail.php';
+
+class mail_quotedprintable_encode extends PHPUnit_Framework_TestCase {
+
+ function test_simple(){
+ $in = 'hello';
+ $out = 'hello';
+ $this->assertEquals(mail_quotedprintable_encode($in),$out);
+ }
+
+ function test_spaceend(){
+ $in = "hello \nhello";
+ $out = "hello=20\nhello";
+ $this->assertEquals(mail_quotedprintable_encode($in),$out);
+ }
+
+ function test_german_utf8(){
+ $in = 'hello überlänge';
+ $out = 'hello =C3=BCberl=C3=A4nge';
+ $this->assertEquals(mail_quotedprintable_encode($in),$out);
+ }
+
+ function test_wrap(){
+ $in = '123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789';
+ $out = "123456789 123456789 123456789 123456789 123456789 123456789 123456789 1234=\n56789 123456789";
+ $this->assertEquals(mail_quotedprintable_encode($in,74),$out);
+ }
+
+ function test_nowrap(){
+ $in = '123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789';
+ $out = '123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789';
+ $this->assertEquals(mail_quotedprintable_encode($in,0),$out);
+ }
+
+ function test_russian_utf8(){
+ $in = 'Ваш пароль для системы Доку Вики';
+ $out = '=D0=92=D0=B0=D1=88 =D0=BF=D0=B0=D1=80=D0=BE=D0=BB=D1=8C =D0=B4=D0=BB=D1=8F =D1=81=D0=B8=D1=81=D1=82=D0=B5=D0=BC=D1=8B =D0=94=D0=BE=D0=BA=D1=83 =D0=92=D0=B8=D0=BA=D0=B8';
+ $this->assertEquals(mail_quotedprintable_encode($in,0),$out);
+ }
+}
+
+//Setup VIM: ex: et ts=4 :