예제 #1
0
 public function test_assign_overdue()
 {
     global $PAGE;
     // Create one month overdue assignment.
     $this->setUser($this->teachers[0]);
     $assign = $this->create_instance(['duedate' => time() - 4 * DAYSECS, 'assignsubmission_onlinetext_enabled' => 1, 'name' => 'Overdue Assignment Test']);
     $this->setUser($this->students[0]);
     $modinfo = get_fast_modinfo($this->course);
     $assigncm = $modinfo->instances['assign'][$assign->get_instance()->id];
     $meta = activity::assign_meta($assigncm);
     $this->assertTrue($meta->overdue);
     // Make sure a submission record does not exist.
     $submission = activity::get_submission_row($this->course->id, $assigncm, 'submission', 'assignment');
     $this->assertEmpty($submission);
     // At one time there was an issue where the overdue status would flip after viewing the module.
     // Make sure this isn't happening by viewing the assignment.
     // Code taken from assign/tests/events_test.php test_submission_status_viewed.
     $PAGE->set_url('/a_url');
     // View the assignment.
     $assign->view();
     // Viewing an assignment creates a submission record with a status of new.
     // Make sure a submission record now exists with a status of new.
     $submission = activity::get_submission_row($this->course->id, $assigncm, 'submission', 'assignment');
     $this->assertNotEmpty($submission);
     $this->assertEquals(ASSIGN_SUBMISSION_STATUS_NEW, $submission->status);
     $meta = activity::assign_meta($assigncm);
     // Ensure that assignment is still classed as overdue.
     $this->assertTrue($meta->overdue);
 }
예제 #2
0
 public function test_assign_reopened_and_resubmitted()
 {
     $this->setUser($this->editingteachers[0]);
     $this->create_instance();
     $assign = $this->create_instance(array('duedate' => time(), 'attemptreopenmethod' => ASSIGN_ATTEMPT_REOPEN_METHOD_MANUAL, 'maxattempts' => 3, 'submissiondrafts' => 1, 'assignsubmission_onlinetext_enabled' => 1));
     // Add a submission.
     $this->setUser($this->students[0]);
     $submission = $assign->get_user_submission($this->students[0]->id, true);
     $data = new stdClass();
     $data->onlinetext_editor = array('itemid' => file_get_unused_draft_itemid(), 'text' => 'Submission text', 'format' => FORMAT_HTML);
     $plugin = $assign->get_submission_plugin_by_type('onlinetext');
     $plugin->save($submission, $data);
     // And now submit it for marking.
     $submission->status = ASSIGN_SUBMISSION_STATUS_SUBMITTED;
     $assign->testable_update_submission($submission, $this->students[0]->id, true, false);
     // Mark the submission.
     $this->setUser($this->teachers[0]);
     $data = new stdClass();
     $data->grade = '50.0';
     $assign->testable_apply_grade_to_user($data, $this->students[0]->id, 0);
     // TODO remove this next line when the above is fixed  to stop triggering debug messages.
     $this->resetDebugging();
     // This is required so that the submissions timemodified > the grade timemodified.
     sleep(2);
     // Edit the submission again.
     $this->setUser($this->students[0]);
     $submission = $assign->get_user_submission($this->students[0]->id, true);
     $assign->testable_update_submission($submission, $this->students[0]->id, true, false);
     // This is required so that the submissions timemodified > the grade timemodified.
     sleep(2);
     // Allow the student another attempt.
     $this->teachers[0]->ignoresesskey = true;
     $this->setUser($this->teachers[0]);
     $assign->testable_process_add_attempt($this->students[0]->id);
     // Add another submission.
     $this->setUser($this->students[0]);
     $submission = $assign->get_user_submission($this->students[0]->id, true);
     $data = new stdClass();
     $data->onlinetext_editor = array('itemid' => file_get_unused_draft_itemid(), 'text' => 'Submission text 2', 'format' => FORMAT_HTML);
     $plugin = $assign->get_submission_plugin_by_type('onlinetext');
     $plugin->save($submission, $data);
     // And now submit it for marking (again).
     $submission->status = ASSIGN_SUBMISSION_STATUS_SUBMITTED;
     $assign->testable_update_submission($submission, $this->students[0]->id, true, false);
     $modinfo = get_fast_modinfo($this->course);
     $assigncm = $modinfo->instances['assign'][$assign->get_instance()->id];
     $expnumsubmissions = 1;
     $expnumrequiregrading = 1;
     $this->setUser($this->editingteachers[0]);
     $actual = activity::assign_meta($assigncm);
     $this->assertSame($actual->numsubmissions, $expnumsubmissions);
     $this->assertSame($actual->numrequiregrading, $expnumrequiregrading);
     $this->assertTrue($actual->isteacher);
     $actual = activity::assign_meta($assigncm);
     $this->assertSame($actual->numsubmissions, $expnumsubmissions);
     $this->assertSame($actual->numrequiregrading, $expnumrequiregrading);
     $this->assertTrue($actual->isteacher);
     $this->setUser($this->teachers[0]);
     $actual = activity::assign_meta($assigncm);
     $this->assertSame($actual->numsubmissions, $expnumsubmissions);
     $this->assertSame($actual->numrequiregrading, $expnumrequiregrading);
     $this->assertTrue($actual->isteacher);
     $this->setUser($this->students[0]);
     $actual = activity::assign_meta($assigncm);
     $this->assertFalse($actual->isteacher);
 }