MDL-55289 workshop: Fix files processing in example submissions
authorDavid Mudrák <david@moodle.com>
Mon, 25 Jul 2016 17:40:26 +0000 (19:40 +0200)
committerDavid Mudrák <david@moodle.com>
Thu, 28 Jul 2016 07:51:16 +0000 (09:51 +0200)
While testing the issue MDL-55289 I realized that attaching files to
workshop example submissions does not work at all and throws an error.

The reason was that in MDL-50794 (996f7e82), the variables $contentopts
and $attachmentopts were replaced with the result of the methods
submission_content_options() and submission_attachment_options().
But I forgot to perform the full refactoring in exsubmission.php too.

Attached behat test should cover both issues on this branch.

mod/workshop/exsubmission.php
mod/workshop/tests/behat/example_submission.feature [new file with mode: 0644]

index f95843b..1f7ebd4 100644 (file)
@@ -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/tests/behat/example_submission.feature b/mod/workshop/tests/behat/example_submission.feature
new file mode 100644 (file)
index 0000000..52bc641
--- /dev/null
@@ -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