aboutsummaryrefslogtreecommitdiffstats
path: root/tests/network
diff options
context:
space:
mode:
authorAndreas Fischer <bantu@phpbb.com>2010-07-21 18:59:02 +0200
committerAndreas Fischer <bantu@phpbb.com>2011-01-03 00:09:40 +0100
commitdc7e3550ab6a4f95f12cbb366f3ad1a0568b8a2d (patch)
treeece191dc438f9a7745b29afc578cfcf7f9838310 /tests/network
parent979158f0a2e1ab88685f608e8756ff40248b86cf (diff)
downloadforums-dc7e3550ab6a4f95f12cbb366f3ad1a0568b8a2d.tar
forums-dc7e3550ab6a4f95f12cbb366f3ad1a0568b8a2d.tar.gz
forums-dc7e3550ab6a4f95f12cbb366f3ad1a0568b8a2d.tar.bz2
forums-dc7e3550ab6a4f95f12cbb366f3ad1a0568b8a2d.tar.xz
forums-dc7e3550ab6a4f95f12cbb366f3ad1a0568b8a2d.zip
[ticket/9746] Adding tests for phpbb_ip_normalise().
PHPBB3-9746
Diffstat (limited to 'tests/network')
-rw-r--r--tests/network/all_tests.php2
-rw-r--r--tests/network/ip_normalise.php65
2 files changed, 67 insertions, 0 deletions
diff --git a/tests/network/all_tests.php b/tests/network/all_tests.php
index b500647f81..6305aae5b8 100644
--- a/tests/network/all_tests.php
+++ b/tests/network/all_tests.php
@@ -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;
}
diff --git a/tests/network/ip_normalise.php b/tests/network/ip_normalise.php
new file mode 100644
index 0000000000..53d41e9371
--- /dev/null
+++ b/tests/network/ip_normalise.php
@@ -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));
+ }
+}