~ubuntu-branches/ubuntu/trusty/moodle/trusty

« back to all changes in this revision

Viewing changes to mod/assign/tests/locallib_test.php

  • Committer: Package Import Robot
  • Author(s): Thijs Kinkhorst
  • Date: 2014-01-21 13:40:52 UTC
  • mfrom: (1.1.13)
  • Revision ID: package-import@ubuntu.com-20140121134052-ym2qvsp2cd9vq0p6
Tags: 2.5.4-1
* New upstream release, fixing security issues:
  - MSA-14-0001 Config passwords visibility issue [CVE-2014-0008]
  - MSA-14-0002 Group constraints lacking in "login as" [CVE-2014-0009]
  - MSA-14-0003 CSRF vulnerability in profile fields [CVE-2014-0010]
* Move /var/lib/moodle directory into package.
* Revert back to bundled yui3. Unfortunately, version in Debian and
  of upstream are not compatible (closes: #735312).

Show diffs side-by-side

added added

removed removed

Lines of Context:
274
274
    public function test_update_calendar() {
275
275
        global $DB;
276
276
 
 
277
        $this->setUser($this->editingteachers[0]);
 
278
        $userctx = context_user::instance($this->editingteachers[0]->id)->id;
 
279
 
 
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();
 
285
 
 
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);
 
291
 
 
292
        // Create a new assignment with links to a draft area.
277
293
        $now = time();
278
 
        $this->setUser($this->editingteachers[0]);
279
 
        $assign = $this->create_instance(array('duedate'=>$now));
 
294
        $assign = $this->create_instance(array(
 
295
            'duedate' => $now,
 
296
            'intro' => $fakearealink1,
 
297
            'introformat' => FORMAT_HTML
 
298
        ));
280
299
 
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.
284
305
 
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.
286
316
    }
287
317
 
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]);
 
642
 
 
643
        // Create an assignment with no groups.
612
644
        $assign = $this->create_instance();
613
 
 
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));
619
650
 
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);
 
657
 
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);
630
667
 
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));
633
673
    }
634
674
 
635
675
    public function test_group_members_only() {