Пример #1
0
 /**
  * Test the group override updated event.
  *
  * There is no external API for updating a group override, so the unit test will simply
  * create and trigger the event and ensure the event data is returned as expected.
  */
 public function test_group_override_updated()
 {
     $course = $this->getDataGenerator()->create_course();
     $assign = $this->getDataGenerator()->create_module('assign', array('course' => $course->id));
     $params = array('objectid' => 1, 'context' => context_module::instance($assign->cmid), 'other' => array('assignid' => $assign->id, 'groupid' => 2));
     $event = \mod_assign\event\group_override_updated::create($params);
     // Trigger and capture the event.
     $sink = $this->redirectEvents();
     $event->trigger();
     $events = $sink->get_events();
     $event = reset($events);
     // Check that the event data is valid.
     $this->assertInstanceOf('\\mod_assign\\event\\group_override_updated', $event);
     $this->assertEquals(context_module::instance($assign->cmid), $event->get_context());
     $this->assertEventContextNotUsed($event);
 }
Пример #2
0
         $assign->delete_override($oldoverride->id);
     }
 }
 // Set the common parameters for one of the events we may be triggering.
 $params = array('context' => $context, 'other' => array('assignid' => $assign->get_context()->id));
 if (!empty($override->id)) {
     $fromform->id = $override->id;
     $DB->update_record('assign_overrides', $fromform);
     // Determine which override updated event to fire.
     $params['objectid'] = $override->id;
     if (!$groupmode) {
         $params['relateduserid'] = $fromform->userid;
         $event = \mod_assign\event\user_override_updated::create($params);
     } else {
         $params['other']['groupid'] = $fromform->groupid;
         $event = \mod_assign\event\group_override_updated::create($params);
     }
     // Trigger the override updated event.
     $event->trigger();
 } else {
     unset($fromform->id);
     $fromform->id = $DB->insert_record('assign_overrides', $fromform);
     if ($groupmode) {
         $fromform->sortorder = $fromform->id;
         $overridecountgroup = $DB->count_records('assign_overrides', array('userid' => null, 'assignid' => $assign->get_context()->id));
         $overridecountall = $DB->count_records('assign_overrides', array('assignid' => $assign->get_context()->id));
         if (!$overridecountgroup && $overridecountall) {
             // No group overrides and there are user overrides.
             $fromform->sortorder = 1;
         } else {
             $fromform->sortorder = $overridecountgroup;