diff --git a/admin/tool/filetypes/edit_form.php b/admin/tool/filetypes/edit_form.php index 5d16177212f..f2c60aa1260 100644 --- a/admin/tool/filetypes/edit_form.php +++ b/admin/tool/filetypes/edit_form.php @@ -94,6 +94,29 @@ class tool_filetypes_form extends moodleform { parent::set_data($data); } + public function get_data() { + $data = parent::get_data(); + + // Update the data to handle the descriptiontype dropdown. (The type + // is not explicitly stored, we just set or unset relevant fields.) + if ($data) { + switch ($data->descriptiontype) { + case 'lang' : + unset($data->description); + break; + case 'custom' : + unset($data->corestring); + break; + default: + unset($data->description); + unset($data->corestring); + break; + } + unset($data->descriptiontype); + } + return $data; + } + public function validation($data, $files) { $errors = parent::validation($data, $files); @@ -110,6 +133,20 @@ class tool_filetypes_form extends moodleform { $errors['defaulticon'] = get_string('error_defaulticon', 'tool_filetypes', $extension); } + // If you choose 'lang' or 'custom' descriptiontype, you must fill something in the field. + switch ($data['descriptiontype']) { + case 'lang' : + if (!trim($data['corestring'])) { + $errors['corestring'] = get_string('required'); + } + break; + case 'custom' : + if (!trim($data['description'])) { + $errors['description'] = get_string('required'); + } + break; + } + return $errors; } } diff --git a/admin/tool/filetypes/tests/behat/add_filetypes.feature b/admin/tool/filetypes/tests/behat/add_filetypes.feature index c36e434fd7c..ca52f01d2fb 100644 --- a/admin/tool/filetypes/tests/behat/add_filetypes.feature +++ b/admin/tool/filetypes/tests/behat/add_filetypes.feature @@ -36,6 +36,35 @@ Feature: Add customised file types And I press "Save changes" And I should see "frog" in the "application/x-7z-compressed" "table_row" + Scenario: Change the text option (was buggy) + Given I log in as "admin" + And I navigate to "File types" node in "Site administration > Server" + When I click on "Edit 7z" "link" + And I set the following fields to these values: + | Description type | Custom description specified in this form | + | Custom description | New description for 7z | + And I press "Save changes" + Then I should see "New description" in the "application/x-7z-compressed" "table_row" + And I click on "Edit 7z" "link" + And I set the field "Description type" to "Default" + And I press "Save changes" + And I should not see "New description" in the "application/x-7z-compressed" "table_row" + + Scenario: Try to select a text option without entering a value. + Given I log in as "admin" + And I navigate to "File types" node in "Site administration > Server" + When I click on "Edit dmg" "link" + And I set the field "Description type" to "Custom description" + And I press "Save changes" + Then I should see "Required" + And I set the field "Description type" to "Alternative language string" + And I press "Save changes" + And I should see "Required" + And I set the field "Description type" to "Default" + And I press "Save changes" + # Check we're back on the main page now. + And "dmg" "table_row" should exist + Scenario: Delete an existing file type Given I log in as "admin" And I navigate to "File types" node in "Site administration > Server"