diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/bootstrap.php | 4 | ||||
-rw-r--r-- | tests/mock/cache.php | 5 | ||||
-rw-r--r-- | tests/regex/password_complexity_test.php | 81 | ||||
-rw-r--r-- | tests/security/hash_test.php | 21 | ||||
-rw-r--r-- | tests/session/continue_test.php | 14 | ||||
-rw-r--r-- | tests/session/fixtures/sessions_full.xml | 4 | ||||
-rw-r--r-- | tests/template/template_test.php | 247 | ||||
-rw-r--r-- | tests/template/templates/includephp.html | 2 | ||||
-rw-r--r-- | tests/template/templates/loop_nested.html | 4 |
9 files changed, 169 insertions, 213 deletions
diff --git a/tests/bootstrap.php b/tests/bootstrap.php index c729c6e2d8..6f3c93a374 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/mock/cache.php b/tests/mock/cache.php index 738d1eaaba..11e525ff79 100644 --- a/tests/mock/cache.php +++ b/tests/mock/cache.php @@ -59,7 +59,12 @@ class phpbb_mock_cache if ($ignore_db_info) { + unset($cache_data['mssqlodbc_version']); + unset($cache_data['mssql_version']); + unset($cache_data['mysql_version']); unset($cache_data['mysqli_version']); + unset($cache_data['pgsql_version']); + unset($cache_data['sqlite_version']); } $test->assertEquals($data, $cache_data); diff --git a/tests/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/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 3080121978..6737562a0a 100644 --- a/tests/session/continue_test.php +++ b/tests/session/continue_test.php @@ -19,21 +19,25 @@ class phpbb_session_continue_test extends phpbb_database_test_case static public function session_begin_attempts() { + // The session_id field is defined as CHAR(32) in the database schema. + // Thus the data we put in session_id fields has to have a length of 32 characters on stricter DBMSes. + // Thus we fill those strings up with zeroes until they have a string length of 32. + return array( array( - 'bar_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' => '__new_session_id__', 'session_user_id' => 1), // use generated SID - array('session_id' => 'bar_session', 'session_user_id' => 4), + array('session_id' => 'bar_session000000000000000000000', 'session_user_id' => 4), ), array( 'u' => array('1', null), 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 1b2f35f210..33c82d53ad 100644 --- a/tests/template/template_test.php +++ b/tests/template/template_test.php @@ -343,8 +343,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); @@ -394,11 +393,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); @@ -409,21 +406,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; } @@ -437,17 +427,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', @@ -458,17 +447,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', @@ -479,17 +467,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', @@ -500,172 +487,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 @@ -675,12 +517,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 --> |