Skip to content

Commit

Permalink
MDL-64745 block_online_users: Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Mihail Geshoski committed Oct 7, 2019
1 parent e1fb8e4 commit e94de2d
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions blocks/online_users/tests/online_users_test.php
Expand Up @@ -155,6 +155,8 @@ public function test_fetcher_sitelevel() {
public function test_user_visibility_course1_group1_members() {
global $CFG;

// Enable users to set their visibility to others in the online users block.
$CFG->block_online_users_onlinestatushiding = true;
$groupid = $this->data['group1']->id;
$now = time();
$timetoshowusers = $CFG->block_online_users_timetosee * 60;
Expand Down Expand Up @@ -190,6 +192,18 @@ public function test_user_visibility_course1_group1_members() {
// User1 should not be displayed in the online users block.
$this->assertEquals(2, $usercount);
$this->assertFalse(array_key_exists($user1->id, $users));

// Disable users to set their visibility to others in the online users block.
// All users should be displayed now and the visibility status of a users should be ignored,
// as the capability of setting the visibility to other user has been disabled.
$CFG->block_online_users_onlinestatushiding = false;
// Test if the fetcher gets all the users including user1.
$onlineusers = new fetcher($groupid, $now, $timetoshowusers, $context, false, $courseid);
$users = $onlineusers->get_users();
$usercount = $onlineusers->count_users();
// User1 should be displayed in the online users block.
$this->assertEquals(3, $usercount);
$this->assertTrue(array_key_exists($user1->id, $users));
}

/**
Expand Down Expand Up @@ -234,6 +248,18 @@ public function test_user_visibility_courses() {
// User1 should not be displayed in the online users block.
$this->assertEquals(8, $usercount);
$this->assertFalse(array_key_exists($user1->id, $users));

// Disable users to set their visibility to others in the online users block.
// All users should be displayed now and the visibility status of a users should be ignored,
// as the capability of setting the visibility to other user has been disabled.
$CFG->block_online_users_onlinestatushiding = false;
// Test if the fetcher gets all the users including user1.
$onlineusers = new fetcher($currentgroup, $now, $timetoshowusers, $context, false, $courseid);
$users = $onlineusers->get_users();
$usercount = $onlineusers->count_users();
// User1 should be displayed in the online users block.
$this->assertEquals(9, $usercount);
$this->assertTrue(array_key_exists($user1->id, $users));
}

/**
Expand Down Expand Up @@ -277,5 +303,17 @@ public function test_user_visibility_sitelevel() {
// User1 should not be displayed in the online users block.
$this->assertEquals(11, $usercount);
$this->assertFalse(array_key_exists($user1->id, $users));

// Disable users to set their visibility to others in the online users block.
// All users should be displayed now and the visibility status of a users should be ignored,
// as the capability of setting the visibility to other user has been disabled.
$CFG->block_online_users_onlinestatushiding = false;
// Test if the fetcher gets all the users including user1.
$onlineusers = new fetcher($currentgroup, $now, $timetoshowusers, $context, true);
$users = $onlineusers->get_users();
$usercount = $onlineusers->count_users();
// User1 should be displayed in the online users block.
$this->assertEquals(12, $usercount);
$this->assertTrue(array_key_exists($user1->id, $users));
}
}

0 comments on commit e94de2d

Please sign in to comment.