diff --git a/lib/behat/behat_base.php b/lib/behat/behat_base.php index 075e2794508..f1daac04d05 100644 --- a/lib/behat/behat_base.php +++ b/lib/behat/behat_base.php @@ -948,9 +948,11 @@ class behat_base extends Behat\MinkExtension\Context\RawMinkContext { /** * Set current $USER, reset access cache. - * @static + * + * In some cases, behat will execute the code as admin but in many cases we need to set an specific user as some + * API's might rely on the logged user to take some action. + * * @param null|int|stdClass $user user record, null or 0 means non-logged-in, positive integer means userid - * @return void */ public static function set_user($user = null) { global $DB; @@ -961,13 +963,13 @@ class behat_base extends Behat\MinkExtension\Context\RawMinkContext { // Assign valid data to admin user (some generator-related code needs a valid user). $user = $DB->get_record('user', array('username' => 'admin')); } else { - $user = $DB->get_record('user', array('id'=> $user)); + $user = $DB->get_record('user', array('id' => $user)); } unset($user->description); unset($user->access); unset($user->preference); - // Enusre session is empty, as it may contain caches and user specific info. + // Ensure session is empty, as it may contain caches and user specific info. \core\session\manager::init_empty_session(); \core\session\manager::set_user($user); diff --git a/mod/quiz/attemptlib.php b/mod/quiz/attemptlib.php index 510f30b9173..00e1eb1b010 100644 --- a/mod/quiz/attemptlib.php +++ b/mod/quiz/attemptlib.php @@ -1833,7 +1833,6 @@ class quiz_attempt { } else { $simulatedpostdata = $simulatedresponses; } - } else { $simulatedpostdata = null; } diff --git a/mod/quiz/report/grading/tests/behat/grading.feature b/mod/quiz/report/grading/tests/behat/grading.feature index 7ea18abc617..840902b045f 100644 --- a/mod/quiz/report/grading/tests/behat/grading.feature +++ b/mod/quiz/report/grading/tests/behat/grading.feature @@ -21,14 +21,14 @@ Feature: Basic use of the Manual grading report | contextlevel | reference | name | | Course | C1 | Test questions | And the following "questions" exist: - | questioncategory | qtype | name | questiontext | answer 1 | grade | - | Test questions | shortanswer | Short answer 001 | Where is the capital city of France? | Paris | 100% | + | questioncategory | qtype | name | questiontext | answer 1 | grade | + | Test questions | shortanswer | Short answer 001 | Where is the capital city of France? | Paris | 100% | And the following "activities" exist: | activity | name | course | idnumber | | quiz | Quiz 1 | C1 | quiz1 | And quiz "Quiz 1" contains the following questions: - | question | page | - | Short answer 001 | 1 | + | question | page | + | Short answer 001 | 1 | # Check report shows nothing when there are no attempts. When I log in as "teacher1" diff --git a/mod/quiz/report/overview/tests/behat/basic.feature b/mod/quiz/report/overview/tests/behat/basic.feature index b879867746c..766f37a83e6 100644 --- a/mod/quiz/report/overview/tests/behat/basic.feature +++ b/mod/quiz/report/overview/tests/behat/basic.feature @@ -37,12 +37,12 @@ Feature: Basic use of the Grades report | TF2 | 1 | 3.0 | And user "student1" has attempted "Quiz 1" with responses: | slot | response | - | 1 | True | + | 1 | True | | 2 | False | And user "student2" has attempted "Quiz 1" with responses: | slot | response | - | 1 | True | - | 2 | True | + | 1 | True | + | 2 | True | # Basic check of the Grades report When I log in as "teacher1" diff --git a/mod/quiz/report/statistics/tests/behat/basic.feature b/mod/quiz/report/statistics/tests/behat/basic.feature index 93e6ce7d01d..a7fe133d43a 100644 --- a/mod/quiz/report/statistics/tests/behat/basic.feature +++ b/mod/quiz/report/statistics/tests/behat/basic.feature @@ -48,14 +48,14 @@ Feature: Basic use of the Statistics report And "Show chart data" "link" should not exist When user "student1" has attempted "Quiz 1" with responses: | slot | response | - | 1 | True | + | 1 | True | | 2 | False | | 3 | False | And user "student2" has attempted "Quiz 1" with responses: | slot | response | - | 1 | True | - | 2 | True | - | 3 | True | + | 1 | True | + | 2 | True | + | 3 | True | And user "student3" has attempted "Quiz 1" with responses: | slot | response | | 1 | False | diff --git a/mod/quiz/tests/behat/behat_mod_quiz.php b/mod/quiz/tests/behat/behat_mod_quiz.php index e14d94c53ca..8f6bf5d0422 100644 --- a/mod/quiz/tests/behat/behat_mod_quiz.php +++ b/mod/quiz/tests/behat/behat_mod_quiz.php @@ -571,7 +571,7 @@ class behat_mod_quiz extends behat_question_base { * * slot The slot * actualquestion This column is optional, and is only needed if the quiz contains - * random questions. If so, this will let you control which acutal + * random questions. If so, this will let you control which actual * question gets picked when this slot is 'randomised' at the * start of the attempt. If you don't specify, then one will be picked * at random (which might make the reponse meaningless). @@ -582,15 +582,15 @@ class behat_mod_quiz extends behat_question_base { * made when the quiz is started. * response The response that was submitted. How this is interpreted depends on * the question type. It gets passed to - * {@link core_question_generator::get_simulated_post_data_for_question_attempt() + * {@link core_question_generator::get_simulated_post_data_for_question_attempt()} * and therefore to the un_summarise_response method of the question to decode. * * Then there should be a number of rows of data, one for each question you want to add. * There is no need to supply answers to all questions. If so, other qusetions will be * left unanswered. * - * @param string $quizname the name of the quiz the user will attempt. * @param string $username the username of the user that will attempt. + * @param string $quizname the name of the quiz the user will attempt. * @param TableNode $attemptinfo information about the questions to add, as above. * @Given /^user "([^"]*)" has attempted "([^"]*)" with responses:$/ */ @@ -644,8 +644,8 @@ class behat_mod_quiz extends behat_question_base { * There is no need to supply answers to all questions. If so, other qusetions will be * left unanswered. * - * @param string $quizname the name of the quiz the user will attempt. * @param string $username the username of the user that will attempt. + * @param string $quizname the name of the quiz the user will attempt. * @Given /^user "([^"]*)" has started an attempt at quiz "([^"]*)"$/ */ public function user_has_started_an_attempt_at_quiz($username, $quizname) { @@ -664,8 +664,8 @@ class behat_mod_quiz extends behat_question_base { /** * Submit answers to an existing quiz attempt. * - * @param string $quizname the name of the quiz the user will attempt. * @param string $username the username of the user that will attempt. + * @param string $quizname the name of the quiz the user will attempt. * @param TableNode $attemptinfo information about the questions to add, as above. * @throws \Behat\Mink\Exception\ExpectationException * @Given /^user "([^"]*)" has submitted answers in their attempt at quiz "([^"]*)":$/ @@ -678,7 +678,7 @@ class behat_mod_quiz extends behat_question_base { $quizid = $DB->get_field('quiz', 'id', ['name' => $quizname], MUST_EXIST); $user = $DB->get_record('user', ['username' => $username], '*', MUST_EXIST); - $forcedrandomquestions = []; + $forcedvariants = []; $responses = []; foreach ($attemptinfo->getHash() as $slotinfo) { @@ -692,11 +692,6 @@ class behat_mod_quiz extends behat_question_base { } $responses[$slotinfo['slot']] = $slotinfo['response']; - if (!empty($slotinfo['actualquestion'])) { - $forcedrandomquestions[$slotinfo['slot']] = $DB->get_field('question', 'id', - ['name' => $slotinfo['actualquestion']], MUST_EXIST); - } - if (!empty($slotinfo['variant'])) { $forcedvariants[$slotinfo['slot']] = (int) $slotinfo['variant']; } @@ -715,8 +710,8 @@ class behat_mod_quiz extends behat_question_base { /** * Finish an existing quiz attempt. * - * @param string $quizname the name of the quiz the user will attempt. * @param string $username the username of the user that will attempt. + * @param string $quizname the name of the quiz the user will attempt. * @Given /^user "([^"]*)" has finished an attempt at quiz "([^"]*)"$/ */ public function user_has_finished_an_attempt_at_quiz($username, $quizname) { @@ -732,6 +727,7 @@ class behat_mod_quiz extends behat_question_base { $attemptobj->process_finish(time(), true); break; } + $this->set_user(); } } diff --git a/mod/quiz/tests/behat/completion_condition_attempts_used.feature b/mod/quiz/tests/behat/completion_condition_attempts_used.feature index 5c05704bffb..7e87610f57a 100644 --- a/mod/quiz/tests/behat/completion_condition_attempts_used.feature +++ b/mod/quiz/tests/behat/completion_condition_attempts_used.feature @@ -32,7 +32,7 @@ Feature: Set a quiz to be marked complete when the student uses all attempts all | First question | 1 | And user "student1" has attempted "Test quiz name" with responses: | slot | response | - | 1 | False | + | 1 | False | Scenario: student1 uses up both attempts without passing When I log in as "student1" diff --git a/mod/quiz/tests/generator/lib.php b/mod/quiz/tests/generator/lib.php index ef9100fb3eb..f7d7b32a659 100644 --- a/mod/quiz/tests/generator/lib.php +++ b/mod/quiz/tests/generator/lib.php @@ -134,10 +134,9 @@ class mod_quiz_generator extends testing_module_generator { * @param int $attemptid the id of the attempt which is being * @param array $responses array responses to submit. See description on * {@link core_question_generator::get_simulated_post_data_for_questions_in_usage()}. - * @param bool $finishattempt of true, the attempt will be submitted. + * @param bool $finishattempt if true, the attempt will be submitted. */ - public function submit_responses($attemptid, array $responses, $finishattempt) { - /** @var $questiongenerator core_question_generator */ + public function submit_responses($attemptid, array $responses, $checkbutton, $finishattempt) { $questiongenerator = $this->datagenerator->get_plugin_generator('core_question'); $attemptobj = quiz_attempt::create($attemptid); diff --git a/question/tests/generator/lib.php b/question/tests/generator/lib.php index 66ca045c83b..9deeb8ca339 100644 --- a/question/tests/generator/lib.php +++ b/question/tests/generator/lib.php @@ -190,7 +190,7 @@ class core_question_generator extends component_generator_base { * are passed to the un_summarise_response method of the question to decode. * * @param question_attempt $qa the question attempt for which we are generating POST data. - * @param $responsesummary a textual summary of the resonse, as described above. + * @param string $responsesummary a textual summary of the resonse, as described above. * @return array the sumulated post data that can be passed to $quba->process_all_actions. */ public function get_simulated_post_data_for_question_attempt( diff --git a/question/type/essay/question.php b/question/type/essay/question.php index e0d770fb343..73466bff99a 100644 --- a/question/type/essay/question.php +++ b/question/type/essay/question.php @@ -91,7 +91,7 @@ class qtype_essay_question extends question_with_responses { public function un_summarise_response(string $summary) { if (!empty($summary)) { - return ['answer' => $summary]; + return ['answer' => text_to_html($summary)]; } else { return []; } diff --git a/question/type/numerical/question.php b/question/type/numerical/question.php index 97634a71577..79733d4aebf 100644 --- a/question/type/numerical/question.php +++ b/question/type/numerical/question.php @@ -85,18 +85,18 @@ class qtype_numerical_question extends question_graded_automatically { return $resp; } - public function un_summarise_response(string $response) { - if (!empty($response)) { - $resp = $response; + public function un_summarise_response(string $summary) { + if ($this->has_separate_unit_field()) { + throw new coding_exception('Sorry, but at the moment un_summarise_response cannot handle the + has_separate_unit_field case for numerical questions. + If you need this, you will have to implement it yourself.'); + } + + if (!empty($summary)) { + return ['answer' => $summary]; } else { - $resp = null; + return []; } - - if ($this->has_separate_unit_field() && !empty($response)) { - $resp = $this->ap->add_unit($resp, $response); - } - - return $resp; } public function is_gradable_response(array $response) {