diff options
author | Marc Alexander <admin@m-a-styles.de> | 2020-01-09 20:34:53 +0100 |
---|---|---|
committer | Marc Alexander <admin@m-a-styles.de> | 2020-01-09 20:34:53 +0100 |
commit | 1b7c42bf5351d3cd978f34e601cfdf326d0b3b75 (patch) | |
tree | 1acdf37f43127e9ca757e39e2cee660307fbf4a8 | |
parent | Merge pull request #5824 from rxu/ticket/16311 (diff) | |
parent | [ticket/16288] Drop redundant parentheses (diff) | |
download | phpbb-1b7c42bf5351d3cd978f34e601cfdf326d0b3b75.tar.gz phpbb-1b7c42bf5351d3cd978f34e601cfdf326d0b3b75.tar.bz2 phpbb-1b7c42bf5351d3cd978f34e601cfdf326d0b3b75.zip |
Merge pull request #5812 from rxu/ticket/16288
[ticket/16288] PHP 8 compatibility
-rw-r--r-- | phpBB/includes/acp/acp_main.php | 14 | ||||
-rw-r--r-- | phpBB/includes/ucp/ucp_pm.php | 16 | ||||
-rw-r--r-- | phpBB/phpbb/search/fulltext_native.php | 2 | ||||
-rw-r--r-- | phpBB/phpbb/template/context.php | 7 | ||||
-rw-r--r-- | tests/functional/feed_test.php | 6 | ||||
-rw-r--r-- | tests/functional/visibility_reapprove_test.php | 2 | ||||
-rw-r--r-- | tests/functions_user/delete_user_test.php | 2 | ||||
-rw-r--r-- | tests/mock/fileupload.php | 5 | ||||
-rw-r--r-- | tests/mock/session_testable.php | 1 | ||||
-rw-r--r-- | tests/mock/user.php | 2 | ||||
-rw-r--r-- | tests/path_helper/path_helper_test.php | 14 | ||||
-rw-r--r-- | tests/request/request_var_test.php | 2 | ||||
-rw-r--r-- | tests/search/common_test_case.php | 3 | ||||
-rw-r--r-- | tests/search/native_test.php | 6 | ||||
-rw-r--r-- | tests/security/base.php | 1 | ||||
-rw-r--r-- | tests/security/redirect_test.php | 6 | ||||
-rw-r--r-- | tests/session/fixtures/sessions_full.xml | 6 | ||||
-rw-r--r-- | tests/session/fixtures/sessions_key.xml | 11 | ||||
-rw-r--r-- | tests/test_framework/phpbb_database_test_case.php | 40 | ||||
-rw-r--r-- | tests/test_framework/phpbb_functional_test_case.php | 6 | ||||
-rw-r--r-- | tests/version/version_helper_remote_test.php | 4 |
21 files changed, 110 insertions, 46 deletions
diff --git a/phpBB/includes/acp/acp_main.php b/phpBB/includes/acp/acp_main.php index 27fac54777..90f5cae383 100644 --- a/phpBB/includes/acp/acp_main.php +++ b/phpBB/includes/acp/acp_main.php @@ -22,6 +22,7 @@ if (!defined('IN_PHPBB')) class acp_main { var $u_action; + private $php_ini; function main($id, $mode) { @@ -684,14 +685,19 @@ class acp_main $template->assign_var('S_WRITABLE_CONFIG', (bool) (@fileperms($phpbb_root_path . 'config.' . $phpEx) & 0x0002)); } + $this->php_ini = $phpbb_container->get('php_ini'); + $func_overload = $this->php_ini->getNumeric('mbstring.func_overload'); + $encoding_translation = $this->php_ini->getString('mbstring.encoding_translation'); + $http_input = $this->php_ini->getString('mbstring.http_input'); + $http_output = $this->php_ini->getString('mbstring.http_output'); if (extension_loaded('mbstring')) { $template->assign_vars(array( 'S_MBSTRING_LOADED' => true, - 'S_MBSTRING_FUNC_OVERLOAD_FAIL' => (intval(@ini_get('mbstring.func_overload')) & (MB_OVERLOAD_MAIL | MB_OVERLOAD_STRING)), - 'S_MBSTRING_ENCODING_TRANSLATION_FAIL' => (@ini_get('mbstring.encoding_translation') != 0), - 'S_MBSTRING_HTTP_INPUT_FAIL' => !in_array(@ini_get('mbstring.http_input'), array('pass', '')), - 'S_MBSTRING_HTTP_OUTPUT_FAIL' => !in_array(@ini_get('mbstring.http_output'), array('pass', '')), + 'S_MBSTRING_FUNC_OVERLOAD_FAIL' => $func_overload && ($func_overload & (MB_OVERLOAD_MAIL | MB_OVERLOAD_STRING)), + 'S_MBSTRING_ENCODING_TRANSLATION_FAIL' => $encoding_translation && ($encoding_translation != 0), + 'S_MBSTRING_HTTP_INPUT_FAIL' => $http_input && !in_array($http_input, array('pass', '')), + 'S_MBSTRING_HTTP_OUTPUT_FAIL' => $http_output && !in_array($http_output, array('pass', '')), )); } diff --git a/phpBB/includes/ucp/ucp_pm.php b/phpBB/includes/ucp/ucp_pm.php index 00d1ce7149..6fcc0146df 100644 --- a/phpBB/includes/ucp/ucp_pm.php +++ b/phpBB/includes/ucp/ucp_pm.php @@ -361,7 +361,7 @@ class ucp_pm $template->assign_vars(array( 'CUR_FOLDER_ID' => $folder_id, - 'CUR_FOLDER_NAME' => $folder_status['folder_name'], + 'CUR_FOLDER_NAME' => $folder_status ? $folder_status['folder_name'] : false, 'NUM_NOT_MOVED' => $num_not_moved, 'NUM_REMOVED' => $num_removed, 'RELEASE_MESSAGE_INFO' => sprintf($user->lang['RELEASE_MESSAGES'], '<a href="' . $this->u_action . '&folder=' . $folder_id . '&release=1">', '</a>'), @@ -384,12 +384,12 @@ class ucp_pm 'S_IN_OUTBOX' => ($folder_id == PRIVMSGS_OUTBOX) ? true : false, 'S_IN_SENTBOX' => ($folder_id == PRIVMSGS_SENTBOX) ? true : false, - 'FOLDER_STATUS' => $folder_status['message'], - 'FOLDER_MAX_MESSAGES' => $folder_status['max'], - 'FOLDER_CUR_MESSAGES' => $folder_status['cur'], - 'FOLDER_REMAINING_MESSAGES' => $folder_status['remaining'], - 'FOLDER_PERCENT' => $folder_status['percent']) - ); + 'FOLDER_STATUS' => $folder_status ? $folder_status['message'] : false, + 'FOLDER_MAX_MESSAGES' => $folder_status ? $folder_status['max'] : false, + 'FOLDER_CUR_MESSAGES' => $folder_status ? $folder_status['cur'] : false, + 'FOLDER_REMAINING_MESSAGES' => $folder_status ? $folder_status['remaining'] : false, + 'FOLDER_PERCENT' => $folder_status ? $folder_status['percent'] : false, + )); if ($action == 'view_folder') { @@ -405,7 +405,7 @@ class ucp_pm { $template->assign_vars(array( 'S_VIEW_MESSAGE' => true, - 'L_RETURN_TO_FOLDER' => $user->lang('RETURN_TO', $folder_status['folder_name']), + 'L_RETURN_TO_FOLDER' => $user->lang('RETURN_TO', $folder_status ? $folder_status['folder_name'] : ''), 'MSG_ID' => $msg_id, )); diff --git a/phpBB/phpbb/search/fulltext_native.php b/phpBB/phpbb/search/fulltext_native.php index 23460d3381..2246dc0aef 100644 --- a/phpBB/phpbb/search/fulltext_native.php +++ b/phpBB/phpbb/search/fulltext_native.php @@ -405,7 +405,7 @@ class fulltext_native extends \phpbb\search\base } // a group of words of which at least one word should be in every resulting post - if ($word[0] == '(') + if (isset($word[0]) && $word[0] == '(') { $word = array_unique(explode('|', substr($word, 1, -1))); } diff --git a/phpBB/phpbb/template/context.php b/phpBB/phpbb/template/context.php index f059c327c1..d98d8b6e28 100644 --- a/phpBB/phpbb/template/context.php +++ b/phpBB/phpbb/template/context.php @@ -384,7 +384,9 @@ class context if (is_array($key)) { // Search array to get correct position - list($search_key, $search_value) = @each($key); + $search_key = key($key); + $search_value = current($key); + foreach ($block as $i => $val_ary) { if ($val_ary[$search_key] === $search_value) @@ -481,7 +483,8 @@ class context if (is_array($key)) { // Search array to get correct position - list($search_key, $search_value) = @each($key); + $search_key = key($key); + $search_value = current($key); $key = null; foreach ($block as $i => $val_ary) diff --git a/tests/functional/feed_test.php b/tests/functional/feed_test.php index 24ddca9c64..8f6fc25650 100644 --- a/tests/functional/feed_test.php +++ b/tests/functional/feed_test.php @@ -850,10 +850,9 @@ class phpbb_functional_feed_test extends phpbb_functional_test_case $this->set_flood_interval(0); $this->login('disapprove_user'); - $post = $this->create_topic($this->data['forums']['Feeds #1.1'], 'Feeds #1.1 - Topic #3', 'This is a test topic posted by the testing framework.', array(), 'POST_STORED_MOD'); - $this->data['topics']['Feeds #1 - Topic #3'] = (int) $post['topic_id']; - $crawler = self::request('GET', "viewforum.php?f={$this->data['forums']['Feeds #1.1']}&sid={$this->sid}"); + $this->create_topic($this->data['forums']['Feeds #1.1'], 'Feeds #1.1 - Topic #3', 'This is a test topic posted by the testing framework.', array(), 'POST_STORED_MOD'); + $crawler = self::request('GET', "viewforum.php?f={$this->data['forums']['Feeds #1.1']}&sid={$this->sid}"); self::assertNotContains('Feeds #1.1 - Topic #3', $crawler->filter('html')->text()); $this->logout(); @@ -1240,6 +1239,7 @@ class phpbb_functional_feed_test extends phpbb_functional_test_case 'posts' => array( 'Feeds #1 - Topic #3', ), + 'attachments' => array(), )); $this->add_lang('viewtopic'); diff --git a/tests/functional/visibility_reapprove_test.php b/tests/functional/visibility_reapprove_test.php index 5af2ddafa4..6a6e2edf18 100644 --- a/tests/functional/visibility_reapprove_test.php +++ b/tests/functional/visibility_reapprove_test.php @@ -226,7 +226,7 @@ class phpbb_functional_visibility_reapprove_test extends phpbb_functional_test_c $link = $crawler->selectLink($this->lang('RETURN_PAGE', '', ''))->link(); $link_url = $link->getUri(); - $this->assertContains('viewtopic.php?f=' . $this->data['topic']['Reapprove Test Topic #2'], $link_url); + $this->assertContains('viewtopic.php?f=' . $this->data['forums']['Reapprove Test #1'], $link_url); $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Reapprove Test Topic #2']}&sid={$this->sid}"); $this->assertContains('Reapprove Test Topic #2', $crawler->filter('h2')->text()); diff --git a/tests/functions_user/delete_user_test.php b/tests/functions_user/delete_user_test.php index 4a82a0eeb7..7e414dad86 100644 --- a/tests/functions_user/delete_user_test.php +++ b/tests/functions_user/delete_user_test.php @@ -193,6 +193,8 @@ class phpbb_functions_user_delete_user_test extends phpbb_database_test_case */ public function test_first_last_post_info($mode, $retain_username, $expected_posts, $expected_topics, $expected_forums) { + global $cache, $config, $db, $user, $phpbb_dispatcher, $phpbb_container, $phpbb_root_path, $phpEx; + $this->assertFalse(user_delete($mode, 2, $retain_username)); $sql = 'SELECT post_id, poster_id, post_username diff --git a/tests/mock/fileupload.php b/tests/mock/fileupload.php index 5a0afc6cd3..83c43d8af0 100644 --- a/tests/mock/fileupload.php +++ b/tests/mock/fileupload.php @@ -21,6 +21,11 @@ class phpbb_mock_fileupload public $error_prefix = ''; public $valid_dimensions = true; + public $min_width = 0; + public $min_height = 0; + public $max_width = 0; + public $max_height = 0; + public function valid_dimensions($filespec) { return $this->valid_dimensions; diff --git a/tests/mock/session_testable.php b/tests/mock/session_testable.php index 7828a864d4..fea5db6fb9 100644 --- a/tests/mock/session_testable.php +++ b/tests/mock/session_testable.php @@ -21,6 +21,7 @@ class phpbb_mock_session_testable extends \phpbb\session { private $_cookies = array(); + public $lang = []; public function set_cookie($name, $data, $time, $httponly = true) { diff --git a/tests/mock/user.php b/tests/mock/user.php index 9888337a9e..d9211369bc 100644 --- a/tests/mock/user.php +++ b/tests/mock/user.php @@ -21,6 +21,8 @@ class phpbb_mock_user { public $host = "testhost"; public $page = array('root_script_path' => '/'); + public $style = []; + public $data = []; private $options = array(); public function optionget($item) diff --git a/tests/path_helper/path_helper_test.php b/tests/path_helper/path_helper_test.php index 447ed7a2db..31182c2daf 100644 --- a/tests/path_helper/path_helper_test.php +++ b/tests/path_helper/path_helper_test.php @@ -103,13 +103,6 @@ class phpbb_path_helper_test extends phpbb_test_case array( $this->phpbb_root_path . 'test.php', '//', - null, - null, - './../', - ), - array( - $this->phpbb_root_path . 'test.php', - '//', 'foo/bar.php', 'bar.php', './../', @@ -140,13 +133,6 @@ class phpbb_path_helper_test extends phpbb_test_case array( './../' . $this->phpbb_root_path . 'test.php', '//', - null, - null, - '', - ), - array( - './../' . $this->phpbb_root_path . 'test.php', - '//', 'foo/bar.php', 'bar.php', '', diff --git a/tests/request/request_var_test.php b/tests/request/request_var_test.php index 8dc8e4c7c7..c95dce46d0 100644 --- a/tests/request/request_var_test.php +++ b/tests/request/request_var_test.php @@ -110,7 +110,7 @@ class phpbb_request_var_test extends phpbb_test_case ); $result = request_var($path, $default); - $this->assertEquals($expected, $result, 'Testing deep access to multidimensional input arrays: ' . $path); + $this->assertEquals($expected, $result); } public function deep_access() diff --git a/tests/search/common_test_case.php b/tests/search/common_test_case.php index 0bb4549832..d157d3ae7e 100644 --- a/tests/search/common_test_case.php +++ b/tests/search/common_test_case.php @@ -200,6 +200,9 @@ abstract class phpbb_search_common_test_case extends phpbb_search_test_case $this->assertEquals($ok, $rv); if ($ok) { + // If there are valid keywords, search->split_keywords perfoms array sort + sort($split_words); + // only check criteria if the search is going to be performed $this->assert_array_content_equals($split_words, $this->search->get_split_words()); } diff --git a/tests/search/native_test.php b/tests/search/native_test.php index 2e11eaff14..ba37660b1f 100644 --- a/tests/search/native_test.php +++ b/tests/search/native_test.php @@ -195,7 +195,7 @@ class phpbb_search_native_test extends phpbb_search_test_case 'foo foo-', 'all', true, - array(1), + array(1, 1), array(), array(), ), @@ -203,7 +203,7 @@ class phpbb_search_native_test extends phpbb_search_test_case 'foo- foo', 'all', true, - array(1), + array(1, 1), array(), array(), ), @@ -219,7 +219,7 @@ class phpbb_search_native_test extends phpbb_search_test_case 'foo-bar-foo', 'all', true, - array(1, 2), + array(1, 2, 1), array(), array(), ), diff --git a/tests/security/base.php b/tests/security/base.php index ad518b5543..77747bf243 100644 --- a/tests/security/base.php +++ b/tests/security/base.php @@ -52,7 +52,6 @@ abstract class phpbb_security_test_base extends phpbb_test_case $lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); $lang = new \phpbb\language\language($lang_loader); $user = new \phpbb\user($lang, '\phpbb\datetime'); - $user->lang = true; $user->browser = $this->server['HTTP_USER_AGENT']; $user->referer = ''; $user->forwarded_for = ''; diff --git a/tests/security/redirect_test.php b/tests/security/redirect_test.php index 313e329e20..8bde1488d8 100644 --- a/tests/security/redirect_test.php +++ b/tests/security/redirect_test.php @@ -60,6 +60,8 @@ class phpbb_security_redirect_test extends phpbb_security_test_base protected function get_path_helper() { + global $phpbb_root_path; + if (!($this->path_helper instanceof \phpbb\path_helper)) { $this->path_helper = new \phpbb\path_helper( @@ -68,7 +70,7 @@ class phpbb_security_redirect_test extends phpbb_security_test_base ), new \phpbb\filesystem\filesystem(), $this->createMock('\phpbb\request\request'), - $this->phpbb_root_path, + $phpbb_root_path, 'php' ); } @@ -109,7 +111,7 @@ class phpbb_security_redirect_test extends phpbb_security_test_base if ($expected_error !== false) { - $this->setExpectedTriggerError(E_USER_WARNING, $user->lang[$expected_error]); + $this->setExpectedTriggerError(E_USER_WARNING, $expected_error); } $result = redirect($test, true, $disable_cd_check); diff --git a/tests/session/fixtures/sessions_full.xml b/tests/session/fixtures/sessions_full.xml index 4fb6b9dfd4..268e19f905 100644 --- a/tests/session/fixtures/sessions_full.xml +++ b/tests/session/fixtures/sessions_full.xml @@ -23,6 +23,12 @@ <value></value> <value></value> </row> + <row> + <value>13</value> + <value>bot</value> + <value></value> + <value></value> + </row> </table> <table name="phpbb_sessions"> <column>session_id</column> diff --git a/tests/session/fixtures/sessions_key.xml b/tests/session/fixtures/sessions_key.xml index 245f89a604..0653dfee82 100644 --- a/tests/session/fixtures/sessions_key.xml +++ b/tests/session/fixtures/sessions_key.xml @@ -29,11 +29,20 @@ <column>username_clean</column> <column>user_permissions</column> <column>user_sig</column> - <row> + <column>user_type</column> + <row> <value>4</value> <value>bar</value> <value></value> <value></value> + <value>0</value> + </row> + <row> + <value>1</value> + <value>anonymous</value> + <value></value> + <value></value> + <value>2</value> </row> </table> </dataset> diff --git a/tests/test_framework/phpbb_database_test_case.php b/tests/test_framework/phpbb_database_test_case.php index c098ff64bd..9b873fbf68 100644 --- a/tests/test_framework/phpbb_database_test_case.php +++ b/tests/test_framework/phpbb_database_test_case.php @@ -304,11 +304,45 @@ abstract class phpbb_database_test_case extends TestCase return new phpbb_database_test_connection_manager($config); } + /** array_diff() does not corretly compare multidimensionsl arrays + * This solution used for that https://www.codeproject.com/Questions/780780/PHP-Finding-differences-in-two-multidimensional-ar + */ + function array_diff_assoc_recursive($array1, $array2) + { + $difference = array(); + foreach ($array1 as $key => $value) + { + if (is_array($value)) + { + if (!isset($array2[$key])) + { + $difference[$key] = $value; + } + else if (!is_array($array2[$key])) + { + $difference[$key] = $value; + } + else + { + $new_diff = $this->array_diff_assoc_recursive($value, $array2[$key]); + if (!empty($new_diff)) + { + $difference[$key] = $new_diff; + } + } + } + else if (!isset($array2[$key]) || $array2[$key] != $value) + { + $difference[$key] = $value; + } + } + return $difference; + } + public function assert_array_content_equals($one, $two) { - // http://stackoverflow.com/questions/3838288/phpunit-assert-two-arrays-are-equal-but-order-of-elements-not-important - // but one array_diff is not enough! - if (count(array_diff($one, $two)) || count(array_diff($two, $one))) + // one-way comparison is not enough! + if (count($this->array_diff_assoc_recursive($one, $two)) || count($this->array_diff_assoc_recursive($two, $one))) { // get a nice error message $this->assertEquals($one, $two); diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index a31aa648bc..19062aa148 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -710,7 +710,7 @@ class phpbb_functional_test_case extends phpbb_test_case protected function remove_user_group($group_name, $usernames) { - global $db, $cache, $auth, $config, $phpbb_dispatcher, $phpbb_log, $phpbb_container, $phpbb_root_path, $phpEx; + global $db, $cache, $auth, $config, $phpbb_dispatcher, $phpbb_log, $phpbb_container, $user, $phpbb_root_path, $phpEx; $config = new \phpbb\config\config(array()); $config['coppa_enable'] = 0; @@ -747,7 +747,7 @@ class phpbb_functional_test_case extends phpbb_test_case protected function add_user_group($group_name, $usernames, $default = false, $leader = false) { - global $db, $cache, $auth, $config, $phpbb_dispatcher, $phpbb_log, $phpbb_container, $phpbb_root_path, $phpEx; + global $db, $cache, $auth, $config, $phpbb_dispatcher, $phpbb_log, $phpbb_container, $user, $phpbb_root_path, $phpEx; $config = new \phpbb\config\config(array()); $config['coppa_enable'] = 0; @@ -869,6 +869,8 @@ class phpbb_functional_test_case extends phpbb_test_case { $this->add_lang($file); } + + return; } $lang_path = __DIR__ . "/../../phpBB/language/en/$lang_file.php"; diff --git a/tests/version/version_helper_remote_test.php b/tests/version/version_helper_remote_test.php index e15ff897b0..d392d6d256 100644 --- a/tests/version/version_helper_remote_test.php +++ b/tests/version/version_helper_remote_test.php @@ -203,6 +203,10 @@ class version_helper_remote_test extends \phpbb_test_case { $this->file_downloader->set($input); + // version_helper->get_versions() doesn't return a value on VERSIONCHECK_FAIL but only throws exception + // so the $return is undefined. Define it here + $return = false; + if (!$valid_data) { try { |