aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/bootstrap.php4
-rw-r--r--tests/config/config_test.php8
-rw-r--r--tests/config/db_test.php38
-rw-r--r--tests/cron/manager_test.php18
-rw-r--r--tests/group_positions/fixtures/group_positions.xml23
-rw-r--r--tests/group_positions/group_positions_test.php287
-rw-r--r--tests/lock/db_test.php2
-rw-r--r--tests/mock/cache.php16
-rw-r--r--tests/regex/password_complexity_test.php81
-rw-r--r--tests/request/request_var_test.php9
-rw-r--r--tests/security/hash_test.php21
-rw-r--r--tests/session/continue_test.php63
-rw-r--r--tests/session/fixtures/sessions_full.xml4
-rw-r--r--tests/template/template_test.php247
-rw-r--r--tests/template/templates/includephp.html2
-rw-r--r--tests/template/templates/loop_nested.html4
-rw-r--r--tests/test_framework/phpbb_database_test_connection_manager.php2
17 files changed, 589 insertions, 240 deletions
diff --git a/tests/bootstrap.php b/tests/bootstrap.php
index 8c4f1ed874..b7c3534cde 100644
--- a/tests/bootstrap.php
+++ b/tests/bootstrap.php
@@ -12,6 +12,10 @@ $phpbb_root_path = 'phpBB/';
$phpEx = 'php';
$table_prefix = 'phpbb_';
+if (!defined('E_DEPRECATED'))
+{
+ define('E_DEPRECATED', 8192);
+}
error_reporting(E_ALL & ~E_DEPRECATED);
// If we are on PHP >= 6.0.0 we do not need some code
diff --git a/tests/config/config_test.php b/tests/config/config_test.php
index 73a365c847..9c91d9eb87 100644
--- a/tests/config/config_test.php
+++ b/tests/config/config_test.php
@@ -109,4 +109,12 @@ class phpbb_config_test extends phpbb_test_case
$config->increment('foo', 1);
$this->assertEquals(27, $config['foo']);
}
+
+ public function test_delete()
+ {
+ $config = new phpbb_config(array('foo' => 'bar'));
+
+ $config->delete('foo');
+ $this->assertFalse(isset($config['foo']));
+ }
}
diff --git a/tests/config/db_test.php b/tests/config/db_test.php
index e0d5252f19..e817545a54 100644
--- a/tests/config/db_test.php
+++ b/tests/config/db_test.php
@@ -125,4 +125,42 @@ class phpbb_config_db_test extends phpbb_database_test_case
$this->config->increment('foobar', 3);
$this->assertEquals(3, $this->config['foobar']);;
}
+
+ public function test_delete()
+ {
+ $this->assertTrue(isset($this->config['foo']));
+ $this->config->delete('foo');
+ $this->cache->checkVarUnset($this, 'foo');
+ $this->assertFalse(isset($this->config['foo']));
+
+ // re-read config and populate cache
+ $cache2 = new phpbb_mock_cache;
+ $config2 = new phpbb_config_db($this->db, $cache2, 'phpbb_config');
+ $cache2->checkVarUnset($this, 'foo');
+ $this->assertFalse(isset($config2['foo']));
+ }
+
+ public function test_delete_write_read_not_cacheable()
+ {
+ // bar is dynamic
+ $this->assertTrue(isset($this->config['bar']));
+ $this->config->delete('bar');
+ $this->cache->checkVarUnset($this, 'bar');
+ $this->assertFalse(isset($this->config['bar']));
+
+ $this->config->set('bar', 'new bar', false);
+ $this->assertEquals('new bar', $this->config['bar']);
+ }
+
+ public function test_delete_write_read_cacheable()
+ {
+ // foo is not dynamic
+ $this->assertTrue(isset($this->config['foo']));
+ $this->config->delete('foo');
+ $this->cache->checkVarUnset($this, 'foo');
+ $this->assertFalse(isset($this->config['foo']));
+
+ $this->config->set('foo', 'new foo', true);
+ $this->assertEquals('new foo', $this->config['foo']);
+ }
}
diff --git a/tests/cron/manager_test.php b/tests/cron/manager_test.php
index 6288a5c641..65d8360fbb 100644
--- a/tests/cron/manager_test.php
+++ b/tests/cron/manager_test.php
@@ -7,18 +7,18 @@
*
*/
-require_once __DIR__ . '/../mock/cache.php';
-require_once __DIR__ . '/task/testmod/dummy_task.php';
-require_once __DIR__ . '/task/testmod/second_dummy_task.php';
-require_once __DIR__ . '/task2/testmod/simple_ready.php';
-require_once __DIR__ . '/task2/testmod/simple_not_runnable.php';
-require_once __DIR__ . '/task2/testmod/simple_should_not_run.php';
+require_once dirname(__FILE__) . '/../mock/cache.php';
+require_once dirname(__FILE__) . '/task/testmod/dummy_task.php';
+require_once dirname(__FILE__) . '/task/testmod/second_dummy_task.php';
+require_once dirname(__FILE__) . '/task2/testmod/simple_ready.php';
+require_once dirname(__FILE__) . '/task2/testmod/simple_not_runnable.php';
+require_once dirname(__FILE__) . '/task2/testmod/simple_should_not_run.php';
class phpbb_cron_manager_test extends PHPUnit_Framework_TestCase
{
public function setUp()
{
- $this->manager = new phpbb_cron_manager(__DIR__ . '/task/', 'php');
+ $this->manager = new phpbb_cron_manager(dirname(__FILE__) . '/task/', 'php');
$this->task_name = 'phpbb_cron_task_testmod_dummy_task';
}
@@ -57,7 +57,7 @@ class phpbb_cron_manager_test extends PHPUnit_Framework_TestCase
public function test_manager_finds_all_ready_tasks_cached()
{
$cache = new phpbb_mock_cache(array('_cron_tasks' => array($this->task_name)));
- $manager = new phpbb_cron_manager(__DIR__ . '/../../phpBB/', 'php', $cache);
+ $manager = new phpbb_cron_manager(dirname(__FILE__) . '/../../phpBB/', 'php', $cache);
$tasks = $manager->find_all_ready_tasks();
$this->assertEquals(1, sizeof($tasks));
@@ -65,7 +65,7 @@ class phpbb_cron_manager_test extends PHPUnit_Framework_TestCase
public function test_manager_finds_only_ready_tasks()
{
- $manager = new phpbb_cron_manager(__DIR__ . '/task2/', 'php');
+ $manager = new phpbb_cron_manager(dirname(__FILE__) . '/task2/', 'php');
$tasks = $manager->find_all_ready_tasks();
$task_names = $this->tasks_to_names($tasks);
$this->assertEquals(array('phpbb_cron_task_testmod_simple_ready'), $task_names);
diff --git a/tests/group_positions/fixtures/group_positions.xml b/tests/group_positions/fixtures/group_positions.xml
new file mode 100644
index 0000000000..55b1c2e08d
--- /dev/null
+++ b/tests/group_positions/fixtures/group_positions.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="phpbb_groups">
+ <column>group_id</column>
+ <column>group_teampage</column>
+ <column>group_legend</column>
+ <row>
+ <value>1</value>
+ <value>0</value>
+ <value>0</value>
+ </row>
+ <row>
+ <value>2</value>
+ <value>1</value>
+ <value>0</value>
+ </row>
+ <row>
+ <value>3</value>
+ <value>2</value>
+ <value>1</value>
+ </row>
+ </table>
+</dataset>
diff --git a/tests/group_positions/group_positions_test.php b/tests/group_positions/group_positions_test.php
new file mode 100644
index 0000000000..b68f205b37
--- /dev/null
+++ b/tests/group_positions/group_positions_test.php
@@ -0,0 +1,287 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2011 phpBB Group
+* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+*
+*/
+
+
+class phpbb_group_positions_test extends phpbb_database_test_case
+{
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/group_positions.xml');
+ }
+
+ public static function get_group_value_data()
+ {
+ return array(
+ array('teampage', 1, 0),
+ array('teampage', 2, 1),
+ array('legend', 1, 0),
+ array('legend', 3, 1),
+ );
+ }
+
+ /**
+ * @dataProvider get_group_value_data
+ */
+ public function test_get_group_value($field, $group_id, $expected)
+ {
+ global $db;
+
+ $db = $this->new_dbal();
+
+ $test_class = new phpbb_group_positions($db, $field);
+ $this->assertEquals($expected, $test_class->get_group_value($group_id));
+ }
+
+ public static function get_group_count_data()
+ {
+ return array(
+ array('teampage', 2),
+ array('legend', 1),
+ );
+ }
+
+ /**
+ * @dataProvider get_group_count_data
+ */
+ public function test_get_group_count($field, $expected)
+ {
+ global $db;
+
+ $db = $this->new_dbal();
+
+ $test_class = new phpbb_group_positions($db, $field);
+ $this->assertEquals($expected, $test_class->get_group_count());
+ }
+
+ public static function add_group_data()
+ {
+ return array(
+ array('teampage', 1, array(
+ array('group_id' => 1, 'group_teampage' => 3, 'group_legend' => 0),
+ array('group_id' => 2, 'group_teampage' => 1, 'group_legend' => 0),
+ array('group_id' => 3, 'group_teampage' => 2, 'group_legend' => 1),
+ )),
+ array('teampage', 2, array(
+ array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0),
+ array('group_id' => 2, 'group_teampage' => 1, 'group_legend' => 0),
+ array('group_id' => 3, 'group_teampage' => 2, 'group_legend' => 1),
+ )),
+ );
+ }
+
+ /**
+ * @dataProvider add_group_data
+ */
+ public function test_add_group($field, $group_id, $expected)
+ {
+ global $db;
+
+ $db = $this->new_dbal();
+ $test_class = new phpbb_group_positions($db, $field);
+ $test_class->add_group($group_id);
+
+ $result = $db->sql_query('SELECT group_id, group_teampage, group_legend
+ FROM ' . GROUPS_TABLE . '
+ ORDER BY group_id ASC');
+
+ $this->assertEquals($expected, $db->sql_fetchrowset($result));
+ }
+
+ public static function delete_group_data()
+ {
+ return array(
+ array('teampage', 1, false, array(
+ array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0),
+ array('group_id' => 2, 'group_teampage' => 1, 'group_legend' => 0),
+ array('group_id' => 3, 'group_teampage' => 2, 'group_legend' => 1),
+ )),
+ array('teampage', 2, false, array(
+ array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0),
+ array('group_id' => 2, 'group_teampage' => 0, 'group_legend' => 0),
+ array('group_id' => 3, 'group_teampage' => 1, 'group_legend' => 1),
+ )),
+ array('teampage', 3, false, array(
+ array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0),
+ array('group_id' => 2, 'group_teampage' => 1, 'group_legend' => 0),
+ array('group_id' => 3, 'group_teampage' => 0, 'group_legend' => 1),
+ )),
+ array('teampage', 1, true, array(
+ array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0),
+ array('group_id' => 2, 'group_teampage' => 1, 'group_legend' => 0),
+ array('group_id' => 3, 'group_teampage' => 2, 'group_legend' => 1),
+ )),
+ array('teampage', 2, true, array(
+ array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0),
+ array('group_id' => 2, 'group_teampage' => 1, 'group_legend' => 0),
+ array('group_id' => 3, 'group_teampage' => 1, 'group_legend' => 1),
+ )),
+ array('teampage', 3, true, array(
+ array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0),
+ array('group_id' => 2, 'group_teampage' => 1, 'group_legend' => 0),
+ array('group_id' => 3, 'group_teampage' => 2, 'group_legend' => 1),
+ )),
+ );
+ }
+
+ /**
+ * @dataProvider delete_group_data
+ */
+ public function test_delete_group($field, $group_id, $skip_group, $expected)
+ {
+ global $db;
+
+ $db = $this->new_dbal();
+ $test_class = new phpbb_group_positions($db, $field);
+ $test_class->delete_group($group_id, $skip_group);
+
+ $result = $db->sql_query('SELECT group_id, group_teampage, group_legend
+ FROM ' . GROUPS_TABLE . '
+ ORDER BY group_id ASC');
+
+ $this->assertEquals($expected, $db->sql_fetchrowset($result));
+ }
+
+ public static function move_up_data()
+ {
+ return array(
+ array('teampage', 1, array(
+ array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0),
+ array('group_id' => 2, 'group_teampage' => 1, 'group_legend' => 0),
+ array('group_id' => 3, 'group_teampage' => 2, 'group_legend' => 1),
+ )),
+ array('teampage', 2, array(
+ array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0),
+ array('group_id' => 2, 'group_teampage' => 1, 'group_legend' => 0),
+ array('group_id' => 3, 'group_teampage' => 2, 'group_legend' => 1),
+ )),
+ array('teampage', 3, array(
+ array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0),
+ array('group_id' => 2, 'group_teampage' => 2, 'group_legend' => 0),
+ array('group_id' => 3, 'group_teampage' => 1, 'group_legend' => 1),
+ )),
+ );
+ }
+
+ /**
+ * @dataProvider move_up_data
+ */
+ public function test_move_up($field, $group_id, $expected)
+ {
+ global $db;
+
+ $db = $this->new_dbal();
+ $test_class = new phpbb_group_positions($db, $field);
+ $test_class->move_up($group_id);
+
+ $result = $db->sql_query('SELECT group_id, group_teampage, group_legend
+ FROM ' . GROUPS_TABLE . '
+ ORDER BY group_id ASC');
+
+ $this->assertEquals($expected, $db->sql_fetchrowset($result));
+ }
+
+ public static function move_down_data()
+ {
+ return array(
+ array('teampage', 1, array(
+ array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0),
+ array('group_id' => 2, 'group_teampage' => 1, 'group_legend' => 0),
+ array('group_id' => 3, 'group_teampage' => 2, 'group_legend' => 1),
+ )),
+ array('teampage', 2, array(
+ array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0),
+ array('group_id' => 2, 'group_teampage' => 2, 'group_legend' => 0),
+ array('group_id' => 3, 'group_teampage' => 1, 'group_legend' => 1),
+ )),
+ array('teampage', 3, array(
+ array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0),
+ array('group_id' => 2, 'group_teampage' => 1, 'group_legend' => 0),
+ array('group_id' => 3, 'group_teampage' => 2, 'group_legend' => 1),
+ )),
+ );
+ }
+
+ /**
+ * @dataProvider move_down_data
+ */
+ public function test_move_down($field, $group_id, $expected)
+ {
+ global $db;
+
+ $db = $this->new_dbal();
+ $test_class = new phpbb_group_positions($db, $field);
+ $test_class->move_down($group_id);
+
+ $result = $db->sql_query('SELECT group_id, group_teampage, group_legend
+ FROM ' . GROUPS_TABLE . '
+ ORDER BY group_id ASC');
+
+ $this->assertEquals($expected, $db->sql_fetchrowset($result));
+ }
+
+ public static function move_data()
+ {
+ return array(
+ array('teampage', 1, 1, array(
+ array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0),
+ array('group_id' => 2, 'group_teampage' => 1, 'group_legend' => 0),
+ array('group_id' => 3, 'group_teampage' => 2, 'group_legend' => 1),
+ )),
+ array('teampage', 1, -1, array(
+ array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0),
+ array('group_id' => 2, 'group_teampage' => 1, 'group_legend' => 0),
+ array('group_id' => 3, 'group_teampage' => 2, 'group_legend' => 1),
+ )),
+ array('teampage', 3, 3, array(
+ array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0),
+ array('group_id' => 2, 'group_teampage' => 2, 'group_legend' => 0),
+ array('group_id' => 3, 'group_teampage' => 1, 'group_legend' => 1),
+ )),
+ array('teampage', 2, 0, array(
+ array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0),
+ array('group_id' => 2, 'group_teampage' => 1, 'group_legend' => 0),
+ array('group_id' => 3, 'group_teampage' => 2, 'group_legend' => 1),
+ )),
+ array('teampage', 2, -1, array(
+ array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0),
+ array('group_id' => 2, 'group_teampage' => 2, 'group_legend' => 0),
+ array('group_id' => 3, 'group_teampage' => 1, 'group_legend' => 1),
+ )),
+ array('teampage', 2, -3, array(
+ array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0),
+ array('group_id' => 2, 'group_teampage' => 2, 'group_legend' => 0),
+ array('group_id' => 3, 'group_teampage' => 1, 'group_legend' => 1),
+ )),
+ array('teampage', 3, -1, array(
+ array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0),
+ array('group_id' => 2, 'group_teampage' => 1, 'group_legend' => 0),
+ array('group_id' => 3, 'group_teampage' => 2, 'group_legend' => 1),
+ )),
+ );
+ }
+
+ /**
+ * @dataProvider move_data
+ */
+ public function test_move($field, $group_id, $increment, $expected)
+ {
+ global $db;
+
+ $db = $this->new_dbal();
+ $test_class = new phpbb_group_positions($db, $field);
+ $test_class->move($group_id, $increment);
+
+ $result = $db->sql_query('SELECT group_id, group_teampage, group_legend
+ FROM ' . GROUPS_TABLE . '
+ ORDER BY group_id ASC');
+
+ $this->assertEquals($expected, $db->sql_fetchrowset($result));
+ }
+}
+
diff --git a/tests/lock/db_test.php b/tests/lock/db_test.php
index 3b2e3ea3b2..ed15423314 100644
--- a/tests/lock/db_test.php
+++ b/tests/lock/db_test.php
@@ -7,7 +7,7 @@
*
*/
-require_once __DIR__ . '/../../phpBB/includes/functions.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
class phpbb_lock_db_test extends phpbb_database_test_case
{
diff --git a/tests/mock/cache.php b/tests/mock/cache.php
index 713f1ca817..d3f9b8ad5a 100644
--- a/tests/mock/cache.php
+++ b/tests/mock/cache.php
@@ -42,9 +42,21 @@ class phpbb_mock_cache implements phpbb_cache_driver_interface
$test->assertFalse(isset($this->data[$var_name]));
}
- public function check(PHPUnit_Framework_Assert $test, $data)
+ public function check(PHPUnit_Framework_Assert $test, $data, $ignore_db_info = true)
{
- $test->assertEquals($data, $this->data);
+ $cache_data = $this->data;
+
+ if ($ignore_db_info)
+ {
+ unset($cache_data['mssqlodbc_version']);
+ unset($cache_data['mssql_version']);
+ unset($cache_data['mysql_version']);
+ unset($cache_data['mysqli_version']);
+ unset($cache_data['pgsql_version']);
+ unset($cache_data['sqlite_version']);
+ }
+
+ $test->assertEquals($data, $cache_data);
}
function load()
diff --git a/tests/regex/password_complexity_test.php b/tests/regex/password_complexity_test.php
new file mode 100644
index 0000000000..21e8d12a0a
--- /dev/null
+++ b/tests/regex/password_complexity_test.php
@@ -0,0 +1,81 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2010 phpBB Group
+* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+*
+*/
+
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions_user.php';
+
+class phpbb_password_complexity_test extends phpbb_test_case
+{
+ public function password_complexity_test_data_positive()
+ {
+ return array(
+ array('12345', 'PASS_TYPE_ANY'),
+ array('qwerty', 'PASS_TYPE_ANY'),
+ array('QWERTY', 'PASS_TYPE_ANY'),
+ array('QwerTY', 'PASS_TYPE_ANY'),
+ array('q$erty', 'PASS_TYPE_ANY'),
+ array('qW$rty', 'PASS_TYPE_ANY'),
+
+ array('QwerTY', 'PASS_TYPE_CASE'),
+ array('QwerTY123', 'PASS_TYPE_ALPHA'),
+ array('QwerTY123$&', 'PASS_TYPE_SYMBOL'),
+
+ array('', 'PASS_TYPE_ANY'),
+ );
+ }
+
+ public function password_complexity_test_data_negative()
+ {
+ return array(
+ array('qwerty', 'PASS_TYPE_CASE'),
+ array('QWERTY', 'PASS_TYPE_CASE'),
+ array('123456', 'PASS_TYPE_CASE'),
+ array('#$&', 'PASS_TYPE_CASE'),
+ array('QTY123$', 'PASS_TYPE_CASE'),
+
+ array('qwerty', 'PASS_TYPE_ALPHA'),
+ array('QWERTY', 'PASS_TYPE_ALPHA'),
+ array('123456', 'PASS_TYPE_ALPHA'),
+ array('QwertY', 'PASS_TYPE_ALPHA'),
+ array('qwerty123', 'PASS_TYPE_ALPHA'),
+ array('QWERTY123', 'PASS_TYPE_ALPHA'),
+ array('#$&', 'PASS_TYPE_ALPHA'),
+ array('QTY123$', 'PASS_TYPE_ALPHA'),
+
+ array('qwerty', 'PASS_TYPE_SYMBOL'),
+ array('QWERTY', 'PASS_TYPE_SYMBOL'),
+ array('123456', 'PASS_TYPE_SYMBOL'),
+ array('QwertY', 'PASS_TYPE_SYMBOL'),
+ array('qwerty123', 'PASS_TYPE_SYMBOL'),
+ array('QWERTY123', 'PASS_TYPE_SYMBOL'),
+ array('#$&', 'PASS_TYPE_SYMBOL'),
+ array('qwerty123$', 'PASS_TYPE_SYMBOL'),
+ array('QWERTY123$', 'PASS_TYPE_SYMBOL'),
+ );
+ }
+
+ /**
+ * @dataProvider password_complexity_test_data_positive
+ */
+ public function test_password_complexity_positive($password, $mode)
+ {
+ global $config;
+ $config['pass_complex'] = $mode;
+ $this->assertFalse(validate_password($password));
+ }
+
+ /**
+ * @dataProvider password_complexity_test_data_negative
+ */
+ public function test_password_complexity_negative($password, $mode)
+ {
+ global $config;
+ $config['pass_complex'] = $mode;
+ $this->assertEquals('INVALID_CHARS', validate_password($password));
+ }
+}
diff --git a/tests/request/request_var_test.php b/tests/request/request_var_test.php
index 6a0ede0106..7a45ef2fee 100644
--- a/tests/request/request_var_test.php
+++ b/tests/request/request_var_test.php
@@ -13,6 +13,15 @@ require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php';
class phpbb_request_var_test extends phpbb_test_case
{
/**
+ * Makes sure request_var has its standard behaviour.
+ */
+ protected function setUp()
+ {
+ parent::setUp();
+ request_var(false, false, false, false, false);
+ }
+
+ /**
* @dataProvider request_variables
*/
public function test_post($variable_value, $default, $multibyte, $expected)
diff --git a/tests/security/hash_test.php b/tests/security/hash_test.php
new file mode 100644
index 0000000000..19a3822145
--- /dev/null
+++ b/tests/security/hash_test.php
@@ -0,0 +1,21 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2011 phpBB Group
+* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+*
+*/
+
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
+
+class phpbb_security_hash_test extends phpbb_test_case
+{
+ public function test_check_hash_with_phpass()
+ {
+ $this->assertTrue(phpbb_check_hash('test', '$H$9isfrtKXWqrz8PvztXlL3.daw4U0zI1'));
+ $this->assertTrue(phpbb_check_hash('test', '$P$9isfrtKXWqrz8PvztXlL3.daw4U0zI1'));
+ $this->assertFalse(phpbb_check_hash('foo', '$H$9isfrtKXWqrz8PvztXlL3.daw4U0zI1'));
+ }
+}
+
diff --git a/tests/session/continue_test.php b/tests/session/continue_test.php
index 06b03f5780..6737562a0a 100644
--- a/tests/session/continue_test.php
+++ b/tests/session/continue_test.php
@@ -19,27 +19,30 @@ class phpbb_session_continue_test extends phpbb_database_test_case
static public function session_begin_attempts()
{
- global $_SID;
+ // The session_id field is defined as CHAR(32) in the database schema.
+ // Thus the data we put in session_id fields has to have a length of 32 characters on stricter DBMSes.
+ // Thus we fill those strings up with zeroes until they have a string length of 32.
+
return array(
array(
- 'bar_session', '4', 'user agent', '127.0.0.1',
+ 'bar_session000000000000000000000', '4', 'user agent', '127.0.0.1',
array(
- array('session_id' => 'anon_session', 'session_user_id' => 1),
- array('session_id' => 'bar_session', 'session_user_id' => 4)
+ array('session_id' => 'anon_session00000000000000000000', 'session_user_id' => 1),
+ array('session_id' => 'bar_session000000000000000000000', 'session_user_id' => 4),
),
array(),
'If a request comes with a valid session id with matching user agent and IP, no new session should be created.',
),
array(
- 'anon_session', '4', 'user agent', '127.0.0.1',
+ 'anon_session00000000000000000000', '4', 'user agent', '127.0.0.1',
array(
- array('session_id' => 'bar_session', 'session_user_id' => 4),
- array('session_id' => null, 'session_user_id' => 1) // use generated SID
+ array('session_id' => '__new_session_id__', 'session_user_id' => 1), // use generated SID
+ array('session_id' => 'bar_session000000000000000000000', 'session_user_id' => 4),
),
array(
'u' => array('1', null),
'k' => array(null, null),
- 'sid' => array($_SID, null),
+ 'sid' => array('__new_session_id__', null),
),
'If a request comes with a valid session id and IP but different user id and user agent, a new anonymous session is created and the session matching the supplied session id is deleted.',
),
@@ -71,26 +74,48 @@ class phpbb_session_continue_test extends phpbb_database_test_case
$session->session_begin();
$sql = 'SELECT session_id, session_user_id
- FROM phpbb_sessions';
+ FROM phpbb_sessions
+ ORDER BY session_user_id';
- // little tickery to allow using a dataProvider with dynamic expected result
- foreach ($expected_sessions as $i => $s)
- {
- if (is_null($s['session_id']))
- {
- $expected_sessions[$i]['session_id'] = $session->session_id;
- }
- }
+ $expected_sessions = $this->replace_session($expected_sessions, $session->session_id);
+ $expected_cookies = $this->replace_session($expected_cookies, $session->session_id);
$this->assertSqlResultEquals(
$expected_sessions,
$sql,
- 'Check if no new session was created'
+ $message
);
$session->check_cookies($this, $expected_cookies);
$session_factory->check($this);
}
-}
+ /**
+ * Replaces recursively the value __new_session_id__ with the given session
+ * id.
+ *
+ * @param array $array An array of data
+ * @param string $session_id The new session id to use instead of the
+ * placeholder.
+ * @return array The input array with all occurances of __new_session_id__
+ * replaced.
+ */
+ public function replace_session($array, $session_id)
+ {
+ foreach ($array as $key => &$value)
+ {
+ if ($value === '__new_session_id__')
+ {
+ $value = $session_id;
+ }
+
+ if (is_array($value))
+ {
+ $value = $this->replace_session($value, $session_id);
+ }
+ }
+
+ return $array;
+ }
+}
diff --git a/tests/session/fixtures/sessions_full.xml b/tests/session/fixtures/sessions_full.xml
index 4559a08c55..bf6fc65997 100644
--- a/tests/session/fixtures/sessions_full.xml
+++ b/tests/session/fixtures/sessions_full.xml
@@ -22,13 +22,13 @@
<column>session_ip</column>
<column>session_browser</column>
<row>
- <value>anon_session</value>
+ <value>anon_session00000000000000000000</value>
<value>1</value>
<value>127.0.0.1</value>
<value>anonymous user agent</value>
</row>
<row>
- <value>bar_session</value>
+ <value>bar_session000000000000000000000</value>
<value>4</value>
<value>127.0.0.1</value>
<value>user agent</value>
diff --git a/tests/template/template_test.php b/tests/template/template_test.php
index a3ba3e581f..62f94f7d32 100644
--- a/tests/template/template_test.php
+++ b/tests/template/template_test.php
@@ -324,8 +324,7 @@ class phpbb_template_template_test extends phpbb_test_case
*/
public function test_template($file, array $vars, array $block_vars, array $destroy, $expected)
{
- global $phpEx;
- $cache_file = $this->template->cachepath . str_replace('/', '.', $file) . '.' . $phpEx;
+ $cache_file = $this->template->cachepath . str_replace('/', '.', $file) . '.php';
$this->assertFileNotExists($cache_file);
@@ -375,11 +374,9 @@ class phpbb_template_template_test extends phpbb_test_case
public function test_php()
{
- global $phpEx;
-
$GLOBALS['config']['tpl_allow_php'] = true;
- $cache_file = $this->template->cachepath . 'php.html.' . $phpEx;
+ $cache_file = $this->template->cachepath . 'php.html.php';
$this->assertFileNotExists($cache_file);
@@ -390,21 +387,14 @@ class phpbb_template_template_test extends phpbb_test_case
public function test_includephp()
{
- $this->markTestIncomplete('Include PHP test file paths are broken');
-
$GLOBALS['config']['tpl_allow_php'] = true;
- $cache_file = $this->template->cachepath . 'includephp.html.' . PHP_EXT;
-
- $cwd = getcwd();
- chdir(dirname(__FILE__) . '/templates');
+ $cache_file = $this->template->cachepath . 'includephp.html.php';
$this->run_template('includephp.html', array(), array(), array(), 'testing included php', $cache_file);
$this->template->set_filenames(array('test' => 'includephp.html'));
- $this->assertEquals('testing included php', $this->display('test'), "Testing $file");
-
- chdir($cwd);
+ $this->assertEquals('testing included php', $this->display('test'), "Testing INCLUDEPHP");
$GLOBALS['config']['tpl_allow_php'] = false;
}
@@ -418,17 +408,16 @@ class phpbb_template_template_test extends phpbb_test_case
false,
'insert',
<<<EOT
-outer - 0/4 - before
-outer - 1/4
-middle - 0/2
-middle - 1/2
-outer - 2/4
-middle - 0/3
-middle - 1/3
-middle - 2/3
-outer - 3/4
-middle - 0/2
-middle - 1/2
+outer - 0 - before
+outer - 1
+middle - 0
+middle - 1
+outer - 2
+middle - 0
+middle - 1
+outer - 3
+middle - 0
+middle - 1
EOT
,
'Test inserting before on top level block',
@@ -439,17 +428,16 @@ EOT
true,
'insert',
<<<EOT
-outer - 0/4
-middle - 0/2
-middle - 1/2
-outer - 1/4
-middle - 0/3
-middle - 1/3
-middle - 2/3
-outer - 2/4
-middle - 0/2
-middle - 1/2
-outer - 3/4 - after
+outer - 0
+middle - 0
+middle - 1
+outer - 1
+middle - 0
+middle - 1
+outer - 2
+middle - 0
+middle - 1
+outer - 3 - after
EOT
,
'Test inserting after on top level block',
@@ -460,17 +448,16 @@ EOT
1,
'insert',
<<<EOT
-outer - 0/4
-middle - 0/2
-middle - 1/2
-outer - 1/4 - pos #1
-outer - 2/4
-middle - 0/3
-middle - 1/3
-middle - 2/3
-outer - 3/4
-middle - 0/2
-middle - 1/2
+outer - 0
+middle - 0
+middle - 1
+outer - 1 - pos #1
+outer - 2
+middle - 0
+middle - 1
+outer - 3
+middle - 0
+middle - 1
EOT
,
'Test inserting at 1 on top level block',
@@ -481,172 +468,27 @@ EOT
0,
'change',
<<<EOT
-outer - 0/3 - pos #1
-middle - 0/2
-middle - 1/2
-outer - 1/3
-middle - 0/3
-middle - 1/3
-middle - 2/3
-outer - 2/3
-middle - 0/2
-middle - 1/2
+outer - 0 - pos #1
+middle - 0
+middle - 1
+outer - 1
+middle - 0
+middle - 1
+outer - 2
+middle - 0
+middle - 1
EOT
,
'Test inserting at 1 on top level block',
),
- array(
- 'outer[0].middle',
- array('VARIABLE' => 'before'),
- false,
- 'insert',
- <<<EOT
-outer - 0/3
-middle - 0/3 - before
-middle - 1/3
-middle - 2/3
-outer - 1/3
-middle - 0/3
-middle - 1/3
-middle - 2/3
-outer - 2/3
-middle - 0/2
-middle - 1/2
-EOT
-,
- 'Test inserting before on nested block',
- ),
- array(
- 'outer[0].middle',
- array('VARIABLE' => 'after'),
- true,
- 'insert',
- <<<EOT
-outer - 0/3
-middle - 0/3
-middle - 1/3
-middle - 2/3 - after
-outer - 1/3
-middle - 0/3
-middle - 1/3
-middle - 2/3
-outer - 2/3
-middle - 0/2
-middle - 1/2
-EOT
-,
- 'Test inserting after on nested block',
- ),
- array(
- 'outer[0].middle',
- array('VARIABLE' => 'pos #1'),
- 1,
- 'insert',
- <<<EOT
-outer - 0/3
-middle - 0/3
-middle - 1/3 - pos #1
-middle - 2/3
-outer - 1/3
-middle - 0/3
-middle - 1/3
-middle - 2/3
-outer - 2/3
-middle - 0/2
-middle - 1/2
-EOT
-,
- 'Test inserting at pos 1 on nested block',
- ),
- array(
- 'outer[1].middle',
- array('VARIABLE' => 'before'),
- false,
- 'insert',
- <<<EOT
-outer - 0/3
-middle - 0/2
-middle - 1/2
-outer - 1/3
-middle - 0/4 - before
-middle - 1/4
-middle - 2/4
-middle - 3/4
-outer - 2/3
-middle - 0/2
-middle - 1/2
-EOT
-,
- 'Test inserting before on nested block (pos 1)',
- ),
- array(
- 'outer[].middle',
- array('VARIABLE' => 'before'),
- false,
- 'insert',
- <<<EOT
-outer - 0/3
-middle - 0/2
-middle - 1/2
-outer - 1/3
-middle - 0/3
-middle - 1/3
-middle - 2/3
-outer - 2/3
-middle - 0/3 - before
-middle - 1/3
-middle - 2/3
-EOT
-,
- 'Test inserting before on nested block (end)',
- ),
- array(
- 'outer.middle',
- array('VARIABLE' => 'before'),
- false,
- 'insert',
- <<<EOT
-outer - 0/3
-middle - 0/2
-middle - 1/2
-outer - 1/3
-middle - 0/3
-middle - 1/3
-middle - 2/3
-outer - 2/3
-middle - 0/3 - before
-middle - 1/3
-middle - 2/3
-EOT
-,
- 'Test inserting before on nested block (end)',
- ),
);
}
-/*
- <<<EOT
-outer - 0/3
-middle - 0/2
-middle - 1/2
-outer - 1/3
-middle - 0/3
-middle - 1/3
-middle - 2/3
-outer - 2/3
-middle - 0/2
-middle - 1/2
-EOT
-,
-*/
-
/**
* @dataProvider alter_block_array_data
*/
public function test_alter_block_array($alter_block, array $vararray, $key, $mode, $expect, $description)
{
- $this->markTestIncomplete('Alter Block Test is broken');
-
$this->template->set_filenames(array('test' => 'loop_nested.html'));
// @todo Change this
@@ -656,12 +498,11 @@ EOT
$this->template->assign_block_vars('outer', array());
$this->template->assign_block_vars('outer.middle', array());
$this->template->assign_block_vars('outer.middle', array());
- $this->template->assign_block_vars('outer.middle', array());
$this->template->assign_block_vars('outer', array());
$this->template->assign_block_vars('outer.middle', array());
$this->template->assign_block_vars('outer.middle', array());
- $this->assertEquals("outer - 0/3\nmiddle - 0/2\nmiddle - 1/2\nouter - 1/3\nmiddle - 0/3\nmiddle - 1/3\nmiddle - 2/3\nouter - 2/3\nmiddle - 0/2\nmiddle - 1/2", $this->display('test'), 'Ensuring template is built correctly before modification');
+ $this->assertEquals("outer - 0\nmiddle - 0\nmiddle - 1\nouter - 1\nmiddle - 0\nmiddle - 1\nouter - 2\nmiddle - 0\nmiddle - 1", $this->display('test'), 'Ensuring template is built correctly before modification');
$this->template->alter_block_array($alter_block, $vararray, $key, $mode);
$this->assertEquals($expect, $this->display('test'), $description);
diff --git a/tests/template/templates/includephp.html b/tests/template/templates/includephp.html
index 117d4273f0..70ebdac0d0 100644
--- a/tests/template/templates/includephp.html
+++ b/tests/template/templates/includephp.html
@@ -1 +1 @@
-<!-- INCLUDEPHP ../templates/_dummy_include.php.inc -->
+<!-- INCLUDEPHP ../tests/template/templates/_dummy_include.php.inc -->
diff --git a/tests/template/templates/loop_nested.html b/tests/template/templates/loop_nested.html
index 571df97b4c..9b251cd453 100644
--- a/tests/template/templates/loop_nested.html
+++ b/tests/template/templates/loop_nested.html
@@ -1,8 +1,8 @@
<!-- BEGIN outer -->
- {outer.S_BLOCK_NAME} - {outer.S_ROW_NUM}/{outer.S_NUM_ROWS}<!-- IF outer.VARIABLE --> - {outer.VARIABLE}<!-- ENDIF -->
+ outer - {outer.S_ROW_COUNT}<!-- IF outer.VARIABLE --> - {outer.VARIABLE}<!-- ENDIF -->
<!-- BEGIN middle -->
- {middle.S_BLOCK_NAME} - {middle.S_ROW_NUM}/{middle.S_NUM_ROWS}<!-- IF middle.VARIABLE --> - {middle.VARIABLE}<!-- ENDIF -->
+ middle - {middle.S_ROW_COUNT}<!-- IF middle.VARIABLE --> - {middle.VARIABLE}<!-- ENDIF -->
<!-- END middle -->
<!-- END outer -->
diff --git a/tests/test_framework/phpbb_database_test_connection_manager.php b/tests/test_framework/phpbb_database_test_connection_manager.php
index 6c06857fbc..a7559e2183 100644
--- a/tests/test_framework/phpbb_database_test_connection_manager.php
+++ b/tests/test_framework/phpbb_database_test_connection_manager.php
@@ -123,7 +123,7 @@ class phpbb_database_test_connection_manager
try
{
- $this->pdo->exec('DROP DATABASE ' . $config['dbname']);
+ $this->pdo->exec('DROP DATABASE ' . $this->config['dbname']);
}
catch (PDOException $e)
{