From 70f9dec810e3104357b6cf13978cb52ea8cd8e99 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Fri, 10 Jun 2011 01:37:19 +0200 Subject: [PATCH 1/3] [ticket/10198] Verify behaviour of validate_range with multibyte strings Using str_repeat instead of custom function to repeat characters. PHPBB3-10198 --- tests/functions_acp/validate_range_test.php | 26 +++++++-------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/tests/functions_acp/validate_range_test.php b/tests/functions_acp/validate_range_test.php index a9c9612ad7..11b7f87957 100644 --- a/tests/functions_acp/validate_range_test.php +++ b/tests/functions_acp/validate_range_test.php @@ -8,23 +8,11 @@ */ require_once dirname(__FILE__) . '/../mock/lang.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.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. */ @@ -53,8 +41,10 @@ class phpbb_functions_acp_validate_range_test extends phpbb_test_case 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)))), + array(array(array('column_type' => 'VCHAR', 'lang' => 'TEST', 'value' => str_repeat('a', 255)))), + array(array(array('column_type' => 'VCHAR', 'lang' => 'TEST', 'value' => str_repeat("\xC3\x84", 255)))), + array(array(array('column_type' => 'VCHAR:128', 'lang' => 'TEST', 'value' => str_repeat('a', 128)))), + array(array(array('column_type' => 'VCHAR:128', 'lang' => 'TEST', 'value' => str_repeat("\xC3\x84", 128)))), ); } @@ -157,8 +147,10 @@ class phpbb_functions_acp_validate_range_test extends phpbb_test_case 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)))), + array(array(array('column_type' => 'VCHAR', 'lang' => 'TEST', 'value' => str_repeat('a', 256)))), + array(array(array('column_type' => 'VCHAR', 'lang' => 'TEST', 'value' => str_repeat("\xC3\x84", 256)))), + array(array(array('column_type' => 'VCHAR:128', 'lang' => 'TEST', 'value' => str_repeat('a', 129)))), + array(array(array('column_type' => 'VCHAR:128', 'lang' => 'TEST', 'value' => str_repeat("\xC3\x84", 129)))), ); } From 48a0bec971625e3654cc825f6a4dff2dbb4e1f6d Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Fri, 10 Jun 2011 01:44:25 +0200 Subject: [PATCH 2/3] [ticket/10198] Verify behaviour of validate_config_vars with multibyte strings Using str_repeat instead of custom function to repeat characters. PHPBB3-10198 --- .../validate_config_vars_test.php | 46 +++++++++++-------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/tests/functions_acp/validate_config_vars_test.php b/tests/functions_acp/validate_config_vars_test.php index aa63bc38df..761788e264 100644 --- a/tests/functions_acp/validate_config_vars_test.php +++ b/tests/functions_acp/validate_config_vars_test.php @@ -12,19 +12,6 @@ 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. */ @@ -35,7 +22,10 @@ class phpbb_functions_acp_validate_config_vars_test extends phpbb_test_case array( 'test_bool' => array('lang' => 'TEST_BOOL', 'validate' => 'bool'), 'test_string' => array('lang' => 'TEST_STRING', 'validate' => 'string'), + 'test_string' => array('lang' => 'TEST_STRING', 'validate' => 'string'), 'test_string_128' => array('lang' => 'TEST_STRING_128', 'validate' => 'string:128'), + '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_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'), @@ -51,9 +41,12 @@ class phpbb_functions_acp_validate_config_vars_test extends phpbb_test_case ), 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_string' => str_repeat('a', 255), + 'test_string' => str_repeat("\xC3\x84", 255), + 'test_string_128' => str_repeat('a', 128), + 'test_string_128' => str_repeat("\xC3\x84", 128), + 'test_string_32_64' => str_repeat('a', 48), + 'test_string_32_64' => str_repeat("\xC3\x84", 48), 'test_int' => 128, 'test_int_32' => 32, 'test_int_32_64' => 48, @@ -86,17 +79,32 @@ class phpbb_functions_acp_validate_config_vars_test extends phpbb_test_case 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('test_string_32_64' => str_repeat('a', 20)), + array('SETTING_TOO_SHORT'), + ), + array( + array('test_string_32_64' => array('lang' => 'TEST_STRING_32_64', 'validate' => 'string:32:64')), + array('test_string_32_64' => str_repeat("\xC3\x84", 20)), array('SETTING_TOO_SHORT'), ), array( array('test_string' => array('lang' => 'TEST_STRING', 'validate' => 'string')), - array('test_string' => self::return_string(256)), + array('test_string' => str_repeat('a', 256)), + array('SETTING_TOO_LONG'), + ), + array( + array('test_string' => array('lang' => 'TEST_STRING', 'validate' => 'string')), + array('test_string' => str_repeat("\xC3\x84", 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('test_string_32_64' => str_repeat('a', 65)), + 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' => str_repeat("\xC3\x84", 65)), array('SETTING_TOO_LONG'), ), From d004ef093fd96e5e84b22b5461f8e82594cd1f5e Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Fri, 10 Jun 2011 02:00:33 +0200 Subject: [PATCH 3/3] [ticket/10198] Test if schema allows reading & writing multibyte config values PHPBB3-10198 --- tests/dbal/schema_test.php | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 tests/dbal/schema_test.php diff --git a/tests/dbal/schema_test.php b/tests/dbal/schema_test.php new file mode 100644 index 0000000000..2475a85708 --- /dev/null +++ b/tests/dbal/schema_test.php @@ -0,0 +1,38 @@ +createXMLDataSet(dirname(__FILE__).'/fixtures/config.xml'); + } + + public function test_config_value_multibyte() + { + $db = $this->new_dbal(); + + $value = str_repeat("\xC3\x84", 255); + $sql = "INSERT INTO phpbb_config + (config_name, config_value) + VALUES ('name', '$value')"; + $result = $db->sql_query($sql); + + $sql = "SELECT config_value + FROM phpbb_config + WHERE config_name = 'name'"; + $result = $db->sql_query_limit($sql, 1); + $row = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + + $this->assertEquals($value, $row['config_value']); + } +}