/** * Test unlock_submissions */ public function test_unlock_submissions() { global $DB, $USER; $this->resetAfterTest(true); // Create a course and assignment and users. $course = self::getDataGenerator()->create_course(); $generator = $this->getDataGenerator()->get_plugin_generator('mod_assign'); $params['course'] = $course->id; $params['assignsubmission_onlinetext_enabled'] = 1; $instance = $generator->create_instance($params); $cm = get_coursemodule_from_instance('assign', $instance->id); $context = context_module::instance($cm->id); $assign = new 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); // Create a student1 with an online text submission. // Simulate a submission. $this->setUser($student1); $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); $plugin = $assign->get_submission_plugin_by_type('onlinetext'); $plugin->save($submission, $data); // Ready to test. $this->setUser($teacher); $students = array($student1->id, $student2->id); $result = mod_assign_external::lock_submissions($instance->id, $students); $result = external_api::clean_returnvalue(mod_assign_external::lock_submissions_returns(), $result); // Check for 0 warnings. $this->assertEquals(0, count($result)); $result = mod_assign_external::unlock_submissions($instance->id, $students); $result = external_api::clean_returnvalue(mod_assign_external::unlock_submissions_returns(), $result); // Check for 0 warnings. $this->assertEquals(0, count($result)); $this->setUser($student2); $submission = $assign->get_user_submission($student2->id, true); $data = new stdClass(); $data->onlinetext_editor = array('itemid' => file_get_unused_draft_itemid(), 'text' => 'Submission text', 'format' => FORMAT_MOODLE); $notices = array(); $assign->save_submission($data, $notices); }