Skip to content

Commit

Permalink
MDL-57610 assignfeedback_editpdf: Add test coverage for conversion task
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
aolley committed Sep 18, 2018
1 parent b722a45 commit bc32547
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions mod/assign/feedback/editpdf/tests/editpdf_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,63 @@ public function test_document_services() {
$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.
Expand Down

0 comments on commit bc32547

Please sign in to comment.