/** * 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']); }