From c83b83eeae9806cb60ea3f41f2cff055b0c6ed7e Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Fri, 17 Aug 2012 15:37:04 +0200 Subject: Fix domain part check in email address validation function. Added test cases. --- tests/Utils.php | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ tests/phpunit.xml | 1 + 2 files changed, 75 insertions(+) create mode 100644 tests/Utils.php (limited to 'tests') diff --git a/tests/Utils.php b/tests/Utils.php new file mode 100644 index 000000000..648b39989 --- /dev/null +++ b/tests/Utils.php @@ -0,0 +1,74 @@ +', 'Encoded html within email is invalid'), + array('email.domain.com', 'Missing @'), + array('email@domain@domain.com', 'Two @ sign'), + array('.email@domain.com', 'Leading dot in address is not allowed'), + array('email.@domain.com', 'Trailing dot in address is not allowed'), + array('email..email@domain.com', 'Multiple dots'), + array('あいうえお@domain.com', 'Unicode char as address'), + array('email@domain.com (Joe Smith)', 'Text followed email is not allowed'), + array('email@domain', 'Missing top level domain (.com/.net/.org/etc)'), + array('email@-domain.com', 'Leading dash in front of domain is invalid'), +// array('email@domain.web', '.web is not a valid top level domain'), + array('email@111.222.333.44444', 'Invalid IP format'), + array('email@domain..com', 'Multiple dot in the domain portion is invalid'), + ); + } + + /** + * @dataProvider data_valid_email + */ + function test_valid_email($email, $title) + { + $this->assertTrue(rcube_utils::check_email($email, false), $title); + } + + /** + * @dataProvider data_invalid_email + */ + function test_invalid_email($email, $title) + { + $this->assertFalse(rcube_utils::check_email($email, false), $title); + } + +} diff --git a/tests/phpunit.xml b/tests/phpunit.xml index 4a3b883cf..cfd066e29 100644 --- a/tests/phpunit.xml +++ b/tests/phpunit.xml @@ -7,6 +7,7 @@ MailDecode.php MailFunc.php ModCss.php + Utils.php VCards.php -- cgit v1.2.3