Skip to content

Commit

Permalink
MDL-48945 tool_filetypes: Added verification to description setting.
Browse files Browse the repository at this point in the history
  • Loading branch information
sammarshallou committed Jan 29, 2015
1 parent da0ef2e commit a79970a
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
37 changes: 37 additions & 0 deletions admin/tool/filetypes/edit_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,29 @@ public function 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) {
$errors = parent::validation($data, $files);

Expand All @@ -110,6 +133,20 @@ public function validation($data, $files) {
$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;
}
}
29 changes: 29 additions & 0 deletions admin/tool/filetypes/tests/behat/add_filetypes.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit a79970a

Please sign in to comment.