diff --git a/mod/workshop/exsubmission.php b/mod/workshop/exsubmission.php index f95843b36a9..1f7ebd40ba3 100644 --- a/mod/workshop/exsubmission.php +++ b/mod/workshop/exsubmission.php @@ -154,11 +154,13 @@ if ($edit and $canmanage) { throw new moodle_exception('err_examplesubmissionid', 'workshop'); } } - // save and relink embedded images and save attachments - $formdata = file_postupdate_standard_editor($formdata, 'content', $contentopts, $workshop->context, - 'mod_workshop', 'submission_content', $example->id); - $formdata = file_postupdate_standard_filemanager($formdata, 'attachment', $attachmentopts, $workshop->context, - 'mod_workshop', 'submission_attachment', $example->id); + + // Save and relink embedded images and save attachments. + $formdata = file_postupdate_standard_editor($formdata, 'content', $workshop->submission_content_options(), + $workshop->context, 'mod_workshop', 'submission_content', $example->id); + $formdata = file_postupdate_standard_filemanager($formdata, 'attachment', $workshop->submission_attachment_options(), + $workshop->context, 'mod_workshop', 'submission_attachment', $example->id); + if (empty($formdata->attachment)) { // explicit cast to zero integer $formdata->attachment = 0; diff --git a/mod/workshop/locallib.php b/mod/workshop/locallib.php index b26d56ac3f4..d074add47f8 100644 --- a/mod/workshop/locallib.php +++ b/mod/workshop/locallib.php @@ -2486,6 +2486,9 @@ class workshop { * @return array */ public function submission_content_options() { + global $CFG; + require_once($CFG->dirroot.'/repository/lib.php'); + return array( 'trusttext' => true, 'subdirs' => false, @@ -2502,6 +2505,8 @@ class workshop { * @return array */ public function submission_attachment_options() { + global $CFG; + require_once($CFG->dirroot.'/repository/lib.php'); $options = array( 'subdirs' => true, @@ -2523,12 +2528,16 @@ class workshop { * @return array */ public function overall_feedback_content_options() { + global $CFG; + require_once($CFG->dirroot.'/repository/lib.php'); + return array( 'subdirs' => 0, 'maxbytes' => $this->overallfeedbackmaxbytes, 'maxfiles' => $this->overallfeedbackfiles, 'changeformat' => 1, 'context' => $this->context, + 'return_types' => FILE_INTERNAL, ); } @@ -2538,6 +2547,8 @@ class workshop { * @return array */ public function overall_feedback_attachment_options() { + global $CFG; + require_once($CFG->dirroot.'/repository/lib.php'); $options = array( 'subdirs' => 1, diff --git a/mod/workshop/submission.php b/mod/workshop/submission.php index 3d7e1fb42e9..6fc9724465f 100644 --- a/mod/workshop/submission.php +++ b/mod/workshop/submission.php @@ -25,7 +25,6 @@ require(__DIR__.'/../../config.php'); require_once(__DIR__.'/locallib.php'); -require_once($CFG->dirroot . '/repository/lib.php'); $cmid = required_param('cmid', PARAM_INT); // Course module id. $id = optional_param('id', 0, PARAM_INT); // Submission id. diff --git a/mod/workshop/tests/behat/example_submission.feature b/mod/workshop/tests/behat/example_submission.feature new file mode 100644 index 00000000000..52bc6414504 --- /dev/null +++ b/mod/workshop/tests/behat/example_submission.feature @@ -0,0 +1,39 @@ +@mod @mod_workshop @_file_upload +Feature: Provide example submission + In order to let students practise the assessment process in the workshop + As a teacher + I need to be able to define example submission and its referential assessment + + @javascript + Scenario: Add example submission with attachments to a workshop + # Prepare the users, course, enrolments and the workshop instance. + Given the following "users" exist: + | username | firstname | lastname | email | + | teacher1 | Terry1 | Teacher1 | teacher1@example.com | + And the following "courses" exist: + | fullname | shortname | + | Course1 | c1 | + And the following "course enrolments" exist: + | user | course | role | + | teacher1 | c1 | editingteacher | + And the following "activities" exist: + | activity | name | intro | course | idnumber | useexamples | + | workshop | TestWorkshop | Test workshop description | c1 | workshop1 | 1 | + # As a teacher, define the assessment form to be used in the workshop. + When I log in as "teacher1" + And I follow "Course1" + And I edit assessment form in workshop "TestWorkshop" as:" + | id_description__idx_0_editor | Aspect1 | + | id_description__idx_1_editor | Aspect2 | + | id_description__idx_2_editor | | + # Add an example submission with an attachment. + And I press "Add example submission" + And I set the following fields to these values: + | Title | First example submission | + | Submission content | Just an example but hey, it works! | + | Attachment | lib/tests/fixtures/empty.txt | + And I press "Save changes" + # Make sure that the submission was saved. + Then I should see "First example submission" + And I should see "Just an example but hey, it works!" + And "empty.txt" "link" should exist