Skip to content

Commit 7ac2fe4

Browse files
laurentdavidsrobotta
authored andcommitted
Add file question type
1 parent 3e23090 commit 7ac2fe4

File tree

2 files changed

+61
-30
lines changed

2 files changed

+61
-30
lines changed

classes/question/file.php

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -95,16 +95,11 @@ protected function question_survey_display($response, $descendantsdata, $blankqu
9595
// Filemanager form element implementation is far from optimal, we need to rework this if we ever fix it...
9696
require_once("$CFG->dirroot/lib/form/filemanager.php");
9797

98-
$fmoptions = array_merge(
99-
$options,
100-
[
101-
'client_id' => uniqid(),
102-
'itemid' => $draftitemid,
103-
'target' => $this->id,
104-
'name' => $elname
105-
]
106-
);
107-
$fm = new form_filemanager((object) $fmoptions);
98+
$options->client_id = uniqid();
99+
$options->itemid = $draftitemid;
100+
$options->target = $this->id;
101+
$options->name = $elname;
102+
$fm = new form_filemanager($options);
108103
$output = $PAGE->get_renderer('core', 'files');
109104

110105
$html = '<div class="form-filemanager" data-fieldtype="filemanager">' .
@@ -146,12 +141,12 @@ public function response_complete($responsedata) {
146141
* @return array
147142
*/
148143
public static function get_file_manager_option() {
149-
return [
150-
'mainfile' => '',
151-
'subdirs' => false,
152-
'accepted_types' => array('image', '.pdf'),
153-
'maxfiles' => 1,
154-
];
144+
$options = new \stdClass();
145+
$options->mainfile = '';
146+
$options->subdirs = false;
147+
$options->accepted_types = ['image', '.pdf'];
148+
$options->maxfiles = 1;
149+
return $options;
155150
}
156151

157152
/**

tests/behat/file_question.feature

Lines changed: 50 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,41 @@
11
@mod @mod_questionnaire
2-
Feature: In questionnaire, we can add a question requiring a file upload.
2+
Feature: Add a question requiring a file upload in questionnaire.
3+
In order to use this plugin
4+
As a teacher
5+
I need to add a a file question to a questionnaire created in my course
6+
and a student answers to it. Then the file has to be accessible.
37

48
Background:
59
Given the following "users" exist:
6-
| username | firstname | lastname | email |
7-
| teacher1 | Teacher | 1 | teacher1@example.com |
8-
| student1 | Student | 1 | student1@example.com |
10+
| username | firstname | lastname | email |
11+
| teacher1 | Teacher | 1 | teacher1@example.com |
12+
| student1 | Student | 1 | student1@example.com |
913
And the following "courses" exist:
1014
| fullname | shortname | category |
11-
| Course 1 | C1 | 0 |
15+
| Course 1 | C1 | 0 |
1216
And the following "course enrolments" exist:
13-
| user | course | role |
14-
| teacher1 | C1 | editingteacher |
15-
| student1 | C1 | student |
17+
| user | course | role |
18+
| teacher1 | C1 | editingteacher |
19+
| student1 | C1 | student |
1620
And the following "activities" exist:
17-
| activity | name | description | course | idnumber | resume | navigate |
18-
| questionnaire | Test questionnaire | Test questionnaire description | C1 | questionnaire0 | 1 | 1 |
21+
| activity | name | description | course | idnumber | resume | navigate |
22+
| questionnaire | Test questionnaire | Test questionnaire description | C1 | questionnaire0 | 1 | 1 |
1923

2024
@javascript @_file_upload
21-
Scenario: As a teacher, I create a questionnaire in my course with a file question and a student answers to it. Then the file has to be accessible.
25+
Scenario: Add a single file question to a questionnaire and view an answer with an uploaded file.
2226
Given I log in as "teacher1"
2327
When I am on the "Test questionnaire" "questionnaire activity" page
2428
And I navigate to "Questions" in current page administration
2529
And I should see "Add questions"
2630
And I add a "File" question and I fill the form with:
27-
| Question Name | File question |
28-
| Yes | Yes |
31+
| Question Name | File question |
32+
| Yes | Yes |
2933
| Question Text | Add a file as an answer |
3034
And I log out
3135
And I log in as "student1"
3236
And I am on the "Test questionnaire" "questionnaire activity" page
3337
And I navigate to "Answer the questions..." in current page administration
34-
And I upload "mod/questionnaire/tests/fixtures/testfilequestion.pdf" to questionnaire filemanager
38+
And I upload "mod/questionnaire/tests/fixtures/testfilequestion.pdf" to questionnaire "Add a file as an answer" filemanager
3539
And I press "Submit questionnaire"
3640
And I should see "Thank you for completing this Questionnaire"
3741
And I press "Continue"
@@ -42,3 +46,35 @@ Feature: In questionnaire, we can add a question requiring a file upload.
4246
And I am on the "Test questionnaire" "questionnaire activity" page
4347
And I navigate to "View all responses" in current page administration
4448
Then I should see "testfilequestion.pdf"
49+
50+
@javascript @_file_upload
51+
Scenario: Add two file questions to a questionnaire and view an answer with two uploaded file.
52+
Given I log in as "teacher1"
53+
When I am on the "Test questionnaire" "questionnaire activity" page
54+
And I navigate to "Questions" in current page administration
55+
And I should see "Add questions"
56+
And I add a "File" question and I fill the form with:
57+
| Question Name | File question one |
58+
| Yes | Yes |
59+
| Question Text | Add a first file as an answer |
60+
And I add a "File" question and I fill the form with:
61+
| Question Name | File question two |
62+
| Yes | Yes |
63+
| Question Text | Add a second file as an answer |
64+
And I log out
65+
And I log in as "student1"
66+
And I am on the "Test questionnaire" "questionnaire activity" page
67+
And I navigate to "Answer the questions..." in current page administration
68+
And I upload "mod/questionnaire/tests/fixtures/testfilequestion.pdf" to questionnaire "Add a first file as an answer" filemanager
69+
And I upload "mod/questionnaire/tests/fixtures/testfilequestion2.pdf" to questionnaire "Add a second file as an answer" filemanager
70+
And I press "Submit questionnaire"
71+
And I should see "Thank you for completing this Questionnaire"
72+
And I press "Continue"
73+
And I should see "View your response(s)"
74+
And ".resourcecontent.resourcepdf" "css_element" should exist
75+
And I log out
76+
And I log in as "teacher1"
77+
And I am on the "Test questionnaire" "questionnaire activity" page
78+
And I navigate to "View all responses" in current page administration
79+
Then I should see "testfilequestion.pdf"
80+
And I should see "testfilequestion2.pdf"

0 commit comments

Comments
 (0)