mirror of
https://github.com/phpbb/phpbb.git
synced 2025-07-26 20:08:55 +00:00
[ticket/9626] Adding tests for regular expressions.
Adding tests for the IPv6 regular expression returned by get_preg_expression() PHPBB3-9626
This commit is contained in:
parent
6d7e30ae99
commit
222173adae
3 changed files with 127 additions and 0 deletions
|
@ -23,6 +23,7 @@ require_once 'security/all_tests.php';
|
||||||
require_once 'template/all_tests.php';
|
require_once 'template/all_tests.php';
|
||||||
require_once 'text_processing/all_tests.php';
|
require_once 'text_processing/all_tests.php';
|
||||||
require_once 'dbal/all_tests.php';
|
require_once 'dbal/all_tests.php';
|
||||||
|
require_once 'regex/all_tests.php';
|
||||||
|
|
||||||
// exclude the test directory from code coverage reports
|
// exclude the test directory from code coverage reports
|
||||||
PHPUnit_Util_Filter::addDirectoryToFilter('./');
|
PHPUnit_Util_Filter::addDirectoryToFilter('./');
|
||||||
|
@ -44,6 +45,7 @@ class phpbb_all_tests
|
||||||
$suite->addTest(phpbb_template_all_tests::suite());
|
$suite->addTest(phpbb_template_all_tests::suite());
|
||||||
$suite->addTest(phpbb_text_processing_all_tests::suite());
|
$suite->addTest(phpbb_text_processing_all_tests::suite());
|
||||||
$suite->addTest(phpbb_dbal_all_tests::suite());
|
$suite->addTest(phpbb_dbal_all_tests::suite());
|
||||||
|
$suite->addTest(phpbb_regex_all_tests::suite());
|
||||||
|
|
||||||
return $suite;
|
return $suite;
|
||||||
}
|
}
|
||||||
|
|
40
tests/regex/all_tests.php
Normal file
40
tests/regex/all_tests.php
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @package testing
|
||||||
|
* @copyright (c) 2010 phpBB Group
|
||||||
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (!defined('PHPUnit_MAIN_METHOD'))
|
||||||
|
{
|
||||||
|
define('PHPUnit_MAIN_METHOD', 'phpbb_regex_all_tests::main');
|
||||||
|
}
|
||||||
|
|
||||||
|
require_once 'test_framework/framework.php';
|
||||||
|
require_once 'PHPUnit/TextUI/TestRunner.php';
|
||||||
|
|
||||||
|
require_once 'regex/ipv6.php';
|
||||||
|
|
||||||
|
class phpbb_regex_all_tests
|
||||||
|
{
|
||||||
|
public static function main()
|
||||||
|
{
|
||||||
|
PHPUnit_TextUI_TestRunner::run(self::suite());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function suite()
|
||||||
|
{
|
||||||
|
$suite = new PHPUnit_Framework_TestSuite('phpBB Regular Expressions');
|
||||||
|
|
||||||
|
$suite->addTestSuite('phpbb_ipv6_test');
|
||||||
|
|
||||||
|
return $suite;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (PHPUnit_MAIN_METHOD == 'phpbb_regex_all_tests::main')
|
||||||
|
{
|
||||||
|
phpbb_regex_all_tests::main();
|
||||||
|
}
|
85
tests/regex/ipv6.php
Normal file
85
tests/regex/ipv6.php
Normal file
|
@ -0,0 +1,85 @@
|
||||||
|
<?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_ipv6_test extends phpbb_test_case
|
||||||
|
{
|
||||||
|
protected $regex;
|
||||||
|
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
$this->regex = get_preg_expression('ipv6');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function positive_match_data()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
// Full length IPv6 address
|
||||||
|
array('2001:0db8:85a3:0000:0000:8a2e:0370:1337'),
|
||||||
|
|
||||||
|
// No leading zeroes in the group
|
||||||
|
array('2001:db8:85a3:0:0:8a2e:370:1337'),
|
||||||
|
array('2001:db8:85a3:c:d:8a2e:370:1337'),
|
||||||
|
|
||||||
|
// Consecutive all-zero groups
|
||||||
|
array('2001:db8:85a3::8a2e:370:1337'),
|
||||||
|
|
||||||
|
// Last 32bit in dotted quad notation
|
||||||
|
array('2001:db8:0:1::192.168.0.2'),
|
||||||
|
|
||||||
|
// Mapped IPv4
|
||||||
|
array('::ffff:c000:280'),
|
||||||
|
array('::ffff:192.0.2.128'),
|
||||||
|
|
||||||
|
// More tests
|
||||||
|
array('::'),
|
||||||
|
array('0:0:0:0:0:0:0:0'),
|
||||||
|
|
||||||
|
array('::1'),
|
||||||
|
array('0:0::0:0:1'),
|
||||||
|
array('0:0:0:0:0:0:0:1'),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function negative_match_data()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
// IPv4 address
|
||||||
|
array('192.168.0.2'),
|
||||||
|
|
||||||
|
// Out of hex scope
|
||||||
|
array('abcd:efgh:0000::0'),
|
||||||
|
|
||||||
|
// Double ::
|
||||||
|
array('2001::23de::2002'),
|
||||||
|
|
||||||
|
// Too many blocks
|
||||||
|
array('2001:0db8:85a3:08d3:1319:8a2e:0370:1337:4430'),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider positive_match_data
|
||||||
|
*/
|
||||||
|
public function test_positive_match($address)
|
||||||
|
{
|
||||||
|
$this->assertEquals(1, preg_match($this->regex, $address));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider negative_match_data
|
||||||
|
*/
|
||||||
|
public function test_negative_match($address)
|
||||||
|
{
|
||||||
|
$this->assertEquals(0, preg_match($this->regex, $address));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue