Skip to content

Commit

Permalink
MDL-67210 tool_uploadcourse: Allow only 0 and 1 for visible value.
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaboesch authored and sarjona committed Nov 26, 2019
1 parent 5f0db00 commit 6c4fda0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions admin/tool/uploadcourse/classes/course.php
Expand Up @@ -720,6 +720,12 @@ public function prepare() {
}
}

// Visibility can only be 0 or 1.
if (!empty($coursedata['visible']) AND !($coursedata['visible'] == 0 OR $coursedata['visible'] == 1)) {
$this->error('invalidvisibilitymode', new lang_string('invalidvisibilitymode', 'tool_uploadcourse'));
return false;
}

// Saving data.
$this->data = $coursedata;
$this->enrolmentdata = tool_uploadcourse_helper::get_enrolment_data($this->rawdata);
Expand Down
1 change: 1 addition & 0 deletions admin/tool/uploadcourse/lang/en/tool_uploadcourse.php
Expand Up @@ -90,6 +90,7 @@
$string['invalidencoding'] = 'Invalid encoding';
$string['invalidmode'] = 'Invalid mode selected';
$string['invalideupdatemode'] = 'Invalid update mode selected';
$string['invalidvisibilitymode'] = 'Invalid visibility mode given';
$string['invalidroles'] = 'Invalid role names: {$a}';
$string['invalidshortname'] = 'Invalid shortname';
$string['missingmandatoryfields'] = 'Missing value for mandatory fields: {$a}';
Expand Down
10 changes: 10 additions & 0 deletions admin/tool/uploadcourse/tests/course_test.php
Expand Up @@ -82,6 +82,16 @@ public function test_invalid_shortname() {
$this->assertArrayHasKey('invalidshortname', $co->get_errors());
}

public function test_invalid_visibility() {
$this->resetAfterTest(true);
$mode = tool_uploadcourse_processor::MODE_CREATE_NEW;
$updatemode = tool_uploadcourse_processor::UPDATE_NOTHING;
$data = array('shortname' => 'test', 'fullname' => 'New course', 'summary' => 'New', 'category' => 1, 'visible' => 2);
$co = new tool_uploadcourse_course($mode, $updatemode, $data);
$this->assertFalse($co->prepare());
$this->assertArrayHasKey('invalidvisibilitymode', $co->get_errors());
}

public function test_create() {
global $DB;
$this->resetAfterTest(true);
Expand Down

0 comments on commit 6c4fda0

Please sign in to comment.