Skip to content

Commit

Permalink
MDL-64063 core_calendar: Unit test for suspended users.
Browse files Browse the repository at this point in the history
  • Loading branch information
abgreeve committed Nov 21, 2018
1 parent 644ffbd commit c84ee67
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
31 changes: 31 additions & 0 deletions calendar/tests/event_vault_test.php
Expand Up @@ -557,6 +557,37 @@ public function test_get_action_events_by_timesort_with_identical_group_override
$this->assertEquals('Assignment 1 due date', $usersevents['For user in no groups'][0]->get_name());
}

/**
* Test that if a user is suspended that events related to that course are not shown.
* User 1 is suspended. User 2 is active.
*/
public function test_get_action_events_by_timesort_with_suspended_user() {
$this->resetAfterTest();
$user1 = $this->getDataGenerator()->create_user();
$user2 = $this->getDataGenerator()->create_user();
$course = $this->getDataGenerator()->create_course();
$this->setAdminuser();
$lesson = $this->getDataGenerator()->create_module('lesson', [
'name' => 'Lesson 1',
'course' => $course->id,
'available' => time(),
'deadline' => (time() + (60 * 60 * 24 * 5))
]
);
$this->getDataGenerator()->enrol_user($user1->id, $course->id, null, 'manual', 0, 0, ENROL_USER_SUSPENDED);
$this->getDataGenerator()->enrol_user($user2->id, $course->id);

$factory = new action_event_test_factory();
$strategy = new raw_event_retrieval_strategy();
$vault = new event_vault($factory, $strategy);

$user1events = $vault->get_action_events_by_timesort($user1, null, null, null, 20, true);
$this->assertEmpty($user1events);
$user2events = $vault->get_action_events_by_timesort($user2, null, null, null, 20, true);
$this->assertCount(1, $user2events);
$this->assertEquals('Lesson 1 closes', $user2events[0]->get_name());
}

/**
* Test that get_action_events_by_course returns events after the
* provided timesort value.
Expand Down
28 changes: 28 additions & 0 deletions calendar/tests/externallib_test.php
Expand Up @@ -937,6 +937,34 @@ public function test_get_calendar_action_events_by_timesort_time_limit_offset()
$this->assertNull($result['lastid']);
}

/**
* Check that it is possible to restrict the calendar events to events where the user is not suspended in the course.
*/
public function test_get_calendar_action_events_by_timesort_suspended_course() {
$this->resetAfterTest();
$user1 = $this->getDataGenerator()->create_user();
$user2 = $this->getDataGenerator()->create_user();
$course = $this->getDataGenerator()->create_course();
$this->setAdminUser();
$lesson = $this->getDataGenerator()->create_module('lesson', [
'name' => 'Lesson 1',
'course' => $course->id,
'available' => time(),
'deadline' => (time() + (60 * 60 * 24 * 5))
]
);
$this->getDataGenerator()->enrol_user($user1->id, $course->id, null, 'manual', 0, 0, ENROL_USER_SUSPENDED);
$this->getDataGenerator()->enrol_user($user2->id, $course->id);

$this->setUser($user1);
$result = core_calendar_external::get_calendar_action_events_by_timesort(0, null, 0, 20, true);
$this->assertEmpty($result->events);
$this->setUser($user2);
$result = core_calendar_external::get_calendar_action_events_by_timesort(0, null, 0, 20, true);
$this->assertCount(1, $result->events);
$this->assertEquals('Lesson 1 closes', $result->events[0]->name);
}

/**
* Requesting calendar events from a given course and time should return all
* events with a sort time at or after the requested time. All events prior
Expand Down

0 comments on commit c84ee67

Please sign in to comment.