Skip to content

Commit

Permalink
MDL-60957 mod_assign: Create test for event creation
Browse files Browse the repository at this point in the history
  • Loading branch information
djarran committed Jul 2, 2024
1 parent ca5695d commit 621ddd3
Showing 1 changed file with 41 additions and 2 deletions.
43 changes: 41 additions & 2 deletions mod/assign/tests/locallib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,6 @@ public function test_gradingtable_extension_due_date(): void {
$output = $assign->get_renderer()->render($gradingtable);
$this->assertStringContainsString(get_string('submissionstatus_', 'assign'), $output);
$this->assertStringContainsString(get_string('userextensiondate', 'assign', userdate($extendedtime)), $output);
$event = $DB->record_exists('event', ['userid' => $student->id, 'eventtype' => ASSIGN_EVENT_TYPE_EXTENSION]);
$this->assertTrue($event);

// Simulate a submission.
$this->setUser($student);
Expand Down Expand Up @@ -709,6 +707,47 @@ public function test_plugin_settings(): void {
$this->assertEquals('12', $plugin->get_config('maxfilesubmissions'));
}

public function test_save_user_extension_calendar_event(): void {
global $DB, $CFG;
require_once($CFG->dirroot.'/calendar/lib.php');

$this->resetAfterTest();

$course = $this->getDataGenerator()->create_course();
$teacher = $this->getDataGenerator()->create_and_enrol($course, 'teacher');
$student = $this->getDataGenerator()->create_and_enrol($course, 'student');

$this->setUser($teacher);

$now = time();
$tomorrow = $now + DAYSECS;
$yesterday = $now - DAYSECS;

$assign = $this->create_instance($course, [
'duedate' => $yesterday,
'cutoffdate' => $yesterday,
]);

$sink = $this->redirectEvents();

// Events for extension granted and calendar extension due date are created.
$assign->testable_save_user_extension($student->id, $tomorrow);

$events = $sink->get_events();

$event = end($events);
$this->assertInstanceOf('\core\event\calendar_event_created', $event);

// Check that calendar event is created.
$event = $DB->record_exists('event', ['userid' => $student->id, 'eventtype' => ASSIGN_EVENT_TYPE_EXTENSION]);
$this->assertTrue($event);

// Check that calendar event is deleted if extension is revoked.
$assign->testable_save_user_extension($student->id, '');
$event = $DB->record_exists('event', ['userid' => $student->id, 'eventtype' => ASSIGN_EVENT_TYPE_EXTENSION]);
$this->assertFalse($event);
}

public function test_update_calendar(): void {
global $DB;

Expand Down

0 comments on commit 621ddd3

Please sign in to comment.