Skip to content

Commit 8c6e0e1

Browse files
authored
Merge pull request #366 from iMattPro/fix-tests
Improve tests
2 parents fd04cc8 + da44168 commit 8c6e0e1

1 file changed

Lines changed: 19 additions & 14 deletions

File tree

‎tests/functional/viewonline_test.php‎

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,32 +16,37 @@
1616
class viewonline_test extends boardrules_functional_base
1717
{
1818
/**
19-
* Visit rules page as user "admin"
19+
* Create a fresh admin session on the board rules page.
2020
*/
21-
public function test_viewonline_visit_rules()
21+
protected function visit_rules_as_admin()
2222
{
23-
// Send the admin to the Rules page
23+
$db = $this->get_db();
24+
25+
// XXX hardcoded user id
26+
$sql = 'DELETE FROM ' . SESSIONS_TABLE . ' WHERE session_user_id = 2';
27+
$db->sql_query($sql);
28+
2429
$this->login();
25-
$crawler = self::request('GET', "app.php/rules?sid={$this->sid}");
30+
$crawler = self::request('GET', "app.php/rules?sid=$this->sid");
2631
$this->assertContainsLang('BOARDRULES_HEADER', $crawler->filter('h2')->text());
2732
}
2833

2934
/**
3035
* Test viewonline page for admin
31-
*
32-
* We use a second function here, so we get a new session and can login
33-
* without having to log out "admin" first.
34-
*
35-
* @depends test_viewonline_visit_rules
3636
*/
3737
public function test_viewonline_check_viewonline()
3838
{
39-
// Create user1 and send them to the Viewonline
40-
$this->create_user('user1');
41-
$this->login('user1');
42-
$crawler = self::request('GET', "viewonline.php?sid={$this->sid}");
39+
$this->visit_rules_as_admin();
40+
41+
// Create a second user and check who is online from a separate session.
42+
self::$client->restart();
43+
$this->create_user('boardrules-viewonline-user1');
44+
$this->login('boardrules-viewonline-user1');
45+
// PHP goes faster than DBMS, make sure session data got written to the database.
46+
sleep(1);
47+
$crawler = self::request('GET', "viewonline.php?sid=$this->sid");
4348

44-
// Is admin still viewing Rules page
49+
// Is admin still viewing Rules page?
4550
self::assertStringContainsString('admin', $crawler->filter('#page-body table.table1')->text());
4651

4752
$session_entries = $crawler->filter('#page-body table.table1 tr')->count();

0 commit comments

Comments
 (0)