mirror of
https://github.com/phpbb/phpbb.git
synced 2025-04-21 00:02:18 +02:00
- adding tests for the new request class and extending the tests for request_var to include deep direct access to multidimensional arrays and arbitrary number of dimensions
git-svn-id: file:///svn/phpbb/trunk@9105 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
parent
c8cba06910
commit
0b11951412
@ -15,10 +15,11 @@ if (!defined('PHPUnit_MAIN_METHOD'))
|
||||
define('PHPUnit_MAIN_METHOD', 'phpbb_request_all_tests::main');
|
||||
}
|
||||
|
||||
require_once 'PHPUnit/Framework.php';
|
||||
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
|
||||
{
|
||||
@ -31,6 +32,7 @@ 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;
|
||||
@ -41,4 +43,3 @@ if (PHPUnit_MAIN_METHOD == 'phpbb_request_all_tests::main')
|
||||
{
|
||||
phpbb_request_all_tests::main();
|
||||
}
|
||||
?>
|
74
tests/request/request_class.php
Normal file
74
tests/request/request_class.php
Normal file
@ -0,0 +1,74 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @version $Id$
|
||||
* @copyright (c) 2008 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
||||
*
|
||||
*/
|
||||
|
||||
define('IN_PHPBB', true);
|
||||
|
||||
require_once 'test_framework/framework.php';
|
||||
|
||||
require_once '../phpBB/includes/functions.php';
|
||||
|
||||
class phpbb_request_request_class_test extends phpbb_test_case
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
$_POST['test'] = 1;
|
||||
$_GET['test'] = 2;
|
||||
$_COOKIE['test'] = 3;
|
||||
$_REQUEST['test'] = 3;
|
||||
|
||||
// reread data from super globals
|
||||
request::reset();
|
||||
}
|
||||
|
||||
public function test_toggle_super_globals()
|
||||
{
|
||||
// toggle super globals
|
||||
request::disable_super_globals();
|
||||
request::enable_super_globals();
|
||||
|
||||
$this->assertEquals(1, $_POST['test'], 'Checking $_POST toggling via request::dis/enable_super_globals');
|
||||
$this->assertEquals(2, $_GET['test'], 'Checking $_GET toggling via request::dis/enable_super_globals');
|
||||
$this->assertEquals(3, $_COOKIE['test'], 'Checking $_COOKIE toggling via request::dis/enable_super_globals');
|
||||
$this->assertEquals(3, $_REQUEST['test'], 'Checking $_REQUEST toggling via request::dis/enable_super_globals');
|
||||
|
||||
$_POST['x'] = 2;
|
||||
$this->assertEquals($_POST, $GLOBALS['_POST'], 'Checking whether $_POST can still be accessed via $GLOBALS[\'_POST\']');
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks that directly accessing $_POST will trigger
|
||||
* an error.
|
||||
*/
|
||||
public function test_disable_post_super_global()
|
||||
{
|
||||
request::disable_super_globals();
|
||||
|
||||
$this->setExpectedTriggerError(E_USER_ERROR);
|
||||
$_POST['test'] = 3;
|
||||
}
|
||||
|
||||
public function test_is_set_post()
|
||||
{
|
||||
$_GET['unset'] = '';
|
||||
request::reset();
|
||||
|
||||
$this->assertTrue(request::is_set_post('test'));
|
||||
$this->assertFalse(request::is_set_post('unset'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes sure super globals work properly after these tests
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
request::enable_super_globals();
|
||||
request::reset();
|
||||
}
|
||||
}
|
@ -10,12 +10,89 @@
|
||||
|
||||
define('IN_PHPBB', true);
|
||||
|
||||
require_once 'PHPUnit/Framework.php';
|
||||
require_once 'test_framework/framework.php';
|
||||
|
||||
require_once '../phpBB/includes/functions.php';
|
||||
|
||||
class phpbb_request_request_var_test extends PHPUnit_Framework_TestCase
|
||||
class phpbb_request_request_var_test extends phpbb_test_case
|
||||
{
|
||||
/**
|
||||
* @dataProvider request_variables
|
||||
*/
|
||||
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' : '');
|
||||
$this->assertEquals($expected, $result, $label);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider request_variables
|
||||
*/
|
||||
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' : '');
|
||||
$this->assertEquals($expected, $result, $label);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider deep_access
|
||||
*/
|
||||
public function test_deep_multi_dim_array_access($path, $default, $expected)
|
||||
{
|
||||
$_REQUEST['var'] = array(
|
||||
0 => array(
|
||||
'b' => array(
|
||||
true => array(
|
||||
5 => 'c',
|
||||
6 => 'd',
|
||||
),
|
||||
),
|
||||
),
|
||||
2 => array(
|
||||
3 => array(
|
||||
false => 5,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// reread data from super globals
|
||||
request::reset();
|
||||
|
||||
$result = request_var($path, $default);
|
||||
$this->assertEquals($expected, $result, 'Testing deep access to multidimensional input arrays: ' . $path);
|
||||
}
|
||||
|
||||
public static function deep_access()
|
||||
{
|
||||
return array(
|
||||
// array(path, default, expected result)
|
||||
array(array('var', 0, 'b', true, 5), '', 'c'),
|
||||
array(array('var', 0, 'b', true, 6), '', 'd'),
|
||||
array(array('var', 2, 3, false), 0, 5),
|
||||
array(array('var', 0, 'b', true), array(0 => ''), array(5 => 'c', 6 => 'd')),
|
||||
);
|
||||
}
|
||||
|
||||
public static function request_variables()
|
||||
{
|
||||
return array(
|
||||
@ -81,9 +158,7 @@ class phpbb_request_request_var_test extends PHPUnit_Framework_TestCase
|
||||
// input:
|
||||
'',
|
||||
// default:
|
||||
array(
|
||||
array(0)
|
||||
),
|
||||
array(array(0)),
|
||||
false,
|
||||
// expected:
|
||||
array()
|
||||
@ -95,9 +170,7 @@ class phpbb_request_request_var_test extends PHPUnit_Framework_TestCase
|
||||
'abc' => 'abc'
|
||||
),
|
||||
// default:
|
||||
array(
|
||||
'' => array('')
|
||||
),
|
||||
array('' => array('')),
|
||||
false,
|
||||
// expected:
|
||||
array(
|
||||
@ -112,9 +185,7 @@ class phpbb_request_request_var_test extends PHPUnit_Framework_TestCase
|
||||
'abc' => 'abc'
|
||||
),
|
||||
// default:
|
||||
array(
|
||||
'' => array(0)
|
||||
),
|
||||
array('' => array(0)),
|
||||
false,
|
||||
// expected:
|
||||
array(
|
||||
@ -122,39 +193,51 @@ class phpbb_request_request_var_test extends PHPUnit_Framework_TestCase
|
||||
'abc' => array()
|
||||
)
|
||||
),
|
||||
array(
|
||||
// input:
|
||||
array(
|
||||
0 => array(0 => array(3, '4', 'ab'), 1 => array()),
|
||||
1 => array(array(3, 4)),
|
||||
),
|
||||
// default:
|
||||
array(0 => array(0 => array(0))),
|
||||
false,
|
||||
// expected:
|
||||
array(
|
||||
0 => array(0 => array(3, 4, 0), 1 => array()),
|
||||
1 => array(array(3, 4))
|
||||
)
|
||||
),
|
||||
array(
|
||||
// input:
|
||||
array(
|
||||
'ü' => array(array('c' => 'd')),
|
||||
'ä' => array(4 => array('a' => 2, 'ö' => 3)),
|
||||
),
|
||||
// default:
|
||||
array('' => array(0 => array('' => 0))),
|
||||
false,
|
||||
// expected:
|
||||
array(
|
||||
'??' => array(4 => array('a' => 2, '??' => 3)),
|
||||
)
|
||||
),
|
||||
array(
|
||||
// input:
|
||||
array(
|
||||
'ü' => array(array('c' => 'd')),
|
||||
'ä' => array(4 => array('a' => 2, 'ö' => 3)),
|
||||
),
|
||||
// default:
|
||||
array('' => array(0 => array('' => 0))),
|
||||
true,
|
||||
// expected:
|
||||
array(
|
||||
'ü' => array(array('c' => 0)),
|
||||
'ä' => array(4 => array('a' => 2, 'ö' => 3)),
|
||||
)
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider request_variables
|
||||
*/
|
||||
public function test_post($variable_value, $default, $multibyte, $expected)
|
||||
{
|
||||
$variable_name = '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' : '');
|
||||
$this->assertEquals($expected, $result, $label);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider request_variables
|
||||
*/
|
||||
public function test_get($variable_value, $default, $multibyte, $expected)
|
||||
{
|
||||
$variable_name = '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' : '');
|
||||
$this->assertEquals($expected, $result, $label);
|
||||
}
|
||||
}
|
||||
?>
|
Loading…
x
Reference in New Issue
Block a user