aboutsummaryrefslogtreecommitdiffstats
path: root/tests/request/request_var.php
diff options
context:
space:
mode:
authorNils Adermann <naderman@naderman.de>2008-11-24 00:28:57 +0000
committerNils Adermann <naderman@naderman.de>2008-11-24 00:28:57 +0000
commit0b119514123bfe6aa99589957cbfcb9b21fbbb2c (patch)
tree8266cd6b3f52f830ef1de293cacfc13560d125cf /tests/request/request_var.php
parentc8cba06910c1f30469cc301c03afa1d5a431c568 (diff)
downloadforums-0b119514123bfe6aa99589957cbfcb9b21fbbb2c.tar
forums-0b119514123bfe6aa99589957cbfcb9b21fbbb2c.tar.gz
forums-0b119514123bfe6aa99589957cbfcb9b21fbbb2c.tar.bz2
forums-0b119514123bfe6aa99589957cbfcb9b21fbbb2c.tar.xz
forums-0b119514123bfe6aa99589957cbfcb9b21fbbb2c.zip
- 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
Diffstat (limited to 'tests/request/request_var.php')
-rw-r--r--tests/request/request_var.php169
1 files changed, 126 insertions, 43 deletions
diff --git a/tests/request/request_var.php b/tests/request/request_var.php
index c0ef3ddba8..549512753b 100644
--- a/tests/request/request_var.php
+++ b/tests/request/request_var.php
@@ -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);
- }
}
-?> \ No newline at end of file