/**
  * Test submit_for_grading
  */
 public function test_submit_for_grading()
 {
     global $DB, $USER;
     $this->resetAfterTest(true);
     // Create a course and seplment and users.
     $course = self::getDataGenerator()->create_course();
     set_config('submissionreceipts', 0, 'sepl');
     $generator = $this->getDataGenerator()->get_plugin_generator('mod_sepl');
     $params['course'] = $course->id;
     $params['seplsubmission_onlinetext_enabled'] = 1;
     $params['submissiondrafts'] = 1;
     $params['sendnotifications'] = 0;
     $params['requiresubmissionstatement'] = 1;
     $instance = $generator->create_instance($params);
     $cm = get_coursemodule_from_instance('sepl', $instance->id);
     $context = context_module::instance($cm->id);
     $sepl = new sepl($context, $cm, $course);
     $student1 = self::getDataGenerator()->create_user();
     $studentrole = $DB->get_record('role', array('shortname' => 'student'));
     $this->getDataGenerator()->enrol_user($student1->id, $course->id, $studentrole->id);
     // Create a student1 with an online text submission.
     // Simulate a submission.
     $this->setUser($student1);
     $submission = $sepl->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);
     $plugin = $sepl->get_submission_plugin_by_type('onlinetext');
     $plugin->save($submission, $data);
     $result = mod_sepl_external::submit_for_grading($instance->id, false);
     $result = external_api::clean_returnvalue(mod_sepl_external::submit_for_grading_returns(), $result);
     // Should be 1 fail because the submission statement was not aceptted.
     $this->assertEquals(1, count($result));
     $result = mod_sepl_external::submit_for_grading($instance->id, true);
     $result = external_api::clean_returnvalue(mod_sepl_external::submit_for_grading_returns(), $result);
     // Check for 0 warnings.
     $this->assertEquals(0, count($result));
     $submission = $sepl->get_user_submission($student1->id, false);
     $this->assertEquals(ASSIGN_SUBMISSION_STATUS_SUBMITTED, $submission->status);
 }
 public function test_upgrade_offline_seplment()
 {
     global $DB, $CFG;
     $commentconfig = false;
     if (!empty($CFG->usecomments)) {
         $commentconfig = $CFG->usecomments;
     }
     $CFG->usecomments = false;
     $this->setUser($this->editingteachers[0]);
     $generator = $this->getDataGenerator()->get_plugin_generator('mod_seplment');
     $params = array('course' => $this->course->id, 'seplmenttype' => 'offline');
     $seplment = $generator->create_instance($params);
     $this->setAdminUser();
     $log = '';
     $upgrader = new sepl_upgrade_manager();
     $this->assertTrue($upgrader->upgrade_seplment($seplment->id, $log));
     $record = $DB->get_record('sepl', array('course' => $this->course->id));
     $cm = get_coursemodule_from_instance('sepl', $record->id);
     $context = context_module::instance($cm->id);
     $sepl = new sepl($context, $cm, $this->course);
     $plugin = $sepl->get_submission_plugin_by_type('onlinetext');
     $this->assertEmpty($plugin->is_enabled());
     $plugin = $sepl->get_submission_plugin_by_type('comments');
     $this->assertEmpty($plugin->is_enabled());
     $plugin = $sepl->get_submission_plugin_by_type('file');
     $this->assertEmpty($plugin->is_enabled());
     $plugin = $sepl->get_feedback_plugin_by_type('comments');
     $this->assertNotEmpty($plugin->is_enabled());
     $plugin = $sepl->get_feedback_plugin_by_type('file');
     $this->assertEmpty($plugin->is_enabled());
     $plugin = $sepl->get_feedback_plugin_by_type('offline');
     $this->assertEmpty($plugin->is_enabled());
     $CFG->usecomments = $commentconfig;
     course_delete_module($cm->id);
 }
Пример #3
0
 /**
  * Fetch the plugin by its type.
  *
  * @return sepl_submission_plugin
  */
 protected function get_submission_plugin()
 {
     global $CFG;
     if (!$this->plugin || !$this->cmid) {
         return null;
     }
     require_once $CFG->dirroot . '/mod/sepl/locallib.php';
     $context = context_module::instance($this->cmid);
     $seplment = new sepl($context, null, null);
     return $seplment->get_submission_plugin_by_type($this->plugin);
 }