aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/RUNNING_TESTS.txt49
-rw-r--r--tests/bbcode/url_bbcode_test.php2
-rw-r--r--tests/bootstrap.php2
-rw-r--r--tests/class_loader/class_loader_test.php2
-rw-r--r--tests/config/db_test.php2
-rw-r--r--tests/cron/manager_test.php1
-rw-r--r--tests/cron/task_provider_test.php4
-rw-r--r--tests/datetime/from_format_test.php57
-rw-r--r--tests/dbal/auto_increment_test.php100
-rw-r--r--tests/dbal/case_test.php69
-rw-r--r--tests/dbal/concatenate_test.php64
-rw-r--r--tests/dbal/db_tools_test.php63
-rw-r--r--tests/dbal/order_lower_test.php2
-rw-r--r--tests/dbal/select_test.php32
-rw-r--r--tests/download/http_byte_range_test.php1
-rw-r--r--tests/extension/finder_test.php3
-rw-r--r--tests/extension/manager_test.php1
-rw-r--r--tests/functional/auth_test.php40
-rw-r--r--tests/functional/browse_test.php6
-rw-r--r--tests/functional/extension_controller_test.php9
-rw-r--r--tests/functional/fileupload_form_test.php69
-rw-r--r--tests/functional/fileupload_remote_test.php72
-rw-r--r--tests/functional/fixtures/files/empty.png0
-rw-r--r--tests/functional/fixtures/files/illegal-extension.bifbin0 -> 519 bytes
-rw-r--r--tests/functional/fixtures/files/too-large.pngbin0 -> 284717 bytes
-rw-r--r--tests/functional/fixtures/files/valid.jpgbin0 -> 554 bytes
-rw-r--r--tests/functional/lang_test.php45
-rw-r--r--tests/functions_acp/build_cfg_template_test.php1
-rw-r--r--tests/functions_acp/build_select_test.php1
-rw-r--r--tests/functions_acp/h_radio_test.php1
-rw-r--r--tests/functions_acp/validate_config_vars_test.php1
-rw-r--r--tests/functions_acp/validate_range_test.php1
-rw-r--r--tests/mock/filespec.php32
-rw-r--r--tests/mock/fileupload.php52
-rw-r--r--tests/mock/user.php (renamed from tests/mock_user.php)0
-rw-r--r--tests/regex/email_test.php3
-rw-r--r--tests/security/base.php2
-rw-r--r--tests/session/continue_test.php1
-rw-r--r--tests/session/init_test.php1
-rw-r--r--tests/session/testable_factory.php3
-rw-r--r--tests/template/invalid_constructs_test.php87
-rw-r--r--tests/template/parent_templates/parent_and_child.js1
-rw-r--r--tests/template/parent_templates/parent_only.js1
-rw-r--r--tests/template/renderer_eval_test.php4
-rw-r--r--tests/template/template_compile_test.php2
-rw-r--r--tests/template/template_includejs_test.php11
-rw-r--r--tests/template/template_locate_test.php6
-rw-r--r--tests/template/template_test.php2
-rw-r--r--tests/template/template_test_case.php7
-rw-r--r--tests/template/template_test_case_with_tree.php6
-rw-r--r--tests/template/templates/child_only.js1
-rw-r--r--tests/template/templates/includejs.html4
-rw-r--r--tests/template/templates/invalid/endif_without_if.html1
-rw-r--r--tests/template/templates/invalid/include_nonexistent_file.html1
-rw-r--r--tests/template/templates/invalid/output/endif_without_if.html1
-rw-r--r--tests/template/templates/invalid/output/include_nonexistent_file.html1
-rw-r--r--tests/template/templates/invalid/output/unknown_tag.html1
-rw-r--r--tests/template/templates/invalid/unknown_tag.html1
-rw-r--r--tests/template/templates/parent_and_child.js1
-rw-r--r--tests/test_framework/phpbb_database_connection_odbc_pdo_wrapper.php37
-rw-r--r--tests/test_framework/phpbb_database_test_case.php35
-rw-r--r--tests/test_framework/phpbb_database_test_connection_manager.php127
-rw-r--r--tests/test_framework/phpbb_functional_test_case.php92
-rw-r--r--tests/test_framework/phpbb_test_case_helpers.php18
-rw-r--r--tests/text_processing/censor_text_test.php6
-rw-r--r--tests/upload/filespec_test.php275
-rw-r--r--tests/upload/fileupload_test.php115
-rw-r--r--tests/upload/fixture/copies/.gitkeep0
-rw-r--r--tests/upload/fixture/gifbin0 -> 35 bytes
-rw-r--r--tests/upload/fixture/jpgbin0 -> 519 bytes
-rw-r--r--tests/upload/fixture/pngbin0 -> 69 bytes
-rw-r--r--tests/upload/fixture/tifbin0 -> 256 bytes
-rw-r--r--tests/upload/fixture/txt2
-rw-r--r--tests/wrapper/phpbb_php_ini_fake.php16
-rw-r--r--tests/wrapper/phpbb_php_ini_test.php86
75 files changed, 1602 insertions, 140 deletions
diff --git a/tests/RUNNING_TESTS.txt b/tests/RUNNING_TESTS.txt
index 59197acc0f..7c2a7c3fce 100644
--- a/tests/RUNNING_TESTS.txt
+++ b/tests/RUNNING_TESTS.txt
@@ -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,26 +37,56 @@ 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
+Special Database Cases
+----------------------
+In order to run tests on some of the databases that we support, it will be
+necessary to provide a custom DSN string in test_config.php. This is only
+needed for MSSQL 2000+ (PHP module), MSSQL via ODBC, and Firebird when
+PDO_Firebird does not work on your system
+(https://bugs.php.net/bug.php?id=61183). The variable must be named $custom_dsn.
+
+Examples:
+Firebird using http://www.firebirdsql.org/en/odbc-driver/
+$custom_dsn = "Driver={Firebird/InterBase(r) driver};dbname=$dbhost:$dbname";
+
+MSSQL
+$custom_dsn = "Driver={SQL Server Native Client 10.0};Server=$dbhost;Database=$dbname";
+
+The other fields in test_config.php should be filled out as you would normally
+to connect to that database in phpBB.
+
+Additionally, you will need to be running the DbUnit fork from
+https://github.com/phpbb/dbunit/tree/phpbb.
+
Running
=======
-Once the prerequisites are installed, run the tests from the project root directory (above phpBB):
+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:
+enable slow tests by copying the phpunit.xml.all file to phpunit.xml. If you
+only want the slow tests, run:
$ phpunit --group slow
@@ -63,4 +94,4 @@ 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/bbcode/url_bbcode_test.php b/tests/bbcode/url_bbcode_test.php
index b944b6135d..d5df386714 100644
--- a/tests/bbcode/url_bbcode_test.php
+++ b/tests/bbcode/url_bbcode_test.php
@@ -11,8 +11,6 @@ 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';
-require_once dirname(__FILE__) . '/../mock/request.php';
class phpbb_url_bbcode_test extends phpbb_test_case
{
diff --git a/tests/bootstrap.php b/tests/bootstrap.php
index f103d8f15a..1017e0c72f 100644
--- a/tests/bootstrap.php
+++ b/tests/bootstrap.php
@@ -16,6 +16,8 @@ $table_prefix = 'phpbb_';
require_once $phpbb_root_path . 'includes/constants.php';
require_once $phpbb_root_path . 'includes/class_loader.' . $phpEx;
+$phpbb_class_loader_mock = new phpbb_class_loader('phpbb_mock_', $phpbb_root_path . '../tests/mock/', ".php");
+$phpbb_class_loader_mock->register();
$phpbb_class_loader_ext = new phpbb_class_loader('phpbb_ext_', $phpbb_root_path . 'ext/', ".php");
$phpbb_class_loader_ext->register();
$phpbb_class_loader = new phpbb_class_loader('phpbb_', $phpbb_root_path . 'includes/', ".php");
diff --git a/tests/class_loader/class_loader_test.php b/tests/class_loader/class_loader_test.php
index 80f0b38095..76af4dde37 100644
--- a/tests/class_loader/class_loader_test.php
+++ b/tests/class_loader/class_loader_test.php
@@ -7,8 +7,6 @@
*
*/
-require_once dirname(__FILE__) . '/../mock/cache.php';
-
class phpbb_class_loader_test extends PHPUnit_Framework_TestCase
{
public function setUp()
diff --git a/tests/config/db_test.php b/tests/config/db_test.php
index a9a53541a5..0b8f73d53a 100644
--- a/tests/config/db_test.php
+++ b/tests/config/db_test.php
@@ -7,8 +7,6 @@
*
*/
-require_once dirname(__FILE__) . '/../mock/cache.php';
-
class phpbb_config_db_test extends phpbb_database_test_case
{
private $cache;
diff --git a/tests/cron/manager_test.php b/tests/cron/manager_test.php
index 8ed33b06e2..3c541be2a6 100644
--- a/tests/cron/manager_test.php
+++ b/tests/cron/manager_test.php
@@ -7,7 +7,6 @@
*
*/
-require_once dirname(__FILE__) . '/../mock/extension_manager.php';
require_once dirname(__FILE__) . '/includes/cron/task/core/dummy_task.php';
require_once dirname(__FILE__) . '/includes/cron/task/core/second_dummy_task.php';
require_once dirname(__FILE__) . '/ext/testext/cron/dummy_task.php';
diff --git a/tests/cron/task_provider_test.php b/tests/cron/task_provider_test.php
index 4458d811a5..ec853bb3ba 100644
--- a/tests/cron/task_provider_test.php
+++ b/tests/cron/task_provider_test.php
@@ -7,10 +7,6 @@
*
*/
-require_once dirname(__FILE__) . '/includes/cron/task/core/dummy_task.php';
-require_once dirname(__FILE__) . '/includes/cron/task/core/second_dummy_task.php';
-require_once dirname(__FILE__) . '/ext/testext/cron/dummy_task.php';
-
class phpbb_cron_task_provider_test extends PHPUnit_Framework_TestCase
{
public function setUp()
diff --git a/tests/datetime/from_format_test.php b/tests/datetime/from_format_test.php
new file mode 100644
index 0000000000..c28925272e
--- /dev/null
+++ b/tests/datetime/from_format_test.php
@@ -0,0 +1,57 @@
+<?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/session.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/user.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/datetime.php';
+require_once dirname(__FILE__) . '/../mock/lang.php';
+
+class phpbb_datetime_from_format_test extends phpbb_test_case
+{
+ public function from_format_data()
+ {
+ return array(
+ array(
+ 'UTC',
+ 'Y-m-d',
+ '2012-06-08',
+ ),
+
+ array(
+ 'Europe/Berlin',
+ 'Y-m-d H:i:s',
+ '2012-06-08 14:01:02',
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider from_format_data()
+ */
+ public function test_from_format($timezone, $format, $expected)
+ {
+ global $user;
+
+ $user = new phpbb_user();
+ $user->timezone = new DateTimeZone($timezone);
+ $user->lang['datetime'] = array(
+ 'TODAY' => 'Today',
+ 'TOMORROW' => 'Tomorrow',
+ 'YESTERDAY' => 'Yesterday',
+ 'AGO' => array(
+ 0 => 'less than a minute ago',
+ 1 => '%d minute ago',
+ 2 => '%d minutes ago',
+ ),
+ );
+
+ $timestamp = $user->get_timestamp_from_format($format, $expected, new DateTimeZone($timezone));
+ $this->assertEquals($expected, $user->format_date($timestamp, $format, true));
+ }
+}
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/case_test.php b/tests/dbal/case_test.php
new file mode 100644
index 0000000000..57a1729a39
--- /dev/null
+++ b/tests/dbal/case_test.php
@@ -0,0 +1,69 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2012 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+class phpbb_dbal_case_test extends phpbb_database_test_case
+{
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/config.xml');
+ }
+
+ public function test_case_int()
+ {
+ $db = $this->new_dbal();
+
+ $sql = 'SELECT ' . $db->sql_case('1 = 1', '1', '2') . ' AS test_num
+ FROM phpbb_config';
+ $result = $db->sql_query_limit($sql, 1);
+
+ $this->assertEquals(1, (int) $db->sql_fetchfield('test_num'));
+
+ $sql = 'SELECT ' . $db->sql_case('1 = 0', '1', '2') . ' AS test_num
+ FROM phpbb_config';
+ $result = $db->sql_query_limit($sql, 1);
+
+ $this->assertEquals(2, (int) $db->sql_fetchfield('test_num'));
+ }
+
+ public function test_case_string()
+ {
+ $db = $this->new_dbal();
+
+ $sql = 'SELECT ' . $db->sql_case('1 = 1', "'foo'", "'bar'") . ' AS test_string
+ FROM phpbb_config';
+ $result = $db->sql_query_limit($sql, 1);
+
+ $this->assertEquals('foo', $db->sql_fetchfield('test_string'));
+
+ $sql = 'SELECT ' . $db->sql_case('1 = 0', "'foo'", "'bar'") . ' AS test_string
+ FROM phpbb_config';
+ $result = $db->sql_query_limit($sql, 1);
+
+ $this->assertEquals('bar', $db->sql_fetchfield('test_string'));
+ }
+
+ public function test_case_column()
+ {
+ $db = $this->new_dbal();
+
+ $sql = 'SELECT ' . $db->sql_case("config_name = 'config1'", 'config_name', 'config_value') . " AS test_string
+ FROM phpbb_config
+ WHERE config_name = 'config1'";
+ $result = $db->sql_query_limit($sql, 1);
+
+ $this->assertEquals('config1', $db->sql_fetchfield('test_string'));
+
+ $sql = 'SELECT ' . $db->sql_case("config_name = 'config1'", 'config_name', 'config_value') . " AS test_string
+ FROM phpbb_config
+ WHERE config_value = 'bar'";
+ $result = $db->sql_query_limit($sql, 1);
+
+ $this->assertEquals('bar', $db->sql_fetchfield('test_string'));
+ }
+}
diff --git a/tests/dbal/concatenate_test.php b/tests/dbal/concatenate_test.php
new file mode 100644
index 0000000000..0891fa58a0
--- /dev/null
+++ b/tests/dbal/concatenate_test.php
@@ -0,0 +1,64 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2012 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+class phpbb_dbal_concatenate_test extends phpbb_database_test_case
+{
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/config.xml');
+ }
+
+ public function test_concatenate_string()
+ {
+ $db = $this->new_dbal();
+
+ $sql = 'SELECT config_name, ' . $db->sql_concatenate('config_name', "'" . $db->sql_escape('append') . "'") . ' AS string
+ FROM phpbb_config';
+ $result = $db->sql_query($sql);
+
+ $db->sql_return_on_error(false);
+
+ $this->assertEquals(array(
+ array(
+ 'config_name' => 'config1',
+ 'string' => 'config1append',
+ ),
+ array(
+ 'config_name' => 'config2',
+ 'string' => 'config2append',
+ ),
+ ),
+ $db->sql_fetchrowset($result)
+ );
+ }
+
+ public function test_concatenate_statement()
+ {
+ $db = $this->new_dbal();
+
+ $sql = 'SELECT config_name, ' . $db->sql_concatenate('config_name', 'config_value') . ' AS string
+ FROM phpbb_config';
+ $result = $db->sql_query($sql);
+
+ $db->sql_return_on_error(false);
+
+ $this->assertEquals(array(
+ array(
+ 'config_name' => 'config1',
+ 'string' => 'config1foo',
+ ),
+ array(
+ 'config_name' => 'config2',
+ 'string' => 'config2bar',
+ ),
+ ),
+ $db->sql_fetchrowset($result)
+ );
+ }
+}
diff --git a/tests/dbal/db_tools_test.php b/tests/dbal/db_tools_test.php
index fbde636b58..c20e46011f 100644
--- a/tests/dbal/db_tools_test.php
+++ b/tests/dbal/db_tools_test.php
@@ -106,7 +106,7 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case
'c_bool' => 0,
'c_vchar' => '',
'c_vchar_size' => '',
- 'c_char_size' => '',
+ 'c_char_size' => 'abcd',
'c_xstext' => '',
'c_stext' => '',
'c_text' => '',
@@ -165,6 +165,11 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case
*/
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;
@@ -189,51 +194,6 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case
$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_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,
- 'c_vchar' => '1', // these values are necessary to avoid unique index issues
- 'c_vchar_size' => '1',
- ));
- $row2 = array_merge(self::get_default_values(), array(
- 'c_uint' => 2,
- 'c_vchar' => '2',
- 'c_vchar_size' => '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);
- }
-
public function test_list_columns()
{
$this->assertEquals(
@@ -354,9 +314,20 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case
$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/order_lower_test.php b/tests/dbal/order_lower_test.php
index e16c0c20ee..84d454742f 100644
--- a/tests/dbal/order_lower_test.php
+++ b/tests/dbal/order_lower_test.php
@@ -14,7 +14,7 @@ class phpbb_dbal_order_lower_test extends phpbb_database_test_case
return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/styles.xml');
}
- public function test_cross_join()
+ public function test_order_lower()
{
$db = $this->new_dbal();
diff --git a/tests/dbal/select_test.php b/tests/dbal/select_test.php
index cc213f09bc..bd524100a2 100644
--- a/tests/dbal/select_test.php
+++ b/tests/dbal/select_test.php
@@ -125,7 +125,33 @@ class phpbb_dbal_select_test extends phpbb_database_test_case
$this->assertEquals($expected, $ary);
}
- public function query_limit_data()
+ 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(
array(0, 0, array(array('username_clean' => 'barfoo'),
@@ -349,7 +375,9 @@ class phpbb_dbal_select_test extends phpbb_database_test_case
{
$db = $this->new_dbal();
- $sql = 'SELECT * FROM (SELECT 1) AS TBL WHERE 1 = 0';
+ $sql = 'SELECT user_id
+ FROM phpbb_users
+ WHERE 1 = 0';
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
diff --git a/tests/download/http_byte_range_test.php b/tests/download/http_byte_range_test.php
index b93c1b630c..23b9169fe3 100644
--- a/tests/download/http_byte_range_test.php
+++ b/tests/download/http_byte_range_test.php
@@ -8,7 +8,6 @@
*/
require_once dirname(__FILE__) . '/../../phpBB/includes/functions_download.php';
-require_once dirname(__FILE__) . '/../mock/request.php';
class phpbb_download_http_byte_range_test extends phpbb_test_case
{
diff --git a/tests/extension/finder_test.php b/tests/extension/finder_test.php
index f7e9bd57bb..622f404786 100644
--- a/tests/extension/finder_test.php
+++ b/tests/extension/finder_test.php
@@ -7,9 +7,6 @@
*
*/
-require_once dirname(__FILE__) . '/../mock/cache.php';
-require_once dirname(__FILE__) . '/../mock/extension_manager.php';
-
class phpbb_extension_finder_test extends phpbb_test_case
{
protected $extension_manager;
diff --git a/tests/extension/manager_test.php b/tests/extension/manager_test.php
index 0a689916c7..45bed247ae 100644
--- a/tests/extension/manager_test.php
+++ b/tests/extension/manager_test.php
@@ -7,7 +7,6 @@
*
*/
-require_once dirname(__FILE__) . '/../mock/cache.php';
require_once dirname(__FILE__) . '/ext/bar/ext.php';
require_once dirname(__FILE__) . '/ext/foo/ext.php';
require_once dirname(__FILE__) . '/ext/vendor/moo/ext.php';
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
index 723cf93232..26c18c4c1f 100644
--- a/tests/functional/browse_test.php
+++ b/tests/functional/browse_test.php
@@ -23,4 +23,10 @@ class phpbb_functional_browse_test extends phpbb_functional_test_case
$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/extension_controller_test.php b/tests/functional/extension_controller_test.php
index 4ee0e68718..e9409d9d3f 100644
--- a/tests/functional/extension_controller_test.php
+++ b/tests/functional/extension_controller_test.php
@@ -65,15 +65,6 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c
}
}
- public static function tearDownAfterClass()
- {
- $phpbb_root_path = self::$config['phpbb_functional_path'];
-
- // @todo delete the fixtures from the $phpbb_root_path board
- // Note that it might be best to find a public domain function
- // and port it into here instead of writing it from scratch
- }
-
public function setUp()
{
parent::setUp();
diff --git a/tests/functional/fileupload_form_test.php b/tests/functional/fileupload_form_test.php
new file mode 100644
index 0000000000..f7267fa659
--- /dev/null
+++ b/tests/functional/fileupload_form_test.php
@@ -0,0 +1,69 @@
+<?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_fileupload_form_test extends phpbb_functional_test_case
+{
+ private $path;
+
+ public function setUp()
+ {
+ parent::setUp();
+ $this->path = __DIR__ . '/fixtures/files/';
+ $this->add_lang('posting');
+ $this->login();
+ }
+
+ private function upload_file($filename, $mimetype)
+ {
+ $file = array(
+ 'tmp_name' => $this->path . $filename,
+ 'name' => $filename,
+ 'type' => $mimetype,
+ 'size' => filesize($this->path . $filename),
+ 'error' => UPLOAD_ERR_OK,
+ );
+
+ $crawler = $this->client->request(
+ 'POST',
+ 'posting.php?mode=reply&f=2&t=1&sid=' . $this->sid,
+ array('add_file' => $this->lang('ADD_FILE')),
+ array('fileupload' => $file)
+ );
+
+ return $crawler;
+ }
+
+ public function test_empty_file()
+ {
+ $crawler = $this->upload_file('empty.png', 'image/png');
+ $this->assertEquals($this->lang('ATTACHED_IMAGE_NOT_IMAGE'), $crawler->filter('div#message p')->text());
+ }
+
+ public function test_invalid_extension()
+ {
+ $crawler = $this->upload_file('illegal-extension.bif', 'application/octet-stream');
+ $this->assertEquals($this->lang('DISALLOWED_EXTENSION', 'bif'), $crawler->filter('p.error')->text());
+ }
+
+ public function test_too_large()
+ {
+ $this->markTestIncomplete('Functional tests use an admin account which ignores maximum upload size.');
+ $crawler = $this->upload_file('too-large.png', 'image/png');
+ $this->assertEquals($this->lang('WRONG_FILESIZE', '256', 'KiB'), $crawler->filter('p.error')->text());
+ }
+
+ public function test_valid_file()
+ {
+ $crawler = $this->upload_file('valid.jpg', 'image/jpeg');
+ $this->assertContains($this->lang('POSTED_ATTACHMENTS'), $crawler->filter('#postform h3')->eq(1)->text());
+ }
+}
diff --git a/tests/functional/fileupload_remote_test.php b/tests/functional/fileupload_remote_test.php
new file mode 100644
index 0000000000..0deb79acf6
--- /dev/null
+++ b/tests/functional/fileupload_remote_test.php
@@ -0,0 +1,72 @@
+<?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_fileupload_remote_test extends phpbb_functional_test_case
+{
+ public function setUp()
+ {
+ parent::setUp();
+ // Only doing this within the functional framework because we need a
+ // URL
+
+ // Global $config required by unique_id
+ // Global $user required by fileupload::remote_upload
+ global $config, $user;
+
+ if (!is_array($config))
+ {
+ $config = array();
+ }
+
+ $config['rand_seed'] = '';
+ $config['rand_seed_last_update'] = time() + 600;
+
+ $user = new phpbb_mock_user();
+ $user->lang = new phpbb_mock_lang();
+ }
+
+ public function tearDown()
+ {
+ global $config, $user;
+ $user = null;
+ $config = array();
+ }
+
+ public function test_invalid_extension()
+ {
+ $upload = new fileupload('', array('jpg'), 100);
+ $file = $upload->remote_upload('http://example.com/image.gif');
+ $this->assertEquals('URL_INVALID', $file->error[0]);
+ }
+
+ public function test_non_existant()
+ {
+ $upload = new fileupload('', array('jpg'), 100);
+ $file = $upload->remote_upload('http://example.com/image.jpg');
+ $this->assertEquals('EMPTY_REMOTE_DATA', $file->error[0]);
+ }
+
+ public function test_successful_upload()
+ {
+ $upload = new fileupload('', array('gif'), 1000);
+ $file = $upload->remote_upload($this->root_url . 'styles/prosilver/theme/images/forum_read.gif');
+ $this->assertEquals(0, sizeof($file->error));
+ $this->assertTrue(file_exists($file->filename));
+ }
+
+ public function test_too_large()
+ {
+ $upload = new fileupload('', array('gif'), 100);
+ $file = $upload->remote_upload($this->root_url . 'styles/prosilver/theme/images/forum_read.gif');
+ $this->assertEquals('WRONG_FILESIZE', $file->error[0]);
+ }
+}
diff --git a/tests/functional/fixtures/files/empty.png b/tests/functional/fixtures/files/empty.png
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/functional/fixtures/files/empty.png
diff --git a/tests/functional/fixtures/files/illegal-extension.bif b/tests/functional/fixtures/files/illegal-extension.bif
new file mode 100644
index 0000000000..3cd5038e38
--- /dev/null
+++ b/tests/functional/fixtures/files/illegal-extension.bif
Binary files differ
diff --git a/tests/functional/fixtures/files/too-large.png b/tests/functional/fixtures/files/too-large.png
new file mode 100644
index 0000000000..ed4b0abd80
--- /dev/null
+++ b/tests/functional/fixtures/files/too-large.png
Binary files differ
diff --git a/tests/functional/fixtures/files/valid.jpg b/tests/functional/fixtures/files/valid.jpg
new file mode 100644
index 0000000000..95a87ddbdf
--- /dev/null
+++ b/tests/functional/fixtures/files/valid.jpg
Binary files differ
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/functions_acp/build_cfg_template_test.php b/tests/functions_acp/build_cfg_template_test.php
index bb479ffac9..12121f6678 100644
--- a/tests/functions_acp/build_cfg_template_test.php
+++ b/tests/functions_acp/build_cfg_template_test.php
@@ -7,7 +7,6 @@
*
*/
-require_once dirname(__FILE__) . '/../mock/lang.php';
require_once dirname(__FILE__) . '/../../phpBB/includes/functions_acp.php';
class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case
diff --git a/tests/functions_acp/build_select_test.php b/tests/functions_acp/build_select_test.php
index 782acae1fa..aca49b7655 100644
--- a/tests/functions_acp/build_select_test.php
+++ b/tests/functions_acp/build_select_test.php
@@ -7,7 +7,6 @@
*
*/
-require_once dirname(__FILE__) . '/../mock/lang.php';
require_once dirname(__FILE__) . '/../../phpBB/includes/functions_acp.php';
class phpbb_functions_acp_built_select_test extends phpbb_test_case
diff --git a/tests/functions_acp/h_radio_test.php b/tests/functions_acp/h_radio_test.php
index 02b2444a9e..a61f2e8975 100644
--- a/tests/functions_acp/h_radio_test.php
+++ b/tests/functions_acp/h_radio_test.php
@@ -7,7 +7,6 @@
*
*/
-require_once dirname(__FILE__) . '/../mock/lang.php';
require_once dirname(__FILE__) . '/../../phpBB/includes/functions_acp.php';
class phpbb_functions_acp_h_radio_test extends phpbb_test_case
diff --git a/tests/functions_acp/validate_config_vars_test.php b/tests/functions_acp/validate_config_vars_test.php
index 55441561a6..7cd7fa3892 100644
--- a/tests/functions_acp/validate_config_vars_test.php
+++ b/tests/functions_acp/validate_config_vars_test.php
@@ -7,7 +7,6 @@
*
*/
-require_once dirname(__FILE__) . '/../mock/lang.php';
require_once dirname(__FILE__) . '/../../phpBB/includes/functions_acp.php';
class phpbb_functions_acp_validate_config_vars_test extends phpbb_test_case
diff --git a/tests/functions_acp/validate_range_test.php b/tests/functions_acp/validate_range_test.php
index 34ce848e76..8606158251 100644
--- a/tests/functions_acp/validate_range_test.php
+++ b/tests/functions_acp/validate_range_test.php
@@ -7,7 +7,6 @@
*
*/
-require_once dirname(__FILE__) . '/../mock/lang.php';
require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php';
require_once dirname(__FILE__) . '/../../phpBB/includes/functions_acp.php';
diff --git a/tests/mock/filespec.php b/tests/mock/filespec.php
new file mode 100644
index 0000000000..9d2a5c84de
--- /dev/null
+++ b/tests/mock/filespec.php
@@ -0,0 +1,32 @@
+<?php
+/**
+ *
+ * @package testing
+ * @copyright (c) 2012 phpBB Group
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+ *
+ */
+
+/**
+ * Mock filespec class with some basic values to help with testing the
+ * fileupload class
+ */
+class phpbb_mock_filespec
+{
+ public $filesize;
+ public $realname;
+ public $extension;
+ public $width;
+ public $height;
+ public $error = array();
+
+ public function check_content($disallowed_content)
+ {
+ return true;
+ }
+
+ public function get($property)
+ {
+ return $this->$property;
+ }
+}
diff --git a/tests/mock/fileupload.php b/tests/mock/fileupload.php
new file mode 100644
index 0000000000..409036ba63
--- /dev/null
+++ b/tests/mock/fileupload.php
@@ -0,0 +1,52 @@
+<?php
+/**
+ *
+ * @package testing
+ * @copyright (c) 2012 phpBB Group
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+ *
+ */
+
+/**
+ * Mock fileupload class with some basic values to help with testing the
+ * filespec class
+ */
+class phpbb_mock_fileupload
+{
+ public $max_filesize = 100;
+ public $error_prefix = '';
+
+ public function valid_dimensions($filespec)
+ {
+ return true;
+ }
+
+ /**
+ * Copied verbatim from phpBB/includes/functions_upload.php's fileupload
+ * class to ensure the correct behaviour of filespec::move_file.
+ *
+ * Maps file extensions to the constant in second index of the array
+ * returned by getimagesize()
+ */
+ public function image_types()
+ {
+ return array(
+ IMAGETYPE_GIF => array('gif'),
+ IMAGETYPE_JPEG => array('jpg', 'jpeg'),
+ IMAGETYPE_PNG => array('png'),
+ IMAGETYPE_SWF => array('swf'),
+ IMAGETYPE_PSD => array('psd'),
+ IMAGETYPE_BMP => array('bmp'),
+ IMAGETYPE_TIFF_II => array('tif', 'tiff'),
+ IMAGETYPE_TIFF_MM => array('tif', 'tiff'),
+ IMAGETYPE_JPC => array('jpg', 'jpeg'),
+ IMAGETYPE_JP2 => array('jpg', 'jpeg'),
+ IMAGETYPE_JPX => array('jpg', 'jpeg'),
+ IMAGETYPE_JB2 => array('jpg', 'jpeg'),
+ IMAGETYPE_SWC => array('swc'),
+ IMAGETYPE_IFF => array('iff'),
+ IMAGETYPE_WBMP => array('wbmp'),
+ IMAGETYPE_XBM => array('xbm'),
+ );
+ }
+}
diff --git a/tests/mock_user.php b/tests/mock/user.php
index ec14ce430e..ec14ce430e 100644
--- a/tests/mock_user.php
+++ b/tests/mock/user.php
diff --git a/tests/regex/email_test.php b/tests/regex/email_test.php
index 17f93259c3..b4ea5b23aa 100644
--- a/tests/regex/email_test.php
+++ b/tests/regex/email_test.php
@@ -28,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
@@ -96,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/security/base.php b/tests/security/base.php
index 82e4dda9d0..08878ad60d 100644
--- a/tests/security/base.php
+++ b/tests/security/base.php
@@ -7,8 +7,6 @@
*
*/
-require_once dirname(__FILE__) . '/../mock/request.php';
-
abstract class phpbb_security_test_base extends phpbb_test_case
{
/**
diff --git a/tests/session/continue_test.php b/tests/session/continue_test.php
index c4f7f8d75b..ad78d92299 100644
--- a/tests/session/continue_test.php
+++ b/tests/session/continue_test.php
@@ -7,7 +7,6 @@
*
*/
-require_once dirname(__FILE__) . '/../mock/cache.php';
require_once dirname(__FILE__) . '/testable_factory.php';
class phpbb_session_continue_test extends phpbb_database_test_case
diff --git a/tests/session/init_test.php b/tests/session/init_test.php
index 2ce6c4a4ac..830de34ed0 100644
--- a/tests/session/init_test.php
+++ b/tests/session/init_test.php
@@ -7,7 +7,6 @@
*
*/
-require_once dirname(__FILE__) . '/../mock/cache.php';
require_once dirname(__FILE__) . '/testable_factory.php';
class phpbb_session_init_test extends phpbb_database_test_case
diff --git a/tests/session/testable_factory.php b/tests/session/testable_factory.php
index a042085908..cb85a01c5c 100644
--- a/tests/session/testable_factory.php
+++ b/tests/session/testable_factory.php
@@ -7,9 +7,6 @@
*
*/
-require_once dirname(__FILE__) . '/../mock/request.php';
-require_once dirname(__FILE__) . '/../mock/session_testable.php';
-
/**
* This class exists to setup an instance of phpbb's session class for testing.
*
diff --git a/tests/template/invalid_constructs_test.php b/tests/template/invalid_constructs_test.php
new file mode 100644
index 0000000000..19d192b8b6
--- /dev/null
+++ b/tests/template/invalid_constructs_test.php
@@ -0,0 +1,87 @@
+<?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__) . '/template_test_case.php';
+
+class phpbb_template_invalid_constructs_test extends phpbb_template_template_test_case
+{
+ public function template_data()
+ {
+ return array(
+ array(
+ 'Unknown tag',
+ 'invalid/unknown_tag.html',
+ array(),
+ array(),
+ array(),
+ 'invalid/output/unknown_tag.html',
+ ),
+ /*
+ * Produces a parse error which is fatal, therefore
+ * destroying the test suite.
+ array(
+ 'ENDIF without IF',
+ 'invalid/endif_without_if.html',
+ array(),
+ array(),
+ array(),
+ 'invalid/output/endif_without_if.html',
+ ),
+ */
+ );
+ }
+
+ public function template_data_error()
+ {
+ return array(
+ array(
+ 'Include a nonexistent file',
+ 'invalid/include_nonexistent_file.html',
+ array(),
+ array(),
+ array(),
+ E_USER_ERROR,
+ 'invalid/output/include_nonexistent_file.html',
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider template_data
+ */
+ public function test_template($description, $file, $vars, $block_vars, $destroy, $expected)
+ {
+ $cache_file = $this->template->cachepath . str_replace('/', '.', $file) . '.php';
+
+ $this->assertFileNotExists($cache_file);
+
+ $expected = file_get_contents(dirname(__FILE__) . '/templates/' . $expected);
+ // apparently the template engine does not put
+ // the trailing newline into compiled templates
+ $expected = trim($expected);
+ $this->run_template($file, $vars, $block_vars, $destroy, $expected, $cache_file);
+ }
+
+ /**
+ * @dataProvider template_data_error
+ */
+ public function test_template_error($description, $file, $vars, $block_vars, $destroy, $error, $expected)
+ {
+ $cache_file = $this->template->cachepath . str_replace('/', '.', $file) . '.php';
+
+ $this->assertFileNotExists($cache_file);
+
+ $expected = file_get_contents(dirname(__FILE__) . '/templates/' . $expected);
+ // apparently the template engine does not put
+ // the trailing newline into compiled templates
+ $expected = trim($expected);
+ $this->setExpectedTriggerError($error, $expected);
+ $this->run_template($file, $vars, $block_vars, $destroy, '', $cache_file);
+ }
+}
diff --git a/tests/template/parent_templates/parent_and_child.js b/tests/template/parent_templates/parent_and_child.js
new file mode 100644
index 0000000000..6d9bb163bf
--- /dev/null
+++ b/tests/template/parent_templates/parent_and_child.js
@@ -0,0 +1 @@
+// JavaScript file in a parent style.
diff --git a/tests/template/parent_templates/parent_only.js b/tests/template/parent_templates/parent_only.js
new file mode 100644
index 0000000000..9c3007d83f
--- /dev/null
+++ b/tests/template/parent_templates/parent_only.js
@@ -0,0 +1 @@
+// JavaScript file only in parent style.
diff --git a/tests/template/renderer_eval_test.php b/tests/template/renderer_eval_test.php
index 9b4f74c824..7ebb8b9bda 100644
--- a/tests/template/renderer_eval_test.php
+++ b/tests/template/renderer_eval_test.php
@@ -13,8 +13,8 @@ class phpbb_template_renderer_eval_test extends phpbb_test_case
{
$compiled_code = '<a href="<?php echo \'Test\'; ?>">';
$valid_code = '<a href="Test">';
- $context = new phpbb_style_template_context();
- $template = new phpbb_style_template_renderer_eval($compiled_code, NULL);
+ $context = new phpbb_template_context();
+ $template = new phpbb_template_renderer_eval($compiled_code, NULL);
ob_start();
try
{
diff --git a/tests/template/template_compile_test.php b/tests/template/template_compile_test.php
index e2264fb1b7..0cfcd6ceb5 100644
--- a/tests/template/template_compile_test.php
+++ b/tests/template/template_compile_test.php
@@ -16,7 +16,7 @@ class phpbb_template_template_compile_test extends phpbb_test_case
protected function setUp()
{
- $this->template_compile = new phpbb_style_template_compile(false, null, '');
+ $this->template_compile = new phpbb_template_compile(false, null, '');
$this->template_path = dirname(__FILE__) . '/templates';
}
diff --git a/tests/template/template_includejs_test.php b/tests/template/template_includejs_test.php
index fa23837553..a8f9a9037f 100644
--- a/tests/template/template_includejs_test.php
+++ b/tests/template/template_includejs_test.php
@@ -14,18 +14,17 @@ class phpbb_template_template_includejs_test extends phpbb_template_template_tes
public function test_includejs_compilation()
{
// Reset the engine state
- $this->setup_engine();
+ $this->setup_engine(array('assets_version' => 1));
// Prepare correct result
- $dir = dirname(__FILE__);
$scripts = array(
- '<script src="' . $dir . '/templates/parent_and_child.html"></script>',
- '<script src="' . $dir . '/parent_templates/parent_only.html"></script>',
- '<script src="' . $dir . '/templates/child_only.html"></script>'
+ '<script src="' . $this->test_path . '/templates/parent_and_child.js?assets_version=1"></script>',
+ '<script src="' . $this->test_path . '/parent_templates/parent_only.js?assets_version=1"></script>',
+ '<script src="' . $this->test_path . '/templates/child_only.js?assets_version=1"></script>'
);
// Run test
$cache_file = $this->template->cachepath . 'includejs.html.php';
- $this->run_template('includejs.html', array('PARENT' => 'parent_only.html'), array(), array(), implode('', $scripts), $cache_file);
+ $this->run_template('includejs.html', array('PARENT' => 'parent_only.js'), array(), array(), implode('', $scripts), $cache_file);
}
}
diff --git a/tests/template/template_locate_test.php b/tests/template/template_locate_test.php
index d6e2e82a47..be9ae06809 100644
--- a/tests/template/template_locate_test.php
+++ b/tests/template/template_locate_test.php
@@ -17,21 +17,21 @@ class phpbb_template_template_locate_test extends phpbb_template_template_test_c
// First element of the array is test name - keep them distinct
array(
'simple inheritance - only parent template exists',
- dirname(__FILE__) . '/parent_templates/parent_only.html',
+ $this->test_path . '/parent_templates/parent_only.html',
'parent_only.html',
false,
true,
),
array(
'simple inheritance - only child template exists',
- dirname(__FILE__) . '/templates/child_only.html',
+ $this->test_path . '/templates/child_only.html',
'child_only.html',
false,
true,
),
array(
'simple inheritance - both parent and child templates exist',
- dirname(__FILE__) . '/templates/parent_and_child.html',
+ $this->test_path . '/templates/parent_and_child.html',
'parent_and_child.html',
false,
true,
diff --git a/tests/template/template_test.php b/tests/template/template_test.php
index 739bbe9387..f8677ed913 100644
--- a/tests/template/template_test.php
+++ b/tests/template/template_test.php
@@ -277,7 +277,7 @@ class phpbb_template_template_test extends phpbb_template_template_test_case
$this->template->set_filenames(array('test' => $filename));
$this->assertFileNotExists($this->template_path . '/' . $filename, 'Testing missing file, file cannot exist');
- $expecting = sprintf('style resource locator: File for handle test does not exist. Could not find: %s', realpath($this->template_path . '/../') . '/templates/' . $filename);
+ $expecting = sprintf('style resource locator: File for handle test does not exist. Could not find: %s', $this->test_path . '/templates/' . $filename);
$this->setExpectedTriggerError(E_USER_ERROR, $expecting);
$this->display('test');
diff --git a/tests/template/template_test_case.php b/tests/template/template_test_case.php
index a87e531a07..6f76cb049d 100644
--- a/tests/template/template_test_case.php
+++ b/tests/template/template_test_case.php
@@ -8,7 +8,6 @@
*/
require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
-require_once dirname(__FILE__) . '/../mock/extension_manager.php';
class phpbb_template_template_test_case extends phpbb_test_case
{
@@ -18,6 +17,8 @@ class phpbb_template_template_test_case extends phpbb_test_case
protected $style_resource_locator;
protected $style_provider;
+ protected $test_path = 'tests/template';
+
// Keep the contents of the cache for debugging?
const PRESERVE_CACHE = true;
@@ -63,10 +64,10 @@ class phpbb_template_template_test_case extends phpbb_test_case
$defaults = $this->config_defaults();
$config = new phpbb_config(array_merge($defaults, $new_config));
- $this->template_path = dirname(__FILE__) . '/templates';
+ $this->template_path = $this->test_path . '/templates';
$this->style_resource_locator = new phpbb_style_resource_locator();
$this->style_provider = new phpbb_style_path_provider();
- $this->template = new phpbb_style_template($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, $this->style_provider);
+ $this->template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator);
$this->style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, $this->style_provider, $this->template);
$this->style->set_custom_style('tests', $this->template_path, '');
}
diff --git a/tests/template/template_test_case_with_tree.php b/tests/template/template_test_case_with_tree.php
index e76d9436cf..05ccb7ee55 100644
--- a/tests/template/template_test_case_with_tree.php
+++ b/tests/template/template_test_case_with_tree.php
@@ -18,11 +18,11 @@ class phpbb_template_template_test_case_with_tree extends phpbb_template_templat
$defaults = $this->config_defaults();
$config = new phpbb_config(array_merge($defaults, $new_config));
- $this->template_path = dirname(__FILE__) . '/templates';
- $this->parent_template_path = dirname(__FILE__) . '/parent_templates';
+ $this->template_path = $this->test_path . '/templates';
+ $this->parent_template_path = $this->test_path . '/parent_templates';
$this->style_resource_locator = new phpbb_style_resource_locator();
$this->style_provider = new phpbb_style_path_provider();
- $this->template = new phpbb_style_template($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, $this->style_provider);
+ $this->template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator);
$this->style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, $this->style_provider, $this->template);
$this->style->set_custom_style('tests', array($this->template_path, $this->parent_template_path), '');
}
diff --git a/tests/template/templates/child_only.js b/tests/template/templates/child_only.js
new file mode 100644
index 0000000000..542b26526c
--- /dev/null
+++ b/tests/template/templates/child_only.js
@@ -0,0 +1 @@
+// JavaScript file only in a child style.
diff --git a/tests/template/templates/includejs.html b/tests/template/templates/includejs.html
index 186fc30b43..8a2587d76b 100644
--- a/tests/template/templates/includejs.html
+++ b/tests/template/templates/includejs.html
@@ -1,5 +1,5 @@
-<!-- INCLUDEJS parent_and_child.html -->
+<!-- INCLUDEJS parent_and_child.js -->
<!-- INCLUDEJS {PARENT} -->
-<!-- DEFINE $TEST = 'child_only.html' -->
+<!-- DEFINE $TEST = 'child_only.js' -->
<!-- INCLUDEJS {$TEST} -->
{SCRIPTS} \ No newline at end of file
diff --git a/tests/template/templates/invalid/endif_without_if.html b/tests/template/templates/invalid/endif_without_if.html
new file mode 100644
index 0000000000..e371ffd150
--- /dev/null
+++ b/tests/template/templates/invalid/endif_without_if.html
@@ -0,0 +1 @@
+<!-- ENDIF -->
diff --git a/tests/template/templates/invalid/include_nonexistent_file.html b/tests/template/templates/invalid/include_nonexistent_file.html
new file mode 100644
index 0000000000..617d2fdaaa
--- /dev/null
+++ b/tests/template/templates/invalid/include_nonexistent_file.html
@@ -0,0 +1 @@
+<!-- INCLUDE nonexistent.html -->
diff --git a/tests/template/templates/invalid/output/endif_without_if.html b/tests/template/templates/invalid/output/endif_without_if.html
new file mode 100644
index 0000000000..5f2239c964
--- /dev/null
+++ b/tests/template/templates/invalid/output/endif_without_if.html
@@ -0,0 +1 @@
+Parse error (fatal, destroys php runtime).
diff --git a/tests/template/templates/invalid/output/include_nonexistent_file.html b/tests/template/templates/invalid/output/include_nonexistent_file.html
new file mode 100644
index 0000000000..8a118d2713
--- /dev/null
+++ b/tests/template/templates/invalid/output/include_nonexistent_file.html
@@ -0,0 +1 @@
+style resource locator: File for handle nonexistent.html does not exist. Could not find:
diff --git a/tests/template/templates/invalid/output/unknown_tag.html b/tests/template/templates/invalid/output/unknown_tag.html
new file mode 100644
index 0000000000..1489e5e31a
--- /dev/null
+++ b/tests/template/templates/invalid/output/unknown_tag.html
@@ -0,0 +1 @@
+<!-- UNKNOWNTAG variable.html -->
diff --git a/tests/template/templates/invalid/unknown_tag.html b/tests/template/templates/invalid/unknown_tag.html
new file mode 100644
index 0000000000..1489e5e31a
--- /dev/null
+++ b/tests/template/templates/invalid/unknown_tag.html
@@ -0,0 +1 @@
+<!-- UNKNOWNTAG variable.html -->
diff --git a/tests/template/templates/parent_and_child.js b/tests/template/templates/parent_and_child.js
new file mode 100644
index 0000000000..d544d94d83
--- /dev/null
+++ b/tests/template/templates/parent_and_child.js
@@ -0,0 +1 @@
+// JavaScript file in a child style.
diff --git a/tests/test_framework/phpbb_database_connection_odbc_pdo_wrapper.php b/tests/test_framework/phpbb_database_connection_odbc_pdo_wrapper.php
new file mode 100644
index 0000000000..ec59fa3886
--- /dev/null
+++ b/tests/test_framework/phpbb_database_connection_odbc_pdo_wrapper.php
@@ -0,0 +1,37 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2011 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+if (!class_exists('PDO'))
+{
+ return;
+}
+
+/**
+* Used for passing in information about the PDO driver
+* since the PDO class reveals nothing about the DSN that
+* the user provided.
+*
+* This is used in the custom PHPUnit ODBC driver
+*/
+class phpbb_database_connection_odbc_pdo_wrapper extends PDO
+{
+ // Name of the driver being used (i.e. mssql, firebird)
+ public $driver = '';
+
+ // Version number of driver since PDO::getAttribute(PDO::ATTR_CLIENT_VERSION) is pretty useless for this
+ public $version = 0;
+
+ function __construct($dbms, $version, $dsn, $user, $pass)
+ {
+ $this->driver = $dbms;
+ $this->version = (double) $version;
+
+ parent::__construct($dsn, $user, $pass);
+ }
+}
diff --git a/tests/test_framework/phpbb_database_test_case.php b/tests/test_framework/phpbb_database_test_case.php
index e742b543b0..bb86df0ef0 100644
--- a/tests/test_framework/phpbb_database_test_case.php
+++ b/tests/test_framework/phpbb_database_test_case.php
@@ -28,6 +28,28 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test
);
}
+ public function createXMLDataSet($path)
+ {
+ $db_config = $this->get_database_config();
+
+ // Firebird requires table and column names to be uppercase
+ if ($db_config['dbms'] == 'firebird')
+ {
+ $xml_data = file_get_contents($path);
+ $xml_data = preg_replace_callback('/(?:(<table name="))([a-z_]+)(?:(">))/', 'phpbb_database_test_case::to_upper', $xml_data);
+ $xml_data = preg_replace_callback('/(?:(<column>))([a-z_]+)(?:(<\/column>))/', 'phpbb_database_test_case::to_upper', $xml_data);
+
+ $new_fixture = tmpfile();
+ fwrite($new_fixture, $xml_data);
+ fseek($new_fixture, 0);
+
+ $meta_data = stream_get_meta_data($new_fixture);
+ $path = $meta_data['uri'];
+ }
+
+ return parent::createXMLDataSet($path);
+ }
+
public function get_test_case_helpers()
{
if (!$this->test_case_helpers)
@@ -106,4 +128,17 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test
{
return new phpbb_database_test_connection_manager($config);
}
+
+ /**
+ * Converts a match in the middle of a string to uppercase.
+ * This is necessary for transforming the fixture information for Firebird tests
+ *
+ * @param $matches The array of matches from a regular expression
+ *
+ * @return string The string with the specified match converted to uppercase
+ */
+ public static function to_upper($matches)
+ {
+ return $matches[1] . strtoupper($matches[2]) . $matches[3];
+ }
}
diff --git a/tests/test_framework/phpbb_database_test_connection_manager.php b/tests/test_framework/phpbb_database_test_connection_manager.php
index c734c90a1a..25e0972f42 100644
--- a/tests/test_framework/phpbb_database_test_connection_manager.php
+++ b/tests/test_framework/phpbb_database_test_connection_manager.php
@@ -8,6 +8,7 @@
*/
require_once dirname(__FILE__) . '/../../phpBB/includes/functions_install.php';
+require_once dirname(__FILE__) . '/phpbb_database_connection_odbc_pdo_wrapper.php';
class phpbb_database_test_connection_manager
{
@@ -62,6 +63,13 @@ class phpbb_database_test_connection_manager
// e.g. Driver={SQL Server Native Client 10.0};Server=(local)\SQLExpress;
$dsn .= $this->config['dbhost'];
+ // Primarily for MSSQL Native/Azure as ODBC needs it in $dbhost, attached to the Server param
+ if ($this->config['dbport'])
+ {
+ $port_delimiter = (defined('PHP_OS') && substr(PHP_OS, 0, 3) === 'WIN') ? ',' : ':';
+ $dsn .= $port_delimiter . $this->config['dbport'];
+ }
+
if ($use_db)
{
$dsn .= ';Database=' . $this->config['dbname'];
@@ -80,12 +88,52 @@ class phpbb_database_test_connection_manager
{
$dsn .= ';dbname=' . $this->config['dbname'];
}
+ else if ($this->dbms['PDO'] == 'pgsql')
+ {
+ // Postgres always connects to a
+ // database. If the database is not
+ // specified here, but the username
+ // is specified, then connection
+ // will be to the database named
+ // as the username.
+ //
+ // For greater compatibility, connect
+ // instead to postgres database which
+ // should always exist:
+ // http://www.postgresql.org/docs/9.0/static/manage-ag-templatedbs.html
+ $dsn .= ';dbname=postgres';
+ }
break;
}
+ // These require different connection strings on the phpBB side than they do in PDO
+ // so you must provide a DSN string for ODBC separately
+ if (!empty($this->config['custom_dsn']) && ($this->config['dbms'] == 'mssql' || $this->config['dbms'] == 'firebird'))
+ {
+ $dsn = 'odbc:' . $this->config['custom_dsn'];
+ }
+
try
{
- $this->pdo = new PDO($dsn, $this->config['dbuser'], $this->config['dbpasswd']);
+ switch ($this->config['dbms'])
+ {
+ case 'mssql':
+ case 'mssql_odbc':
+ $this->pdo = new phpbb_database_connection_odbc_pdo_wrapper('mssql', 0, $dsn, $this->config['dbuser'], $this->config['dbpasswd']);
+ break;
+
+ case 'firebird':
+ if (!empty($this->config['custom_dsn']))
+ {
+ $this->pdo = new phpbb_database_connection_odbc_pdo_wrapper('firebird', 0, $dsn, $this->config['dbuser'], $this->config['dbpasswd']);
+ break;
+ }
+ // Fall through if they're using the firebird PDO driver and not the generic ODBC driver
+
+ default:
+ $this->pdo = new PDO($dsn, $this->config['dbuser'], $this->config['dbpasswd']);
+ break;
+ }
}
catch (PDOException $e)
{
@@ -93,8 +141,7 @@ class phpbb_database_test_connection_manager
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);
+ $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
/**
@@ -125,12 +172,41 @@ class phpbb_database_test_connection_manager
}
break;
+ case 'firebird':
+ $this->connect();
+ // Drop all of the tables
+ foreach ($this->get_tables() as $table)
+ {
+ $this->pdo->exec('DROP TABLE ' . $table);
+ }
+ $this->purge_extras();
+ break;
+
+ case 'oracle':
+ $this->connect();
+ // Drop all of the tables
+ foreach ($this->get_tables() as $table)
+ {
+ $this->pdo->exec('DROP TABLE ' . $table . ' CASCADE CONSTRAINTS');
+ }
+ $this->purge_extras();
+ break;
+
default:
$this->connect(false);
try
{
$this->pdo->exec('DROP DATABASE ' . $this->config['dbname']);
+
+ try
+ {
+ $this->pdo->exec('CREATE DATABASE ' . $this->config['dbname']);
+ }
+ catch (PDOException $e)
+ {
+ throw new Exception("Unable to re-create database: {$e->getMessage()}");
+ }
}
catch (PDOException $e)
{
@@ -139,9 +215,8 @@ class phpbb_database_test_connection_manager
{
$this->pdo->exec('DROP TABLE ' . $table);
}
+ $this->purge_extras();
}
-
- $this->pdo->exec('CREATE DATABASE ' . $this->config['dbname']);
break;
}
}
@@ -243,7 +318,7 @@ class phpbb_database_test_connection_manager
$filename = $directory . $schema . '_schema.sql';
$queries = file_get_contents($filename);
- $sql = remove_comments($queries);
+ $sql = phpbb_remove_comments($queries);
$sql = split_sql_file($sql, $this->dbms['DELIM']);
@@ -317,4 +392,44 @@ class phpbb_database_test_connection_manager
throw new Exception($message);
}
}
+
+ /**
+ * Removes extra objects from a database. This is for cases where dropping the database fails.
+ */
+ public function purge_extras()
+ {
+ $this->ensure_connected(__METHOD__);
+ $queries = array();
+
+ switch ($this->config['dbms'])
+ {
+ case 'firebird':
+ $sql = 'SELECT RDB$GENERATOR_NAME
+ FROM RDB$GENERATORS
+ WHERE RDB$SYSTEM_FLAG = 0';
+ $result = $this->pdo->query($sql);
+
+ while ($row = $result->fetch(PDO::FETCH_NUM))
+ {
+ $queries[] = 'DROP GENERATOR ' . current($row);
+ }
+ break;
+
+ case 'oracle':
+ $sql = 'SELECT sequence_name
+ FROM USER_SEQUENCES';
+ $result = $this->pdo->query($sql);
+
+ while ($row = $result->fetch(PDO::FETCH_NUM))
+ {
+ $queries[] = 'DROP SEQUENCE ' . current($row);
+ }
+ break;
+ }
+
+ foreach ($queries as $query)
+ {
+ $this->pdo->exec($query);
+ }
+ }
}
diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php
index 69c62af297..c042d75811 100644
--- a/tests/test_framework/phpbb_functional_test_case.php
+++ b/tests/test_framework/phpbb_functional_test_case.php
@@ -6,6 +6,7 @@
* @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';
@@ -18,18 +19,20 @@ class phpbb_functional_test_case extends phpbb_test_case
protected $db = null;
protected $extension_manager = null;
- static protected $config = array();
- static protected $already_installed = false;
+ /**
+ * Session ID for current test's session (each test makes its own)
+ * @var string
+ */
+ protected $sid;
- static public function setUpBeforeClass()
- {
- if (!extension_loaded('phar'))
- {
- self::markTestSkipped('phar extension is not loaded');
- }
+ /**
+ * Language array used by phpBB
+ * @var array
+ */
+ protected $lang = array();
- require_once 'phar://' . __DIR__ . '/../../vendor/goutte.phar';
- }
+ static protected $config = array();
+ static protected $already_installed = false;
public function setUp()
{
@@ -38,8 +41,16 @@ class phpbb_functional_test_case extends phpbb_test_case
$this->markTestSkipped('phpbb_functional_url was not set in test_config and wasn\'t set as PHPBB_FUNCTIONAL_URL environment variable either.');
}
- $this->client = new Goutte\Client();
+ $this->cookieJar = new CookieJar;
+ $this->client = new Goutte\Client(array(), null, $this->cookieJar);
+ // Reset the curl handle because it is 0 at this point and not a valid
+ // resource
+ $this->client->getClient()->getCurlMulti()->reset(true);
$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)
@@ -219,4 +230,63 @@ class phpbb_functional_test_case extends phpbb_test_case
$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 $cookie);
+ {
+ if (substr($cookie->getName(), -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_helpers.php b/tests/test_framework/phpbb_test_case_helpers.php
index 9c91778cb0..46feef550a 100644
--- a/tests/test_framework/phpbb_test_case_helpers.php
+++ b/tests/test_framework/phpbb_test_case_helpers.php
@@ -63,9 +63,19 @@ class phpbb_test_case_helpers
));
}
- if (file_exists(dirname(__FILE__) . '/../test_config.php'))
+ if (isset($_SERVER['PHPBB_TEST_CONFIG']))
{
- include(dirname(__FILE__) . '/../test_config.php');
+ // 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,
@@ -74,6 +84,7 @@ class phpbb_test_case_helpers
'dbname' => $dbname,
'dbuser' => $dbuser,
'dbpasswd' => $dbpasswd,
+ 'custom_dsn' => isset($custom_dsn) ? $custom_dsn : '',
));
if (isset($phpbb_functional_url))
@@ -90,7 +101,8 @@ class phpbb_test_case_helpers
'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'] : ''
+ 'dbpasswd' => isset($_SERVER['PHPBB_TEST_DBPASSWD']) ? $_SERVER['PHPBB_TEST_DBPASSWD'] : '',
+ 'custom_dsn' => isset($_SERVER['PHPBB_TEST_CUSTOM_DSN']) ? $_SERVER['PHPBB_TEST_CUSTOM_DSN'] : '',
));
}
diff --git a/tests/text_processing/censor_text_test.php b/tests/text_processing/censor_text_test.php
index 8fcdb7ef85..043d8eb27d 100644
--- a/tests/text_processing/censor_text_test.php
+++ b/tests/text_processing/censor_text_test.php
@@ -9,8 +9,6 @@
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
{
@@ -19,7 +17,7 @@ class phpbb_text_processing_censor_text_test extends phpbb_test_case
global $cache, $user;
$cache = new phpbb_mock_cache;
$user = new phpbb_mock_user;
-
+
$user->optionset('viewcensors', false);
return array(
@@ -61,7 +59,7 @@ class phpbb_text_processing_censor_text_test extends phpbb_test_case
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('öäü', 'öäü'),
diff --git a/tests/upload/filespec_test.php b/tests/upload/filespec_test.php
new file mode 100644
index 0000000000..c7ff2e78e0
--- /dev/null
+++ b/tests/upload/filespec_test.php
@@ -0,0 +1,275 @@
+<?php
+/**
+ *
+ * @package testing
+ * @copyright (c) 2012 phpBB Group
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+ *
+ */
+
+require_once __DIR__ . '/../../phpBB/includes/functions.php';
+require_once __DIR__ . '/../../phpBB/includes/utf/utf_tools.php';
+require_once __DIR__ . '/../../phpBB/includes/functions_upload.php';
+
+class phpbb_filespec_test extends phpbb_test_case
+{
+ const TEST_COUNT = 100;
+ const PREFIX = 'phpbb_';
+ const MAX_STR_LEN = 50;
+ const UPLOAD_MAX_FILESIZE = 1000;
+
+ private $config;
+ public $path;
+
+ protected function setUp()
+ {
+ // Global $config required by unique_id
+ // Global $user required by filespec::additional_checks and
+ // filespec::move_file
+ global $config, $user;
+
+ if (!is_array($config))
+ {
+ $config = array();
+ }
+
+ $config['rand_seed'] = '';
+ $config['rand_seed_last_update'] = time() + 600;
+ // This config value is normally pulled from the database which is set
+ // to this value at install time.
+ // See: phpBB/install/schemas/schema_data.sql
+ $config['mime_triggers'] = 'body|head|html|img|plaintext|a href|pre|script|table|title';
+
+ $user = new phpbb_mock_user();
+ $user->lang = new phpbb_mock_lang();
+
+ $this->config = &$config;
+ $this->path = __DIR__ . '/fixture/';
+
+ // Create copies of the files for use in testing move_file
+ $iterator = new DirectoryIterator($this->path);
+ foreach ($iterator as $fileinfo)
+ {
+ if ($fileinfo->isDot() || $fileinfo->isDir())
+ {
+ continue;
+ }
+
+ copy($fileinfo->getPathname(), $this->path . 'copies/' . $fileinfo->getFilename() . '_copy');
+ if ($fileinfo->getFilename() === 'txt')
+ {
+ copy($fileinfo->getPathname(), $this->path . 'copies/' . $fileinfo->getFilename() . '_copy_2');
+ }
+ }
+ }
+
+ private function get_filespec($override = array())
+ {
+ // Initialise a blank filespec object for use with trivial methods
+ $upload_ary = array(
+ 'name' => '',
+ 'type' => '',
+ 'size' => '',
+ 'tmp_name' => '',
+ 'error' => '',
+ );
+
+ return new filespec(array_merge($upload_ary, $override), null);
+ }
+
+ protected function tearDown()
+ {
+ global $user;
+ $this->config = array();
+ $user = null;
+
+ $iterator = new DirectoryIterator($this->path . 'copies');
+ foreach ($iterator as $fileinfo)
+ {
+ $name = $fileinfo->getFilename();
+ if ($name[0] !== '.')
+ {
+ unlink($fileinfo->getPathname());
+ }
+ }
+ }
+
+ public function additional_checks_variables()
+ {
+ // False here just indicates the file is too large and fails the
+ // filespec::additional_checks method because of it. All other code
+ // paths in that method are covered elsewhere.
+ return array(
+ array('gif', true),
+ array('jpg', false),
+ array('png', true),
+ array('tif', false),
+ array('txt', false),
+ );
+ }
+
+ /**
+ * @dataProvider additional_checks_variables
+ */
+ public function test_additional_checks($filename, $expected)
+ {
+ $upload = new phpbb_mock_fileupload();
+ $filespec = $this->get_filespec();
+ $filespec->upload = $upload;
+ $filespec->file_moved = true;
+ $filespec->filesize = $filespec->get_filesize($this->path . $filename);
+
+ $this->assertEquals($expected, $filespec->additional_checks());
+ }
+
+ public function check_content_variables()
+ {
+ // False here indicates that a file is non-binary and contains
+ // disallowed content that makes IE report the mimetype incorrectly.
+ return array(
+ array('gif', true),
+ array('jpg', true),
+ array('png', true),
+ array('tif', true),
+ array('txt', false),
+ );
+ }
+
+ /**
+ * @dataProvider check_content_variables
+ */
+ public function test_check_content($filename, $expected)
+ {
+ $disallowed_content = explode('|', $this->config['mime_triggers']);
+ $filespec = $this->get_filespec(array('tmp_name' => $this->path . $filename));
+ $this->assertEquals($expected, $filespec->check_content($disallowed_content));
+ }
+
+ public function clean_filename_variables()
+ {
+ $chunks = str_split('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\'\\" /:*?<>|[];(){},#+=-_`', 8);
+ return array(
+ array($chunks[0] . $chunks[7]),
+ array($chunks[1] . $chunks[8]),
+ array($chunks[2] . $chunks[9]),
+ array($chunks[3] . $chunks[4]),
+ array($chunks[5] . $chunks[6]),
+ );
+ }
+
+ /**
+ * @dataProvider clean_filename_variables
+ */
+ public function test_clean_filename_real($filename)
+ {
+ $bad_chars = array("'", "\\", ' ', '/', ':', '*', '?', '"', '<', '>', '|');
+ $filespec = $this->get_filespec(array('name' => $filename));
+ $filespec->clean_filename('real', self::PREFIX);
+ $name = $filespec->realname;
+
+ $this->assertEquals(0, preg_match('/%(\w{2})/', $name));
+ foreach ($bad_chars as $char)
+ {
+ $this->assertFalse(strpos($name, $char));
+ }
+ }
+
+ public function test_clean_filename_unique()
+ {
+ $filenames = array();
+ for ($tests = 0; $tests < self::TEST_COUNT; $tests++)
+ {
+ $filespec = $this->get_filespec();
+ $filespec->clean_filename('unique', self::PREFIX);
+ $name = $filespec->realname;
+
+ $this->assertEquals(strlen($name), 32 + strlen(self::PREFIX));
+ $this->assertRegExp('#^[A-Za-z0-9]+$#', substr($name, strlen(self::PREFIX)));
+ $this->assertFalse(isset($filenames[$name]));
+ $filenames[$name] = true;
+ }
+ }
+
+ public function get_extension_variables()
+ {
+ return array(
+ array('file.png', 'png'),
+ array('file.phpbb.gif', 'gif'),
+ array('file..', ''),
+ array('.file..jpg.webp', 'webp'),
+ );
+ }
+
+ /**
+ * @dataProvider get_extension_variables
+ */
+ public function test_get_extension($filename, $expected)
+ {
+ $filespec = $this->get_filespec();
+ $this->assertEquals($expected, $filespec->get_extension($filename));
+ }
+
+ public function is_image_variables()
+ {
+ return array(
+ array('gif', 'image/gif', true),
+ array('jpg', 'image/jpg', true),
+ array('png', 'image/png', true),
+ array('tif', 'image/tif', true),
+ array('txt', 'text/plain', false),
+ );
+ }
+
+ /**
+ * @dataProvider is_image_variables
+ */
+ public function test_is_image($filename, $mimetype, $expected)
+ {
+ $filespec = $this->get_filespec(array('tmp_name' => $this->path . $filename, 'type' => $mimetype));
+ $this->assertEquals($expected, $filespec->is_image());
+ }
+
+ public function move_file_variables()
+ {
+ return array(
+ array('gif_copy', 'gif_moved', 'image/gif', 'gif', false, true),
+ array('non_existant', 'still_non_existant', 'text/plain', 'txt', 'GENERAL_UPLOAD_ERROR', false),
+ array('txt_copy', 'txt_as_img', 'image/jpg', 'txt', false, true),
+ array('txt_copy_2', 'txt_moved', 'text/plain', 'txt', false, true),
+ array('jpg_copy', 'jpg_moved', 'image/png', 'jpg', false, true),
+ array('png_copy', 'png_moved', 'image/png', 'jpg', 'IMAGE_FILETYPE_MISMATCH', true),
+ );
+ }
+
+ /**
+ * @dataProvider move_file_variables
+ */
+ public function test_move_file($tmp_name, $realname, $mime_type, $extension, $error, $expected)
+ {
+ // Global $phpbb_root_path and $phpEx are required by phpbb_chmod
+ global $phpbb_root_path, $phpEx;
+ $phpbb_root_path = '';
+ $phpEx = 'php';
+
+ $upload = new phpbb_mock_fileupload();
+ $upload->max_filesize = self::UPLOAD_MAX_FILESIZE;
+
+ $filespec = $this->get_filespec(array(
+ 'tmp_name' => $this->path . 'copies/' . $tmp_name,
+ 'name' => $realname,
+ 'type' => $mime_type,
+ ));
+ $filespec->extension = $extension;
+ $filespec->upload = $upload;
+ $filespec->local = true;
+
+ $this->assertEquals($expected, $filespec->move_file($this->path . 'copies'));
+ $this->assertEquals($filespec->file_moved, file_exists($this->path . 'copies/' . $realname));
+ if ($error)
+ {
+ $this->assertEquals($error, $filespec->error[0]);
+ }
+
+ $phpEx = '';
+ }
+}
diff --git a/tests/upload/fileupload_test.php b/tests/upload/fileupload_test.php
new file mode 100644
index 0000000000..076855ab56
--- /dev/null
+++ b/tests/upload/fileupload_test.php
@@ -0,0 +1,115 @@
+<?php
+/**
+ *
+ * @package testing
+ * @copyright (c) 2012 phpBB Group
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+ *
+ */
+
+require_once __DIR__ . '/../../phpBB/includes/functions.php';
+require_once __DIR__ . '/../../phpBB/includes/utf/utf_tools.php';
+require_once __DIR__ . '/../../phpBB/includes/functions_upload.php';
+
+class phpbb_fileupload_test extends phpbb_test_case
+{
+ private $path;
+
+ protected function setUp()
+ {
+ // Global $config required by unique_id
+ // Global $user required by several functions dealing with translations
+ global $config, $user;
+
+ if (!is_array($config))
+ {
+ $config = array();
+ }
+
+ $config['rand_seed'] = '';
+ $config['rand_seed_last_update'] = time() + 600;
+
+ $user = new phpbb_mock_user();
+ $user->lang = new phpbb_mock_lang();
+ $this->path = __DIR__ . '/fixture/';
+ }
+
+ private function gen_valid_filespec()
+ {
+ $filespec = new phpbb_mock_filespec();
+ $filespec->filesize = 1;
+ $filespec->extension = 'jpg';
+ $filespec->realname = 'valid';
+ $filespec->width = 2;
+ $filespec->height = 2;
+
+ return $filespec;
+ }
+
+ protected function tearDown()
+ {
+ // Clear globals
+ global $config, $user;
+ $config = array();
+ $user = null;
+ }
+
+ public function test_common_checks_invalid_extension()
+ {
+ $upload = new fileupload('', array('png'), 100);
+ $file = $this->gen_valid_filespec();
+ $upload->common_checks($file);
+ $this->assertEquals('DISALLOWED_EXTENSION', $file->error[0]);
+ }
+
+ public function test_common_checks_invalid_filename()
+ {
+ $upload = new fileupload('', array('jpg'), 100);
+ $file = $this->gen_valid_filespec();
+ $file->realname = 'invalid?';
+ $upload->common_checks($file);
+ $this->assertEquals('INVALID_FILENAME', $file->error[0]);
+ }
+
+ public function test_common_checks_too_large()
+ {
+ $upload = new fileupload('', array('jpg'), 100);
+ $file = $this->gen_valid_filespec();
+ $file->filesize = 1000;
+ $upload->common_checks($file);
+ $this->assertEquals('WRONG_FILESIZE', $file->error[0]);
+ }
+
+ public function test_common_checks_valid_file()
+ {
+ $upload = new fileupload('', array('jpg'), 1000);
+ $file = $this->gen_valid_filespec();
+ $upload->common_checks($file);
+ $this->assertEquals(0, sizeof($file->error));
+ }
+
+ public function test_local_upload()
+ {
+ $upload = new fileupload('', array('jpg'), 1000);
+
+ copy($this->path . 'jpg', $this->path . 'jpg.jpg');
+ $file = $upload->local_upload($this->path . 'jpg.jpg');
+ $this->assertEquals(0, sizeof($file->error));
+ unlink($this->path . 'jpg.jpg');
+ }
+
+ public function test_valid_dimensions()
+ {
+ $upload = new fileupload('', false, false, 1, 1, 100, 100);
+
+ $file1 = $this->gen_valid_filespec();
+ $file2 = $this->gen_valid_filespec();
+ $file2->height = 101;
+ $file3 = $this->gen_valid_filespec();
+ $file3->width = 0;
+
+ $this->assertTrue($upload->valid_dimensions($file1));
+ $this->assertFalse($upload->valid_dimensions($file2));
+ $this->assertFalse($upload->valid_dimensions($file3));
+ }
+}
diff --git a/tests/upload/fixture/copies/.gitkeep b/tests/upload/fixture/copies/.gitkeep
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/upload/fixture/copies/.gitkeep
diff --git a/tests/upload/fixture/gif b/tests/upload/fixture/gif
new file mode 100644
index 0000000000..b636f4b8df
--- /dev/null
+++ b/tests/upload/fixture/gif
Binary files differ
diff --git a/tests/upload/fixture/jpg b/tests/upload/fixture/jpg
new file mode 100644
index 0000000000..3cd5038e38
--- /dev/null
+++ b/tests/upload/fixture/jpg
Binary files differ
diff --git a/tests/upload/fixture/png b/tests/upload/fixture/png
new file mode 100644
index 0000000000..5514ad40e9
--- /dev/null
+++ b/tests/upload/fixture/png
Binary files differ
diff --git a/tests/upload/fixture/tif b/tests/upload/fixture/tif
new file mode 100644
index 0000000000..248b50f9cb
--- /dev/null
+++ b/tests/upload/fixture/tif
Binary files differ
diff --git a/tests/upload/fixture/txt b/tests/upload/fixture/txt
new file mode 100644
index 0000000000..a78c858f5c
--- /dev/null
+++ b/tests/upload/fixture/txt
@@ -0,0 +1,2 @@
+<HTML>mime trigger</HTML>
+The HTML tags should remain uppercase so that case-insensitivity can be checked.
diff --git a/tests/wrapper/phpbb_php_ini_fake.php b/tests/wrapper/phpbb_php_ini_fake.php
new file mode 100644
index 0000000000..49bc5936e5
--- /dev/null
+++ b/tests/wrapper/phpbb_php_ini_fake.php
@@ -0,0 +1,16 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2011 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+class phpbb_php_ini_fake extends phpbb_php_ini
+{
+ function get($varname)
+ {
+ return $varname;
+ }
+}
diff --git a/tests/wrapper/phpbb_php_ini_test.php b/tests/wrapper/phpbb_php_ini_test.php
new file mode 100644
index 0000000000..8e08d5c204
--- /dev/null
+++ b/tests/wrapper/phpbb_php_ini_test.php
@@ -0,0 +1,86 @@
+<?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_php_ini_fake.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
+
+class phpbb_wrapper_phpbb_php_ini_test extends phpbb_test_case
+{
+ protected $php_ini;
+
+ public function setUp()
+ {
+ $this->php_ini = new phpbb_php_ini_fake;
+ }
+
+ public function test_get_string()
+ {
+ $this->assertSame(false, $this->php_ini->get_string(false));
+ $this->assertSame('phpbb', $this->php_ini->get_string(' phpbb '));
+ }
+
+ public function test_get_bool()
+ {
+ $this->assertSame(true, $this->php_ini->get_bool('ON'));
+ $this->assertSame(true, $this->php_ini->get_bool('on'));
+ $this->assertSame(true, $this->php_ini->get_bool('1'));
+
+ $this->assertSame(false, $this->php_ini->get_bool('OFF'));
+ $this->assertSame(false, $this->php_ini->get_bool('off'));
+ $this->assertSame(false, $this->php_ini->get_bool('0'));
+ $this->assertSame(false, $this->php_ini->get_bool(''));
+ }
+
+ public function test_get_int()
+ {
+ $this->assertSame(1234, $this->php_ini->get_int('1234'));
+ $this->assertSame(-12345, $this->php_ini->get_int('-12345'));
+ $this->assertSame(false, $this->php_ini->get_int('phpBB'));
+ }
+
+ public function test_get_float()
+ {
+ $this->assertSame(1234.0, $this->php_ini->get_float('1234'));
+ $this->assertSame(-12345.0, $this->php_ini->get_float('-12345'));
+ $this->assertSame(false, $this->php_ini->get_float('phpBB'));
+ }
+
+ public function test_get_bytes_invalid()
+ {
+ $this->assertSame(false, $this->php_ini->get_bytes(false));
+ $this->assertSame(false, $this->php_ini->get_bytes('phpBB'));
+ $this->assertSame(false, $this->php_ini->get_bytes('k'));
+ $this->assertSame(false, $this->php_ini->get_bytes('-k'));
+ $this->assertSame(false, $this->php_ini->get_bytes('M'));
+ $this->assertSame(false, $this->php_ini->get_bytes('-M'));
+ }
+
+ /**
+ * @dataProvider get_bytes_data
+ */
+ public function test_get_bytes($expected, $value)
+ {
+ $actual = $this->php_ini->get_bytes($value);
+
+ $this->assertTrue(is_float($actual) || is_int($actual));
+ $this->assertEquals($expected, $actual);
+ }
+
+ static public function get_bytes_data()
+ {
+ return array(
+ array(32 * pow(2, 20), '32m'),
+ array(- 32 * pow(2, 20), '-32m'),
+ array(8 * pow(2, 30), '8G'),
+ array(- 8 * pow(2, 30), '-8G'),
+ array(1234, '1234'),
+ array(-12345, '-12345'),
+ );
+ }
+}