MDL-57610 assignfeedback_editpdf: Add test coverage for conversion task

Without this, we have no coverage of the convert_submissions task. This test
validates it both works normally, and that it also skips queued items that have
exceeded the conversion attempt limit introduced in this improvement.
This commit is contained in:
Adam Olley 2018-09-18 14:14:23 +09:30
parent b722a457ad
commit bc32547da9

View File

@ -338,6 +338,63 @@ class assignfeedback_editpdf_testcase extends advanced_testcase {
$this->assertEmpty($file3);
}
public function test_conversion_task() {
global $DB;
$this->require_ghostscript();
$this->resetAfterTest();
cron_setup_user();
$task = new \assignfeedback_editpdf\task\convert_submissions;
$course = $this->getDataGenerator()->create_course();
$student = $this->getDataGenerator()->create_and_enrol($course, 'student');
$assignopts = [
'assignsubmission_file_enabled' => 1,
'assignsubmission_file_maxfiles' => 1,
'assignfeedback_editpdf_enabled' => 1,
'assignsubmission_file_maxsizebytes' => 1000000,
];
$assign = $this->create_instance($course, $assignopts);
// Add the standard submission.
$this->add_file_submission($student, $assign);
// Run the conversion task.
ob_start();
$task->execute();
$output = ob_get_clean();
// Verify it acted on both submissions in the queue.
$this->assertContains("Convert 1 submission attempt(s) for assignment {$assign->get_instance()->id}", $output);
$this->assertEquals(0, $DB->count_records('assignfeedback_editpdf_queue'));
// Set a known limit.
set_config('conversionattemptlimit', 3);
// Trigger a re-queue by 'updating' a submission.
$submission = $assign->get_user_submission($student->id, true);
$plugin = $assign->get_submission_plugin_by_type('file');
$plugin->save($submission, (new stdClass));
// Verify that queued a conversion task.
$this->assertEquals(1, $DB->count_records('assignfeedback_editpdf_queue'));
// Fake some failed attempts for it.
$queuerecord = $DB->get_record('assignfeedback_editpdf_queue', ['submissionid' => $submission->id]);
$queuerecord->attemptedconversions = 3;
$DB->update_record('assignfeedback_editpdf_queue', $queuerecord);
ob_start();
$task->execute();
$output = ob_get_clean();
// Verify that the cron task skipped the submission.
$this->assertNotContains("Convert 1 submission attempt(s) for assignment {$assign->get_instance()->id}", $output);
// And it removed it from the queue.
$this->assertEquals(0, $DB->count_records('assignfeedback_editpdf_queue'));
}
/**
* Test that modifying the annotated pdf form return true when modified
* and false when not modified.