Ejemplo 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);
 }
Ejemplo 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);
 }
Ejemplo n.º 3
0
 /**
  * Create a submission for testing the get_submission_status function.
  * @param  boolean $submitforgrading whether to submit for grading the submission
  * @return array an array containing all the required data for testing
  */
 private function create_submission_for_testing_status($submitforgrading = false)
 {
     global $DB, $CFG;
     require_once $CFG->dirroot . '/mod/assign/tests/base_test.php';
     // Create a course and assignment and users.
     $course = self::getDataGenerator()->create_course();
     $generator = $this->getDataGenerator()->get_plugin_generator('mod_assign');
     $params = array('course' => $course->id, 'assignsubmission_file_maxfiles' => 1, 'assignsubmission_file_maxsizebytes' => 1024 * 1024, 'assignsubmission_onlinetext_enabled' => 1, 'assignsubmission_file_enabled' => 1, 'submissiondrafts' => 1, 'assignfeedback_file_enabled' => 1, 'assignfeedback_comments_enabled' => 1, 'attemptreopenmethod' => ASSIGN_ATTEMPT_REOPEN_METHOD_MANUAL, 'sendnotifications' => 0);
     set_config('submissionreceipts', 0, 'assign');
     $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);
     $student1 = self::getDataGenerator()->create_user();
     $student2 = self::getDataGenerator()->create_user();
     $studentrole = $DB->get_record('role', array('shortname' => 'student'));
     $this->getDataGenerator()->enrol_user($student1->id, $course->id, $studentrole->id);
     $this->getDataGenerator()->enrol_user($student2->id, $course->id, $studentrole->id);
     $teacher = self::getDataGenerator()->create_user();
     $teacherrole = $DB->get_record('role', array('shortname' => 'teacher'));
     $this->getDataGenerator()->enrol_user($teacher->id, $course->id, $teacherrole->id);
     $this->setUser($student1);
     // Create a student1 with an online text submission.
     // Simulate a submission.
     $submission = $assign->get_user_submission($student1->id, true);
     $data = new stdClass();
     $data->onlinetext_editor = array('itemid' => file_get_unused_draft_itemid(), 'text' => 'Submission text', 'format' => FORMAT_MOODLE);
     $draftidfile = file_get_unused_draft_itemid();
     $usercontext = context_user::instance($student1->id);
     $filerecord = array('contextid' => $usercontext->id, 'component' => 'user', 'filearea' => 'draft', 'itemid' => $draftidfile, 'filepath' => '/', 'filename' => 't.txt');
     $fs = get_file_storage();
     $fs->create_file_from_string($filerecord, 'text contents');
     $data->files_filemanager = $draftidfile;
     $notices = array();
     $assign->save_submission($data, $notices);
     if ($submitforgrading) {
         // Now, submit the draft for grading.
         $notices = array();
         $data = new stdClass();
         $data->userid = $student1->id;
         $assign->submit_for_grading($data, $notices);
     }
     return array($assign, $instance, $student1, $student2, $teacher);
 }