diff options
-rw-r--r-- | phpBB/download/file.php | 10 | ||||
-rw-r--r-- | phpBB/includes/acp/acp_forums.php | 6 | ||||
-rw-r--r-- | phpBB/includes/acp/acp_prune.php | 8 | ||||
-rw-r--r-- | phpBB/includes/auth/auth_ldap.php | 2 | ||||
-rw-r--r-- | phpBB/includes/constants.php | 1 | ||||
-rw-r--r-- | phpBB/includes/functions.php | 45 | ||||
-rw-r--r-- | phpBB/includes/functions_posting.php | 2 | ||||
-rw-r--r-- | phpBB/includes/functions_user.php | 1 | ||||
-rw-r--r-- | phpBB/includes/ucp/ucp_pm_viewfolder.php | 26 | ||||
-rw-r--r-- | phpBB/language/en/common.php | 2 | ||||
-rw-r--r-- | phpBB/styles/prosilver/template/ucp_pm_viewfolder.html | 2 | ||||
-rw-r--r-- | phpBB/styles/prosilver/template/viewforum_body.html | 6 | ||||
-rw-r--r-- | phpBB/styles/prosilver/theme/forms.css | 5 | ||||
-rw-r--r-- | phpBB/styles/subsilver2/template/ucp_pm_message_footer.html | 1 | ||||
-rw-r--r-- | phpBB/styles/subsilver2/template/ucp_pm_viewfolder.html | 3 | ||||
-rw-r--r-- | tests/dbal/dbal.php | 200 |
16 files changed, 276 insertions, 44 deletions
diff --git a/phpBB/download/file.php b/phpBB/download/file.php index 00b8e2e656..2154847865 100644 --- a/phpBB/download/file.php +++ b/phpBB/download/file.php @@ -670,15 +670,7 @@ function set_modified_headers($stamp, $browser) { if ($last_load !== false && $last_load >= $stamp) { - if (substr(strtolower(@php_sapi_name()),0,3) === 'cgi') - { - // in theory, we shouldn't need that due to php doing it. Reality offers a differing opinion, though - header('Status: 304 Not Modified', true, 304); - } - else - { - header('HTTP/1.0 304 Not Modified', true, 304); - } + send_status_line(304, 'Not Modified'); // seems that we need those too ... browsers header('Pragma: public'); header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', time() + 31536000)); diff --git a/phpBB/includes/acp/acp_forums.php b/phpBB/includes/acp/acp_forums.php index 541a514bef..6261f866bb 100644 --- a/phpBB/includes/acp/acp_forums.php +++ b/phpBB/includes/acp/acp_forums.php @@ -190,12 +190,14 @@ class acp_forums $forum_perm_from = request_var('forum_perm_from', 0); $cache->destroy('sql', FORUMS_TABLE); + $copied_permissions = false; // Copy permissions? if ($forum_perm_from && $forum_perm_from != $forum_data['forum_id'] && ($action != 'edit' || empty($forum_id) || ($auth->acl_get('a_fauth') && $auth->acl_get('a_authusers') && $auth->acl_get('a_authgroups') && $auth->acl_get('a_mauth')))) { copy_forum_permissions($forum_perm_from, $forum_data['forum_id'], ($action == 'edit') ? true : false); cache_moderators(); + $copied_permissions = true; } /* Commented out because of questionable UI workflow - re-visit for 3.0.7 else if (!$this->parent_id && $action != 'edit' && $auth->acl_get('a_fauth') && $auth->acl_get('a_authusers') && $auth->acl_get('a_authgroups') && $auth->acl_get('a_mauth')) @@ -211,13 +213,13 @@ class acp_forums $message = ($action == 'add') ? $user->lang['FORUM_CREATED'] : $user->lang['FORUM_UPDATED']; // Redirect to permissions - if ($auth->acl_get('a_fauth')) + if ($auth->acl_get('a_fauth') && !$copied_permissions) { $message .= '<br /><br />' . sprintf($user->lang['REDIRECT_ACL'], '<a href="' . append_sid("{$phpbb_admin_path}index.$phpEx", 'i=permissions' . $acl_url) . '">', '</a>'); } // redirect directly to permission settings screen if authed - if ($action == 'add' && !$forum_perm_from && $auth->acl_get('a_fauth')) + if ($action == 'add' && !$copied_permissions && $auth->acl_get('a_fauth')) { meta_refresh(4, append_sid("{$phpbb_admin_path}index.$phpEx", 'i=permissions' . $acl_url)); } diff --git a/phpBB/includes/acp/acp_prune.php b/phpBB/includes/acp/acp_prune.php index 7eeb37133f..ffe20f86f5 100644 --- a/phpBB/includes/acp/acp_prune.php +++ b/phpBB/includes/acp/acp_prune.php @@ -315,8 +315,8 @@ class acp_prune 'mode' => $mode, 'prune' => 1, - 'users' => request_var('users', '', true), - 'username' => request_var('username', '', true), + 'users' => utf8_normalize_nfc(request_var('users', '', true)), + 'username' => utf8_normalize_nfc(request_var('username', '', true)), 'email' => request_var('email', ''), 'joined_select' => request_var('joined_select', ''), 'joined' => request_var('joined', ''), @@ -369,7 +369,7 @@ class acp_prune { global $user, $db; - $users = request_var('users', '', true); + $users = utf8_normalize_nfc(request_var('users', '', true)); if ($users) { @@ -378,7 +378,7 @@ class acp_prune } else { - $username = request_var('username', '', true); + $username = utf8_normalize_nfc(request_var('username', '', true)); $email = request_var('email', ''); $joined_select = request_var('joined_select', 'lt'); diff --git a/phpBB/includes/auth/auth_ldap.php b/phpBB/includes/auth/auth_ldap.php index a6092baba5..e8c957aaa3 100644 --- a/phpBB/includes/auth/auth_ldap.php +++ b/phpBB/includes/auth/auth_ldap.php @@ -74,7 +74,7 @@ function init_ldap() if ($search === false) { - return $user->lang['LDAP_NO_SERVER_CONNECTION']; + return $user->lang['LDAP_SEARCH_FAILED']; } $result = @ldap_get_entries($ldap, $search); diff --git a/phpBB/includes/constants.php b/phpBB/includes/constants.php index a3da196cf8..ff572869e2 100644 --- a/phpBB/includes/constants.php +++ b/phpBB/includes/constants.php @@ -121,7 +121,6 @@ define('NOTIFY_BOTH', 2); define('NOTIFY_YES', 0); define('NOTIFY_NO', 1); - // Email Priority Settings define('MAIL_LOW_PRIORITY', 4); define('MAIL_NORMAL_PRIORITY', 3); diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index cd8447a2a3..3e80f93114 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -2578,6 +2578,47 @@ function meta_refresh($time, $url, $disable_cd_check = false) return $url; } +/** +* Outputs correct status line header. +* +* Depending on php sapi one of the two following forms is used: +* +* Status: 404 Not Found +* +* HTTP/1.x 404 Not Found +* +* HTTP version is taken from HTTP_VERSION environment variable, +* and defaults to 1.0. +* +* Sample usage: +* +* send_status_line(404, 'Not Found'); +* +* @param int $code HTTP status code +* @param string $message Message for the status code +* @return void +*/ +function send_status_line($code, $message) +{ + if (substr(strtolower(@php_sapi_name()), 0, 3) === 'cgi') + { + // in theory, we shouldn't need that due to php doing it. Reality offers a differing opinion, though + header("Status: $code $message", true, $code); + } + else + { + if (isset($_SERVER['HTTP_VERSION'])) + { + $version = $_SERVER['HTTP_VERSION']; + } + else + { + $version = 'HTTP/1.0'; + } + header("$version $code $message", true, $code); + } +} + //Form validation @@ -3621,9 +3662,9 @@ function msg_handler($errno, $msg_text, $errfile, $errline) $user->setup(); } - if ($msg_text == 'NO_FORUM' || $msg_text == 'NO_TOPIC' || $msg_text == 'NO_USER') + if ($msg_text == 'ERROR_NO_ATTACHMENT' || $msg_text == 'NO_FORUM' || $msg_text == 'NO_TOPIC' || $msg_text == 'NO_USER') { - header("HTTP/1.x 404 Not Found"); + send_status_line(404, 'Not Found'); } $msg_text = (!empty($user->lang[$msg_text])) ? $user->lang[$msg_text] : $msg_text; diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 7242e7987b..f6f90575d4 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -348,7 +348,7 @@ function posting_gen_topic_types($forum_id, $cur_topic_type = POST_NORMAL) { $topic_type_array = array_merge(array(0 => array( 'VALUE' => POST_NORMAL, - 'S_CHECKED' => ($topic_type == POST_NORMAL) ? ' checked="checked"' : '', + 'S_CHECKED' => ($cur_topic_type == POST_NORMAL) ? ' checked="checked"' : '', 'L_TOPIC_TYPE' => $user->lang['POST_NORMAL'])), $topic_type_array diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index 21e82030ee..271542efdd 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -297,6 +297,7 @@ function user_add($user_row, $cp_data = false) if ($config['new_member_group_default']) { group_user_add($add_group_id, $user_id, false, false, true); + $user_row['group_id'] = $add_group_id; } else { diff --git a/phpBB/includes/ucp/ucp_pm_viewfolder.php b/phpBB/includes/ucp/ucp_pm_viewfolder.php index 665dd2c83f..6b7172ca2b 100644 --- a/phpBB/includes/ucp/ucp_pm_viewfolder.php +++ b/phpBB/includes/ucp/ucp_pm_viewfolder.php @@ -170,10 +170,12 @@ function view_folder($id, $mode, $folder_id, $folder) 'ATTACH_ICON_IMG' => ($auth->acl_get('u_pm_download') && $row['message_attachment'] && $config['allow_pm_attach']) ? $user->img('icon_topic_attach', $user->lang['TOTAL_ATTACHMENTS']) : '', 'S_PM_DELETED' => ($row['pm_deleted']) ? true : false, + 'S_PM_REPORTED' => (isset($row['report_id'])) ? true : false, 'S_AUTHOR_DELETED' => ($row['author_id'] == ANONYMOUS) ? true : false, 'U_VIEW_PM' => ($row['pm_deleted']) ? '' : $view_message_url, 'U_REMOVE_PM' => ($row['pm_deleted']) ? $remove_message_url : '', + 'U_MCP_REPORT' => (isset($row['report_id'])) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=pm_reports&mode=pm_report_details&r=' . $row['report_id']) : '', 'RECIPIENTS' => ($folder_id == PRIVMSGS_OUTBOX || $folder_id == PRIVMSGS_SENTBOX) ? implode(', ', $address_list[$message_id]) : '') ); } @@ -183,6 +185,7 @@ function view_folder($id, $mode, $folder_id, $folder) 'S_SHOW_RECIPIENTS' => ($folder_id == PRIVMSGS_OUTBOX || $folder_id == PRIVMSGS_SENTBOX) ? true : false, 'S_SHOW_COLOUR_LEGEND' => true, + 'REPORTED_IMG' => $user->img('icon_topic_reported', 'PM_REPORTED'), 'S_PM_ICONS' => ($config['enable_pm_icons']) ? true : false) ); } @@ -502,7 +505,7 @@ function get_pm_from($folder_id, $folder, $user_id) $sql_sort_order = $sort_by_sql[$sort_key] . ' ' . $direction; } - $sql = 'SELECT t.*, p.root_level, p.message_time, p.message_subject, p.icon_id, p.to_address, p.message_attachment, p.bcc_address, u.username, u.username_clean, u.user_colour + $sql = 'SELECT t.*, p.root_level, p.message_time, p.message_subject, p.icon_id, p.to_address, p.message_attachment, p.bcc_address, u.username, u.username_clean, u.user_colour, p.message_reported FROM ' . PRIVMSGS_TO_TABLE . ' t, ' . PRIVMSGS_TABLE . ' p, ' . USERS_TABLE . " u WHERE t.user_id = $user_id AND p.author_id = u.user_id @@ -512,13 +515,34 @@ function get_pm_from($folder_id, $folder, $user_id) ORDER BY $sql_sort_order"; $result = $db->sql_query_limit($sql, $sql_limit, $sql_start); + $pm_reported = array(); while ($row = $db->sql_fetchrow($result)) { $rowset[$row['msg_id']] = $row; $pm_list[] = $row['msg_id']; + if ($row['message_reported']) + { + $pm_reported[] = $row['msg_id']; + } } $db->sql_freeresult($result); + // Fetch the report_ids, if there are any reported pms. + if (!empty($pm_reported) && $auth->acl_getf_global('m_report')) + { + $sql = 'SELECT pm_id, report_id + FROM ' . REPORTS_TABLE . ' + WHERE report_closed = 0 + AND ' . $db->sql_in_set('pm_id', $pm_reported); + $result = $db->sql_query($sql); + + while ($row = $db->sql_fetchrow($result)) + { + $rowset[$row['pm_id']]['report_id'] = $row['report_id']; + } + $db->sql_freeresult($result); + } + $pm_list = ($store_reverse) ? array_reverse($pm_list) : $pm_list; return array( diff --git a/phpBB/language/en/common.php b/phpBB/language/en/common.php index a3d47b5b59..03986c0361 100644 --- a/phpBB/language/en/common.php +++ b/phpBB/language/en/common.php @@ -295,6 +295,7 @@ $lang = array_merge($lang, array( 'LAST_VISIT' => 'Last visit', 'LDAP_NO_LDAP_EXTENSION' => 'LDAP extension not available.', 'LDAP_NO_SERVER_CONNECTION' => 'Could not connect to LDAP server.', + 'LDAP_SEARCH_FAILED' => 'An error occured while searching the LDAP directory.', 'LEGEND' => 'Legend', 'LOCATION' => 'Location', 'LOCK_POST' => 'Lock post', @@ -420,6 +421,7 @@ $lang = array_merge($lang, array( 'PIXEL' => 'px', 'PLAY_QUICKTIME_FILE' => 'Play Quicktime file', 'PM' => 'PM', + 'PM_REPORTED' => 'Click to view report', 'POSTING_MESSAGE' => 'Posting message in %s', 'POSTING_PRIVATE_MESSAGE' => 'Composing private message', 'POST' => 'Post', diff --git a/phpBB/styles/prosilver/template/ucp_pm_viewfolder.html b/phpBB/styles/prosilver/template/ucp_pm_viewfolder.html index 7b309a74f7..d7e02e405e 100644 --- a/phpBB/styles/prosilver/template/ucp_pm_viewfolder.html +++ b/phpBB/styles/prosilver/template/ucp_pm_viewfolder.html @@ -71,7 +71,7 @@ <br /><em class="small">{L_PM_FROM_REMOVED_AUTHOR}</em> <!-- ENDIF --> - <!-- IF messagerow.S_TOPIC_REPORTED --><a href="{messagerow.U_MCP_REPORT}">{REPORTED_IMG}</a><!-- ENDIF --> {messagerow.ATTACH_ICON_IMG}<br /> + <!-- IF messagerow.S_PM_REPORTED --><a href="{messagerow.U_MCP_REPORT}">{REPORTED_IMG}</a><!-- ENDIF --> {messagerow.ATTACH_ICON_IMG}<br /> <!-- IF S_SHOW_RECIPIENTS -->{L_MESSAGE_TO} {messagerow.RECIPIENTS}<!-- ELSE -->{L_MESSAGE_BY_AUTHOR} {messagerow.MESSAGE_AUTHOR_FULL} » {messagerow.SENT_TIME}<!-- ENDIF --> </dt> <!-- IF S_SHOW_RECIPIENTS --><dd class="info"><span>{L_SENT_AT}: {messagerow.SENT_TIME}</span></dd><!-- ENDIF --> diff --git a/phpBB/styles/prosilver/template/viewforum_body.html b/phpBB/styles/prosilver/template/viewforum_body.html index cc38ed9d2b..309375c269 100644 --- a/phpBB/styles/prosilver/template/viewforum_body.html +++ b/phpBB/styles/prosilver/template/viewforum_body.html @@ -122,12 +122,12 @@ <!-- ENDIF --> <!-- IF topicrow.S_FIRST_ROW or not topicrow.S_TOPIC_TYPE_SWITCH --> - <div class="forumbg<!-- IF topicrow.S_TOPIC_TYPE_SWITCH --> announcement<!-- ENDIF -->"> + <div class="forumbg<!-- IF topicrow.S_TOPIC_TYPE_SWITCH and (topicrow.S_POST_ANNOUNCE or topicrow.S_POST_GLOBAL) --> announcement<!-- ENDIF -->"> <div class="inner"><span class="corners-top"><span></span></span> <ul class="topiclist"> <li class="header"> <dl class="icon"> - <dt><!-- IF S_DISPLAY_ACTIVE -->{L_ACTIVE_TOPICS}<!-- ELSEIF topicrow.S_TOPIC_TYPE_SWITCH and topicrow.S_TOPIC_TYPE gt 1 -->{L_ANNOUNCEMENTS}<!-- ELSE -->{L_TOPICS}<!-- ENDIF --></dt> + <dt><!-- IF S_DISPLAY_ACTIVE -->{L_ACTIVE_TOPICS}<!-- ELSEIF topicrow.S_TOPIC_TYPE_SWITCH and (topicrow.S_POST_ANNOUNCE or topicrow.S_POST_GLOBAL) -->{L_ANNOUNCEMENTS}<!-- ELSE -->{L_TOPICS}<!-- ENDIF --></dt> <dd class="posts">{L_REPLIES}</dd> <dd class="views">{L_VIEWS}</dd> <dd class="lastpost"><span>{L_LAST_POST}</span></dd> @@ -137,7 +137,7 @@ <ul class="topiclist topics"> <!-- ENDIF --> - <li class="row<!-- IF topicrow.S_ROW_COUNT is even --> bg1<!-- ELSE --> bg2<!-- ENDIF --><!-- IF topicrow.S_POST_ANNOUNCE --> announce<!-- ENDIF --><!-- IF topicrow.S_POST_STICKY --> sticky<!-- ENDIF --><!-- IF topicrow.S_TOPIC_REPORTED --> reported<!-- ENDIF -->"> + <li class="row<!-- IF topicrow.S_ROW_COUNT is even --> bg1<!-- ELSE --> bg2<!-- ENDIF --><!-- IF topicrow.S_POST_GLOBAL --> global-announce<!-- ENDIF --><!-- IF topicrow.S_POST_ANNOUNCE --> announce<!-- ENDIF --><!-- IF topicrow.S_POST_STICKY --> sticky<!-- ENDIF --><!-- IF topicrow.S_TOPIC_REPORTED --> reported<!-- ENDIF -->"> <dl class="icon" style="background-image: url({topicrow.TOPIC_FOLDER_IMG_SRC}); background-repeat: no-repeat;"> <dt<!-- IF topicrow.TOPIC_ICON_IMG and S_TOPIC_ICONS --> style="background-image: url({T_ICONS_PATH}{topicrow.TOPIC_ICON_IMG}); background-repeat: no-repeat;"<!-- ENDIF --> title="{topicrow.TOPIC_FOLDER_IMG_ALT}"><!-- IF topicrow.S_UNREAD_TOPIC --><a href="{topicrow.U_NEWEST_POST}">{NEWEST_POST_IMG}</a> <!-- ENDIF --><a href="{topicrow.U_VIEW_TOPIC}" class="topictitle">{topicrow.TOPIC_TITLE}</a> <!-- IF topicrow.S_TOPIC_UNAPPROVED or topicrow.S_POSTS_UNAPPROVED --><a href="{topicrow.U_MCP_QUEUE}">{topicrow.UNAPPROVED_IMG}</a> <!-- ENDIF --> diff --git a/phpBB/styles/prosilver/theme/forms.css b/phpBB/styles/prosilver/theme/forms.css index 4db342661c..4e48a93a55 100644 --- a/phpBB/styles/prosilver/theme/forms.css +++ b/phpBB/styles/prosilver/theme/forms.css @@ -96,6 +96,11 @@ fieldset.fields1 div { margin-bottom: 3px; } +/* Set it back to 0px for the reCaptcha divs: PHPBB3-9587 */ +fieldset.fields1 #recaptcha_widget_div div { + margin-bottom: 0; +} + /* Specific layout 2 */ fieldset.fields2 dt { width: 15em; diff --git a/phpBB/styles/subsilver2/template/ucp_pm_message_footer.html b/phpBB/styles/subsilver2/template/ucp_pm_message_footer.html index 314d03caf3..d1ef5ebd10 100644 --- a/phpBB/styles/subsilver2/template/ucp_pm_message_footer.html +++ b/phpBB/styles/subsilver2/template/ucp_pm_message_footer.html @@ -14,6 +14,7 @@ <span class="gensmall"> <!-- IF U_PRINT_PM --><a href="{U_PRINT_PM}" title="{L_PRINT_PM}">{L_PRINT_PM}</a><!-- IF U_FORWARD_PM --> | <!-- ENDIF --><!-- ENDIF --> <!-- IF U_FORWARD_PM --><a href="{U_FORWARD_PM}" title="{L_FORWARD_PM}">{L_FORWARD_PM}</a><!-- ENDIF --> + <!-- IF U_POST_REPLY_PM and S_PM_RECIPIENTS gt 1 --><!-- IF U_PRINT_PM or U_FORWARD_PM --> | <!-- ENDIF --><a title="{L_REPLY_TO_ALL}" href="{U_POST_REPLY_ALL}">{L_REPLY_TO_ALL}</a><!-- ENDIF --> </span> <!-- ENDIF --> </td> diff --git a/phpBB/styles/subsilver2/template/ucp_pm_viewfolder.html b/phpBB/styles/subsilver2/template/ucp_pm_viewfolder.html index 1663502865..f0b076edb2 100644 --- a/phpBB/styles/subsilver2/template/ucp_pm_viewfolder.html +++ b/phpBB/styles/subsilver2/template/ucp_pm_viewfolder.html @@ -81,6 +81,9 @@ <!-- ELSE --> <a href="{messagerow.U_VIEW_PM}">{messagerow.SUBJECT}</a> <!-- ENDIF --> + <!-- IF messagerow.S_PM_REPORTED --> + <a href="{messagerow.U_MCP_REPORT}">{REPORTED_IMG}</a> + <!-- ENDIF --> <!-- IF messagerow.S_AUTHOR_DELETED --> <br /><em class="gensmall">{L_PM_FROM_REMOVED_AUTHOR}</em> <!-- ENDIF --> diff --git a/tests/dbal/dbal.php b/tests/dbal/dbal.php index f90b5efeb5..1cce891ca9 100644 --- a/tests/dbal/dbal.php +++ b/tests/dbal/dbal.php @@ -21,10 +21,7 @@ class phpbb_dbal_test extends phpbb_database_test_case { return array( array('phpbb_users', "username_clean = 'bertie'", array(array('username_clean' => 'bertie'))), - array('phpbb_users', "username_clean = 'phpBB'", array()), array('phpbb_users', 'username_clean syntax_error', false), - array('phpbb_users', 'column_not_exists = 2', false), - array('table_not_exists', 'column_not_exists = 2', false), ); } @@ -103,7 +100,6 @@ class phpbb_dbal_test extends phpbb_database_test_case return array( array('', array('barfoo', 'foobar', 'bertie')), array('user_id = 2', array('foobar')), - array("username_clean = 'bertie'", array('bertie')), ); } @@ -138,7 +134,6 @@ class phpbb_dbal_test extends phpbb_database_test_case array(0, 1, array(array('username_clean' => 'foobar'), array('username_clean' => 'bertie'))), array(1, 0, array(array('username_clean' => 'barfoo'))), - array(1, 1, array(array('username_clean' => 'foobar'))), array(1, 2, array(array('username_clean' => 'bertie'))), array(2, 0, array(array('username_clean' => 'barfoo'), array('username_clean' => 'foobar'))), @@ -180,9 +175,6 @@ class phpbb_dbal_test extends phpbb_database_test_case array('bar*', array(array('username_clean' => 'barfoo'))), array('*bar*', array(array('username_clean' => 'barfoo'), array('username_clean' => 'foobar'))), - array('*b*', array(array('username_clean' => 'barfoo'), - array('username_clean' => 'foobar'), - array('username_clean' => 'bertie'))), array('b*r', array()), array('b*e', array(array('username_clean' => 'bertie'))), array('#b*e', array()), @@ -220,11 +212,11 @@ class phpbb_dbal_test extends phpbb_database_test_case array('username_clean' => 'foobar'))), array('user_id', 3, true, true, array(array('username_clean' => 'barfoo'), array('username_clean' => 'foobar'))), - array('user_id', '3', false, false, array(array('username_clean' => 'bertie'))), - array('user_id', '3', false, true, array(array('username_clean' => 'bertie'))), - array('user_id', '3', true, false, array(array('username_clean' => 'barfoo'), + array('username_clean', 'bertie', false, false, array(array('username_clean' => 'bertie'))), + array('username_clean', 'bertie', false, true, array(array('username_clean' => 'bertie'))), + array('username_clean', 'bertie', true, false, array(array('username_clean' => 'barfoo'), array('username_clean' => 'foobar'))), - array('user_id', '3', true, true, array(array('username_clean' => 'barfoo'), + array('username_clean', 'bertie', true, true, array(array('username_clean' => 'barfoo'), array('username_clean' => 'foobar'))), array('user_id', array(3), false, false, array(array('username_clean' => 'bertie'))), array('user_id', array(3), false, true, array(array('username_clean' => 'bertie'))), @@ -238,12 +230,12 @@ class phpbb_dbal_test extends phpbb_database_test_case array('username_clean' => 'bertie'))), array('user_id', array(1, 3), true, false, array(array('username_clean' => 'foobar'))), array('user_id', array(1, 3), true, true, array(array('username_clean' => 'foobar'))), - array('user_id', '', false, false, array()), - array('user_id', '', false, true, array()), - array('user_id', '', true, false, array(array('username_clean' => 'barfoo'), + array('username_clean', '', false, false, array()), + array('username_clean', '', false, true, array()), + array('username_clean', '', true, false, array(array('username_clean' => 'barfoo'), array('username_clean' => 'foobar'), array('username_clean' => 'bertie'))), - array('user_id', '', true, true, array(array('username_clean' => 'barfoo'), + array('username_clean', '', true, true, array(array('username_clean' => 'barfoo'), array('username_clean' => 'foobar'), array('username_clean' => 'bertie'))), array('user_id', array(), false, true, array()), @@ -310,10 +302,11 @@ class phpbb_dbal_test extends phpbb_database_test_case $db->sql_return_on_error(true); } - $result = $db->sql_query('SELECT username_clean + $sql = 'SELECT username_clean FROM phpbb_users WHERE ' . $db->sql_build_array('SELECT', $assoc_ary) . ' - ORDER BY user_id ASC'); + ORDER BY user_id ASC'; + $result = $db->sql_query($sql); if ($catch_error) { @@ -324,5 +317,174 @@ class phpbb_dbal_test extends phpbb_database_test_case $db->sql_freeresult($result); } -} + public static function build_array_insert_data() + { + return array( + array(array( + 'config_name' => 'test_version', + 'config_value' => '0.0.0', + 'is_dynamic' => 1, + )), + array(array( + 'config_name' => 'second config', + 'config_value' => '10', + 'is_dynamic' => 0, + )), + ); + } + + /** + * @dataProvider build_array_insert_data + */ + public function test_build_array_insert($sql_ary) + { + $db = $this->new_dbal(); + + $sql = 'INSERT INTO phpbb_config ' . $db->sql_build_array('INSERT', $sql_ary); + $result = $db->sql_query($sql); + + $sql = "SELECT * + FROM phpbb_config + WHERE config_name = '" . $sql_ary['config_name'] . "'"; + $result = $db->sql_query_limit($sql, 1); + + $this->assertEquals($sql_ary, $db->sql_fetchrow($result)); + + $db->sql_freeresult($result); + } + + public static function delete_data() + { + return array( + array( + "WHERE config_name = 'test_version'", + array( + array( + 'config_name' => 'second config', + 'config_value' => '10', + 'is_dynamic' => 0, + ), + ), + ), + array( + '', + array(), + ), + ); + } + + /** + * @dataProvider delete_data + */ + public function test_delete($where, $expected) + { + $db = $this->new_dbal(); + + $sql = 'DELETE FROM phpbb_config + ' . $where; + $result = $db->sql_query($sql); + + $sql = 'SELECT * + FROM phpbb_config'; + $result = $db->sql_query($sql); + + $this->assertEquals($expected, $db->sql_fetchrowset($result)); + + $db->sql_freeresult($result); + } + + public function test_multiple_insert() + { + $db = $this->new_dbal(); + + $batch_ary = array( + array( + 'config_name' => 'batch one', + 'config_value' => 'b1', + 'is_dynamic' => 0, + ), + array( + 'config_name' => 'batch two', + 'config_value' => 'b2', + 'is_dynamic' => 1, + ), + ); + + $result = $db->sql_multi_insert('phpbb_config', $batch_ary); + + $sql = 'SELECT * + FROM phpbb_config + ORDER BY config_name ASC'; + $result = $db->sql_query($sql); + + $this->assertEquals($batch_ary, $db->sql_fetchrowset($result)); + + $db->sql_freeresult($result); + } + + public static function update_data() + { + return array( + array( + array( + 'config_value' => '20', + 'is_dynamic' => 0, + ), + " WHERE config_name = 'batch one'", + array( + array( + 'config_name' => 'batch one', + 'config_value' => '20', + 'is_dynamic' => 0, + ), + array( + 'config_name' => 'batch two', + 'config_value' => 'b2', + 'is_dynamic' => 1, + ), + ), + ), + array( + array( + 'config_value' => '0', + 'is_dynamic' => 1, + ), + '', + array( + array( + 'config_name' => 'batch one', + 'config_value' => '0', + 'is_dynamic' => 1, + ), + array( + 'config_name' => 'batch two', + 'config_value' => '0', + 'is_dynamic' => 1, + ), + ), + ), + ); + } + + /** + * @dataProvider update_data + */ + public function test_update($sql_ary, $where, $expected) + { + $db = $this->new_dbal(); + + $sql = 'UPDATE phpbb_config + SET ' . $db->sql_build_array('UPDATE', $sql_ary) . $where; + $result = $db->sql_query($sql); + + $sql = 'SELECT * + FROM phpbb_config + ORDER BY config_name ASC'; + $result = $db->sql_query($sql); + + $this->assertEquals($expected, $db->sql_fetchrowset($result)); + + $db->sql_freeresult($result); + } +} |