diff --git a/edit_coderunner_form.php b/edit_coderunner_form.php index 50f04f940..ccbdc5458 100644 --- a/edit_coderunner_form.php +++ b/edit_coderunner_form.php @@ -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'); } diff --git a/lang/en/qtype_coderunner.php b/lang/en/qtype_coderunner.php index 6fc357286..c68ddb499 100644 --- a/lang/en/qtype_coderunner.php +++ b/lang/en/qtype_coderunner.php @@ -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'; diff --git a/tests/behat/make_prototype.feature b/tests/behat/make_prototype.feature index c083b6d57..b1b1617f9 100644 --- a/tests/behat/make_prototype.feature +++ b/tests/behat/make_prototype.feature @@ -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"