From d5b573987649fa18609a67882f9db60347840516 Mon Sep 17 00:00:00 2001 From: eWallah Date: Sun, 28 Oct 2018 20:38:05 +0100 Subject: [PATCH] fix phpunit - behat --- questiontype.php | 19 ++++--- tests/behat/add.feature | 40 ++++++++++----- tests/behat/backup_and_restore.feature | 31 +++++++----- tests/behat/edit.feature | 34 ++++++++----- tests/behat/export.feature | 25 +++++----- tests/behat/import.feature | 4 +- tests/behat/preview.feature | 24 ++++----- tests/helper.php | 68 ++++++++++++++++++++++---- tests/question_test.php | 12 ++--- tests/walkthrough_test.php | 45 +++++++---------- 10 files changed, 188 insertions(+), 114 deletions(-) diff --git a/questiontype.php b/questiontype.php index d80322e..7c87cc1 100644 --- a/questiontype.php +++ b/questiontype.php @@ -120,16 +120,16 @@ public function save_question_options($formdata) { 'graderinfoformat' => $formdata->graderinfo['format'], 'responsetemplate' => $formdata->responsetemplate['text'], 'responsetemplateformat' => $formdata->responsetemplate['format'], - 'enableautograde' => $formdata->enableautograde, - 'itemtype' => $formdata->itemtype, - 'itemcount' => $formdata->itemcount, - 'showfeedback' => $formdata->showfeedback, - 'showcalculation' => $formdata->showcalculation, - 'showtextstats' => $formdata->showtextstats, + 'enableautograde' => isset($formdata->enableautograde) ? $formdata->enableautograde : 1, + 'itemtype' => isset($formdata->itemtype) ? $formdata->itemtype : self::ITEM_TYPE_CHARS, + 'itemcount' => isset($formdata->itemcount) ? $formdata->itemcount : 1, + 'showfeedback' => isset($formdata->showfeedback) ? $formdata->showfeedback : 1, + 'showcalculation' => isset($formdata->showcalculation) ? $formdata->showcalculation : 1, + 'showtextstats' => isset($formdata->showtextstats) ? $formdata->showtextstats : 1, 'textstatitems' => $textstatitems, - 'showgradebands' => $formdata->showgradebands, - 'addpartialgrades' => $formdata->addpartialgrades, - 'showtargetphrases' => $formdata->showtargetphrases + 'showgradebands' => isset($formdata->showgradebands) ? $formdata->showgradebands : 1, + 'addpartialgrades' => isset($formdata->addpartialgrades) ? $formdata->addpartialgrades : 1, + 'showtargetphrases' => isset($formdata->showtargetphrases) ? $formdata->showtargetphrases : 1, ); // add options for feedback fields @@ -482,7 +482,6 @@ public function export_to_xml($question, qformat_xml $format, $extra=null) { $output .= " <$tag percent=\"$percent\">$text\n";; } $output .= " \n"; - return $output; } diff --git a/tests/behat/add.feature b/tests/behat/add.feature index c6f1f61..77a1479 100644 --- a/tests/behat/add.feature +++ b/tests/behat/add.feature @@ -1,8 +1,8 @@ @qtype @qtype_essayautograde -Feature: Test creating an Essay question +Feature: Test creating an Essay autograde question As a teacher In order to test my students - I need to be able to create an Essay question + I need to be able to create an Essay autograde question Background: Given the following "users" exist: @@ -15,21 +15,37 @@ Feature: Test creating an Essay question | user | course | role | | teacher1 | C1 | editingteacher | And I log in as "teacher1" - And I follow "Course 1" - And I navigate to "Question bank" node in "Course administration" + And I am on "Course 1" course homepage + And I navigate to "Question bank" in current page administration - Scenario: Create an Essay question with Response format set to 'HTML editor' - When I add a "Essay" question filling the form with: + Scenario: Create an Essay autograde question with Response format set to 'HTML editor' + When I add a "Essay (auto-grade)" question filling the form with: | Question name | essayautograde-001 | | Question text | Write an essayautograde with 500 words. | - | General feedback | This is general feedback | - | Response format | HTML editor | + | General feedback | This is general feedback | + | Response format | HTML editor | Then I should see "essayautograde-001" - Scenario: Create an Essay question with Response format set to 'HTML editor with the file picker' - When I add a "Essay" question filling the form with: + Scenario: Create an Essay autograde question with Response format set to 'HTML editor with file picker' + When I add a "Essay (auto-grade)" question filling the form with: | Question name | essayautograde-002 | | Question text | Write an essayautograde with 500 words. | - | General feedback | This is general feedback | - | Response format | HTML editor | + | General feedback | This is general feedback | + | Response format | HTML editor with file picker | Then I should see "essayautograde-002" + + Scenario: Create an Essay autograde question with Response format set to 'plain' + When I add a "Essay (auto-grade)" question filling the form with: + | Question name | essayautograde-003 | + | Question text | Write an essayautograde with 500 words. | + | General feedback | This is general feedback | + | Response format | Plain | + Then I should see "essayautograde-003" + + Scenario: Create an Essay autograde question with Response format set to 'monospaced' + When I add a "Essay (auto-grade)" question filling the form with: + | Question name | essayautograde-004 | + | Question text | Write an essayautograde with 500 words. | + | General feedback | This is general feedback | + | Response format | Plain text, monospaced font | + Then I should see "essayautograde-004" diff --git a/tests/behat/backup_and_restore.feature b/tests/behat/backup_and_restore.feature index 264015c..66cbc18 100644 --- a/tests/behat/backup_and_restore.feature +++ b/tests/behat/backup_and_restore.feature @@ -1,39 +1,44 @@ @qtype @qtype_essayautograde -Feature: Test duplicating a quiz containing an Assay question - As a teacher - In order re-use my courses containing Essay questions +Feature: Test duplicating a quiz containing an Essay autograde question + As andmin + In order re-use my courses containing Essay autograde questions I need to be able to backup and restore them Background: + Given the following "users" exist: + | username | firstname | lastname | email | + | teacher1 | T1 | Teacher1 | teacher1@moodle.com | And the following "courses" exist: | fullname | shortname | category | | Course 1 | C1 | 0 | + And the following "course enrolments" exist: + | user | course | role | + | teacher1 | C1 | editingteacher | And the following "question categories" exist: | contextlevel | reference | name | | Course | C1 | Test questions | + And the following "activities" exist: + | activity | name | course | idnumber | + | quiz | Test quiz | C1 | quiz1 | And the following "questions" exist: - | questioncategory | qtype | name | template | + | questioncategory | qtype | name | template | | Test questions | essayautograde | essayautograde-001 | editor | | Test questions | essayautograde | essayautograde-002 | editorfilepicker | | Test questions | essayautograde | essayautograde-003 | plain | - And the following "activities" exist: - | activity | name | course | idnumber | - | quiz | Test quiz | C1 | quiz1 | And quiz "Test quiz" contains the following questions: | essayautograde-001 | 1 | | essayautograde-002 | 1 | | essayautograde-003 | 1 | - And I log in as "admin" - And I am on site homepage - And I follow "Course 1" @javascript - Scenario: Backup and restore a course containing 3 Essay questions - When I backup "Course 1" course using this options: + Scenario: Backup and restore a course containing 3 Essay autograde questions + Given I log in as "admin" + And I am on "Course 1" course homepage + And I backup "Course 1" course using this options: | Confirmation | Filename | test_backup.mbz | And I restore "test_backup.mbz" backup into a new course using this options: | Schema | Course name | Course 2 | - And I navigate to "Question bank" node in "Course administration" + And I navigate to "Question bank" in current page administration And I should see "essayautograde-001" And I should see "essayautograde-002" And I should see "essayautograde-003" diff --git a/tests/behat/edit.feature b/tests/behat/edit.feature index c0d23ef..6c8cd7e 100644 --- a/tests/behat/edit.feature +++ b/tests/behat/edit.feature @@ -1,7 +1,7 @@ @qtype @qtype_essayautograde -Feature: Test editing an Essay question +Feature: Test editing an Essay autograde question As a teacher - In order to be able to update my Essay question + In order to be able to update my Essay autograde question I need to edit them Background: @@ -17,16 +17,26 @@ Feature: Test editing an Essay question And the following "question categories" exist: | contextlevel | reference | name | | Course | C1 | Test questions | - And the following "questions" exist: - | questioncategory | qtype | name | template | - | Test questions | essayautograde | essayautograde-001 | editor | - | Test questions | essayautograde | essayautograde-002 | editorfilepicker | - | Test questions | essayautograde | essayautograde-003 | plain | And I log in as "teacher1" - And I follow "Course 1" - And I navigate to "Question bank" node in "Course administration" + And I am on "Course 1" course homepage + And I navigate to "Question bank" in current page administration + And I add a "Essay (auto-grade)" question filling the form with: + | Question name | essayautograde-001 | + | Question text | Please write a story about a frog. | + | General feedback | I hope your story had a beginning, a middle and an end. | + | Response format | HTML editor | + And I add a "Essay (auto-grade)" question filling the form with: + | Question name | essayautograde-002 | + | Question text | Please write a story about a frog. | + | General feedback | I hope your story had a beginning, a middle and an end. | + | Response format | HTML editor with file picker | + And I add a "Essay (auto-grade)" question filling the form with: + | Question name | essayautograde-003 | + | Question text | Please write a story about a frog. | + | General feedback | I hope your story had a beginning, a middle and an end. | + | Response format | Plain text | - Scenario: Edit an Essay question + Scenario: Edit an Essay autograde question When I click on "Edit" "link" in the "essayautograde-001" "table_row" And I set the following fields to these values: | Question name | | @@ -34,9 +44,9 @@ Feature: Test editing an Essay question Then I should see "You must supply a value here." When I set the following fields to these values: | Question name | Edited essayautograde-001 name | - | Response format | No inline text | + | Response format | No online text | And I press "id_submitbutton" - Then I should see "When \"no inline text\" is selected, or responses are optional, you must allow at least one attachment." + Then I should see "When \"No online text\" is selected, or responses are optional, you must allow at least one attachment." When I set the following fields to these values: | Response format | Plain text | And I press "id_submitbutton" diff --git a/tests/behat/export.feature b/tests/behat/export.feature index 38ed712..811ca12 100644 --- a/tests/behat/export.feature +++ b/tests/behat/export.feature @@ -1,7 +1,7 @@ @qtype @qtype_essayautograde -Feature: Test exporting Essay questions +Feature: Test exporting Essay autograde questions As a teacher - In order to be able to reuse my Essay questions + In order to be able to reuse my Essay autograde questions I need to export them Background: @@ -18,18 +18,19 @@ Feature: Test exporting Essay questions | contextlevel | reference | name | | Course | C1 | Test questions | And the following "questions" exist: - | questioncategory | qtype | name | template | - | Test questions | essayautograde | essayautograde-001 | editor | - | Test questions | essayautograde | essayautograde-002 | editorfilepicker | - | Test questions | essayautograde | essayautograde-003 | plain | - And I log in as "teacher1" - And I follow "Course 1" - - Scenario: Export 3 Essay questions - When I navigate to "Export" node in "Course administration > Question bank" + | questioncategory | qtype | name | template | + | Test questions | essayautograde | essayautograde-001 | editor | + | Test questions | essayautograde | essayautograde-002 | editorfilepicker | + | Test questions | essayautograde | essayautograde-003 | plain | + And I log in as "admin" + + Scenario: Export 3 Essay autograde questions + When I am on "Course 1" course homepage + And I navigate to "Question bank > Export" in current page administration And I set the field "id_format_xml" to "1" And I press "Export questions to file" - Then following "click here" should download between "2600" and "2700" bytes + Then I should see "Your export file should start to download shortly" + #TODO: And following "click here" should download between "2600" and "12700" bytes # If the download step is the last in the scenario then we can sometimes run # into the situation where the download page causes a http redirect but behat # has already conducted its reset (generating an error). By putting a logout diff --git a/tests/behat/import.feature b/tests/behat/import.feature index 9199b27..150febe 100644 --- a/tests/behat/import.feature +++ b/tests/behat/import.feature @@ -15,11 +15,11 @@ Feature: Test importing Essay questions | user | course | role | | teacher1 | C1 | editingteacher | And I log in as "teacher1" - And I follow "Course 1" + And I am on "Course 1" course homepage @javascript @_file_upload Scenario: import Essay question. - When I navigate to "Import" node in "Course administration > Question bank" + When I navigate to "Question bank > Import" in current page administration And I set the field "id_format_xml" to "1" And I upload "question/type/essayautograde/tests/fixtures/testquestion.moodle.xml" file to "Import" filemanager And I press "id_submitbutton" diff --git a/tests/behat/preview.feature b/tests/behat/preview.feature index 6b2945a..940849d 100644 --- a/tests/behat/preview.feature +++ b/tests/behat/preview.feature @@ -1,7 +1,7 @@ @qtype @qtype_essayautograde -Feature: Preview Essay questions +Feature: Preview Essay autograde questions As a teacher - In order to check my Essay questions will work for students + In order to check my Essay autograde questions will work for students I need to preview them Background: @@ -18,16 +18,16 @@ Feature: Preview Essay questions | contextlevel | reference | name | | Course | C1 | Test questions | And the following "questions" exist: - | questioncategory | qtype | name | template | - | Test questions | essayautograde | essayautograde-001 | editor | - | Test questions | essayautograde | essayautograde-002 | editorfilepicker | - | Test questions | essayautograde | essayautograde-003 | plain | + | questioncategory | qtype | name | template | + | Test questions | essayautograde | essayautograde-001 | editor | + | Test questions | essayautograde | essayautograde-002 | editorfilepicker | + | Test questions | essayautograde | essayautograde-003 | plain | Given I log in as "teacher1" - And I follow "Course 1" - And I navigate to "Question bank" node in "Course administration" - + 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 submit a partially correct response. + Scenario: Preview an Essay autograde question and submit a partially correct response. When I click on "Preview" "link" in the "essayautograde-001" "table_row" And I switch to "questionpreview" window And I set the field "How questions behave" to "Immediate feedback" @@ -36,7 +36,7 @@ Feature: Preview Essay questions And I switch to the main window @javascript @_switch_window - Scenario: Preview an Essay question and submit a partially correct response. + Scenario: Preview an Essay autograde question and submit a partially correct response. When I click on "Preview" "link" in the "essayautograde-002" "table_row" And I switch to "questionpreview" window And I set the field "How questions behave" to "Immediate feedback" @@ -46,7 +46,7 @@ Feature: Preview Essay questions And I switch to the main window @javascript @_switch_window - Scenario: Preview an Essay question and submit a partially correct response. + Scenario: Preview an Essay autograde question and submit a partially correct response. When I click on "Preview" "link" in the "essayautograde-003" "table_row" And I switch to "questionpreview" window And I set the field "How questions behave" to "Immediate feedback" diff --git a/tests/helper.php b/tests/helper.php index 709c098..333f1cb 100644 --- a/tests/helper.php +++ b/tests/helper.php @@ -33,6 +33,7 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class qtype_essayautograde_test_helper extends question_test_helper { + public function get_test_questions() { return array('editor', 'editorfilepicker', 'plain', 'monospaced', 'responsetemplate', 'noinline'); } @@ -56,7 +57,17 @@ protected function initialise_essayautograde_question() { $q->graderinfo = ''; $q->graderinfoformat = FORMAT_HTML; $q->qtype = question_bank::get_qtype('essayautograde'); - + $q->enableautograde = 1; + $q->itemtype = 1; + $q->itemcount = 0; + $q->showfeedback = 0; + $q->showcalculation = 0; + $q->showtextstats = 0; + $q->textstatitems = 0; + $q->showgradebands = 0; + $q->addpartialgrades = 0; + $q->showtargetphrases = 0; + $q->correctfeedback = 'Correct feedback'; return $q; } @@ -81,7 +92,8 @@ public function get_essayautograde_question_form_data_editor() { $fromform->name = 'Essay question (HTML editor)'; $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->generalfeedback = + array('text' => 'I hope your story had a beginning, a middle and an end.', 'format' => FORMAT_HTML); $fromform->responseformat = 'editor'; $fromform->responserequired = 1; $fromform->responsefieldlines = 10; @@ -89,6 +101,10 @@ public function get_essayautograde_question_form_data_editor() { $fromform->attachmentsrequired = 0; $fromform->graderinfo = array('text' => '', 'format' => FORMAT_HTML); $fromform->responsetemplate = array('text' => '', 'format' => FORMAT_HTML); + $fromform->correctfeedback = array('text' => '', 'format' => FORMAT_HTML); + $fromform->partiallycorrectfeedback = array('text' => '', 'format' => FORMAT_HTML); + $fromform->incorrectfeedback = array('text' => '', 'format' => FORMAT_HTML); + $fromform->addpartialgrades = 1; return $fromform; } @@ -118,7 +134,8 @@ public function get_essayautograde_question_form_data_editorfilepicker() { $fromform->name = 'Essay 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->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; @@ -126,6 +143,10 @@ public function get_essayautograde_question_form_data_editorfilepicker() { $fromform->attachmentsrequired = 0; $fromform->graderinfo = array('text' => '', 'format' => FORMAT_HTML); $fromform->responsetemplate = array('text' => '', 'format' => FORMAT_HTML); + $fromform->correctfeedback = array('text' => '', 'format' => FORMAT_HTML); + $fromform->partiallycorrectfeedback = array('text' => '', 'format' => FORMAT_HTML); + $fromform->incorrectfeedback = array('text' => '', 'format' => FORMAT_HTML); + $fromform->addpartialgrades = 1; return $fromform; } @@ -151,17 +172,23 @@ public function get_essayautograde_question_form_data_plain() { $fromform = new stdClass(); $fromform->name = 'Essay question with filepicker and attachments'; - $fromform->questiontext = array('text' => 'Please write a story about a frog.', 'format' => FORMAT_HTML); + $fromform->questiontext = array('text' => 'Please write a story about a frog.', 'format' => FORMAT_PLAIN); $fromform->defaultmark = 1.0; - $fromform->generalfeedback = array('text' => 'I hope your story had a beginning, a middle and an end.', 'format' => FORMAT_HTML); + $fromform->generalfeedback = + array('text' => 'I hope your story had a beginning, a middle and an end.', 'format' => FORMAT_PLAIN); $fromform->responseformat = 'plain'; $fromform->responserequired = 1; $fromform->responsefieldlines = 10; $fromform->attachments = 0; $fromform->attachmentsrequired = 0; - $fromform->graderinfo = array('text' => '', 'format' => FORMAT_HTML); - $fromform->responsetemplate = array('text' => '', 'format' => FORMAT_HTML); - + $fromform->graderinfo = array('text' => '', 'format' => FORMAT_PLAIN); + $fromform->responsetemplate = array('text' => '', 'format' => FORMAT_PLAIN); + $fromform->graderinfo = array('text' => '', 'format' => FORMAT_PLAIN); + $fromform->responsetemplate = array('text' => '', 'format' => FORMAT_PLAIN); + $fromform->correctfeedback = array('text' => '', 'format' => FORMAT_PLAIN); + $fromform->partiallycorrectfeedback = array('text' => '', 'format' => FORMAT_PLAIN); + $fromform->incorrectfeedback = array('text' => '', 'format' => FORMAT_PLAIN); + $fromform->addpartialgrades = 0; return $fromform; } @@ -263,5 +290,28 @@ public function make_attachments_saver($attachments) { return new question_file_saver($this->make_attachments($attachments), 'question', 'response_attachments'); } - + /** + * Makes a essay autograde question with correct ansewer true, defaultmark 1. + * @return qtype_essayautograde_question + */ + public static function make_an_essayautograde_question() { + question_bank::load_question_definition_classes('essayautograde'); + $essay = new qtype_essayautograde_question(); + test_question_maker::initialise_a_question($essay); + $essay->name = 'Essayautograde question'; + $essay->questiontext = 'Write an essay.'; + $essay->generalfeedback = 'I hope you wrote an interesting essay.'; + $essay->penalty = 0; + $essay->qtype = question_bank::get_qtype('essayautograde'); + $essay->responseformat = 'editor'; + $essay->responserequired = 1; + $essay->responsefieldlines = 15; + $essay->attachments = 0; + $essay->attachmentsrequired = 0; + $essay->responsetemplate = ''; + $essay->responsetemplateformat = FORMAT_MOODLE; + $essay->graderinfo = ''; + $essay->graderinfoformat = FORMAT_MOODLE; + return $essay; + } } diff --git a/tests/question_test.php b/tests/question_test.php index 88df932..b46f5c1 100644 --- a/tests/question_test.php +++ b/tests/question_test.php @@ -28,7 +28,7 @@ global $CFG; require_once($CFG->dirroot . '/question/engine/tests/helpers.php'); - +require_once($CFG->dirroot . '/question/type/essayautograde/tests/helper.php'); /** * Unit tests for the matching question definition class. @@ -38,20 +38,20 @@ */ class qtype_essayautograde_question_test extends advanced_testcase { public function test_get_question_summary() { - $essayautograde = test_question_maker::make_an_essayautograde_question(); + $essayautograde = qtype_essayautograde_test_helper::make_an_essayautograde_question(); $essayautograde->questiontext = 'Hello world'; $this->assertEquals('Hello [world]', $essayautograde->get_question_summary()); } public function test_summarise_response() { $longstring = str_repeat('0123456789', 50); - $essayautograde = test_question_maker::make_an_essayautograde_question(); + $essayautograde = qtype_essayautograde_test_helper::make_an_essayautograde_question(); $this->assertEquals($longstring, $essayautograde->summarise_response( array('answer' => $longstring, 'answerformat' => FORMAT_HTML))); } public function test_is_same_response() { - $essayautograde = test_question_maker::make_an_essayautograde_question(); + $essayautograde = qtype_essayautograde_test_helper::make_an_essayautograde_question(); $essayautograde->responsetemplate = ''; @@ -95,7 +95,7 @@ public function test_is_same_response() { } public function test_is_same_response_with_template() { - $essayautograde = test_question_maker::make_an_essayautograde_question(); + $essayautograde = qtype_essayautograde_test_helper::make_an_essayautograde_question(); $essayautograde->responsetemplate = 'Once upon a time'; @@ -153,7 +153,7 @@ public function test_is_complete_response() { } // Create the essayautograde question under test. - $essayautograde = test_question_maker::make_an_essayautograde_question(); + $essayautograde = qtype_essayautograde_test_helper::make_an_essayautograde_question(); $essayautograde->start_attempt(new question_attempt_step(), 1); // Test the "traditional" case, where we must recieve a response from the user. diff --git a/tests/walkthrough_test.php b/tests/walkthrough_test.php index 3fa8c77..4874a2b 100644 --- a/tests/walkthrough_test.php +++ b/tests/walkthrough_test.php @@ -39,11 +39,8 @@ class qtype_essayautograde_walkthrough_testcase extends qbehaviour_walkthrough_t protected function check_contains_textarea($name, $content = '', $height = 10) { $fieldname = $this->quba->get_field_prefix($this->slot) . $name; - - $this->assertTag(array('tag' => 'textarea', - 'attributes' => array('cols' => '60', 'rows' => $height, - 'name' => $fieldname)), - $this->currentoutput); + $arr = ['tag' => 'textarea', 'attributes' => ['cols' => '60', 'rows' => $height, 'name' => $fieldname]]; + $this->assertTag($arr, $this->currentoutput); if ($content) { $this->assertRegExp('/' . preg_quote(s($content), '/') . '/', $this->currentoutput); @@ -121,8 +118,8 @@ public function test_deferred_feedback_html_editor() { $this->quba->finish_all_questions(); // Verify. - $this->check_current_state(question_state::$needsgrading); - $this->check_current_mark(null); + $this->check_current_state(question_state::$gradedwrong); + $this->check_current_mark(0.0); $this->render(); $this->assertRegExp('/' . preg_quote($response, '/') . '/', $this->currentoutput); $this->check_current_output( @@ -173,8 +170,8 @@ public function test_deferred_feedback_plain_text() { $this->quba->finish_all_questions(); // Verify. - $this->check_current_state(question_state::$needsgrading); - $this->check_current_mark(null); + $this->check_current_state(question_state::$gradedwrong); + $this->check_current_mark(0.0); $this->render(); $this->assertRegExp('/' . preg_quote(s($response), '/') . '/', $this->currentoutput); $this->check_current_output( @@ -230,10 +227,11 @@ public function test_responsetemplate() { $this->quba->finish_all_questions(); // Verify. - $this->check_current_state(question_state::$needsgrading); - $this->check_current_mark(null); + $this->check_current_state(question_state::$gradedwrong); + $this->check_current_mark(0.0); $this->render(); - $this->assertRegExp('/' . preg_quote(s('Once upon a time there was a little green frog.'), '/') . '/', $this->currentoutput); + $this->assertRegExp('/' . preg_quote(s('Once upon a time there was a little green frog.'), '/') . '/', + $this->currentoutput); $this->check_current_output( $this->get_contains_question_text_expectation($q), $this->get_contains_general_feedback_expectation($q)); @@ -247,7 +245,6 @@ public function test_deferred_feedback_html_editor_with_files_attempt_on_last() // Required to init a text editor. $PAGE->set_url('/'); $usercontextid = context_user::instance($USER->id)->id; - $fs = get_file_storage(); // Create an essayautograde question in the DB. $generator = $this->getDataGenerator()->get_plugin_generator('core_question'); @@ -316,8 +313,8 @@ public function test_deferred_feedback_html_editor_with_files_attempt_on_last() // Now submit all and finish. $this->finish(); - $this->check_current_state(question_state::$needsgrading); - $this->check_current_mark(null); + $this->check_current_state(question_state::$gradedright); + $this->check_current_mark(1.0); $this->check_step_count(3); $this->save_quba(); @@ -364,14 +361,12 @@ public function test_deferred_feedback_html_editor_with_files_attempt_on_last() } public function test_deferred_feedback_html_editor_with_files_attempt_on_last_no_files_uploaded() { - global $CFG, $USER, $PAGE; + global $PAGE; $this->resetAfterTest(true); $this->setAdminUser(); // Required to init a text editor. $PAGE->set_url('/'); - $usercontextid = context_user::instance($USER->id)->id; - $fs = get_file_storage(); // Create an essayautograde question in the DB. $generator = $this->getDataGenerator()->get_plugin_generator('core_question'); @@ -411,8 +406,8 @@ public function test_deferred_feedback_html_editor_with_files_attempt_on_last_no // Now submit all and finish. $this->finish(); - $this->check_current_state(question_state::$needsgrading); - $this->check_current_mark(null); + $this->check_current_state(question_state::$gradedright); + $this->check_current_mark(1.0); $this->check_step_count(3); $this->save_quba(); @@ -439,11 +434,8 @@ public function test_deferred_feedback_html_editor_with_files_attempt_on_last_no } public function test_deferred_feedback_plain_attempt_on_last() { - global $CFG, $USER; - $this->resetAfterTest(true); $this->setAdminUser(); - $usercontextid = context_user::instance($USER->id)->id; // Create an essayautograde question in the DB. $generator = $this->getDataGenerator()->get_plugin_generator('core_question'); @@ -472,8 +464,8 @@ public function test_deferred_feedback_plain_attempt_on_last() { // Now submit all and finish. $this->finish(); - $this->check_current_state(question_state::$needsgrading); - $this->check_current_mark(null); + $this->check_current_state(question_state::$gradedright); + $this->check_current_mark(1.0); $this->check_step_count(3); $this->save_quba(); @@ -497,7 +489,8 @@ public function test_deferred_feedback_plain_attempt_on_last() { $this->load_quba(); $this->render(); // Test taht no HTML comment has been added to the response. - $this->assertRegExp('/Once upon a time there was a frog called Freddy. He lived happily ever after.(?!<!--)/', $this->currentoutput); + $this->assertRegExp('/Once upon a time there was a frog called Freddy. He lived happily ever after.(?!<!--)/', + $this->currentoutput); // Test for the hash of an empty file area. $this->assertNotContains('d41d8cd98f00b204e9800998ecf8427e', $this->currentoutput); }