/** * Call cron on the assign module */ function assign_cron() { global $CFG; require_once $CFG->dirroot . '/mod/assign/locallib.php'; assign::cron(); $plugins = get_plugin_list('assignsubmission'); foreach ($plugins as $name => $plugin) { $disabled = get_config('assignsubmission_' . $name, 'disabled'); if (!$disabled) { $class = 'assign_submission_' . $name; require_once $CFG->dirroot . '/mod/assign/submission/' . $name . '/locallib.php'; $class::cron(); } } $plugins = get_plugin_list('assignfeedback'); foreach ($plugins as $name => $plugin) { $disabled = get_config('assignfeedback_' . $name, 'disabled'); if (!$disabled) { $class = 'assign_feedback_' . $name; require_once $CFG->dirroot . '/mod/assign/feedback/' . $name . '/locallib.php'; $class::cron(); } } }
/** * Test delivery of grade notifications as controlled by marking workflow. */ public function test_markingworkflow_cron() { // First run cron so there are no messages waiting to be sent (from other tests). cron_setup_user(); assign::cron(); // Now create an assignment with marking workflow enabled. $this->setUser($this->editingteachers[0]); $assign = $this->create_instance(array('sendstudentnotifications' => 1, 'markingworkflow' => 1)); // Simulate adding a grade. $this->setUser($this->teachers[0]); $data = new stdClass(); $data->grade = '50.0'; // This student will not receive notification. $data->workflowstate = ASSIGN_MARKING_WORKFLOW_STATE_READYFORRELEASE; $assign->testable_apply_grade_to_user($data, $this->students[0]->id, 0); // This student will receive notification. $data->workflowstate = ASSIGN_MARKING_WORKFLOW_STATE_RELEASED; $assign->testable_apply_grade_to_user($data, $this->students[1]->id, 0); // Now run cron and see that one message was sent. $this->preventResetByRollback(); $sink = $this->redirectMessages(); cron_setup_user(); $this->expectOutputRegex('/Done processing 1 assignment submissions/'); assign::cron(); $messages = $sink->get_messages(); $this->assertEquals(1, count($messages)); $this->assertEquals($messages[0]->useridto, $this->students[1]->id); $this->assertEquals($assign->get_instance()->name, $messages[0]->contexturlname); }
public function test_cron() { // First run cron so there are no messages waiting to be sent (from other tests). cron_setup_user(); assign::cron(); // Now create an assignment and add some feedback. $this->setUser($this->editingteachers[0]); $assign = $this->create_instance(array('sendstudentnotifications' => 1)); // Simulate adding a grade. $this->setUser($this->teachers[0]); $data = new stdClass(); $data->grade = '50.0'; $assign->testable_apply_grade_to_user($data, $this->students[0]->id, 0); $assign->testable_apply_grade_to_user($data, $this->students[1]->id, 0); $data->sendstudentnotifications = false; $assign->testable_apply_grade_to_user($data, $this->students[2]->id, 0); // Now run cron and see that one message was sent. $this->preventResetByRollback(); $sink = $this->redirectMessages(); cron_setup_user(); $this->expectOutputRegex('/Done processing 2 assignment submissions/'); assign::cron(); $messages = $sink->get_messages(); // The sent count should be 2, because the 3rd one was marked as do not send notifications. $this->assertEquals(2, count($messages)); $this->assertEquals(1, $messages[0]->notification); $this->assertEquals($assign->get_instance()->name, $messages[0]->contexturlname); }
public function test_cron_message_includes_courseid() { // First run cron so there are no messages waiting to be sent (from other tests). cron_setup_user(); assign::cron(); // Now create an assignment. $this->setUser($this->editingteachers[0]); $assign = $this->create_instance(array('sendstudentnotifications' => 1)); // Simulate adding a grade. $this->setUser($this->teachers[0]); $data = new stdClass(); $data->grade = '50.0'; $assign->testable_apply_grade_to_user($data, $this->students[0]->id, 0); $this->preventResetByRollback(); $sink = $this->redirectEvents(); $this->expectOutputRegex('/Done processing 1 assignment submissions/'); assign::cron(); $events = $sink->get_events(); // Two messages are sent, one to student and one to teacher. This generates // four events: // core\event\message_sent // core\event\message_viewed // core\event\message_sent // core\event\message_viewed. $event = reset($events); $this->assertInstanceOf('\\core\\event\\message_sent', $event); $this->assertEquals($assign->get_course()->id, $event->other['courseid']); $sink->close(); }