mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 08:56:36 +02:00
MDL-48945 tool_filetypes: Added verification to description setting.
This commit is contained in:
parent
da0ef2e4cf
commit
a79970a295
2 changed files with 66 additions and 0 deletions
|
@ -94,6 +94,29 @@ class tool_filetypes_form extends moodleform {
|
||||||
parent::set_data($data);
|
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) {
|
public function validation($data, $files) {
|
||||||
$errors = parent::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);
|
$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;
|
return $errors;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,35 @@ Feature: Add customised file types
|
||||||
And I press "Save changes"
|
And I press "Save changes"
|
||||||
And I should see "frog" in the "application/x-7z-compressed" "table_row"
|
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
|
Scenario: Delete an existing file type
|
||||||
Given I log in as "admin"
|
Given I log in as "admin"
|
||||||
And I navigate to "File types" node in "Site administration > Server"
|
And I navigate to "File types" node in "Site administration > Server"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue