From 4194cb2228ad257cda5db8963990d95f30a362c6 Mon Sep 17 00:00:00 2001 From: rxu Date: Thu, 31 Oct 2024 14:55:35 +0700 Subject: [PATCH] [ticket/17422] Adjust tests code PHPBB-17422 --- tests/functional/search/base.php | 6 ++---- tests/functional/ucp_attachments_test.php | 3 +-- tests/test_framework/phpbb_functional_test_case.php | 8 +++++--- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/tests/functional/search/base.php b/tests/functional/search/base.php index 04b69a4934..e5ee1feee3 100644 --- a/tests/functional/search/base.php +++ b/tests/functional/search/base.php @@ -117,15 +117,13 @@ abstract class phpbb_functional_search_base extends phpbb_functional_test_case $this->add_lang('common'); // Create a new standard user if needed, topic and post to test searh for author - $searchforauthoruser_name = 'searchforauthoruser'; - $searchforauthoruser_id = null; // if the user exists, array with user_id will be returned - if (!$this->user_exists($searchforauthoruser_name, $searchforauthoruser_id)) + if (!$searchforauthoruser_id = $this->user_exists('searchforauthoruser')) { $searchforauthoruser_id = $this->create_user('searchforauthoruser'); } else { - $searchforauthoruser_id = (int) $searchforauthoruser_id[0]; + $searchforauthoruser_id = key($searchforauthoruser_id); } $this->remove_user_group('NEWLY_REGISTERED', ['searchforauthoruser']); $this->set_flood_interval(0); diff --git a/tests/functional/ucp_attachments_test.php b/tests/functional/ucp_attachments_test.php index 9614911786..d8aac88b49 100644 --- a/tests/functional/ucp_attachments_test.php +++ b/tests/functional/ucp_attachments_test.php @@ -24,8 +24,7 @@ class phpbb_functional_ucp_attachments_test extends phpbb_functional_test_case $this->path = __DIR__ . '/fixtures/files/'; $this->add_lang('posting'); - $username = 'ucp-file-test'; - if (!$this->user_exists($username)) + if (!$this->user_exists('ucp-file-test')) { $this->create_user('ucp-file-test'); } diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 1652be8e44..6f8bc2d013 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -1523,9 +1523,9 @@ class phpbb_functional_test_case extends phpbb_test_case * @param string $username The username to check or empty if user_id is used * @param int $user_id The user id to check or empty if username is used * - * @return bool Returns true if a user exists, false otherwise + * @return array Returns user_id => username array or empty array if user does not exist */ - protected function user_exists(&$username, &$user_id = null) + protected function user_exists($username = '', $user_id = '') { global $db; @@ -1540,6 +1540,8 @@ class phpbb_functional_test_case extends phpbb_test_case require_once(__DIR__ . '/../../phpBB/includes/functions_user.php'); } - return user_get_id_name($user_id, $username) ? false : true; + user_get_id_name($user_id, $username, false, true); + + return $username; } }