From 8f0d40a39c5df321a61159dc5dfd436a88e4c95f Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Mon, 16 Nov 2020 15:20:34 +0100 Subject: [PATCH 1/2] MDL-70153 qtype_essay: Fix max size displayed for attachments --- question/type/essay/renderer.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/question/type/essay/renderer.php b/question/type/essay/renderer.php index a0cb56969eb..da1303552c7 100644 --- a/question/type/essay/renderer.php +++ b/question/type/essay/renderer.php @@ -106,7 +106,7 @@ class qtype_essay_renderer extends qtype_renderer { */ public function files_input(question_attempt $qa, $numallowed, question_display_options $options) { - global $CFG; + global $CFG, $COURSE; require_once($CFG->dirroot . '/lib/form/filemanager.php'); $pickeroptions = new stdClass(); @@ -122,7 +122,8 @@ class qtype_essay_renderer extends qtype_renderer { $pickeroptions->accepted_types = $qa->get_question()->filetypeslist; $fm = new form_filemanager($pickeroptions); - $fm->options->maxbytes = $qa->get_question()->maxbytes;; + $fm->options->maxbytes = get_user_max_upload_file_size( + $this->page->context, $CFG->maxbytes, $COURSE->maxbytes, $qa->get_question()->maxbytes); $filesrenderer = $this->page->get_renderer('core', 'files'); $text = ''; From b76093e90c711bb7f4f94794f6c3b1546cbd44d5 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Tue, 17 Nov 2020 10:31:32 +0100 Subject: [PATCH 2/2] MDL-70153 qtype_essay: Add behat test for attachments max size --- .../essay/tests/behat/max_file_size.feature | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/question/type/essay/tests/behat/max_file_size.feature b/question/type/essay/tests/behat/max_file_size.feature index 943bae11195..0ac3052fc9a 100644 --- a/question/type/essay/tests/behat/max_file_size.feature +++ b/question/type/essay/tests/behat/max_file_size.feature @@ -8,8 +8,8 @@ I need to choose the appropriate maxbytes for attachments | username | firstname | lastname | email | | teacher1 | T1 | Teacher1 | teacher1@moodle.com | And the following "courses" exist: - | fullname | shortname | category | - | Course 1 | C1 | 0 | + | fullname | shortname | category | maxbytes | + | Course 1 | C1 | 0 | 1048576 | And the following "course enrolments" exist: | user | course | role | | teacher1 | C1 | editingteacher | @@ -18,15 +18,24 @@ I need to choose the appropriate maxbytes for attachments | Course | C1 | Test questions | And the following "questions" exist: | questioncategory | qtype | name | template | attachments | maxbytes | - | Test questions | essay | essay-1-20MB | editor | 1 | 20971520 | + | Test questions | essay | essay-1-512KB | editor | 1 | 524288 | + | Test questions | essay | essay-1-max | editor | 1 | 0 | Given I log in as "teacher1" And I am on "Course 1" course homepage And I navigate to "Question bank" in current page administration @javascript @_switch_window Scenario: Preview an Essay question and see the allowed maximum file sizes and number of attachments. - When I choose "Preview" action for "essay-1-20MB" in the question bank + When I choose "Preview" action for "essay-1-512KB" in the question bank And I switch to "questionpreview" window And I should see "Please write a story about a frog." - And I should see "Maximum file size: 20MB, maximum number of files: 1" + And I should see "Maximum file size: 512KB, maximum number of files: 1" + And I switch to the main window + + @javascript @_switch_window + Scenario: Preview an Essay question with Course upload limit and see the allowed maximum file size. + When I choose "Preview" action for "essay-1-max" in the question bank + And I switch to "questionpreview" window + And I should see "Please write a story about a frog." + And I should see "Maximum file size: 1MB, maximum number of files: 1" And I switch to the main window