1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-01-19 07:08:09 +01:00

[ticket/9626] A few tests for the email regular expression.

PHPBB3-9626
This commit is contained in:
Andreas Fischer 2010-04-14 02:27:07 +02:00
parent 12e92fc45e
commit 6a5ad05d8a
2 changed files with 80 additions and 0 deletions

View File

@ -15,6 +15,7 @@ if (!defined('PHPUnit_MAIN_METHOD'))
require_once 'test_framework/framework.php'; require_once 'test_framework/framework.php';
require_once 'PHPUnit/TextUI/TestRunner.php'; require_once 'PHPUnit/TextUI/TestRunner.php';
require_once 'regex/email.php';
require_once 'regex/ipv4.php'; require_once 'regex/ipv4.php';
require_once 'regex/ipv6.php'; require_once 'regex/ipv6.php';
@ -29,6 +30,7 @@ class phpbb_regex_all_tests
{ {
$suite = new PHPUnit_Framework_TestSuite('phpBB Regular Expressions'); $suite = new PHPUnit_Framework_TestSuite('phpBB Regular Expressions');
$suite->addTestSuite('phpbb_email_test');
$suite->addTestSuite('phpbb_ipv4_test'); $suite->addTestSuite('phpbb_ipv4_test');
$suite->addTestSuite('phpbb_ipv6_test'); $suite->addTestSuite('phpbb_ipv6_test');

78
tests/regex/email.php Normal file
View File

@ -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));
}
}