aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/bootstrap.php5
-rw-r--r--tests/dbal/db_tools_test.php26
-rw-r--r--tests/dbal/select_test.php18
-rw-r--r--tests/functional/browse_test.php26
-rw-r--r--tests/profile/custom_test.php2
-rw-r--r--tests/template/template_test.php12
-rw-r--r--tests/template/templates/lang.html2
-rw-r--r--tests/template/templates/loop_nested_deep_multilevel_ref.html3
-rw-r--r--tests/test_framework/phpbb_database_test_case.php42
-rw-r--r--tests/test_framework/phpbb_database_test_connection_manager.php5
-rw-r--r--tests/test_framework/phpbb_functional_test_case.php148
-rw-r--r--tests/test_framework/phpbb_test_case_helpers.php57
-rw-r--r--tests/utf/normalizer_test.php4
13 files changed, 302 insertions, 48 deletions
diff --git a/tests/bootstrap.php b/tests/bootstrap.php
index b7c3534cde..855ea1ce1f 100644
--- a/tests/bootstrap.php
+++ b/tests/bootstrap.php
@@ -39,3 +39,8 @@ 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/db_tools_test.php b/tests/dbal/db_tools_test.php
index 753cc08fc5..c0c66b5be7 100644
--- a/tests/dbal/db_tools_test.php
+++ b/tests/dbal/db_tools_test.php
@@ -234,6 +234,14 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case
$this->assertEquals($row2, $row_actual);
}
+ 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'));
@@ -258,6 +266,13 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case
$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'));
@@ -333,4 +348,15 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case
),
));
}
+
+ public function test_index_exists()
+ {
+ $this->assertTrue($this->tools->sql_index_exists('prefix_table_name', 'i_simple'));
+ }
+
+ 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'));
+ }
}
diff --git a/tests/dbal/select_test.php b/tests/dbal/select_test.php
index e0d08d9306..8ddd27465d 100644
--- a/tests/dbal/select_test.php
+++ b/tests/dbal/select_test.php
@@ -319,7 +319,7 @@ class phpbb_dbal_select_test extends phpbb_database_test_case
$db->sql_freeresult($result);
}
- function test_nested_transactions()
+ public function test_nested_transactions()
{
$db = $this->new_dbal();
@@ -341,4 +341,20 @@ class phpbb_dbal_select_test extends phpbb_database_test_case
$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 * FROM (SELECT 1) AS TBL WHERE 1 = 0';
+ $result = $db->sql_query($sql);
+
+ $row = $db->sql_fetchrow($result);
+ $db->sql_freeresult($result);
+
+ $this->assertSame(false, $row);
+ }
}
diff --git a/tests/functional/browse_test.php b/tests/functional/browse_test.php
new file mode 100644
index 0000000000..9c1d04f35d
--- /dev/null
+++ b/tests/functional/browse_test.php
@@ -0,0 +1,26 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2011 phpBB Group
+* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+*
+*/
+
+/**
+* @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());
+ }
+}
diff --git a/tests/profile/custom_test.php b/tests/profile/custom_test.php
index 0e0a851243..585182e583 100644
--- a/tests/profile/custom_test.php
+++ b/tests/profile/custom_test.php
@@ -48,7 +48,7 @@ class phpbb_profile_custom_test extends phpbb_database_test_case
);
$cp = new custom_profile;
- $result = $cp->validate_profile_field(FIELD_DROPDOWN, &$field_value, $field_data);
+ $result = $cp->validate_profile_field(FIELD_DROPDOWN, $field_value, $field_data);
$this->assertEquals($expected, $result, $description);
}
diff --git a/tests/template/template_test.php b/tests/template/template_test.php
index 28eba05217..86ff2e9ec6 100644
--- a/tests/template/template_test.php
+++ b/tests/template/template_test.php
@@ -211,21 +211,21 @@ class phpbb_template_template_test extends phpbb_template_template_test_case
array(),
array(),
array(),
- "{ VARIABLE }\n{ VARIABLE }",
+ "{ VARIABLE }\n{ 1_VARIABLE }\n{ VARIABLE }\n{ 1_VARIABLE }",
),
array(
'lang.html',
- array('L_VARIABLE' => "Value'"),
+ array('L_VARIABLE' => "Value'", 'L_1_VARIABLE' => "1 O'Clock"),
array(),
array(),
- "Value'\nValue\'",
+ "Value'\n1 O'Clock\nValue\'\n1 O\'Clock",
),
array(
'lang.html',
- array('LA_VARIABLE' => "Value'"),
+ array('LA_VARIABLE' => "Value'", 'LA_1_VARIABLE' => "1 O'Clock"),
array(),
array(),
- "{ VARIABLE }\nValue'",
+ "{ VARIABLE }\n{ 1_VARIABLE }\nValue'\n1 O'Clock",
),
array(
'loop_nested_multilevel_ref.html',
@@ -248,7 +248,7 @@ class phpbb_template_template_test extends phpbb_template_template_test_case
array('outer' => array(array()), 'outer.middle' => array(array()), 'outer.middle.inner' => array(array('VARIABLE' => 'z'), array('VARIABLE' => 'zz'))),
array(),
// I don't completely understand this output, hopefully it's correct
- "top-level content\nouter\n\ninner z\nfirst row\n\ninner zz",
+ "top-level content\nouter\nmiddle\ninner z\nfirst row of 2 in inner\n\ninner zz",
),
array(
'loop_size.html',
diff --git a/tests/template/templates/lang.html b/tests/template/templates/lang.html
index 2b5ea1cafe..3eecc298cb 100644
--- a/tests/template/templates/lang.html
+++ b/tests/template/templates/lang.html
@@ -1,3 +1,5 @@
{L_VARIABLE}
+{L_1_VARIABLE}
{LA_VARIABLE}
+{LA_1_VARIABLE}
diff --git a/tests/template/templates/loop_nested_deep_multilevel_ref.html b/tests/template/templates/loop_nested_deep_multilevel_ref.html
index 60fad7b4cd..bcc2a7c07b 100644
--- a/tests/template/templates/loop_nested_deep_multilevel_ref.html
+++ b/tests/template/templates/loop_nested_deep_multilevel_ref.html
@@ -2,10 +2,11 @@ top-level content
<!-- BEGIN outer -->
outer
<!-- BEGIN middle -->
+ {outer.middle.S_BLOCK_NAME}
<!-- BEGIN inner -->
inner {inner.VARIABLE}
<!-- IF outer.middle.inner.S_FIRST_ROW -->
- first row
+ first row of {outer.middle.inner.S_NUM_ROWS} in {middle.inner.S_BLOCK_NAME}
<!-- ENDIF -->
<!-- END inner -->
<!-- END middle -->
diff --git a/tests/test_framework/phpbb_database_test_case.php b/tests/test_framework/phpbb_database_test_case.php
index e1b368dcea..b1484450b8 100644
--- a/tests/test_framework/phpbb_database_test_case.php
+++ b/tests/test_framework/phpbb_database_test_case.php
@@ -40,46 +40,14 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test
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(dirname(__FILE__) . '/../test_config.php'))
- {
- include(dirname(__FILE__) . '/../test_config.php');
-
- 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' => dirname(__FILE__) . '/../phpbb_unit_tests.sqlite2', // filename
- 'dbport' => '',
- 'dbname' => '',
- 'dbuser' => '',
- 'dbpasswd' => '',
- );
- }
- else
+ $config = phpbb_test_case_helpers::get_test_config();
+
+ if (!isset($config['dbms']))
{
$this->markTestSkipped('Missing test_config.php: See first error.');
}
+
+ return $config;
}
public function getConnection()
diff --git a/tests/test_framework/phpbb_database_test_connection_manager.php b/tests/test_framework/phpbb_database_test_connection_manager.php
index a7559e2183..68e09add94 100644
--- a/tests/test_framework/phpbb_database_test_connection_manager.php
+++ b/tests/test_framework/phpbb_database_test_connection_manager.php
@@ -69,6 +69,11 @@ class phpbb_database_test_connection_manager
default:
$dsn .= 'host=' . $this->config['dbhost'];
+ if ($this->config['dbport'])
+ {
+ $dsn .= ';port=' . $this->config['dbport'];
+ }
+
if ($use_db)
{
$dsn .= ';dbname=' . $this->config['dbname'];
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..18bf2a84a8
--- /dev/null
+++ b/tests/test_framework/phpbb_functional_test_case.php
@@ -0,0 +1,148 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2011 phpBB Group
+* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+*
+*/
+
+require_once __DIR__ . '/../../vendor/goutte.phar';
+require_once __DIR__ . '/../../phpBB/includes/functions_install.php';
+
+class phpbb_functional_test_case extends phpbb_test_case
+{
+ protected $client;
+ protected $root_url;
+
+ static protected $config = array();
+ static protected $already_installed = false;
+
+ 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->client = new Goutte\Client();
+ $this->root_url = self::$config['phpbb_functional_url'];
+ }
+
+ public function request($method, $path)
+ {
+ return $this->client->request($method, $this->root_url . $path);
+ }
+
+ 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 (!self::$already_installed)
+ {
+ $this->install_board();
+ self::$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_email1' => 'nobody@example.com',
+ 'board_email2' => '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();
+ }
+}
diff --git a/tests/test_framework/phpbb_test_case_helpers.php b/tests/test_framework/phpbb_test_case_helpers.php
index 697dc93501..649b88fdfd 100644
--- a/tests/test_framework/phpbb_test_case_helpers.php
+++ b/tests/test_framework/phpbb_test_case_helpers.php
@@ -46,4 +46,61 @@ class phpbb_test_case_helpers
{
mkdir($path, 0777, true);
}
+
+ 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 (file_exists(dirname(__FILE__) . '/../test_config.php'))
+ {
+ include(dirname(__FILE__) . '/../test_config.php');
+
+ $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/utf/normalizer_test.php b/tests/utf/normalizer_test.php
index a0ba470416..1dc69e283e 100644
--- a/tests/utf/normalizer_test.php
+++ b/tests/utf/normalizer_test.php
@@ -102,7 +102,7 @@ class phpbb_utf_normalizer_test extends phpbb_test_case
foreach ($tests as $test)
{
$utf_result = $utf_expected;
- call_user_func(array('utf_normalizer', $form), &$utf_result);
+ 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)");
@@ -154,7 +154,7 @@ class phpbb_utf_normalizer_test extends phpbb_test_case
foreach (array('nfc', 'nfkc', 'nfd', 'nfkd') as $form)
{
$utf_result = $utf_expected;
- call_user_func(array('utf_normalizer', $form), &$utf_result);
+ 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)");