MDL-41945 mod_assign: Properly check if submission is empty

Previous empty submission checks required the submission to
be saved to the database. This patch adds a new method to
submission plugins that lets them report whether the submission
is empty before it is saved.
This commit is contained in:
Cameron Ball 2016-05-31 14:20:03 +08:00
parent 16b36d376a
commit c89d23ee6d
No known key found for this signature in database
GPG key ID: 305B7F70214D810C
8 changed files with 375 additions and 0 deletions

View file

@ -687,6 +687,63 @@ class mod_assign_locallib_testcase extends mod_assign_base_testcase {
$this->assertContains(get_string('submitassignment', 'assign'), $output, 'Can submit non empty onlinetext assignment');
}
/**
* Test new_submission_empty
*
* We only test combinations of plugins here. Individual plugins are tested
* in their respective test files.
*
* @dataProvider test_new_submission_empty_testcases
* @param string $data The file submission data
* @param bool $expected The expected return value
*/
public function test_new_submission_empty($data, $expected) {
$this->resetAfterTest();
$assign = $this->create_instance(['assignsubmission_file_enabled' => 1,
'assignsubmission_file_maxfiles' => 12,
'assignsubmission_file_maxsizebytes' => 10,
'assignsubmission_onlinetext_enabled' => 1]);
$this->setUser($this->students[0]);
$submission = new stdClass();
if ($data['file'] && isset($data['file']['filename'])) {
$itemid = file_get_unused_draft_itemid();
$submission->files_filemanager = $itemid;
$data['file'] += ['contextid' => context_user::instance($this->students[0]->id)->id, 'itemid' => $itemid];
$fs = get_file_storage();
$fs->create_file_from_string((object)$data['file'], 'Content of ' . $data['file']['filename']);
}
if ($data['onlinetext']) {
$submission->onlinetext_editor = ['text' => $data['onlinetext']];
}
$result = $assign->new_submission_empty($submission);
$this->assertTrue($result === $expected);
}
/**
* Dataprovider for the test_new_submission_empty testcase
*
* @return array of testcases
*/
public function test_new_submission_empty_testcases() {
return [
'With file and onlinetext' => [
[
'file' => [
'component' => 'user',
'filearea' => 'draft',
'filepath' => '/',
'filename' => 'not_a_virus.exe'
],
'onlinetext' => 'Balin Fundinul Uzbadkhazaddumu'
],
false
]
];
}
public function test_list_participants() {
global $CFG, $DB;