aboutsummaryrefslogtreecommitdiffstats
path: root/tests/regex
diff options
context:
space:
mode:
authorAndreas Fischer <bantu@phpbb.com>2010-04-14 02:27:07 +0200
committerAndreas Fischer <bantu@phpbb.com>2010-05-25 12:08:51 +0200
commit6a5ad05d8a15c0d4f6be2413190c5a2fdc270f5d (patch)
tree2636decf929881bbe94d60827f3b12f76042e0a6 /tests/regex
parent12e92fc45e7c023122d0c52d94fc49710ca6d4dd (diff)
downloadforums-6a5ad05d8a15c0d4f6be2413190c5a2fdc270f5d.tar
forums-6a5ad05d8a15c0d4f6be2413190c5a2fdc270f5d.tar.gz
forums-6a5ad05d8a15c0d4f6be2413190c5a2fdc270f5d.tar.bz2
forums-6a5ad05d8a15c0d4f6be2413190c5a2fdc270f5d.tar.xz
forums-6a5ad05d8a15c0d4f6be2413190c5a2fdc270f5d.zip
[ticket/9626] A few tests for the email regular expression.
PHPBB3-9626
Diffstat (limited to 'tests/regex')
-rw-r--r--tests/regex/all_tests.php2
-rw-r--r--tests/regex/email.php78
2 files changed, 80 insertions, 0 deletions
diff --git a/tests/regex/all_tests.php b/tests/regex/all_tests.php
index 32cd9a3a4e..0e193620e1 100644
--- a/tests/regex/all_tests.php
+++ b/tests/regex/all_tests.php
@@ -15,6 +15,7 @@ if (!defined('PHPUnit_MAIN_METHOD'))
require_once 'test_framework/framework.php';
require_once 'PHPUnit/TextUI/TestRunner.php';
+require_once 'regex/email.php';
require_once 'regex/ipv4.php';
require_once 'regex/ipv6.php';
@@ -29,6 +30,7 @@ class phpbb_regex_all_tests
{
$suite = new PHPUnit_Framework_TestSuite('phpBB Regular Expressions');
+ $suite->addTestSuite('phpbb_email_test');
$suite->addTestSuite('phpbb_ipv4_test');
$suite->addTestSuite('phpbb_ipv6_test');
diff --git a/tests/regex/email.php b/tests/regex/email.php
new file mode 100644
index 0000000000..37fb9d81d0
--- /dev/null
+++ b/tests/regex/email.php
@@ -0,0 +1,78 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2010 phpBB Group
+* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+*
+*/
+
+require_once 'test_framework/framework.php';
+require_once '../phpBB/includes/functions.php';
+
+class phpbb_email_test extends phpbb_test_case
+{
+ protected $regex;
+
+ public function setUp()
+ {
+ $this->regex = '#^' . get_preg_expression('email') . '$#i';
+ }
+
+ public function positive_match_data()
+ {
+ return array(
+ array('nobody@phpbb.com'),
+ array('Nobody@sub.phpbb.com'),
+ array('alice.bob@foo.phpbb.com'),
+ array('alice-foo@bar.phpbb.com'),
+ array('alice_foo@bar.phpbb.com'),
+ array('alice+tag@foo.phpbb.com'),
+ array('alice&amp;tag@foo.phpbb.com'),
+
+ //array('"John Doe"@example.com'),
+ //array('Alice@[192.168.2.1]'), // IPv4
+ //array('Bob@[2001:0db8:85a3:08d3:1319:8a2e:0370:7344]'), // IPv6
+ );
+ }
+
+ public function negative_match_data()
+ {
+ return array(
+ array('foo.example.com'), // @ is missing
+ array('.foo.example.com'), // . as first character
+ array('Foo.@example.com'), // . is last in local part
+ array('foo..123@example.com'), // . doubled
+ array('a@b@c@example.com'), // @ doubled
+
+ array('()[]\;:,<>@example.com'), // invalid characters
+ array('abc(def@example.com'), // invalid character (
+ array('abc)def@example.com'), // invalid character )
+ array('abc[def@example.com'), // invalid character [
+ array('abc]def@example.com'), // invalid character ]
+ array('abc\def@example.com'), // invalid character \
+ array('abc;def@example.com'), // invalid character ;
+ array('abc:def@example.com'), // invalid character :
+ array('abc,def@example.com'), // invalid character ,
+ array('abc<def@example.com'), // invalid character <
+ array('abc>def@example.com'), // invalid character >
+ );
+ }
+
+ /**
+ * @dataProvider positive_match_data
+ */
+ public function test_positive_match($email)
+ {
+ $this->assertEquals(1, preg_match($this->regex, $email));
+ }
+
+ /**
+ * @dataProvider negative_match_data
+ */
+ public function test_negative_match($address)
+ {
+ $this->assertEquals(0, preg_match($this->regex, $email));
+ }
+}
+