aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/RUNNING_TESTS.txt33
-rw-r--r--tests/all_tests.php2
-rw-r--r--tests/dbal/dbal.php200
-rw-r--r--tests/regex/all_tests.php46
-rw-r--r--tests/regex/email.php119
-rw-r--r--tests/regex/ipv4.php72
-rw-r--r--tests/regex/ipv6.php143
-rw-r--r--tests/regex/url.php34
-rw-r--r--tests/template/template.php24
9 files changed, 651 insertions, 22 deletions
diff --git a/tests/RUNNING_TESTS.txt b/tests/RUNNING_TESTS.txt
new file mode 100644
index 0000000000..f1b40f71ad
--- /dev/null
+++ b/tests/RUNNING_TESTS.txt
@@ -0,0 +1,33 @@
+Running Tests
+-------------
+
+Prerequisites
+-------------
+
+PHPUnit
+=======
+
+phpBB unit tests use PHPUnit framework. Version 3.3 or better is required
+to run the tests. PHPUnit prefers to be installed via PEAR; refer to
+http://www.phpunit.de/ for more information.
+
+PHP extensions
+==============
+
+Unit tests use several PHP extensions that board code does not use. Currently
+the following PHP extensions must be installed and enabled to run unit tests:
+
+- ctype
+
+Running
+-------
+
+Once the prerequisites are installed, run the tests from tests directory:
+
+$ phpunit all_tests.php
+
+More Information
+----------------
+
+Further information is available on phpbb wiki:
+http://wiki.phpbb.com/display/DEV/Unit+Tests
diff --git a/tests/all_tests.php b/tests/all_tests.php
index e693427809..7894d688ee 100644
--- a/tests/all_tests.php
+++ b/tests/all_tests.php
@@ -23,6 +23,7 @@ require_once 'security/all_tests.php';
require_once 'template/all_tests.php';
require_once 'text_processing/all_tests.php';
require_once 'dbal/all_tests.php';
+require_once 'regex/all_tests.php';
// exclude the test directory from code coverage reports
PHPUnit_Util_Filter::addDirectoryToFilter('./');
@@ -44,6 +45,7 @@ class phpbb_all_tests
$suite->addTest(phpbb_template_all_tests::suite());
$suite->addTest(phpbb_text_processing_all_tests::suite());
$suite->addTest(phpbb_dbal_all_tests::suite());
+ $suite->addTest(phpbb_regex_all_tests::suite());
return $suite;
}
diff --git a/tests/dbal/dbal.php b/tests/dbal/dbal.php
index f90b5efeb5..1cce891ca9 100644
--- a/tests/dbal/dbal.php
+++ b/tests/dbal/dbal.php
@@ -21,10 +21,7 @@ class phpbb_dbal_test extends phpbb_database_test_case
{
return array(
array('phpbb_users', "username_clean = 'bertie'", array(array('username_clean' => 'bertie'))),
- array('phpbb_users', "username_clean = 'phpBB'", array()),
array('phpbb_users', 'username_clean syntax_error', false),
- array('phpbb_users', 'column_not_exists = 2', false),
- array('table_not_exists', 'column_not_exists = 2', false),
);
}
@@ -103,7 +100,6 @@ class phpbb_dbal_test extends phpbb_database_test_case
return array(
array('', array('barfoo', 'foobar', 'bertie')),
array('user_id = 2', array('foobar')),
- array("username_clean = 'bertie'", array('bertie')),
);
}
@@ -138,7 +134,6 @@ class phpbb_dbal_test extends phpbb_database_test_case
array(0, 1, array(array('username_clean' => 'foobar'),
array('username_clean' => 'bertie'))),
array(1, 0, array(array('username_clean' => 'barfoo'))),
- array(1, 1, array(array('username_clean' => 'foobar'))),
array(1, 2, array(array('username_clean' => 'bertie'))),
array(2, 0, array(array('username_clean' => 'barfoo'),
array('username_clean' => 'foobar'))),
@@ -180,9 +175,6 @@ class phpbb_dbal_test extends phpbb_database_test_case
array('bar*', array(array('username_clean' => 'barfoo'))),
array('*bar*', array(array('username_clean' => 'barfoo'),
array('username_clean' => 'foobar'))),
- array('*b*', array(array('username_clean' => 'barfoo'),
- array('username_clean' => 'foobar'),
- array('username_clean' => 'bertie'))),
array('b*r', array()),
array('b*e', array(array('username_clean' => 'bertie'))),
array('#b*e', array()),
@@ -220,11 +212,11 @@ class phpbb_dbal_test extends phpbb_database_test_case
array('username_clean' => 'foobar'))),
array('user_id', 3, true, true, array(array('username_clean' => 'barfoo'),
array('username_clean' => 'foobar'))),
- array('user_id', '3', false, false, array(array('username_clean' => 'bertie'))),
- array('user_id', '3', false, true, array(array('username_clean' => 'bertie'))),
- array('user_id', '3', true, false, array(array('username_clean' => 'barfoo'),
+ array('username_clean', 'bertie', false, false, array(array('username_clean' => 'bertie'))),
+ array('username_clean', 'bertie', false, true, array(array('username_clean' => 'bertie'))),
+ array('username_clean', 'bertie', true, false, array(array('username_clean' => 'barfoo'),
array('username_clean' => 'foobar'))),
- array('user_id', '3', true, true, array(array('username_clean' => 'barfoo'),
+ array('username_clean', 'bertie', true, true, array(array('username_clean' => 'barfoo'),
array('username_clean' => 'foobar'))),
array('user_id', array(3), false, false, array(array('username_clean' => 'bertie'))),
array('user_id', array(3), false, true, array(array('username_clean' => 'bertie'))),
@@ -238,12 +230,12 @@ class phpbb_dbal_test extends phpbb_database_test_case
array('username_clean' => 'bertie'))),
array('user_id', array(1, 3), true, false, array(array('username_clean' => 'foobar'))),
array('user_id', array(1, 3), true, true, array(array('username_clean' => 'foobar'))),
- array('user_id', '', false, false, array()),
- array('user_id', '', false, true, array()),
- array('user_id', '', true, false, array(array('username_clean' => 'barfoo'),
+ array('username_clean', '', false, false, array()),
+ array('username_clean', '', false, true, array()),
+ array('username_clean', '', true, false, array(array('username_clean' => 'barfoo'),
array('username_clean' => 'foobar'),
array('username_clean' => 'bertie'))),
- array('user_id', '', true, true, array(array('username_clean' => 'barfoo'),
+ array('username_clean', '', true, true, array(array('username_clean' => 'barfoo'),
array('username_clean' => 'foobar'),
array('username_clean' => 'bertie'))),
array('user_id', array(), false, true, array()),
@@ -310,10 +302,11 @@ class phpbb_dbal_test extends phpbb_database_test_case
$db->sql_return_on_error(true);
}
- $result = $db->sql_query('SELECT username_clean
+ $sql = 'SELECT username_clean
FROM phpbb_users
WHERE ' . $db->sql_build_array('SELECT', $assoc_ary) . '
- ORDER BY user_id ASC');
+ ORDER BY user_id ASC';
+ $result = $db->sql_query($sql);
if ($catch_error)
{
@@ -324,5 +317,174 @@ class phpbb_dbal_test extends phpbb_database_test_case
$db->sql_freeresult($result);
}
-}
+ public static function build_array_insert_data()
+ {
+ return array(
+ array(array(
+ 'config_name' => 'test_version',
+ 'config_value' => '0.0.0',
+ 'is_dynamic' => 1,
+ )),
+ array(array(
+ 'config_name' => 'second config',
+ 'config_value' => '10',
+ 'is_dynamic' => 0,
+ )),
+ );
+ }
+
+ /**
+ * @dataProvider build_array_insert_data
+ */
+ public function test_build_array_insert($sql_ary)
+ {
+ $db = $this->new_dbal();
+
+ $sql = 'INSERT INTO phpbb_config ' . $db->sql_build_array('INSERT', $sql_ary);
+ $result = $db->sql_query($sql);
+
+ $sql = "SELECT *
+ FROM phpbb_config
+ WHERE config_name = '" . $sql_ary['config_name'] . "'";
+ $result = $db->sql_query_limit($sql, 1);
+
+ $this->assertEquals($sql_ary, $db->sql_fetchrow($result));
+
+ $db->sql_freeresult($result);
+ }
+
+ public static function delete_data()
+ {
+ return array(
+ array(
+ "WHERE config_name = 'test_version'",
+ array(
+ array(
+ 'config_name' => 'second config',
+ 'config_value' => '10',
+ 'is_dynamic' => 0,
+ ),
+ ),
+ ),
+ array(
+ '',
+ array(),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider delete_data
+ */
+ public function test_delete($where, $expected)
+ {
+ $db = $this->new_dbal();
+
+ $sql = 'DELETE FROM phpbb_config
+ ' . $where;
+ $result = $db->sql_query($sql);
+
+ $sql = 'SELECT *
+ FROM phpbb_config';
+ $result = $db->sql_query($sql);
+
+ $this->assertEquals($expected, $db->sql_fetchrowset($result));
+
+ $db->sql_freeresult($result);
+ }
+
+ public function test_multiple_insert()
+ {
+ $db = $this->new_dbal();
+
+ $batch_ary = array(
+ array(
+ 'config_name' => 'batch one',
+ 'config_value' => 'b1',
+ 'is_dynamic' => 0,
+ ),
+ array(
+ 'config_name' => 'batch two',
+ 'config_value' => 'b2',
+ 'is_dynamic' => 1,
+ ),
+ );
+
+ $result = $db->sql_multi_insert('phpbb_config', $batch_ary);
+
+ $sql = 'SELECT *
+ FROM phpbb_config
+ ORDER BY config_name ASC';
+ $result = $db->sql_query($sql);
+
+ $this->assertEquals($batch_ary, $db->sql_fetchrowset($result));
+
+ $db->sql_freeresult($result);
+ }
+
+ public static function update_data()
+ {
+ return array(
+ array(
+ array(
+ 'config_value' => '20',
+ 'is_dynamic' => 0,
+ ),
+ " WHERE config_name = 'batch one'",
+ array(
+ array(
+ 'config_name' => 'batch one',
+ 'config_value' => '20',
+ 'is_dynamic' => 0,
+ ),
+ array(
+ 'config_name' => 'batch two',
+ 'config_value' => 'b2',
+ 'is_dynamic' => 1,
+ ),
+ ),
+ ),
+ array(
+ array(
+ 'config_value' => '0',
+ 'is_dynamic' => 1,
+ ),
+ '',
+ array(
+ array(
+ 'config_name' => 'batch one',
+ 'config_value' => '0',
+ 'is_dynamic' => 1,
+ ),
+ array(
+ 'config_name' => 'batch two',
+ 'config_value' => '0',
+ 'is_dynamic' => 1,
+ ),
+ ),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider update_data
+ */
+ public function test_update($sql_ary, $where, $expected)
+ {
+ $db = $this->new_dbal();
+
+ $sql = 'UPDATE phpbb_config
+ SET ' . $db->sql_build_array('UPDATE', $sql_ary) . $where;
+ $result = $db->sql_query($sql);
+
+ $sql = 'SELECT *
+ FROM phpbb_config
+ ORDER BY config_name ASC';
+ $result = $db->sql_query($sql);
+
+ $this->assertEquals($expected, $db->sql_fetchrowset($result));
+
+ $db->sql_freeresult($result);
+ }
+}
diff --git a/tests/regex/all_tests.php b/tests/regex/all_tests.php
new file mode 100644
index 0000000000..316a9d4a58
--- /dev/null
+++ b/tests/regex/all_tests.php
@@ -0,0 +1,46 @@
+<?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/email.php';
+require_once 'regex/ipv4.php';
+require_once 'regex/ipv6.php';
+require_once 'regex/url.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_regex_email_test');
+ $suite->addTestSuite('phpbb_regex_ipv4_test');
+ $suite->addTestSuite('phpbb_regex_ipv6_test');
+ $suite->addTestSuite('phpbb_regex_url_test');
+
+ return $suite;
+ }
+}
+
+if (PHPUnit_MAIN_METHOD == 'phpbb_regex_all_tests::main')
+{
+ phpbb_regex_all_tests::main();
+}
diff --git a/tests/regex/email.php b/tests/regex/email.php
new file mode 100644
index 0000000000..8658b8af36
--- /dev/null
+++ b/tests/regex/email.php
@@ -0,0 +1,119 @@
+<?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_regex_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
+
+ // http://fightingforalostcause.net/misc/2006/compare-email-regex.php
+ array('l3tt3rsAndNumb3rs@domain.com'),
+ array('has-dash@domain.com'),
+ array('hasApostrophe.o\'leary@domain.org'),
+ array('uncommonTLD@domain.museum'),
+ array('uncommonTLD@domain.travel'),
+ array('uncommonTLD@domain.mobi'),
+ array('countryCodeTLD@domain.uk'),
+ array('countryCodeTLD@domain.rw'),
+ array('numbersInDomain@911.com'),
+ array('underscore_inLocal@domain.net'),
+ array('IPInsteadOfDomain@127.0.0.1'),
+ array('IPAndPort@127.0.0.1:25'),
+ array('subdomain@sub.domain.com'),
+ array('local@dash-inDomain.com'),
+ array('dot.inLocal@foo.com'),
+ array('a@singleLetterLocal.org'),
+ array('singleLetterDomain@x.org'),
+ array('&amp;*=?^+{}\'~@validCharsInLocal.net'),
+ array('foor@bar.newTLD'),
+ );
+ }
+
+ 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 >
+
+ // http://fightingforalostcause.net/misc/2006/compare-email-regex.php
+ array('missingDomain@.com'),
+ array('@missingLocal.org'),
+ array('missingatSign.net'),
+ array('missingDot@com'),
+ array('two@@signs.com'),
+ array('colonButNoPort@127.0.0.1:'),
+ array(''),
+ array('someone-else@127.0.0.1.26'),
+ array('.localStartsWithDot@domain.com'),
+ array('localEndsWithDot.@domain.com'),
+ array('two..consecutiveDots@domain.com'),
+ array('domainStartsWithDash@-domain.com'),
+ array('domainEndsWithDash@domain-.com'),
+ array('numbersInTLD@domain.c0m'),
+ array('missingTLD@domain.'),
+ array('! "#$%(),/;<>[]`|@invalidCharsInLocal.org'),
+ array('invalidCharsInDomain@! "#$%(),/;<>_[]`|.org'),
+ array('local@SecondLevelDomainNamesAreInvalidIfTheyAreLongerThan64Charactersss.org'),
+ );
+ }
+
+ /**
+ * @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($email)
+ {
+ $this->assertEquals(0, preg_match($this->regex, $email));
+ }
+}
+
diff --git a/tests/regex/ipv4.php b/tests/regex/ipv4.php
new file mode 100644
index 0000000000..9d131ad0ca
--- /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_regex_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));
+ }
+}
+
diff --git a/tests/regex/ipv6.php b/tests/regex/ipv6.php
new file mode 100644
index 0000000000..3d7a72e492
--- /dev/null
+++ b/tests/regex/ipv6.php
@@ -0,0 +1,143 @@
+<?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_regex_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'),
+ array('0000:0000:0000:0000:0000:0000:0000:0001'),
+ array('3FFE:0b00:0000:0000:0001:0000:0000:000a'),
+ array('3ffe:0b00:0000:0000:0001:0000:0000:000a'),
+ array('2002:0db8:0000:0000:0000:dead:1337:d00d'),
+
+ // 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'),
+ array('1::2:3:4:5:6:7'),
+ array('1::2:3:4:5:6'),
+ array('1::2:3:4:5'),
+ array('1::2:3:4'),
+ array('1::2:3'),
+ array('1::2'),
+
+ // Last 32bit in dotted quad notation
+ array('2001:db8:0:1::192.168.0.2'),
+
+ // IPv4-compatible IPv6 address
+ array('::13.1.68.3'),
+ array('0:0:0:0:0:0:13.1.68.3'),
+
+ // IPv4-mapped IPv6 address
+ array('::ffff:c000:280'),
+ array('::ffff:c000:0280'),
+ array('::ffff:192.0.2.128'),
+ array('0:0:0:0:0:ffff:c000:280'),
+ array('0:0:0:0:0:ffff:c000:0280'),
+ array('0:0:0:0:0:ffff:192.0.2.128'),
+ array('0000:0000:0000:0000:0000:ffff:c000:280'),
+ array('0000:0000:0000:0000:0000:ffff:c000:0280'),
+ array('0000:0000:0000:0000:0000:ffff:192.0.2.128'),
+
+ // No trailing zeroes
+ array('fe80::'),
+ array('2002::'),
+ array('2001:db8::'),
+ array('2001:0db8:1234::'),
+ array('1:2:3:4:5:6::'),
+ array('1:2:3:4:5::'),
+ array('1:2:3:4::'),
+ array('1:2:3::'),
+ array('1:2::'),
+
+ // No leading zeroes
+ array('::2:3:4:5:6:7:8'),
+ array('::2:3:4:5:6:7'),
+ array('::2:3:4:5:6'),
+ array('::2:3:4:5'),
+ array('::2:3:4'),
+ array('::2:3'),
+ array('::1'),
+ array('::8'),
+ array('::c'),
+ array('::abcd'),
+
+ // All zeroes
+ array('::'),
+ array('0:0:0:0:0:0:0:0'),
+ array('0000:0000:0000:0000:0000:0000:0000:0000'),
+
+ // More tests
+ array('2::10'),
+ array('0:0::0:0:1'),
+ array('0:0:0:0:0:0:0:1'),
+ array('::ffff:0:0'),
+ );
+ }
+
+ public function negative_match_data()
+ {
+ return array(
+ // Empty address
+ array(''),
+
+ // IPv4 address
+ array('192.168.0.2'),
+
+ // Out of scope
+ array('abcd:efgh:0000::0'),
+ array('::ffff:192.168.255.256'),
+
+ // Double ::
+ array('2001::23de::2002'),
+ array('3ffe:b00::1::b'),
+ array('::1111:2222:3333:4444:5555:6666::'),
+
+ // Too many blocks
+ array('2001:0db8:85a3:08d3:1319:8a2e:0370:1337:4430'),
+
+ // More tests
+ array('02001:0000:1234:0000:0000:C1C0:ABCD:9876'),
+ array('2001:0000:1234: 0000:0000:C1C0:ABCD:9876'),
+ array('::ffff:192x168.255.255'),
+ );
+ }
+
+ /**
+ * @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));
+ }
+}
+
diff --git a/tests/regex/url.php b/tests/regex/url.php
new file mode 100644
index 0000000000..678b7d108f
--- /dev/null
+++ b/tests/regex/url.php
@@ -0,0 +1,34 @@
+<?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_regex_url_test extends phpbb_test_case
+{
+ public function url_test_data()
+ {
+ return array(
+ array('http://www.phpbb.com/community/', 1),
+ array('http://www.phpbb.com/path/file.ext#section', 1),
+ array('ftp://ftp.phpbb.com/', 1),
+ array('sip://bantu@phpbb.com', 1),
+
+ array('www.phpbb.com/community/', 0),
+ );
+ }
+
+ /**
+ * @dataProvider url_test_data
+ */
+ public function test_url($url, $expected)
+ {
+ $this->assertEquals($expected, preg_match('#^' . get_preg_expression('url') . '$#i', $url));
+ }
+}
diff --git a/tests/template/template.php b/tests/template/template.php
index 145fe8de61..024d3712f7 100644
--- a/tests/template/template.php
+++ b/tests/template/template.php
@@ -26,12 +26,24 @@ class phpbb_template_template_test extends phpbb_test_case
error_reporting($error_level & ~E_NOTICE);
ob_start();
- $this->assertTrue($this->template->display($handle, false));
+
+ try
+ {
+ $this->assertTrue($this->template->display($handle, false));
+ }
+ catch (Exception $exception)
+ {
+ // reset the error level even when an error occured
+ // PHPUnit turns trigger_error into exceptions as well
+ error_reporting($error_level);
+ throw $exception;
+ }
+
+ $result = self::trim_template_result(ob_get_clean());
// reset error level
error_reporting($error_level);
-
- return self::trim_template_result(ob_get_clean());
+ return $result;
}
private static function trim_template_result($result)
@@ -368,9 +380,15 @@ class phpbb_template_template_test extends phpbb_test_case
$this->template->destroy_block_vars($block);
}
+ $error_level = error_reporting();
+ error_reporting($error_level & ~E_NOTICE);
+
$this->assertEquals($expected, self::trim_template_result($this->template->assign_display('test')), "Testing assign_display($file)");
$this->template->assign_display('test', 'VARIABLE', false);
+
+ error_reporting($error_level);
+
$this->assertEquals($expected, $this->display('container'), "Testing assign_display($file)");
}