Exemplo n.º 1
0
 public function test_assessable_uploaded()
 {
     $this->resetAfterTest();
     $user = $this->getDataGenerator()->create_user();
     $course = $this->getDataGenerator()->create_course();
     $generator = $this->getDataGenerator()->get_plugin_generator('mod_assign');
     $params['course'] = $course->id;
     $instance = $generator->create_instance($params);
     $cm = get_coursemodule_from_instance('assign', $instance->id);
     $context = context_module::instance($cm->id);
     $assign = new testable_assign($context, $cm, $course);
     $this->setUser($user->id);
     $submission = $assign->get_user_submission($user->id, true);
     $data = new stdClass();
     $data->onlinetext_editor = array('itemid' => file_get_unused_draft_itemid(), 'text' => 'Submission text', 'format' => FORMAT_PLAIN);
     $plugin = $assign->get_submission_plugin_by_type('onlinetext');
     $sink = $this->redirectEvents();
     $plugin->save($submission, $data);
     $events = $sink->get_events();
     $this->assertCount(1, $events);
     $event = reset($events);
     $this->assertInstanceOf('\\assignsubmission_onlinetext\\event\\assessable_uploaded', $event);
     $this->assertEquals($context->id, $event->contextid);
     $this->assertEquals($submission->id, $event->objectid);
     $this->assertEquals(array(), $event->other['pathnamehashes']);
     $this->assertEquals('Submission text', $event->other['content']);
     $expected = new stdClass();
     $expected->modulename = 'assign';
     $expected->cmid = $cm->id;
     $expected->itemid = $submission->id;
     $expected->courseid = $course->id;
     $expected->userid = $user->id;
     $expected->content = 'Submission text';
     $this->assertEventLegacyData($expected, $event);
 }
Exemplo n.º 2
0
 public function test_assessable_uploaded()
 {
     $this->resetAfterTest();
     $user = $this->getDataGenerator()->create_user();
     $course = $this->getDataGenerator()->create_course();
     $generator = $this->getDataGenerator()->get_plugin_generator('mod_assign');
     $params['course'] = $course->id;
     $instance = $generator->create_instance($params);
     $cm = get_coursemodule_from_instance('assign', $instance->id);
     $context = context_module::instance($cm->id);
     $assign = new testable_assign($context, $cm, $course);
     $this->setUser($user->id);
     $submission = $assign->get_user_submission($user->id, true);
     $fs = get_file_storage();
     $dummy = (object) array('contextid' => $context->id, 'component' => 'assignsubmission_file', 'filearea' => ASSIGNSUBMISSION_FILE_FILEAREA, 'itemid' => $submission->id, 'filepath' => '/', 'filename' => 'myassignmnent.pdf');
     $fi = $fs->create_file_from_string($dummy, 'Content of ' . $dummy->filename);
     $dummy = (object) array('contextid' => $context->id, 'component' => 'assignsubmission_file', 'filearea' => ASSIGNSUBMISSION_FILE_FILEAREA, 'itemid' => $submission->id, 'filepath' => '/', 'filename' => 'myassignmnent.png');
     $fi2 = $fs->create_file_from_string($dummy, 'Content of ' . $dummy->filename);
     $files = $fs->get_area_files($context->id, 'assignsubmission_file', ASSIGNSUBMISSION_FILE_FILEAREA, $submission->id, 'id', false);
     $data = new stdClass();
     $plugin = $assign->get_submission_plugin_by_type('file');
     $sink = $this->redirectEvents();
     $plugin->save($submission, $data);
     $events = $sink->get_events();
     $this->assertCount(1, $events);
     $event = reset($events);
     $this->assertInstanceOf('\\assignsubmission_file\\event\\assessable_uploaded', $event);
     $this->assertEquals($context->id, $event->contextid);
     $this->assertEquals($submission->id, $event->objectid);
     $this->assertCount(2, $event->other['pathnamehashes']);
     $this->assertEquals($fi->get_pathnamehash(), $event->other['pathnamehashes'][0]);
     $this->assertEquals($fi2->get_pathnamehash(), $event->other['pathnamehashes'][1]);
     $expected = new stdClass();
     $expected->modulename = 'assign';
     $expected->cmid = $cm->id;
     $expected->itemid = $submission->id;
     $expected->courseid = $course->id;
     $expected->userid = $user->id;
     $expected->file = $files;
     $expected->files = $files;
     $expected->pathnamehashes = array($fi->get_pathnamehash(), $fi2->get_pathnamehash());
     $this->assertEventLegacyData($expected, $event);
 }
 public function test_group_members_only()
 {
     global $CFG;
     $this->setAdminUser();
     $this->create_extra_users();
     $CFG->enableavailability = true;
     $grouping = $this->getDataGenerator()->create_grouping(array('courseid' => $this->course->id));
     groups_assign_grouping($grouping->id, $this->groups[0]->id);
     // Force create an assignment with SEPARATEGROUPS.
     $instance = $this->getDataGenerator()->create_module('assign', array('course' => $this->course->id), array('availability' => json_encode(\core_availability\tree::get_root_json(array(\availability_grouping\condition::get_json()))), 'groupingid' => $grouping->id));
     $cm = get_coursemodule_from_instance('assign', $instance->id);
     $context = context_module::instance($cm->id);
     $assign = new testable_assign($context, $cm, $this->course);
     $this->setUser($this->teachers[0]);
     get_fast_modinfo($this->course, 0, true);
     $this->assertCount(5, $assign->list_participants(0, true));
 }
