| Línea 17... | 
            Línea 17... | 
          
          
            | 17 | 
            namespace mod_quiz;
  | 
            17 | 
            namespace mod_quiz;
  | 
          
          
            | Línea 18... | 
            Línea 18... | 
          
          
            | 18 | 
             
  | 
            18 | 
             
  | 
          
          
            | 19 | 
            use moodle_url;
  | 
            19 | 
            use moodle_url;
  | 
          
          
            | 20 | 
            use question_bank;
  | 
            20 | 
            use question_bank;
  | 
          
          
            | 21 | 
            use question_engine;
  | 
            21 | 
            use question_engine;
  | 
          
          
            | 22 | 
            use mod_quiz\question\bank\qbank_helper;
  | 
            - | 
               | 
          
          
            | 23 | 
             
  | 
            - | 
               | 
          
          
            | 24 | 
            defined('MOODLE_INTERNAL') || die();
  | 
            - | 
               | 
          
          
            | 25 | 
             
  | 
            - | 
               | 
          
          
            | 26 | 
            global $CFG;
  | 
            - | 
               | 
          
          
            | 27 | 
            require_once($CFG->dirroot . '/mod/quiz/locallib.php');
  | 
            - | 
               | 
          
          
            | Línea 28... | 
            Línea 22... | 
          
          
            | 28 | 
            require_once($CFG->dirroot . '/mod/quiz/tests/quiz_question_helper_test_trait.php');
  | 
            22 | 
            use mod_quiz\tests\question_helper_test_trait;
  | 
          
          
            | 29 | 
             
  | 
            23 | 
             
  | 
          
          
            | 30 | 
            /**
  | 
            24 | 
            /**
  | 
          
          
            | 31 | 
             * Quiz attempt walk through.
  | 
            25 | 
             * Quiz attempt walk through.
  | 
          
          
            | Línea 35... | 
            Línea 29... | 
          
          
            | 35 | 
             * @copyright 2013 The Open University
  | 
            29 | 
             * @copyright 2013 The Open University
  | 
          
          
            | 36 | 
             * @author    Jamie Pratt <me@jamiep.org>
  | 
            30 | 
             * @author    Jamie Pratt <me@jamiep.org>
  | 
          
          
            | 37 | 
             * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  | 
            31 | 
             * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  | 
          
          
            | 38 | 
             * @covers \mod_quiz\quiz_attempt
  | 
            32 | 
             * @covers \mod_quiz\quiz_attempt
  | 
          
          
            | 39 | 
             */
  | 
            33 | 
             */
  | 
          
          
            | 40 | 
            class attempt_walkthrough_test extends \advanced_testcase {
  | 
            34 | 
            final class attempt_walkthrough_test extends \advanced_testcase {
  | 
          
          
            | - | 
               | 
            35 | 
                use question_helper_test_trait;
  | 
          
          
            | Línea -... | 
            Línea 36... | 
          
          
            | - | 
               | 
            36 | 
             
  | 
          
          
            | 41 | 
             
  | 
            37 | 
                #[\Override]
  | 
          
          
            | - | 
               | 
            38 | 
                public static function setUpBeforeClass(): void {
  | 
          
          
            | - | 
               | 
            39 | 
                    global $CFG;
  | 
          
          
            | - | 
               | 
            40 | 
             
  | 
          
          
            | - | 
               | 
            41 | 
                    parent::setUpBeforeClass();
  | 
          
          
            | - | 
               | 
            42 | 
             
  | 
          
          
            | - | 
               | 
            43 | 
                    require_once($CFG->dirroot . '/mod/quiz/locallib.php');
  | 
          
          
            | Línea 42... | 
            Línea 44... | 
          
          
            | 42 | 
                use \quiz_question_helper_test_trait;
  | 
            44 | 
                }
  | 
          
          
            | 43 | 
             
  | 
            45 | 
             
  | 
          
          
            | 44 | 
                /**
  | 
            46 | 
                /**
  | 
          
          
            | 45 | 
                 * Create a quiz with questions and walk through a quiz attempt.
  | 
            47 | 
                 * Create a quiz with questions and walk through a quiz attempt.
  | 
          
          
            | Línea 102... | 
            Línea 104... | 
          
          
            | 102 | 
             
  | 
            104 | 
             
  | 
          
          
            | 103 | 
                    $tosubmit = [
  | 
            105 | 
                    $tosubmit = [
  | 
          
          
            | 104 | 
                        3 => [
  | 
            106 | 
                        3 => [
  | 
          
          
            | 105 | 
                            'frog' => 'amphibian',
  | 
            107 | 
                            'frog' => 'amphibian',
  | 
          
          
            | 106 | 
                            'cat' => 'mammal',
  | 
            108 | 
                            'cat' => 'mammal',
  | 
          
          
            | 107 | 
                            'newt' => ''
  | 
            109 | 
                            'newt' => '',
  | 
          
          
            | 108 | 
                        ]
  | 
            110 | 
                        ],
  | 
          
          
            | Línea 109... | 
            Línea 111... | 
          
          
            | 109 | 
                    ];
  | 
            111 | 
                    ];
  | 
          
          
            | 110 | 
             
  | 
            112 | 
             
  | 
          
          
            | 111 | 
                    $attemptobj->process_submitted_actions($timenow, false, $tosubmit);
  | 
            113 | 
                    $attemptobj->process_submitted_actions($timenow, false, $tosubmit);
  | 
          
          
            | Línea 112... | 
            Línea 114... | 
          
          
            | 112 | 
                    // The student has answered three questions but one is invalid, so there is still one remaining.
  | 
            114 | 
                    // The student has answered three questions but one is invalid, so there is still one remaining.
  | 
          
          
            | 113 | 
                    $this->assertEquals(1, $attemptobj->get_number_of_unanswered_questions());
  | 
            115 | 
                    $this->assertEquals(1, $attemptobj->get_number_of_unanswered_questions());
  | 
          
          
            | 114 | 
             
  | 
            116 | 
             
  | 
          
          
            | 115 | 
                    $tosubmit = [
  | 
            117 | 
                    $tosubmit = [
  | 
          
          
            | 116 | 
                        3 => [
  | 
            118 | 
                        3 => [
  | 
          
          
            | 117 | 
                            'frog' => 'amphibian',
  | 
            119 | 
                            'frog' => 'amphibian',
  | 
          
          
            | 118 | 
                            'cat' => 'mammal',
  | 
            120 | 
                            'cat' => 'mammal',
  | 
          
          
            | Línea 119... | 
            Línea 121... | 
          
          
            | 119 | 
                            'newt' => 'amphibian'
  | 
            121 | 
                            'newt' => 'amphibian',
  | 
          
          
            | 120 | 
                        ]
  | 
            122 | 
                        ],
  | 
          
          
            | 121 | 
                    ];
  | 
            123 | 
                    ];
  | 
          
          
            | Línea 122... | 
            Línea 124... | 
          
          
            | 122 | 
             
  | 
            124 | 
             
  | 
          
          
            | 123 | 
                    $attemptobj->process_submitted_actions($timenow, false, $tosubmit);
  | 
            125 | 
                    $attemptobj->process_submitted_actions($timenow, false, $tosubmit);
  | 
          
          
            | 124 | 
                    // The student has answered three questions, so there are no remaining.
  | 
            126 | 
                    // The student has answered three questions, so there are no remaining.
  | 
          
          
            | 125 | 
                    $this->assertEquals(0, $attemptobj->get_number_of_unanswered_questions());
  | 
            127 | 
                    $this->assertEquals(0, $attemptobj->get_number_of_unanswered_questions());
  | 
          
          
            | Línea 126... | 
            Línea 128... | 
          
          
            | 126 | 
             
  | 
            128 | 
             
  | 
          
          
            | 127 | 
                    // Finish the attempt.
  | 
            129 | 
                    // Finish the attempt.
  | 
          
          
            | Línea 128... | 
            Línea 130... | 
          
          
            | 128 | 
                    $attemptobj = quiz_attempt::create($attempt->id);
  | 
            130 | 
                    $attemptobj = quiz_attempt::create($attempt->id);
  | 
          
          
            | 129 | 
                    $this->assertTrue($attemptobj->has_response_to_at_least_one_graded_question());
  | 
            131 | 
                    $this->assertTrue($attemptobj->has_response_to_at_least_one_graded_question());
  | 
          
          
            | 130 | 
                    $attemptobj->process_finish($timenow, false);
  | 
            - | 
               | 
          
          
            | 131 | 
             
  | 
            132 | 
                    $attemptobj->process_submit($timenow, false);
  | 
          
          
            | 132 | 
                    // Re-load quiz attempt data.
  | 
            133 | 
             
  | 
          
          
            | 133 | 
                    $attemptobj = quiz_attempt::create($attempt->id);
  | 
            134 | 
                    // Re-load quiz attempt data.
  | 
          
          
            | 134 | 
             
  | 
            135 | 
                    $attemptobj = quiz_attempt::create($attempt->id);
  | 
          
          
            | 135 | 
                    // Check that results are stored as expected.
  | 
            136 | 
             
  | 
          
          
            | - | 
               | 
            137 | 
                    // Check that results are stored as expected.
  | 
          
          
            | - | 
               | 
            138 | 
                    $this->assertEquals(1, $attemptobj->get_attempt_number());
  | 
          
          
            | - | 
               | 
            139 | 
                    $this->assertEquals(false, $attemptobj->is_finished());
  | 
          
          
            | - | 
               | 
            140 | 
                    $this->assertEquals($timenow, $attemptobj->get_submitted_date());
  | 
          
          
            | - | 
               | 
            141 | 
                    $this->assertEquals($user1->id, $attemptobj->get_userid());
  | 
          
          
            | - | 
               | 
            142 | 
                    $this->assertTrue($attemptobj->has_response_to_at_least_one_graded_question());
  | 
          
          
            | - | 
               | 
            143 | 
                    $this->assertEquals(0, $attemptobj->get_number_of_unanswered_questions());
  | 
          
          
            | Línea 136... | 
            Línea 144... | 
          
          
            | 136 | 
                    $this->assertEquals(1, $attemptobj->get_attempt_number());
  | 
            144 | 
                    // Check we don't have grades yet.
  | 
          
          
            | - | 
               | 
            145 | 
                    $this->assertEmpty(quiz_get_user_grades($quiz, $user1->id));
  | 
          
          
            | - | 
               | 
            146 | 
                    $this->assertNull($attemptobj->get_sum_marks());
  | 
          
          
            | - | 
               | 
            147 | 
             
  | 
          
          
            | 137 | 
                    $this->assertEquals(3, $attemptobj->get_sum_marks());
  | 
            148 | 
                    // Now grade the submission.
  | 
          
          
            | 138 | 
                    $this->assertEquals(true, $attemptobj->is_finished());
  | 
            149 | 
                    $attemptobj->process_grade_submission($timenow);
  | 
          
          
            | 139 | 
                    $this->assertEquals($timenow, $attemptobj->get_submitted_date());
  | 
            150 | 
                    $attemptobj = quiz_attempt::create($attempt->id);
  | 
          
          
            | Línea 140... | 
            Línea 151... | 
          
          
            | 140 | 
                    $this->assertEquals($user1->id, $attemptobj->get_userid());
  | 
            151 | 
             
  | 
          
          
            | Línea 151... | 
            Línea 162... | 
          
          
            | 151 | 
                    $gradebookitem = array_shift($gradebookgrades->items);
  | 
            162 | 
                    $gradebookitem = array_shift($gradebookgrades->items);
  | 
          
          
            | 152 | 
                    $gradebookgrade = array_shift($gradebookitem->grades);
  | 
            163 | 
                    $gradebookgrade = array_shift($gradebookitem->grades);
  | 
          
          
            | 153 | 
                    $this->assertEquals(100, $gradebookgrade->grade);
  | 
            164 | 
                    $this->assertEquals(100, $gradebookgrade->grade);
  | 
          
          
            | Línea 154... | 
            Línea 165... | 
          
          
            | 154 | 
             
  | 
            165 | 
             
  | 
          
          
            | 155 | 
                    // Update question in quiz.
  | 
            166 | 
                    // Update question in quiz.
  | 
          
          
            | - | 
               | 
            167 | 
                    $newsa = $questiongenerator->update_question(
  | 
          
          
            | - | 
               | 
            168 | 
                        $saq,
  | 
          
          
            | 156 | 
                    $newsa = $questiongenerator->update_question($saq, null,
  | 
            169 | 
                        null,
  | 
          
          
            | - | 
               | 
            170 | 
                        ['name' => 'This is the second version of shortanswer']
  | 
          
          
            | 157 | 
                        ['name' => 'This is the second version of shortanswer']);
  | 
            171 | 
                    );
  | 
          
          
            | - | 
               | 
            172 | 
                    $newnumbq = $questiongenerator->update_question(
  | 
          
          
            | - | 
               | 
            173 | 
                        $numq,
  | 
          
          
            | 158 | 
                    $newnumbq = $questiongenerator->update_question($numq, null,
  | 
            174 | 
                        null,
  | 
          
          
            | - | 
               | 
            175 | 
                        ['name' => 'This is the second version of numerical']
  | 
          
          
            | 159 | 
                        ['name' => 'This is the second version of numerical']);
  | 
            176 | 
                    );
  | 
          
          
            | - | 
               | 
            177 | 
                    $newmatch = $questiongenerator->update_question(
  | 
          
          
            | - | 
               | 
            178 | 
                        $matchq,
  | 
          
          
            | 160 | 
                    $newmatch = $questiongenerator->update_question($matchq, null,
  | 
            179 | 
                        null,
  | 
          
          
            | - | 
               | 
            180 | 
                        ['name' => 'This is the second version of match']
  | 
          
          
            | 161 | 
                        ['name' => 'This is the second version of match']);
  | 
            181 | 
                    );
  | 
          
          
            | - | 
               | 
            182 | 
                    $newdescription = $questiongenerator->update_question(
  | 
          
          
            | - | 
               | 
            183 | 
                        $description,
  | 
          
          
            | 162 | 
                    $newdescription = $questiongenerator->update_question($description, null,
  | 
            184 | 
                        null,
  | 
          
          
            | - | 
               | 
            185 | 
                        ['name' => 'This is the second version of description']
  | 
          
          
            | Línea 163... | 
            Línea 186... | 
          
          
            | 163 | 
                        ['name' => 'This is the second version of description']);
  | 
            186 | 
                    );
  | 
          
          
            | 164 | 
             
  | 
            187 | 
             
  | 
          
          
            | 165 | 
                    // Update the attempt to use this questions.
  | 
            188 | 
                    // Update the attempt to use this questions.
  | 
          
          
            | Línea 216... | 
            Línea 239... | 
          
          
            | 216 | 
                    // Make a quiz.
  | 
            239 | 
                    // Make a quiz.
  | 
          
          
            | 217 | 
                    $timeclose = time() + HOURSECS;
  | 
            240 | 
                    $timeclose = time() + HOURSECS;
  | 
          
          
            | 218 | 
                    $quizgenerator = $this->getDataGenerator()->get_plugin_generator('mod_quiz');
  | 
            241 | 
                    $quizgenerator = $this->getDataGenerator()->get_plugin_generator('mod_quiz');
  | 
          
          
            | Línea 219... | 
            Línea 242... | 
          
          
            | 219 | 
             
  | 
            242 | 
             
  | 
          
          
            | 220 | 
                    $quiz = $quizgenerator->create_instance(
  | 
            243 | 
                    $quiz = $quizgenerator->create_instance(
  | 
          
          
            | 221 | 
                            ['course' => $SITE->id, 'timeclose' => $timeclose,
  | 
            244 | 
                        ['course' => $SITE->id, 'timeclose' => $timeclose,
  | 
          
          
            | - | 
               | 
            245 | 
                        'overduehandling' => $overduehandling,
  | 
          
          
            | - | 
               | 
            246 | 
                        'graceperiod' => HOURSECS]
  | 
          
          
            | Línea 222... | 
            Línea 247... | 
          
          
            | 222 | 
                                    'overduehandling' => $overduehandling, 'graceperiod' => HOURSECS]);
  | 
            247 | 
                    );
  | 
          
          
            | 223 | 
             
  | 
            248 | 
             
  | 
          
          
            | 224 | 
                    // Create a question.
  | 
            249 | 
                    // Create a question.
  | 
          
          
            | 225 | 
                    /** @var \core_question_generator $questiongenerator */
  | 
            250 | 
                    /** @var \core_question_generator $questiongenerator */
  | 
          
          
            | Línea 394... | 
            Línea 419... | 
          
          
            | 394 | 
             
  | 
            419 | 
             
  | 
          
          
            | 395 | 
                        // Finish the attempt.
  | 
            420 | 
                        // Finish the attempt.
  | 
          
          
            | 396 | 
                        $attemptobj = quiz_attempt::create($attempt->id);
  | 
            421 | 
                        $attemptobj = quiz_attempt::create($attempt->id);
  | 
          
          
            | 397 | 
                        $this->assertTrue($attemptobj->has_response_to_at_least_one_graded_question());
  | 
            422 | 
                        $this->assertTrue($attemptobj->has_response_to_at_least_one_graded_question());
  | 
          
          
            | 398 | 
                        $this->assertEquals(0, $attemptobj->get_number_of_unanswered_questions());
  | 
            423 | 
                        $this->assertEquals(0, $attemptobj->get_number_of_unanswered_questions());
  | 
          
          
            | Línea 399... | 
            Línea 424... | 
          
          
            | 399 | 
                        $attemptobj->process_finish($timenow, false);
  | 
            424 | 
                        $attemptobj->process_submit($timenow, false);
  | 
          
          
            | 400 | 
             
  | 
            425 | 
             
  | 
          
          
            | Línea 401... | 
            Línea 426... | 
          
          
            | 401 | 
                        // Re-load quiz attempt data.
  | 
            426 | 
                        // Re-load quiz attempt data.
  | 
          
          
            | 402 | 
                        $attemptobj = quiz_attempt::create($attempt->id);
  | 
            427 | 
                        $attemptobj = quiz_attempt::create($attempt->id);
  | 
          
          
            | 403 | 
             
  | 
            - | 
               | 
          
          
            | 404 | 
                        // Check that results are stored as expected.
  | 
            428 | 
             
  | 
          
          
            | 405 | 
                        $this->assertEquals(1, $attemptobj->get_attempt_number());
  | 
            429 | 
                        // Check that results are stored as expected.
  | 
          
          
            | 406 | 
                        $this->assertEquals(4, $attemptobj->get_sum_marks());
  | 
            430 | 
                        $this->assertEquals(1, $attemptobj->get_attempt_number());
  | 
          
          
            | 407 | 
                        $this->assertEquals(true, $attemptobj->is_finished());
  | 
            431 | 
                        $this->assertEquals(false, $attemptobj->is_finished());
  | 
          
          
            | 408 | 
                        $this->assertEquals($timenow, $attemptobj->get_submitted_date());
  | 
            432 | 
                        $this->assertEquals($timenow, $attemptobj->get_submitted_date());
  | 
          
          
            | Línea -... | 
            Línea 433... | 
          
          
            | - | 
               | 
            433 | 
                        $this->assertEquals($user1->id, $attemptobj->get_userid());
  | 
          
          
            | - | 
               | 
            434 | 
                        $this->assertTrue($attemptobj->has_response_to_at_least_one_graded_question());
  | 
          
          
            | - | 
               | 
            435 | 
                        $this->assertEquals(0, $attemptobj->get_number_of_unanswered_questions());
  | 
          
          
            | - | 
               | 
            436 | 
             
  | 
          
          
            | - | 
               | 
            437 | 
                        // Check we don't have grades yet.
  | 
          
          
            | - | 
               | 
            438 | 
                        $this->assertEmpty(quiz_get_user_grades($quiz, $user1->id));
  | 
          
          
            | - | 
               | 
            439 | 
                        $this->assertNull($attemptobj->get_sum_marks());
  | 
          
          
            | - | 
               | 
            440 | 
             
  | 
          
          
            | - | 
               | 
            441 | 
                        // Now grade the submission.
  | 
          
          
            | - | 
               | 
            442 | 
                        $attemptobj->process_grade_submission($timenow);
  | 
          
          
            | - | 
               | 
            443 | 
                        $attemptobj = quiz_attempt::create($attempt->id);
  | 
          
          
            | - | 
               | 
            444 | 
             
  | 
          
          
            | 409 | 
                        $this->assertEquals($user1->id, $attemptobj->get_userid());
  | 
            445 | 
                        // Check quiz grades.
  | 
          
          
            | 410 | 
                        $this->assertTrue($attemptobj->has_response_to_at_least_one_graded_question());
  | 
            446 | 
                        $this->assertEquals(true, $attemptobj->is_finished());
  | 
          
          
            | 411 | 
                        $this->assertEquals(0, $attemptobj->get_number_of_unanswered_questions());
  | 
            447 | 
                        $this->assertEquals(4, $attemptobj->get_sum_marks());
  | 
          
          
            | 412 | 
             
  | 
            448 | 
             
  | 
          
          
            | Línea 421... | 
            Línea 457... | 
          
          
            | 421 | 
                        $gradebookgrade = array_shift($gradebookitem->grades);
  | 
            457 | 
                        $gradebookgrade = array_shift($gradebookitem->grades);
  | 
          
          
            | 422 | 
                        $this->assertEquals(100, $gradebookgrade->grade);
  | 
            458 | 
                        $this->assertEquals(100, $gradebookgrade->grade);
  | 
          
          
            | 423 | 
                    }
  | 
            459 | 
                    }
  | 
          
          
            | 424 | 
                }
  | 
            460 | 
                }
  | 
          
          
            | Línea -... | 
            Línea 461... | 
          
          
            | - | 
               | 
            461 | 
             
  | 
          
          
            | - | 
               | 
            462 | 
                /**
  | 
          
          
            | 425 | 
             
  | 
            463 | 
                 * Get the correct response for variants.
  | 
          
          
            | - | 
               | 
            464 | 
                 *
  | 
          
          
            | - | 
               | 
            465 | 
                 * @return array
  | 
          
          
            | 426 | 
             
  | 
            466 | 
                 */
  | 
          
          
            | 427 | 
                public function get_correct_response_for_variants() {
  | 
            467 | 
                public static function get_correct_response_for_variants(): array {
  | 
          
          
            | 428 | 
                    return [[1, 9.9], [2, 8.5], [5, 14.2], [10, 6.8, true]];
  | 
            468 | 
                    return [[1, 9.9], [2, 8.5], [5, 14.2], [10, 6.8, true]];
  | 
          
          
            | Línea -... | 
            Línea 469... | 
          
          
            | - | 
               | 
            469 | 
                }
  | 
          
          
            | 429 | 
                }
  | 
            470 | 
             
  | 
          
          
            | Línea 430... | 
            Línea 471... | 
          
          
            | 430 | 
             
  | 
            471 | 
                /** @var ?\quiz A quiz with variants */
  | 
          
          
            | 431 | 
                protected $quizwithvariants = null;
  | 
            472 | 
                protected $quizwithvariants = null;
  | 
          
          
            | 432 | 
             
  | 
            473 | 
             
  | 
          
          
            | Línea 487... | 
            Línea 528... | 
          
          
            | 487 | 
                    // Finish the attempt.
  | 
            528 | 
                    // Finish the attempt.
  | 
          
          
            | 488 | 
                    $attemptobj = quiz_attempt::create($attempt->id);
  | 
            529 | 
                    $attemptobj = quiz_attempt::create($attempt->id);
  | 
          
          
            | 489 | 
                    $this->assertTrue($attemptobj->has_response_to_at_least_one_graded_question());
  | 
            530 | 
                    $this->assertTrue($attemptobj->has_response_to_at_least_one_graded_question());
  | 
          
          
            | 490 | 
                    $this->assertEquals(0, $attemptobj->get_number_of_unanswered_questions());
  | 
            531 | 
                    $this->assertEquals(0, $attemptobj->get_number_of_unanswered_questions());
  | 
          
          
            | Línea 491... | 
            Línea 532... | 
          
          
            | 491 | 
             
  | 
            532 | 
             
  | 
          
          
            | Línea 492... | 
            Línea 533... | 
          
          
            | 492 | 
                    $attemptobj->process_finish($timenow, false);
  | 
            533 | 
                    $attemptobj->process_submit($timenow, false);
  | 
          
          
            | 493 | 
             
  | 
            534 | 
             
  | 
          
          
            | Línea 494... | 
            Línea 535... | 
          
          
            | 494 | 
                    // Re-load quiz attempt data.
  | 
            535 | 
                    // Re-load quiz attempt data.
  | 
          
          
            | 495 | 
                    $attemptobj = quiz_attempt::create($attempt->id);
  | 
            536 | 
                    $attemptobj = quiz_attempt::create($attempt->id);
  | 
          
          
            | 496 | 
             
  | 
            - | 
               | 
          
          
            | 497 | 
                    // Check that results are stored as expected.
  | 
            537 | 
             
  | 
          
          
            | 498 | 
                    $this->assertEquals(1, $attemptobj->get_attempt_number());
  | 
            538 | 
                    // Check that results are stored as expected.
  | 
          
          
            | 499 | 
                    $this->assertEquals(1, $attemptobj->get_sum_marks());
  | 
            539 | 
                    $this->assertEquals(1, $attemptobj->get_attempt_number());
  | 
          
          
            | 500 | 
                    $this->assertEquals(true, $attemptobj->is_finished());
  | 
            540 | 
                    $this->assertEquals(false, $attemptobj->is_finished());
  | 
          
          
            | 501 | 
                    $this->assertEquals($timenow, $attemptobj->get_submitted_date());
  | 
            541 | 
                    $this->assertEquals($timenow, $attemptobj->get_submitted_date());
  | 
          
          
            | Línea -... | 
            Línea 542... | 
          
          
            | - | 
               | 
            542 | 
                    $this->assertEquals($user1->id, $attemptobj->get_userid());
  | 
          
          
            | - | 
               | 
            543 | 
                    $this->assertTrue($attemptobj->has_response_to_at_least_one_graded_question());
  | 
          
          
            | - | 
               | 
            544 | 
                    $this->assertEquals(0, $attemptobj->get_number_of_unanswered_questions());
  | 
          
          
            | - | 
               | 
            545 | 
             
  | 
          
          
            | - | 
               | 
            546 | 
                    // Check we don't have grades yet.
  | 
          
          
            | - | 
               | 
            547 | 
                    $this->assertEmpty(quiz_get_user_grades($this->quizwithvariants, $user1->id));
  | 
          
          
            | - | 
               | 
            548 | 
                    $this->assertNull($attemptobj->get_sum_marks());
  | 
          
          
            | - | 
               | 
            549 | 
             
  | 
          
          
            | - | 
               | 
            550 | 
                    // Now grade the submission.
  | 
          
          
            | - | 
               | 
            551 | 
                    $attemptobj->process_grade_submission($timenow);
  | 
          
          
            | - | 
               | 
            552 | 
                    $attemptobj = quiz_attempt::create($attempt->id);
  | 
          
          
            | 502 | 
                    $this->assertEquals($user1->id, $attemptobj->get_userid());
  | 
            553 | 
             
  | 
          
          
            | 503 | 
                    $this->assertTrue($attemptobj->has_response_to_at_least_one_graded_question());
  | 
            554 | 
                    // Check quiz grades.
  | 
          
          
            | 504 | 
                    $this->assertEquals(0, $attemptobj->get_number_of_unanswered_questions());
  | 
            555 | 
                    $this->assertEquals(true, $attemptobj->is_finished());
  | 
          
          
            | 505 | 
             
  | 
            556 | 
                    $this->assertEquals(1, $attemptobj->get_sum_marks());
  | 
          
          
            | Línea 559... | 
            Línea 610... | 
          
          
            | 559 | 
                    $this->assertEquals(1, $attemptobj->get_attempt_number());
  | 
            610 | 
                    $this->assertEquals(1, $attemptobj->get_attempt_number());
  | 
          
          
            | 560 | 
                    $this->assertFalse($attemptobj->is_finished());
  | 
            611 | 
                    $this->assertFalse($attemptobj->is_finished());
  | 
          
          
            | 561 | 
                    $this->assertEquals(quiz_attempt::IN_PROGRESS, $attemptobj->get_state());
  | 
            612 | 
                    $this->assertEquals(quiz_attempt::IN_PROGRESS, $attemptobj->get_state());
  | 
          
          
            | 562 | 
                    $this->assertEquals(0, $attemptobj->get_submitted_date());
  | 
            613 | 
                    $this->assertEquals(0, $attemptobj->get_submitted_date());
  | 
          
          
            | 563 | 
                    $this->assertEquals($user->id, $attemptobj->get_userid());
  | 
            614 | 
                    $this->assertEquals($user->id, $attemptobj->get_userid());
  | 
          
          
            | - | 
               | 
            615 | 
                    $this->assertEquals(
  | 
          
          
            | 564 | 
                    $this->assertEquals($overriddentimeclose,
  | 
            616 | 
                        $overriddentimeclose,
  | 
          
          
            | 565 | 
                            $attemptobj->get_access_manager($reopentime)->get_end_time($attemptobj->get_attempt()));
  | 
            617 | 
                        $attemptobj->get_access_manager($reopentime)->get_end_time($attemptobj->get_attempt())
  | 
          
          
            | - | 
               | 
            618 | 
                    );
  | 
          
          
            | Línea 566... | 
            Línea 619... | 
          
          
            | 566 | 
             
  | 
            619 | 
             
  | 
          
          
            | 567 | 
                    // Verify this was logged correctly.
  | 
            620 | 
                    // Verify this was logged correctly.
  | 
          
          
            | 568 | 
                    $events = $sink->get_events();
  | 
            621 | 
                    $events = $sink->get_events();
  | 
          
          
            | Línea 569... | 
            Línea 622... | 
          
          
            | 569 | 
                    $this->assertCount(1, $events);
  | 
            622 | 
                    $this->assertCount(1, $events);
  | 
          
          
            | 570 | 
             
  | 
            623 | 
             
  | 
          
          
            | 571 | 
                    $reopenedevent = array_shift($events);
  | 
            624 | 
                    $reopenedevent = array_shift($events);
  | 
          
          
            | - | 
               | 
            625 | 
                    $this->assertInstanceOf('\mod_quiz\event\attempt_reopened', $reopenedevent);
  | 
          
          
            | 572 | 
                    $this->assertInstanceOf('\mod_quiz\event\attempt_reopened', $reopenedevent);
  | 
            626 | 
                    $this->assertEquals($attemptobj->get_context(), $reopenedevent->get_context());
  | 
          
          
            | 573 | 
                    $this->assertEquals($attemptobj->get_context(), $reopenedevent->get_context());
  | 
            627 | 
                    $this->assertEquals(
  | 
          
          
            | - | 
               | 
            628 | 
                        new moodle_url('/mod/quiz/review.php', ['attempt' => $attemptobj->get_attemptid()]),
  | 
          
          
            | 574 | 
                    $this->assertEquals(new moodle_url('/mod/quiz/review.php', ['attempt' => $attemptobj->get_attemptid()]),
  | 
            629 | 
                        $reopenedevent->get_url()
  | 
          
          
            | Línea 575... | 
            Línea 630... | 
          
          
            | 575 | 
                            $reopenedevent->get_url());
  | 
            630 | 
                    );
  | 
          
          
            | 576 | 
                }
  | 
            631 | 
                }
  | 
          
          
            | 577 | 
             
  | 
            632 | 
             
  | 
          
          
            | Línea 614... | 
            Línea 669... | 
          
          
            | 614 | 
                    $this->assertEquals($user->id, $attemptobj->get_userid());
  | 
            669 | 
                    $this->assertEquals($user->id, $attemptobj->get_userid());
  | 
          
          
            | 615 | 
                    $this->assertEquals(1, $attemptobj->get_sum_marks());
  | 
            670 | 
                    $this->assertEquals(1, $attemptobj->get_sum_marks());
  | 
          
          
            | Línea 616... | 
            Línea 671... | 
          
          
            | 616 | 
             
  | 
            671 | 
             
  | 
          
          
            | 617 | 
                    // Verify this was logged correctly - there are some gradebook events between the two we want to check.
  | 
            672 | 
                    // Verify this was logged correctly - there are some gradebook events between the two we want to check.
  | 
          
          
            | 618 | 
                    $events = $sink->get_events();
  | 
            673 | 
                    $events = $sink->get_events();
  | 
          
          
            | Línea -... | 
            Línea 674... | 
          
          
            | - | 
               | 
            674 | 
                    $this->assertGreaterThanOrEqual(3, $events);
  | 
          
          
            | - | 
               | 
            675 | 
             
  | 
          
          
            | - | 
               | 
            676 | 
                    $attempturl = new moodle_url(
  | 
          
          
            | - | 
               | 
            677 | 
                        '/mod/quiz/review.php',
  | 
          
          
            | 619 | 
                    $this->assertGreaterThanOrEqual(2, $events);
  | 
            678 | 
                        ['attempt' => $attemptobj->get_attemptid()],
  | 
          
          
            | 620 | 
             
  | 
            679 | 
                    );
  | 
          
          
            | 621 | 
                    $reopenedevent = array_shift($events);
  | 
            680 | 
                    $reopenedevent = array_shift($events);
  | 
          
          
            | 622 | 
                    $this->assertInstanceOf('\mod_quiz\event\attempt_reopened', $reopenedevent);
  | 
            - | 
               | 
          
          
            | 623 | 
                    $this->assertEquals($attemptobj->get_context(), $reopenedevent->get_context());
  | 
            - | 
               | 
          
          
            | Línea -... | 
            Línea 681... | 
          
          
            | - | 
               | 
            681 | 
                    $this->assertInstanceOf('\mod_quiz\event\attempt_reopened', $reopenedevent);
  | 
          
          
            | - | 
               | 
            682 | 
                    $this->assertEquals($attemptobj->get_context(), $reopenedevent->get_context());
  | 
          
          
            | 624 | 
                    $this->assertEquals(new moodle_url('/mod/quiz/review.php', ['attempt' => $attemptobj->get_attemptid()]),
  | 
            683 | 
             
  | 
          
          
            | 625 | 
                            $reopenedevent->get_url());
  | 
            684 | 
                    $this->assertEquals($attempturl, $reopenedevent->get_url());
  | 
          
          
            | 626 | 
             
  | 
            685 | 
             
  | 
          
          
            | - | 
               | 
            686 | 
                    $submittedevent = array_shift($events);
  | 
          
          
            | - | 
               | 
            687 | 
                    $this->assertInstanceOf('\mod_quiz\event\attempt_submitted', $submittedevent);
  | 
          
          
            | - | 
               | 
            688 | 
                    $this->assertEquals($attemptobj->get_context(), $submittedevent->get_context());
  | 
          
          
            | - | 
               | 
            689 | 
             
  | 
          
          
            | - | 
               | 
            690 | 
                    $this->assertEquals($attempturl, $submittedevent->get_url());
  | 
          
          
            | 627 | 
                    $submittedevent = array_pop($events);
  | 
            691 | 
             
  | 
          
          
            | - | 
               | 
            692 | 
                    $gradedevent = array_pop($events);
  | 
          
          
            | - | 
               | 
            693 | 
                    $this->assertInstanceOf('\mod_quiz\event\attempt_graded', $gradedevent);
  | 
          
          
            | - | 
               | 
            694 | 
                    $this->assertEquals($attemptobj->get_context(), $gradedevent->get_context());
  | 
          
          
            | - | 
               | 
            695 | 
                    $this->assertEquals($attempturl, $gradedevent->get_url());
  | 
          
          
            | - | 
               | 
            696 | 
                }
  | 
          
          
            | - | 
               | 
            697 | 
             
  | 
          
          
            | - | 
               | 
            698 | 
                /**
  | 
          
          
            | - | 
               | 
            699 | 
                 * Create a quiz with questions, pre-create an attempt, edit a question, then begin the attempt.
  | 
          
          
            | - | 
               | 
            700 | 
                 */
  | 
          
          
            | - | 
               | 
            701 | 
                public function test_quiz_attempt_walkthrough_update_question_after_precreate(): void {
  | 
          
          
            | - | 
               | 
            702 | 
                    global $SITE;
  | 
          
          
            | - | 
               | 
            703 | 
             
  | 
          
          
            | - | 
               | 
            704 | 
                    $this->resetAfterTest(true);
  | 
          
          
            | - | 
               | 
            705 | 
             
  | 
          
          
            | - | 
               | 
            706 | 
                    // Make a quiz.
  | 
          
          
            | - | 
               | 
            707 | 
                    $quizgenerator = $this->getDataGenerator()->get_plugin_generator('mod_quiz');
  | 
          
          
            | - | 
               | 
            708 | 
             
  | 
          
          
            | 628 | 
                    $this->assertInstanceOf('\mod_quiz\event\attempt_submitted', $submittedevent);
  | 
            709 | 
                    $quiz = $quizgenerator->create_instance(
  | 
          
          
            | - | 
               | 
            710 | 
                        [
  | 
          
          
            | - | 
               | 
            711 | 
                            'course' => $SITE->id,
  | 
          
          
            | - | 
               | 
            712 | 
                            'questionsperpage' => 0,
  | 
          
          
            | - | 
               | 
            713 | 
                            'grade' => 100.0,
  | 
          
          
            | - | 
               | 
            714 | 
                            'sumgrades' => 3,
  | 
          
          
            | - | 
               | 
            715 | 
                        ],
  | 
          
          
            | - | 
               | 
            716 | 
                    );
  | 
          
          
            | - | 
               | 
            717 | 
             
  | 
          
          
            | - | 
               | 
            718 | 
                    // Create a couple of questions.
  | 
          
          
            | - | 
               | 
            719 | 
                    $questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question');
  | 
          
          
            | - | 
               | 
            720 | 
             
  | 
          
          
            | - | 
               | 
            721 | 
                    $cat = $questiongenerator->create_question_category();
  | 
          
          
            | - | 
               | 
            722 | 
                    $saq = $questiongenerator->create_question('shortanswer', null, ['category' => $cat->id]);
  | 
          
          
            | - | 
               | 
            723 | 
                    $numq = $questiongenerator->create_question('numerical', null, ['category' => $cat->id]);
  | 
          
          
            | - | 
               | 
            724 | 
                    $matchq = $questiongenerator->create_question('match', null, ['category' => $cat->id]);
  | 
          
          
            | - | 
               | 
            725 | 
                    $description = $questiongenerator->create_question('description', null, ['category' => $cat->id]);
  | 
          
          
            | - | 
               | 
            726 | 
             
  | 
          
          
            | - | 
               | 
            727 | 
                    // Add them to the quiz.
  | 
          
          
            | - | 
               | 
            728 | 
                    quiz_add_quiz_question($saq->id, $quiz);
  | 
          
          
            | - | 
               | 
            729 | 
                    quiz_add_quiz_question($numq->id, $quiz);
  | 
          
          
            | - | 
               | 
            730 | 
                    quiz_add_quiz_question($matchq->id, $quiz);
  | 
          
          
            | - | 
               | 
            731 | 
                    quiz_add_quiz_question($description->id, $quiz);
  | 
          
          
            | - | 
               | 
            732 | 
             
  | 
          
          
            | - | 
               | 
            733 | 
                    // Make a user to do the quiz.
  | 
          
          
            | - | 
               | 
            734 | 
                    $user1 = $this->getDataGenerator()->create_user();
  | 
          
          
            | - | 
               | 
            735 | 
             
  | 
          
          
            | - | 
               | 
            736 | 
                    $quizobj = quiz_settings::create($quiz->id, $user1->id);
  | 
          
          
            | - | 
               | 
            737 | 
             
  | 
          
          
            | - | 
               | 
            738 | 
                    // Start the attempt.
  | 
          
          
            | - | 
               | 
            739 | 
                    $quba = question_engine::make_questions_usage_by_activity('mod_quiz', $quizobj->get_context());
  | 
          
          
            | - | 
               | 
            740 | 
                    $quba->set_preferred_behaviour($quizobj->get_quiz()->preferredbehaviour);
  | 
          
          
            | - | 
               | 
            741 | 
             
  | 
          
          
            | - | 
               | 
            742 | 
                    $timenow = time();
  | 
          
          
            | - | 
               | 
            743 | 
                    $attempt = quiz_create_attempt($quizobj, 1, false, $timenow, false, $user1->id);
  | 
          
          
            | - | 
               | 
            744 | 
             
  | 
          
          
            | - | 
               | 
            745 | 
                    quiz_start_new_attempt($quizobj, $quba, $attempt, 1, $timenow);
  | 
          
          
            | - | 
               | 
            746 | 
                    $this->assertEquals('1,2,3,4,0', $attempt->layout);
  | 
          
          
            | - | 
               | 
            747 | 
             
  | 
          
          
            | - | 
               | 
            748 | 
                    quiz_attempt_save_not_started($quba, $attempt);
  | 
          
          
            | - | 
               | 
            749 | 
             
  | 
          
          
            | - | 
               | 
            750 | 
                    $attemptobj = quiz_attempt::create($attempt->id);
  | 
          
          
            | - | 
               | 
            751 | 
             
  | 
          
          
            | - | 
               | 
            752 | 
                    // Update question in quiz.
  | 
          
          
            | - | 
               | 
            753 | 
                    $newsa = $questiongenerator->update_question($saq, null,
  | 
          
          
            | - | 
               | 
            754 | 
                        ['name' => 'This is the second version of shortanswer']);
  | 
          
          
            | - | 
               | 
            755 | 
                    $newnumbq = $questiongenerator->update_question($numq, null,
  | 
          
          
            | - | 
               | 
            756 | 
                        ['name' => 'This is the second version of numerical']);
  | 
          
          
            | - | 
               | 
            757 | 
                    $newmatch = $questiongenerator->update_question($matchq, null,
  | 
          
          
            | - | 
               | 
            758 | 
                        ['name' => 'This is the second version of match']);
  | 
          
          
            | - | 
               | 
            759 | 
                    $newdescription = $questiongenerator->update_question($description, null,
  | 
          
          
            | - | 
               | 
            760 | 
                        ['name' => 'This is the second version of description']);
  | 
          
          
            | - | 
               | 
            761 | 
             
  | 
          
          
            | - | 
               | 
            762 | 
                    $this->assertEquals($saq->id, $attemptobj->get_question_attempt(1)->get_question_id());
  | 
          
          
            | - | 
               | 
            763 | 
                    $this->assertEquals($numq->id, $attemptobj->get_question_attempt(2)->get_question_id());
  | 
          
          
            | - | 
               | 
            764 | 
                    $this->assertEquals($matchq->id, $attemptobj->get_question_attempt(3)->get_question_id());
  | 
          
          
            | - | 
               | 
            765 | 
                    $this->assertEquals($description->id, $attemptobj->get_question_attempt(4)->get_question_id());
  | 
          
          
            | - | 
               | 
            766 | 
             
  | 
          
          
            | - | 
               | 
            767 | 
                    quiz_attempt_save_started($quizobj, $quba, $attempt);
  | 
          
          
            | - | 
               | 
            768 | 
             
  | 
          
          
            | - | 
               | 
            769 | 
                    // Verify that the started attempt contains the new questions.
  | 
          
          
            | - | 
               | 
            770 | 
                    $attemptobj = quiz_attempt::create($attempt->id);
  | 
          
          
            | - | 
               | 
            771 | 
                    $this->assertEquals($newsa->id, $attemptobj->get_question_attempt(1)->get_question_id());
  | 
          
          
            | 629 | 
                    $this->assertEquals($attemptobj->get_context(), $submittedevent->get_context());
  | 
            772 | 
                    $this->assertEquals($newnumbq->id, $attemptobj->get_question_attempt(2)->get_question_id());
  | 
          
          
            | 630 | 
                    $this->assertEquals(new moodle_url('/mod/quiz/review.php', ['attempt' => $attemptobj->get_attemptid()]),
  | 
            773 | 
                    $this->assertEquals($newmatch->id, $attemptobj->get_question_attempt(3)->get_question_id());
  |