From 6b00d7aa096b01ce6e59a8467f79eb193c25a35b Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 1 Feb 2011 14:09:52 +0100 Subject: [ticket/9823] Update Unit tests to the new system and correct some minor issues PHPBB3-9823 --- tests/functions_acp/all_tests.php | 48 ------ tests/functions_acp/build_cfg_template.php | 193 ---------------------- tests/functions_acp/build_cfg_template_test.php | 192 +++++++++++++++++++++ tests/functions_acp/build_select.php | 57 ------- tests/functions_acp/build_select_test.php | 56 +++++++ tests/functions_acp/h_radio.php | 122 -------------- tests/functions_acp/h_radio_test.php | 121 ++++++++++++++ tests/functions_acp/validate_config_vars.php | 152 ----------------- tests/functions_acp/validate_config_vars_test.php | 151 +++++++++++++++++ tests/functions_acp/validate_range.php | 180 -------------------- tests/functions_acp/validate_range_test.php | 179 ++++++++++++++++++++ 11 files changed, 699 insertions(+), 752 deletions(-) delete mode 100644 tests/functions_acp/all_tests.php delete mode 100644 tests/functions_acp/build_cfg_template.php create mode 100644 tests/functions_acp/build_cfg_template_test.php delete mode 100644 tests/functions_acp/build_select.php create mode 100644 tests/functions_acp/build_select_test.php delete mode 100644 tests/functions_acp/h_radio.php create mode 100644 tests/functions_acp/h_radio_test.php delete mode 100644 tests/functions_acp/validate_config_vars.php create mode 100644 tests/functions_acp/validate_config_vars_test.php delete mode 100644 tests/functions_acp/validate_range.php create mode 100644 tests/functions_acp/validate_range_test.php diff --git a/tests/functions_acp/all_tests.php b/tests/functions_acp/all_tests.php deleted file mode 100644 index 64956593fd..0000000000 --- a/tests/functions_acp/all_tests.php +++ /dev/null @@ -1,48 +0,0 @@ -addTestSuite('phpbb_functions_acp_build_cfg_template_test'); - $suite->addTestSuite('phpbb_functions_acp_built_select_test'); - $suite->addTestSuite('phpbb_functions_acp_h_radio_test'); - $suite->addTestSuite('phpbb_functions_acp_validate_config_vars_test'); - $suite->addTestSuite('phpbb_functions_acp_validate_range_test'); - - return $suite; - } -} - -if (PHPUnit_MAIN_METHOD == 'phpbb_functions_acp_all_tests::main') -{ - phpbb_functions_acp_all_tests::main(); -} diff --git a/tests/functions_acp/build_cfg_template.php b/tests/functions_acp/build_cfg_template.php deleted file mode 100644 index 07f82e933a..0000000000 --- a/tests/functions_acp/build_cfg_template.php +++ /dev/null @@ -1,193 +0,0 @@ - '1'), - 'config_key_name', - array(), - '', - ), - array( - array('password', 20, 128), - 'key_name', - array('config_key_name' => '2'), - 'config_key_name', - array(), - '', - ), - array( - array('text', 0, 255), - 'key_name', - array('config_key_name' => '3'), - 'config_key_name', - array(), - '', - ), - ); - } - - /** - * @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(), - ' x ', - ), - array( - array('dimension', 0, 255), - 'key_name', - array('config_key_name_width' => 10, 'config_key_name_height' => 20), - 'config_key_name', - array(), - ' x ', - ), - ); - } - - /** - * @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(), - '', - ), - ); - } - - /** - * @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(), - '', - ), - array( - array('radio', 'enabled_disabled'), - 'key_name', - array('config_key_name' => '1'), - 'config_key_name', - array(), - '', - ), - array( - array('radio', 'yes_no'), - 'key_name', - array('config_key_name' => '0'), - 'config_key_name', - array(), - '', - ), - array( - array('radio', 'yes_no'), - 'key_name', - array('config_key_name' => '1'), - 'config_key_name', - array(), - '', - ), - ); - } - - /** - * @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!'), - '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)); - } -} diff --git a/tests/functions_acp/build_cfg_template_test.php b/tests/functions_acp/build_cfg_template_test.php new file mode 100644 index 0000000000..c573c7cdb0 --- /dev/null +++ b/tests/functions_acp/build_cfg_template_test.php @@ -0,0 +1,192 @@ + '1'), + 'config_key_name', + array(), + '', + ), + array( + array('password', 20, 128), + 'key_name', + array('config_key_name' => '2'), + 'config_key_name', + array(), + '', + ), + array( + array('text', 0, 255), + 'key_name', + array('config_key_name' => '3'), + 'config_key_name', + array(), + '', + ), + ); + } + + /** + * @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(), + ' x ', + ), + array( + array('dimension', 0, 255), + 'key_name', + array('config_key_name_width' => 10, 'config_key_name_height' => 20), + 'config_key_name', + array(), + ' x ', + ), + ); + } + + /** + * @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(), + '', + ), + ); + } + + /** + * @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(), + '', + ), + array( + array('radio', 'enabled_disabled'), + 'key_name', + array('config_key_name' => '1'), + 'config_key_name', + array(), + '', + ), + array( + array('radio', 'yes_no'), + 'key_name', + array('config_key_name' => '0'), + 'config_key_name', + array(), + '', + ), + array( + array('radio', 'yes_no'), + 'key_name', + array('config_key_name' => '1'), + 'config_key_name', + array(), + '', + ), + ); + } + + /** + * @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!'), + '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)); + } +} diff --git a/tests/functions_acp/build_select.php b/tests/functions_acp/build_select.php deleted file mode 100644 index 5a097fefab..0000000000 --- a/tests/functions_acp/build_select.php +++ /dev/null @@ -1,57 +0,0 @@ - 'TEST', - 'second' => 'SEC_OPTION', - ), - false, - '', - ), - array( - array( - 'test' => 'TEST', - 'second' => 'SEC_OPTION', - ), - 'test', - '', - ), - array( - array( - 'test' => 'TEST', - 'second' => 'SEC_OPTION', - ), - 'second', - '', - ), - ); - } - - /** - * @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)); - } -} diff --git a/tests/functions_acp/build_select_test.php b/tests/functions_acp/build_select_test.php new file mode 100644 index 0000000000..a4f5e419ea --- /dev/null +++ b/tests/functions_acp/build_select_test.php @@ -0,0 +1,56 @@ + 'TEST', + 'second' => 'SEC_OPTION', + ), + false, + '', + ), + array( + array( + 'test' => 'TEST', + 'second' => 'SEC_OPTION', + ), + 'test', + '', + ), + array( + array( + 'test' => 'TEST', + 'second' => 'SEC_OPTION', + ), + 'second', + '', + ), + ); + } + + /** + * @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)); + } +} diff --git a/tests/functions_acp/h_radio.php b/tests/functions_acp/h_radio.php deleted file mode 100644 index 6550c8f818..0000000000 --- a/tests/functions_acp/h_radio.php +++ /dev/null @@ -1,122 +0,0 @@ - 'TEST', - 'second' => 'SEC_OPTION', - ), - false, - false, - false, - '', - ), - array( - 'test_name', - array( - 'test' => 'TEST', - 'second' => 'SEC_OPTION', - ), - 'test', - false, - false, - '', - ), - array( - 'test_name', - array( - 'test' => 'TEST', - 'second' => 'SEC_OPTION', - ), - false, - 'test_id', - false, - '', - ), - array( - 'test_name', - array( - 'test' => 'TEST', - 'second' => 'SEC_OPTION', - ), - 'test', - 'test_id', - false, - '', - ), - - array( - 'test_name', - array( - 'test' => 'TEST', - 'second' => 'SEC_OPTION', - ), - false, - false, - 'k', - '', - ), - array( - 'test_name', - array( - 'test' => 'TEST', - 'second' => 'SEC_OPTION', - ), - 'test', - false, - 'k', - '', - ), - array( - 'test_name', - array( - 'test' => 'TEST', - 'second' => 'SEC_OPTION', - ), - false, - 'test_id', - 'k', - '', - ), - array( - 'test_name', - array( - 'test' => 'TEST', - 'second' => 'SEC_OPTION', - ), - 'test', - 'test_id', - 'k', - '', - ), - ); - } - - /** - * @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)); - } -} diff --git a/tests/functions_acp/h_radio_test.php b/tests/functions_acp/h_radio_test.php new file mode 100644 index 0000000000..924b502ede --- /dev/null +++ b/tests/functions_acp/h_radio_test.php @@ -0,0 +1,121 @@ + 'TEST', + 'second' => 'SEC_OPTION', + ), + false, + false, + false, + '', + ), + array( + 'test_name', + array( + 'test' => 'TEST', + 'second' => 'SEC_OPTION', + ), + 'test', + false, + false, + '', + ), + array( + 'test_name', + array( + 'test' => 'TEST', + 'second' => 'SEC_OPTION', + ), + false, + 'test_id', + false, + '', + ), + array( + 'test_name', + array( + 'test' => 'TEST', + 'second' => 'SEC_OPTION', + ), + 'test', + 'test_id', + false, + '', + ), + + array( + 'test_name', + array( + 'test' => 'TEST', + 'second' => 'SEC_OPTION', + ), + false, + false, + 'k', + '', + ), + array( + 'test_name', + array( + 'test' => 'TEST', + 'second' => 'SEC_OPTION', + ), + 'test', + false, + 'k', + '', + ), + array( + 'test_name', + array( + 'test' => 'TEST', + 'second' => 'SEC_OPTION', + ), + false, + 'test_id', + 'k', + '', + ), + array( + 'test_name', + array( + 'test' => 'TEST', + 'second' => 'SEC_OPTION', + ), + 'test', + 'test_id', + 'k', + '', + ), + ); + } + + /** + * @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)); + } +} diff --git a/tests/functions_acp/validate_config_vars.php b/tests/functions_acp/validate_config_vars.php deleted file mode 100644 index 04a5fead7a..0000000000 --- a/tests/functions_acp/validate_config_vars.php +++ /dev/null @@ -1,152 +0,0 @@ - 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); - } -} diff --git a/tests/functions_acp/validate_config_vars_test.php b/tests/functions_acp/validate_config_vars_test.php new file mode 100644 index 0000000000..722d0ebddb --- /dev/null +++ b/tests/functions_acp/validate_config_vars_test.php @@ -0,0 +1,151 @@ + 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); + } +} diff --git a/tests/functions_acp/validate_range.php b/tests/functions_acp/validate_range.php deleted file mode 100644 index cac54dd5ed..0000000000 --- a/tests/functions_acp/validate_range.php +++ /dev/null @@ -1,180 +0,0 @@ - '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) 0x80000000))), - 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) 0x80000000) - 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); - } -} diff --git a/tests/functions_acp/validate_range_test.php b/tests/functions_acp/validate_range_test.php new file mode 100644 index 0000000000..fb1d15c032 --- /dev/null +++ b/tests/functions_acp/validate_range_test.php @@ -0,0 +1,179 @@ + '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) 0x80000000))), + 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) 0x80000000) - 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); + } +} -- cgit v1.2.1