mirror of
https://github.com/phpbb/phpbb.git
synced 2025-02-24 12:03:21 +01:00
[ticket/9746] Adding tests for phpbb_ip_normalise().
PHPBB3-9746
This commit is contained in:
parent
979158f0a2
commit
dc7e3550ab
@ -16,6 +16,7 @@ require_once 'test_framework/framework.php';
|
||||
require_once 'PHPUnit/TextUI/TestRunner.php';
|
||||
|
||||
require_once 'network/checkdnsrr.php';
|
||||
require_once 'network/ip_normalise.php';
|
||||
|
||||
class phpbb_network_all_tests
|
||||
{
|
||||
@ -29,6 +30,7 @@ class phpbb_network_all_tests
|
||||
$suite = new PHPUnit_Framework_TestSuite('phpBB Network Functions');
|
||||
|
||||
$suite->addTestSuite('phpbb_network_checkdnsrr_test');
|
||||
$suite->addTestSuite('phpbb_network_ip_normalise_test');
|
||||
|
||||
return $suite;
|
||||
}
|
||||
|
65
tests/network/ip_normalise.php
Normal file
65
tests/network/ip_normalise.php
Normal file
@ -0,0 +1,65 @@
|
||||
<?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_network_ip_normalise_test extends phpbb_test_case
|
||||
{
|
||||
public function data_provider()
|
||||
{
|
||||
return array(
|
||||
// From: A Recommendation for IPv6 Address Text Representation
|
||||
// http://tools.ietf.org/html/draft-ietf-6man-text-addr-representation-07
|
||||
|
||||
// Section 4: A Recommendation for IPv6 Text Representation
|
||||
// Section 4.1: Handling Leading Zeros in a 16 Bit Field
|
||||
array('2001:0db8::0001', '2001:db8::1'),
|
||||
|
||||
// Section 4.2: "::" Usage
|
||||
// Section 4.2.1: Shorten As Much As Possible
|
||||
array('2001:db8::0:1', '2001:db8::1'),
|
||||
|
||||
// Section 4.2.2: Handling One 16 Bit 0 Field
|
||||
array('2001:db8::1:1:1:1:1', '2001:db8:0:1:1:1:1:1'),
|
||||
|
||||
// Section 4.2.3: Choice in Placement of "::"
|
||||
array('2001:db8:0:0:1:0:0:1', '2001:db8::1:0:0:1'),
|
||||
|
||||
// Section 4.3: Lower Case
|
||||
array('2001:DB8::1', '2001:db8::1'),
|
||||
|
||||
// Section 5: Text Representation of Special Addresses
|
||||
// We want to show IPv4-mapped addresses as plain IPv4 addresses, though.
|
||||
array('::ffff:192.168.0.1', '192.168.0.1'),
|
||||
array('0000::0000:ffff:c000:0280', '192.0.2.128'),
|
||||
|
||||
// IPv6 addresses with the last 32-bit written in dotted-quad notation
|
||||
// should be converted to hex-only IPv6 addresses.
|
||||
array('2001:db8::192.0.2.128', '2001:db8::c000:280'),
|
||||
|
||||
// Any string not passing the IPv4 or IPv6 regular expression
|
||||
// is supposed to result in false being returned.
|
||||
// Valid and invalid IP addresses are tested in
|
||||
// tests/regex/ipv4.php and tests/regex/ipv6.php.
|
||||
array('', false),
|
||||
array('192.168.1.256', false),
|
||||
array('::ffff:192.168.255.256', false),
|
||||
array('::1111:2222:3333:4444:5555:6666::', false),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider data_provider
|
||||
*/
|
||||
public function test_ip_normalise($ip_address, $expected)
|
||||
{
|
||||
$this->assertEquals($expected, phpbb_ip_normalise($ip_address));
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user