|
From: Meik S. <acy...@ph...> - 2009-10-05 16:16:44
|
Author: acydburn
Date: Mon Oct 5 17:15:54 2009
New Revision: 10212
Log:
adjust tests a little bit to let them work again in trunk (not adjusted template/bbcode yet)
Modified:
trunk/tests/all_tests.php
trunk/tests/request/all_tests.php
trunk/tests/request/request_var.php
trunk/tests/security/all_tests.php
trunk/tests/security/extract_current_page.php
trunk/tests/security/redirect.php
trunk/tests/template/all_tests.php
trunk/tests/template/template.php
trunk/tests/test_framework/framework.php
trunk/tests/text_processing/all_tests.php
trunk/tests/text_processing/make_clickable.php
trunk/tests/utf/all_tests.php
trunk/tests/utf/utf8_clean_string_test.php
trunk/tests/utf/utf8_wordwrap_test.php
Modified: trunk/tests/all_tests.php
==============================================================================
*** trunk/tests/all_tests.php (original)
--- trunk/tests/all_tests.php Mon Oct 5 17:15:54 2009
***************
*** 8,15 ****
*
*/
- define('IN_PHPBB', true);
-
if (!defined('PHPUnit_MAIN_METHOD'))
{
define('PHPUnit_MAIN_METHOD', 'phpbb_all_tests::main');
--- 8,13 ----
***************
*** 18,28 ****
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 'text_processing/all_tests.php';
// exclude the test directory from code coverage reports
--- 16,26 ----
require_once 'test_framework/framework.php';
require_once 'PHPUnit/TextUI/TestRunner.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 'bbcode/all_tests.php';
require_once 'text_processing/all_tests.php';
// exclude the test directory from code coverage reports
***************
*** 39,50 ****
{
$suite = new PHPUnit_Framework_TestSuite('phpBB');
! $suite->addTest(phpbb_bbcode_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_text_processing_all_tests::suite());
- $suite->addTest(phpbb_utf_all_tests::suite());
return $suite;
}
--- 37,48 ----
{
$suite = new PHPUnit_Framework_TestSuite('phpBB');
! $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_bbcode_all_tests::suite());
$suite->addTest(phpbb_text_processing_all_tests::suite());
return $suite;
}
***************
*** 54,58 ****
{
phpbb_all_tests::main();
}
-
- ?>
\ No newline at end of file
--- 52,54 ----
Modified: trunk/tests/request/all_tests.php
==============================================================================
*** trunk/tests/request/all_tests.php (original)
--- trunk/tests/request/all_tests.php Mon Oct 5 17:15:54 2009
***************
*** 8,15 ****
*
*/
- define('IN_PHPBB', true);
-
if (!defined('PHPUnit_MAIN_METHOD'))
{
define('PHPUnit_MAIN_METHOD', 'phpbb_request_all_tests::main');
--- 8,13 ----
***************
*** 19,25 ****
require_once 'PHPUnit/TextUI/TestRunner.php';
require_once 'request/request_var.php';
- require_once 'request/request_class.php';
class phpbb_request_all_tests
{
--- 17,22 ----
***************
*** 32,38 ****
{
$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;
--- 29,34 ----
Modified: trunk/tests/request/request_var.php
==============================================================================
*** trunk/tests/request/request_var.php (original)
--- trunk/tests/request/request_var.php Mon Oct 5 17:15:54 2009
***************
*** 8,17 ****
*
*/
- 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
--- 8,14 ----
***************
*** 22,34 ****
public function test_post($variable_value, $default, $multibyte, $expected)
{
$variable_name = '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' : '');
--- 19,29 ----
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;
$result = request_var($variable_name, $default, $multibyte);
$label = 'Requesting POST variable, converting from ' . gettype($variable_value) . ' to ' . gettype($default) . (($multibyte) ? ' multibyte' : '');
***************
*** 41,53 ****
public function test_get($variable_value, $default, $multibyte, $expected)
{
$variable_name = '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' : '');
--- 36,46 ----
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;
$result = request_var($variable_name, $default, $multibyte);
$label = 'Requesting GET variable, converting from ' . gettype($variable_value) . ' to ' . gettype($default) . (($multibyte) ? ' multibyte' : '');
***************
*** 55,64 ****
}
/**
! * @dataProvider deep_access
*/
public function test_deep_multi_dim_array_access($path, $default, $expected)
{
$_REQUEST['var'] = array(
0 => array(
'b' => array(
--- 48,86 ----
}
/**
! * @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,83 ****
),
);
- // reread data from super globals
- request::reset();
-
$result = request_var($path, $default);
$this->assertEquals($expected, $result, 'Testing deep access to multidimensional input arrays: ' . $path);
}
--- 97,102 ----
***************
*** 92,98 ****
array(array('var', 0, 'b', true), array(0 => ''), array(5 => 'c', 6 => 'd')),
);
}
!
public static function request_variables()
{
return array(
--- 111,117 ----
array(array('var', 0, 'b', true), array(0 => ''), array(5 => 'c', 6 => 'd')),
);
}
! */
public static function request_variables()
{
return array(
***************
*** 193,198 ****
--- 212,218 ----
'abc' => array()
)
),
+ /* 3-dimensional (not supported atm!
array(
// input:
array(
***************
*** 237,242 ****
--- 257,263 ----
'ä' => array(4 => array('a' => 2, 'ö' => 3)),
)
),
+ */
);
}
Modified: trunk/tests/security/all_tests.php
==============================================================================
*** trunk/tests/security/all_tests.php (original)
--- trunk/tests/security/all_tests.php Mon Oct 5 17:15:54 2009
***************
*** 8,15 ****
*
*/
- define('IN_PHPBB', true);
-
if (!defined('PHPUnit_MAIN_METHOD'))
{
define('PHPUnit_MAIN_METHOD', 'phpbb_security_all_tests::main');
--- 8,13 ----
***************
*** 28,34 ****
*/
protected function setUp()
{
! global $user;
// Put this into a global function being run by every test to init a proper user session
$_SERVER['HTTP_HOST'] = 'localhost';
--- 26,32 ----
*/
protected function setUp()
{
! 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,63 ****
$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);
}
protected function tearDown()
--- 55,61 ----
$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);
}
protected function tearDown()
Modified: trunk/tests/security/extract_current_page.php
==============================================================================
*** trunk/tests/security/extract_current_page.php (original)
--- trunk/tests/security/extract_current_page.php Mon Oct 5 17:15:54 2009
***************
*** 8,15 ****
*
*/
- define('IN_PHPBB', true);
-
require_once 'test_framework/framework.php';
require_once '../phpBB/includes/functions.php';
--- 8,13 ----
***************
*** 53,57 ****
$this->assertEquals($expected, $result['query_string'], $label);
}
}
-
- ?>
\ No newline at end of file
--- 51,53 ----
Modified: trunk/tests/security/redirect.php
==============================================================================
*** trunk/tests/security/redirect.php (original)
--- trunk/tests/security/redirect.php Mon Oct 5 17:15:54 2009
***************
*** 8,20 ****
*
*/
- 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';
--- 8,15 ----
***************
*** 36,42 ****
protected function setUp()
{
$GLOBALS['config'] = array(
! 'force_server_vars' => 0,
);
}
--- 31,37 ----
protected function setUp()
{
$GLOBALS['config'] = array(
! 'force_server_vars' => '0',
);
}
***************
*** 61,65 ****
}
}
}
-
- ?>
\ No newline at end of file
--- 56,58 ----
Modified: trunk/tests/template/all_tests.php
==============================================================================
*** trunk/tests/template/all_tests.php (original)
--- trunk/tests/template/all_tests.php Mon Oct 5 17:15:54 2009
***************
*** 8,15 ****
*
*/
- define('IN_PHPBB', true);
-
if (!defined('PHPUnit_MAIN_METHOD'))
{
define('PHPUnit_MAIN_METHOD', 'phpbb_template_all_tests::main');
--- 8,13 ----
***************
*** 40,44 ****
if (PHPUnit_MAIN_METHOD == 'phpbb_template_all_tests::main')
{
phpbb_template_all_tests::main();
! }
! ?>
\ No newline at end of file
--- 38,41 ----
if (PHPUnit_MAIN_METHOD == 'phpbb_template_all_tests::main')
{
phpbb_template_all_tests::main();
! }
\ No newline at end of file
Modified: trunk/tests/template/template.php
==============================================================================
*** trunk/tests/template/template.php (original)
--- trunk/tests/template/template.php Mon Oct 5 17:15:54 2009
***************
*** 8,20 ****
*
*/
- 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';
class phpbb_template_template_test extends phpbb_test_case
{
--- 8,16 ----
*
*/
require_once 'test_framework/framework.php';
! require_once '../phpBB/includes/template.php';
class phpbb_template_template_test extends phpbb_test_case
{
***************
*** 22,28 ****
private $template_path;
// Keep the contents of the cache for debugging?
! const PRESERVE_CACHE = true;
private function display($handle)
{
--- 18,24 ----
private $template_path;
// Keep the contents of the cache for debugging?
! const PRESERVE_CACHE = false;
private function display($handle)
{
***************
*** 39,45 ****
private function setup_engine()
{
$this->template_path = dirname(__FILE__) . '/templates';
! $this->template = new phpbb_template;
$this->template->set_custom_template($this->template_path, 'tests');
}
--- 35,41 ----
private function setup_engine()
{
$this->template_path = dirname(__FILE__) . '/templates';
! $this->template = new template();
$this->template->set_custom_template($this->template_path, 'tests');
}
***************
*** 58,64 ****
unlink($file);
}
! phpbb::$config = array(
'load_tplcompile' => true,
'tpl_allow_php' => false,
);
--- 54,60 ----
unlink($file);
}
! $GLOBALS['config'] = array(
'load_tplcompile' => true,
'tpl_allow_php' => false,
);
***************
*** 269,329 ****
$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);
! try
! {
! $this->display('test');
! }
! catch (ErrorException $e)
! {
! $this->assertEquals($expecting, $e->getMessage());
!
! if ($expecting != $e->getMessage())
! {
! // Unrelated error message throw it out
! throw $e;
! }
! }
}
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;
! }
! }
}
public function test_invalid_handle()
{
$expecting = 'template->_tpl_load(): No file specified for handle test';
! try
! {
! $this->display('test');
! }
! catch (ErrorException $e)
! {
! $this->assertEquals($expecting, $e->getMessage());
!
! if ($expecting != $e->getMessage())
! {
! // Unrelated error message throw it out
! throw $e;
! }
! }
}
private function run_template($file, array $vars, array $block_vars, array $destroy, $expected, $cache_file)
--- 265,289 ----
$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);
! $this->display('test');
}
public function test_empty_file()
{
$expecting = 'template->set_filenames: Empty filename specified for test';
! $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);
! $this->display('test');
}
private function run_template($file, array $vars, array $block_vars, array $destroy, $expected, $cache_file)
***************
*** 371,377 ****
*/
public function test_template($file, array $vars, array $block_vars, array $destroy, $expected)
{
! $cache_file = $this->template->cachepath . str_replace('/', '.', $file) . '.' . PHP_EXT;
$this->assertFileNotExists($cache_file);
--- 331,338 ----
*/
public function test_template($file, array $vars, array $block_vars, array $destroy, $expected)
{
! global $phpEx;
! $cache_file = $this->template->cachepath . str_replace('/', '.', $file) . '.' . $phpEx;
$this->assertFileNotExists($cache_file);
***************
*** 385,391 ****
/**
* @dataProvider template_data
- */
public function test_assign_display($file, array $vars, array $block_vars, array $destroy, $expected)
{
$this->template->set_filenames(array(
--- 346,351 ----
***************
*** 415,430 ****
public function test_php()
{
! phpbb::$config['tpl_allow_php'] = true;
! $cache_file = $this->template->cachepath . 'php.html.' . PHP_EXT;
$this->assertFileNotExists($cache_file);
$this->run_template('php.html', array(), array(), array(), 'test', $cache_file);
! phpbb::$config['tpl_allow_php'] = false;
}
/*
public function test_includephp()
{
--- 375,393 ----
public function test_php()
{
! global $phpEx;
! $GLOBALS['config']['tpl_allow_php'] = true;
!
! $cache_file = $this->template->cachepath . 'php.html.' . $phpEx;
$this->assertFileNotExists($cache_file);
$this->run_template('php.html', array(), array(), array(), 'test', $cache_file);
! $GLOBALS['config']['tpl_allow_php'] = false;
}
+ */
/*
public function test_includephp()
{
***************
*** 678,684 ****
/**
* @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'));
--- 641,646 ----
***************
*** 700,704 ****
$this->template->alter_block_array($alter_block, $vararray, $key, $mode);
$this->assertEquals($expect, $this->display('test'), $description);
}
}
- ?>
\ No newline at end of file
--- 662,666 ----
$this->template->alter_block_array($alter_block, $vararray, $key, $mode);
$this->assertEquals($expect, $this->display('test'), $description);
}
+ */
}
Modified: trunk/tests/test_framework/framework.php
==============================================================================
*** trunk/tests/test_framework/framework.php (original)
--- trunk/tests/test_framework/framework.php Mon Oct 5 17:15:54 2009
***************
*** 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', '<'))
Modified: trunk/tests/text_processing/all_tests.php
==============================================================================
*** trunk/tests/text_processing/all_tests.php (original)
--- trunk/tests/text_processing/all_tests.php Mon Oct 5 17:15:54 2009
***************
*** 8,15 ****
*
*/
- define('IN_PHPBB', true);
-
if (!defined('PHPUnit_MAIN_METHOD'))
{
define('PHPUnit_MAIN_METHOD', 'phpbb_text_processing_all_tests::main');
--- 8,13 ----
***************
*** 41,44 ****
{
phpbb_text_processing_all_tests::main();
}
- ?>
\ No newline at end of file
--- 39,41 ----
Modified: trunk/tests/text_processing/make_clickable.php
==============================================================================
*** trunk/tests/text_processing/make_clickable.php (original)
--- trunk/tests/text_processing/make_clickable.php Mon Oct 5 17:15:54 2009
***************
*** 8,15 ****
*
*/
- define('IN_PHPBB', true);
-
require_once 'test_framework/framework.php';
require_once '../phpBB/includes/functions.php';
--- 8,13 ----
***************
*** 66,72 ****
{
foreach ($urls as $url => $url_type)
{
! $input = $prefix . $schema . $url . $suffix;
// no valid url => no change
$output = $input;
--- 64,70 ----
{
foreach ($urls as $url => $url_type)
{
! $input = $prefix . $url . $suffix;
// no valid url => no change
$output = $input;
***************
*** 106,109 ****
}
}
- ?>
\ No newline at end of file
--- 104,106 ----
Modified: trunk/tests/utf/all_tests.php
==============================================================================
*** trunk/tests/utf/all_tests.php (original)
--- trunk/tests/utf/all_tests.php Mon Oct 5 17:15:54 2009
***************
*** 8,15 ****
*
*/
- define('IN_PHPBB', true);
-
if (!defined('PHPUnit_MAIN_METHOD'))
{
define('PHPUnit_MAIN_METHOD', 'phpbb_utf_all_tests::main');
--- 8,13 ----
***************
*** 43,46 ****
{
phpbb_utf_all_tests::main();
}
- ?>
\ No newline at end of file
--- 41,43 ----
Modified: trunk/tests/utf/utf8_clean_string_test.php
==============================================================================
*** trunk/tests/utf/utf8_clean_string_test.php (original)
--- trunk/tests/utf/utf8_clean_string_test.php Mon Oct 5 17:15:54 2009
***************
*** 8,19 ****
*
*/
- 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
--- 8,14 ----
***************
*** 35,38 ****
$this->assertEquals($output, utf8_clean_string($input), $label);
}
}
- ?>
\ No newline at end of file
--- 30,32 ----
Modified: trunk/tests/utf/utf8_wordwrap_test.php
==============================================================================
*** trunk/tests/utf/utf8_wordwrap_test.php (original)
--- trunk/tests/utf/utf8_wordwrap_test.php Mon Oct 5 17:15:54 2009
***************
*** 8,15 ****
*
*/
- define('IN_PHPBB', true);
-
require_once 'test_framework/framework.php';
require_once '../phpBB/includes/utf/utf_tools.php';
--- 8,13 ----
***************
*** 84,87 ****
$this->assertEquals($expected, $phpbb_utf8_wordwrap, 'Checking UTF-8 cutting long words');
}
}
- ?>
\ No newline at end of file
--- 82,84 ----
|