From eb2de91e7b3982c2613f93ab05ce4a2001c0f163 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 16 Sep 2010 01:05:12 +0200 Subject: [PATCH 01/10] [ticket/9823] Moving the functions. Unit tests for build_select. PHPBB3-9823 --- phpBB/adm/index.php | 538 +------------------------- phpBB/includes/functions_acp.php | 546 +++++++++++++++++++++++++++ tests/functions_acp/all_tests.php | 40 ++ tests/functions_acp/build_select.php | 57 +++ 4 files changed, 644 insertions(+), 537 deletions(-) create mode 100644 phpBB/includes/functions_acp.php create mode 100644 tests/functions_acp/all_tests.php create mode 100644 tests/functions_acp/build_select.php diff --git a/phpBB/adm/index.php b/phpBB/adm/index.php index c4037d05bf..726cb1644c 100644 --- a/phpBB/adm/index.php +++ b/phpBB/adm/index.php @@ -18,6 +18,7 @@ define('NEED_SID', true); $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './../'; $phpEx = substr(strrchr(__FILE__, '.'), 1); require($phpbb_root_path . 'common.' . $phpEx); +require($phpbb_root_path . 'includes/functions_acp.' . $phpEx); require($phpbb_root_path . 'includes/functions_admin.' . $phpEx); require($phpbb_root_path . 'includes/functions_module.' . $phpEx); @@ -81,540 +82,3 @@ $template->set_filenames(array( )); adm_page_footer(); - -/** -* Header for acp pages -*/ -function adm_page_header($page_title) -{ - global $config, $db, $user, $template; - global $phpbb_root_path, $phpbb_admin_path, $phpEx, $SID, $_SID; - - if (defined('HEADER_INC')) - { - return; - } - - define('HEADER_INC', true); - - // gzip_compression - if ($config['gzip_compress']) - { - if (@extension_loaded('zlib') && !headers_sent()) - { - ob_start('ob_gzhandler'); - } - } - - $template->assign_vars(array( - 'PAGE_TITLE' => $page_title, - 'USERNAME' => $user->data['username'], - - 'SID' => $SID, - '_SID' => $_SID, - 'SESSION_ID' => $user->session_id, - 'ROOT_PATH' => $phpbb_admin_path, - - 'U_LOGOUT' => append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=logout'), - 'U_ADM_LOGOUT' => append_sid("{$phpbb_admin_path}index.$phpEx", 'action=admlogout'), - 'U_ADM_INDEX' => append_sid("{$phpbb_admin_path}index.$phpEx"), - 'U_INDEX' => append_sid("{$phpbb_root_path}index.$phpEx"), - - 'T_IMAGES_PATH' => "{$phpbb_root_path}images/", - 'T_SMILIES_PATH' => "{$phpbb_root_path}{$config['smilies_path']}/", - 'T_AVATAR_PATH' => "{$phpbb_root_path}{$config['avatar_path']}/", - 'T_AVATAR_GALLERY_PATH' => "{$phpbb_root_path}{$config['avatar_gallery_path']}/", - 'T_ICONS_PATH' => "{$phpbb_root_path}{$config['icons_path']}/", - 'T_RANKS_PATH' => "{$phpbb_root_path}{$config['ranks_path']}/", - 'T_UPLOAD_PATH' => "{$phpbb_root_path}{$config['upload_path']}/", - - 'ICON_MOVE_UP' => '' . $user->lang['MOVE_UP'] . '', - 'ICON_MOVE_UP_DISABLED' => '' . $user->lang['MOVE_UP'] . '', - 'ICON_MOVE_DOWN' => '' . $user->lang['MOVE_DOWN'] . '', - 'ICON_MOVE_DOWN_DISABLED' => '' . $user->lang['MOVE_DOWN'] . '', - 'ICON_EDIT' => '' . $user->lang['EDIT'] . '', - 'ICON_EDIT_DISABLED' => '' . $user->lang['EDIT'] . '', - 'ICON_DELETE' => '' . $user->lang['DELETE'] . '', - 'ICON_DELETE_DISABLED' => '' . $user->lang['DELETE'] . '', - 'ICON_SYNC' => '' . $user->lang['RESYNC'] . '', - 'ICON_SYNC_DISABLED' => '' . $user->lang['RESYNC'] . '', - - 'S_USER_LANG' => $user->lang['USER_LANG'], - 'S_CONTENT_DIRECTION' => $user->lang['DIRECTION'], - 'S_CONTENT_ENCODING' => 'UTF-8', - 'S_CONTENT_FLOW_BEGIN' => ($user->lang['DIRECTION'] == 'ltr') ? 'left' : 'right', - 'S_CONTENT_FLOW_END' => ($user->lang['DIRECTION'] == 'ltr') ? 'right' : 'left', - )); - - // application/xhtml+xml not used because of IE - header('Content-type: text/html; charset=UTF-8'); - - header('Cache-Control: private, no-cache="set-cookie"'); - header('Expires: 0'); - header('Pragma: no-cache'); - - return; -} - -/** -* Page footer for acp pages -*/ -function adm_page_footer($copyright_html = true) -{ - global $db, $config, $template, $user, $auth, $cache; - global $starttime, $phpbb_root_path, $phpbb_admin_path, $phpEx; - global $request; - - // Output page creation time - if (defined('DEBUG')) - { - $mtime = explode(' ', microtime()); - $totaltime = $mtime[0] + $mtime[1] - $starttime; - - if ($request->variable('explain', false) && $auth->acl_get('a_') && defined('DEBUG_EXTRA') && method_exists($db, 'sql_report')) - { - $db->sql_report('display'); - } - - $debug_output = sprintf('Time : %.3fs | ' . $db->sql_num_queries() . ' Queries | GZIP : ' . (($config['gzip_compress']) ? 'On' : 'Off') . (($user->load) ? ' | Load : ' . $user->load : ''), $totaltime); - - if ($auth->acl_get('a_') && defined('DEBUG_EXTRA')) - { - if (function_exists('memory_get_usage')) - { - if ($memory_usage = memory_get_usage()) - { - global $base_memory_usage; - $memory_usage -= $base_memory_usage; - $memory_usage = get_formatted_filesize($memory_usage); - - $debug_output .= ' | Memory Usage: ' . $memory_usage; - } - } - - $debug_output .= ' | Explain'; - } - } - - $template->assign_vars(array( - 'DEBUG_OUTPUT' => (defined('DEBUG')) ? $debug_output : '', - 'TRANSLATION_INFO' => (!empty($user->lang['TRANSLATION_INFO'])) ? $user->lang['TRANSLATION_INFO'] : '', - 'S_COPYRIGHT_HTML' => $copyright_html, - 'VERSION' => $config['version']) - ); - - $template->display('body'); - - garbage_collection(); - exit_handler(); -} - -/** -* Generate back link for acp pages -*/ -function adm_back_link($u_action) -{ - global $user; - return '

« ' . $user->lang['BACK_TO_PREV'] . ''; -} - -/** -* Build select field options in acp pages -*/ -function build_select($option_ary, $option_default = false) -{ - global $user; - - $html = ''; - foreach ($option_ary as $value => $title) - { - $selected = ($option_default !== false && $value == $option_default) ? ' selected="selected"' : ''; - $html .= ''; - } - - return $html; -} - -/** -* Build radio fields in acp pages -*/ -function h_radio($name, &$input_ary, $input_default = false, $id = false, $key = false) -{ - global $user; - - $html = ''; - $id_assigned = false; - foreach ($input_ary as $value => $title) - { - $selected = ($input_default !== false && $value == $input_default) ? ' checked="checked"' : ''; - $html .= ''; - $id_assigned = true; - } - - return $html; -} - -/** -* Build configuration template for acp configuration pages -*/ -function build_cfg_template($tpl_type, $key, &$new, $config_key, $vars) -{ - global $user, $module; - - $tpl = ''; - $name = 'config[' . $config_key . ']'; - - // Make sure there is no notice printed out for non-existent config options (we simply set them) - if (!isset($new[$config_key])) - { - $new[$config_key] = ''; - } - - switch ($tpl_type[0]) - { - case 'text': - case 'password': - $size = (int) $tpl_type[1]; - $maxlength = (int) $tpl_type[2]; - - $tpl = ''; - break; - - case 'dimension': - $size = (int) $tpl_type[1]; - $maxlength = (int) $tpl_type[2]; - - $tpl = ' x '; - break; - - case 'textarea': - $rows = (int) $tpl_type[1]; - $cols = (int) $tpl_type[2]; - - $tpl = ''; - break; - - case 'radio': - $key_yes = ($new[$config_key]) ? ' checked="checked"' : ''; - $key_no = (!$new[$config_key]) ? ' checked="checked"' : ''; - - $tpl_type_cond = explode('_', $tpl_type[1]); - $type_no = ($tpl_type_cond[0] == 'disabled' || $tpl_type_cond[0] == 'enabled') ? false : true; - - $tpl_no = ''; - $tpl_yes = ''; - - $tpl = ($tpl_type_cond[0] == 'yes' || $tpl_type_cond[0] == 'enabled') ? $tpl_yes . $tpl_no : $tpl_no . $tpl_yes; - break; - - case 'select': - case 'custom': - - $return = ''; - - if (isset($vars['method'])) - { - $call = array($module->module, $vars['method']); - } - else if (isset($vars['function'])) - { - $call = $vars['function']; - } - else - { - break; - } - - if (isset($vars['params'])) - { - $args = array(); - foreach ($vars['params'] as $value) - { - switch ($value) - { - case '{CONFIG_VALUE}': - $value = $new[$config_key]; - break; - - case '{KEY}': - $value = $key; - break; - } - - $args[] = $value; - } - } - else - { - $args = array($new[$config_key], $key); - } - - $return = call_user_func_array($call, $args); - - if ($tpl_type[0] == 'select') - { - $tpl = ''; - } - else - { - $tpl = $return; - } - - break; - - default: - break; - } - - if (isset($vars['append'])) - { - $tpl .= $vars['append']; - } - - return $tpl; -} - -/** -* Going through a config array and validate values, writing errors to $error. The validation method accepts parameters separated by ':' for string and int. -* The first parameter defines the type to be used, the second the lower bound and the third the upper bound. Only the type is required. -*/ -function validate_config_vars($config_vars, &$cfg_array, &$error) -{ - global $phpbb_root_path, $user; - $type = 0; - $min = 1; - $max = 2; - - foreach ($config_vars as $config_name => $config_definition) - { - if (!isset($cfg_array[$config_name]) || strpos($config_name, 'legend') !== false) - { - continue; - } - - if (!isset($config_definition['validate'])) - { - continue; - } - - $validator = explode(':', $config_definition['validate']); - - // Validate a bit. ;) (0 = type, 1 = min, 2= max) - switch ($validator[$type]) - { - case 'string': - $length = strlen($cfg_array[$config_name]); - - // the column is a VARCHAR - $validator[$max] = (isset($validator[$max])) ? min(255, $validator[$max]) : 255; - - if (isset($validator[$min]) && $length < $validator[$min]) - { - $error[] = sprintf($user->lang['SETTING_TOO_SHORT'], $user->lang[$config_definition['lang']], $validator[$min]); - } - else if (isset($validator[$max]) && $length > $validator[2]) - { - $error[] = sprintf($user->lang['SETTING_TOO_LONG'], $user->lang[$config_definition['lang']], $validator[$max]); - } - break; - - case 'bool': - $cfg_array[$config_name] = ($cfg_array[$config_name]) ? 1 : 0; - break; - - case 'int': - $cfg_array[$config_name] = (int) $cfg_array[$config_name]; - - if (isset($validator[$min]) && $cfg_array[$config_name] < $validator[$min]) - { - $error[] = sprintf($user->lang['SETTING_TOO_LOW'], $user->lang[$config_definition['lang']], $validator[$min]); - } - else if (isset($validator[$max]) && $cfg_array[$config_name] > $validator[$max]) - { - $error[] = sprintf($user->lang['SETTING_TOO_BIG'], $user->lang[$config_definition['lang']], $validator[$max]); - } - - if (strpos($config_name, '_max') !== false) - { - // Min/max pairs of settings should ensure that min <= max - // Replace _max with _min to find the name of the minimum - // corresponding configuration variable - $min_name = str_replace('_max', '_min', $config_name); - - if (isset($cfg_array[$min_name]) && is_numeric($cfg_array[$min_name]) && $cfg_array[$config_name] < $cfg_array[$min_name]) - { - // A minimum value exists and the maximum value is less than it - $error[] = sprintf($user->lang['SETTING_TOO_LOW'], $user->lang[$config_definition['lang']], (int) $cfg_array[$min_name]); - } - } - break; - - // Absolute path - case 'script_path': - if (!$cfg_array[$config_name]) - { - break; - } - - $destination = str_replace('\\', '/', $cfg_array[$config_name]); - - if ($destination !== '/') - { - // Adjust destination path (no trailing slash) - if (substr($destination, -1, 1) == '/') - { - $destination = substr($destination, 0, -1); - } - - $destination = str_replace(array('../', './'), '', $destination); - - if ($destination[0] != '/') - { - $destination = '/' . $destination; - } - } - - $cfg_array[$config_name] = trim($destination); - - break; - - // Absolute path - case 'lang': - if (!$cfg_array[$config_name]) - { - break; - } - - $cfg_array[$config_name] = basename($cfg_array[$config_name]); - - if (!file_exists($phpbb_root_path . 'language/' . $cfg_array[$config_name] . '/')) - { - $error[] = $user->lang['WRONG_DATA_LANG']; - } - break; - - // Relative path (appended $phpbb_root_path) - case 'rpath': - case 'rwpath': - if (!$cfg_array[$config_name]) - { - break; - } - - $destination = $cfg_array[$config_name]; - - // Adjust destination path (no trailing slash) - if (substr($destination, -1, 1) == '/' || substr($destination, -1, 1) == '\\') - { - $destination = substr($destination, 0, -1); - } - - $destination = str_replace(array('../', '..\\', './', '.\\'), '', $destination); - if ($destination && ($destination[0] == '/' || $destination[0] == "\\")) - { - $destination = ''; - } - - $cfg_array[$config_name] = trim($destination); - - // Path being relative (still prefixed by phpbb_root_path), but with the ability to escape the root dir... - case 'path': - case 'wpath': - - if (!$cfg_array[$config_name]) - { - break; - } - - $cfg_array[$config_name] = trim($cfg_array[$config_name]); - - // Make sure no NUL byte is present... - if (strpos($cfg_array[$config_name], "\0") !== false || strpos($cfg_array[$config_name], '%00') !== false) - { - $cfg_array[$config_name] = ''; - break; - } - - if (!file_exists($phpbb_root_path . $cfg_array[$config_name])) - { - $error[] = sprintf($user->lang['DIRECTORY_DOES_NOT_EXIST'], $cfg_array[$config_name]); - } - - if (file_exists($phpbb_root_path . $cfg_array[$config_name]) && !is_dir($phpbb_root_path . $cfg_array[$config_name])) - { - $error[] = sprintf($user->lang['DIRECTORY_NOT_DIR'], $cfg_array[$config_name]); - } - - // Check if the path is writable - if ($config_definition['validate'] == 'wpath' || $config_definition['validate'] == 'rwpath') - { - if (file_exists($phpbb_root_path . $cfg_array[$config_name]) && !phpbb_is_writable($phpbb_root_path . $cfg_array[$config_name])) - { - $error[] = sprintf($user->lang['DIRECTORY_NOT_WRITABLE'], $cfg_array[$config_name]); - } - } - - break; - } - } - - return; -} - -/** -* Checks whatever or not a variable is OK for use in the Database -* param mixed $value_ary An array of the form array(array('lang' => ..., 'value' => ..., 'column_type' =>))' -* param mixed $error The error array -*/ -function validate_range($value_ary, &$error) -{ - global $user; - - $column_types = array( - 'BOOL' => array('php_type' => 'int', 'min' => 0, 'max' => 1), - 'USINT' => array('php_type' => 'int', 'min' => 0, 'max' => 65535), - 'UINT' => array('php_type' => 'int', 'min' => 0, 'max' => (int) 0x7fffffff), - 'INT' => array('php_type' => 'int', 'min' => (int) 0x80000000, 'max' => (int) 0x7fffffff), - 'TINT' => array('php_type' => 'int', 'min' => -128, 'max' => 127), - - 'VCHAR' => array('php_type' => 'string', 'min' => 0, 'max' => 255), - ); - foreach ($value_ary as $value) - { - $column = explode(':', $value['column_type']); - $max = $min = 0; - $type = 0; - if (!isset($column_types[$column[0]])) - { - continue; - } - else - { - $type = $column_types[$column[0]]; - } - - switch ($type['php_type']) - { - case 'string' : - $max = (isset($column[1])) ? min($column[1],$type['max']) : $type['max']; - if (strlen($value['value']) > $max) - { - $error[] = sprintf($user->lang['SETTING_TOO_LONG'], $user->lang[$value['lang']], $max); - } - break; - - case 'int': - $min = (isset($column[1])) ? max($column[1],$type['min']) : $type['min']; - $max = (isset($column[2])) ? min($column[2],$type['max']) : $type['max']; - if ($value['value'] < $min) - { - $error[] = sprintf($user->lang['SETTING_TOO_LOW'], $user->lang[$value['lang']], $min); - } - else if ($value['value'] > $max) - { - $error[] = sprintf($user->lang['SETTING_TOO_BIG'], $user->lang[$value['lang']], $max); - } - break; - } - } -} diff --git a/phpBB/includes/functions_acp.php b/phpBB/includes/functions_acp.php new file mode 100644 index 0000000000..40b92db1f5 --- /dev/null +++ b/phpBB/includes/functions_acp.php @@ -0,0 +1,546 @@ +assign_vars(array( + 'PAGE_TITLE' => $page_title, + 'USERNAME' => $user->data['username'], + + 'SID' => $SID, + '_SID' => $_SID, + 'SESSION_ID' => $user->session_id, + 'ROOT_PATH' => $phpbb_admin_path, + + 'U_LOGOUT' => append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=logout'), + 'U_ADM_LOGOUT' => append_sid("{$phpbb_admin_path}index.$phpEx", 'action=admlogout'), + 'U_ADM_INDEX' => append_sid("{$phpbb_admin_path}index.$phpEx"), + 'U_INDEX' => append_sid("{$phpbb_root_path}index.$phpEx"), + + 'T_IMAGES_PATH' => "{$phpbb_root_path}images/", + 'T_SMILIES_PATH' => "{$phpbb_root_path}{$config['smilies_path']}/", + 'T_AVATAR_PATH' => "{$phpbb_root_path}{$config['avatar_path']}/", + 'T_AVATAR_GALLERY_PATH' => "{$phpbb_root_path}{$config['avatar_gallery_path']}/", + 'T_ICONS_PATH' => "{$phpbb_root_path}{$config['icons_path']}/", + 'T_RANKS_PATH' => "{$phpbb_root_path}{$config['ranks_path']}/", + 'T_UPLOAD_PATH' => "{$phpbb_root_path}{$config['upload_path']}/", + + 'ICON_MOVE_UP' => '' . $user->lang['MOVE_UP'] . '', + 'ICON_MOVE_UP_DISABLED' => '' . $user->lang['MOVE_UP'] . '', + 'ICON_MOVE_DOWN' => '' . $user->lang['MOVE_DOWN'] . '', + 'ICON_MOVE_DOWN_DISABLED' => '' . $user->lang['MOVE_DOWN'] . '', + 'ICON_EDIT' => '' . $user->lang['EDIT'] . '', + 'ICON_EDIT_DISABLED' => '' . $user->lang['EDIT'] . '', + 'ICON_DELETE' => '' . $user->lang['DELETE'] . '', + 'ICON_DELETE_DISABLED' => '' . $user->lang['DELETE'] . '', + 'ICON_SYNC' => '' . $user->lang['RESYNC'] . '', + 'ICON_SYNC_DISABLED' => '' . $user->lang['RESYNC'] . '', + + 'S_USER_LANG' => $user->lang['USER_LANG'], + 'S_CONTENT_DIRECTION' => $user->lang['DIRECTION'], + 'S_CONTENT_ENCODING' => 'UTF-8', + 'S_CONTENT_FLOW_BEGIN' => ($user->lang['DIRECTION'] == 'ltr') ? 'left' : 'right', + 'S_CONTENT_FLOW_END' => ($user->lang['DIRECTION'] == 'ltr') ? 'right' : 'left', + )); + + // application/xhtml+xml not used because of IE + header('Content-type: text/html; charset=UTF-8'); + + header('Cache-Control: private, no-cache="set-cookie"'); + header('Expires: 0'); + header('Pragma: no-cache'); + + return; +} + +/** +* Page footer for acp pages +*/ +function adm_page_footer($copyright_html = true) +{ + global $db, $config, $template, $user, $auth, $cache; + global $starttime, $phpbb_root_path, $phpbb_admin_path, $phpEx; + + // Output page creation time + if (defined('DEBUG')) + { + $mtime = explode(' ', microtime()); + $totaltime = $mtime[0] + $mtime[1] - $starttime; + + if (!empty($_REQUEST['explain']) && $auth->acl_get('a_') && defined('DEBUG_EXTRA') && method_exists($db, 'sql_report')) + { + $db->sql_report('display'); + } + + $debug_output = sprintf('Time : %.3fs | ' . $db->sql_num_queries() . ' Queries | GZIP : ' . (($config['gzip_compress']) ? 'On' : 'Off') . (($user->load) ? ' | Load : ' . $user->load : ''), $totaltime); + + if ($auth->acl_get('a_') && defined('DEBUG_EXTRA')) + { + if (function_exists('memory_get_usage')) + { + if ($memory_usage = memory_get_usage()) + { + global $base_memory_usage; + $memory_usage -= $base_memory_usage; + $memory_usage = get_formatted_filesize($memory_usage); + + $debug_output .= ' | Memory Usage: ' . $memory_usage; + } + } + + $debug_output .= ' | Explain'; + } + } + + $template->assign_vars(array( + 'DEBUG_OUTPUT' => (defined('DEBUG')) ? $debug_output : '', + 'TRANSLATION_INFO' => (!empty($user->lang['TRANSLATION_INFO'])) ? $user->lang['TRANSLATION_INFO'] : '', + 'S_COPYRIGHT_HTML' => $copyright_html, + 'VERSION' => $config['version']) + ); + + $template->display('body'); + + garbage_collection(); + exit_handler(); +} + +/** +* Generate back link for acp pages +*/ +function adm_back_link($u_action) +{ + global $user; + return '

« ' . $user->lang['BACK_TO_PREV'] . ''; +} + +/** +* Build select field options in acp pages +*/ +function build_select($option_ary, $option_default = false) +{ + global $user; + + $html = ''; + foreach ($option_ary as $value => $title) + { + $selected = ($option_default !== false && $value == $option_default) ? ' selected="selected"' : ''; + $html .= ''; + } + + return $html; +} + +/** +* Build radio fields in acp pages +*/ +function h_radio($name, &$input_ary, $input_default = false, $id = false, $key = false) +{ + global $user; + + $html = ''; + $id_assigned = false; + foreach ($input_ary as $value => $title) + { + $selected = ($input_default !== false && $value == $input_default) ? ' checked="checked"' : ''; + $html .= ''; + $id_assigned = true; + } + + return $html; +} + +/** +* Build configuration template for acp configuration pages +*/ +function build_cfg_template($tpl_type, $key, &$new, $config_key, $vars) +{ + global $user, $module; + + $tpl = ''; + $name = 'config[' . $config_key . ']'; + + // Make sure there is no notice printed out for non-existent config options (we simply set them) + if (!isset($new[$config_key])) + { + $new[$config_key] = ''; + } + + switch ($tpl_type[0]) + { + case 'text': + case 'password': + $size = (int) $tpl_type[1]; + $maxlength = (int) $tpl_type[2]; + + $tpl = ''; + break; + + case 'dimension': + $size = (int) $tpl_type[1]; + $maxlength = (int) $tpl_type[2]; + + $tpl = ' x '; + break; + + case 'textarea': + $rows = (int) $tpl_type[1]; + $cols = (int) $tpl_type[2]; + + $tpl = ''; + break; + + case 'radio': + $key_yes = ($new[$config_key]) ? ' checked="checked"' : ''; + $key_no = (!$new[$config_key]) ? ' checked="checked"' : ''; + + $tpl_type_cond = explode('_', $tpl_type[1]); + $type_no = ($tpl_type_cond[0] == 'disabled' || $tpl_type_cond[0] == 'enabled') ? false : true; + + $tpl_no = ''; + $tpl_yes = ''; + + $tpl = ($tpl_type_cond[0] == 'yes' || $tpl_type_cond[0] == 'enabled') ? $tpl_yes . $tpl_no : $tpl_no . $tpl_yes; + break; + + case 'select': + case 'custom': + + $return = ''; + + if (isset($vars['method'])) + { + $call = array($module->module, $vars['method']); + } + else if (isset($vars['function'])) + { + $call = $vars['function']; + } + else + { + break; + } + + if (isset($vars['params'])) + { + $args = array(); + foreach ($vars['params'] as $value) + { + switch ($value) + { + case '{CONFIG_VALUE}': + $value = $new[$config_key]; + break; + + case '{KEY}': + $value = $key; + break; + } + + $args[] = $value; + } + } + else + { + $args = array($new[$config_key], $key); + } + + $return = call_user_func_array($call, $args); + + if ($tpl_type[0] == 'select') + { + $tpl = ''; + } + else + { + $tpl = $return; + } + + break; + + default: + break; + } + + if (isset($vars['append'])) + { + $tpl .= $vars['append']; + } + + return $tpl; +} + +/** +* Going through a config array and validate values, writing errors to $error. The validation method accepts parameters separated by ':' for string and int. +* The first parameter defines the type to be used, the second the lower bound and the third the upper bound. Only the type is required. +*/ +function validate_config_vars($config_vars, &$cfg_array, &$error) +{ + global $phpbb_root_path, $user; + $type = 0; + $min = 1; + $max = 2; + + foreach ($config_vars as $config_name => $config_definition) + { + if (!isset($cfg_array[$config_name]) || strpos($config_name, 'legend') !== false) + { + continue; + } + + if (!isset($config_definition['validate'])) + { + continue; + } + + $validator = explode(':', $config_definition['validate']); + + // Validate a bit. ;) (0 = type, 1 = min, 2= max) + switch ($validator[$type]) + { + case 'string': + $length = strlen($cfg_array[$config_name]); + + // the column is a VARCHAR + $validator[$max] = (isset($validator[$max])) ? min(255, $validator[$max]) : 255; + + if (isset($validator[$min]) && $length < $validator[$min]) + { + $error[] = sprintf($user->lang['SETTING_TOO_SHORT'], $user->lang[$config_definition['lang']], $validator[$min]); + } + else if (isset($validator[$max]) && $length > $validator[2]) + { + $error[] = sprintf($user->lang['SETTING_TOO_LONG'], $user->lang[$config_definition['lang']], $validator[$max]); + } + break; + + case 'bool': + $cfg_array[$config_name] = ($cfg_array[$config_name]) ? 1 : 0; + break; + + case 'int': + $cfg_array[$config_name] = (int) $cfg_array[$config_name]; + + if (isset($validator[$min]) && $cfg_array[$config_name] < $validator[$min]) + { + $error[] = sprintf($user->lang['SETTING_TOO_LOW'], $user->lang[$config_definition['lang']], $validator[$min]); + } + else if (isset($validator[$max]) && $cfg_array[$config_name] > $validator[$max]) + { + $error[] = sprintf($user->lang['SETTING_TOO_BIG'], $user->lang[$config_definition['lang']], $validator[$max]); + } + + if (strpos($config_name, '_max') !== false) + { + // Min/max pairs of settings should ensure that min <= max + // Replace _max with _min to find the name of the minimum + // corresponding configuration variable + $min_name = str_replace('_max', '_min', $config_name); + + if (isset($cfg_array[$min_name]) && is_numeric($cfg_array[$min_name]) && $cfg_array[$config_name] < $cfg_array[$min_name]) + { + // A minimum value exists and the maximum value is less than it + $error[] = sprintf($user->lang['SETTING_TOO_LOW'], $user->lang[$config_definition['lang']], (int) $cfg_array[$min_name]); + } + } + break; + + // Absolute path + case 'script_path': + if (!$cfg_array[$config_name]) + { + break; + } + + $destination = str_replace('\\', '/', $cfg_array[$config_name]); + + if ($destination !== '/') + { + // Adjust destination path (no trailing slash) + if (substr($destination, -1, 1) == '/') + { + $destination = substr($destination, 0, -1); + } + + $destination = str_replace(array('../', './'), '', $destination); + + if ($destination[0] != '/') + { + $destination = '/' . $destination; + } + } + + $cfg_array[$config_name] = trim($destination); + + break; + + // Absolute path + case 'lang': + if (!$cfg_array[$config_name]) + { + break; + } + + $cfg_array[$config_name] = basename($cfg_array[$config_name]); + + if (!file_exists($phpbb_root_path . 'language/' . $cfg_array[$config_name] . '/')) + { + $error[] = $user->lang['WRONG_DATA_LANG']; + } + break; + + // Relative path (appended $phpbb_root_path) + case 'rpath': + case 'rwpath': + if (!$cfg_array[$config_name]) + { + break; + } + + $destination = $cfg_array[$config_name]; + + // Adjust destination path (no trailing slash) + if (substr($destination, -1, 1) == '/' || substr($destination, -1, 1) == '\\') + { + $destination = substr($destination, 0, -1); + } + + $destination = str_replace(array('../', '..\\', './', '.\\'), '', $destination); + if ($destination && ($destination[0] == '/' || $destination[0] == "\\")) + { + $destination = ''; + } + + $cfg_array[$config_name] = trim($destination); + + // Path being relative (still prefixed by phpbb_root_path), but with the ability to escape the root dir... + case 'path': + case 'wpath': + + if (!$cfg_array[$config_name]) + { + break; + } + + $cfg_array[$config_name] = trim($cfg_array[$config_name]); + + // Make sure no NUL byte is present... + if (strpos($cfg_array[$config_name], "\0") !== false || strpos($cfg_array[$config_name], '%00') !== false) + { + $cfg_array[$config_name] = ''; + break; + } + + if (!file_exists($phpbb_root_path . $cfg_array[$config_name])) + { + $error[] = sprintf($user->lang['DIRECTORY_DOES_NOT_EXIST'], $cfg_array[$config_name]); + } + + if (file_exists($phpbb_root_path . $cfg_array[$config_name]) && !is_dir($phpbb_root_path . $cfg_array[$config_name])) + { + $error[] = sprintf($user->lang['DIRECTORY_NOT_DIR'], $cfg_array[$config_name]); + } + + // Check if the path is writable + if ($config_definition['validate'] == 'wpath' || $config_definition['validate'] == 'rwpath') + { + if (file_exists($phpbb_root_path . $cfg_array[$config_name]) && !phpbb_is_writable($phpbb_root_path . $cfg_array[$config_name])) + { + $error[] = sprintf($user->lang['DIRECTORY_NOT_WRITABLE'], $cfg_array[$config_name]); + } + } + + break; + } + } + + return; +} + +/** +* Checks whatever or not a variable is OK for use in the Database +* param mixed $value_ary An array of the form array(array('lang' => ..., 'value' => ..., 'column_type' =>))' +* param mixed $error The error array +*/ +function validate_range($value_ary, &$error) +{ + global $user; + + $column_types = array( + 'BOOL' => array('php_type' => 'int', 'min' => 0, 'max' => 1), + 'USINT' => array('php_type' => 'int', 'min' => 0, 'max' => 65535), + 'UINT' => array('php_type' => 'int', 'min' => 0, 'max' => (int) 0x7fffffff), + 'INT' => array('php_type' => 'int', 'min' => (int) 0x80000000, 'max' => (int) 0x7fffffff), + 'TINT' => array('php_type' => 'int', 'min' => -128, 'max' => 127), + + 'VCHAR' => array('php_type' => 'string', 'min' => 0, 'max' => 255), + ); + + foreach ($value_ary as $value) + { + $column = explode(':', $value['column_type']); + $max = $min = 0; + $type = 0; + if (!isset($column_types[$column[0]])) + { + continue; + } + else + { + $type = $column_types[$column[0]]; + } + + switch ($type['php_type']) + { + case 'string' : + $max = (isset($column[1])) ? min($column[1], $type['max']) : $type['max']; + if (strlen($value['value']) > $max) + { + $error[] = sprintf($user->lang['SETTING_TOO_LONG'], $user->lang[$value['lang']], $max); + } + break; + + case 'int': + $min = (isset($column[1])) ? max($column[1], $type['min']) : $type['min']; + $max = (isset($column[2])) ? min($column[2], $type['max']) : $type['max']; + if ($value['value'] < $min) + { + $error[] = sprintf($user->lang['SETTING_TOO_LOW'], $user->lang[$value['lang']], $min); + } + else if ($value['value'] > $max) + { + $error[] = sprintf($user->lang['SETTING_TOO_BIG'], $user->lang[$value['lang']], $max); + } + break; + } + } +} diff --git a/tests/functions_acp/all_tests.php b/tests/functions_acp/all_tests.php new file mode 100644 index 0000000000..6b2d676e60 --- /dev/null +++ b/tests/functions_acp/all_tests.php @@ -0,0 +1,40 @@ +addTestSuite('phpbb_functions_acp_built_select_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_select.php b/tests/functions_acp/build_select.php new file mode 100644 index 0000000000..5a097fefab --- /dev/null +++ b/tests/functions_acp/build_select.php @@ -0,0 +1,57 @@ + '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)); + } +} From d59327a9c4dfcef41ccb884f396dadeff6aa1fbd Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 16 Sep 2010 01:07:12 +0200 Subject: [PATCH 02/10] [ticket/9823] Unit tests for h_radio. PHPBB3-9823 --- tests/functions_acp/all_tests.php | 2 + tests/functions_acp/h_radio.php | 122 ++++++++++++++++++++++++++++++ tests/functions_acp/user_mock.php | 33 ++++++++ 3 files changed, 157 insertions(+) create mode 100644 tests/functions_acp/h_radio.php create mode 100644 tests/functions_acp/user_mock.php diff --git a/tests/functions_acp/all_tests.php b/tests/functions_acp/all_tests.php index 6b2d676e60..d5f0c86dc9 100644 --- a/tests/functions_acp/all_tests.php +++ b/tests/functions_acp/all_tests.php @@ -16,6 +16,7 @@ require_once 'test_framework/framework.php'; require_once 'PHPUnit/TextUI/TestRunner.php'; require_once 'functions_acp/build_select.php'; +require_once 'functions_acp/h_radio.php'; class phpbb_functions_acp_all_tests { @@ -29,6 +30,7 @@ class phpbb_functions_acp_all_tests $suite = new PHPUnit_Framework_TestSuite('phpBB Network Functions'); $suite->addTestSuite('phpbb_functions_acp_built_select_test'); + $suite->addTestSuite('phpbb_functions_acp_h_radio_test'); return $suite; } diff --git a/tests/functions_acp/h_radio.php b/tests/functions_acp/h_radio.php new file mode 100644 index 0000000000..6550c8f818 --- /dev/null +++ b/tests/functions_acp/h_radio.php @@ -0,0 +1,122 @@ + '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/user_mock.php b/tests/functions_acp/user_mock.php new file mode 100644 index 0000000000..c7f62fc39b --- /dev/null +++ b/tests/functions_acp/user_mock.php @@ -0,0 +1,33 @@ + Date: Thu, 16 Sep 2010 01:08:18 +0200 Subject: [PATCH 03/10] [ticket/9823] Unit tests for validate_rang. PHPBB3-9823 --- tests/functions_acp/all_tests.php | 2 + tests/functions_acp/validate_range.php | 185 +++++++++++++++++++++++++ 2 files changed, 187 insertions(+) create mode 100644 tests/functions_acp/validate_range.php diff --git a/tests/functions_acp/all_tests.php b/tests/functions_acp/all_tests.php index d5f0c86dc9..2b9c06f0ed 100644 --- a/tests/functions_acp/all_tests.php +++ b/tests/functions_acp/all_tests.php @@ -17,6 +17,7 @@ require_once 'PHPUnit/TextUI/TestRunner.php'; require_once 'functions_acp/build_select.php'; require_once 'functions_acp/h_radio.php'; +require_once 'functions_acp/validate_range.php'; class phpbb_functions_acp_all_tests { @@ -31,6 +32,7 @@ class phpbb_functions_acp_all_tests $suite->addTestSuite('phpbb_functions_acp_built_select_test'); $suite->addTestSuite('phpbb_functions_acp_h_radio_test'); + $suite->addTestSuite('phpbb_functions_acp_validate_range_test'); return $suite; } diff --git a/tests/functions_acp/validate_range.php b/tests/functions_acp/validate_range.php new file mode 100644 index 0000000000..fc2eaf1a60 --- /dev/null +++ b/tests/functions_acp/validate_range.php @@ -0,0 +1,185 @@ + array('php_type' => 'int', 'min' => 0, 'max' => 1), + 'USINT' => array('php_type' => 'int', 'min' => 0, 'max' => 65535), + 'UINT' => array('php_type' => 'int', 'min' => 0, 'max' => (int) 0x7fffffff), + 'INT' => array('php_type' => 'int', 'min' => (int) 0x80000000, 'max' => (int) 0x7fffffff), + 'TINT' => array('php_type' => 'int', 'min' => -128, 'max' => 127), + + 'VCHAR' => array('php_type' => 'string', 'min' => 0, 'max' => 255), +*/ + 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) 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' => phpbb_functions_acp_validate_range_test::return_string(255)))), + array(array(array('column_type' => 'VCHAR:128', 'lang' => 'TEST', 'value' => phpbb_functions_acp_validate_range_test::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' => phpbb_functions_acp_validate_range_test::return_string(256)))), + array(array(array('column_type' => 'VCHAR:128', 'lang' => 'TEST', 'value' => phpbb_functions_acp_validate_range_test::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); + } +} From 11e3804f97fc0ac5317d8e211c117c6572699976 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 16 Sep 2010 01:09:56 +0200 Subject: [PATCH 04/10] [ticket/9823] Unit tests for build_cfg_template. PHPBB3-9823 --- tests/functions_acp/all_tests.php | 2 + tests/functions_acp/build_cfg_template.php | 193 +++++++++++++++++++++ 2 files changed, 195 insertions(+) create mode 100644 tests/functions_acp/build_cfg_template.php diff --git a/tests/functions_acp/all_tests.php b/tests/functions_acp/all_tests.php index 2b9c06f0ed..d2895da311 100644 --- a/tests/functions_acp/all_tests.php +++ b/tests/functions_acp/all_tests.php @@ -15,6 +15,7 @@ if (!defined('PHPUnit_MAIN_METHOD')) require_once 'test_framework/framework.php'; require_once 'PHPUnit/TextUI/TestRunner.php'; +require_once 'functions_acp/build_cfg_template.php'; require_once 'functions_acp/build_select.php'; require_once 'functions_acp/h_radio.php'; require_once 'functions_acp/validate_range.php'; @@ -30,6 +31,7 @@ class phpbb_functions_acp_all_tests { $suite = new PHPUnit_Framework_TestSuite('phpBB Network Functions'); + $suite->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_range_test'); diff --git a/tests/functions_acp/build_cfg_template.php b/tests/functions_acp/build_cfg_template.php new file mode 100644 index 0000000000..07f82e933a --- /dev/null +++ b/tests/functions_acp/build_cfg_template.php @@ -0,0 +1,193 @@ + '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)); + } +} From 737849bc23dc8081a82f00c78247e824b6a42daf Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 16 Sep 2010 13:04:12 +0200 Subject: [PATCH 05/10] [ticket/9823] Unit tests for validate_config_vars. Fix some documentations and use the $max-var instead of the magic-number in validate_config_vars. PHPBB3-9823 --- phpBB/includes/functions_acp.php | 4 +- tests/functions_acp/all_tests.php | 2 + tests/functions_acp/validate_config_vars.php | 152 +++++++++++++++++++ tests/functions_acp/validate_range.php | 11 +- 4 files changed, 159 insertions(+), 10 deletions(-) create mode 100644 tests/functions_acp/validate_config_vars.php diff --git a/phpBB/includes/functions_acp.php b/phpBB/includes/functions_acp.php index 40b92db1f5..af419c4288 100644 --- a/phpBB/includes/functions_acp.php +++ b/phpBB/includes/functions_acp.php @@ -300,7 +300,7 @@ function build_cfg_template($tpl_type, $key, &$new, $config_key, $vars) } /** -* Going through a config array and validate values, writing errors to $error. The validation method accepts parameters separated by ':' for string and int. +* Going through a config array and validate values, writing errors to $error. The validation method accepts parameters separated by ':' for string and int. * The first parameter defines the type to be used, the second the lower bound and the third the upper bound. Only the type is required. */ function validate_config_vars($config_vars, &$cfg_array, &$error) @@ -337,7 +337,7 @@ function validate_config_vars($config_vars, &$cfg_array, &$error) { $error[] = sprintf($user->lang['SETTING_TOO_SHORT'], $user->lang[$config_definition['lang']], $validator[$min]); } - else if (isset($validator[$max]) && $length > $validator[2]) + else if (isset($validator[$max]) && $length > $validator[$max]) { $error[] = sprintf($user->lang['SETTING_TOO_LONG'], $user->lang[$config_definition['lang']], $validator[$max]); } diff --git a/tests/functions_acp/all_tests.php b/tests/functions_acp/all_tests.php index d2895da311..64956593fd 100644 --- a/tests/functions_acp/all_tests.php +++ b/tests/functions_acp/all_tests.php @@ -18,6 +18,7 @@ require_once 'PHPUnit/TextUI/TestRunner.php'; require_once 'functions_acp/build_cfg_template.php'; require_once 'functions_acp/build_select.php'; require_once 'functions_acp/h_radio.php'; +require_once 'functions_acp/validate_config_vars.php'; require_once 'functions_acp/validate_range.php'; class phpbb_functions_acp_all_tests @@ -34,6 +35,7 @@ class phpbb_functions_acp_all_tests $suite->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; diff --git a/tests/functions_acp/validate_config_vars.php b/tests/functions_acp/validate_config_vars.php new file mode 100644 index 0000000000..be7c3bf6de --- /dev/null +++ b/tests/functions_acp/validate_config_vars.php @@ -0,0 +1,152 @@ + 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' => phpbb_functions_acp_validate_config_vars_test::return_string(255), + 'test_string_128' => phpbb_functions_acp_validate_config_vars_test::return_string(128), + 'test_string_32_64' => phpbb_functions_acp_validate_config_vars_test::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' => phpbb_functions_acp_validate_config_vars_test::return_string(20)), + array('SETTING_TOO_SHORT'), + ), + array( + array('test_string' => array('lang' => 'TEST_STRING', 'validate' => 'string')), + array('test_string' => phpbb_functions_acp_validate_config_vars_test::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' => phpbb_functions_acp_validate_config_vars_test::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 index fc2eaf1a60..253ef8d266 100644 --- a/tests/functions_acp/validate_range.php +++ b/tests/functions_acp/validate_range.php @@ -13,14 +13,9 @@ require_once '../phpBB/includes/functions_acp.php'; class phpbb_functions_acp_validate_range_test extends phpbb_test_case { -/* 'BOOL' => array('php_type' => 'int', 'min' => 0, 'max' => 1), - 'USINT' => array('php_type' => 'int', 'min' => 0, 'max' => 65535), - 'UINT' => array('php_type' => 'int', 'min' => 0, 'max' => (int) 0x7fffffff), - 'INT' => array('php_type' => 'int', 'min' => (int) 0x80000000, 'max' => (int) 0x7fffffff), - 'TINT' => array('php_type' => 'int', 'min' => -128, 'max' => 127), - - 'VCHAR' => array('php_type' => 'string', 'min' => 0, 'max' => 255), -*/ + /** + * Helper function which returns a string in a given length. + */ static public function return_string($length) { $string = ''; From 1dd5058d519e2812f6bbe234b6d0bdf07c87f774 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 27 Jan 2011 19:14:56 +0100 Subject: [PATCH 06/10] [ticket/9823] Correct unit-tests to use self:: instead of the class-name. PHPBB3-9823 --- tests/functions_acp/validate_config_vars.php | 12 ++++++------ tests/functions_acp/validate_range.php | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/functions_acp/validate_config_vars.php b/tests/functions_acp/validate_config_vars.php index be7c3bf6de..04a5fead7a 100644 --- a/tests/functions_acp/validate_config_vars.php +++ b/tests/functions_acp/validate_config_vars.php @@ -52,9 +52,9 @@ class phpbb_functions_acp_validate_config_vars_test extends phpbb_test_case ), array( 'test_bool' => true, - 'test_string' => phpbb_functions_acp_validate_config_vars_test::return_string(255), - 'test_string_128' => phpbb_functions_acp_validate_config_vars_test::return_string(128), - 'test_string_32_64' => phpbb_functions_acp_validate_config_vars_test::return_string(48), + '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, @@ -87,17 +87,17 @@ 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' => phpbb_functions_acp_validate_config_vars_test::return_string(20)), + 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' => phpbb_functions_acp_validate_config_vars_test::return_string(256)), + 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' => phpbb_functions_acp_validate_config_vars_test::return_string(65)), + array('test_string_32_64' => self::return_string(65)), array('SETTING_TOO_LONG'), ), diff --git a/tests/functions_acp/validate_range.php b/tests/functions_acp/validate_range.php index 253ef8d266..cac54dd5ed 100644 --- a/tests/functions_acp/validate_range.php +++ b/tests/functions_acp/validate_range.php @@ -54,8 +54,8 @@ 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' => phpbb_functions_acp_validate_range_test::return_string(255)))), - array(array(array('column_type' => 'VCHAR:128', 'lang' => 'TEST', 'value' => phpbb_functions_acp_validate_range_test::return_string(128)))), + 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)))), ); } @@ -158,8 +158,8 @@ 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' => phpbb_functions_acp_validate_range_test::return_string(256)))), - array(array(array('column_type' => 'VCHAR:128', 'lang' => 'TEST', 'value' => phpbb_functions_acp_validate_range_test::return_string(129)))), + 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)))), ); } From 2b70f3d0e2c85f4ff639aec1077afff3154506dc Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 1 Feb 2011 08:57:04 +0100 Subject: [PATCH 07/10] [ticket/9823] Update copyright year and add newline at the end of the file. PHPBB3-9823 --- tests/functions_acp/user_mock.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/functions_acp/user_mock.php b/tests/functions_acp/user_mock.php index c7f62fc39b..17a39629c1 100644 --- a/tests/functions_acp/user_mock.php +++ b/tests/functions_acp/user_mock.php @@ -2,7 +2,7 @@ /** * * @package testing -* @copyright (c) 2008 phpBB Group +* @copyright (c) 2010 phpBB Group * @license http://opensource.org/licenses/gpl-license.php GNU Public License * */ @@ -30,4 +30,4 @@ class phpbb_mock_lang implements ArrayAccess public function offsetUnset($offset) { } -} \ No newline at end of file +} From 6b00d7aa096b01ce6e59a8467f79eb193c25a35b Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 1 Feb 2011 14:09:52 +0100 Subject: [PATCH 08/10] [ticket/9823] Update Unit tests to the new system and correct some minor issues PHPBB3-9823 --- tests/functions_acp/all_tests.php | 48 ------------------- ...mplate.php => build_cfg_template_test.php} | 15 +++--- ...build_select.php => build_select_test.php} | 7 ++- .../{h_radio.php => h_radio_test.php} | 7 ++- ...vars.php => validate_config_vars_test.php} | 5 +- ...date_range.php => validate_range_test.php} | 5 +- 6 files changed, 17 insertions(+), 70 deletions(-) delete mode 100644 tests/functions_acp/all_tests.php rename tests/functions_acp/{build_cfg_template.php => build_cfg_template_test.php} (94%) rename tests/functions_acp/{build_select.php => build_select_test.php} (86%) rename tests/functions_acp/{h_radio.php => h_radio_test.php} (94%) rename tests/functions_acp/{validate_config_vars.php => validate_config_vars_test.php} (96%) rename tests/functions_acp/{validate_range.php => validate_range_test.php} (97%) 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_test.php similarity index 94% rename from tests/functions_acp/build_cfg_template.php rename to tests/functions_acp/build_cfg_template_test.php index 07f82e933a..c573c7cdb0 100644 --- a/tests/functions_acp/build_cfg_template.php +++ b/tests/functions_acp/build_cfg_template_test.php @@ -7,9 +7,8 @@ * */ -require_once 'test_framework/framework.php'; -require_once 'functions_acp/user_mock.php'; -require_once '../phpBB/includes/functions_acp.php'; +require_once dirname(__FILE__) . 'user_mock.php'; +require_once dirname(__FILE__) . '../../phpBB/includes/functions_acp.php'; class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case { @@ -50,7 +49,7 @@ class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case { global $user; - $user->lang =new phpbb_mock_lang(); + $user->lang = new phpbb_mock_lang(); $this->assertEquals($expected, build_cfg_template($tpl_type, $key, $new, $config_key, $vars)); } @@ -84,7 +83,7 @@ class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case { global $user; - $user->lang =new phpbb_mock_lang(); + $user->lang = new phpbb_mock_lang(); $this->assertEquals($expected, build_cfg_template($tpl_type, $key, $new, $config_key, $vars)); } @@ -110,7 +109,7 @@ class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case { global $user; - $user->lang =new phpbb_mock_lang(); + $user->lang = new phpbb_mock_lang(); $this->assertEquals($expected, build_cfg_template($tpl_type, $key, $new, $config_key, $vars)); } @@ -160,7 +159,7 @@ class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case { global $user; - $user->lang =new phpbb_mock_lang(); + $user->lang = new phpbb_mock_lang(); $this->assertEquals($expected, build_cfg_template($tpl_type, $key, $new, $config_key, $vars)); } @@ -186,7 +185,7 @@ class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case { global $user; - $user->lang =new phpbb_mock_lang(); + $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_test.php similarity index 86% rename from tests/functions_acp/build_select.php rename to tests/functions_acp/build_select_test.php index 5a097fefab..a4f5e419ea 100644 --- a/tests/functions_acp/build_select.php +++ b/tests/functions_acp/build_select_test.php @@ -7,9 +7,8 @@ * */ -require_once 'test_framework/framework.php'; -require_once 'functions_acp/user_mock.php'; -require_once '../phpBB/includes/functions_acp.php'; +require_once dirname(__FILE__) . 'user_mock.php'; +require_once dirname(__FILE__) . '../../phpBB/includes/functions_acp.php'; class phpbb_functions_acp_built_select_test extends phpbb_test_case { @@ -50,7 +49,7 @@ class phpbb_functions_acp_built_select_test extends phpbb_test_case { global $user; - $user->lang =new phpbb_mock_lang(); + $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_test.php similarity index 94% rename from tests/functions_acp/h_radio.php rename to tests/functions_acp/h_radio_test.php index 6550c8f818..924b502ede 100644 --- a/tests/functions_acp/h_radio.php +++ b/tests/functions_acp/h_radio_test.php @@ -7,9 +7,8 @@ * */ -require_once 'test_framework/framework.php'; -require_once 'functions_acp/user_mock.php'; -require_once '../phpBB/includes/functions_acp.php'; +require_once dirname(__FILE__) . 'user_mock.php'; +require_once dirname(__FILE__) . '../../phpBB/includes/functions_acp.php'; class phpbb_functions_acp_h_radio_test extends phpbb_test_case { @@ -115,7 +114,7 @@ class phpbb_functions_acp_h_radio_test extends phpbb_test_case { global $user; - $user->lang =new phpbb_mock_lang(); + $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_test.php similarity index 96% rename from tests/functions_acp/validate_config_vars.php rename to tests/functions_acp/validate_config_vars_test.php index 04a5fead7a..722d0ebddb 100644 --- a/tests/functions_acp/validate_config_vars.php +++ b/tests/functions_acp/validate_config_vars_test.php @@ -7,9 +7,8 @@ * */ -require_once 'test_framework/framework.php'; -require_once 'functions_acp/user_mock.php'; -require_once '../phpBB/includes/functions_acp.php'; +require_once dirname(__FILE__) . 'user_mock.php'; +require_once dirname(__FILE__) . '../../phpBB/includes/functions_acp.php'; class phpbb_functions_acp_validate_config_vars_test extends phpbb_test_case { diff --git a/tests/functions_acp/validate_range.php b/tests/functions_acp/validate_range_test.php similarity index 97% rename from tests/functions_acp/validate_range.php rename to tests/functions_acp/validate_range_test.php index cac54dd5ed..fb1d15c032 100644 --- a/tests/functions_acp/validate_range.php +++ b/tests/functions_acp/validate_range_test.php @@ -7,9 +7,8 @@ * */ -require_once 'test_framework/framework.php'; -require_once 'functions_acp/user_mock.php'; -require_once '../phpBB/includes/functions_acp.php'; +require_once dirname(__FILE__) . 'user_mock.php'; +require_once dirname(__FILE__) . '../../phpBB/includes/functions_acp.php'; class phpbb_functions_acp_validate_range_test extends phpbb_test_case { From 9846d806f3bc719138f237b64c8ca7db961838e8 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 1 Feb 2011 14:54:29 +0100 Subject: [PATCH 09/10] [ticket/9823] Move mock file into the mock/ folder. PHPBB3-9823 --- tests/functions_acp/build_cfg_template_test.php | 4 ++-- tests/functions_acp/build_select_test.php | 4 ++-- tests/functions_acp/h_radio_test.php | 4 ++-- tests/functions_acp/validate_config_vars_test.php | 4 ++-- tests/functions_acp/validate_range_test.php | 4 ++-- tests/{functions_acp/user_mock.php => mock/lang.php} | 0 6 files changed, 10 insertions(+), 10 deletions(-) rename tests/{functions_acp/user_mock.php => mock/lang.php} (100%) diff --git a/tests/functions_acp/build_cfg_template_test.php b/tests/functions_acp/build_cfg_template_test.php index c573c7cdb0..7bf85a3532 100644 --- a/tests/functions_acp/build_cfg_template_test.php +++ b/tests/functions_acp/build_cfg_template_test.php @@ -7,8 +7,8 @@ * */ -require_once dirname(__FILE__) . 'user_mock.php'; -require_once dirname(__FILE__) . '../../phpBB/includes/functions_acp.php'; +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 { diff --git a/tests/functions_acp/build_select_test.php b/tests/functions_acp/build_select_test.php index a4f5e419ea..7079e69f12 100644 --- a/tests/functions_acp/build_select_test.php +++ b/tests/functions_acp/build_select_test.php @@ -7,8 +7,8 @@ * */ -require_once dirname(__FILE__) . 'user_mock.php'; -require_once dirname(__FILE__) . '../../phpBB/includes/functions_acp.php'; +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 { diff --git a/tests/functions_acp/h_radio_test.php b/tests/functions_acp/h_radio_test.php index 924b502ede..18cb5d031e 100644 --- a/tests/functions_acp/h_radio_test.php +++ b/tests/functions_acp/h_radio_test.php @@ -7,8 +7,8 @@ * */ -require_once dirname(__FILE__) . 'user_mock.php'; -require_once dirname(__FILE__) . '../../phpBB/includes/functions_acp.php'; +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 { diff --git a/tests/functions_acp/validate_config_vars_test.php b/tests/functions_acp/validate_config_vars_test.php index 722d0ebddb..aa63bc38df 100644 --- a/tests/functions_acp/validate_config_vars_test.php +++ b/tests/functions_acp/validate_config_vars_test.php @@ -7,8 +7,8 @@ * */ -require_once dirname(__FILE__) . 'user_mock.php'; -require_once dirname(__FILE__) . '../../phpBB/includes/functions_acp.php'; +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 { diff --git a/tests/functions_acp/validate_range_test.php b/tests/functions_acp/validate_range_test.php index fb1d15c032..07c9538c66 100644 --- a/tests/functions_acp/validate_range_test.php +++ b/tests/functions_acp/validate_range_test.php @@ -7,8 +7,8 @@ * */ -require_once dirname(__FILE__) . 'user_mock.php'; -require_once dirname(__FILE__) . '../../phpBB/includes/functions_acp.php'; +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 { diff --git a/tests/functions_acp/user_mock.php b/tests/mock/lang.php similarity index 100% rename from tests/functions_acp/user_mock.php rename to tests/mock/lang.php From 7dc293232114fc8a16326675fa229ef924b1b289 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Fri, 4 Feb 2011 00:28:33 +0100 Subject: [PATCH 10/10] [ticket/9823] Replace 0x80000000 with -2147483648 in tests. See 181f2551cfc82e119d73f462268813d18de06097 PHPBB3-9823 --- tests/functions_acp/validate_range_test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/functions_acp/validate_range_test.php b/tests/functions_acp/validate_range_test.php index 07c9538c66..a9c9612ad7 100644 --- a/tests/functions_acp/validate_range_test.php +++ b/tests/functions_acp/validate_range_test.php @@ -42,7 +42,7 @@ class phpbb_functions_acp_validate_range_test extends phpbb_test_case 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) -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))), @@ -87,7 +87,7 @@ class phpbb_functions_acp_validate_range_test extends phpbb_test_case 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', '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))),