274
274
public function test_update_calendar() {
277
$this->setUser($this->editingteachers[0]);
278
$userctx = context_user::instance($this->editingteachers[0]->id)->id;
280
// Hack to pretend that there was an editor involved. We need both $_POST and $_REQUEST, and a sesskey.
281
$draftid = file_get_unused_draft_itemid();
282
$_REQUEST['introeditor'] = $draftid;
283
$_POST['introeditor'] = $draftid;
284
$_POST['sesskey'] = sesskey();
286
// Write links to a draft area.
287
$fakearealink1 = file_rewrite_pluginfile_urls('<a href="@@PLUGINFILE@@/pic.gif">link</a>', 'draftfile.php', $userctx,
288
'user', 'draft', $draftid);
289
$fakearealink2 = file_rewrite_pluginfile_urls('<a href="@@PLUGINFILE@@/pic.gif">new</a>', 'draftfile.php', $userctx,
290
'user', 'draft', $draftid);
292
// Create a new assignment with links to a draft area.
278
$this->setUser($this->editingteachers[0]);
279
$assign = $this->create_instance(array('duedate'=>$now));
294
$assign = $this->create_instance(array(
296
'intro' => $fakearealink1,
297
'introformat' => FORMAT_HTML
281
300
// See if there is an event in the calendar.
282
301
$params = array('modulename'=>'assign', 'instance'=>$assign->get_instance()->id);
283
$id = $DB->get_field('event', 'id', $params);
302
$event = $DB->get_record('event', $params);
303
$this->assertNotEmpty($event);
304
$this->assertSame('link', $event->description); // The pluginfile links are removed.
285
$this->assertEquals(false, empty($id));
306
// Make sure the same works when updating the assignment.
307
$instance = $assign->get_instance();
308
$instance->instance = $instance->id;
309
$instance->intro = $fakearealink2;
310
$instance->introformat = FORMAT_HTML;
311
$assign->update_instance($instance);
312
$params = array('modulename' => 'assign', 'instance' => $assign->get_instance()->id);
313
$event = $DB->get_record('event', $params);
314
$this->assertNotEmpty($event);
315
$this->assertSame('new', $event->description); // The pluginfile links are removed.
288
318
public function test_update_instance() {
609
639
public function test_get_graders() {
610
640
$this->create_extra_users();
611
641
$this->setUser($this->editingteachers[0]);
643
// Create an assignment with no groups.
612
644
$assign = $this->create_instance();
614
645
$this->assertCount(self::DEFAULT_TEACHER_COUNT +
615
646
self::DEFAULT_EDITING_TEACHER_COUNT +
616
647
self::EXTRA_TEACHER_COUNT +
617
648
self::EXTRA_EDITING_TEACHER_COUNT,
618
649
$assign->testable_get_graders($this->students[0]->id));
620
$assign = $this->create_instance();
621
651
// Force create an assignment with SEPARATEGROUPS.
652
$data = new stdClass();
653
$data->courseid = $this->course->id;
654
$data->name = 'Grouping';
655
$groupingid = groups_create_grouping($data);
656
groups_assign_grouping($groupingid, $this->groups[0]->id);
622
658
$generator = $this->getDataGenerator()->get_plugin_generator('mod_assign');
623
659
$params = array('course'=>$this->course->id);
624
660
$instance = $generator->create_instance($params);
625
661
$cm = get_coursemodule_from_instance('assign', $instance->id);
626
662
set_coursemodule_groupmode($cm->id, SEPARATEGROUPS);
627
663
$cm->groupmode = SEPARATEGROUPS;
664
$cm->groupingid = $groupingid;
628
665
$context = context_module::instance($cm->id);
629
666
$assign = new testable_assign($context, $cm, $this->course);
631
668
$this->setUser($this->students[1]);
632
669
$this->assertCount(4, $assign->testable_get_graders($this->students[0]->id));
670
// Note the second student is in a group that is not in the grouping.
671
// This means that we get all graders that are not in a group in the grouping.
672
$this->assertCount(10, $assign->testable_get_graders($this->students[1]->id));
635
675
public function test_group_members_only() {