diff --git a/phpBB/phpbb/event/kernel_exception_subscriber.php b/phpBB/phpbb/event/kernel_exception_subscriber.php index 0dc9ccaf9c..ccc3107d82 100644 --- a/phpBB/phpbb/event/kernel_exception_subscriber.php +++ b/phpBB/phpbb/event/kernel_exception_subscriber.php @@ -90,12 +90,15 @@ class kernel_exception_subscriber implements EventSubscriberInterface } else if (!$this->debug && $exception instanceof NotFoundHttpException) { - // Do not update user session page if it does not exist - $this->user->update_session_page = false; - $message = $this->language->lang('PAGE_NOT_FOUND'); } + // Do not update user session page if it does not exist + if ($exception instanceof NotFoundHttpException) + { + $this->user->update_session_page = false; + } + // Show text in bold $message = preg_replace('#<(/?strong)>#i', '<$1>', $message); diff --git a/tests/functional/session_page_update_test.php b/tests/functional/session_page_update_test.php index 35a1647a7d..00f857223d 100644 --- a/tests/functional/session_page_update_test.php +++ b/tests/functional/session_page_update_test.php @@ -24,41 +24,31 @@ class phpbb_functional_session_page_update_test extends phpbb_functional_test_ca global $db; $db = $this->db; + + $this->login(); } public function test_session_page_update() { - $this->login(); $db = $this->get_db(); - if (!function_exists('utf_clean_string')) - { - require_once(__DIR__ . '/../../phpBB/includes/utf/utf_tools.php'); - } - if (!function_exists('user_get_id_name')) - { - require_once(__DIR__ . '/../../phpBB/includes/functions_user.php'); - } - - $user_ids = []; - $username = ['admin']; - user_get_id_name($user_ids, $username); - $user_id = (int) $user_ids[0]; + // Sleep for 2 seconds to ensure we don't have session time race condition + sleep(2); // Request index page self::request('GET', 'index.php'); $this->assertEquals(200, self::$client->getResponse()->getStatus()); - $sql = 'SELECT session_page FROM ' . SESSIONS_TABLE . ' WHERE session_user_id = ' . $user_id . ' ORDER BY session_time DESC'; + $sql = 'SELECT session_page FROM ' . SESSIONS_TABLE . ' WHERE session_user_id = 2 ORDER BY session_time DESC'; $db->sql_query_limit($sql, 1); - $this->assertEquals('index.php', $db->sql_fetchfield('session_page')); + $this->assertEquals('index.php', $db->sql_fetchfield('session_page'), 'Failed asserting that session_page is index.php for admin user'); // Request non-existent url self::request('GET', 'nonexistent.jpg', [], false); - $this->assertEquals(404, self::$client->getResponse()->getStatus()); + $this->assertEquals(404, self::$client->getResponse()->getStatus(), 'Failed asserting that status of non-existent image is 404'); $db->sql_query_limit($sql, 1); // User page should not be updated to non-existent one - $this->assertEquals('index.php', $db->sql_fetchfield('session_page')); + $this->assertEquals('index.php', $db->sql_fetchfield('session_page'), 'Failed asserting that session page has not changed after 404'); } }