Exemplo n.º 4
0
 public function test_group_members_only()
 {
     global $CFG;
     $this->setAdminUser();
     $this->create_extra_users();
     $CFG->enablegroupmembersonly = true;
     $grouping = $this->getDataGenerator()->create_grouping(array('courseid' => $this->course->id));
     groups_assign_grouping($grouping->id, $this->groups[0]->id);
     // Force create an assignment with SEPARATEGROUPS.
     $instance = $this->getDataGenerator()->create_module('assign', array('course' => $this->course->id), array('groupmembersonly' => SEPARATEGROUPS, 'groupingid' => $grouping->id));
     $cm = get_coursemodule_from_instance('assign', $instance->id);
     $context = context_module::instance($cm->id);
     $assign = new testable_assign($context, $cm, $this->course);
     $this->setUser($this->teachers[0]);
     $this->assertCount(5, $assign->list_participants(0, true));
 }
Exemplo n.º 5
0
 /**
  * get_participant should return group details if a group submission was
  * submitted.
  */
 public function test_get_participant_group_submission()
 {
     global $DB, $CFG;
     require_once $CFG->dirroot . '/mod/assign/tests/base_test.php';
     $this->resetAfterTest(true);
     $result = $this->create_assign_with_student_and_teacher(array('assignsubmission_onlinetext_enabled' => 1, 'teamsubmission' => 1));
     $assignmodule = $result['assign'];
     $student = $result['student'];
     $teacher = $result['teacher'];
     $course = $result['course'];
     $context = context_course::instance($course->id);
     $teacherrole = $DB->get_record('role', array('shortname' => 'teacher'));
     $group = $this->getDataGenerator()->create_group(array('courseid' => $course->id));
     $cm = get_coursemodule_from_instance('assign', $assignmodule->id);
     $context = context_module::instance($cm->id);
     $assign = new testable_assign($context, $cm, $course);
     groups_add_member($group, $student);
     $this->setUser($student);
     $submission = $assign->get_group_submission($student->id, $group->id, true);
     $submission->status = ASSIGN_SUBMISSION_STATUS_SUBMITTED;
     $assign->testable_update_submission($submission, $student->id, true, false);
     $data = new stdClass();
     $data->onlinetext_editor = array('itemid' => file_get_unused_draft_itemid(), 'text' => 'Submission text', 'format' => FORMAT_MOODLE);
     $plugin = $assign->get_submission_plugin_by_type('onlinetext');
     $plugin->save($submission, $data);
     $this->setUser($teacher);
     $result = mod_assign_external::get_participant($assignmodule->id, $student->id, false);
     // Check some of the extended properties we get when not requesting a summary.
     $this->assertEquals($student->id, $result['id']);
     $this->assertEquals($group->id, $result['groupid']);
     $this->assertEquals($group->name, $result['groupname']);
 }
Exemplo n.º 6
0
    public function test_get_graders() {
        $this->create_extra_users();
        $this->setUser($this->editingteachers[0]);
        $assign = $this->create_instance();

        $this->assertCount(self::DEFAULT_TEACHER_COUNT +
                           self::DEFAULT_EDITING_TEACHER_COUNT +
                           self::EXTRA_TEACHER_COUNT +
                           self::EXTRA_EDITING_TEACHER_COUNT,
                           $assign->testable_get_graders($this->students[0]->id));

        $assign = $this->create_instance();
        // Force create an assignment with SEPARATEGROUPS.
        $generator = $this->getDataGenerator()->get_plugin_generator('mod_assign');
        $params = array('course'=>$this->course->id);
        $instance = $generator->create_instance($params);
        $cm = get_coursemodule_from_instance('assign', $instance->id);
        set_coursemodule_groupmode($cm->id, SEPARATEGROUPS);
        $cm->groupmode = SEPARATEGROUPS;
        $context = context_module::instance($cm->id);
        $assign = new testable_assign($context, $cm, $this->course);

        $this->setUser($this->students[1]);
        $this->assertCount(4, $assign->testable_get_graders($this->students[0]->id));
    }