mirror of
https://github.com/phpbb/phpbb.git
synced 2025-04-21 00:02:18 +02:00
- adding request_var tests
git-svn-id: file:///svn/phpbb/trunk@8549 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
parent
0d631c2ae0
commit
6871e7caa4
@ -20,6 +20,7 @@ require_once 'PHPUnit/TextUI/TestRunner.php';
|
||||
|
||||
require_once 'bbcode/all_tests.php';
|
||||
require_once 'utf/all_tests.php';
|
||||
require_once 'request/all_tests.php';
|
||||
|
||||
// exclude the test directory from code coverage reports
|
||||
PHPUnit_Util_Filter::addDirectoryToFilter('./');
|
||||
@ -37,6 +38,7 @@ class phpbb_all_tests
|
||||
|
||||
$suite->addTest(phpbb_bbcode_all_tests::suite());
|
||||
$suite->addTest(phpbb_utf_all_tests::suite());
|
||||
$suite->addTest(phpbb_request_all_tests::suite());
|
||||
|
||||
return $suite;
|
||||
}
|
||||
|
44
tests/request/all_tests.php
Normal file
44
tests/request/all_tests.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?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);
|
||||
|
||||
if (!defined('PHPUnit_MAIN_METHOD'))
|
||||
{
|
||||
define('PHPUnit_MAIN_METHOD', 'phpbb_request_all_tests::main');
|
||||
}
|
||||
|
||||
require_once 'PHPUnit/Framework.php';
|
||||
require_once 'PHPUnit/TextUI/TestRunner.php';
|
||||
|
||||
require_once 'request/request_var.php';
|
||||
|
||||
class phpbb_request_all_tests
|
||||
{
|
||||
public static function main()
|
||||
{
|
||||
PHPUnit_TextUI_TestRunner::run(self::suite());
|
||||
}
|
||||
|
||||
public static function suite()
|
||||
{
|
||||
$suite = new PHPUnit_Framework_TestSuite('phpBB Request Parameter Handling');
|
||||
|
||||
$suite->addTestSuite('phpbb_request_request_var_test');
|
||||
|
||||
return $suite;
|
||||
}
|
||||
}
|
||||
|
||||
if (PHPUnit_MAIN_METHOD == 'phpbb_request_all_tests::main')
|
||||
{
|
||||
phpbb_request_all_tests::main();
|
||||
}
|
||||
?>
|
160
tests/request/request_var.php
Normal file
160
tests/request/request_var.php
Normal file
@ -0,0 +1,160 @@
|
||||
<?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 'PHPUnit/Framework.php';
|
||||
|
||||
require_once '../phpBB/includes/functions.php';
|
||||
|
||||
class phpbb_request_request_var_test extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public static function request_variables()
|
||||
{
|
||||
return array(
|
||||
// strings
|
||||
array('abc', '', false, 'abc'),
|
||||
array(' some spaces ', '', true, 'some spaces'),
|
||||
array("\r\rsome\rcarriage\r\rreturns\r", '', true, "some\ncarriage\n\nreturns"),
|
||||
array("\n\nsome\ncarriage\n\nreturns\n", '', true, "some\ncarriage\n\nreturns"),
|
||||
array("\r\n\r\nsome\r\ncarriage\r\n\r\nreturns\r\n", '', true, "some\ncarriage\n\nreturns"),
|
||||
array("we\xC2\xA1rd\xE1\x9A\x80ch\xCE\xB1r\xC2\xADacters", '', true, "we\xC2\xA1rd\xE1\x9A\x80ch\xCE\xB1r\xC2\xADacters"),
|
||||
array("we\xC2\xA1rd\xE1\x9A\x80ch\xCE\xB1r\xC2\xADacters", '', false, "we??rd???ch??r??acters"),
|
||||
array("Some <html> \"entities\" like &", '', true, "Some <html> "entities" like &"),
|
||||
|
||||
// integers
|
||||
array('1234', 0, false, 1234),
|
||||
array('abc', 12, false, 0),
|
||||
array('324abc', 0, false, 324),
|
||||
|
||||
// string to array
|
||||
array('123', array(0), false, array()),
|
||||
array('123', array(''), false, array()),
|
||||
|
||||
// 1 dimensional arrays
|
||||
array(
|
||||
// input:
|
||||
array('123', 'abc'),
|
||||
// default:
|
||||
array(''),
|
||||
false,
|
||||
// expected:
|
||||
array('123', 'abc')
|
||||
),
|
||||
array(
|
||||
// input:
|
||||
array('123', 'abc'),
|
||||
// default:
|
||||
array(999),
|
||||
false,
|
||||
// expected:
|
||||
array(123, 0)
|
||||
),
|
||||
array(
|
||||
// input:
|
||||
array('xyz' => '123', 'abc' => 'abc'),
|
||||
// default:
|
||||
array('' => ''),
|
||||
false,
|
||||
// expected:
|
||||
array('xyz' => '123', 'abc' => 'abc')
|
||||
),
|
||||
array(
|
||||
// input:
|
||||
array('xyz' => '123', 'abc' => 'abc'),
|
||||
// default:
|
||||
array('' => 0),
|
||||
false,
|
||||
// expected:
|
||||
array('xyz' => 123, 'abc' => 0)
|
||||
),
|
||||
|
||||
// 2 dimensional arrays
|
||||
array(
|
||||
// input:
|
||||
'',
|
||||
// default:
|
||||
array(
|
||||
array(0)
|
||||
),
|
||||
false,
|
||||
// expected:
|
||||
array()
|
||||
),
|
||||
array(
|
||||
// input:
|
||||
array(
|
||||
'xyz' => array('123', 'def'),
|
||||
'abc' => 'abc'
|
||||
),
|
||||
// default:
|
||||
array(
|
||||
'' => array('')
|
||||
),
|
||||
false,
|
||||
// expected:
|
||||
array(
|
||||
'xyz' => array('123', 'def'),
|
||||
'abc' => array()
|
||||
)
|
||||
),
|
||||
array(
|
||||
// input:
|
||||
array(
|
||||
'xyz' => array('123', 'def'),
|
||||
'abc' => 'abc'
|
||||
),
|
||||
// default:
|
||||
array(
|
||||
'' => array(0)
|
||||
),
|
||||
false,
|
||||
// expected:
|
||||
array(
|
||||
'xyz' => array(123, 0),
|
||||
'abc' => array()
|
||||
)
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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