mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-08 04:18:52 +00:00
[ticket/17188] Add unit tests
Adds rxu's unit tests, with rubencm's fix PHPBB3-17188
This commit is contained in:
parent
8360752b2a
commit
d59a4d4aad
1 changed files with 74 additions and 31 deletions
|
@ -20,43 +20,86 @@ class phpbb_type_cast_helper_test extends phpbb_test_case
|
||||||
$this->type_cast_helper = new \phpbb\request\type_cast_helper();
|
$this->type_cast_helper = new \phpbb\request\type_cast_helper();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_simple_recursive_set_var()
|
public function type_cast_helper_test_data()
|
||||||
{
|
{
|
||||||
$data = 'eviL<3';
|
return [
|
||||||
$expected = 'eviL<3';
|
[
|
||||||
|
'eviL<3',
|
||||||
|
'eviL<3',
|
||||||
|
'',
|
||||||
|
true,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
['eviL<3'],
|
||||||
|
['eviL<3'],
|
||||||
|
[0 => ''],
|
||||||
|
true,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
" eviL<3\t\t",
|
||||||
|
" eviL<3\t\t",
|
||||||
|
'',
|
||||||
|
true,
|
||||||
|
false,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
[" eviL<3\t\t"],
|
||||||
|
[" eviL<3\t\t"],
|
||||||
|
[0 => ''],
|
||||||
|
true,
|
||||||
|
false,
|
||||||
|
],
|
||||||
|
// Test multiline unicode vars
|
||||||
|
[
|
||||||
|
"
|
||||||
|
|
||||||
$this->type_cast_helper->recursive_set_var($data, '', true);
|
Тест ",
|
||||||
|
"
|
||||||
|
|
||||||
$this->assertEquals($expected, $data);
|
Тест ",
|
||||||
|
'',
|
||||||
|
true,
|
||||||
|
false,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"
|
||||||
|
|
||||||
|
Тест ",
|
||||||
|
"Тест",
|
||||||
|
'',
|
||||||
|
true,
|
||||||
|
true,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
["
|
||||||
|
|
||||||
|
Тест "],
|
||||||
|
["
|
||||||
|
|
||||||
|
Тест "],
|
||||||
|
[0 => ''],
|
||||||
|
true,
|
||||||
|
false,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
["
|
||||||
|
|
||||||
|
Тест "],
|
||||||
|
["Тест"],
|
||||||
|
[0 => ''],
|
||||||
|
true,
|
||||||
|
true,
|
||||||
|
],
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_nested_recursive_set_var()
|
/**
|
||||||
|
* @dataProvider type_cast_helper_test_data
|
||||||
|
*/
|
||||||
|
public function test_recursive_set_var($var, $expected, $default, $multibyte, $trim = true)
|
||||||
{
|
{
|
||||||
$data = array('eviL<3');
|
$this->type_cast_helper->recursive_set_var($var, $default, $multibyte, $trim);
|
||||||
$expected = array('eviL<3');
|
|
||||||
|
|
||||||
$this->type_cast_helper->recursive_set_var($data, array(0 => ''), true);
|
$this->assertEquals($expected, $var);
|
||||||
|
|
||||||
$this->assertEquals($expected, $data);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test_simple_untrimmed_recursive_set_var()
|
|
||||||
{
|
|
||||||
$data = " eviL<3\t\t";
|
|
||||||
$expected = " eviL<3\t\t";
|
|
||||||
|
|
||||||
$this->type_cast_helper->recursive_set_var($data, '', true, false);
|
|
||||||
|
|
||||||
$this->assertEquals($expected, $data);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test_nested_untrimmed_recursive_set_var()
|
|
||||||
{
|
|
||||||
$data = array(" eviL<3\t\t");
|
|
||||||
$expected = array(" eviL<3\t\t");
|
|
||||||
|
|
||||||
$this->type_cast_helper->recursive_set_var($data, array(0 => ''), true, false);
|
|
||||||
|
|
||||||
$this->assertEquals($expected, $data);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue