Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.
   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  /**
  18   * Tests of the upgrade to the new Moodle question engine for attempts at
  19   * essay questions.
  20   *
  21   * @package    qtype
  22   * @subpackage essay
  23   * @copyright  2009 The Open University
  24   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  25   */
  26  
  27  
  28  defined('MOODLE_INTERNAL') || die();
  29  
  30  global $CFG;
  31  require_once($CFG->dirroot . '/question/engine/upgrade/tests/helper.php');
  32  
  33  
  34  /**
  35   * Testing the upgrade of essay question attempts.
  36   *
  37   * @copyright  2009 The Open University
  38   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  39   */
  40  class qtype_essay_attempt_upgrader_test extends question_attempt_upgrader_test_base {
  41  
  42      public function test_essay_deferredfeedback_history98220() {
  43          $quiz = (object) array(
  44              'id' => '4140',
  45              'course' => '5012',
  46              'name' => 'M887 Online Examination: 19th April 2010, 10am - 1pm',
  47              'intro' => '<h2>M887 Examination Paper 19th April 2010</h2>
  48  
  49          <h2>Postgraduate Computing<br />Web Systems Integration<br /></h2>
  50  
  51          <h2>Begin by pressing Start Attempt (below)</h2>',
  52              'introformat' => FORMAT_HTML,
  53              'questiondecimalpoints' => '-1',
  54              'showuserpicture' => '1',
  55              'showblocks' => '1',
  56              'timeopen' => '1271665800',
  57              'timeclose' => '1271682000',
  58              'preferredbehaviour' => 'deferredfeedback',
  59              'attempts' => '1',
  60              'attemptonlast' => '0',
  61              'grademethod' => '1',
  62              'decimalpoints' => '2',
  63              'review' => '71727591',
  64              'questionsperpage' => '1',
  65              'shufflequestions' => '0',
  66              'shuffleanswers' => '1',
  67              'sumgrades' => '100',
  68              'grade' => '100',
  69              'timecreated' => '0',
  70              'timemodified' => '1272274569',
  71              'password' => '',
  72              'subnet' => '',
  73              'popup' => '0',
  74              'delay1' => '0',
  75              'delay2' => '0',
  76              'timelimit' => '0',
  77          );
  78          $attempt = (object) array(
  79              'id' => '388325',
  80              'uniqueid' => '388326',
  81              'quiz' => '4140',
  82              'userid' => '118065',
  83              'attempt' => '1',
  84              'sumgrades' => '51',
  85              'timestart' => '1271667586',
  86              'timefinish' => '1271678351',
  87              'timemodified' => '1273069013',
  88              'layout' => '90042,0,90043,0,90045,0,90052,0,90053,0,90054,0,90055,0,90056,0,90057,0,90058,0,90059,0,90046,0,90044,0,90047,0,90048,0,90049,0',
  89              'preview' => '0',
  90          );
  91          $question = (object) array(
  92              'id' => '90056',
  93              'category' => '8619',
  94              'parent' => '0',
  95              'name' => 'Question 6',
  96              'questiontext' => '<p>
  97  
  98          <meta http-equiv="Content-Type" content="text/html; charset=utf-8"></meta><meta name="ProgId" content="Word.Document"></meta><meta name="Generator" content="Microsoft Word 11"></meta><meta name="Originator" content="Microsoft Word 11"></meta><link rel="File-List" href="file:///C:\\DOCUME~1\\pgt2\\LOCALS~1\\Temp\\msohtml1\\01\\clip_filelist.xml"></link><style></style>Give two examples of facilities within XML schemas that cannot be found in Document Type Definitions (DTDs).<br /><i>(2 marks)</i></p>',
  99              'questiontextformat' => '1',
 100              'defaultmark' => '2',
 101              'penalty' => '0',
 102              'qtype' => 'essay',
 103              'length' => '1',
 104              'stamp' => 'learn.open.ac.uk+100205101651+5eB30s',
 105              'version' => 'learn.open.ac.uk+100209161823+oZCX9n',
 106              'hidden' => '0',
 107              'generalfeedback' => '',
 108              'generalfeedbackformat' => '1',
 109              'timecreated' => '1265365011',
 110              'timemodified' => '1265732303',
 111              'createdby' => '219095',
 112              'modifiedby' => '25483',
 113              'unlimited' => '0',
 114              'maxmark' => '2',
 115              'options' => (object) array(
 116                  'answers' => array(
 117                      303772 => (object) array(
 118                          'question' => '90056',
 119                          'answer' => '',
 120                          'fraction' => '0',
 121                          'feedback' => '',
 122                          'id' => 303772,
 123                      ),
 124                  ),
 125              ),
 126              'hints' => false,
 127          );
 128          $qsession = (object) array(
 129              'id' => '3962570',
 130              'attemptid' => '388326',
 131              'questionid' => '90056',
 132              'newest' => '10517712',
 133              'newgraded' => '10517712',
 134              'sumpenalty' => '0',
 135              'manualcomment' => '',
 136              'manualcommentformat' => '1',
 137              'flagged' => '1',
 138          );
 139          $qstates = array(
 140              10094242 => (object) array(
 141                  'attempt' => '388326',
 142                  'question' => '90056',
 143                  'originalquestion' => '0',
 144                  'seq_number' => '0',
 145                  'answer' => '',
 146                  'timestamp' => '1271667586',
 147                  'event' => '0',
 148                  'grade' => '0',
 149                  'raw_grade' => '0',
 150                  'penalty' => '0',
 151                  'id' => 10094242,
 152              ),
 153              10096161 => (object) array(
 154                  'attempt' => '388326',
 155                  'question' => '90056',
 156                  'originalquestion' => '0',
 157                  'seq_number' => '1',
 158                  'answer' => '<p>Variable typeing</p>
 159          <p>Namespaces</p>',
 160                  'timestamp' => '1271670445',
 161                  'event' => '2',
 162                  'grade' => '0',
 163                  'raw_grade' => '0',
 164                  'penalty' => '0',
 165                  'id' => 10096161,
 166              ),
 167              10097144 => (object) array(
 168                  'attempt' => '388326',
 169                  'question' => '90056',
 170                  'originalquestion' => '0',
 171                  'seq_number' => '2',
 172                  'answer' => '<p>Variable can be typed</p>
 173          <p>xml Schemas fully support Namespaces</p>',
 174                  'timestamp' => '1271671440',
 175                  'event' => '2',
 176                  'grade' => '0',
 177                  'raw_grade' => '0',
 178                  'penalty' => '0',
 179                  'id' => 10097144,
 180              ),
 181              10103710 => (object) array(
 182                  'attempt' => '388326',
 183                  'question' => '90056',
 184                  'originalquestion' => '0',
 185                  'seq_number' => '3',
 186                  'answer' => '<p>Variable can be typed</p>
 187          <p>xml Schemas fully support Namespaces</p>',
 188                  'timestamp' => '1271671440',
 189                  'event' => '8',
 190                  'grade' => '0',
 191                  'raw_grade' => '0',
 192                  'penalty' => '0',
 193                  'id' => 10103710,
 194              ),
 195              10517712 => (object) array(
 196                  'attempt' => '388326',
 197                  'question' => '90056',
 198                  'originalquestion' => '0',
 199                  'seq_number' => '4',
 200                  'answer' => '<p>Variable can be typed</p>
 201          <p>xml Schemas fully support Namespaces</p>',
 202                  'timestamp' => '1273068477',
 203                  'event' => '9',
 204                  'grade' => '2',
 205                  'raw_grade' => '2',
 206                  'penalty' => '0',
 207                  'id' => 10517712,
 208              ),
 209          );
 210  
 211          $qa = $this->updater->convert_question_attempt($quiz, $attempt, $question, $qsession, $qstates);
 212  
 213          $expectedqa = (object) array(
 214              'behaviour' => 'manualgraded',
 215              'questionid' => 90056,
 216              'variant' => 1,
 217              'maxmark' => 2,
 218              'minfraction' => 0,
 219              'maxfraction' => 1,
 220              'flagged' => 0,
 221              'questionsummary' => "Give two examples of facilities within XML schemas that cannot be found in Document Type Definitions (DTDs).\n_(2 marks)_",
 222              'rightanswer' => '',
 223              'responsesummary' => "Variable can be typed \n\nxml Schemas fully support Namespaces",
 224              'timemodified' => 1273068477,
 225              'steps' => array(
 226                  0 => (object) array(
 227                      'sequencenumber' => 0,
 228                      'state' => 'todo',
 229                      'fraction' => null,
 230                      'timecreated' => 1271667586,
 231                      'userid' => 118065,
 232                      'data' => array(),
 233                  ),
 234                  1 => (object) array(
 235                      'sequencenumber' => 1,
 236                      'state' => 'complete',
 237                      'fraction' => null,
 238                      'timecreated' => 1271670445,
 239                      'userid' => 118065,
 240                      'data' => array('answer' => '<p>Variable typeing</p>
 241          <p>Namespaces</p>', 'answerformat' => FORMAT_HTML),
 242                  ),
 243                  2 => (object) array(
 244                      'sequencenumber' => 2,
 245                      'state' => 'complete',
 246                      'fraction' => null,
 247                      'timecreated' => 1271671440,
 248                      'userid' => 118065,
 249                      'data' => array('answer' => '<p>Variable can be typed</p>
 250          <p>xml Schemas fully support Namespaces</p>', 'answerformat' => FORMAT_HTML),
 251                  ),
 252                  3 => (object) array(
 253                      'sequencenumber' => 3,
 254                      'state' => 'needsgrading',
 255                      'fraction' => null,
 256                      'timecreated' => 1271671440,
 257                      'userid' => 118065,
 258                      'data' => array('answer' => '<p>Variable can be typed</p>
 259          <p>xml Schemas fully support Namespaces</p>', '-finish' => 1, 'answerformat' => FORMAT_HTML),
 260                  ),
 261                  4 => (object) array(
 262                      'sequencenumber' => 4,
 263                      'state' => 'mangrright',
 264                      'fraction' => 1,
 265                      'timecreated' => 1273068477,
 266                      'userid' => null,
 267                      'data' => array('-comment' => '', '-mark' => 2, '-maxmark' => 2, 'answerformat' => FORMAT_HTML),
 268                  ),
 269              ),
 270          );
 271  
 272          $this->compare_qas($expectedqa, $qa);
 273      }
 274  
 275      public function test_essay_deferredfeedback_history820() {
 276          $quiz = (object) array(
 277              'id' => '142',
 278              'course' => '187',
 279              'name' => 'Questionnaire',
 280              'intro' => '<p>B680 is pioneering the use of the eAssessment module in the OU VLE (Virtual Learning Environment). We believe that the module is fit for purpose but we need users\' (students and ALs) experience to confirm this. Your answers to this short questionnaire therefore are of wide importance to the OU VLE Development Programme.  If you could complete this short questionnaire after attempting Practice CTMA04 <b></b>it would be greatly appreciated.</p>
 281          <p>The questionnaire has 15 questions and we would like you to answer as many of these as possible.  When you have completed your answers you will see a End test button, similar to the one in Practice CTMA 04, which you will need to click.  This will move you to a Summary page.  Please click the \'Submit all and finish\' button when you are happy to submit your final answers.  <strong>Please complete the questionnaire only once.</strong>  At a later stage the B680 Course Team will analyse the students\' answers to the questions. <br /></p>',
 282              'introformat' => FORMAT_HTML,
 283              'questiondecimalpoints' => '-1',
 284              'showuserpicture' => '1',
 285              'showblocks' => '1',
 286              'timeopen' => '0',
 287              'timeclose' => '0',
 288              'preferredbehaviour' => 'deferredfeedback',
 289              'attempts' => '0',
 290              'attemptonlast' => '0',
 291              'grademethod' => '1',
 292              'decimalpoints' => '2',
 293              'review' => '71727591',
 294              'questionsperpage' => '1',
 295              'shufflequestions' => '0',
 296              'shuffleanswers' => '0',
 297              'sumgrades' => '0',
 298              'grade' => '0',
 299              'timecreated' => '0',
 300              'timemodified' => '1178202609',
 301              'password' => '',
 302              'subnet' => '',
 303              'popup' => '0',
 304              'delay1' => '0',
 305              'delay2' => '0',
 306              'timelimit' => '0',
 307          );
 308          $attempt = (object) array(
 309              'id' => '4246',
 310              'uniqueid' => '4246',
 311              'quiz' => '142',
 312              'userid' => '96864',
 313              'attempt' => '1',
 314              'sumgrades' => '0',
 315              'timestart' => '1179134211',
 316              'timefinish' => '1179134998',
 317              'timemodified' => '1179134869',
 318              'layout' => '3664,3716,0,3663,3717,0,3718,3719,0,3720,0,3733,3727,0,3728,3730,0,3731,3732,0,3726,3729,0',
 319              'preview' => '0',
 320          );
 321          $question = (object) array(
 322              'id' => '3729',
 323              'category' => '163',
 324              'parent' => '0',
 325              'name' => 'Question 98',
 326              'questiontext' => 'If you answered ‘No’ to the previous question please expand on your problem here.<br /><b></b><br />',
 327              'questiontextformat' => '1',
 328              'defaultmark' => '0',
 329              'penalty' => '0',
 330              'qtype' => 'essay',
 331              'length' => '1',
 332              'stamp' => 'learn.open.ac.uk+070312094434+k2HaUF',
 333              'version' => 'learn.open.ac.uk+070501173219+spx2IM',
 334              'hidden' => '0',
 335              'generalfeedback' => '',
 336              'generalfeedbackformat' => '1',
 337              'timecreated' => '0',
 338              'timemodified' => '0',
 339              'createdby' => null,
 340              'modifiedby' => null,
 341              'unlimited' => null,
 342              'maxmark' => '0',
 343              'options' => (object) array(
 344                  'answers' => array(
 345                      11264 => (object) array(
 346                          'question' => '3729',
 347                          'answer' => '',
 348                          'fraction' => '0',
 349                          'feedback' => '',
 350                          'id' => 11264,
 351                      ),
 352                  ),
 353              ),
 354              'hints' => false,
 355          );
 356          $qsession = (object) array(
 357              'id' => '47133',
 358              'attemptid' => '4246',
 359              'questionid' => '3729',
 360              'newest' => '107502',
 361              'newgraded' => '107407',
 362              'sumpenalty' => '0',
 363              'manualcomment' => '',
 364              'manualcommentformat' => '1',
 365              'flagged' => '1',
 366          );
 367          $qstates = array(
 368              107407 => (object) array(
 369                  'attempt' => '4246',
 370                  'question' => '3729',
 371                  'originalquestion' => '0',
 372                  'seq_number' => '0',
 373                  'answer' => '',
 374                  'timestamp' => '1179134211',
 375                  'event' => '0',
 376                  'grade' => '0',
 377                  'raw_grade' => '0',
 378                  'penalty' => '0',
 379                  'id' => 107407,
 380              ),
 381              107484 => (object) array(
 382                  'attempt' => '4246',
 383                  'question' => '3729',
 384                  'originalquestion' => '0',
 385                  'seq_number' => '1',
 386                  'answer' => 'it would be better to point our a \'red colour\' on the number which indicates the questions that we have done wrong. similar to previously, from question 1 to 10, green colour shows the right answer and red colour shows the wrong answer, so that we do not need to click on each answer to find out if it is right or wrong.',
 387                  'timestamp' => '1179134869',
 388                  'event' => '2',
 389                  'grade' => '0',
 390                  'raw_grade' => '0',
 391                  'penalty' => '0',
 392                  'id' => 107484,
 393              ),
 394              107502 => (object) array(
 395                  'attempt' => '4246',
 396                  'question' => '3729',
 397                  'originalquestion' => '0',
 398                  'seq_number' => '2',
 399                  'answer' => 'it would be better to point our a \'red colour\' on the number which indicates the questions that we have done wrong. similar to previously, from question 1 to 10, green colour shows the right answer and red colour shows the wrong answer, so that we do not need to click on each answer to find out if it is right or wrong.',
 400                  'timestamp' => '1179134869',
 401                  'event' => '8',
 402                  'grade' => '0',
 403                  'raw_grade' => '0',
 404                  'penalty' => '0',
 405                  'id' => 107502,
 406              ),
 407          );
 408  
 409          $qa = $this->updater->convert_question_attempt($quiz, $attempt, $question, $qsession, $qstates);
 410  
 411          $expectedqa = (object) array(
 412              'behaviour' => 'manualgraded',
 413              'questionid' => 3729,
 414              'variant' => 1,
 415              'maxmark' => 0,
 416              'minfraction' => 0,
 417              'maxfraction' => 1,
 418              'flagged' => 0,
 419              'questionsummary' => "If you answered ‘No’ to the previous question please expand on your problem here.",
 420              'rightanswer' => '',
 421              'responsesummary' => 'it would be better to point our a \'red colour\' on the number which indicates the questions that we have done wrong. similar to previously, from question 1 to 10, green colour shows the right answer and red colour shows the wrong answer, so that we do not need to click on each answer to find out if it is right or wrong.',
 422              'timemodified' => 1179134869,
 423              'steps' => array(
 424                  0 => (object) array(
 425                      'sequencenumber' => 0,
 426                      'state' => 'todo',
 427                      'fraction' => null,
 428                      'timecreated' => 1179134211,
 429                      'userid' => 96864,
 430                      'data' => array(),
 431                  ),
 432                  1 => (object) array(
 433                      'sequencenumber' => 1,
 434                      'state' => 'complete',
 435                      'fraction' => null,
 436                      'timecreated' => 1179134869,
 437                      'userid' => 96864,
 438                      'data' => array('answer' => 'it would be better to point our a \'red colour\' on the number which indicates the questions that we have done wrong. similar to previously, from question 1 to 10, green colour shows the right answer and red colour shows the wrong answer, so that we do not need to click on each answer to find out if it is right or wrong.', 'answerformat' => FORMAT_HTML),
 439                  ),
 440                  2 => (object) array(
 441                      'sequencenumber' => 2,
 442                      'state' => 'needsgrading',
 443                      'fraction' => null,
 444                      'timecreated' => 1179134869,
 445                      'userid' => 96864,
 446                      'data' => array('-finish' => 1, 'answer' => 'it would be better to point our a \'red colour\' on the number which indicates the questions that we have done wrong. similar to previously, from question 1 to 10, green colour shows the right answer and red colour shows the wrong answer, so that we do not need to click on each answer to find out if it is right or wrong.', 'answerformat' => FORMAT_HTML),
 447                  ),
 448              ),
 449          );
 450  
 451          $this->compare_qas($expectedqa, $qa);
 452      }
 453  
 454      public function test_essay_deferredfeedback_missing() {
 455          $quiz = (object) array(
 456              'id' => '142',
 457              'course' => '187',
 458              'name' => 'Questionnaire',
 459              'intro' => '<p>B680 is pioneering the use of the eAssessment module in the OU VLE (Virtual Learning Environment). We believe that the module is fit for purpose but we need users\' (students and ALs) experience to confirm this. Your answers to this short questionnaire therefore are of wide importance to the OU VLE Development Programme.  If you could complete this short questionnaire after attempting Practice CTMA04 <b></b>it would be greatly appreciated.</p>
 460          <p>The questionnaire has 15 questions and we would like you to answer as many of these as possible.  When you have completed your answers you will see a End test button, similar to the one in Practice CTMA 04, which you will need to click.  This will move you to a Summary page.  Please click the \'Submit all and finish\' button when you are happy to submit your final answers.  <strong>Please complete the questionnaire only once.</strong>  At a later stage the B680 Course Team will analyse the students\' answers to the questions. <br /></p>',
 461              'introformat' => FORMAT_HTML,
 462              'questiondecimalpoints' => '-1',
 463              'showuserpicture' => '1',
 464              'showblocks' => '1',
 465              'timeopen' => '0',
 466              'timeclose' => '0',
 467              'preferredbehaviour' => 'deferredfeedback',
 468              'attempts' => '0',
 469              'attemptonlast' => '0',
 470              'grademethod' => '1',
 471              'decimalpoints' => '2',
 472              'review' => '71727591',
 473              'questionsperpage' => '1',
 474              'shufflequestions' => '0',
 475              'shuffleanswers' => '0',
 476              'sumgrades' => '0',
 477              'grade' => '0',
 478              'timecreated' => '0',
 479              'timemodified' => '1178202609',
 480              'password' => '',
 481              'subnet' => '',
 482              'popup' => '0',
 483              'delay1' => '0',
 484              'delay2' => '0',
 485              'timelimit' => '0',
 486          );
 487          $attempt = (object) array(
 488              'id' => '4246',
 489              'uniqueid' => '4246',
 490              'quiz' => '142',
 491              'userid' => '96864',
 492              'attempt' => '1',
 493              'sumgrades' => '0',
 494              'timestart' => '1179134211',
 495              'timefinish' => '1179134998',
 496              'timemodified' => '1179134869',
 497              'layout' => '3664,3716,0,3663,3717,0,3718,3719,0,3720,0,3733,3727,0,3728,3730,0,3731,3732,0,3726,3729,0',
 498              'preview' => '0',
 499          );
 500          $question = (object) array(
 501              'id' => '3729',
 502              'category' => '163',
 503              'parent' => '0',
 504              'name' => 'Question 98',
 505              'questiontext' => 'If you answered ‘No’ to the previous question please expand on your problem here.<br /><b></b><br />',
 506              'questiontextformat' => '1',
 507              'defaultmark' => '0',
 508              'penalty' => '0',
 509              'qtype' => 'essay',
 510              'length' => '1',
 511              'stamp' => 'learn.open.ac.uk+070312094434+k2HaUF',
 512              'version' => 'learn.open.ac.uk+070501173219+spx2IM',
 513              'hidden' => '0',
 514              'generalfeedback' => '',
 515              'generalfeedbackformat' => '1',
 516              'timecreated' => '0',
 517              'timemodified' => '0',
 518              'createdby' => null,
 519              'modifiedby' => null,
 520              'unlimited' => null,
 521              'maxmark' => '0',
 522              'options' => (object) array(
 523                  'answers' => array(
 524                      11264 => (object) array(
 525                          'question' => '3729',
 526                          'answer' => '',
 527                          'fraction' => '0',
 528                          'feedback' => '',
 529                          'id' => 11264,
 530                      ),
 531                  ),
 532              ),
 533              'hints' => false,
 534          );
 535  
 536          $qa = $this->updater->supply_missing_question_attempt( $quiz, $attempt, $question);
 537  
 538          $expectedqa = (object) array(
 539              'behaviour' => 'manualgraded',
 540              'questionid' => 3729,
 541              'variant' => 1,
 542              'maxmark' => 0,
 543              'minfraction' => 0,
 544              'maxfraction' => 1,
 545              'flagged' => 0,
 546              'questionsummary' => "If you answered ‘No’ to the previous question please expand on your problem here.",
 547              'rightanswer' => '',
 548              'responsesummary' => '',
 549              'timemodified' => 1179134211,
 550              'steps' => array(
 551                  0 => (object) array(
 552                      'sequencenumber' => 0,
 553                      'state' => 'todo',
 554                      'fraction' => null,
 555                      'timecreated' => 1179134211,
 556                      'userid' => 96864,
 557                      'data' => array(),
 558                  ),
 559              ),
 560          );
 561  
 562          $this->compare_qas($expectedqa, $qa);
 563      }
 564  }