mirror of
https://github.com/phpbb/phpbb.git
synced 2025-08-27 10:14:47 +02:00
Merge branch 'ticket/nickvergessen/9823' into develop
* ticket/nickvergessen/9823: [ticket/9823] Replace 0x80000000 with -2147483648 in tests. [ticket/9823] Move mock file into the mock/ folder. [ticket/9823] Update Unit tests to the new system and correct some minor issues [ticket/9823] Update copyright year and add newline at the end of the file. [ticket/9823] Correct unit-tests to use self:: instead of the class-name. [ticket/9823] Unit tests for validate_config_vars. [ticket/9823] Unit tests for build_cfg_template. [ticket/9823] Unit tests for validate_rang. [ticket/9823] Unit tests for h_radio. [ticket/9823] Moving the functions. Unit tests for build_select. Conflicts: phpBB/adm/index.php
This commit is contained in:
192
tests/functions_acp/build_cfg_template_test.php
Normal file
192
tests/functions_acp/build_cfg_template_test.php
Normal file
@@ -0,0 +1,192 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2010 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/../mock/lang.php';
|
||||
require_once dirname(__FILE__) . '/../../phpBB/includes/functions_acp.php';
|
||||
|
||||
class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case
|
||||
{
|
||||
public function build_cfg_template_text_data()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
array('text', 20, 255),
|
||||
'key_name',
|
||||
array('config_key_name' => '1'),
|
||||
'config_key_name',
|
||||
array(),
|
||||
'<input id="key_name" type="text" size="20" maxlength="255" name="config[config_key_name]" value="1" />',
|
||||
),
|
||||
array(
|
||||
array('password', 20, 128),
|
||||
'key_name',
|
||||
array('config_key_name' => '2'),
|
||||
'config_key_name',
|
||||
array(),
|
||||
'<input id="key_name" type="password" size="20" maxlength="128" name="config[config_key_name]" value="2" />',
|
||||
),
|
||||
array(
|
||||
array('text', 0, 255),
|
||||
'key_name',
|
||||
array('config_key_name' => '3'),
|
||||
'config_key_name',
|
||||
array(),
|
||||
'<input id="key_name" type="text" maxlength="255" name="config[config_key_name]" value="3" />',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider build_cfg_template_text_data
|
||||
*/
|
||||
public function test_build_cfg_template_text($tpl_type, $key, $new, $config_key, $vars, $expected)
|
||||
{
|
||||
global $user;
|
||||
|
||||
$user->lang = new phpbb_mock_lang();
|
||||
|
||||
$this->assertEquals($expected, build_cfg_template($tpl_type, $key, $new, $config_key, $vars));
|
||||
}
|
||||
|
||||
public function build_cfg_template_dimension_data()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
array('dimension', 20, 255),
|
||||
'key_name',
|
||||
array('config_key_name_width' => 10, 'config_key_name_height' => 20),
|
||||
'config_key_name',
|
||||
array(),
|
||||
'<input id="key_name" type="text" size="20" maxlength="255" name="config[config_key_name_width]" value="10" /> x <input type="text" size="20" maxlength="255" name="config[config_key_name_height]" value="20" />',
|
||||
),
|
||||
array(
|
||||
array('dimension', 0, 255),
|
||||
'key_name',
|
||||
array('config_key_name_width' => 10, 'config_key_name_height' => 20),
|
||||
'config_key_name',
|
||||
array(),
|
||||
'<input id="key_name" type="text" maxlength="255" name="config[config_key_name_width]" value="10" /> x <input type="text" maxlength="255" name="config[config_key_name_height]" value="20" />',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider build_cfg_template_dimension_data
|
||||
*/
|
||||
public function test_build_cfg_template_dimension($tpl_type, $key, $new, $config_key, $vars, $expected)
|
||||
{
|
||||
global $user;
|
||||
|
||||
$user->lang = new phpbb_mock_lang();
|
||||
|
||||
$this->assertEquals($expected, build_cfg_template($tpl_type, $key, $new, $config_key, $vars));
|
||||
}
|
||||
|
||||
public function build_cfg_template_textarea_data()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
array('textarea', 5, 30),
|
||||
'key_name',
|
||||
array('config_key_name' => 'phpBB'),
|
||||
'config_key_name',
|
||||
array(),
|
||||
'<textarea id="key_name" name="config[config_key_name]" rows="5" cols="30">phpBB</textarea>',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider build_cfg_template_textarea_data
|
||||
*/
|
||||
public function test_build_cfg_template_textarea($tpl_type, $key, $new, $config_key, $vars, $expected)
|
||||
{
|
||||
global $user;
|
||||
|
||||
$user->lang = new phpbb_mock_lang();
|
||||
|
||||
$this->assertEquals($expected, build_cfg_template($tpl_type, $key, $new, $config_key, $vars));
|
||||
}
|
||||
|
||||
public function build_cfg_template_radio_data()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
array('radio', 'enabled_disabled'),
|
||||
'key_name',
|
||||
array('config_key_name' => '0'),
|
||||
'config_key_name',
|
||||
array(),
|
||||
'<label><input type="radio" id="key_name" name="config[config_key_name]" value="1" class="radio" /> ENABLED</label><label><input type="radio" name="config[config_key_name]" value="0" checked="checked" class="radio" /> DISABLED</label>',
|
||||
),
|
||||
array(
|
||||
array('radio', 'enabled_disabled'),
|
||||
'key_name',
|
||||
array('config_key_name' => '1'),
|
||||
'config_key_name',
|
||||
array(),
|
||||
'<label><input type="radio" id="key_name" name="config[config_key_name]" value="1" checked="checked" class="radio" /> ENABLED</label><label><input type="radio" name="config[config_key_name]" value="0" class="radio" /> DISABLED</label>',
|
||||
),
|
||||
array(
|
||||
array('radio', 'yes_no'),
|
||||
'key_name',
|
||||
array('config_key_name' => '0'),
|
||||
'config_key_name',
|
||||
array(),
|
||||
'<label><input type="radio" id="key_name" name="config[config_key_name]" value="1" class="radio" /> YES</label><label><input type="radio" name="config[config_key_name]" value="0" checked="checked" class="radio" /> NO</label>',
|
||||
),
|
||||
array(
|
||||
array('radio', 'yes_no'),
|
||||
'key_name',
|
||||
array('config_key_name' => '1'),
|
||||
'config_key_name',
|
||||
array(),
|
||||
'<label><input type="radio" id="key_name" name="config[config_key_name]" value="1" checked="checked" class="radio" /> YES</label><label><input type="radio" name="config[config_key_name]" value="0" class="radio" /> NO</label>',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider build_cfg_template_radio_data
|
||||
*/
|
||||
public function test_build_cfg_template_radio($tpl_type, $key, $new, $config_key, $vars, $expected)
|
||||
{
|
||||
global $user;
|
||||
|
||||
$user->lang = new phpbb_mock_lang();
|
||||
|
||||
$this->assertEquals($expected, build_cfg_template($tpl_type, $key, $new, $config_key, $vars));
|
||||
}
|
||||
|
||||
public function build_cfg_template_append_data()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
array('textarea', 5, 30),
|
||||
'key_name',
|
||||
array('config_key_name' => 'phpBB'),
|
||||
'config_key_name',
|
||||
array('append' => 'Bertie is cool!'),
|
||||
'<textarea id="key_name" name="config[config_key_name]" rows="5" cols="30">phpBB</textarea>Bertie is cool!',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider build_cfg_template_append_data
|
||||
*/
|
||||
public function test_build_cfg_template_append($tpl_type, $key, $new, $config_key, $vars, $expected)
|
||||
{
|
||||
global $user;
|
||||
|
||||
$user->lang = new phpbb_mock_lang();
|
||||
|
||||
$this->assertEquals($expected, build_cfg_template($tpl_type, $key, $new, $config_key, $vars));
|
||||
}
|
||||
}
|
56
tests/functions_acp/build_select_test.php
Normal file
56
tests/functions_acp/build_select_test.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2010 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/../mock/lang.php';
|
||||
require_once dirname(__FILE__) . '/../../phpBB/includes/functions_acp.php';
|
||||
|
||||
class phpbb_functions_acp_built_select_test extends phpbb_test_case
|
||||
{
|
||||
public function build_select_data()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
array(
|
||||
'test' => 'TEST',
|
||||
'second' => 'SEC_OPTION',
|
||||
),
|
||||
false,
|
||||
'<option value="test">TEST</option><option value="second">SEC_OPTION</option>',
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'test' => 'TEST',
|
||||
'second' => 'SEC_OPTION',
|
||||
),
|
||||
'test',
|
||||
'<option value="test" selected="selected">TEST</option><option value="second">SEC_OPTION</option>',
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'test' => 'TEST',
|
||||
'second' => 'SEC_OPTION',
|
||||
),
|
||||
'second',
|
||||
'<option value="test">TEST</option><option value="second" selected="selected">SEC_OPTION</option>',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider build_select_data
|
||||
*/
|
||||
public function test_build_select($option_ary, $option_default, $expected)
|
||||
{
|
||||
global $user;
|
||||
|
||||
$user->lang = new phpbb_mock_lang();
|
||||
|
||||
$this->assertEquals($expected, build_select($option_ary, $option_default));
|
||||
}
|
||||
}
|
121
tests/functions_acp/h_radio_test.php
Normal file
121
tests/functions_acp/h_radio_test.php
Normal file
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2010 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/../mock/lang.php';
|
||||
require_once dirname(__FILE__) . '/../../phpBB/includes/functions_acp.php';
|
||||
|
||||
class phpbb_functions_acp_h_radio_test extends phpbb_test_case
|
||||
{
|
||||
public function h_radio_data()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'test_name',
|
||||
array(
|
||||
'test' => 'TEST',
|
||||
'second' => 'SEC_OPTION',
|
||||
),
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
'<label><input type="radio" name="test_name" value="test" class="radio" /> TEST</label><label><input type="radio" name="test_name" value="second" class="radio" /> SEC_OPTION</label>',
|
||||
),
|
||||
array(
|
||||
'test_name',
|
||||
array(
|
||||
'test' => 'TEST',
|
||||
'second' => 'SEC_OPTION',
|
||||
),
|
||||
'test',
|
||||
false,
|
||||
false,
|
||||
'<label><input type="radio" name="test_name" value="test" checked="checked" class="radio" /> TEST</label><label><input type="radio" name="test_name" value="second" class="radio" /> SEC_OPTION</label>',
|
||||
),
|
||||
array(
|
||||
'test_name',
|
||||
array(
|
||||
'test' => 'TEST',
|
||||
'second' => 'SEC_OPTION',
|
||||
),
|
||||
false,
|
||||
'test_id',
|
||||
false,
|
||||
'<label><input type="radio" name="test_name" id="test_id" value="test" class="radio" /> TEST</label><label><input type="radio" name="test_name" value="second" class="radio" /> SEC_OPTION</label>',
|
||||
),
|
||||
array(
|
||||
'test_name',
|
||||
array(
|
||||
'test' => 'TEST',
|
||||
'second' => 'SEC_OPTION',
|
||||
),
|
||||
'test',
|
||||
'test_id',
|
||||
false,
|
||||
'<label><input type="radio" name="test_name" id="test_id" value="test" checked="checked" class="radio" /> TEST</label><label><input type="radio" name="test_name" value="second" class="radio" /> SEC_OPTION</label>',
|
||||
),
|
||||
|
||||
array(
|
||||
'test_name',
|
||||
array(
|
||||
'test' => 'TEST',
|
||||
'second' => 'SEC_OPTION',
|
||||
),
|
||||
false,
|
||||
false,
|
||||
'k',
|
||||
'<label><input type="radio" name="test_name" value="test" accesskey="k" class="radio" /> TEST</label><label><input type="radio" name="test_name" value="second" accesskey="k" class="radio" /> SEC_OPTION</label>',
|
||||
),
|
||||
array(
|
||||
'test_name',
|
||||
array(
|
||||
'test' => 'TEST',
|
||||
'second' => 'SEC_OPTION',
|
||||
),
|
||||
'test',
|
||||
false,
|
||||
'k',
|
||||
'<label><input type="radio" name="test_name" value="test" checked="checked" accesskey="k" class="radio" /> TEST</label><label><input type="radio" name="test_name" value="second" accesskey="k" class="radio" /> SEC_OPTION</label>',
|
||||
),
|
||||
array(
|
||||
'test_name',
|
||||
array(
|
||||
'test' => 'TEST',
|
||||
'second' => 'SEC_OPTION',
|
||||
),
|
||||
false,
|
||||
'test_id',
|
||||
'k',
|
||||
'<label><input type="radio" name="test_name" id="test_id" value="test" accesskey="k" class="radio" /> TEST</label><label><input type="radio" name="test_name" value="second" accesskey="k" class="radio" /> SEC_OPTION</label>',
|
||||
),
|
||||
array(
|
||||
'test_name',
|
||||
array(
|
||||
'test' => 'TEST',
|
||||
'second' => 'SEC_OPTION',
|
||||
),
|
||||
'test',
|
||||
'test_id',
|
||||
'k',
|
||||
'<label><input type="radio" name="test_name" id="test_id" value="test" checked="checked" accesskey="k" class="radio" /> TEST</label><label><input type="radio" name="test_name" value="second" accesskey="k" class="radio" /> SEC_OPTION</label>',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider h_radio_data
|
||||
*/
|
||||
public function test_h_radio($name, $input_ary, $input_default, $id, $key, $expected)
|
||||
{
|
||||
global $user;
|
||||
|
||||
$user->lang = new phpbb_mock_lang();
|
||||
|
||||
$this->assertEquals($expected, h_radio($name, $input_ary, $input_default, $id, $key));
|
||||
}
|
||||
}
|
151
tests/functions_acp/validate_config_vars_test.php
Normal file
151
tests/functions_acp/validate_config_vars_test.php
Normal file
@@ -0,0 +1,151 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2010 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/../mock/lang.php';
|
||||
require_once dirname(__FILE__) . '/../../phpBB/includes/functions_acp.php';
|
||||
|
||||
class phpbb_functions_acp_validate_config_vars_test extends phpbb_test_case
|
||||
{
|
||||
/**
|
||||
* Helper function which returns a string in a given length.
|
||||
*/
|
||||
static public function return_string($length)
|
||||
{
|
||||
$string = '';
|
||||
for ($i = 0; $i < $length; $i++)
|
||||
{
|
||||
$string .= 'a';
|
||||
}
|
||||
return $string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Data sets that don't throw an error.
|
||||
*/
|
||||
public function validate_config_vars_fit_data()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
array(
|
||||
'test_bool' => array('lang' => 'TEST_BOOL', 'validate' => 'bool'),
|
||||
'test_string' => array('lang' => 'TEST_STRING', 'validate' => 'string'),
|
||||
'test_string_128' => array('lang' => 'TEST_STRING_128', 'validate' => 'string:128'),
|
||||
'test_string_32_64' => array('lang' => 'TEST_STRING_32_64', 'validate' => 'string:32:64'),
|
||||
'test_int' => array('lang' => 'TEST_INT', 'validate' => 'int'),
|
||||
'test_int_32' => array('lang' => 'TEST_INT', 'validate' => 'int:32'),
|
||||
'test_int_32_64' => array('lang' => 'TEST_INT', 'validate' => 'int:32:64'),
|
||||
'test_lang' => array('lang' => 'TEST_LANG', 'validate' => 'lang'),
|
||||
/*
|
||||
'test_sp' => array('lang' => 'TEST_SP', 'validate' => 'script_path'),
|
||||
'test_rpath' => array('lang' => 'TEST_RPATH', 'validate' => 'rpath'),
|
||||
'test_rwpath' => array('lang' => 'TEST_RWPATH', 'validate' => 'rwpath'),
|
||||
'test_path' => array('lang' => 'TEST_PATH', 'validate' => 'path'),
|
||||
'test_wpath' => array('lang' => 'TEST_WPATH', 'validate' => 'wpath'),
|
||||
*/
|
||||
),
|
||||
array(
|
||||
'test_bool' => true,
|
||||
'test_string' => self::return_string(255),
|
||||
'test_string_128' => self::return_string(128),
|
||||
'test_string_32_64' => self::return_string(48),
|
||||
'test_int' => 128,
|
||||
'test_int_32' => 32,
|
||||
'test_int_32_64' => 48,
|
||||
'test_lang' => 'en',
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider validate_config_vars_fit_data
|
||||
*/
|
||||
public function test_validate_config_vars_fit($test_data, $cfg_array)
|
||||
{
|
||||
global $user;
|
||||
|
||||
$user->lang = new phpbb_mock_lang();
|
||||
|
||||
$phpbb_error = array();
|
||||
validate_config_vars($test_data, $cfg_array, $phpbb_error);
|
||||
|
||||
$this->assertEquals(array(), $phpbb_error);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data sets that throw the error.
|
||||
*/
|
||||
public function validate_config_vars_error_data()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
array('test_string_32_64' => array('lang' => 'TEST_STRING_32_64', 'validate' => 'string:32:64')),
|
||||
array('test_string_32_64' => self::return_string(20)),
|
||||
array('SETTING_TOO_SHORT'),
|
||||
),
|
||||
array(
|
||||
array('test_string' => array('lang' => 'TEST_STRING', 'validate' => 'string')),
|
||||
array('test_string' => self::return_string(256)),
|
||||
array('SETTING_TOO_LONG'),
|
||||
),
|
||||
array(
|
||||
array('test_string_32_64' => array('lang' => 'TEST_STRING_32_64', 'validate' => 'string:32:64')),
|
||||
array('test_string_32_64' => self::return_string(65)),
|
||||
array('SETTING_TOO_LONG'),
|
||||
),
|
||||
|
||||
array(
|
||||
array('test_int_32' => array('lang' => 'TEST_INT', 'validate' => 'int:32')),
|
||||
array('test_int_32' => 31),
|
||||
array('SETTING_TOO_LOW'),
|
||||
),
|
||||
array(
|
||||
array('test_int_32_64' => array('lang' => 'TEST_INT', 'validate' => 'int:32:64')),
|
||||
array('test_int_32_64' => 31),
|
||||
array('SETTING_TOO_LOW'),
|
||||
),
|
||||
array(
|
||||
array('test_int_32_64' => array('lang' => 'TEST_INT', 'validate' => 'int:32:64')),
|
||||
array('test_int_32_64' => 65),
|
||||
array('SETTING_TOO_BIG'),
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'test_int_min' => array('lang' => 'TEST_INT_MIN', 'validate' => 'int:32:64'),
|
||||
'test_int_max' => array('lang' => 'TEST_INT_MAX', 'validate' => 'int:32:64'),
|
||||
),
|
||||
array(
|
||||
'test_int_min' => 52,
|
||||
'test_int_max' => 48,
|
||||
),
|
||||
array('SETTING_TOO_LOW'),
|
||||
),
|
||||
array(
|
||||
array('test_lang' => array('lang' => 'TEST_LANG', 'validate' => 'lang')),
|
||||
array('test_lang' => 'this_is_no_language'),
|
||||
array('WRONG_DATA_LANG'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider validate_config_vars_error_data
|
||||
*/
|
||||
public function test_validate_config_vars_error($test_data, $cfg_array, $expected)
|
||||
{
|
||||
global $user;
|
||||
|
||||
$user->lang = new phpbb_mock_lang();
|
||||
|
||||
$phpbb_error = array();
|
||||
validate_config_vars($test_data, $cfg_array, $phpbb_error);
|
||||
|
||||
$this->assertEquals($expected, $phpbb_error);
|
||||
}
|
||||
}
|
179
tests/functions_acp/validate_range_test.php
Normal file
179
tests/functions_acp/validate_range_test.php
Normal file
@@ -0,0 +1,179 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2010 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/../mock/lang.php';
|
||||
require_once dirname(__FILE__) . '/../../phpBB/includes/functions_acp.php';
|
||||
|
||||
class phpbb_functions_acp_validate_range_test extends phpbb_test_case
|
||||
{
|
||||
/**
|
||||
* Helper function which returns a string in a given length.
|
||||
*/
|
||||
static public function return_string($length)
|
||||
{
|
||||
$string = '';
|
||||
for ($i = 0; $i < $length; $i++)
|
||||
{
|
||||
$string .= 'a';
|
||||
}
|
||||
return $string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Data sets that don't throw an error.
|
||||
*/
|
||||
public function validate_range_data_fit()
|
||||
{
|
||||
return array(
|
||||
array(array(array('column_type' => 'BOOL', 'lang' => 'TEST', 'value' => 0))),
|
||||
array(array(array('column_type' => 'BOOL', 'lang' => 'TEST', 'value' => 1))),
|
||||
|
||||
array(array(array('column_type' => 'USINT', 'lang' => 'TEST', 'value' => 0))),
|
||||
array(array(array('column_type' => 'USINT', 'lang' => 'TEST', 'value' => 65535))),
|
||||
array(array(array('column_type' => 'USINT:32:128', 'lang' => 'TEST', 'value' => 35))),
|
||||
|
||||
array(array(array('column_type' => 'UINT', 'lang' => 'TEST', 'value' => 0))),
|
||||
array(array(array('column_type' => 'UINT', 'lang' => 'TEST', 'value' => (int) 0x7fffffff))),
|
||||
array(array(array('column_type' => 'UINT:32:128', 'lang' => 'TEST', 'value' => 35))),
|
||||
|
||||
array(array(array('column_type' => 'INT', 'lang' => 'TEST', 'value' => (int) -2147483648))),
|
||||
array(array(array('column_type' => 'INT', 'lang' => 'TEST', 'value' => (int) 0x7fffffff))),
|
||||
array(array(array('column_type' => 'INT:-32:128', 'lang' => 'TEST', 'value' => -28))),
|
||||
array(array(array('column_type' => 'INT:-32:128', 'lang' => 'TEST', 'value' => 35))),
|
||||
|
||||
array(array(array('column_type' => 'TINT', 'lang' => 'TEST', 'value' => -128))),
|
||||
array(array(array('column_type' => 'TINT', 'lang' => 'TEST', 'value' => 127))),
|
||||
array(array(array('column_type' => 'TINT:-32:64', 'lang' => 'TEST', 'value' => -16))),
|
||||
array(array(array('column_type' => 'TINT:-32:64', 'lang' => 'TEST', 'value' => 16))),
|
||||
|
||||
array(array(array('column_type' => 'VCHAR', 'lang' => 'TEST', 'value' => ''))),
|
||||
array(array(array('column_type' => 'VCHAR', 'lang' => 'TEST', 'value' => self::return_string(255)))),
|
||||
array(array(array('column_type' => 'VCHAR:128', 'lang' => 'TEST', 'value' => self::return_string(128)))),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider validate_range_data_fit
|
||||
*/
|
||||
public function test_validate_range_fit($test_data)
|
||||
{
|
||||
global $user;
|
||||
|
||||
$user->lang = new phpbb_mock_lang();
|
||||
|
||||
$phpbb_error = array();
|
||||
validate_range($test_data, $phpbb_error);
|
||||
|
||||
$this->assertEquals(array(), $phpbb_error);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data sets that throw the SETTING_TOO_LOW-error.
|
||||
*/
|
||||
public function validate_range_data_too_low()
|
||||
{
|
||||
return array(
|
||||
array(array(array('column_type' => 'BOOL', 'lang' => 'TEST', 'value' => -1))),
|
||||
|
||||
array(array(array('column_type' => 'USINT', 'lang' => 'TEST', 'value' => -1))),
|
||||
array(array(array('column_type' => 'USINT:32:128', 'lang' => 'TEST', 'value' => 31))),
|
||||
|
||||
array(array(array('column_type' => 'UINT', 'lang' => 'TEST', 'value' => -1))),
|
||||
array(array(array('column_type' => 'UINT:32:128', 'lang' => 'TEST', 'value' => 31))),
|
||||
|
||||
array(array(array('column_type' => 'INT', 'lang' => 'TEST', 'value' => ((int) -2147483648) - 1))),
|
||||
array(array(array('column_type' => 'INT:32:128', 'lang' => 'TEST', 'value' => 31))),
|
||||
array(array(array('column_type' => 'INT:-32:128', 'lang' => 'TEST', 'value' => -33))),
|
||||
|
||||
array(array(array('column_type' => 'TINT', 'lang' => 'TEST', 'value' => -129))),
|
||||
array(array(array('column_type' => 'TINT:32:64', 'lang' => 'TEST', 'value' => 31))),
|
||||
array(array(array('column_type' => 'TINT:-32:64', 'lang' => 'TEST', 'value' => -33))),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider validate_range_data_too_low
|
||||
*/
|
||||
public function test_validate_range_too_low($test_data)
|
||||
{
|
||||
global $user;
|
||||
|
||||
$user->lang = new phpbb_mock_lang();
|
||||
|
||||
$phpbb_error = array();
|
||||
validate_range($test_data, $phpbb_error);
|
||||
|
||||
$this->assertEquals(array('SETTING_TOO_LOW'), $phpbb_error);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data sets that throw the SETTING_TOO_BIG-error.
|
||||
*/
|
||||
public function validate_range_data_too_big()
|
||||
{
|
||||
return array(
|
||||
array(array(array('column_type' => 'BOOL', 'lang' => 'TEST', 'value' => 2))),
|
||||
|
||||
array(array(array('column_type' => 'USINT', 'lang' => 'TEST', 'value' => 65536))),
|
||||
array(array(array('column_type' => 'USINT:32:128', 'lang' => 'TEST', 'value' => 129))),
|
||||
|
||||
array(array(array('column_type' => 'UINT', 'lang' => 'TEST', 'value' => ((int) 0x7fffffff) + 1))),
|
||||
array(array(array('column_type' => 'UINT:32:128', 'lang' => 'TEST', 'value' => 129))),
|
||||
|
||||
array(array(array('column_type' => 'INT', 'lang' => 'TEST', 'value' => ((int) 0x7fffffff) + 1))),
|
||||
array(array(array('column_type' => 'INT:-32:-16', 'lang' => 'TEST', 'value' => -15))),
|
||||
array(array(array('column_type' => 'INT:-32:128', 'lang' => 'TEST', 'value' => 129))),
|
||||
|
||||
array(array(array('column_type' => 'TINT', 'lang' => 'TEST', 'value' => 128))),
|
||||
array(array(array('column_type' => 'TINT:-32:-16', 'lang' => 'TEST', 'value' => -15))),
|
||||
array(array(array('column_type' => 'TINT:-32:64', 'lang' => 'TEST', 'value' => 65))),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider validate_range_data_too_big
|
||||
*/
|
||||
public function test_validate_range_too_big($test_data)
|
||||
{
|
||||
global $user;
|
||||
|
||||
$user->lang = new phpbb_mock_lang();
|
||||
|
||||
$phpbb_error = array();
|
||||
validate_range($test_data, $phpbb_error);
|
||||
|
||||
$this->assertEquals(array('SETTING_TOO_BIG'), $phpbb_error);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data sets that throw the SETTING_TOO_LONG-error.
|
||||
*/
|
||||
public function validate_range_data_too_long()
|
||||
{
|
||||
return array(
|
||||
array(array(array('column_type' => 'VCHAR', 'lang' => 'TEST', 'value' => self::return_string(256)))),
|
||||
array(array(array('column_type' => 'VCHAR:128', 'lang' => 'TEST', 'value' => self::return_string(129)))),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider validate_range_data_too_long
|
||||
*/
|
||||
public function test_validate_range_too_long($test_data)
|
||||
{
|
||||
global $user;
|
||||
|
||||
$user->lang = new phpbb_mock_lang();
|
||||
|
||||
$phpbb_error = array();
|
||||
validate_range($test_data, $phpbb_error);
|
||||
|
||||
$this->assertEquals(array('SETTING_TOO_LONG'), $phpbb_error);
|
||||
}
|
||||
}
|
33
tests/mock/lang.php
Normal file
33
tests/mock/lang.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2010 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* phpbb_mock_lang
|
||||
* mock a user with some language-keys specified
|
||||
*/
|
||||
class phpbb_mock_lang implements ArrayAccess
|
||||
{
|
||||
public function offsetExists($offset)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function offsetGet($offset)
|
||||
{
|
||||
return $offset;
|
||||
}
|
||||
|
||||
public function offsetSet($offset, $value)
|
||||
{
|
||||
}
|
||||
|
||||
public function offsetUnset($offset)
|
||||
{
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user