aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tests/all_tests.php14
-rw-r--r--tests/request/all_tests.php4
-rw-r--r--tests/request/request_var.php49
-rw-r--r--tests/security/all_tests.php6
-rw-r--r--tests/security/extract_current_page.php4
-rw-r--r--tests/security/redirect.php9
-rw-r--r--tests/template/all_tests.php5
-rw-r--r--tests/template/template.php76
-rw-r--r--tests/test_framework/framework.php18
-rw-r--r--tests/text_processing/all_tests.php3
-rw-r--r--tests/text_processing/make_clickable.php5
-rw-r--r--tests/utf/all_tests.php3
-rw-r--r--tests/utf/utf8_clean_string_test.php6
-rw-r--r--tests/utf/utf8_wordwrap_test.php3
14 files changed, 82 insertions, 123 deletions
diff --git a/tests/all_tests.php b/tests/all_tests.php
index 60a66598e7..f22ee5dc49 100644
--- a/tests/all_tests.php
+++ b/tests/all_tests.php
@@ -8,8 +8,6 @@
*
*/
-define('IN_PHPBB', true);
-
if (!defined('PHPUnit_MAIN_METHOD'))
{
define('PHPUnit_MAIN_METHOD', 'phpbb_all_tests::main');
@@ -18,11 +16,11 @@ if (!defined('PHPUnit_MAIN_METHOD'))
require_once 'test_framework/framework.php';
require_once 'PHPUnit/TextUI/TestRunner.php';
-require_once 'bbcode/all_tests.php';
require_once 'utf/all_tests.php';
require_once 'request/all_tests.php';
require_once 'security/all_tests.php';
-require_once 'template/all_tests.php';
+#require_once 'template/all_tests.php';
+#require_once 'bbcode/all_tests.php';
require_once 'text_processing/all_tests.php';
// exclude the test directory from code coverage reports
@@ -39,12 +37,12 @@ class phpbb_all_tests
{
$suite = new PHPUnit_Framework_TestSuite('phpBB');
- $suite->addTest(phpbb_bbcode_all_tests::suite());
+ $suite->addTest(phpbb_utf_all_tests::suite());
$suite->addTest(phpbb_request_all_tests::suite());
$suite->addTest(phpbb_security_all_tests::suite());
- $suite->addTest(phpbb_template_all_tests::suite());
+# $suite->addTest(phpbb_template_all_tests::suite());
+# $suite->addTest(phpbb_bbcode_all_tests::suite());
$suite->addTest(phpbb_text_processing_all_tests::suite());
- $suite->addTest(phpbb_utf_all_tests::suite());
return $suite;
}
@@ -54,5 +52,3 @@ if (PHPUnit_MAIN_METHOD == 'phpbb_all_tests::main')
{
phpbb_all_tests::main();
}
-
-?> \ No newline at end of file
diff --git a/tests/request/all_tests.php b/tests/request/all_tests.php
index 3b235311d3..dc5d26417f 100644
--- a/tests/request/all_tests.php
+++ b/tests/request/all_tests.php
@@ -8,8 +8,6 @@
*
*/
-define('IN_PHPBB', true);
-
if (!defined('PHPUnit_MAIN_METHOD'))
{
define('PHPUnit_MAIN_METHOD', 'phpbb_request_all_tests::main');
@@ -19,7 +17,6 @@ require_once 'test_framework/framework.php';
require_once 'PHPUnit/TextUI/TestRunner.php';
require_once 'request/request_var.php';
-require_once 'request/request_class.php';
class phpbb_request_all_tests
{
@@ -32,7 +29,6 @@ class phpbb_request_all_tests
{
$suite = new PHPUnit_Framework_TestSuite('phpBB Request Parameter Handling');
- $suite->addTestSuite('phpbb_request_request_class_test');
$suite->addTestSuite('phpbb_request_request_var_test');
return $suite;
diff --git a/tests/request/request_var.php b/tests/request/request_var.php
index 549512753b..c0f8a22d95 100644
--- a/tests/request/request_var.php
+++ b/tests/request/request_var.php
@@ -8,10 +8,7 @@
*
*/
-define('IN_PHPBB', true);
-
require_once 'test_framework/framework.php';
-
require_once '../phpBB/includes/functions.php';
class phpbb_request_request_var_test extends phpbb_test_case
@@ -22,13 +19,11 @@ class phpbb_request_request_var_test extends phpbb_test_case
public function test_post($variable_value, $default, $multibyte, $expected)
{
$variable_name = 'name';
+ $this->unset_variables($variable_name);
$_POST[$variable_name] = $variable_value;
$_REQUEST[$variable_name] = $variable_value;
- // reread data from super globals
- request::reset();
-
$result = request_var($variable_name, $default, $multibyte);
$label = 'Requesting POST variable, converting from ' . gettype($variable_value) . ' to ' . gettype($default) . (($multibyte) ? ' multibyte' : '');
@@ -41,13 +36,11 @@ class phpbb_request_request_var_test extends phpbb_test_case
public function test_get($variable_value, $default, $multibyte, $expected)
{
$variable_name = 'name';
+ $this->unset_variables($variable_name);
$_GET[$variable_name] = $variable_value;
$_REQUEST[$variable_name] = $variable_value;
- // reread data from super globals
- request::reset();
-
$result = request_var($variable_name, $default, $multibyte);
$label = 'Requesting GET variable, converting from ' . gettype($variable_value) . ' to ' . gettype($default) . (($multibyte) ? ' multibyte' : '');
@@ -55,10 +48,39 @@ class phpbb_request_request_var_test extends phpbb_test_case
}
/**
- * @dataProvider deep_access
+ * @dataProvider request_variables
*/
+ public function test_cookie($variable_value, $default, $multibyte, $expected)
+ {
+ $variable_name = 'name';
+ $this->unset_variables($variable_name);
+
+ $_GET[$variable_name] = false;
+ $_POST[$variable_name] = false;
+ $_REQUEST[$variable_name] = false;
+ $_COOKIE[$variable_name] = $variable_value;
+
+ $result = request_var($variable_name, $default, $multibyte, true);
+
+ $label = 'Requesting COOKIE variable, converting from ' . gettype($variable_value) . ' to ' . gettype($default) . (($multibyte) ? ' multibyte' : '');
+ $this->assertEquals($expected, $result, $label);
+ }
+
+ /**
+ * Helper for unsetting globals
+ */
+ private function unset_variables($var)
+ {
+ unset($_GET[$var], $_POST[$var], $_REQUEST[$var], $_COOKIE[$var]);
+ }
+
+ /**
+ * @dataProvider deep_access
+ * Only possible with 3.1.x (later)
public function test_deep_multi_dim_array_access($path, $default, $expected)
{
+ $this->unset_variables('var');
+
$_REQUEST['var'] = array(
0 => array(
'b' => array(
@@ -75,9 +97,6 @@ class phpbb_request_request_var_test extends phpbb_test_case
),
);
- // reread data from super globals
- request::reset();
-
$result = request_var($path, $default);
$this->assertEquals($expected, $result, 'Testing deep access to multidimensional input arrays: ' . $path);
}
@@ -92,7 +111,7 @@ class phpbb_request_request_var_test extends phpbb_test_case
array(array('var', 0, 'b', true), array(0 => ''), array(5 => 'c', 6 => 'd')),
);
}
-
+*/
public static function request_variables()
{
return array(
@@ -193,6 +212,7 @@ class phpbb_request_request_var_test extends phpbb_test_case
'abc' => array()
)
),
+ /* 3-dimensional (not supported atm!
array(
// input:
array(
@@ -237,6 +257,7 @@ class phpbb_request_request_var_test extends phpbb_test_case
'ä' => array(4 => array('a' => 2, 'ö' => 3)),
)
),
+ */
);
}
diff --git a/tests/security/all_tests.php b/tests/security/all_tests.php
index 0132e594b9..bff3ca82ab 100644
--- a/tests/security/all_tests.php
+++ b/tests/security/all_tests.php
@@ -8,8 +8,6 @@
*
*/
-define('IN_PHPBB', true);
-
if (!defined('PHPUnit_MAIN_METHOD'))
{
define('PHPUnit_MAIN_METHOD', 'phpbb_security_all_tests::main');
@@ -28,7 +26,7 @@ class phpbb_security_all_tests extends PHPUnit_Framework_TestSuite
*/
protected function setUp()
{
- global $user;
+ global $user, $phpbb_root_path;
// Put this into a global function being run by every test to init a proper user session
$_SERVER['HTTP_HOST'] = 'localhost';
@@ -57,7 +55,7 @@ class phpbb_security_all_tests extends PHPUnit_Framework_TestSuite
$user->referer = (!empty($_SERVER['HTTP_REFERER'])) ? htmlspecialchars((string) $_SERVER['HTTP_REFERER']) : '';
$user->forwarded_for = (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) ? (string) $_SERVER['HTTP_X_FORWARDED_FOR'] : '';
$user->host = (!empty($_SERVER['HTTP_HOST'])) ? (string) strtolower($_SERVER['HTTP_HOST']) : ((!empty($_SERVER['SERVER_NAME'])) ? $_SERVER['SERVER_NAME'] : getenv('SERVER_NAME'));
- $user->page = session::extract_current_page(PHPBB_ROOT_PATH);
+ $user->page = session::extract_current_page($phpbb_root_path);
}
protected function tearDown()
diff --git a/tests/security/extract_current_page.php b/tests/security/extract_current_page.php
index 9e04649f80..2b61ac7062 100644
--- a/tests/security/extract_current_page.php
+++ b/tests/security/extract_current_page.php
@@ -8,8 +8,6 @@
*
*/
-define('IN_PHPBB', true);
-
require_once 'test_framework/framework.php';
require_once '../phpBB/includes/functions.php';
@@ -53,5 +51,3 @@ class phpbb_security_extract_current_page_test extends phpbb_test_case
$this->assertEquals($expected, $result['query_string'], $label);
}
}
-
-?> \ No newline at end of file
diff --git a/tests/security/redirect.php b/tests/security/redirect.php
index 24ad60b0d1..1d565ec7e3 100644
--- a/tests/security/redirect.php
+++ b/tests/security/redirect.php
@@ -8,13 +8,8 @@
*
*/
-define('IN_PHPBB', true);
-
require_once 'test_framework/framework.php';
-define('PHPBB_ROOT_PATH', './../phpBB/');
-define('PHP_EXT', 'php');
-
require_once '../phpBB/includes/functions.php';
require_once '../phpBB/includes/session.php';
@@ -36,7 +31,7 @@ class phpbb_security_redirect_test extends phpbb_test_case
protected function setUp()
{
$GLOBALS['config'] = array(
- 'force_server_vars' => 0,
+ 'force_server_vars' => '0',
);
}
@@ -61,5 +56,3 @@ class phpbb_security_redirect_test extends phpbb_test_case
}
}
}
-
-?> \ No newline at end of file
diff --git a/tests/template/all_tests.php b/tests/template/all_tests.php
index beb064a396..b4f6f741ca 100644
--- a/tests/template/all_tests.php
+++ b/tests/template/all_tests.php
@@ -8,8 +8,6 @@
*
*/
-define('IN_PHPBB', true);
-
if (!defined('PHPUnit_MAIN_METHOD'))
{
define('PHPUnit_MAIN_METHOD', 'phpbb_template_all_tests::main');
@@ -40,5 +38,4 @@ class phpbb_template_all_tests
if (PHPUnit_MAIN_METHOD == 'phpbb_template_all_tests::main')
{
phpbb_template_all_tests::main();
-}
-?> \ No newline at end of file
+} \ No newline at end of file
diff --git a/tests/template/template.php b/tests/template/template.php
index e75e8a2618..bde1c55e9d 100644
--- a/tests/template/template.php
+++ b/tests/template/template.php
@@ -8,13 +8,9 @@
*
*/
-define('IN_PHPBB', true);
-define('PHP_EXT', 'php');
-define('PHPBB_ROOT_PATH', '../phpBB/');
-
require_once 'test_framework/framework.php';
-require_once '../phpBB/includes/core/bootstrap.php';
+require_once '../phpBB/includes/template.php';
class phpbb_template_template_test extends phpbb_test_case
{
@@ -22,7 +18,7 @@ class phpbb_template_template_test extends phpbb_test_case
private $template_path;
// Keep the contents of the cache for debugging?
- const PRESERVE_CACHE = true;
+ const PRESERVE_CACHE = false;
private function display($handle)
{
@@ -39,7 +35,7 @@ class phpbb_template_template_test extends phpbb_test_case
private function setup_engine()
{
$this->template_path = dirname(__FILE__) . '/templates';
- $this->template = new phpbb_template;
+ $this->template = new template();
$this->template->set_custom_template($this->template_path, 'tests');
}
@@ -58,7 +54,7 @@ class phpbb_template_template_test extends phpbb_test_case
unlink($file);
}
- phpbb::$config = array(
+ $GLOBALS['config'] = array(
'load_tplcompile' => true,
'tpl_allow_php' => false,
);
@@ -269,61 +265,25 @@ class phpbb_template_template_test extends phpbb_test_case
$this->assertFileNotExists($this->template_path . '/' . $filename, 'Testing missing file, file cannot exist');
$expecting = sprintf('template->_tpl_load_file(): File %s does not exist or is empty', realpath($this->template_path) . '/' . $filename);
+ $this->setExpectedTriggerError(E_USER_ERROR, $expecting);
- try
- {
- $this->display('test');
- }
- catch (ErrorException $e)
- {
- $this->assertEquals($expecting, $e->getMessage());
-
- if ($expecting != $e->getMessage())
- {
- // Unrelated error message throw it out
- throw $e;
- }
- }
+ $this->display('test');
}
public function test_empty_file()
{
$expecting = 'template->set_filenames: Empty filename specified for test';
- try
- {
- $this->template->set_filenames(array('test' => ''));
- }
- catch (ErrorException $e)
- {
- $this->assertEquals($expecting, $e->getMessage());
-
- if ($expecting != $e->getMessage())
- {
- // Unrelated error message throw it out
- throw $e;
- }
- }
+ $this->setExpectedTriggerError(E_USER_ERROR, $expecting);
+ $this->template->set_filenames(array('test' => ''));
}
public function test_invalid_handle()
{
$expecting = 'template->_tpl_load(): No file specified for handle test';
+ $this->setExpectedTriggerError(E_USER_ERROR, $expecting);
- try
- {
- $this->display('test');
- }
- catch (ErrorException $e)
- {
- $this->assertEquals($expecting, $e->getMessage());
-
- if ($expecting != $e->getMessage())
- {
- // Unrelated error message throw it out
- throw $e;
- }
- }
+ $this->display('test');
}
private function run_template($file, array $vars, array $block_vars, array $destroy, $expected, $cache_file)
@@ -371,7 +331,8 @@ class phpbb_template_template_test extends phpbb_test_case
*/
public function test_template($file, array $vars, array $block_vars, array $destroy, $expected)
{
- $cache_file = $this->template->cachepath . str_replace('/', '.', $file) . '.' . PHP_EXT;
+ global $phpEx;
+ $cache_file = $this->template->cachepath . str_replace('/', '.', $file) . '.' . $phpEx;
$this->assertFileNotExists($cache_file);
@@ -385,7 +346,6 @@ class phpbb_template_template_test extends phpbb_test_case
/**
* @dataProvider template_data
- */
public function test_assign_display($file, array $vars, array $block_vars, array $destroy, $expected)
{
$this->template->set_filenames(array(
@@ -415,16 +375,19 @@ class phpbb_template_template_test extends phpbb_test_case
public function test_php()
{
- phpbb::$config['tpl_allow_php'] = true;
+ global $phpEx;
+
+ $GLOBALS['config']['tpl_allow_php'] = true;
- $cache_file = $this->template->cachepath . 'php.html.' . PHP_EXT;
+ $cache_file = $this->template->cachepath . 'php.html.' . $phpEx;
$this->assertFileNotExists($cache_file);
$this->run_template('php.html', array(), array(), array(), 'test', $cache_file);
- phpbb::$config['tpl_allow_php'] = false;
+ $GLOBALS['config']['tpl_allow_php'] = false;
}
+*/
/*
public function test_includephp()
{
@@ -678,7 +641,6 @@ EOT
/**
* @dataProvider alter_block_array_data
- */
public function test_alter_block_array($alter_block, array $vararray, $key, $mode, $expect, $description)
{
$this->template->set_filenames(array('test' => 'loop_nested.html'));
@@ -700,5 +662,5 @@ EOT
$this->template->alter_block_array($alter_block, $vararray, $key, $mode);
$this->assertEquals($expect, $this->display('test'), $description);
}
+ */
}
-?> \ No newline at end of file
diff --git a/tests/test_framework/framework.php b/tests/test_framework/framework.php
index d8fa40e102..01afd4e37e 100644
--- a/tests/test_framework/framework.php
+++ b/tests/test_framework/framework.php
@@ -1,5 +1,23 @@
<?php
+define('IN_PHPBB', true);
+$phpbb_root_path = '../phpBB/';
+$phpEx = 'php';
+$table_prefix = '';
+
+// If we are on PHP >= 6.0.0 we do not need some code
+if (version_compare(PHP_VERSION, '6.0.0-dev', '>='))
+{
+ define('STRIP', false);
+}
+else
+{
+ @set_magic_quotes_runtime(0);
+ define('STRIP', (get_magic_quotes_gpc()) ? true : false);
+}
+
+require_once $phpbb_root_path . 'includes/constants.php';
+
// require at least PHPUnit 3.3.0
require_once 'PHPUnit/Runner/Version.php';
if (version_compare(PHPUnit_Runner_Version::id(), '3.3.0', '<'))
diff --git a/tests/text_processing/all_tests.php b/tests/text_processing/all_tests.php
index 7bb84057a9..d53dd1127e 100644
--- a/tests/text_processing/all_tests.php
+++ b/tests/text_processing/all_tests.php
@@ -8,8 +8,6 @@
*
*/
-define('IN_PHPBB', true);
-
if (!defined('PHPUnit_MAIN_METHOD'))
{
define('PHPUnit_MAIN_METHOD', 'phpbb_text_processing_all_tests::main');
@@ -41,4 +39,3 @@ if (PHPUnit_MAIN_METHOD == 'phpbb_text_processing_all_tests::main')
{
phpbb_text_processing_all_tests::main();
}
-?> \ No newline at end of file
diff --git a/tests/text_processing/make_clickable.php b/tests/text_processing/make_clickable.php
index 994cbd023c..25199c428a 100644
--- a/tests/text_processing/make_clickable.php
+++ b/tests/text_processing/make_clickable.php
@@ -8,8 +8,6 @@
*
*/
-define('IN_PHPBB', true);
-
require_once 'test_framework/framework.php';
require_once '../phpBB/includes/functions.php';
@@ -66,7 +64,7 @@ class phpbb_text_processing_make_clickable_test extends phpbb_test_case
{
foreach ($urls as $url => $url_type)
{
- $input = $prefix . $schema . $url . $suffix;
+ $input = $prefix . $url . $suffix;
// no valid url => no change
$output = $input;
@@ -106,4 +104,3 @@ class phpbb_text_processing_make_clickable_test extends phpbb_test_case
}
}
-?> \ No newline at end of file
diff --git a/tests/utf/all_tests.php b/tests/utf/all_tests.php
index bee5df7365..bccabf6529 100644
--- a/tests/utf/all_tests.php
+++ b/tests/utf/all_tests.php
@@ -8,8 +8,6 @@
*
*/
-define('IN_PHPBB', true);
-
if (!defined('PHPUnit_MAIN_METHOD'))
{
define('PHPUnit_MAIN_METHOD', 'phpbb_utf_all_tests::main');
@@ -43,4 +41,3 @@ if (PHPUnit_MAIN_METHOD == 'phpbb_utf_all_tests::main')
{
phpbb_utf_all_tests::main();
}
-?> \ No newline at end of file
diff --git a/tests/utf/utf8_clean_string_test.php b/tests/utf/utf8_clean_string_test.php
index e7fa7280c9..bd9e3f5f26 100644
--- a/tests/utf/utf8_clean_string_test.php
+++ b/tests/utf/utf8_clean_string_test.php
@@ -8,12 +8,7 @@
*
*/
-define('IN_PHPBB', true);
-
require_once 'test_framework/framework.php';
-
-define(PHPBB_ROOT_PATH, '../phpBB/');
-define(PHP_EXT, 'php');
require_once '../phpBB/includes/utf/utf_tools.php';
class phpbb_utf_utf8_clean_string_test extends phpbb_test_case
@@ -35,4 +30,3 @@ class phpbb_utf_utf8_clean_string_test extends phpbb_test_case
$this->assertEquals($output, utf8_clean_string($input), $label);
}
}
-?> \ No newline at end of file
diff --git a/tests/utf/utf8_wordwrap_test.php b/tests/utf/utf8_wordwrap_test.php
index c35069d734..51245ec418 100644
--- a/tests/utf/utf8_wordwrap_test.php
+++ b/tests/utf/utf8_wordwrap_test.php
@@ -8,8 +8,6 @@
*
*/
-define('IN_PHPBB', true);
-
require_once 'test_framework/framework.php';
require_once '../phpBB/includes/utf/utf_tools.php';
@@ -84,4 +82,3 @@ class phpbb_utf_utf8_wordwrap_test extends phpbb_test_case
$this->assertEquals($expected, $phpbb_utf8_wordwrap, 'Checking UTF-8 cutting long words');
}
}
-?> \ No newline at end of file