aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/RUNNING_TESTS.txt39
-rw-r--r--tests/all_tests.php69
-rw-r--r--tests/bbcode/url_bbcode_test.php63
-rw-r--r--tests/bootstrap.php26
-rw-r--r--tests/dbal/all_tests.php42
-rw-r--r--tests/dbal/auto_increment_test.php100
-rw-r--r--tests/dbal/cross_join_test.php55
-rw-r--r--tests/dbal/db_tools_test.php333
-rw-r--r--tests/dbal/fixtures/massmail_crossjoin.xml59
-rw-r--r--tests/dbal/fixtures/styles.xml39
-rw-r--r--tests/dbal/fixtures/three_users.xml16
-rw-r--r--tests/dbal/order_lower_test.php62
-rw-r--r--tests/dbal/select_test.php (renamed from tests/dbal/select.php)98
-rw-r--r--tests/dbal/write_test.php (renamed from tests/dbal/write.php)5
-rw-r--r--tests/error_collector_test.php35
-rw-r--r--tests/functional/auth_test.php40
-rw-r--r--tests/functional/browse_test.php32
-rw-r--r--tests/functional/lang_test.php45
-rw-r--r--tests/mock/cache.php95
-rw-r--r--tests/mock/session_testable.php63
-rw-r--r--tests/mock_user.php36
-rw-r--r--tests/network/all_tests.php40
-rw-r--r--tests/network/checkdnsrr_test.php (renamed from tests/network/checkdnsrr.php)8
-rw-r--r--tests/network/ftp_fsock_pasv_epsv_test.php63
-rw-r--r--tests/profile/custom_test.php55
-rw-r--r--tests/profile/fixtures/profile_fields.xml31
-rw-r--r--tests/random/all_tests.php40
-rw-r--r--tests/random/gen_rand_string_test.php (renamed from tests/random/gen_rand_string.php)5
-rw-r--r--tests/regex/all_tests.php46
-rw-r--r--tests/regex/censor_test.php50
-rw-r--r--tests/regex/email_test.php (renamed from tests/regex/email.php)8
-rw-r--r--tests/regex/ipv4_test.php (renamed from tests/regex/ipv4.php)5
-rw-r--r--tests/regex/ipv6_test.php (renamed from tests/regex/ipv6.php)5
-rw-r--r--tests/regex/password_complexity_test.php81
-rw-r--r--tests/regex/table_prefix_test.php35
-rw-r--r--tests/regex/url_test.php (renamed from tests/regex/url.php)5
-rw-r--r--tests/request/all_tests.php41
-rw-r--r--tests/request/request_var_test.php (renamed from tests/request/request_var.php)6
-rw-r--r--tests/security/base.php (renamed from tests/security/all_tests.php)36
-rw-r--r--tests/security/extract_current_page_test.php (renamed from tests/security/extract_current_page.php)10
-rw-r--r--tests/security/hash_test.php21
-rw-r--r--tests/security/redirect_test.php (renamed from tests/security/redirect.php)14
-rw-r--r--tests/session/append_sid_test.php51
-rw-r--r--tests/session/continue_test.php121
-rw-r--r--tests/session/fixtures/sessions_empty.xml41
-rw-r--r--tests/session/fixtures/sessions_full.xml53
-rw-r--r--tests/session/init_test.php56
-rw-r--r--tests/session/testable_factory.php171
-rw-r--r--tests/template/all_tests.php40
-rw-r--r--tests/template/template_test.php (renamed from tests/template/template.php)259
-rw-r--r--tests/template/templates/_dummy_include.php3
-rw-r--r--tests/template/templates/_dummy_include.php.inc3
-rw-r--r--tests/template/templates/includephp.html2
-rw-r--r--tests/template/templates/loop_nested.html4
-rw-r--r--tests/test_framework/framework.php43
-rw-r--r--tests/test_framework/phpbb_database_test_case.php353
-rw-r--r--tests/test_framework/phpbb_database_test_connection_manager.php320
-rw-r--r--tests/test_framework/phpbb_functional_test_case.php241
-rw-r--r--tests/test_framework/phpbb_test_case.php17
-rw-r--r--tests/test_framework/phpbb_test_case_helpers.php69
-rw-r--r--tests/text_processing/all_tests.php41
-rw-r--r--tests/text_processing/censor_text_test.php85
-rw-r--r--tests/text_processing/make_clickable_test.php (renamed from tests/text_processing/make_clickable.php)8
-rw-r--r--tests/tmp/.gitkeep0
-rw-r--r--tests/user/lang_test.php58
-rw-r--r--tests/utf/all_tests.php43
-rw-r--r--tests/utf/normalizer_test.php323
-rw-r--r--tests/utf/utf8_clean_string_test.php5
-rw-r--r--tests/utf/utf8_wordwrap_test.php5
-rw-r--r--tests/wrapper/gmgetdate_test.php49
-rw-r--r--tests/wrapper/mt_rand_test.php46
-rw-r--r--tests/wrapper/version_compare_test.php130
72 files changed, 3532 insertions, 1065 deletions
diff --git a/tests/RUNNING_TESTS.txt b/tests/RUNNING_TESTS.txt
index 74a0635c1a..b976545c22 100644
--- a/tests/RUNNING_TESTS.txt
+++ b/tests/RUNNING_TESTS.txt
@@ -7,7 +7,7 @@ Prerequisites
PHPUnit
-------
-phpBB unit tests use PHPUnit framework. Version 3.3 or better is required
+phpBB unit tests use PHPUnit framework. Version 3.5 or better is required
to run the tests. PHPUnit prefers to be installed via PEAR; refer to
http://www.phpunit.de/ for more information.
@@ -21,12 +21,13 @@ the following PHP extensions must be installed and enabled to run unit tests:
Database Tests
--------------
+
By default all tests requiring a database connection will use sqlite. If you
do not have sqlite installed the tests will be skipped. If you wish to run the
tests on a different database you have to create a test_config.php file within
-your tests directory following the same format as phpBB's config.php. An example
-for mysqli can be found below. More information on configuration options can be
-found on the wiki (see below).
+your tests directory following the same format as phpBB's config.php. An
+example for mysqli can be found below. More information on configuration
+options can be found on the wiki (see below).
<?php
$dbms = 'mysqli';
@@ -36,22 +37,40 @@ found on the wiki (see below).
$dbuser = 'user';
$dbpasswd = 'password';
-Alternatively you can specify parameters in the environment, so e.g. the following
-will run phpunit with the same parameters as in the shown test_config.php file:
+It is possible to have multiple test_config.php files, for example if you
+are testing on multiple databases. You can specify which test_config.php file
+to use in the environment as follows:
+
+ $ PHPBB_TEST_CONFIG=tests/test_config.php phpunit
+
+Alternatively you can specify parameters in the environment, so e.g. the
+following will run phpunit with the same parameters as in the shown
+test_config.php file:
$ PHPBB_TEST_DBMS='mysqli' PHPBB_TEST_DBHOST='localhost' \
PHPBB_TEST_DBNAME='database' PHPBB_TEST_DBUSER='user' \
- PHPBB_TEST_DBPASSWD='password' phpunit all_tests.php
+ PHPBB_TEST_DBPASSWD='password' phpunit
Running
=======
-Once the prerequisites are installed, run the tests from tests directory:
+Once the prerequisites are installed, run the tests from the project root
+directory (above phpBB):
+
+ $ phpunit
+
+Slow tests
+--------------
+
+Certain tests, such as the UTF-8 normalizer or the DNS tests tend to be slow.
+Thus these tests are in the `slow` group, which is excluded by default. You can
+enable slow tests by copying the phpunit.xml.all file to phpunit.xml. If you
+only want the slow tests, run:
- $ phpunit all_tests.php
+ $ phpunit --group slow
More Information
================
Further information is available on phpbb wiki:
-http://wiki.phpbb.com/display/DEV/Unit+Tests
+http://wiki.phpbb.com/Unit_Tests
diff --git a/tests/all_tests.php b/tests/all_tests.php
deleted file mode 100644
index d1d711c4d7..0000000000
--- a/tests/all_tests.php
+++ /dev/null
@@ -1,69 +0,0 @@
-<?php
-/**
-*
-* @package testing
-* @copyright (c) 2008 phpBB Group
-* @license http://opensource.org/licenses/gpl-license.php GNU Public License
-*
-*/
-
-error_reporting(E_ALL);
-
-if (!defined('PHPUnit_MAIN_METHOD'))
-{
- define('PHPUnit_MAIN_METHOD', 'phpbb_all_tests::main');
-}
-
-require_once 'test_framework/framework.php';
-require_once 'PHPUnit/TextUI/TestRunner.php';
-
-require_once 'utf/all_tests.php';
-require_once 'request/all_tests.php';
-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';
-require_once 'network/all_tests.php';
-require_once 'random/all_tests.php';
-
-// exclude the test directory from code coverage reports
-if (version_compare(PHPUnit_Runner_Version::id(), '3.5.0') >= 0)
-{
- PHP_CodeCoverage_Filter::getInstance()->addDirectoryToBlacklist('./');
-}
-else
-{
- PHPUnit_Util_Filter::addDirectoryToFilter('./');
-}
-
-class phpbb_all_tests
-{
- public static function main()
- {
- PHPUnit_TextUI_TestRunner::run(self::suite());
- }
-
- public static function suite()
- {
- $suite = new PHPUnit_Framework_TestSuite('phpBB');
-
- $suite->addTest(phpbb_utf_all_tests::suite());
- $suite->addTest(phpbb_request_all_tests::suite());
- $suite->addTest(phpbb_security_all_tests::suite());
- $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());
- $suite->addTest(phpbb_network_all_tests::suite());
- $suite->addTest(phpbb_random_all_tests::suite());
-
- return $suite;
- }
-}
-
-if (PHPUnit_MAIN_METHOD == 'phpbb_all_tests::main')
-{
- phpbb_all_tests::main();
-}
-
diff --git a/tests/bbcode/url_bbcode_test.php b/tests/bbcode/url_bbcode_test.php
new file mode 100644
index 0000000000..15bdfc434f
--- /dev/null
+++ b/tests/bbcode/url_bbcode_test.php
@@ -0,0 +1,63 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2010 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions_content.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/bbcode.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/message_parser.php';
+require_once dirname(__FILE__) . '/../mock_user.php';
+
+class phpbb_url_bbcode_test extends phpbb_test_case
+{
+ public function url_bbcode_test_data()
+ {
+ return array(
+ array(
+ 'url only',
+ '[url]http://www.phpbb.com/community/[/url]',
+ '[url:]http&#58;//www&#46;phpbb&#46;com/community/[/url:]'
+ ),
+ array(
+ 'url with title',
+ '[url=http://www.phpbb.com/community/]One line URL text[/url]',
+ '[url=http&#58;//www&#46;phpbb&#46;com/community/:]One line URL text[/url:]'
+ ),
+ array(
+ 'url with multiline title',
+ "[url=http://www.phpbb.com/community/]Multiline\x0AURL\x0Atext[/url]",
+ "[url=http&#58;//www&#46;phpbb&#46;com/community/:]Multiline\x0AURL\x0Atext[/url:]"
+ ),
+ array(
+ 'unclosed url with multiline',
+ "test [url] test \x0A test [url=http://www.phpbb.com/]test[/url] test",
+ "test [url] test \x0A test [url=http&#58;//www&#46;phpbb&#46;com/:]test[/url:] test"
+ ),
+ array(
+ 'unclosed url with multiline and title',
+ "test [url=http://www.phpbb.com/]test \x0A [url]http://phpbb.com[/url] test",
+ "test [url=http&#58;//www&#46;phpbb&#46;com/:]test \x0A [url]http://phpbb.com[/url:] test"
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider url_bbcode_test_data
+ */
+ public function test_url($description, $message, $expected)
+ {
+ global $user;
+ $user = new phpbb_mock_user;
+
+ $bbcode = new bbcode_firstpass();
+ $bbcode->message = $message;
+ $bbcode->bbcode_init(false);
+ $bbcode->parse_bbcode();
+ $this->assertEquals($expected, $bbcode->message);
+ }
+}
diff --git a/tests/bootstrap.php b/tests/bootstrap.php
new file mode 100644
index 0000000000..d6c5d25bc8
--- /dev/null
+++ b/tests/bootstrap.php
@@ -0,0 +1,26 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2008 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+define('IN_PHPBB', true);
+$phpbb_root_path = 'phpBB/';
+$phpEx = 'php';
+require_once $phpbb_root_path . 'includes/startup.php';
+
+$table_prefix = 'phpbb_';
+require_once $phpbb_root_path . 'includes/constants.php';
+
+require_once 'test_framework/phpbb_test_case_helpers.php';
+require_once 'test_framework/phpbb_test_case.php';
+require_once 'test_framework/phpbb_database_test_case.php';
+require_once 'test_framework/phpbb_database_test_connection_manager.php';
+
+if (version_compare(PHP_VERSION, '5.3.0-dev', '>='))
+{
+ require_once 'test_framework/phpbb_functional_test_case.php';
+}
diff --git a/tests/dbal/all_tests.php b/tests/dbal/all_tests.php
deleted file mode 100644
index cfa8176246..0000000000
--- a/tests/dbal/all_tests.php
+++ /dev/null
@@ -1,42 +0,0 @@
-<?php
-/**
-*
-* @package testing
-* @copyright (c) 2008 phpBB Group
-* @license http://opensource.org/licenses/gpl-license.php GNU Public License
-*
-*/
-
-if (!defined('PHPUnit_MAIN_METHOD'))
-{
- define('PHPUnit_MAIN_METHOD', 'phpbb_dbal_all_tests::main');
-}
-
-require_once 'test_framework/framework.php';
-require_once 'PHPUnit/TextUI/TestRunner.php';
-
-require_once 'dbal/select.php';
-require_once 'dbal/write.php';
-
-class phpbb_dbal_all_tests
-{
- public static function main()
- {
- PHPUnit_TextUI_TestRunner::run(self::suite());
- }
-
- public static function suite()
- {
- $suite = new PHPUnit_Framework_TestSuite('phpBB Database Abstraction Layer');
-
- $suite->addTestSuite('phpbb_dbal_select_test');
- $suite->addTestSuite('phpbb_dbal_write_test');
-
- return $suite;
- }
-}
-
-if (PHPUnit_MAIN_METHOD == 'phpbb_dbal_all_tests::main')
-{
- phpbb_dbal_all_tests::main();
-}
diff --git a/tests/dbal/auto_increment_test.php b/tests/dbal/auto_increment_test.php
new file mode 100644
index 0000000000..e87fc1c6bd
--- /dev/null
+++ b/tests/dbal/auto_increment_test.php
@@ -0,0 +1,100 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2012 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/db/db_tools.php';
+
+class phpbb_dbal_auto_increment_test extends phpbb_database_test_case
+{
+ protected $db;
+ protected $tools;
+ protected $table_exists;
+ protected $table_data;
+
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/config.xml');
+ }
+
+ protected function setUp()
+ {
+ parent::setUp();
+
+ $this->db = $this->new_dbal();
+ $this->tools = new phpbb_db_tools($this->db);
+
+ $this->table_data = array(
+ 'COLUMNS' => array(
+ 'c_id' => array('UINT', NULL, 'auto_increment'),
+ 'c_uint' => array('UINT', 4),
+ ),
+ 'PRIMARY_KEY' => 'c_id',
+ );
+ $this->tools->sql_create_table('prefix_table_name', $this->table_data);
+ $this->table_exists = true;
+ }
+
+ protected function tearDown()
+ {
+ if ($this->table_exists)
+ {
+ $this->tools->sql_table_drop('prefix_table_name');
+ }
+
+ parent::tearDown();
+ }
+
+ static protected function get_default_values()
+ {
+ return array(
+ 'c_uint' => 0,
+ );
+ }
+
+ public function test_auto_increment()
+ {
+ $sql = 'DELETE FROM prefix_table_name';
+ $result = $this->db->sql_query($sql);
+
+ $row1 = array_merge(self::get_default_values(), array(
+ 'c_uint' => 1,
+ ));
+ $row2 = array_merge(self::get_default_values(), array(
+ 'c_uint' => 2,
+ ));
+
+ $sql = 'INSERT INTO prefix_table_name ' . $this->db->sql_build_array('INSERT', $row1);
+ $result = $this->db->sql_query($sql);
+ $id1 = $this->db->sql_nextid();
+
+ $sql = 'INSERT INTO prefix_table_name ' . $this->db->sql_build_array('INSERT', $row2);
+ $result = $this->db->sql_query($sql);
+ $id2 = $this->db->sql_nextid();
+
+ $this->assertGreaterThan($id1, $id2, 'Auto increment should increase the id value');
+
+ $sql = "SELECT *
+ FROM prefix_table_name WHERE c_id = $id1";
+ $result = $this->db->sql_query($sql);
+ $row_actual = $this->db->sql_fetchrow($result);
+ $this->db->sql_freeresult($result);
+
+ $row1['c_id'] = $id1;
+ $this->assertEquals($row1, $row_actual);
+
+ $sql = "SELECT *
+ FROM prefix_table_name WHERE c_id = $id2";
+ $result = $this->db->sql_query($sql);
+ $row_actual = $this->db->sql_fetchrow($result);
+ $this->db->sql_freeresult($result);
+
+ $row2['c_id'] = $id2;
+ $this->assertEquals($row2, $row_actual);
+ }
+}
diff --git a/tests/dbal/cross_join_test.php b/tests/dbal/cross_join_test.php
new file mode 100644
index 0000000000..6c6b8a8449
--- /dev/null
+++ b/tests/dbal/cross_join_test.php
@@ -0,0 +1,55 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2011 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php';
+
+class phpbb_dbal_cross_join_test extends phpbb_database_test_case
+{
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/massmail_crossjoin.xml');
+ }
+
+ public function test_cross_join()
+ {
+ $db = $this->new_dbal();
+
+ // http://tracker.phpbb.com/browse/PHPBB3-10296
+ // Test CROSS JOIN with INNER JOIN
+ // Failed on Postgres, MSSQL and Oracle
+ $db->sql_return_on_error(true);
+
+ $sql_ary = array(
+ 'SELECT' => 'u.username',
+ 'FROM' => array(
+ 'phpbb_users' => 'u',
+ 'phpbb_user_group' => 'ug',
+ ),
+ 'LEFT_JOIN' => array(
+ array(
+ 'FROM' => array(
+ 'phpbb_banlist' => 'b',
+ ),
+ 'ON' => 'u.user_id = b.ban_userid',
+ ),
+ ),
+ 'WHERE' => 'ug.group_id = 1
+ AND u.user_id = ug.user_id
+ AND b.ban_id IS NULL',
+ 'ORDER_BY' => 'u.username',
+ );
+ $sql = $db->sql_build_query('SELECT', $sql_ary);
+ $result = $db->sql_query($sql);
+
+ $db->sql_return_on_error(false);
+
+ $this->assertEquals(array(array('username' => 'mass email')), $db->sql_fetchrowset($result));
+ }
+}
diff --git a/tests/dbal/db_tools_test.php b/tests/dbal/db_tools_test.php
new file mode 100644
index 0000000000..c20e46011f
--- /dev/null
+++ b/tests/dbal/db_tools_test.php
@@ -0,0 +1,333 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2011 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/db/db_tools.php';
+
+class phpbb_dbal_db_tools_test extends phpbb_database_test_case
+{
+ protected $db;
+ protected $tools;
+ protected $table_exists;
+ protected $table_data;
+
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/config.xml');
+ }
+
+ protected function setUp()
+ {
+ parent::setUp();
+
+ $this->db = $this->new_dbal();
+ $this->tools = new phpbb_db_tools($this->db);
+
+ $this->table_data = array(
+ 'COLUMNS' => array(
+ 'c_id' => array('UINT', NULL, 'auto_increment'),
+ 'c_int_size' => array('INT:4', 4),
+ 'c_bint' => array('BINT', 4),
+ 'c_uint' => array('UINT', 4),
+ 'c_uint_size' => array('UINT:4', 4),
+ 'c_tint_size' => array('TINT:2', 4),
+ 'c_usint' => array('USINT', 4),
+ 'c_bool' => array('BOOL', 1),
+ 'c_vchar' => array('VCHAR', 'foo'),
+ 'c_vchar_size' => array('VCHAR:4', 'foo'),
+ 'c_char_size' => array('CHAR:4', 'foo'),
+ 'c_xstext' => array('XSTEXT', 'foo'),
+ 'c_stext' => array('STEXT', 'foo'),
+ 'c_text' => array('TEXT', 'foo'),
+ 'c_mtext' => array('MTEXT', 'foo'),
+ 'c_xstext_uni' => array('XSTEXT_UNI', 'foo'),
+ 'c_stext_uni' => array('STEXT_UNI', 'foo'),
+ 'c_text_uni' => array('TEXT_UNI', 'foo'),
+ 'c_mtext_uni' => array('MTEXT_UNI', 'foo'),
+ 'c_timestamp' => array('TIMESTAMP', 4),
+ 'c_decimal' => array('DECIMAL', 4.2),
+ 'c_decimal_size' => array('DECIMAL:6', 4.2),
+ 'c_pdecimal' => array('PDECIMAL', 4.2),
+ 'c_pdecimal_size' => array('PDECIMAL:7', 4.2),
+ 'c_vchar_uni' => array('VCHAR_UNI', 'foo'),
+ 'c_vchar_uni_size' => array('VCHAR_UNI:4', 'foo'),
+ 'c_vchar_ci' => array('VCHAR_CI', 'foo'),
+ 'c_varbinary' => array('VARBINARY', 'foo'),
+ ),
+ 'PRIMARY_KEY' => 'c_id',
+ 'KEYS' => array(
+ 'i_simple' => array('INDEX', 'c_uint'),
+ 'i_uniq' => array('UNIQUE', 'c_vchar'),
+ 'i_comp' => array('INDEX', array('c_vchar_uni', 'c_bool')),
+ 'i_comp_uniq' => array('UNIQUE', array('c_vchar_size', 'c_usint')),
+ ),
+ );
+ $this->tools->sql_create_table('prefix_table_name', $this->table_data);
+ $this->table_exists = true;
+ }
+
+ protected function tearDown()
+ {
+ if ($this->table_exists)
+ {
+ $this->tools->sql_table_drop('prefix_table_name');
+ }
+
+ parent::tearDown();
+ }
+
+ public function test_created_and_drop_table()
+ {
+ // table is empty after creation and queryable
+ $sql = 'SELECT * FROM prefix_table_name';
+ $result = $this->db->sql_query($sql);
+ $this->assertTrue(! $this->db->sql_fetchrow($result));
+ $this->db->sql_freeresult($result);
+
+ $this->table_exists = false;
+ $this->tools->sql_table_drop('prefix_table_name');
+ }
+
+ static protected function get_default_values()
+ {
+ return array(
+ 'c_int_size' => 0,
+ 'c_bint' => 0,
+ 'c_uint' => 0,
+ 'c_uint_size' => 0,
+ 'c_tint_size' => 0,
+ 'c_usint' => 0,
+ 'c_bool' => 0,
+ 'c_vchar' => '',
+ 'c_vchar_size' => '',
+ 'c_char_size' => 'abcd',
+ 'c_xstext' => '',
+ 'c_stext' => '',
+ 'c_text' => '',
+ 'c_mtext' => '',
+ 'c_xstext_uni' => '',
+ 'c_stext_uni' => '',
+ 'c_text_uni' => '',
+ 'c_mtext_uni' => '',
+ 'c_timestamp' => 0,
+ 'c_decimal' => 0,
+ 'c_decimal_size' => 0,
+ 'c_pdecimal' => 0,
+ 'c_pdecimal_size' => 0,
+ 'c_vchar_uni' => '',
+ 'c_vchar_uni_size' => '',
+ 'c_vchar_ci' => '',
+ 'c_varbinary' => '',
+ );
+ }
+
+ static public function column_values()
+ {
+ return array(
+ array('c_int_size', -9999),
+ array('c_bint', '99999999999999999'),
+ array('c_uint', 16777215),
+ array('c_uint_size', 9999),
+ array('c_tint_size', -99),
+ array('c_usint', 99),
+ array('c_bool', 0),
+ array('c_vchar', str_repeat('a', 255)),
+ array('c_vchar_size', str_repeat('a', 4)),
+ array('c_char_size', str_repeat('a', 4)),
+ array('c_xstext', str_repeat('a', 1000)),
+ array('c_stext', str_repeat('a', 3000)),
+ array('c_text', str_repeat('a', 8000)),
+ array('c_mtext', str_repeat('a', 10000)),
+ array('c_xstext_uni', str_repeat("\xC3\x84", 100)),
+ array('c_stext_uni', str_repeat("\xC3\x84", 255)),
+ array('c_text_uni', str_repeat("\xC3\x84", 4000)),
+ array('c_mtext_uni', str_repeat("\xC3\x84", 10000)),
+ array('c_timestamp', 2147483647),
+ array('c_decimal', 999.99),
+ array('c_decimal_size', 9999.99),
+ array('c_pdecimal', 999.999),
+ array('c_pdecimal_size', 9999.999),
+ array('c_vchar_uni', str_repeat("\xC3\x84", 255)),
+ array('c_vchar_uni_size', str_repeat("\xC3\x84", 4)),
+ array('c_vchar_ci', str_repeat("\xC3\x84", 255)),
+ array('c_varbinary', str_repeat("\x00\xFF", 127)),
+ );
+ }
+
+ /**
+ * @dataProvider column_values
+ */
+ public function test_created_column($column_name, $column_value)
+ {
+ if ($column_name === 'c_varbinary' && stripos(get_class($this->db), 'mysql') === false)
+ {
+ $this->markTestIncomplete('Binary handling is not implemented properly on non-MySQL DBMSes.');
+ }
+
+ $row_insert = self::get_default_values();
+ $row_insert[$column_name] = $column_value;
+
+ // empty table
+ $sql = 'DELETE FROM prefix_table_name';
+ $result = $this->db->sql_query($sql);
+
+ $sql = 'INSERT INTO prefix_table_name ' . $this->db->sql_build_array('INSERT', $row_insert);
+ $result = $this->db->sql_query($sql);
+
+ $sql = "SELECT *
+ FROM prefix_table_name";
+ $result = $this->db->sql_query($sql);
+ $row_actual = $this->db->sql_fetchrow($result);
+ $this->db->sql_freeresult($result);
+
+ $row_expect = $row_insert;
+
+ unset($row_actual['id']); // auto increment id changes, so ignore
+
+ $type = $this->table_data['COLUMNS'][$column_name][0];
+ $this->assertEquals($row_expect[$column_name], $row_actual[$column_name], "Column $column_name of type $type should have equal return and input value.");
+ }
+
+ public function test_list_columns()
+ {
+ $this->assertEquals(
+ array_keys($this->table_data['COLUMNS']),
+ array_values($this->tools->sql_list_columns('prefix_table_name'))
+ );
+ }
+
+ public function test_column_exists()
+ {
+ $this->assertTrue($this->tools->sql_column_exists('prefix_table_name', 'c_id'));
+ $this->assertFalse($this->tools->sql_column_exists('prefix_table_name', 'column_does_not_exist'));
+ }
+
+ public function test_column_remove()
+ {
+ $this->assertTrue($this->tools->sql_column_exists('prefix_table_name', 'c_int_size'));
+
+ $this->assertTrue($this->tools->sql_column_remove('prefix_table_name', 'c_int_size'));
+
+ $this->assertFalse($this->tools->sql_column_exists('prefix_table_name', 'c_int_size'));
+ }
+
+ public function test_column_remove_primary()
+ {
+ $this->assertTrue($this->tools->sql_column_exists('prefix_table_name', 'c_id'));
+
+ $this->assertTrue($this->tools->sql_column_remove('prefix_table_name', 'c_id'));
+
+ $this->assertFalse($this->tools->sql_column_exists('prefix_table_name', 'c_id'));
+ }
+
+ public function test_list_tables()
+ {
+ $tables = $this->tools->sql_list_tables();
+ $this->assertTrue(isset($tables['prefix_table_name']));
+ $this->assertFalse(isset($tables['prefix_does_not_exist']));
+ }
+
+ public function test_table_exists()
+ {
+ $this->assertTrue($this->tools->sql_table_exists('prefix_table_name'));
+ $this->assertFalse($this->tools->sql_table_exists('prefix_does_not_exist'));
+ }
+
+ public function test_table_drop()
+ {
+ $this->tools->sql_create_table('prefix_test_table',
+ array('COLUMNS' => array(
+ 'foo' => array('UINT', 42)))
+ );
+
+ $this->assertTrue($this->tools->sql_table_exists('prefix_test_table'));
+
+ $this->tools->sql_table_drop('prefix_test_table');
+
+ $this->assertFalse($this->tools->sql_table_exists('prefix_test_table'));
+ }
+
+ public function test_peform_schema_changes_drop_tables()
+ {
+ $db_tools = $this->getMock('phpbb_db_tools', array(
+ 'sql_table_exists',
+ 'sql_table_drop',
+ ), array(&$this->db));
+
+ // pretend all tables exist
+ $db_tools->expects($this->any())->method('sql_table_exists')
+ ->will($this->returnValue(true));
+
+ // drop tables
+ $db_tools->expects($this->exactly(2))->method('sql_table_drop');
+ $db_tools->expects($this->at(1))->method('sql_table_drop')
+ ->with($this->equalTo('dropped_table_1'));
+ $db_tools->expects($this->at(3))->method('sql_table_drop')
+ ->with($this->equalTo('dropped_table_2'));
+
+ $db_tools->perform_schema_changes(array(
+ 'drop_tables' => array(
+ 'dropped_table_1',
+ 'dropped_table_2',
+ ),
+ ));
+ }
+
+ public function test_peform_schema_changes_drop_columns()
+ {
+ $db_tools = $this->getMock('phpbb_db_tools', array(
+ 'sql_column_exists',
+ 'sql_column_remove',
+ ), array(&$this->db));
+
+ // pretend all columns exist
+ $db_tools->expects($this->any())->method('sql_column_exists')
+ ->will($this->returnValue(true));
+ $db_tools->expects($this->any())->method('sql_column_exists')
+ ->will($this->returnValue(true));
+
+ // drop columns
+ $db_tools->expects($this->exactly(2))->method('sql_column_remove');
+ $db_tools->expects($this->at(1))->method('sql_column_remove')
+ ->with($this->equalTo('existing_table'), $this->equalTo('dropped_column_1'));
+ $db_tools->expects($this->at(3))->method('sql_column_remove')
+ ->with($this->equalTo('existing_table'), $this->equalTo('dropped_column_2'));
+
+ $db_tools->perform_schema_changes(array(
+ 'drop_columns' => array(
+ 'existing_table' => array(
+ 'dropped_column_1',
+ 'dropped_column_2',
+ ),
+ ),
+ ));
+ }
+
+ public function test_index_exists()
+ {
+ $this->assertTrue($this->tools->sql_index_exists('prefix_table_name', 'i_simple'));
+ }
+
+ public function test_unique_index_exists()
+ {
+ $this->assertTrue($this->tools->sql_unique_index_exists('prefix_table_name', 'i_uniq'));
+ }
+
+ public function test_create_index_against_index_exists()
+ {
+ $this->tools->sql_create_index('prefix_table_name', 'fookey', array('c_timestamp', 'c_decimal'));
+ $this->assertTrue($this->tools->sql_index_exists('prefix_table_name', 'fookey'));
+ }
+
+ public function test_create_unique_index_against_unique_index_exists()
+ {
+ $this->tools->sql_create_unique_index('prefix_table_name', 'i_uniq_ts_id', array('c_timestamp', 'c_id'));
+ $this->assertTrue($this->tools->sql_unique_index_exists('prefix_table_name', 'i_uniq_ts_id'));
+ }
+}
diff --git a/tests/dbal/fixtures/massmail_crossjoin.xml b/tests/dbal/fixtures/massmail_crossjoin.xml
new file mode 100644
index 0000000000..ef0a2b7149
--- /dev/null
+++ b/tests/dbal/fixtures/massmail_crossjoin.xml
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="phpbb_banlist">
+ <column>ban_id</column>
+ <column>ban_userid</column>
+ <row>
+ <value>1</value>
+ <value>2</value>
+ </row>
+ </table>
+ <table name="phpbb_users">
+ <column>user_id</column>
+ <column>username</column>
+ <column>username_clean</column>
+ <column>user_permissions</column>
+ <column>user_sig</column>
+ <column>user_occ</column>
+ <column>user_interests</column>
+ <row>
+ <value>1</value>
+ <value>mass email</value>
+ <value>mass email</value>
+ <value></value>
+ <value></value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>2</value>
+ <value>banned</value>
+ <value>banned</value>
+ <value></value>
+ <value></value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>3</value>
+ <value>not in group</value>
+ <value>not in group</value>
+ <value></value>
+ <value></value>
+ <value></value>
+ <value></value>
+ </row>
+ </table>
+ <table name="phpbb_user_group">
+ <column>user_id</column>
+ <column>group_id</column>
+ <row>
+ <value>1</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>2</value>
+ <value>1</value>
+ </row>
+ </table>
+</dataset>
diff --git a/tests/dbal/fixtures/styles.xml b/tests/dbal/fixtures/styles.xml
new file mode 100644
index 0000000000..47b384c47f
--- /dev/null
+++ b/tests/dbal/fixtures/styles.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="phpbb_styles">
+ <column>style_id</column>
+ <column>style_name</column>
+ <column>style_copyright</column>
+ <column>style_active</column>
+ <column>template_id</column>
+ <column>theme_id</column>
+ <column>imageset_id</column>
+ <row>
+ <value>1</value>
+ <value>prosilver</value>
+ <value>&amp;copy; phpBB Group</value>
+ <value>1</value>
+ <value>1</value>
+ <value>1</value>
+ <value>1</value>
+ </row>
+ <row>
+ <value>2</value>
+ <value>prosilver2</value>
+ <value>&amp;copy; phpBB Group</value>
+ <value>0</value>
+ <value>2</value>
+ <value>2</value>
+ <value>2</value>
+ </row>
+ <row>
+ <value>3</value>
+ <value>Prosilver1</value>
+ <value>&amp;copy; phpBB Group</value>
+ <value>0</value>
+ <value>3</value>
+ <value>3</value>
+ <value>3</value>
+ </row>
+ </table>
+</dataset>
diff --git a/tests/dbal/fixtures/three_users.xml b/tests/dbal/fixtures/three_users.xml
index a6789f4a01..a50e3e8634 100644
--- a/tests/dbal/fixtures/three_users.xml
+++ b/tests/dbal/fixtures/three_users.xml
@@ -3,17 +3,33 @@
<table name="phpbb_users">
<column>user_id</column>
<column>username_clean</column>
+ <column>user_permissions</column>
+ <column>user_sig</column>
+ <column>user_occ</column>
+ <column>user_interests</column>
<row>
<value>1</value>
<value>barfoo</value>
+ <value></value>
+ <value></value>
+ <value></value>
+ <value></value>
</row>
<row>
<value>2</value>
<value>foobar</value>
+ <value></value>
+ <value></value>
+ <value></value>
+ <value></value>
</row>
<row>
<value>3</value>
<value>bertie</value>
+ <value></value>
+ <value></value>
+ <value></value>
+ <value></value>
</row>
</table>
</dataset>
diff --git a/tests/dbal/order_lower_test.php b/tests/dbal/order_lower_test.php
new file mode 100644
index 0000000000..b50494d506
--- /dev/null
+++ b/tests/dbal/order_lower_test.php
@@ -0,0 +1,62 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2011 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+class phpbb_dbal_order_lower_test extends phpbb_database_test_case
+{
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/styles.xml');
+ }
+
+ public function test_cross_join()
+ {
+ $db = $this->new_dbal();
+
+ // http://tracker.phpbb.com/browse/PHPBB3-10507
+ // Test ORDER BY LOWER(style_name)
+ $db->sql_return_on_error(true);
+
+ $sql = 'SELECT * FROM phpbb_styles ORDER BY LOWER(style_name)';
+ $result = $db->sql_query($sql);
+
+ $db->sql_return_on_error(false);
+
+ $this->assertEquals(array(
+ array(
+ 'style_id' => 1,
+ 'style_name' => 'prosilver',
+ 'style_copyright' => '&copy; phpBB Group',
+ 'style_active' => 1,
+ 'template_id' => 1,
+ 'theme_id' => 1,
+ 'imageset_id' => 1
+ ),
+ array(
+ 'style_id' => 3,
+ 'style_name' => 'Prosilver1',
+ 'style_copyright' => '&copy; phpBB Group',
+ 'style_active' => 0,
+ 'template_id' => 3,
+ 'theme_id' => 3,
+ 'imageset_id' => 3
+ ),
+ array(
+ 'style_id' => 2,
+ 'style_name' => 'prosilver2',
+ 'style_copyright' => '&copy; phpBB Group',
+ 'style_active' => 0,
+ 'template_id' => 2,
+ 'theme_id' => 2,
+ 'imageset_id' => 2
+ )
+ ),
+ $db->sql_fetchrowset($result)
+ );
+ }
+}
diff --git a/tests/dbal/select.php b/tests/dbal/select_test.php
index 70f27549d2..81cd13b006 100644
--- a/tests/dbal/select.php
+++ b/tests/dbal/select_test.php
@@ -3,12 +3,12 @@
*
* @package testing
* @copyright (c) 2008 phpBB Group
-* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
-require_once 'test_framework/framework.php';
-require_once '../phpBB/includes/functions.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php';
class phpbb_dbal_select_test extends phpbb_database_test_case
{
@@ -125,6 +125,32 @@ class phpbb_dbal_select_test extends phpbb_database_test_case
$this->assertEquals($expected, $ary);
}
+ public static function fetchfield_seek_data()
+ {
+ return array(
+ array(1, 'foobar'),
+ array(0, 'barfoo'),
+ array(2, 'bertie'),
+ );
+ }
+
+ /**
+ * @dataProvider fetchfield_seek_data
+ */
+ public function test_fetchfield_seek($rownum, $expected)
+ {
+ $db = $this->new_dbal();
+
+ $result = $db->sql_query('SELECT username_clean
+ FROM phpbb_users
+ ORDER BY user_id ASC');
+
+ $field = $db->sql_fetchfield('username_clean', $rownum, $result);
+ $db->sql_freeresult($result);
+
+ $this->assertEquals($expected, $field);
+ }
+
public static function query_limit_data()
{
return array(
@@ -318,4 +344,70 @@ class phpbb_dbal_select_test extends phpbb_database_test_case
$db->sql_freeresult($result);
}
+
+ public function test_nested_transactions()
+ {
+ $db = $this->new_dbal();
+
+ // nested transactions should work on systems that do not require
+ // buffering of nested transactions, so ignore the ones that need
+ // buffering
+ if ($db->sql_buffer_nested_transactions())
+ {
+ return;
+ }
+
+ $sql = 'SELECT user_id FROM phpbb_users ORDER BY user_id ASC';
+ $result1 = $db->sql_query($sql);
+
+ $db->sql_transaction('begin');
+ $result2 = $db->sql_query($sql);
+ $row = $db->sql_fetchrow($result2);
+ $db->sql_transaction('commit');
+
+ $this->assertEquals('1', $row['user_id']);
+ }
+
+ /**
+ * fix for PHPBB3-10307
+ */
+ public function test_sql_fetchrow_returns_false_when_empty()
+ {
+ $db = $this->new_dbal();
+
+ $sql = 'SELECT user_id
+ FROM phpbb_users
+ WHERE 1 = 0';
+ $result = $db->sql_query($sql);
+
+ $row = $db->sql_fetchrow($result);
+ $db->sql_freeresult($result);
+
+ $this->assertSame(false, $row);
+ }
+
+ public function test_get_row_count()
+ {
+ $this->assertSame(
+ 3,
+ (int) $this->new_dbal()->get_row_count('phpbb_users'),
+ "Failed asserting that user table has exactly 3 rows."
+ );
+ }
+
+ public function test_get_estimated_row_count()
+ {
+ $actual = $this->new_dbal()->get_estimated_row_count('phpbb_users');
+
+ if (is_string($actual) && isset($actual[0]) && $actual[0] === '~')
+ {
+ $actual = substr($actual, 1);
+ }
+
+ $this->assertGreaterThan(
+ 1,
+ $actual,
+ "Failed asserting that estimated row count of user table is greater than 1."
+ );
+ }
}
diff --git a/tests/dbal/write.php b/tests/dbal/write_test.php
index 01deacda69..596c50a220 100644
--- a/tests/dbal/write.php
+++ b/tests/dbal/write_test.php
@@ -3,12 +3,11 @@
*
* @package testing
* @copyright (c) 2008 phpBB Group
-* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
-require_once 'test_framework/framework.php';
-require_once '../phpBB/includes/functions.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
class phpbb_dbal_write_test extends phpbb_database_test_case
{
diff --git a/tests/error_collector_test.php b/tests/error_collector_test.php
new file mode 100644
index 0000000000..d67dea3719
--- /dev/null
+++ b/tests/error_collector_test.php
@@ -0,0 +1,35 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2011 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+require_once dirname(__FILE__) . '/../phpBB/includes/functions.php';
+require_once dirname(__FILE__) . '/../phpBB/includes/error_collector.php';
+
+class phpbb_error_collector_test extends phpbb_test_case
+{
+ public function test_collection()
+ {
+ $collector = new phpbb_error_collector;
+ $collector->install();
+
+ // Cause a warning
+ 1/0; $line = __LINE__;
+
+ $collector->uninstall();
+
+ list($errno, $msg_text, $errfile, $errline) = $collector->errors[0];
+ $error_contents = $collector->format_errors();
+
+ $this->assertEquals($errno, 2);
+
+ // Unfortunately $error_contents will contain the full path here,
+ // because the tests directory is outside of phpbb root path.
+ $this->assertStringStartsWith('Errno 2: Division by zero at ', $error_contents);
+ $this->assertStringEndsWith(" line $line", $error_contents);
+ }
+}
diff --git a/tests/functional/auth_test.php b/tests/functional/auth_test.php
new file mode 100644
index 0000000000..e955dcb4df
--- /dev/null
+++ b/tests/functional/auth_test.php
@@ -0,0 +1,40 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2012 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+/**
+* @group functional
+*/
+class phpbb_functional_auth_test extends phpbb_functional_test_case
+{
+ public function test_login()
+ {
+ $this->login();
+
+ // check for logout link
+ $crawler = $this->request('GET', 'index.php');
+ $this->assertContains($this->lang('LOGOUT_USER', 'admin'), $crawler->filter('.navbar')->text());
+ }
+
+ /**
+ * @depends test_login
+ */
+ public function test_logout()
+ {
+ $this->login();
+ $this->add_lang('ucp');
+
+ // logout
+ $crawler = $this->request('GET', 'ucp.php?sid=' . $this->sid . '&mode=logout');
+ $this->assertContains($this->lang('LOGOUT_REDIRECT'), $crawler->filter('#message')->text());
+
+ // look for a register link, which should be visible only when logged out
+ $crawler = $this->request('GET', 'index.php');
+ $this->assertContains($this->lang('REGISTER'), $crawler->filter('.navbar')->text());
+ }
+}
diff --git a/tests/functional/browse_test.php b/tests/functional/browse_test.php
new file mode 100644
index 0000000000..26c18c4c1f
--- /dev/null
+++ b/tests/functional/browse_test.php
@@ -0,0 +1,32 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2011 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+/**
+* @group functional
+*/
+class phpbb_functional_browse_test extends phpbb_functional_test_case
+{
+ public function test_index()
+ {
+ $crawler = $this->request('GET', 'index.php');
+ $this->assertGreaterThan(0, $crawler->filter('.topiclist')->count());
+ }
+
+ public function test_viewforum()
+ {
+ $crawler = $this->request('GET', 'viewforum.php?f=2');
+ $this->assertGreaterThan(0, $crawler->filter('.topiclist')->count());
+ }
+
+ public function test_viewtopic()
+ {
+ $crawler = $this->request('GET', 'viewtopic.php?t=1');
+ $this->assertGreaterThan(0, $crawler->filter('.postbody')->count());
+ }
+}
diff --git a/tests/functional/lang_test.php b/tests/functional/lang_test.php
new file mode 100644
index 0000000000..053806a431
--- /dev/null
+++ b/tests/functional/lang_test.php
@@ -0,0 +1,45 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2012 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+/**
+* @group functional
+*/
+class phpbb_functional_lang_test extends phpbb_functional_test_case
+{
+ public function test_lang()
+ {
+ // Test a language string present in the common language file
+ $this->assertEquals('Board index', $this->lang('FORUM_INDEX'));
+ }
+
+ /**
+ * @expectedException RuntimeException
+ */
+ public function test_lang_missing()
+ {
+ $this->assertEquals('Your account has now been activated. Thank you for registering.', $this->lang('ACCOUNT_ACTIVE'));
+ }
+
+ public function test_add_lang()
+ {
+ $this->add_lang('ucp');
+
+ // Test a language string present only in the UCP language file
+ $this->assertEquals('Your account has now been activated. Thank you for registering.', $this->lang('ACCOUNT_ACTIVE'));
+ }
+
+ public function test_add_langs()
+ {
+ $this->add_lang(array('groups', 'memberlist'));
+
+ // Test a language string from each UCP and memberlist
+ $this->assertEquals('The selected group is already your default group.', $this->lang('ALREADY_DEFAULT_GROUP'));
+ $this->assertEquals('Profile', $this->lang('ABOUT_USER'));
+ }
+}
diff --git a/tests/mock/cache.php b/tests/mock/cache.php
new file mode 100644
index 0000000000..650545c3d6
--- /dev/null
+++ b/tests/mock/cache.php
@@ -0,0 +1,95 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2008 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+class phpbb_mock_cache
+{
+ public function __construct($data = array())
+ {
+ $this->data = $data;
+
+ if (!isset($this->data['_bots']))
+ {
+ $this->data['_bots'] = array();
+ }
+ }
+
+ public function get($var_name)
+ {
+ if (isset($this->data[$var_name]))
+ {
+ return $this->data[$var_name];
+ }
+
+ return false;
+ }
+
+ public function put($var_name, $var, $ttl = 0)
+ {
+ $this->data[$var_name] = $var;
+ }
+
+ /**
+ * Obtain active bots
+ */
+ public function obtain_bots()
+ {
+ return $this->data['_bots'];
+ }
+
+ /**
+ * Obtain list of word censors. We don't need to parse them here,
+ * that is tested elsewhere.
+ */
+ public function obtain_word_list()
+ {
+ return array(
+ 'match' => array(
+ '#(?<![\\p{Nd}\\p{L}_-])([\\p{Nd}\\p{L}_-]*?badword1[\\p{Nd}\\p{L}_-]*?)(?![\\p{Nd}\\p{L}_-])#iu',
+ '#(?<![\\p{Nd}\\p{L}_-])([\\p{Nd}\\p{L}_-]*?badword2)(?![\\p{Nd}\\p{L}_-])#iu',
+ '#(?<![\\p{Nd}\\p{L}_-])(badword3[\\p{Nd}\\p{L}_-]*?)(?![\\p{Nd}\\p{L}_-])#iu',
+ '#(?<![\\p{Nd}\\p{L}_-])(badword4)(?![\\p{Nd}\\p{L}_-])#iu',
+ ),
+ 'replace' => array(
+ 'replacement1',
+ 'replacement2',
+ 'replacement3',
+ 'replacement4',
+ ),
+ );
+ }
+
+ public function set_bots($bots)
+ {
+ $this->data['_bots'] = $bots;
+ }
+
+ public function checkVar(PHPUnit_Framework_Assert $test, $var_name, $data)
+ {
+ $test->assertTrue(isset($this->data[$var_name]));
+ $test->assertEquals($data, $this->data[$var_name]);
+ }
+
+ public function check(PHPUnit_Framework_Assert $test, $data, $ignore_db_info = true)
+ {
+ $cache_data = $this->data;
+
+ if ($ignore_db_info)
+ {
+ unset($cache_data['mssqlodbc_version']);
+ unset($cache_data['mssql_version']);
+ unset($cache_data['mysql_version']);
+ unset($cache_data['mysqli_version']);
+ unset($cache_data['pgsql_version']);
+ unset($cache_data['sqlite_version']);
+ }
+
+ $test->assertEquals($data, $cache_data);
+ }
+}
+
diff --git a/tests/mock/session_testable.php b/tests/mock/session_testable.php
new file mode 100644
index 0000000000..70a58fb6cc
--- /dev/null
+++ b/tests/mock/session_testable.php
@@ -0,0 +1,63 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2008 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/session.php';
+
+/**
+* Extends the session class to overwrite the setting of cookies.
+*
+* The session class directly writes cookie headers making it impossible to
+* test it without warnings about sent headers. This class only stores cookie
+* data for later verification.
+*/
+class phpbb_mock_session_testable extends session
+{
+ private $_cookies = array();
+
+ public function set_cookie($name, $data, $time)
+ {
+ $this->_cookies[$name] = array($data, $time);
+ }
+
+ /**
+ * Checks if the cookies were set correctly.
+ *
+ * @param PHPUnit_Framework_Assert test The test from which this is called
+ * @param array(string => mixed) cookies The cookie data to check against.
+ * The keys are cookie names, the values can either be null to
+ * check only the existance of the cookie, or an array(d, t),
+ * where d is the cookie data to check, or null to skip the
+ * check and t is the cookie time to check, or null to skip.
+ */
+ public function check_cookies(PHPUnit_Framework_Assert $test, $cookies)
+ {
+ $test->assertEquals(array_keys($cookies), array_keys($this->_cookies), 'Incorrect cookies were set');
+
+ foreach ($cookies as $name => $cookie)
+ {
+ if (!is_null($cookie))
+ {
+ $data = $cookie[0];
+ $time = $cookie[1];
+
+ if (!is_null($data))
+ {
+ $test->assertEquals($data, $this->_cookies[$name][0], "Cookie $name contains incorrect data");
+ }
+
+ if (!is_null($time))
+ {
+ $test->assertEquals($time, $this->_cookies[$name][1], "Cookie $name expires at the wrong time");
+ }
+ }
+ }
+ }
+}
+
diff --git a/tests/mock_user.php b/tests/mock_user.php
new file mode 100644
index 0000000000..ec14ce430e
--- /dev/null
+++ b/tests/mock_user.php
@@ -0,0 +1,36 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2011 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+/**
+* Mock user class.
+* This class is used when tests invoke phpBB code expecting to have a global
+* user object, to avoid instantiating the actual user object.
+* It has a minimum amount of functionality, just to make tests work.
+*/
+class phpbb_mock_user
+{
+ public $host = "testhost";
+ public $page = array('root_script_path' => '/');
+
+ private $options = array();
+ public function optionget($item)
+ {
+ if (!isset($this->options[$item]))
+ {
+ throw new Exception(sprintf("You didn't set the option '%s' on the mock user using optionset.", $item));
+ }
+
+ return $this->options[$item];
+ }
+
+ public function optionset($item, $value)
+ {
+ $this->options[$item] = $value;
+ }
+}
diff --git a/tests/network/all_tests.php b/tests/network/all_tests.php
deleted file mode 100644
index b500647f81..0000000000
--- a/tests/network/all_tests.php
+++ /dev/null
@@ -1,40 +0,0 @@
-<?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_network_all_tests::main');
-}
-
-require_once 'test_framework/framework.php';
-require_once 'PHPUnit/TextUI/TestRunner.php';
-
-require_once 'network/checkdnsrr.php';
-
-class phpbb_network_all_tests
-{
- public static function main()
- {
- PHPUnit_TextUI_TestRunner::run(self::suite());
- }
-
- public static function suite()
- {
- $suite = new PHPUnit_Framework_TestSuite('phpBB Network Functions');
-
- $suite->addTestSuite('phpbb_network_checkdnsrr_test');
-
- return $suite;
- }
-}
-
-if (PHPUnit_MAIN_METHOD == 'phpbb_network_all_tests::main')
-{
- phpbb_network_all_tests::main();
-}
diff --git a/tests/network/checkdnsrr.php b/tests/network/checkdnsrr_test.php
index 57fe2761cc..1942a50f06 100644
--- a/tests/network/checkdnsrr.php
+++ b/tests/network/checkdnsrr_test.php
@@ -3,13 +3,15 @@
*
* @package testing
* @copyright (c) 2010 phpBB Group
-* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
-require_once 'test_framework/framework.php';
-require_once '../phpBB/includes/functions.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
+/**
+* @group slow
+*/
class phpbb_network_checkdnsrr_test extends phpbb_test_case
{
public function data_provider()
diff --git a/tests/network/ftp_fsock_pasv_epsv_test.php b/tests/network/ftp_fsock_pasv_epsv_test.php
new file mode 100644
index 0000000000..22f17785b8
--- /dev/null
+++ b/tests/network/ftp_fsock_pasv_epsv_test.php
@@ -0,0 +1,63 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2011 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions_transfer.php';
+
+/**
+* @group slow
+*/
+class phpbb_network_ftp_fsock_pasv_epsv_test extends phpbb_test_case
+{
+ static protected $ipv4;
+
+ static public function setUpBeforeClass()
+ {
+ $hostname = 'ftp.debian.org.';
+ self::$ipv4 = gethostbyname($hostname);
+
+ if (self::$ipv4 == $hostname)
+ {
+ self::markTestSkipped("Got no A record back from DNS query for $hostname");
+ }
+ }
+
+ public function test_pasv()
+ {
+ // PASV
+ $this->assert_ls_contains_debian(self::$ipv4);
+ }
+
+ public function test_epsv()
+ {
+ $ipv4 = self::$ipv4;
+ // EPSV
+ $this->assert_ls_contains_debian("[::ffff:$ipv4]");
+ }
+
+ protected function assert_ls_contains_debian($hostname)
+ {
+ $o = $this->get_object($hostname);
+ $result = $o->_init();
+ // This test may fail on IPv6 addresses if IPv6 support is
+ // not available. PHP must be compiled with IPv6 support enabled,
+ // and your operating system must be configured for IPv6 as well.
+ if ($result !== true)
+ {
+ $this->markTestSkipped("Failed to connect to $hostname: $result");
+ }
+ $this->assertContains('debian', $o->_ls());
+ $o->_close();
+ }
+
+ protected function get_object($hostname)
+ {
+ return new ftp_fsock($hostname, 'anonymous', 'anonymous@localhost.tld', '/');
+ }
+}
diff --git a/tests/profile/custom_test.php b/tests/profile/custom_test.php
new file mode 100644
index 0000000000..1f33b45ba9
--- /dev/null
+++ b/tests/profile/custom_test.php
@@ -0,0 +1,55 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2011 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions_profile_fields.php';
+
+class phpbb_profile_custom_test extends phpbb_database_test_case
+{
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/profile_fields.xml');
+ }
+
+ static public function dropdownFields()
+ {
+ return array(
+ // note, there is an offset of 1 between option_id (0-indexed)
+ // in the database and values (1-indexed) to avoid problems with
+ // transmitting 0 in an HTML form
+ // required, value, expected
+ array(1, '0', 'FIELD_INVALID_VALUE', 'Required field should throw error for out-of-range value'),
+ array(1, '1', 'FIELD_REQUIRED', 'Required field should throw error for default value'),
+ array(1, '2', false, 'Required field should accept non-default value'),
+ array(0, '0', 'FIELD_INVALID_VALUE', 'Optional field should throw error for out-of-range value'),
+ array(0, '1', false, 'Optional field should accept default value'),
+ array(0, '2', false, 'Optional field should accept non-default value'),
+ );
+ }
+
+ /**
+ * @dataProvider dropdownFields
+ */
+ public function test_dropdown_validate($field_required, $field_value, $expected, $description)
+ {
+ global $db;
+ $db = $this->new_dbal();
+
+ $field_data = array(
+ 'field_id' => 1,
+ 'lang_id' => 1,
+ 'field_novalue' => 1,
+ 'field_required' => $field_required,
+ );
+
+ $cp = new custom_profile;
+ $result = $cp->validate_profile_field(FIELD_DROPDOWN, $field_value, $field_data);
+
+ $this->assertEquals($expected, $result, $description);
+ }
+}
diff --git a/tests/profile/fixtures/profile_fields.xml b/tests/profile/fixtures/profile_fields.xml
new file mode 100644
index 0000000000..0b2929f625
--- /dev/null
+++ b/tests/profile/fixtures/profile_fields.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="phpbb_profile_fields_lang">
+ <column>field_id</column>
+ <column>lang_id</column>
+ <column>option_id</column>
+ <column>field_type</column>
+ <column>lang_value</column>
+ <row>
+ <value>1</value>
+ <value>1</value>
+ <value>0</value>
+ <value>5</value>
+ <value>Default Option</value>
+ </row>
+ <row>
+ <value>1</value>
+ <value>1</value>
+ <value>1</value>
+ <value>5</value>
+ <value>First Alternative</value>
+ </row>
+ <row>
+ <value>1</value>
+ <value>1</value>
+ <value>2</value>
+ <value>5</value>
+ <value>Third Alternative</value>
+ </row>
+ </table>
+</dataset>
diff --git a/tests/random/all_tests.php b/tests/random/all_tests.php
deleted file mode 100644
index c6ffe78024..0000000000
--- a/tests/random/all_tests.php
+++ /dev/null
@@ -1,40 +0,0 @@
-<?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_random_all_tests::main');
-}
-
-require_once 'test_framework/framework.php';
-require_once 'PHPUnit/TextUI/TestRunner.php';
-
-require_once 'random/gen_rand_string.php';
-
-class phpbb_random_all_tests
-{
- public static function main()
- {
- PHPUnit_TextUI_TestRunner::run(self::suite());
- }
-
- public static function suite()
- {
- $suite = new PHPUnit_Framework_TestSuite('phpBB Random Functions');
-
- $suite->addTestSuite('phpbb_random_gen_rand_string_test');
-
- return $suite;
- }
-}
-
-if (PHPUnit_MAIN_METHOD == 'phpbb_random_all_tests::main')
-{
- phpbb_random_all_tests::main();
-}
diff --git a/tests/random/gen_rand_string.php b/tests/random/gen_rand_string_test.php
index cd58d14ed3..3317c78ed9 100644
--- a/tests/random/gen_rand_string.php
+++ b/tests/random/gen_rand_string_test.php
@@ -3,12 +3,11 @@
*
* @package testing
* @copyright (c) 2010 phpBB Group
-* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
-require_once 'test_framework/framework.php';
-require_once '../phpBB/includes/functions.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
class phpbb_random_gen_rand_string_test extends phpbb_test_case
{
diff --git a/tests/regex/all_tests.php b/tests/regex/all_tests.php
deleted file mode 100644
index 316a9d4a58..0000000000
--- a/tests/regex/all_tests.php
+++ /dev/null
@@ -1,46 +0,0 @@
-<?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/censor_test.php b/tests/regex/censor_test.php
new file mode 100644
index 0000000000..5929092e07
--- /dev/null
+++ b/tests/regex/censor_test.php
@@ -0,0 +1,50 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2010 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
+
+class phpbb_regex_censor_test extends phpbb_test_case
+{
+ public function censor_test_data()
+ {
+ return array(
+ array('bad*word', 'bad word'),
+ array('bad***word', 'bad word'),
+ array('bad**word', 'bad word'),
+ array('*bad*word*', 'bad word'),
+ array('b*d', 'bad'),
+ array('*bad*', 'bad'),
+ array('*b*d*', 'bad'),
+ array('*b*d*', 'b d'),
+ array('b*d*word', 'bad word'),
+ array('**b**d**word**', 'bad word'),
+ array('**b**d**word**', 'the bad word catched'),
+ );
+ }
+
+ /**
+ * @dataProvider censor_test_data
+ */
+ public function test_censor_unicode($pattern, $subject)
+ {
+ $regex = get_censor_preg_expression($pattern, true);
+
+ $this->assertRegExp($regex, $subject);
+ }
+
+ /**
+ * @dataProvider censor_test_data
+ */
+ public function test_censor_no_unicode($pattern, $subject)
+ {
+ $regex = get_censor_preg_expression($pattern, false);
+
+ $this->assertRegExp($regex, $subject);
+ }
+} \ No newline at end of file
diff --git a/tests/regex/email.php b/tests/regex/email_test.php
index 8658b8af36..b4ea5b23aa 100644
--- a/tests/regex/email.php
+++ b/tests/regex/email_test.php
@@ -3,12 +3,11 @@
*
* @package testing
* @copyright (c) 2010 phpBB Group
-* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
-require_once 'test_framework/framework.php';
-require_once '../phpBB/includes/functions.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
class phpbb_regex_email_test extends phpbb_test_case
{
@@ -29,6 +28,8 @@ class phpbb_regex_email_test extends phpbb_test_case
array('alice_foo@bar.phpbb.com'),
array('alice+tag@foo.phpbb.com'),
array('alice&amp;tag@foo.phpbb.com'),
+ array('alice@phpbb.australia'),
+ array('alice@phpbb.topZlevelZdomainZnamesZcanZbeZupZtoZsixtyZthreeZcharactersZlong'),
//array('"John Doe"@example.com'),
//array('Alice@[192.168.2.1]'), // IPv4
@@ -97,6 +98,7 @@ class phpbb_regex_email_test extends phpbb_test_case
array('! "#$%(),/;<>[]`|@invalidCharsInLocal.org'),
array('invalidCharsInDomain@! "#$%(),/;<>_[]`|.org'),
array('local@SecondLevelDomainNamesAreInvalidIfTheyAreLongerThan64Charactersss.org'),
+ array('alice@phpbb.topZlevelZdomainZnamesZcanZbeZupZtoZsixtyZthreeZcharactersZlongZ'),
);
}
diff --git a/tests/regex/ipv4.php b/tests/regex/ipv4_test.php
index 9d131ad0ca..38a3aa4a8e 100644
--- a/tests/regex/ipv4.php
+++ b/tests/regex/ipv4_test.php
@@ -3,12 +3,11 @@
*
* @package testing
* @copyright (c) 2010 phpBB Group
-* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
-require_once 'test_framework/framework.php';
-require_once '../phpBB/includes/functions.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
class phpbb_regex_ipv4_test extends phpbb_test_case
{
diff --git a/tests/regex/ipv6.php b/tests/regex/ipv6_test.php
index 3d7a72e492..d24217b346 100644
--- a/tests/regex/ipv6.php
+++ b/tests/regex/ipv6_test.php
@@ -3,12 +3,11 @@
*
* @package testing
* @copyright (c) 2010 phpBB Group
-* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
-require_once 'test_framework/framework.php';
-require_once '../phpBB/includes/functions.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
class phpbb_regex_ipv6_test extends phpbb_test_case
{
diff --git a/tests/regex/password_complexity_test.php b/tests/regex/password_complexity_test.php
new file mode 100644
index 0000000000..07453555ee
--- /dev/null
+++ b/tests/regex/password_complexity_test.php
@@ -0,0 +1,81 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2010 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions_user.php';
+
+class phpbb_password_complexity_test extends phpbb_test_case
+{
+ public function password_complexity_test_data_positive()
+ {
+ return array(
+ array('12345', 'PASS_TYPE_ANY'),
+ array('qwerty', 'PASS_TYPE_ANY'),
+ array('QWERTY', 'PASS_TYPE_ANY'),
+ array('QwerTY', 'PASS_TYPE_ANY'),
+ array('q$erty', 'PASS_TYPE_ANY'),
+ array('qW$rty', 'PASS_TYPE_ANY'),
+
+ array('QwerTY', 'PASS_TYPE_CASE'),
+ array('QwerTY123', 'PASS_TYPE_ALPHA'),
+ array('QwerTY123$&', 'PASS_TYPE_SYMBOL'),
+
+ array('', 'PASS_TYPE_ANY'),
+ );
+ }
+
+ public function password_complexity_test_data_negative()
+ {
+ return array(
+ array('qwerty', 'PASS_TYPE_CASE'),
+ array('QWERTY', 'PASS_TYPE_CASE'),
+ array('123456', 'PASS_TYPE_CASE'),
+ array('#$&', 'PASS_TYPE_CASE'),
+ array('QTY123$', 'PASS_TYPE_CASE'),
+
+ array('qwerty', 'PASS_TYPE_ALPHA'),
+ array('QWERTY', 'PASS_TYPE_ALPHA'),
+ array('123456', 'PASS_TYPE_ALPHA'),
+ array('QwertY', 'PASS_TYPE_ALPHA'),
+ array('qwerty123', 'PASS_TYPE_ALPHA'),
+ array('QWERTY123', 'PASS_TYPE_ALPHA'),
+ array('#$&', 'PASS_TYPE_ALPHA'),
+ array('QTY123$', 'PASS_TYPE_ALPHA'),
+
+ array('qwerty', 'PASS_TYPE_SYMBOL'),
+ array('QWERTY', 'PASS_TYPE_SYMBOL'),
+ array('123456', 'PASS_TYPE_SYMBOL'),
+ array('QwertY', 'PASS_TYPE_SYMBOL'),
+ array('qwerty123', 'PASS_TYPE_SYMBOL'),
+ array('QWERTY123', 'PASS_TYPE_SYMBOL'),
+ array('#$&', 'PASS_TYPE_SYMBOL'),
+ array('qwerty123$', 'PASS_TYPE_SYMBOL'),
+ array('QWERTY123$', 'PASS_TYPE_SYMBOL'),
+ );
+ }
+
+ /**
+ * @dataProvider password_complexity_test_data_positive
+ */
+ public function test_password_complexity_positive($password, $mode)
+ {
+ global $config;
+ $config['pass_complex'] = $mode;
+ $this->assertFalse(validate_password($password));
+ }
+
+ /**
+ * @dataProvider password_complexity_test_data_negative
+ */
+ public function test_password_complexity_negative($password, $mode)
+ {
+ global $config;
+ $config['pass_complex'] = $mode;
+ $this->assertEquals('INVALID_CHARS', validate_password($password));
+ }
+}
diff --git a/tests/regex/table_prefix_test.php b/tests/regex/table_prefix_test.php
new file mode 100644
index 0000000000..33bdd4ae2d
--- /dev/null
+++ b/tests/regex/table_prefix_test.php
@@ -0,0 +1,35 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2011 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
+
+class phpbb_regex_table_prefix_test extends phpbb_test_case
+{
+ public function table_prefix_test_data()
+ {
+ return array(
+ array('phpbb_', 1),
+ array('phpBB3', 1),
+ array('a', 1),
+
+ array('', 0),
+ array('_', 0),
+ array('a-', 0),
+ array("'", 0),
+ );
+ }
+
+ /**
+ * @dataProvider table_prefix_test_data
+ */
+ public function test_table_prefix($prefix, $expected)
+ {
+ $this->assertEquals($expected, preg_match(get_preg_expression('table_prefix'), $prefix));
+ }
+}
diff --git a/tests/regex/url.php b/tests/regex/url_test.php
index 678b7d108f..b395f5cae2 100644
--- a/tests/regex/url.php
+++ b/tests/regex/url_test.php
@@ -3,12 +3,11 @@
*
* @package testing
* @copyright (c) 2010 phpBB Group
-* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
-require_once 'test_framework/framework.php';
-require_once '../phpBB/includes/functions.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
class phpbb_regex_url_test extends phpbb_test_case
{
diff --git a/tests/request/all_tests.php b/tests/request/all_tests.php
deleted file mode 100644
index 1ee3029b36..0000000000
--- a/tests/request/all_tests.php
+++ /dev/null
@@ -1,41 +0,0 @@
-<?php
-/**
-*
-* @package testing
-* @copyright (c) 2008 phpBB Group
-* @license http://opensource.org/licenses/gpl-license.php GNU Public License
-*
-*/
-
-if (!defined('PHPUnit_MAIN_METHOD'))
-{
- define('PHPUnit_MAIN_METHOD', 'phpbb_request_all_tests::main');
-}
-
-require_once 'test_framework/framework.php';
-require_once 'PHPUnit/TextUI/TestRunner.php';
-
-require_once 'request/request_var.php';
-
-class phpbb_request_all_tests
-{
- public static function main()
- {
- PHPUnit_TextUI_TestRunner::run(self::suite());
- }
-
- public static function suite()
- {
- $suite = new PHPUnit_Framework_TestSuite('phpBB Request Parameter Handling');
-
- $suite->addTestSuite('phpbb_request_request_var_test');
-
- return $suite;
- }
-}
-
-if (PHPUnit_MAIN_METHOD == 'phpbb_request_all_tests::main')
-{
- phpbb_request_all_tests::main();
-}
-
diff --git a/tests/request/request_var.php b/tests/request/request_var_test.php
index b1dacef3fd..8e609c00af 100644
--- a/tests/request/request_var.php
+++ b/tests/request/request_var_test.php
@@ -3,12 +3,12 @@
*
* @package testing
* @copyright (c) 2008 phpBB Group
-* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
-require_once 'test_framework/framework.php';
-require_once '../phpBB/includes/functions.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php';
class phpbb_request_request_var_test extends phpbb_test_case
{
diff --git a/tests/security/all_tests.php b/tests/security/base.php
index 8e3916733f..2658798237 100644
--- a/tests/security/all_tests.php
+++ b/tests/security/base.php
@@ -3,22 +3,11 @@
*
* @package testing
* @copyright (c) 2008 phpBB Group
-* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
-if (!defined('PHPUnit_MAIN_METHOD'))
-{
- define('PHPUnit_MAIN_METHOD', 'phpbb_security_all_tests::main');
-}
-
-require_once 'test_framework/framework.php';
-require_once 'PHPUnit/TextUI/TestRunner.php';
-
-require_once 'security/extract_current_page.php';
-require_once 'security/redirect.php';
-
-class phpbb_security_all_tests extends PHPUnit_Framework_TestSuite
+abstract class phpbb_security_test_base extends phpbb_test_case
{
/**
* Set up the required user object and server variables for the suites
@@ -62,25 +51,4 @@ class phpbb_security_all_tests extends PHPUnit_Framework_TestSuite
global $user;
$user = NULL;
}
-
- public static function main()
- {
- PHPUnit_TextUI_TestRunner::run(self::suite());
- }
-
- public static function suite()
- {
- // I bet there is a better method calling this... :)
- $suite = new phpbb_security_all_tests('phpBB Security Fixes');
-
- $suite->addTestSuite('phpbb_security_extract_current_page_test');
- $suite->addTestSuite('phpbb_security_redirect_test');
-
- return $suite;
- }
-}
-
-if (PHPUnit_MAIN_METHOD == 'phpbb_security_all_tests::main')
-{
- phpbb_security_all_tests::main();
}
diff --git a/tests/security/extract_current_page.php b/tests/security/extract_current_page_test.php
index 8c72fe1440..4911f7b452 100644
--- a/tests/security/extract_current_page.php
+++ b/tests/security/extract_current_page_test.php
@@ -3,16 +3,16 @@
*
* @package testing
* @copyright (c) 2008 phpBB Group
-* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
-require_once 'test_framework/framework.php';
+require_once dirname(__FILE__) . '/base.php';
-require_once '../phpBB/includes/functions.php';
-require_once '../phpBB/includes/session.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/session.php';
-class phpbb_security_extract_current_page_test extends phpbb_test_case
+class phpbb_security_extract_current_page_test extends phpbb_security_test_base
{
public static function security_variables()
{
diff --git a/tests/security/hash_test.php b/tests/security/hash_test.php
new file mode 100644
index 0000000000..0c2580c19b
--- /dev/null
+++ b/tests/security/hash_test.php
@@ -0,0 +1,21 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2011 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
+
+class phpbb_security_hash_test extends phpbb_test_case
+{
+ public function test_check_hash_with_phpass()
+ {
+ $this->assertTrue(phpbb_check_hash('test', '$H$9isfrtKXWqrz8PvztXlL3.daw4U0zI1'));
+ $this->assertTrue(phpbb_check_hash('test', '$P$9isfrtKXWqrz8PvztXlL3.daw4U0zI1'));
+ $this->assertFalse(phpbb_check_hash('foo', '$H$9isfrtKXWqrz8PvztXlL3.daw4U0zI1'));
+ }
+}
+
diff --git a/tests/security/redirect.php b/tests/security/redirect_test.php
index 37b0a5bb41..4848a938c6 100644
--- a/tests/security/redirect.php
+++ b/tests/security/redirect_test.php
@@ -3,16 +3,16 @@
*
* @package testing
* @copyright (c) 2008 phpBB Group
-* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
-require_once 'test_framework/framework.php';
+require_once dirname(__FILE__) . '/base.php';
-require_once '../phpBB/includes/functions.php';
-require_once '../phpBB/includes/session.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/session.php';
-class phpbb_security_redirect_test extends phpbb_test_case
+class phpbb_security_redirect_test extends phpbb_security_test_base
{
public static function provider()
{
@@ -22,13 +22,15 @@ class phpbb_security_redirect_test extends phpbb_test_case
array('bad://localhost/phpBB/index.php', 'Tried to redirect to potentially insecure url.', false),
array('http://www.otherdomain.com/somescript.php', false, 'http://localhost/phpBB'),
array("http://localhost/phpBB/memberlist.php\n\rConnection: close", 'Tried to redirect to potentially insecure url.', false),
- array('javascript:test', false, 'http://localhost/phpBB/../tests/javascript:test'),
+ array('javascript:test', false, 'http://localhost/phpBB/../javascript:test'),
array('http://localhost/phpBB/index.php;url=', 'Tried to redirect to potentially insecure url.', false),
);
}
protected function setUp()
{
+ parent::setUp();
+
$GLOBALS['config'] = array(
'force_server_vars' => '0',
);
diff --git a/tests/session/append_sid_test.php b/tests/session/append_sid_test.php
new file mode 100644
index 0000000000..88f6f0718e
--- /dev/null
+++ b/tests/session/append_sid_test.php
@@ -0,0 +1,51 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2011 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
+
+class phpbb_session_append_sid_test extends phpbb_test_case
+{
+
+ public function append_sid_data()
+ {
+ return array(
+ array('viewtopic.php?t=1&amp;f=2', false, true, false, 'viewtopic.php?t=1&amp;f=2', 'parameters in url-argument'),
+ array('viewtopic.php', 't=1&amp;f=2', true, false, 'viewtopic.php?t=1&amp;f=2', 'parameters in params-argument using amp'),
+ array('viewtopic.php', 't=1&f=2', false, false, 'viewtopic.php?t=1&f=2', 'parameters in params-argument using &'),
+ array('viewtopic.php', array('t' => 1, 'f' => 2), true, false, 'viewtopic.php?t=1&amp;f=2', 'parameters in params-argument as array'),
+
+ // Custom sid parameter
+ array('viewtopic.php', 't=1&amp;f=2', true, 'custom-sid', 'viewtopic.php?t=1&amp;f=2&amp;sid=custom-sid', 'using session_id'),
+
+ // Testing anchors
+ array('viewtopic.php?t=1&amp;f=2#anchor', false, true, false, 'viewtopic.php?t=1&amp;f=2#anchor', 'anchor in url-argument'),
+ array('viewtopic.php', 't=1&amp;f=2#anchor', true, false, 'viewtopic.php?t=1&amp;f=2#anchor', 'anchor in params-argument'),
+ array('viewtopic.php', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, false, 'viewtopic.php?t=1&amp;f=2#anchor', 'anchor in params-argument (array)'),
+
+ // Anchors and custom sid
+ array('viewtopic.php?t=1&amp;f=2#anchor', false, true, 'custom-sid', 'viewtopic.php?t=1&amp;f=2&amp;sid=custom-sid#anchor', 'anchor in url-argument using session_id'),
+ array('viewtopic.php', 't=1&amp;f=2#anchor', true, 'custom-sid', 'viewtopic.php?t=1&amp;f=2&amp;sid=custom-sid#anchor', 'anchor in params-argument using session_id'),
+ array('viewtopic.php', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, 'custom-sid', 'viewtopic.php?t=1&amp;f=2&amp;sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'),
+
+ // Empty parameters should not append the ?
+ array('viewtopic.php', false, true, false, 'viewtopic.php', 'no params using bool false'),
+ array('viewtopic.php', '', true, false, 'viewtopic.php', 'no params using empty string'),
+ array('viewtopic.php', array(), true, false, 'viewtopic.php', 'no params using empty array'),
+ );
+ }
+
+ /**
+ * @dataProvider append_sid_data
+ */
+ public function test_append_sid($url, $params, $is_amp, $session_id, $expected, $description)
+ {
+ $this->assertEquals($expected, append_sid($url, $params, $is_amp, $session_id));
+ }
+}
+
diff --git a/tests/session/continue_test.php b/tests/session/continue_test.php
new file mode 100644
index 0000000000..c4f7f8d75b
--- /dev/null
+++ b/tests/session/continue_test.php
@@ -0,0 +1,121 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2011 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+require_once dirname(__FILE__) . '/../mock/cache.php';
+require_once dirname(__FILE__) . '/testable_factory.php';
+
+class phpbb_session_continue_test extends phpbb_database_test_case
+{
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/sessions_full.xml');
+ }
+
+ static public function session_begin_attempts()
+ {
+ // The session_id field is defined as CHAR(32) in the database schema.
+ // Thus the data we put in session_id fields has to have a length of 32 characters on stricter DBMSes.
+ // Thus we fill those strings up with zeroes until they have a string length of 32.
+
+ return array(
+ array(
+ 'bar_session000000000000000000000', '4', 'user agent', '127.0.0.1',
+ array(
+ array('session_id' => 'anon_session00000000000000000000', 'session_user_id' => 1),
+ array('session_id' => 'bar_session000000000000000000000', 'session_user_id' => 4),
+ ),
+ array(),
+ 'If a request comes with a valid session id with matching user agent and IP, no new session should be created.',
+ ),
+ array(
+ 'anon_session00000000000000000000', '4', 'user agent', '127.0.0.1',
+ array(
+ array('session_id' => '__new_session_id__', 'session_user_id' => 1), // use generated SID
+ array('session_id' => 'bar_session000000000000000000000', 'session_user_id' => 4),
+ ),
+ array(
+ 'u' => array('1', null),
+ 'k' => array(null, null),
+ 'sid' => array('__new_session_id__', null),
+ ),
+ 'If a request comes with a valid session id and IP but different user id and user agent, a new anonymous session is created and the session matching the supplied session id is deleted.',
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider session_begin_attempts
+ */
+ public function test_session_begin_valid_session($session_id, $user_id, $user_agent, $ip, $expected_sessions, $expected_cookies, $message)
+ {
+ $db = $this->new_dbal();
+ $session_factory = new phpbb_session_testable_factory;
+ $session_factory->set_cookies(array(
+ '_sid' => $session_id,
+ '_u' => $user_id,
+ ));
+ $session_factory->merge_config_data(array(
+ 'session_length' => time(), // need to do this to allow sessions started at time 0
+ ));
+ $session_factory->merge_server_data(array(
+ 'HTTP_USER_AGENT' => $user_agent,
+ 'REMOTE_ADDR' => $ip,
+ ));
+
+ $session = $session_factory->get_session($db);
+ $session->page = array('page' => 'page', 'forum' => 0);
+
+ $session->session_begin();
+
+ $sql = 'SELECT session_id, session_user_id
+ FROM phpbb_sessions
+ ORDER BY session_user_id';
+
+ $expected_sessions = $this->replace_session($expected_sessions, $session->session_id);
+ $expected_cookies = $this->replace_session($expected_cookies, $session->session_id);
+
+ $this->assertSqlResultEquals(
+ $expected_sessions,
+ $sql,
+ $message
+ );
+
+ $session->check_cookies($this, $expected_cookies);
+
+ $session_factory->check($this);
+ }
+
+ /**
+ * Replaces recursively the value __new_session_id__ with the given session
+ * id.
+ *
+ * @param array $array An array of data
+ * @param string $session_id The new session id to use instead of the
+ * placeholder.
+ * @return array The input array with all occurances of __new_session_id__
+ * replaced.
+ */
+ public function replace_session($array, $session_id)
+ {
+ foreach ($array as $key => &$value)
+ {
+ if ($value === '__new_session_id__')
+ {
+ $value = $session_id;
+ }
+
+ if (is_array($value))
+ {
+ $value = $this->replace_session($value, $session_id);
+ }
+ }
+
+ return $array;
+ }
+}
diff --git a/tests/session/fixtures/sessions_empty.xml b/tests/session/fixtures/sessions_empty.xml
new file mode 100644
index 0000000000..0e6ddccd88
--- /dev/null
+++ b/tests/session/fixtures/sessions_empty.xml
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="phpbb_users">
+ <column>user_id</column>
+ <column>username_clean</column>
+ <column>user_permissions</column>
+ <column>user_sig</column>
+ <column>user_occ</column>
+ <column>user_interests</column>
+ <row>
+ <value>1</value>
+ <value>anonymous</value>
+ <value></value>
+ <value></value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>3</value>
+ <value>foo</value>
+ <value></value>
+ <value></value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>4</value>
+ <value>bar</value>
+ <value></value>
+ <value></value>
+ <value></value>
+ <value></value>
+ </row>
+ </table>
+ <table name="phpbb_sessions">
+ <column>session_id</column>
+ <column>session_user_id</column>
+ <column>session_ip</column>
+ <column>session_browser</column>
+ </table>
+</dataset>
diff --git a/tests/session/fixtures/sessions_full.xml b/tests/session/fixtures/sessions_full.xml
new file mode 100644
index 0000000000..509687f4d2
--- /dev/null
+++ b/tests/session/fixtures/sessions_full.xml
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="phpbb_users">
+ <column>user_id</column>
+ <column>username_clean</column>
+ <column>user_permissions</column>
+ <column>user_sig</column>
+ <column>user_occ</column>
+ <column>user_interests</column>
+ <row>
+ <value>1</value>
+ <value>anonymous</value>
+ <value></value>
+ <value></value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>3</value>
+ <value>foo</value>
+ <value></value>
+ <value></value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>4</value>
+ <value>bar</value>
+ <value></value>
+ <value></value>
+ <value></value>
+ <value></value>
+ </row>
+ </table>
+ <table name="phpbb_sessions">
+ <column>session_id</column>
+ <column>session_user_id</column>
+ <column>session_ip</column>
+ <column>session_browser</column>
+ <row>
+ <value>anon_session00000000000000000000</value>
+ <value>1</value>
+ <value>127.0.0.1</value>
+ <value>anonymous user agent</value>
+ </row>
+ <row>
+ <value>bar_session000000000000000000000</value>
+ <value>4</value>
+ <value>127.0.0.1</value>
+ <value>user agent</value>
+ </row>
+ </table>
+</dataset>
diff --git a/tests/session/init_test.php b/tests/session/init_test.php
new file mode 100644
index 0000000000..2ce6c4a4ac
--- /dev/null
+++ b/tests/session/init_test.php
@@ -0,0 +1,56 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2011 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+require_once dirname(__FILE__) . '/../mock/cache.php';
+require_once dirname(__FILE__) . '/testable_factory.php';
+
+class phpbb_session_init_test extends phpbb_database_test_case
+{
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/sessions_empty.xml');
+ }
+
+ // also see security/extract_current_page.php
+
+ public function test_login_session_create()
+ {
+ $db = $this->new_dbal();
+ $session_factory = new phpbb_session_testable_factory;
+
+ $session = $session_factory->get_session($db);
+ $session->page = array('page' => 'page', 'forum' => 0);
+
+ $session->session_create(3);
+
+ $sql = 'SELECT session_user_id
+ FROM phpbb_sessions';
+
+ $this->assertSqlResultEquals(
+ array(array('session_user_id' => 3)),
+ $sql,
+ 'Check if exacly one session for user id 3 was created'
+ );
+
+ $cookie_expire = $session->time_now + 31536000; // default is one year
+
+ $session->check_cookies($this, array(
+ 'u' => array(null, $cookie_expire),
+ 'k' => array(null, $cookie_expire),
+ 'sid' => array($session->session_id, $cookie_expire),
+ ));
+
+ global $SID, $_SID;
+ $this->assertEquals($session->session_id, $_SID);
+ $this->assertEquals('?sid=' . $session->session_id, $SID);
+
+ $session_factory->check($this);
+ }
+}
+
diff --git a/tests/session/testable_factory.php b/tests/session/testable_factory.php
new file mode 100644
index 0000000000..00f79738ef
--- /dev/null
+++ b/tests/session/testable_factory.php
@@ -0,0 +1,171 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2011 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+require_once dirname(__FILE__) . '/../mock/session_testable.php';
+
+/**
+* This class exists to setup an instance of phpbb's session class for testing.
+*
+* The session class has rather complex dependencies, so in order to make its
+* tests more * understandable and to make its dependencies more visible this
+* factory class sets up all the necessary global state & variable contents.
+*/
+class phpbb_session_testable_factory
+{
+ protected $config_data;
+ protected $cache_data;
+ protected $cookies;
+
+ protected $config;
+ protected $cache;
+
+ /**
+ * Initialises the factory with a set of default config and cache values.
+ */
+ public function __construct()
+ {
+ // default configuration values
+ $this->config_data = array(
+ 'allow_autologin' => false,
+ 'auth_method' => 'db',
+ 'forwarded_for_check' => true,
+ 'active_sessions' => 0, // disable
+ 'rand_seed' => 'foo',
+ 'rand_seed_last_update' => 0,
+ 'max_autologin_time' => 0,
+ 'session_length' => 100,
+ 'form_token_lifetime' => 100,
+ 'cookie_name' => '',
+ 'limit_load' => 0,
+ 'limit_search_load' => 0,
+ 'ip_check' => 3,
+ 'browser_check' => 1,
+ );
+
+ $this->cache_data = array(
+ '_bots' => array(),
+ );
+
+ $this->cookies = array();
+
+ $this->server_data = $_SERVER;
+ }
+
+ /**
+ * Retrieve the configured session class instance
+ *
+ * @param dbal $dbal The database connection to use for session data
+ * @return phpbb_mock_session_testable A session instance
+ */
+ public function get_session(dbal $dbal)
+ {
+ // set up all the global variables used by session
+ global $SID, $_SID, $db, $config, $cache;
+
+ $config = $this->config = $this->get_config_data();
+ $db = $dbal;
+
+ $cache = $this->cache = new phpbb_mock_cache($this->get_cache_data());
+ $SID = $_SID = null;
+
+ $_COOKIE = $this->cookies;
+ $_SERVER = $this->server_data;
+
+ $session = new phpbb_mock_session_testable;
+ return $session;
+ }
+
+ /**
+ * Set the cookies which should be present in the request data.
+ *
+ * @param array $cookies The cookie data, structured like $_COOKIE contents.
+ */
+ public function set_cookies(array $cookies)
+ {
+ $this->cookies = $cookies;
+ }
+
+ /**
+ * Check if the cache used for the generated session contains correct data.
+ *
+ * @param PHPUnit_Framework_Assert $test The test case to call assert methods
+ * on
+ */
+ public function check(PHPUnit_Framework_Assert $test)
+ {
+ $this->cache->check($test, $this->get_cache_data());
+ }
+
+ /**
+ * Merge config data with the current config data to be supplied to session.
+ *
+ * New values overwrite new ones.
+ *
+ * @param array $config_data The config data to merge with previous data
+ */
+ public function merge_config_data(array $config_data)
+ {
+ $this->config_data = array_merge($this->config_data, $config_data);
+ }
+
+ /**
+ * Retrieve the entire config data to be passed to the session.
+ *
+ * @return array Configuration
+ */
+ public function get_config_data()
+ {
+ return $this->config_data;
+ }
+
+ /**
+ * Merge the cache contents with more data.
+ *
+ * New values overwrite old ones.
+ *
+ * @param array $cache_data The additional cache data
+ */
+ public function merge_cache_data(array $cache_data)
+ {
+ $this->cache_data = array_merge($this->cache_data, $cache_data);
+ }
+
+ /**
+ * Retrieve the entire cache data to be passed to the session.
+ *
+ * @return array Cache contents
+ */
+ public function get_cache_data()
+ {
+ return $this->cache_data;
+ }
+
+ /**
+ * Merge the current server info ($_SERVER) with more data.
+ *
+ * New values overwrite old ones.
+ *
+ * @param array $server_data The additional server variables
+ */
+ public function merge_server_data($server_data)
+ {
+ return $this->server_data = array_merge($this->server_data, $server_data);
+ }
+
+ /**
+ * Retrieve all server variables to be passed to the session.
+ *
+ * @return array Server variables
+ */
+ public function get_server_data()
+ {
+ return $this->server_data;
+ }
+}
+
diff --git a/tests/template/all_tests.php b/tests/template/all_tests.php
deleted file mode 100644
index ea258c1680..0000000000
--- a/tests/template/all_tests.php
+++ /dev/null
@@ -1,40 +0,0 @@
-<?php
-/**
-*
-* @package testing
-* @copyright (c) 2008 phpBB Group
-* @license http://opensource.org/licenses/gpl-license.php GNU Public License
-*
-*/
-
-if (!defined('PHPUnit_MAIN_METHOD'))
-{
- define('PHPUnit_MAIN_METHOD', 'phpbb_template_all_tests::main');
-}
-
-require_once 'test_framework/framework.php';
-require_once 'PHPUnit/TextUI/TestRunner.php';
-
-require_once 'template/template.php';
-
-class phpbb_template_all_tests
-{
- public static function main()
- {
- PHPUnit_TextUI_TestRunner::run(self::suite());
- }
-
- public static function suite()
- {
- $suite = new PHPUnit_Framework_TestSuite('phpBB Template Engine');
-
- $suite->addTestSuite('phpbb_template_template_test');
-
- return $suite;
- }
-}
-
-if (PHPUnit_MAIN_METHOD == 'phpbb_template_all_tests::main')
-{
- phpbb_template_all_tests::main();
-}
diff --git a/tests/template/template.php b/tests/template/template_test.php
index 0c2ca8a032..aaee7bb4a0 100644
--- a/tests/template/template.php
+++ b/tests/template/template_test.php
@@ -3,13 +3,12 @@
*
* @package testing
* @copyright (c) 2008 phpBB Group
-* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
-require_once 'test_framework/framework.php';
-
-require_once '../phpBB/includes/template.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/template.php';
class phpbb_template_template_test extends phpbb_test_case
{
@@ -64,9 +63,10 @@ class phpbb_template_template_test extends phpbb_test_case
// Test the engine can be used
$this->setup_engine();
- if (!is_writable(dirname($this->template->cachepath)))
+ $template_cache_dir = dirname($this->template->cachepath);
+ if (!is_writable($template_cache_dir))
{
- $this->markTestSkipped("Template cache directory is not writable.");
+ $this->markTestSkipped("Template cache directory ({$template_cache_dir}) is not writable.");
}
foreach (glob($this->template->cachepath . '*') as $file)
@@ -344,8 +344,7 @@ class phpbb_template_template_test extends phpbb_test_case
*/
public function test_template($file, array $vars, array $block_vars, array $destroy, $expected)
{
- global $phpEx;
- $cache_file = $this->template->cachepath . str_replace('/', '.', $file) . '.' . $phpEx;
+ $cache_file = $this->template->cachepath . str_replace('/', '.', $file) . '.php';
$this->assertFileNotExists($cache_file);
@@ -395,11 +394,9 @@ class phpbb_template_template_test extends phpbb_test_case
public function test_php()
{
- global $phpEx;
-
$GLOBALS['config']['tpl_allow_php'] = true;
- $cache_file = $this->template->cachepath . 'php.html.' . $phpEx;
+ $cache_file = $this->template->cachepath . 'php.html.php';
$this->assertFileNotExists($cache_file);
@@ -410,21 +407,14 @@ class phpbb_template_template_test extends phpbb_test_case
public function test_includephp()
{
- $this->markTestIncomplete('Include PHP test file paths are broken');
-
$GLOBALS['config']['tpl_allow_php'] = true;
- $cache_file = $this->template->cachepath . 'includephp.html.' . PHP_EXT;
-
- $cwd = getcwd();
- chdir(dirname(__FILE__) . '/templates');
+ $cache_file = $this->template->cachepath . 'includephp.html.php';
$this->run_template('includephp.html', array(), array(), array(), 'testing included php', $cache_file);
$this->template->set_filenames(array('test' => 'includephp.html'));
- $this->assertEquals('testing included php', $this->display('test'), "Testing $file");
-
- chdir($cwd);
+ $this->assertEquals('testing included php', $this->display('test'), "Testing INCLUDEPHP");
$GLOBALS['config']['tpl_allow_php'] = false;
}
@@ -438,17 +428,16 @@ class phpbb_template_template_test extends phpbb_test_case
false,
'insert',
<<<EOT
-outer - 0/4 - before
-outer - 1/4
-middle - 0/2
-middle - 1/2
-outer - 2/4
-middle - 0/3
-middle - 1/3
-middle - 2/3
-outer - 3/4
-middle - 0/2
-middle - 1/2
+outer - 0 - before
+outer - 1
+middle - 0
+middle - 1
+outer - 2
+middle - 0
+middle - 1
+outer - 3
+middle - 0
+middle - 1
EOT
,
'Test inserting before on top level block',
@@ -459,17 +448,16 @@ EOT
true,
'insert',
<<<EOT
-outer - 0/4
-middle - 0/2
-middle - 1/2
-outer - 1/4
-middle - 0/3
-middle - 1/3
-middle - 2/3
-outer - 2/4
-middle - 0/2
-middle - 1/2
-outer - 3/4 - after
+outer - 0
+middle - 0
+middle - 1
+outer - 1
+middle - 0
+middle - 1
+outer - 2
+middle - 0
+middle - 1
+outer - 3 - after
EOT
,
'Test inserting after on top level block',
@@ -480,17 +468,16 @@ EOT
1,
'insert',
<<<EOT
-outer - 0/4
-middle - 0/2
-middle - 1/2
-outer - 1/4 - pos #1
-outer - 2/4
-middle - 0/3
-middle - 1/3
-middle - 2/3
-outer - 3/4
-middle - 0/2
-middle - 1/2
+outer - 0
+middle - 0
+middle - 1
+outer - 1 - pos #1
+outer - 2
+middle - 0
+middle - 1
+outer - 3
+middle - 0
+middle - 1
EOT
,
'Test inserting at 1 on top level block',
@@ -501,172 +488,27 @@ EOT
0,
'change',
<<<EOT
-outer - 0/3 - pos #1
-middle - 0/2
-middle - 1/2
-outer - 1/3
-middle - 0/3
-middle - 1/3
-middle - 2/3
-outer - 2/3
-middle - 0/2
-middle - 1/2
+outer - 0 - pos #1
+middle - 0
+middle - 1
+outer - 1
+middle - 0
+middle - 1
+outer - 2
+middle - 0
+middle - 1
EOT
,
'Test inserting at 1 on top level block',
),
- array(
- 'outer[0].middle',
- array('VARIABLE' => 'before'),
- false,
- 'insert',
- <<<EOT
-outer - 0/3
-middle - 0/3 - before
-middle - 1/3
-middle - 2/3
-outer - 1/3
-middle - 0/3
-middle - 1/3
-middle - 2/3
-outer - 2/3
-middle - 0/2
-middle - 1/2
-EOT
-,
- 'Test inserting before on nested block',
- ),
- array(
- 'outer[0].middle',
- array('VARIABLE' => 'after'),
- true,
- 'insert',
- <<<EOT
-outer - 0/3
-middle - 0/3
-middle - 1/3
-middle - 2/3 - after
-outer - 1/3
-middle - 0/3
-middle - 1/3
-middle - 2/3
-outer - 2/3
-middle - 0/2
-middle - 1/2
-EOT
-,
- 'Test inserting after on nested block',
- ),
- array(
- 'outer[0].middle',
- array('VARIABLE' => 'pos #1'),
- 1,
- 'insert',
- <<<EOT
-outer - 0/3
-middle - 0/3
-middle - 1/3 - pos #1
-middle - 2/3
-outer - 1/3
-middle - 0/3
-middle - 1/3
-middle - 2/3
-outer - 2/3
-middle - 0/2
-middle - 1/2
-EOT
-,
- 'Test inserting at pos 1 on nested block',
- ),
- array(
- 'outer[1].middle',
- array('VARIABLE' => 'before'),
- false,
- 'insert',
- <<<EOT
-outer - 0/3
-middle - 0/2
-middle - 1/2
-outer - 1/3
-middle - 0/4 - before
-middle - 1/4
-middle - 2/4
-middle - 3/4
-outer - 2/3
-middle - 0/2
-middle - 1/2
-EOT
-,
- 'Test inserting before on nested block (pos 1)',
- ),
- array(
- 'outer[].middle',
- array('VARIABLE' => 'before'),
- false,
- 'insert',
- <<<EOT
-outer - 0/3
-middle - 0/2
-middle - 1/2
-outer - 1/3
-middle - 0/3
-middle - 1/3
-middle - 2/3
-outer - 2/3
-middle - 0/3 - before
-middle - 1/3
-middle - 2/3
-EOT
-,
- 'Test inserting before on nested block (end)',
- ),
- array(
- 'outer.middle',
- array('VARIABLE' => 'before'),
- false,
- 'insert',
- <<<EOT
-outer - 0/3
-middle - 0/2
-middle - 1/2
-outer - 1/3
-middle - 0/3
-middle - 1/3
-middle - 2/3
-outer - 2/3
-middle - 0/3 - before
-middle - 1/3
-middle - 2/3
-EOT
-,
- 'Test inserting before on nested block (end)',
- ),
);
}
-/*
- <<<EOT
-outer - 0/3
-middle - 0/2
-middle - 1/2
-outer - 1/3
-middle - 0/3
-middle - 1/3
-middle - 2/3
-outer - 2/3
-middle - 0/2
-middle - 1/2
-EOT
-,
-*/
-
/**
* @dataProvider alter_block_array_data
*/
public function test_alter_block_array($alter_block, array $vararray, $key, $mode, $expect, $description)
{
- $this->markTestIncomplete('Alter Block Test is broken');
-
$this->template->set_filenames(array('test' => 'loop_nested.html'));
// @todo Change this
@@ -676,12 +518,11 @@ EOT
$this->template->assign_block_vars('outer', array());
$this->template->assign_block_vars('outer.middle', array());
$this->template->assign_block_vars('outer.middle', array());
- $this->template->assign_block_vars('outer.middle', array());
$this->template->assign_block_vars('outer', array());
$this->template->assign_block_vars('outer.middle', array());
$this->template->assign_block_vars('outer.middle', array());
- $this->assertEquals("outer - 0/3\nmiddle - 0/2\nmiddle - 1/2\nouter - 1/3\nmiddle - 0/3\nmiddle - 1/3\nmiddle - 2/3\nouter - 2/3\nmiddle - 0/2\nmiddle - 1/2", $this->display('test'), 'Ensuring template is built correctly before modification');
+ $this->assertEquals("outer - 0\nmiddle - 0\nmiddle - 1\nouter - 1\nmiddle - 0\nmiddle - 1\nouter - 2\nmiddle - 0\nmiddle - 1", $this->display('test'), 'Ensuring template is built correctly before modification');
$this->template->alter_block_array($alter_block, $vararray, $key, $mode);
$this->assertEquals($expect, $this->display('test'), $description);
diff --git a/tests/template/templates/_dummy_include.php b/tests/template/templates/_dummy_include.php
deleted file mode 100644
index 1de5dddf59..0000000000
--- a/tests/template/templates/_dummy_include.php
+++ /dev/null
@@ -1,3 +0,0 @@
-<?php
-
-echo "testing included php";
diff --git a/tests/template/templates/_dummy_include.php.inc b/tests/template/templates/_dummy_include.php.inc
new file mode 100644
index 0000000000..aacb6b2045
--- /dev/null
+++ b/tests/template/templates/_dummy_include.php.inc
@@ -0,0 +1,3 @@
+<?php
+// extension is .php.inc so PHPUnit ignores it
+echo "testing included php";
diff --git a/tests/template/templates/includephp.html b/tests/template/templates/includephp.html
index 3e13fa33fa..70ebdac0d0 100644
--- a/tests/template/templates/includephp.html
+++ b/tests/template/templates/includephp.html
@@ -1 +1 @@
-<!-- INCLUDEPHP ../templates/_dummy_include.php -->
+<!-- INCLUDEPHP ../tests/template/templates/_dummy_include.php.inc -->
diff --git a/tests/template/templates/loop_nested.html b/tests/template/templates/loop_nested.html
index 571df97b4c..9b251cd453 100644
--- a/tests/template/templates/loop_nested.html
+++ b/tests/template/templates/loop_nested.html
@@ -1,8 +1,8 @@
<!-- BEGIN outer -->
- {outer.S_BLOCK_NAME} - {outer.S_ROW_NUM}/{outer.S_NUM_ROWS}<!-- IF outer.VARIABLE --> - {outer.VARIABLE}<!-- ENDIF -->
+ outer - {outer.S_ROW_COUNT}<!-- IF outer.VARIABLE --> - {outer.VARIABLE}<!-- ENDIF -->
<!-- BEGIN middle -->
- {middle.S_BLOCK_NAME} - {middle.S_ROW_NUM}/{middle.S_NUM_ROWS}<!-- IF middle.VARIABLE --> - {middle.VARIABLE}<!-- ENDIF -->
+ middle - {middle.S_ROW_COUNT}<!-- IF middle.VARIABLE --> - {middle.VARIABLE}<!-- ENDIF -->
<!-- END middle -->
<!-- END outer -->
diff --git a/tests/test_framework/framework.php b/tests/test_framework/framework.php
deleted file mode 100644
index 3a11cc6df9..0000000000
--- a/tests/test_framework/framework.php
+++ /dev/null
@@ -1,43 +0,0 @@
-<?php
-/**
-*
-* @package testing
-* @copyright (c) 2008 phpBB Group
-* @license http://opensource.org/licenses/gpl-license.php GNU Public License
-*
-*/
-
-define('IN_PHPBB', true);
-$phpbb_root_path = '../phpBB/';
-$phpEx = 'php';
-$table_prefix = '';
-
-// If we are on PHP >= 6.0.0 we do not need some code
-if (version_compare(PHP_VERSION, '6.0.0-dev', '>='))
-{
- define('STRIP', false);
-}
-else
-{
- @set_magic_quotes_runtime(0);
- define('STRIP', (get_magic_quotes_gpc()) ? true : false);
-}
-
-require_once $phpbb_root_path . 'includes/constants.php';
-
-// require at least PHPUnit 3.3.0
-require_once 'PHPUnit/Runner/Version.php';
-if (version_compare(PHPUnit_Runner_Version::id(), '3.3.0', '<'))
-{
- trigger_error('PHPUnit >= 3.3.0 required');
-}
-
-if (version_compare(PHPUnit_Runner_Version::id(), '3.5.0', '<'))
-{
- require_once 'PHPUnit/Framework.php';
- require_once 'PHPUnit/Extensions/Database/TestCase.php';
-}
-
-require_once 'test_framework/phpbb_test_case_helpers.php';
-require_once 'test_framework/phpbb_test_case.php';
-require_once 'test_framework/phpbb_database_test_case.php';
diff --git a/tests/test_framework/phpbb_database_test_case.php b/tests/test_framework/phpbb_database_test_case.php
index a64bae8c57..e742b543b0 100644
--- a/tests/test_framework/phpbb_database_test_case.php
+++ b/tests/test_framework/phpbb_database_test_case.php
@@ -3,16 +3,31 @@
*
* @package testing
* @copyright (c) 2008 phpBB Group
-* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_TestCase
{
- private static $already_connected;
+ static private $already_connected;
protected $test_case_helpers;
+ public function __construct($name = NULL, array $data = array(), $dataName = '')
+ {
+ parent::__construct($name, $data, $dataName);
+ $this->backupStaticAttributesBlacklist += array(
+ 'PHP_CodeCoverage' => array('instance'),
+ 'PHP_CodeCoverage_Filter' => array('instance'),
+ 'PHP_CodeCoverage_Util' => array('ignoredLines', 'templateMethods'),
+ 'PHP_Timer' => array('startTimes',),
+ 'PHP_Token_Stream' => array('customTokens'),
+ 'PHP_Token_Stream_CachingFactory' => array('cache'),
+
+ 'phpbb_database_test_case' => array('already_connected'),
+ );
+ }
+
public function get_test_case_helpers()
{
if (!$this->test_case_helpers)
@@ -23,336 +38,38 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test
return $this->test_case_helpers;
}
- public function get_dbms_data($dbms)
- {
- $available_dbms = array(
- 'firebird' => array(
- 'SCHEMA' => 'firebird',
- 'DELIM' => ';;',
- 'PDO' => 'firebird',
- ),
- 'mysqli' => array(
- 'SCHEMA' => 'mysql_41',
- 'DELIM' => ';',
- 'PDO' => 'mysql',
- ),
- 'mysql' => array(
- 'SCHEMA' => 'mysql',
- 'DELIM' => ';',
- 'PDO' => 'mysql',
- ),
- 'mssql' => array(
- 'SCHEMA' => 'mssql',
- 'DELIM' => 'GO',
- 'PDO' => 'odbc',
- ),
- 'mssql_odbc'=> array(
- 'SCHEMA' => 'mssql',
- 'DELIM' => 'GO',
- 'PDO' => 'odbc',
- ),
- 'mssqlnative' => array(
- 'SCHEMA' => 'mssql',
- 'DELIM' => 'GO',
- 'PDO' => 'sqlsrv',
- ),
- 'oracle' => array(
- 'SCHEMA' => 'oracle',
- 'DELIM' => '/',
- 'PDO' => 'oci',
- ),
- 'postgres' => array(
- 'SCHEMA' => 'postgres',
- 'DELIM' => ';',
- 'PDO' => 'pgsql',
- ),
- 'sqlite' => array(
- 'SCHEMA' => 'sqlite',
- 'DELIM' => ';',
- 'PDO' => 'sqlite2',
- ),
- );
-
- if (isset($available_dbms[$dbms]))
- {
- return $available_dbms[$dbms];
- }
- else
- {
- trigger_error('Database unsupported', E_USER_ERROR);
- }
- }
-
public function get_database_config()
{
- if (isset($_SERVER['PHPBB_TEST_DBMS']))
- {
- return array(
- 'dbms' => isset($_SERVER['PHPBB_TEST_DBMS']) ? $_SERVER['PHPBB_TEST_DBMS'] : '',
- 'dbhost' => isset($_SERVER['PHPBB_TEST_DBHOST']) ? $_SERVER['PHPBB_TEST_DBHOST'] : '',
- 'dbport' => isset($_SERVER['PHPBB_TEST_DBPORT']) ? $_SERVER['PHPBB_TEST_DBPORT'] : '',
- 'dbname' => isset($_SERVER['PHPBB_TEST_DBNAME']) ? $_SERVER['PHPBB_TEST_DBNAME'] : '',
- 'dbuser' => isset($_SERVER['PHPBB_TEST_DBUSER']) ? $_SERVER['PHPBB_TEST_DBUSER'] : '',
- 'dbpasswd' => isset($_SERVER['PHPBB_TEST_DBPASSWD']) ? $_SERVER['PHPBB_TEST_DBPASSWD'] : '',
- );
- }
- else if (file_exists('test_config.php'))
- {
- include('test_config.php');
+ $config = phpbb_test_case_helpers::get_test_config();
- return array(
- 'dbms' => $dbms,
- 'dbhost' => $dbhost,
- 'dbport' => $dbport,
- 'dbname' => $dbname,
- 'dbuser' => $dbuser,
- 'dbpasswd' => $dbpasswd,
- );
- }
- else if (extension_loaded('sqlite') && version_compare(PHPUnit_Runner_Version::id(), '3.4.15', '>='))
- {
- // Silently use sqlite
- return array(
- 'dbms' => 'sqlite',
- 'dbhost' => 'phpbb_unit_tests.sqlite2', // filename
- 'dbport' => '',
- 'dbname' => '',
- 'dbuser' => '',
- 'dbpasswd' => '',
- );
- }
- else
+ if (!isset($config['dbms']))
{
$this->markTestSkipped('Missing test_config.php: See first error.');
}
- }
-
- // NOTE: This function is not the same as split_sql_file from functions_install
- public function split_sql_file($sql, $dbms)
- {
- $dbms_data = $this->get_dbms_data($dbms);
-
- $sql = str_replace("\r" , '', $sql);
- $data = preg_split('/' . preg_quote($dbms_data['DELIM'], '/') . '$/m', $sql);
-
- $data = array_map('trim', $data);
-
- // The empty case
- $end_data = end($data);
-
- if (empty($end_data))
- {
- unset($data[key($data)]);
- }
- if ($dbms == 'sqlite')
- {
- // remove comment lines starting with # - they are not proper sqlite
- // syntax and break sqlite2
- foreach ($data as $i => $query)
- {
- $data[$i] = preg_replace('/^#.*$/m', "\n", $query);
- }
- }
-
- return $data;
- }
-
- /**
- * Retrieves a list of all tables from the database.
- *
- * @param PDO $pdo
- * @param string $dbms
- * @return array(string)
- */
- function get_tables($pdo, $dbms)
- {
- switch ($pdo)
- {
- case 'mysql':
- case 'mysql4':
- case 'mysqli':
- $sql = 'SHOW TABLES';
- break;
-
- case 'sqlite':
- $sql = 'SELECT name
- FROM sqlite_master
- WHERE type = "table"';
- break;
-
- case 'mssql':
- case 'mssql_odbc':
- case 'mssqlnative':
- $sql = "SELECT name
- FROM sysobjects
- WHERE type='U'";
- break;
-
- case 'postgres':
- $sql = 'SELECT relname
- FROM pg_stat_user_tables';
- break;
-
- case 'firebird':
- $sql = 'SELECT rdb$relation_name
- FROM rdb$relations
- WHERE rdb$view_source is null
- AND rdb$system_flag = 0';
- break;
-
- case 'oracle':
- $sql = 'SELECT table_name
- FROM USER_TABLES';
- break;
- }
-
- $result = $pdo->query($sql);
-
- $tables = array();
- while ($row = $result->fetch(PDO::FETCH_NUM))
- {
- $tables[] = current($row);
- }
-
- return $tables;
- }
-
- /**
- * Returns a PDO connection for the configured database.
- *
- * @param array $config The database configuration
- * @param array $dbms Information on the used DBMS.
- * @param bool $use_db Whether the DSN should be tied to a
- * particular database making it impossible
- * to delete that database.
- * @return PDO The PDO database connection.
- */
- public function new_pdo($config, $dbms, $use_db)
- {
- $dsn = $dbms['PDO'] . ':';
-
- switch ($dbms['PDO'])
- {
- case 'sqlite2':
- $dsn .= $config['dbhost'];
- break;
-
- case 'sqlsrv':
- // prefix the hostname (or DSN) with Server= so using just (local)\SQLExpress
- // works for example, further parameters can still be appended using ;x=y
- $dsn .= 'Server=';
- // no break -> rest like ODBC
- case 'odbc':
- // for ODBC assume dbhost is a suitable DSN
- // e.g. Driver={SQL Server Native Client 10.0};Server=(local)\SQLExpress;
- $dsn .= $config['dbhost'];
-
- if ($use_db)
- {
- $dsn .= ';Database=' . $config['dbname'];
- }
- break;
-
- default:
- $dsn .= 'host=' . $config['dbhost'];
-
- if ($use_db)
- {
- $dsn .= ';dbname=' . $config['dbname'];
- }
- break;
- }
-
- $pdo = new PDO($dsn, $config['dbuser'], $config['dbpasswd']);;
-
- // good for debug
- // $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
-
- return $pdo;
- }
-
- private function recreate_db($config, $dbms)
- {
- switch ($config['dbms'])
- {
- case 'sqlite':
- if (file_exists($config['dbhost']))
- {
- unlink($config['dbhost']);
- }
- break;
-
- default:
- $pdo = $this->new_pdo($config, $dbms, false);
-
- try
- {
- $pdo->exec('DROP DATABASE ' . $config['dbname']);
- }
- catch (PDOException $e)
- {
- // try to delete all tables if dropping the database was not possible.
- foreach ($this->get_tables() as $table)
- {
- try
- {
- $pdo->exec('DROP TABLE ' . $table);
- }
- catch (PDOException $e){} // ignore non-existent tables
- }
- }
-
- $pdo->exec('CREATE DATABASE ' . $config['dbname']);
- break;
- }
- }
-
- private function load_schema($pdo, $config, $dbms)
- {
- if ($config['dbms'] == 'mysql')
- {
- $sth = $pdo->query('SELECT VERSION() AS version');
- $row = $sth->fetch(PDO::FETCH_ASSOC);
-
- if (version_compare($row['version'], '4.1.3', '>='))
- {
- $dbms['SCHEMA'] .= '_41';
- }
- else
- {
- $dbms['SCHEMA'] .= '_40';
- }
- }
-
- $sql = $this->split_sql_file(file_get_contents("../phpBB/install/schemas/{$dbms['SCHEMA']}_schema.sql"), $config['dbms']);
-
- foreach ($sql as $query)
- {
- $pdo->exec($query);
- }
+ return $config;
}
public function getConnection()
{
$config = $this->get_database_config();
- $dbms = $this->get_dbms_data($config['dbms']);
+
+ $manager = $this->create_connection_manager($config);
if (!self::$already_connected)
{
- $this->recreate_db($config, $dbms);
+ $manager->recreate_db();
}
- $pdo = $this->new_pdo($config, $dbms, true);
+ $manager->connect();
if (!self::$already_connected)
{
- $this->load_schema($pdo, $config, $dbms);
-
+ $manager->load_schema();
self::$already_connected = true;
}
- return $this->createDefaultDBConnection($pdo, 'testdb');
+ return $this->createDefaultDBConnection($manager->get_pdo(), 'testdb');
}
public function new_dbal()
@@ -361,7 +78,7 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test
$config = $this->get_database_config();
- require_once '../phpBB/includes/db/' . $config['dbms'] . '.php';
+ require_once dirname(__FILE__) . '/../../phpBB/includes/db/' . $config['dbms'] . '.php';
$dbal = 'dbal_' . $config['dbms'];
$db = new $dbal();
$db->sql_connect($config['dbhost'], $config['dbuser'], $config['dbpasswd'], $config['dbname'], $config['dbport']);
@@ -369,8 +86,24 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test
return $db;
}
+ public function assertSqlResultEquals($expected, $sql, $message = '')
+ {
+ $db = $this->new_dbal();
+
+ $result = $db->sql_query($sql);
+ $rows = $db->sql_fetchrowset($result);
+ $db->sql_freeresult($result);
+
+ $this->assertEquals($expected, $rows, $message);
+ }
+
public function setExpectedTriggerError($errno, $message = '')
{
$this->get_test_case_helpers()->setExpectedTriggerError($errno, $message);
}
+
+ protected function create_connection_manager($config)
+ {
+ return new phpbb_database_test_connection_manager($config);
+ }
}
diff --git a/tests/test_framework/phpbb_database_test_connection_manager.php b/tests/test_framework/phpbb_database_test_connection_manager.php
new file mode 100644
index 0000000000..c734c90a1a
--- /dev/null
+++ b/tests/test_framework/phpbb_database_test_connection_manager.php
@@ -0,0 +1,320 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2011 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions_install.php';
+
+class phpbb_database_test_connection_manager
+{
+ private $config;
+ private $dbms;
+ private $pdo;
+
+ /**
+ * Constructor
+ *
+ * @param array $config Tests database configuration as returned by
+ * phpbb_database_test_case::get_database_config()
+ */
+ public function __construct($config)
+ {
+ $this->config = $config;
+ $this->dbms = $this->get_dbms_data($this->config['dbms']);
+ }
+
+ /**
+ * Return the current PDO instance
+ */
+ public function get_pdo()
+ {
+ return $this->pdo;
+ }
+
+ /**
+ * Creates a PDO connection for the configured database.
+ *
+ * @param bool $use_db Whether the DSN should be tied to a
+ * particular database making it impossible
+ * to delete that database.
+ */
+ public function connect($use_db = true)
+ {
+ $dsn = $this->dbms['PDO'] . ':';
+
+ switch ($this->dbms['PDO'])
+ {
+ case 'sqlite2':
+ $dsn .= $this->config['dbhost'];
+ break;
+
+ case 'sqlsrv':
+ // prefix the hostname (or DSN) with Server= so using just (local)\SQLExpress
+ // works for example, further parameters can still be appended using ;x=y
+ $dsn .= 'Server=';
+ // no break -> rest like ODBC
+ case 'odbc':
+ // for ODBC assume dbhost is a suitable DSN
+ // e.g. Driver={SQL Server Native Client 10.0};Server=(local)\SQLExpress;
+ $dsn .= $this->config['dbhost'];
+
+ if ($use_db)
+ {
+ $dsn .= ';Database=' . $this->config['dbname'];
+ }
+ break;
+
+ default:
+ $dsn .= 'host=' . $this->config['dbhost'];
+
+ if ($this->config['dbport'])
+ {
+ $dsn .= ';port=' . $this->config['dbport'];
+ }
+
+ if ($use_db)
+ {
+ $dsn .= ';dbname=' . $this->config['dbname'];
+ }
+ break;
+ }
+
+ try
+ {
+ $this->pdo = new PDO($dsn, $this->config['dbuser'], $this->config['dbpasswd']);
+ }
+ catch (PDOException $e)
+ {
+ $cleaned_dsn = str_replace($this->config['dbpasswd'], '*password*', $dsn);
+ throw new Exception("Unable do connect to $cleaned_dsn using PDO with error: {$e->getMessage()}");
+ }
+
+ // good for debug
+ // $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+ }
+
+ /**
+ * Load the phpBB database schema into the database
+ */
+ public function load_schema()
+ {
+ $this->ensure_connected(__METHOD__);
+
+ $directory = dirname(__FILE__) . '/../../phpBB/install/schemas/';
+ $this->load_schema_from_file($directory);
+ }
+
+ /**
+ * Drop the database if it exists and re-create it
+ *
+ * Note: This does not load the schema, and it is suggested
+ * to re-connect after calling to get use_db isolation.
+ */
+ public function recreate_db()
+ {
+ switch ($this->config['dbms'])
+ {
+ case 'sqlite':
+ if (file_exists($this->config['dbhost']))
+ {
+ unlink($this->config['dbhost']);
+ }
+ break;
+
+ default:
+ $this->connect(false);
+
+ try
+ {
+ $this->pdo->exec('DROP DATABASE ' . $this->config['dbname']);
+ }
+ catch (PDOException $e)
+ {
+ // try to delete all tables if dropping the database was not possible.
+ foreach ($this->get_tables() as $table)
+ {
+ $this->pdo->exec('DROP TABLE ' . $table);
+ }
+ }
+
+ $this->pdo->exec('CREATE DATABASE ' . $this->config['dbname']);
+ break;
+ }
+ }
+
+ /**
+ * Retrieves a list of all tables from the database.
+ *
+ * @return array(string)
+ */
+ public function get_tables()
+ {
+ $this->ensure_connected(__METHOD__);
+
+ switch ($this->config['dbms'])
+ {
+ case 'mysql':
+ case 'mysql4':
+ case 'mysqli':
+ $sql = 'SHOW TABLES';
+ break;
+
+ case 'sqlite':
+ $sql = 'SELECT name
+ FROM sqlite_master
+ WHERE type = "table"';
+ break;
+
+ case 'mssql':
+ case 'mssql_odbc':
+ case 'mssqlnative':
+ $sql = "SELECT name
+ FROM sysobjects
+ WHERE type='U'";
+ break;
+
+ case 'postgres':
+ $sql = 'SELECT relname
+ FROM pg_stat_user_tables';
+ break;
+
+ case 'firebird':
+ $sql = 'SELECT rdb$relation_name
+ FROM rdb$relations
+ WHERE rdb$view_source is null
+ AND rdb$system_flag = 0';
+ break;
+
+ case 'oracle':
+ $sql = 'SELECT table_name
+ FROM USER_TABLES';
+ break;
+ }
+
+ $result = $this->pdo->query($sql);
+
+ $tables = array();
+ while ($row = $result->fetch(PDO::FETCH_NUM))
+ {
+ $tables[] = current($row);
+ }
+
+ return $tables;
+ }
+
+ /**
+ * Throw an exception if not connected
+ */
+ protected function ensure_connected($method_name)
+ {
+ if (null === $this->pdo)
+ {
+ throw new Exception(sprintf('You must connect before calling %s', $method_name));
+ }
+ }
+
+ /**
+ * Compile the correct schema filename (as per create_schema_files) and
+ * load it into the database.
+ */
+ protected function load_schema_from_file($directory)
+ {
+ $schema = $this->dbms['SCHEMA'];
+
+ if ($this->config['dbms'] == 'mysql')
+ {
+ $sth = $this->pdo->query('SELECT VERSION() AS version');
+ $row = $sth->fetch(PDO::FETCH_ASSOC);
+
+ if (version_compare($row['version'], '4.1.3', '>='))
+ {
+ $schema .= '_41';
+ }
+ else
+ {
+ $schema .= '_40';
+ }
+ }
+
+ $filename = $directory . $schema . '_schema.sql';
+
+ $queries = file_get_contents($filename);
+ $sql = remove_comments($queries);
+
+ $sql = split_sql_file($sql, $this->dbms['DELIM']);
+
+ foreach ($sql as $query)
+ {
+ $this->pdo->exec($query);
+ }
+ }
+
+ /**
+ * Map a phpBB dbms driver name to dbms data array
+ */
+ protected function get_dbms_data($dbms)
+ {
+ $available_dbms = array(
+ 'firebird' => array(
+ 'SCHEMA' => 'firebird',
+ 'DELIM' => ';;',
+ 'PDO' => 'firebird',
+ ),
+ 'mysqli' => array(
+ 'SCHEMA' => 'mysql_41',
+ 'DELIM' => ';',
+ 'PDO' => 'mysql',
+ ),
+ 'mysql' => array(
+ 'SCHEMA' => 'mysql',
+ 'DELIM' => ';',
+ 'PDO' => 'mysql',
+ ),
+ 'mssql' => array(
+ 'SCHEMA' => 'mssql',
+ 'DELIM' => 'GO',
+ 'PDO' => 'odbc',
+ ),
+ 'mssql_odbc'=> array(
+ 'SCHEMA' => 'mssql',
+ 'DELIM' => 'GO',
+ 'PDO' => 'odbc',
+ ),
+ 'mssqlnative' => array(
+ 'SCHEMA' => 'mssql',
+ 'DELIM' => 'GO',
+ 'PDO' => 'sqlsrv',
+ ),
+ 'oracle' => array(
+ 'SCHEMA' => 'oracle',
+ 'DELIM' => '/',
+ 'PDO' => 'oci',
+ ),
+ 'postgres' => array(
+ 'SCHEMA' => 'postgres',
+ 'DELIM' => ';',
+ 'PDO' => 'pgsql',
+ ),
+ 'sqlite' => array(
+ 'SCHEMA' => 'sqlite',
+ 'DELIM' => ';',
+ 'PDO' => 'sqlite2',
+ ),
+ );
+
+ if (isset($available_dbms[$dbms]))
+ {
+ return $available_dbms[$dbms];
+ }
+ else
+ {
+ $message = "Supplied dbms \"$dbms\" is not a valid phpBB dbms, must be one of: ";
+ $message .= implode(', ', array_keys($available_dbms));
+ throw new Exception($message);
+ }
+ }
+}
diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php
new file mode 100644
index 0000000000..76fed76fae
--- /dev/null
+++ b/tests/test_framework/phpbb_functional_test_case.php
@@ -0,0 +1,241 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2011 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+use Symfony\Component\BrowserKit\CookieJar;
+
+require_once __DIR__ . '/../../phpBB/includes/functions_install.php';
+
+class phpbb_functional_test_case extends phpbb_test_case
+{
+ protected $client;
+ protected $root_url;
+
+ /**
+ * Session ID for current test's session (each test makes its own)
+ * @var string
+ */
+ protected $sid;
+
+ /**
+ * Language array used by phpBB
+ * @var array
+ */
+ protected $lang = array();
+
+ static protected $config = array();
+ static protected $already_installed = false;
+
+ static public function setUpBeforeClass()
+ {
+ if (!extension_loaded('phar'))
+ {
+ self::markTestSkipped('phar extension is not loaded');
+ }
+
+ require_once 'phar://' . __DIR__ . '/../../vendor/goutte.phar';
+ }
+
+ public function setUp()
+ {
+ if (!isset(self::$config['phpbb_functional_url']))
+ {
+ $this->markTestSkipped('phpbb_functional_url was not set in test_config and wasn\'t set as PHPBB_FUNCTIONAL_URL environment variable either.');
+ }
+
+ $this->cookieJar = new CookieJar;
+ $this->client = new Goutte\Client(array(), array(), null, $this->cookieJar);
+ $this->root_url = self::$config['phpbb_functional_url'];
+ // Clear the language array so that things
+ // that were added in other tests are gone
+ $this->lang = array();
+ $this->add_lang('common');
+ }
+
+ public function request($method, $path)
+ {
+ return $this->client->request($method, $this->root_url . $path);
+ }
+
+ // bootstrap, called after board is set up
+ // once per test case class
+ // test cases can override this
+ protected function bootstrap()
+ {
+ }
+
+ public function __construct($name = NULL, array $data = array(), $dataName = '')
+ {
+ parent::__construct($name, $data, $dataName);
+
+ $this->backupStaticAttributesBlacklist += array(
+ 'phpbb_functional_test_case' => array('config', 'already_installed'),
+ );
+
+ if (!static::$already_installed)
+ {
+ $this->install_board();
+ $this->bootstrap();
+ static::$already_installed = true;
+ }
+ }
+
+ protected function install_board()
+ {
+ global $phpbb_root_path, $phpEx;
+
+ self::$config = phpbb_test_case_helpers::get_test_config();
+
+ if (!isset(self::$config['phpbb_functional_url']))
+ {
+ return;
+ }
+
+ self::$config['table_prefix'] = 'phpbb_';
+ $this->recreate_database(self::$config);
+
+ if (file_exists($phpbb_root_path . "config.$phpEx"))
+ {
+ if (!file_exists($phpbb_root_path . "config_dev.$phpEx"))
+ {
+ rename($phpbb_root_path . "config.$phpEx", $phpbb_root_path . "config_dev.$phpEx");
+ }
+ else
+ {
+ unlink($phpbb_root_path . "config.$phpEx");
+ }
+ }
+
+ // begin data
+ $data = array();
+
+ $data = array_merge($data, self::$config);
+
+ $data = array_merge($data, array(
+ 'default_lang' => 'en',
+ 'admin_name' => 'admin',
+ 'admin_pass1' => 'admin',
+ 'admin_pass2' => 'admin',
+ 'board_email' => 'nobody@example.com',
+ ));
+
+ $parseURL = parse_url(self::$config['phpbb_functional_url']);
+
+ $data = array_merge($data, array(
+ 'email_enable' => false,
+ 'smtp_delivery' => false,
+ 'smtp_host' => '',
+ 'smtp_auth' => '',
+ 'smtp_user' => '',
+ 'smtp_pass' => '',
+ 'cookie_secure' => false,
+ 'force_server_vars' => false,
+ 'server_protocol' => $parseURL['scheme'] . '://',
+ 'server_name' => 'localhost',
+ 'server_port' => isset($parseURL['port']) ? (int) $parseURL['port'] : 80,
+ 'script_path' => $parseURL['path'],
+ ));
+ // end data
+
+ $content = $this->do_request('install');
+ $this->assertContains('Welcome to Installation', $content);
+
+ $this->do_request('create_table', $data);
+
+ file_put_contents($phpbb_root_path . "config.$phpEx", phpbb_create_config_file_data($data, self::$config['dbms'], array(), true));
+
+ $this->do_request('config_file', $data);
+
+ copy($phpbb_root_path . "config.$phpEx", $phpbb_root_path . "config_test.$phpEx");
+
+ $this->do_request('final', $data);
+ }
+
+ private function do_request($sub, $post_data = null)
+ {
+ $context = null;
+
+ if ($post_data)
+ {
+ $context = stream_context_create(array(
+ 'http' => array(
+ 'method' => 'POST',
+ 'header' => 'Content-Type: application/x-www-form-urlencoded',
+ 'content' => http_build_query($post_data),
+ 'ignore_errors' => true,
+ ),
+ ));
+ }
+
+ return file_get_contents(self::$config['phpbb_functional_url'] . 'install/index.php?mode=install&sub=' . $sub, false, $context);
+ }
+
+ private function recreate_database($config)
+ {
+ $db_conn_mgr = new phpbb_database_test_connection_manager($config);
+ $db_conn_mgr->recreate_db();
+ }
+
+ protected function login()
+ {
+ $this->add_lang('ucp');
+
+ $crawler = $this->request('GET', 'ucp.php');
+ $this->assertContains($this->lang('LOGIN_EXPLAIN_UCP'), $crawler->filter('html')->text());
+
+ $form = $crawler->selectButton($this->lang('LOGIN'))->form();
+ $login = $this->client->submit($form, array('username' => 'admin', 'password' => 'admin'));
+
+ $cookies = $this->cookieJar->all();
+
+ // The session id is stored in a cookie that ends with _sid - we assume there is only one such cookie
+ foreach ($cookies as $key => $cookie);
+ {
+ if (substr($key, -4) == '_sid')
+ {
+ $this->sid = $cookie->getValue();
+ }
+ }
+ }
+
+ protected function add_lang($lang_file)
+ {
+ if (is_array($lang_file))
+ {
+ foreach ($lang_file as $file)
+ {
+ $this->add_lang($file);
+ }
+ }
+
+ $lang_path = __DIR__ . "/../../phpBB/language/en/$lang_file.php";
+
+ $lang = array();
+
+ if (file_exists($lang_path))
+ {
+ include($lang_path);
+ }
+
+ $this->lang = array_merge($this->lang, $lang);
+ }
+
+ protected function lang()
+ {
+ $args = func_get_args();
+ $key = $args[0];
+
+ if (empty($this->lang[$key]))
+ {
+ throw new RuntimeException('Language key "' . $key . '" could not be found.');
+ }
+
+ $args[0] = $this->lang[$key];
+
+ return call_user_func_array('sprintf', $args);
+ }
+}
diff --git a/tests/test_framework/phpbb_test_case.php b/tests/test_framework/phpbb_test_case.php
index fe90d321dc..8b16f02638 100644
--- a/tests/test_framework/phpbb_test_case.php
+++ b/tests/test_framework/phpbb_test_case.php
@@ -3,7 +3,7 @@
*
* @package testing
* @copyright (c) 2008 phpBB Group
-* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
@@ -11,6 +11,21 @@ class phpbb_test_case extends PHPUnit_Framework_TestCase
{
protected $test_case_helpers;
+ public function __construct($name = NULL, array $data = array(), $dataName = '')
+ {
+ parent::__construct($name, $data, $dataName);
+ $this->backupStaticAttributesBlacklist += array(
+ 'PHP_CodeCoverage' => array('instance'),
+ 'PHP_CodeCoverage_Filter' => array('instance'),
+ 'PHP_CodeCoverage_Util' => array('ignoredLines', 'templateMethods'),
+ 'PHP_Timer' => array('startTimes',),
+ 'PHP_Token_Stream' => array('customTokens'),
+ 'PHP_Token_Stream_CachingFactory' => array('cache'),
+
+ 'phpbb_database_test_case' => array('already_connected'),
+ );
+ }
+
public function get_test_case_helpers()
{
if (!$this->test_case_helpers)
diff --git a/tests/test_framework/phpbb_test_case_helpers.php b/tests/test_framework/phpbb_test_case_helpers.php
index 0acdce32e0..2a3c27f9f9 100644
--- a/tests/test_framework/phpbb_test_case_helpers.php
+++ b/tests/test_framework/phpbb_test_case_helpers.php
@@ -3,7 +3,7 @@
*
* @package testing
* @copyright (c) 2008 phpBB Group
-* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
@@ -41,4 +41,71 @@ class phpbb_test_case_helpers
$this->expectedTriggerError = true;
$this->test_case->setExpectedException($exceptionName, (string) $message, $errno);
}
+
+ static public function get_test_config()
+ {
+ $config = array();
+
+ if (extension_loaded('sqlite') && version_compare(PHPUnit_Runner_Version::id(), '3.4.15', '>='))
+ {
+ $config = array_merge($config, array(
+ 'dbms' => 'sqlite',
+ 'dbhost' => dirname(__FILE__) . '/../phpbb_unit_tests.sqlite2', // filename
+ 'dbport' => '',
+ 'dbname' => '',
+ 'dbuser' => '',
+ 'dbpasswd' => '',
+ ));
+ }
+
+ if (isset($_SERVER['PHPBB_TEST_CONFIG']))
+ {
+ // Could be an absolute path
+ $test_config = $_SERVER['PHPBB_TEST_CONFIG'];
+ }
+ else
+ {
+ $test_config = dirname(__FILE__) . '/../test_config.php';
+ }
+
+ if (file_exists($test_config))
+ {
+ include($test_config);
+
+ $config = array_merge($config, array(
+ 'dbms' => $dbms,
+ 'dbhost' => $dbhost,
+ 'dbport' => $dbport,
+ 'dbname' => $dbname,
+ 'dbuser' => $dbuser,
+ 'dbpasswd' => $dbpasswd,
+ ));
+
+ if (isset($phpbb_functional_url))
+ {
+ $config['phpbb_functional_url'] = $phpbb_functional_url;
+ }
+ }
+
+ if (isset($_SERVER['PHPBB_TEST_DBMS']))
+ {
+ $config = array_merge($config, array(
+ 'dbms' => isset($_SERVER['PHPBB_TEST_DBMS']) ? $_SERVER['PHPBB_TEST_DBMS'] : '',
+ 'dbhost' => isset($_SERVER['PHPBB_TEST_DBHOST']) ? $_SERVER['PHPBB_TEST_DBHOST'] : '',
+ 'dbport' => isset($_SERVER['PHPBB_TEST_DBPORT']) ? $_SERVER['PHPBB_TEST_DBPORT'] : '',
+ 'dbname' => isset($_SERVER['PHPBB_TEST_DBNAME']) ? $_SERVER['PHPBB_TEST_DBNAME'] : '',
+ 'dbuser' => isset($_SERVER['PHPBB_TEST_DBUSER']) ? $_SERVER['PHPBB_TEST_DBUSER'] : '',
+ 'dbpasswd' => isset($_SERVER['PHPBB_TEST_DBPASSWD']) ? $_SERVER['PHPBB_TEST_DBPASSWD'] : ''
+ ));
+ }
+
+ if (isset($_SERVER['PHPBB_FUNCTIONAL_URL']))
+ {
+ $config = array_merge($config, array(
+ 'phpbb_functional_url' => isset($_SERVER['PHPBB_FUNCTIONAL_URL']) ? $_SERVER['PHPBB_FUNCTIONAL_URL'] : '',
+ ));
+ }
+
+ return $config;
+ }
}
diff --git a/tests/text_processing/all_tests.php b/tests/text_processing/all_tests.php
deleted file mode 100644
index 5e759c72ee..0000000000
--- a/tests/text_processing/all_tests.php
+++ /dev/null
@@ -1,41 +0,0 @@
-<?php
-/**
-*
-* @package testing
-* @copyright (c) 2008 phpBB Group
-* @license http://opensource.org/licenses/gpl-license.php GNU Public License
-*
-*/
-
-if (!defined('PHPUnit_MAIN_METHOD'))
-{
- define('PHPUnit_MAIN_METHOD', 'phpbb_text_processing_all_tests::main');
-}
-
-require_once 'test_framework/framework.php';
-require_once 'PHPUnit/TextUI/TestRunner.php';
-
-require_once 'text_processing/make_clickable.php';
-
-class phpbb_text_processing_all_tests
-{
- public static function main()
- {
- PHPUnit_TextUI_TestRunner::run(self::suite());
- }
-
- public static function suite()
- {
- $suite = new PHPUnit_Framework_TestSuite('phpBB Text Processing Tools');
-
- $suite->addTestSuite('phpbb_text_processing_make_clickable_test');
-
- return $suite;
- }
-}
-
-if (PHPUnit_MAIN_METHOD == 'phpbb_text_processing_all_tests::main')
-{
- phpbb_text_processing_all_tests::main();
-}
-
diff --git a/tests/text_processing/censor_text_test.php b/tests/text_processing/censor_text_test.php
new file mode 100644
index 0000000000..8fcdb7ef85
--- /dev/null
+++ b/tests/text_processing/censor_text_test.php
@@ -0,0 +1,85 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2011 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions_content.php';
+require_once dirname(__FILE__) . '/../mock_user.php';
+require_once dirname(__FILE__) . '/../mock/cache.php';
+
+class phpbb_text_processing_censor_text_test extends phpbb_test_case
+{
+ public function censor_text_data()
+ {
+ global $cache, $user;
+ $cache = new phpbb_mock_cache;
+ $user = new phpbb_mock_user;
+
+ $user->optionset('viewcensors', false);
+
+ return array(
+ array('', ''),
+
+ array('badword1', 'replacement1'),
+ array(' badword1', ' replacement1'),
+ array('badword1 ', 'replacement1 '),
+ array(' badword1 ', ' replacement1 '),
+ array('abadword1', 'replacement1'),
+ array('badword1w', 'replacement1'),
+ array('abadword1w', 'replacement1'),
+ array('anotherbadword1test', 'replacement1'),
+ array('this badword1', 'this replacement1'),
+ array('this badword1 word', 'this replacement1 word'),
+
+ array('badword2', 'replacement2'),
+ array('bbadword2', 'replacement2'),
+ array('bbbadword2', 'replacement2'),
+ array('badword2d', 'badword2d'),
+ array('bbadword2d', 'bbadword2d'),
+ array('test badword2', 'test replacement2'),
+ array('test badword2 word', 'test replacement2 word'),
+
+ array('badword3', 'replacement3'),
+ array('bbadword3', 'bbadword3'),
+ array('badword3d', 'replacement3'),
+ array('badword3ddd', 'replacement3'),
+ array('bbadword3d', 'bbadword3d'),
+ array(' badword3 ', ' replacement3 '),
+ array(' badword3', ' replacement3'),
+
+ array('badword4', 'replacement4'),
+ array('this badword4 word', 'this replacement4 word'),
+ array('abadword4', 'abadword4'),
+ array('badword4d', 'badword4d'),
+ array('abadword4d', 'abadword4d'),
+
+ array('badword1 badword2 badword3 badword4', 'replacement1 replacement2 replacement3 replacement4'),
+ array('badword1 badword2 badword3 badword4d', 'replacement1 replacement2 replacement3 badword4d'),
+ array('abadword1 badword2 badword3 badword4', 'replacement1 replacement2 replacement3 replacement4'),
+
+ array("new\nline\ntest", "new\nline\ntest"),
+ array("tab\ttest\t", "tab\ttest\t"),
+ array('öäü', 'öäü'),
+ array('badw' . chr(1) . 'ord1', 'badw' . chr(1) . 'ord1'),
+ array('badw' . chr(2) . 'ord1', 'badw' . chr(2) . 'ord1'),
+ array('badw' . chr(3) . 'ord1', 'badw' . chr(3) . 'ord1'),
+ array('badw' . chr(4) . 'ord1', 'badw' . chr(4) . 'ord1'),
+ array('badw' . chr(5) . 'ord1', 'badw' . chr(5) . 'ord1'),
+ array('badw' . chr(6) . 'ord1', 'badw' . chr(6) . 'ord1'),
+ );
+ }
+
+ /**
+ * @dataProvider censor_text_data
+ */
+ public function test_censor_text($input, $expected)
+ {
+ $label = 'Testing word censor: ' . $input;
+ $this->assertEquals($expected, censor_text($input), $label);
+ }
+}
diff --git a/tests/text_processing/make_clickable.php b/tests/text_processing/make_clickable_test.php
index a667dd705e..8697907311 100644
--- a/tests/text_processing/make_clickable.php
+++ b/tests/text_processing/make_clickable_test.php
@@ -3,14 +3,12 @@
*
* @package testing
* @copyright (c) 2008 phpBB Group
-* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
-require_once 'test_framework/framework.php';
-
-require_once '../phpBB/includes/functions.php';
-require_once '../phpBB/includes/functions_content.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions_content.php';
class phpbb_text_processing_make_clickable_test extends phpbb_test_case
{
diff --git a/tests/tmp/.gitkeep b/tests/tmp/.gitkeep
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/tmp/.gitkeep
diff --git a/tests/user/lang_test.php b/tests/user/lang_test.php
new file mode 100644
index 0000000000..d33f430955
--- /dev/null
+++ b/tests/user/lang_test.php
@@ -0,0 +1,58 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2011 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+require_once dirname(__FILE__) . '/../../phpBB/includes/session.php';
+
+class phpbb_user_lang_test extends phpbb_test_case
+{
+ public function test_user_lang_sprintf()
+ {
+ $user = new user;
+ $user->lang = array(
+ 'FOO' => 'BAR',
+ 'BARZ' => 'PENG',
+ 'EMPTY' => '',
+ 'ZERO' => '0',
+ 'STR' => '%d %s, %d topics',
+ 'STR2' => '%d foos',
+ 'ARRY' => array(
+ 0 => 'No posts', // 0
+ 1 => '1 post', // 1
+ 2 => '%d posts', // 2+
+ ),
+ );
+
+ // No param
+ $this->assertEquals($user->lang('FOO'), 'BAR');
+ $this->assertEquals($user->lang('EMPTY'), '');
+ $this->assertEquals($user->lang('ZERO'), '0');
+
+ // Invalid index
+ $this->assertEquals($user->lang('VOID'), 'VOID');
+
+ // Unnecessary param
+ $this->assertEquals($user->lang('FOO', 2), 'BAR');
+ $this->assertEquals($user->lang('FOO', 2, 3), 'BAR');
+ $this->assertEquals($user->lang('FOO', 2, 3, 'BARZ'), 'BAR');
+
+ // String
+ $this->assertEquals($user->lang('STR', 24, 'x', 42), '24 x, 42 topics');
+ $this->assertEquals($user->lang('STR2', 64), '64 foos');
+
+ // Array
+ $this->assertEquals($user->lang('ARRY', 0), 'No posts');
+ $this->assertEquals($user->lang('ARRY', 1), '1 post');
+ $this->assertEquals($user->lang('ARRY', 2), '2 posts');
+ $this->assertEquals($user->lang('ARRY', 123), '123 posts');
+
+ // Bug PHPBB3-9949
+ $this->assertEquals($user->lang('ARRY', 1, 2), '1 post');
+ $this->assertEquals($user->lang('ARRY', 1, 's', 2), '1 post');
+ }
+}
diff --git a/tests/utf/all_tests.php b/tests/utf/all_tests.php
deleted file mode 100644
index 0d5d44d695..0000000000
--- a/tests/utf/all_tests.php
+++ /dev/null
@@ -1,43 +0,0 @@
-<?php
-/**
-*
-* @package testing
-* @copyright (c) 2008 phpBB Group
-* @license http://opensource.org/licenses/gpl-license.php GNU Public License
-*
-*/
-
-if (!defined('PHPUnit_MAIN_METHOD'))
-{
- define('PHPUnit_MAIN_METHOD', 'phpbb_utf_all_tests::main');
-}
-
-require_once 'test_framework/framework.php';
-require_once 'PHPUnit/TextUI/TestRunner.php';
-
-require_once 'utf/utf8_wordwrap_test.php';
-require_once 'utf/utf8_clean_string_test.php';
-
-class phpbb_utf_all_tests
-{
- public static function main()
- {
- PHPUnit_TextUI_TestRunner::run(self::suite());
- }
-
- public static function suite()
- {
- $suite = new PHPUnit_Framework_TestSuite('phpBB Unicode Transformation Format');
-
- $suite->addTestSuite('phpbb_utf_utf8_wordwrap_test');
- $suite->addTestSuite('phpbb_utf_utf8_clean_string_test');
-
- return $suite;
- }
-}
-
-if (PHPUnit_MAIN_METHOD == 'phpbb_utf_all_tests::main')
-{
- phpbb_utf_all_tests::main();
-}
-
diff --git a/tests/utf/normalizer_test.php b/tests/utf/normalizer_test.php
new file mode 100644
index 0000000000..92230cfcc9
--- /dev/null
+++ b/tests/utf/normalizer_test.php
@@ -0,0 +1,323 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2011 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_normalizer.php';
+
+/**
+* @group slow
+*/
+class phpbb_utf_normalizer_test extends phpbb_test_case
+{
+ static private $data_dir;
+
+ static public function setUpBeforeClass()
+ {
+ self::$data_dir = dirname(__file__) . '/../tmp';
+ self::download('http://www.unicode.org/Public/UNIDATA/NormalizationTest.txt', self::$data_dir);
+ self::download('http://www.unicode.org/Public/UNIDATA/UnicodeData.txt', self::$data_dir);
+ }
+
+ public function test_normalizer()
+ {
+ $test_suite = array(
+ /**
+ * NFC
+ * c2 == NFC(c1) == NFC(c2) == NFC(c3)
+ * c4 == NFC(c4) == NFC(c5)
+ */
+ 'NFC' => array(
+ 'c2' => array('c1', 'c2', 'c3'),
+ 'c4' => array('c4', 'c5')
+ ),
+
+ /**
+ * NFD
+ * c3 == NFD(c1) == NFD(c2) == NFD(c3)
+ * c5 == NFD(c4) == NFD(c5)
+ */
+ 'NFD' => array(
+ 'c3' => array('c1', 'c2', 'c3'),
+ 'c5' => array('c4', 'c5')
+ ),
+
+ /**
+ * NFKC
+ * c4 == NFKC(c1) == NFKC(c2) == NFKC(c3) == NFKC(c4) == NFKC(c5)
+ */
+ 'NFKC' => array(
+ 'c4' => array('c1', 'c2', 'c3', 'c4', 'c5')
+ ),
+
+ /**
+ * NFKD
+ * c5 == NFKD(c1) == NFKD(c2) == NFKD(c3) == NFKD(c4) == NFKD(c5)
+ */
+ 'NFKD' => array(
+ 'c5' => array('c1', 'c2', 'c3', 'c4', 'c5')
+ )
+ );
+
+ $tested_chars = array();
+
+ $fp = fopen(self::$data_dir . '/NormalizationTest.txt', 'rb');
+ while (!feof($fp))
+ {
+ $line = fgets($fp);
+
+ if ($line[0] == '@')
+ {
+ continue;
+ }
+
+ if (!strpos(' 0123456789ABCDEF', $line[0]))
+ {
+ continue;
+ }
+
+ list($c1, $c2, $c3, $c4, $c5) = explode(';', $line);
+
+ if (!strpos($c1, ' '))
+ {
+ /**
+ * We are currently testing a single character, we add it to the list of
+ * characters we have processed so that we can exclude it when testing
+ * for invariants
+ */
+ $tested_chars[$c1] = 1;
+ }
+
+ foreach ($test_suite as $form => $serie)
+ {
+ foreach ($serie as $expected => $tests)
+ {
+ $hex_expected = ${$expected};
+ $utf_expected = $this->hexseq_to_utf($hex_expected);
+
+ foreach ($tests as $test)
+ {
+ $utf_result = $utf_expected;
+ call_user_func_array(array('utf_normalizer', $form), array(&$utf_result));
+
+ $hex_result = $this->utf_to_hexseq($utf_result);
+ $this->assertEquals($utf_expected, $utf_result, "$expected == $form($test) ($hex_expected != $hex_result)");
+ }
+ }
+ }
+ }
+ fclose($fp);
+
+ return $tested_chars;
+ }
+
+ /**
+ * @depends test_normalizer
+ */
+ public function test_invariants(array $tested_chars)
+ {
+ $fp = fopen(self::$data_dir . '/UnicodeData.txt', 'rb');
+
+ while (!feof($fp))
+ {
+ $line = fgets($fp, 1024);
+
+ if (!$pos = strpos($line, ';'))
+ {
+ continue;
+ }
+
+ $hex_tested = $hex_expected = substr($line, 0, $pos);
+
+ if (isset($tested_chars[$hex_tested]))
+ {
+ continue;
+ }
+
+ $utf_expected = $this->hex_to_utf($hex_expected);
+
+ if ($utf_expected >= UTF8_SURROGATE_FIRST
+ && $utf_expected <= UTF8_SURROGATE_LAST)
+ {
+ /**
+ * Surrogates are illegal on their own, we expect the normalizer
+ * to return a replacement char
+ */
+ $utf_expected = UTF8_REPLACEMENT;
+ $hex_expected = $this->utf_to_hexseq($utf_expected);
+ }
+
+ foreach (array('nfc', 'nfkc', 'nfd', 'nfkd') as $form)
+ {
+ $utf_result = $utf_expected;
+ call_user_func_array(array('utf_normalizer', $form), array(&$utf_result));
+ $hex_result = $this->utf_to_hexseq($utf_result);
+
+ $this->assertEquals($utf_expected, $utf_result, "$hex_expected == $form($hex_tested) ($hex_expected != $hex_result)");
+ }
+ }
+ fclose($fp);
+ }
+
+ /**
+ * Convert a UTF string to a sequence of codepoints in hexadecimal
+ *
+ * @param string $utf UTF string
+ * @return integer Unicode codepoints in hex
+ */
+ protected function utf_to_hexseq($str)
+ {
+ $pos = 0;
+ $len = strlen($str);
+ $ret = array();
+
+ while ($pos < $len)
+ {
+ $c = $str[$pos];
+ switch ($c & "\xF0")
+ {
+ case "\xC0":
+ case "\xD0":
+ $utf_char = substr($str, $pos, 2);
+ $pos += 2;
+ break;
+
+ case "\xE0":
+ $utf_char = substr($str, $pos, 3);
+ $pos += 3;
+ break;
+
+ case "\xF0":
+ $utf_char = substr($str, $pos, 4);
+ $pos += 4;
+ break;
+
+ default:
+ $utf_char = $c;
+ ++$pos;
+ }
+
+ $hex = dechex($this->utf_to_cp($utf_char));
+
+ if (!isset($hex[3]))
+ {
+ $hex = substr('000' . $hex, -4);
+ }
+
+ $ret[] = $hex;
+ }
+
+ return strtr(implode(' ', $ret), 'abcdef', 'ABCDEF');
+ }
+
+ /**
+ * Convert a UTF-8 char to its codepoint
+ *
+ * @param string $utf_char UTF-8 char
+ * @return integer Unicode codepoint
+ */
+ protected function utf_to_cp($utf_char)
+ {
+ switch (strlen($utf_char))
+ {
+ case 1:
+ return ord($utf_char);
+
+ case 2:
+ return ((ord($utf_char[0]) & 0x1F) << 6) | (ord($utf_char[1]) & 0x3F);
+
+ case 3:
+ return ((ord($utf_char[0]) & 0x0F) << 12) | ((ord($utf_char[1]) & 0x3F) << 6) | (ord($utf_char[2]) & 0x3F);
+
+ case 4:
+ return ((ord($utf_char[0]) & 0x07) << 18) | ((ord($utf_char[1]) & 0x3F) << 12) | ((ord($utf_char[2]) & 0x3F) << 6) | (ord($utf_char[3]) & 0x3F);
+
+ default:
+ throw new RuntimeException('UTF-8 chars can only be 1-4 bytes long');
+ }
+ }
+
+ /**
+ * Return a UTF string formed from a sequence of codepoints in hexadecimal
+ *
+ * @param string $seq Sequence of codepoints, separated with a space
+ * @return string UTF-8 string
+ */
+ protected function hexseq_to_utf($seq)
+ {
+ return implode('', array_map(array($this, 'hex_to_utf'), explode(' ', $seq)));
+ }
+
+ /**
+ * Convert a codepoint in hexadecimal to a UTF-8 char
+ *
+ * @param string $hex Codepoint, in hexadecimal
+ * @return string UTF-8 char
+ */
+ protected function hex_to_utf($hex)
+ {
+ return $this->cp_to_utf(hexdec($hex));
+ }
+
+ /**
+ * Convert a codepoint to a UTF-8 char
+ *
+ * @param integer $cp Unicode codepoint
+ * @return string UTF-8 string
+ */
+ protected function cp_to_utf($cp)
+ {
+ if ($cp > 0xFFFF)
+ {
+ return chr(0xF0 | ($cp >> 18)) . chr(0x80 | (($cp >> 12) & 0x3F)) . chr(0x80 | (($cp >> 6) & 0x3F)) . chr(0x80 | ($cp & 0x3F));
+ }
+ else if ($cp > 0x7FF)
+ {
+ return chr(0xE0 | ($cp >> 12)) . chr(0x80 | (($cp >> 6) & 0x3F)) . chr(0x80 | ($cp & 0x3F));
+ }
+ else if ($cp > 0x7F)
+ {
+ return chr(0xC0 | ($cp >> 6)) . chr(0x80 | ($cp & 0x3F));
+ }
+ else
+ {
+ return chr($cp);
+ }
+ }
+
+ // chunked download helper
+ static protected function download($url, $to)
+ {
+ $target = $to . '/' . basename($url);
+
+ if (file_exists($target))
+ {
+ return;
+ }
+
+ if (!$fpr = fopen($url, 'rb'))
+ {
+ echo "Failed to download $url\n";
+ return;
+ }
+
+ if (!$fpw = fopen($target, 'wb'))
+ {
+ echo "Failed to open $target for writing\n";
+ return;
+ }
+
+ $chunk = 32768;
+
+ while (!feof($fpr))
+ {
+ fwrite($fpw, fread($fpr, $chunk));
+ }
+ fclose($fpr);
+ fclose($fpw);
+ }
+}
diff --git a/tests/utf/utf8_clean_string_test.php b/tests/utf/utf8_clean_string_test.php
index 870ad76fc4..70bd549d5b 100644
--- a/tests/utf/utf8_clean_string_test.php
+++ b/tests/utf/utf8_clean_string_test.php
@@ -3,12 +3,11 @@
*
* @package testing
* @copyright (c) 2008 phpBB Group
-* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
-require_once 'test_framework/framework.php';
-require_once '../phpBB/includes/utf/utf_tools.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php';
class phpbb_utf_utf8_clean_string_test extends phpbb_test_case
{
diff --git a/tests/utf/utf8_wordwrap_test.php b/tests/utf/utf8_wordwrap_test.php
index ef1165a897..39fdf73308 100644
--- a/tests/utf/utf8_wordwrap_test.php
+++ b/tests/utf/utf8_wordwrap_test.php
@@ -3,12 +3,11 @@
*
* @package testing
* @copyright (c) 2008 phpBB Group
-* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
-require_once 'test_framework/framework.php';
-require_once '../phpBB/includes/utf/utf_tools.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php';
class phpbb_utf_utf8_wordwrap_test extends phpbb_test_case
{
diff --git a/tests/wrapper/gmgetdate_test.php b/tests/wrapper/gmgetdate_test.php
new file mode 100644
index 0000000000..a838cfdba9
--- /dev/null
+++ b/tests/wrapper/gmgetdate_test.php
@@ -0,0 +1,49 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2011 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
+
+class phpbb_wrapper_gmgetdate_test extends phpbb_test_case
+{
+ public function test_gmgetdate()
+ {
+ $this->run_gmgetdate_assertion();
+ $this->run_test_with_timezone('UTC');
+ $this->run_test_with_timezone('Europe/Berlin');
+ $this->run_test_with_timezone('America/Los_Angeles');
+ $this->run_test_with_timezone('Antarctica/South_Pole');
+ }
+
+ protected function run_test_with_timezone($timezone_identifier)
+ {
+ $current_timezone = date_default_timezone_get();
+
+ date_default_timezone_set($timezone_identifier);
+ $this->run_gmgetdate_assertion();
+ date_default_timezone_set($current_timezone);
+ }
+
+ protected function run_gmgetdate_assertion()
+ {
+ $expected = time();
+
+ $date_array = phpbb_gmgetdate($expected);
+
+ $actual = gmmktime(
+ $date_array['hours'],
+ $date_array['minutes'],
+ $date_array['seconds'],
+ $date_array['mon'],
+ $date_array['mday'],
+ $date_array['year']
+ );
+
+ $this->assertEquals($expected, $actual);
+ }
+}
diff --git a/tests/wrapper/mt_rand_test.php b/tests/wrapper/mt_rand_test.php
new file mode 100644
index 0000000000..eba0bf2faa
--- /dev/null
+++ b/tests/wrapper/mt_rand_test.php
@@ -0,0 +1,46 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2011 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
+
+class phpbb_wrapper_mt_rand_test extends phpbb_test_case
+{
+ public function test_max_equals_min()
+ {
+ $result = phpbb_mt_rand(42, 42);
+ $this->assertEquals(42, $result);
+ }
+
+ public function test_max_equals_min_negative()
+ {
+ $result = phpbb_mt_rand(-42, -42);
+ $this->assertEquals(-42, $result);
+ }
+
+ public function test_max_greater_min()
+ {
+ $result = phpbb_mt_rand(3, 4);
+ $this->assertGreaterThanOrEqual(3, $result);
+ $this->assertLessThanOrEqual(4, $result);
+ }
+
+ public function test_min_greater_max()
+ {
+ $result = phpbb_mt_rand(4, 3);
+ $this->assertGreaterThanOrEqual(3, $result);
+ $this->assertLessThanOrEqual(4, $result);
+ }
+
+ public function test_min_greater_max_negative()
+ {
+ $result = phpbb_mt_rand(-3, -4);
+ $this->assertGreaterThanOrEqual(-4, $result);
+ $this->assertLessThanOrEqual(-3, $result);
+ }
+}
diff --git a/tests/wrapper/version_compare_test.php b/tests/wrapper/version_compare_test.php
new file mode 100644
index 0000000000..8b42eb4bee
--- /dev/null
+++ b/tests/wrapper/version_compare_test.php
@@ -0,0 +1,130 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2011 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
+
+class phpbb_wrapper_version_compare_test extends phpbb_test_case
+{
+ public function test_two_parameters()
+ {
+ $this->assertEquals(-1, phpbb_version_compare('1.0.0', '1.0.1'));
+ $this->assertEquals(0, phpbb_version_compare('1.0.0', '1.0.0'));
+ $this->assertEquals(1, phpbb_version_compare('1.0.1', '1.0.0'));
+ }
+
+ public function test_three_parameters()
+ {
+ $this->assertEquals(true, phpbb_version_compare('1.0.0', '1.0.1', '<'));
+ $this->assertEquals(true, phpbb_version_compare('1.0.0', '1.0.0', '<='));
+ $this->assertEquals(true, phpbb_version_compare('1.0.0', '1.0.0', '='));
+ $this->assertEquals(true, phpbb_version_compare('1.0.0', '1.0.0', '>='));
+ $this->assertEquals(true, phpbb_version_compare('1.0.1', '1.0.0', '>'));
+ }
+
+ public function test_strict_order()
+ {
+ $releases = array(
+ '2.0.0',
+ '2.0.1',
+ // Those are not version_compare() compatible
+ //'2.0.6a',
+ //'2.0.6b',
+ //'2.0.6c',
+ //'2.0.6d',
+ '2.0.7',
+ '2.0.23',
+ '3.0.A1',
+ '3.0.A2',
+ '3.0.A3',
+ '3.0.B1',
+ '3.0.B2',
+ '3.0.B4',
+ '3.0.B5',
+ '3.0.RC1',
+ '3.0.RC5',
+ '3.0.0',
+ '3.0.1',
+ '3.0.2',
+ '3.0.7',
+ '3.0.7-PL1',
+ '3.0.8-RC1',
+ '3.0.8',
+ '3.0.9-dev',
+ '3.0.9-RC1',
+ '3.0.9-RC2',
+ '3.0.9-RC4',
+ '3.0.10-RC1',
+ '3.1-dev',
+ '3.2-A1',
+ );
+
+ for ($i = 0, $size = sizeof($releases); $i < $size - 1; ++$i)
+ {
+ $version1 = $releases[$i];
+ $version2 = $releases[$i + 1];
+
+ $this->assertEquals(
+ true,
+ phpbb_version_compare($version1, $version2, '<'),
+ "Result of version comparison $version1 < $version2 is incorrect."
+ );
+ }
+ }
+
+ /**
+ * @dataProvider equality_test_data
+ */
+ public function test_equality($version1, $version2)
+ {
+ $this->assertEquals(
+ 0,
+ phpbb_version_compare($version1, $version2),
+ "Result of version comparison $version1 = $version2 is incorrect."
+ );
+
+ $this->assertEquals(
+ true,
+ phpbb_version_compare($version1, $version2, '='),
+ "Result of version comparison $version1 = $version2 is incorrect."
+ );
+ }
+
+ public function equality_test_data()
+ {
+ return array(
+ array('1.1.0-A2', '1.1.0-a2'),
+ array('1.1.0-B1', '1.1.0-b1'),
+ );
+ }
+
+ /**
+ * @dataProvider alpha_beta_test_data
+ */
+ public function test_alpha_beta($expected, $version1, $version2)
+ {
+ $this->assertEquals(
+ $expected,
+ phpbb_version_compare($version1, $version2),
+ "Result of version comparison ($version1, $version2) = $expected is incorrect."
+ );
+
+ }
+
+ public function alpha_beta_test_data()
+ {
+ return array(
+ array(-1, '1.1.0-A2', '1.1.0-B1'),
+ array(-1, '1.1.0-a2', '1.1.0-b1'),
+
+ array(-1, '1.1.0-a2', '1.1.0-B1'),
+ array(-1, '1.1.0-A2', '1.1.0-b1'),
+ );
+ }
+
+}