From 60d267893c43ac01e2bc0b941c839b234a871f40 Mon Sep 17 00:00:00 2001 From: rxu Date: Tue, 23 May 2023 19:57:31 +0700 Subject: [PATCH] [ticket/17107] Fix viewonline functional test PHPBB3-17107 --- tests/functional/viewonline_test.php | 80 +++++++++++++--------------- 1 file changed, 37 insertions(+), 43 deletions(-) diff --git a/tests/functional/viewonline_test.php b/tests/functional/viewonline_test.php index a6aed91661..871d43792d 100644 --- a/tests/functional/viewonline_test.php +++ b/tests/functional/viewonline_test.php @@ -16,7 +16,6 @@ */ class phpbb_functional_viewonline_test extends phpbb_functional_test_case { - protected function get_forum_name_by_topic_id($topic_id) { $db = $this->get_db(); @@ -40,7 +39,7 @@ class phpbb_functional_viewonline_test extends phpbb_functional_test_case // Forum info $sql = 'SELECT forum_name FROM ' . FORUMS_TABLE . ' - WHERE forum_id = ' . (int) $topic_id; + WHERE forum_id = ' . (int) $forum_id; $result = $db->sql_query($sql); $forum_name = $db->sql_fetchfield('forum_name'); $db->sql_freeresult($result, 1800); // cache for 30 minutes @@ -48,71 +47,66 @@ class phpbb_functional_viewonline_test extends phpbb_functional_test_case return $forum_name; } - public function test_viewonline_reply_mode() + public function test_viewonline() { - $this->create_user('viewonline-test-user'); - $this->logout(); - $this->login('viewonline-test-user'); + $this->create_user('viewonline-test-user1'); + + // Log in as test user + self::$client->restart(); + $this->login('viewonline-test-user1'); $crawler = self::request('GET', 'posting.php?mode=reply&t=1&sid=' . $this->sid); $this->assertContainsLang('POST_REPLY', $crawler->text()); - // Log in as another user - $this->logout(); + self::$client->restart(); $this->login(); + // PHP goes faster than DBMS, make sure session data got written to the database + sleep(1); $crawler = self::request('GET', 'viewonline.php?sid=' . $this->sid); - $this->assertContainsLang('FORUM_LOCATION', $crawler->text()); - // Make sure posting reply page is in the list - $this->assertStringContainsString('viewonline-test-user', $crawler->text()); + $this->assertStringContainsString('viewonline-test-user1', $crawler->text()); $this->assertStringContainsString($this->lang('REPLYING_MESSAGE', $this->get_forum_name_by_topic_id(1)), $crawler->text()); - } - public function test_viewonline_posting_mode() - { - $this->logout(); - $this->login('viewonline-test-user'); - $crawler = self::request('GET', 'posting.php?mode=post&f=1&sid=' . $this->sid); + // Log in as test user + self::$client->restart(); + $this->login('viewonline-test-user1'); + $crawler = self::request('GET', 'posting.php?mode=post&f=2&sid=' . $this->sid); $this->assertContainsLang('POST_TOPIC', $crawler->text()); - // Log in as another user - $this->logout(); + self::$client->restart(); $this->login(); + // PHP goes faster than DBMS, make sure session data got written to the database + sleep(1); $crawler = self::request('GET', 'viewonline.php?sid=' . $this->sid); - // Make sure posting message page is in the list - $this->assertStringContainsString('viewonline-test-user', $crawler->text()); + $this->assertStringContainsString('viewonline-test-user1', $crawler->text()); $this->assertStringContainsString($this->lang('POSTING_MESSAGE', $this->get_forum_name_by_forum_id(2)), $crawler->text()); - } - - public function test_viewonline_reading_topic() - { - $this->logout(); - $this->login('viewonline-test-user'); - $crawler = self::request('GET', 'viewtopic.php?t=1&sid=' . $this->sid); + // Log in as test user + self::$client->restart(); + $this->login('viewonline-test-user1'); + self::request('GET', 'viewtopic.php?t=1&sid=' . $this->sid); // Log in as another user - $this->logout(); + self::$client->restart(); $this->login(); + // PHP goes faster than DBMS, make sure session data got written to the database + sleep(1); $crawler = self::request('GET', 'viewonline.php?sid=' . $this->sid); - - // Make sure the page is in the list - $this->assertStringContainsString('viewonline-test-user', $crawler->text()); + // Make sure reading topic page is in the list + $this->assertStringContainsString('viewonline-test-user1', $crawler->text()); $this->assertStringContainsString($this->lang('READING_TOPIC', $this->get_forum_name_by_topic_id(1)), $crawler->text()); - } - - public function test_viewonline_reading_forum() - { - $this->logout(); - $this->login('viewonline-test-user'); - $crawler = self::request('GET', 'viewforum.php?f=2&sid=' . $this->sid); + // Log in as test user + self::$client->restart(); + $this->login('viewonline-test-user1'); + self::request('GET', 'viewforum.php?f=2&sid=' . $this->sid); // Log in as another user - $this->logout(); + self::$client->restart(); $this->login(); + // PHP goes faster than DBMS, make sure session data got written to the database + sleep(1); $crawler = self::request('GET', 'viewonline.php?sid=' . $this->sid); - - // Make sure the page is in the list - $this->assertStringContainsString('viewonline-test-user', $crawler->text()); + // Make sure reading forum page is in the list + $this->assertStringContainsString('viewonline-test-user1', $crawler->text()); $this->assertStringContainsString($this->lang('READING_FORUM', $this->get_forum_name_by_forum_id(2)), $crawler->text()); } }