Permalink
Browse files

Merge branch 'MDL-49025-m34' of https://github.com/NeillM/moodle into…

… MOODLE_34_STABLE
  • Loading branch information...
dmonllao committed Jul 16, 2018
2 parents 982a838 + 3c50648 commit b88a479c6d48f7a5264996668caeb5aa3de05ab0
Showing with 75 additions and 2 deletions.
  1. +10 −2 mod/assign/submission/file/locallib.php
  2. +65 −0 mod/assign/submission/file/tests/locallib_test.php
@@ -513,8 +513,16 @@ public function is_empty(stdClass $submission) {
* @return bool
*/
public function submission_is_empty(stdClass $data) {
$files = file_get_drafarea_files($data->files_filemanager);
return count($files->list) == 0;
global $USER;
$fs = get_file_storage();
// Get a count of all the draft files, excluding any directories.
$files = $fs->get_area_files(context_user::instance($USER->id)->id,
'user',
'draft',
$data->files_filemanager,
'id',
false);
return count($files) == 0;
}
/**
@@ -72,6 +72,34 @@ public function test_submission_is_empty($data, $expected) {
$this->assertTrue($result === $expected);
}
/**
* Test that an empty directory is is not detected as a valid submission by submission_is_empty.
*/
public function test_submission_is_empty_directory_only() {
$this->resetAfterTest();
$course = $this->getDataGenerator()->create_course();
$student = $this->getDataGenerator()->create_and_enrol($course, 'student');
$assign = $this->create_instance($course, [
'assignsubmission_file_enabled' => 1,
'assignsubmission_file_maxfiles' => 12,
'assignsubmission_file_maxsizebytes' => 10,
]);
$this->setUser($student->id);
$itemid = file_get_unused_draft_itemid();
$submission = (object)['files_filemanager' => $itemid];
$plugin = $assign->get_submission_plugin_by_type('file');
$fs = get_file_storage();
$fs->create_directory(
context_user::instance($student->id)->id,
'user',
'draft',
$itemid,
'/subdirectory/'
);
$this->assertTrue($plugin->submission_is_empty($submission));
}
/**
* Test new_submission_empty
*
@@ -105,6 +133,34 @@ public function test_new_submission_empty($data, $expected) {
$this->assertTrue($result === $expected);
}
/**
* Test that an empty directory is is not detected as a valid submission by new_submission_is_empty.
*/
public function test_new_submission_empty_directory_only() {
$this->resetAfterTest();
$course = $this->getDataGenerator()->create_course();
$student = $this->getDataGenerator()->create_and_enrol($course, 'student');
$assign = $this->create_instance($course, [
'assignsubmission_file_enabled' => 1,
'assignsubmission_file_maxfiles' => 12,
'assignsubmission_file_maxsizebytes' => 10,
]);
$this->setUser($student->id);
$itemid = file_get_unused_draft_itemid();
$submission = (object)['files_filemanager' => $itemid];
$plugin = $assign->get_submission_plugin_by_type('file');
$fs = get_file_storage();
$fs->create_directory(
context_user::instance($student->id)->id,
'user',
'draft',
$itemid,
'/subdirectory/'
);
$this->assertTrue($assign->new_submission_empty($submission));
}
/**
* Dataprovider for the test_submission_is_empty testcase
*
@@ -121,6 +177,15 @@ public function submission_is_empty_testcases() {
],
false
],
'With file in directory' => [
[
'component' => 'user',
'filearea' => 'draft',
'filepath' => '/subdir/',
'filename' => 'not_a_virus.exe'
],
false
],
'Without file' => [null, true]
];
}

0 comments on commit b88a479

Please sign in to comment.