aboutsummaryrefslogtreecommitdiffstats
path: root/tests/regex
diff options
context:
space:
mode:
authorAndreas Fischer <bantu@phpbb.com>2010-04-09 00:54:19 +0200
committerAndreas Fischer <bantu@phpbb.com>2010-05-25 12:08:51 +0200
commit1c59f3dbd0e27be2057dc32344421e82122276ca (patch)
tree4cf01fdc15a090b11a0eaf064505fcbba566a3ac /tests/regex
parent222173adae59af660c18ce89c606b3ee212d9a4a (diff)
downloadforums-1c59f3dbd0e27be2057dc32344421e82122276ca.tar
forums-1c59f3dbd0e27be2057dc32344421e82122276ca.tar.gz
forums-1c59f3dbd0e27be2057dc32344421e82122276ca.tar.bz2
forums-1c59f3dbd0e27be2057dc32344421e82122276ca.tar.xz
forums-1c59f3dbd0e27be2057dc32344421e82122276ca.zip
[ticket/9626] Adding tests for the IPv4 regular expression.
PHPBB3-9626
Diffstat (limited to 'tests/regex')
-rw-r--r--tests/regex/all_tests.php2
-rw-r--r--tests/regex/ipv4.php72
2 files changed, 74 insertions, 0 deletions
diff --git a/tests/regex/all_tests.php b/tests/regex/all_tests.php
index aeb242b78b..32cd9a3a4e 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/ipv4.php';
require_once 'regex/ipv6.php';
class phpbb_regex_all_tests
@@ -28,6 +29,7 @@ class phpbb_regex_all_tests
{
$suite = new PHPUnit_Framework_TestSuite('phpBB Regular Expressions');
+ $suite->addTestSuite('phpbb_ipv4_test');
$suite->addTestSuite('phpbb_ipv6_test');
return $suite;
diff --git a/tests/regex/ipv4.php b/tests/regex/ipv4.php
new file mode 100644
index 0000000000..5ffc700831
--- /dev/null
+++ b/tests/regex/ipv4.php
@@ -0,0 +1,72 @@
+<?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_ipv4_test extends phpbb_test_case
+{
+ protected $regex;
+
+ public function setUp()
+ {
+ $this->regex = get_preg_expression('ipv4');
+ }
+
+ public function positive_match_data()
+ {
+ return array(
+ array('0.0.0.0'),
+ array('127.0.0.1'),
+ array('192.168.0.1'),
+ array('255.255.255.255'),
+ );
+ }
+
+ public function negative_match_data()
+ {
+ return array(
+ // IPv6 addresses
+ array('2001:0db8:85a3:0000:0000:8a2e:0370:1337'),
+ array('2001:db8:85a3:c:d:8a2e:370:1337'),
+ array('2001:db8:85a3::8a2e:370:1337'),
+ array('2001:db8:0:1::192.168.0.2'),
+ array('0:0:0:0:0:0:0:1'),
+ array('0:0::0:0:1'),
+ array('::1'),
+
+ // Out of scope
+ array('255.255.255.256'),
+
+ // Other tests
+ array('a.b.c.d'),
+ array('11.22.33.'),
+ array('11.22.33'),
+ array('11.22'),
+ array('11'),
+ );
+ }
+
+ /**
+ * @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));
+ }
+}
+