/** * Test get_submission_status for a reopened submission. */ public function test_get_submission_status_in_reopened_status() { global $USER; $this->resetAfterTest(true); list($assign, $instance, $student1, $student2, $teacher) = $this->create_submission_for_testing_status(true); $this->setUser($teacher); // Grade and reopen. $feedbackpluginparams = array(); $feedbackpluginparams['files_filemanager'] = file_get_unused_draft_itemid(); $feedbackeditorparams = array('text' => 'Yeeha!', 'format' => 1); $feedbackpluginparams['assignfeedbackcomments_editor'] = $feedbackeditorparams; $result = mod_assign_external::save_grade($instance->id, $student1->id, 50.0, -1, false, 'released', false, $feedbackpluginparams); $USER->ignoresesskey = true; $assign->testable_process_add_attempt($student1->id); $this->setUser($student1); $result = mod_assign_external::get_submission_status($assign->get_instance()->id); // We expect debugging because of the $PAGE object, this won't happen in a normal WS request. $this->assertDebuggingCalled(); $result = external_api::clean_returnvalue(mod_assign_external::get_submission_status_returns(), $result); $this->assertCount(0, $result['warnings']); $this->assertFalse(isset($result['gradingsummary'])); $this->assertTrue($result['lastattempt']['submissionsenabled']); $this->assertTrue($result['lastattempt']['canedit']); $this->assertFalse($result['lastattempt']['cansubmit']); $this->assertFalse($result['lastattempt']['locked']); $this->assertFalse($result['lastattempt']['graded']); $this->assertEmpty($result['lastattempt']['extensionduedate']); $this->assertFalse($result['lastattempt']['blindmarking']); $this->assertCount(0, $result['lastattempt']['submissiongroupmemberswhoneedtosubmit']); $this->assertEquals('notgraded', $result['lastattempt']['gradingstatus']); // Check new attempt reopened. $this->assertEquals($student1->id, $result['lastattempt']['submission']['userid']); $this->assertEquals(1, $result['lastattempt']['submission']['attemptnumber']); $this->assertEquals('reopened', $result['lastattempt']['submission']['status']); $this->assertEquals(0, $result['lastattempt']['submission']['groupid']); $this->assertEquals($assign->get_instance()->id, $result['lastattempt']['submission']['assignment']); $this->assertEquals(1, $result['lastattempt']['submission']['latest']); $this->assertCount(3, $result['lastattempt']['submission']['plugins']); // Now see feedback and the attempts history (remember, is a submission reopened). // Only 2 fields (no grade, no plugins data). $this->assertCount(2, $result['feedback']); // One previous attempt. $this->assertCount(1, $result['previousattempts']); $this->assertEquals(0, $result['previousattempts'][0]['attemptnumber']); $this->assertEquals(50, $result['previousattempts'][0]['grade']['grade']); $this->assertEquals($teacher->id, $result['previousattempts'][0]['grade']['grader']); $this->assertEquals($student1->id, $result['previousattempts'][0]['grade']['userid']); // Map plugins based on their type - we can't rely on them being in a // particular order, especially if 3rd party plugins are installed. $feedbackplugins = array(); foreach ($result['previousattempts'][0]['feedbackplugins'] as $plugin) { $feedbackplugins[$plugin['type']] = $plugin; } $this->assertEquals('Yeeha!', $feedbackplugins['comments']['editorfields'][0]['text']); $submissionplugins = array(); foreach ($result['previousattempts'][0]['submission']['plugins'] as $plugin) { $submissionplugins[$plugin['type']] = $plugin; } $this->assertEquals('Submission text', $submissionplugins['onlinetext']['editorfields'][0]['text']); $this->assertEquals('/t.txt', $submissionplugins['file']['fileareas'][0]['files'][0]['filepath']); }
/** * Test copy_previous_attempt */ public function test_copy_previous_attempt() { global $DB, $USER; $this->resetAfterTest(true); // Create a course and assignment and users. $course = self::getDataGenerator()->create_course(); $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($teacher); $generator = $this->getDataGenerator()->get_plugin_generator('mod_assign'); $params['course'] = $course->id; $params['assignsubmission_onlinetext_enabled'] = 1; $params['assignsubmission_file_enabled'] = 0; $params['assignfeedback_file_enabled'] = 0; $params['attemptreopenmethod'] = 'manual'; $params['maxattempts'] = 5; $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(); $studentrole = $DB->get_record('role', array('shortname' => 'student')); $this->getDataGenerator()->enrol_user($student1->id, $course->id, $studentrole->id); // Now try a submission. $this->setUser($student1); $draftidonlinetext = file_get_unused_draft_itemid(); $submissionpluginparams = array(); $onlinetexteditorparams = array('text' => 'Yeeha!', 'format' => 1, 'itemid' => $draftidonlinetext); $submissionpluginparams['onlinetext_editor'] = $onlinetexteditorparams; $submissionpluginparams['files_filemanager'] = file_get_unused_draft_itemid(); $result = mod_assign_external::save_submission($instance->id, $submissionpluginparams); $this->setUser($teacher); // Add a grade and reopen the attempt. // Now try a grade. $feedbackpluginparams = array(); $feedbackpluginparams['files_filemanager'] = file_get_unused_draft_itemid(); $feedbackeditorparams = array('text' => 'Yeeha!', 'format' => 1); $feedbackpluginparams['assignfeedbackcomments_editor'] = $feedbackeditorparams; $result = mod_assign_external::save_grade($instance->id, $student1->id, 50.0, -1, true, 'released', false, $feedbackpluginparams); $this->setUser($student1); // Now copy the previous attempt. $result = mod_assign_external::copy_previous_attempt($instance->id); // No warnings. $this->assertEquals(0, count($result)); $this->setUser($teacher); $result = mod_assign_external::get_submissions(array($instance->id)); // Check we are now on the second attempt. $this->assertEquals($result['assignments'][0]['submissions'][0]['attemptnumber'], 1); // Check the plugins data is not empty. $this->assertNotEmpty($result['assignments'][0]['submissions'][0]['plugins']); }