diff --git a/tests/behat/file_type_restriction.feature b/tests/behat/file_type_restriction.feature deleted file mode 100755 index 35b6b6e..0000000 --- a/tests/behat/file_type_restriction.feature +++ /dev/null @@ -1,75 +0,0 @@ -@qtype @qtype_aitext -Feature: In a aitext question, limit submittable file types - In order to constrain student submissions for marking - As a teacher - I need to limit the submittable file types - - Background: - Given the following "users" exist: - | username | - | teacher | - | student | - And the following "courses" exist: - | fullname | shortname | category | - | Course 1 | C1 | 0 | - And the following "course enrolments" exist: - | user | course | role | - | teacher | C1 | editingteacher | - | student | C1 | student | - And the following "question categories" exist: - | contextlevel | reference | name | - | Course | C1 | Test questions | - And the following "questions" exist: - | questioncategory | qtype | name | questiontext | defaultmark | - | Test questions | aitext | TF1 | First question | 20 | - And the following "activities" exist: - | activity | name | intro | course | idnumber | grade | - | quiz | Quiz 1 | Quiz 1 description | C1 | quiz1 | 20 | - And quiz "Quiz 1" contains the following questions: - | question | page | - | TF1 | 1 | - And the following "blocks" exist: - | blockname | contextlevel | reference | pagetypepattern | defaultregion | - | private_files | System | 1 | my-index | side-post | - Given I am on the "Quiz 1" "mod_quiz > edit" page logged in as teacher - And I click on "Edit question TF1" "link" - And I set the field "Allow attachments" to "1" - And I set the field "Response format" to "No online text" - And I set the field "Require attachments" to "1" - And I set the field "filetypeslist[filetypes]" to ".txt" - And I press "Save changes" - And I am on the "Quiz 1" "mod_quiz > edit" page - And I set the field "version" to "Always latest" - Then I log out - - @javascript @_file_upload - Scenario: Preview an aitext question and submit a response with a correct filetype. - When I log in as "student" - And I follow "Manage private files" - And I upload "lib/tests/fixtures/empty.txt" file to "Files" filemanager - And I press "Save changes" - And I am on the "Quiz 1" "quiz activity" page - And I press "Attempt quiz" - And I should see "First question" - And I should see "You can drag and drop files here to add them." - And I click on "Add..." "button" - And I click on "Private files" "link" in the ".fp-repo-area" "css_element" - And I click on "empty.txt" "link" - And I click on "Select this file" "button" - # Wait for the page to "settle". - And I wait until the page is ready - Then I should not see "These file types are not allowed here:" - - @javascript @_file_upload - Scenario: Preview an aitext question and try to submit a response with an incorrect filetype. - When I log in as "student" - And I follow "Manage private files" - And I upload "lib/tests/fixtures/upload_users.csv" file to "Files" filemanager - And I press "Save changes" - And I am on the "Quiz 1" "quiz activity" page - And I press "Attempt quiz" - And I should see "First question" - And I should see "You can drag and drop files here to add them." - And I click on "Add..." "button" - And I click on "Private files" "link" in the ".fp-repo-area" "css_element" - Then I should see "No files available" diff --git a/tests/behat/max_file_size.feature b/tests/behat/max_file_size.feature deleted file mode 100755 index f2620bf..0000000 --- a/tests/behat/max_file_size.feature +++ /dev/null @@ -1,35 +0,0 @@ -@qtype @qtype_aitext -Feature: In an aitext question, let the question author choose the maxbytes for attachments - In order to constrain student submissions for marking - As a teacher - I need to choose the appropriate maxbytes for attachments - - Background: - Given the following "users" exist: - | username | - | teacher | - And the following "courses" exist: - | fullname | shortname | category | maxbytes | - | Course 1 | C1 | 0 | 1048576 | - And the following "course enrolments" exist: - | user | course | role | - | teacher | C1 | editingteacher | - And the following "question categories" exist: - | contextlevel | reference | name | - | Course | C1 | Test questions | - And the following "questions" exist: - | questioncategory | qtype | name | template | attachments | maxbytes | - | Test questions | aitext | aitext-1-512KB | editor | 1 | 524288 | - | Test questions | aitext | aitext-1-max | editor | 1 | 0 | - - @javascript @_switch_window - Scenario: Preview an aitext question and see the allowed maximum file sizes and number of attachments. - When I am on the "aitext-1-512KB" "core_question > preview" page logged in as teacher - Then I should see "Please write a story about a frog." - And I should see "Maximum file size: 512 KB, maximum number of files: 1" - - @javascript @_switch_window - Scenario: Preview an aitext question with Course upload limit and see the allowed maximum file size. - When I am on the "aitext-1-max" "core_question > preview" page logged in as teacher - Then I should see "Please write a story about a frog." - And I should see "Maximum file size: 1 MB, maximum number of files: 1" diff --git a/tests/fixtures/testquestion.moodle.xml b/tests/fixtures/testquestion.moodle.xml index ee6968e..8b39bb4 100755 --- a/tests/fixtures/testquestion.moodle.xml +++ b/tests/fixtures/testquestion.moodle.xml @@ -13,7 +13,7 @@ aitext-001 - Write an essay with 500 words. + Write an aitext with 500 words. This is general feedback diff --git a/tests/helper.php b/tests/helper.php index d734714..83307fd 100755 --- a/tests/helper.php +++ b/tests/helper.php @@ -30,7 +30,7 @@ */ class qtype_aitext_test_helper extends question_test_helper { public function get_test_questions() { - return array('editor', 'editorfilepicker', 'plain', 'monospaced', 'responsetemplate', 'noinline'); + return array('editor', 'plain', 'monospaced', 'responsetemplate', 'noinline'); } public static function make_aitext_question(array $options) { $optionsparam = [ @@ -63,10 +63,6 @@ protected function initialise_aitext_question() { $q->responsefieldlines = 10; $q->minwordlimit = null; $q->maxwordlimit = null; - $q->attachments = 0; - $q->attachmentsrequired = 0; - $q->maxbytes = 0; - $q->filetypeslist = null; $q->graderinfo = ''; $q->graderinfoformat = FORMAT_HTML; $q->qtype = question_bank::get_qtype('aitext'); @@ -101,9 +97,6 @@ public function get_aitext_question_form_data_editor() { $fromform->responserequired = 1; $fromform->responsefieldlines = 10; $fromform->attachments = 0; - $fromform->attachmentsrequired = 0; - $fromform->maxbytes = 0; - $fromform->filetypeslist = ''; // Although once saved in the DB, this becomes null, the form returns '' here. $fromform->graderinfo = array('text' => '', 'format' => FORMAT_HTML); $fromform->responsetemplate = array('text' => '', 'format' => FORMAT_HTML); $fromform->status = \core_question\local\bank\question_version_status::QUESTION_STATUS_READY; @@ -112,60 +105,6 @@ public function get_aitext_question_form_data_editor() { return $fromform; } - /** - * Makes an aitext question using the HTML editor allowing embedded files as - * input, and up to three attachments. - * @return qtype_aitext_question - */ - public function make_aitext_question_editorfilepicker() { - $q = $this->initialise_aitext_question(); - $q->responseformat = 'editorfilepicker'; - $q->attachments = 3; - return $q; - } - - /** - * Makes an aitext question using the HTML editor allowing embedded files as - * input, and up to two attachments, two needed. - * @return qtype_aitext_question - */ - public function make_aitext_question_editorfilepickertworequired() { - $q = $this->initialise_aitext_question(); - $q->responseformat = 'editorfilepicker'; - $q->attachments = 2; - $q->attachmentsrequired = 2; - return $q; - } - - /** - * Make the data what would be received from the editing form for an aitext - * question using the HTML editor allowing embedded files as input, and up - * to three attachments. - * - * @return stdClass the data that would be returned by $form->get_gata(); - */ - public function get_aitext_question_form_data_editorfilepicker() { - $fromform = new stdClass(); - - $fromform->name = 'aitext question with filepicker and attachments'; - $fromform->questiontext = array('text' => 'Please write a story about a frog.', 'format' => FORMAT_HTML); - $fromform->defaultmark = 1.0; - $fromform->generalfeedback = array('text' => 'I hope your story had a beginning, a middle and an end.', - 'format' => FORMAT_HTML); - $fromform->responseformat = 'editorfilepicker'; - $fromform->responserequired = 1; - $fromform->responsefieldlines = 10; - $fromform->attachments = 3; - $fromform->attachmentsrequired = 0; - $fromform->maxbytes = 0; - $fromform->filetypeslist = ''; // Although once saved in the DB, this becomes null, the form returns '' here. - $fromform->graderinfo = array('text' => '', 'format' => FORMAT_HTML); - $fromform->responsetemplate = array('text' => '', 'format' => FORMAT_HTML); - $fromform->status = \core_question\local\bank\question_version_status::QUESTION_STATUS_READY; - - return $fromform; - } - /** * Makes an aitext question using plain text input. * @return qtype_aitext_question @@ -194,10 +133,9 @@ public function get_aitext_question_form_data_plain() { $fromform->responseformat = 'plain'; $fromform->responserequired = 1; $fromform->responsefieldlines = 10; - $fromform->attachments = 0; - $fromform->attachmentsrequired = 0; + $fromform->aiprompt = 'Evaluate this'; + $fromform->markscheme = 'One mark if correct'; $fromform->maxbytes = 0; - $fromform->filetypeslist = ''; // Although once saved in the DB, this becomes null, the form returns '' here. $fromform->graderinfo = array('text' => '', 'format' => FORMAT_HTML); $fromform->responsetemplate = array('text' => '', 'format' => FORMAT_HTML); $fromform->status = \core_question\local\bank\question_version_status::QUESTION_STATUS_READY; @@ -229,81 +167,7 @@ public function make_aitext_question_responsetemplate() { public function make_aitext_question_noinline() { $q = $this->initialise_aitext_question(); $q->responseformat = 'noinline'; - $q->attachments = 3; - $q->attachmentsrequired = 1; - $q->filetypeslist = ''; - $q->maxbytes = 0; return $q; } - /** - * Creates an empty draft area for attachments. - * @return int The draft area's itemid. - */ - protected function make_attachment_draft_area() { - $draftid = 0; - $contextid = 0; - - $component = 'question'; - $filearea = 'response_attachments'; - - // Create an empty file area. - file_prepare_draft_area($draftid, $contextid, $component, $filearea, null); - return $draftid; - } - - /** - * Creates an attachment in the provided attachment draft area. - * @param int $draftid The itemid for the draft area in which the file should be created. - * @param string $name The filename for the file to be created. - * @param string $contents The contents of the file to be created. - */ - protected function make_attachment($draftid, $name, $contents) { - global $USER; - - $fs = get_file_storage(); - $usercontext = context_user::instance($USER->id); - - // Create the file in the provided draft area. - $fileinfo = array( - 'contextid' => $usercontext->id, - 'component' => 'user', - 'filearea' => 'draft', - 'itemid' => $draftid, - 'filepath' => '/', - 'filename' => $name, - ); - $fs->create_file_from_string($fileinfo, $contents); - } - - /** - * Generates a draft file area that contains the provided number of attachments. You should ensure - * that a user is logged in with setUser before you run this function. - * - * @param int $attachments The number of attachments to generate. - * @return int The itemid of the generated draft file area. - */ - public function make_attachments($attachments) { - $draftid = $this->make_attachment_draft_area(); - - // Create the relevant amount of dummy attachments in the given draft area. - for ($i = 0; $i < $attachments; ++$i) { - $this->make_attachment($draftid, $i, $i); - } - - return $draftid; - } - - /** - * Generates a question_file_saver that contains the provided number of attachments. You should ensure - * that a user is logged in with setUser before you run this function. - * - * @param int $:attachments The number of attachments to generate. - * @return question_file_saver a question_file_saver that contains the given amount of dummy files, for use in testing. - */ - public function make_attachments_saver($attachments) { - return new question_file_saver($this->make_attachments($attachments), 'question', 'response_attachments'); - } - - }