Skip to content

Commit

Permalink
Add validation: Sandbox lang cannot be empty when creating a prototype (
Browse files Browse the repository at this point in the history
  • Loading branch information
AnupamaSarjoshi authored Feb 11, 2024
1 parent 1b024b0 commit 22ba2ab
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions edit_coderunner_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,11 @@ public function validation($data, $files) {
$errors = array_merge($errors, $testcaseerrors);
}

if ($data['prototypetype'] == 2 && empty($data['language'])) {
// Language cannot be empty when it is a prototype template.
$errors['languages'] = get_string('emptysandboxlanguage', 'qtype_coderunner');
}

if ($data['iscombinatortemplate'] && empty($data['testsplitterre'])) {
$errors['templatecontrols'] = get_string('bad_empty_splitter', 'qtype_coderunner');
}
Expand Down
1 change: 1 addition & 0 deletions lang/en/qtype_coderunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@
$string['editingcoderunner'] = 'Editing a CodeRunner Question';
$string['empty_new_prototype_name'] = 'New question type name cannot be empty';
$string['emptypenaltyregime'] = 'Penalty regime must be defined (since version 3.1)';
$string['emptysandboxlanguage'] = 'Sandbox language cannot be empty when creating a prototype.';
$string['enable'] = 'Enable';
$string['enablecombinator'] = 'Enable combinator';
$string['enable_diff_check'] = 'Enable \'Show differences\' button';
Expand Down
10 changes: 10 additions & 0 deletions tests/behat/make_prototype.feature
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,13 @@ Feature: make_prototype
And I set the field "prototypetype" to "No"
And I set the field "id_coderunnertype" to "python3" and dismiss the alert
Then I should not see "This is a prototype; cannot change question type"

Scenario: As a teacher, when I try to create the prototype with empty Sandbox language I should see the validation error
Given I am on the "PROTOTYPE_test_prototype" "core_question > edit" page logged in as teacher1
And I click on "a[aria-controls='id_advancedcustomisationheadercontainer']" "css_element"
When I set the field "language" to ""
And I press "id_submitbutton"
Then I should see "Sandbox language cannot be empty when creating a prototype."
And I set the field "language" to "python3"
And I press "id_submitbutton"
And I should see "Question bank"

0 comments on commit 22ba2ab

Please sign in to comment.