Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is 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  namespace qtype_description;
  18  
  19  defined('MOODLE_INTERNAL') || die();
  20  
  21  global $CFG;
  22  require_once($CFG->dirroot . '/question/engine/upgrade/tests/helper.php');
  23  
  24  
  25  /**
  26   * Testing the upgrade of description question attempts.
  27   *
  28   * @package    qtype_description
  29   * @copyright  2009 The Open University
  30   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  31   */
  32  class upgrade_old_attempt_data_test extends \question_attempt_upgrader_test_base {
  33  
  34      public function test_description_deferredfeedback_history80() {
  35          $quiz = (object) array(
  36              'id' => '278',
  37              'course' => '2950',
  38              'name' => 'test quiz 1',
  39              'intro' => 'my demonstration quiz ',
  40              'introformat' => FORMAT_HTML,
  41              'questiondecimalpoints' => '-1',
  42              'showuserpicture' => '1',
  43              'showblocks' => '1',
  44              'timeopen' => '0',
  45              'timeclose' => '0',
  46              'preferredbehaviour' => 'deferredfeedback',
  47              'attempts' => '0',
  48              'attemptonlast' => '0',
  49              'grademethod' => '1',
  50              'decimalpoints' => '2',
  51              'review' => '71727591',
  52              'questionsperpage' => '1',
  53              'shufflequestions' => '0',
  54              'shuffleanswers' => '1',
  55              'sumgrades' => '5',
  56              'grade' => '10',
  57              'timecreated' => '0',
  58              'timemodified' => '1178101987',
  59              'password' => '',
  60              'subnet' => '',
  61              'popup' => '0',
  62              'delay1' => '0',
  63              'delay2' => '0',
  64              'timelimit' => '0',
  65          );
  66          $attempt = (object) array(
  67              'id' => '6802',
  68              'uniqueid' => '6802',
  69              'quiz' => '278',
  70              'userid' => '13',
  71              'attempt' => '1',
  72              'sumgrades' => '2.33333',
  73              'timestart' => '1185289572',
  74              'timefinish' => '1185289637',
  75              'timemodified' => '1185289590',
  76              'layout' => '4940,0,5043,0,4945,0,4942,0,5566,0',
  77              'preview' => '1',
  78          );
  79          $question = (object) array(
  80              'id' => '4940',
  81              'category' => '247',
  82              'parent' => '0',
  83              'name' => 'Northampton Gallery Case Study',
  84              'questiontext' => 'The following questions are based on the Northampton Art Gallery case study and associated web links.  The questions cover artists and works that were available during the study weeks for Block 3.  Some items may no longer be available on websites but will be available in the readings for Block 3.',
  85              'questiontextformat' => '1',
  86              'defaultmark' => '0',
  87              'penalty' => '0',
  88              'qtype' => 'description',
  89              'length' => '1',
  90              'stamp' => 'learn.open.ac.uk+070501114616+rtsfKk',
  91              'version' => 'learn.open.ac.uk+070501114616+ZY94d5',
  92              'hidden' => '0',
  93              'generalfeedback' => '',
  94              'generalfeedbackformat' => '1',
  95              'timecreated' => '0',
  96              'timemodified' => '0',
  97              'createdby' => null,
  98              'modifiedby' => null,
  99              'unlimited' => null,
 100              'maxmark' => '1',
 101          );
 102          $qsession = (object) array(
 103              'id' => '130459',
 104              'attemptid' => '6802',
 105              'questionid' => '4940',
 106              'newest' => '297740',
 107              'newgraded' => '297730',
 108              'sumpenalty' => '0',
 109              'manualcomment' => '',
 110              'manualcommentformat' => '1',
 111              'flagged' => '1',
 112          );
 113          $qstates = array(
 114              297730 => (object) array(
 115                  'attempt' => '6802',
 116                  'question' => '4940',
 117                  'originalquestion' => '0',
 118                  'seq_number' => '0',
 119                  'answer' => '',
 120                  'timestamp' => '1185289572',
 121                  'event' => '0',
 122                  'grade' => '0',
 123                  'raw_grade' => '0',
 124                  'penalty' => '0',
 125                  'id' => 297730,
 126              ),
 127              297740 => (object) array(
 128                  'attempt' => '6802',
 129                  'question' => '4940',
 130                  'originalquestion' => '0',
 131                  'seq_number' => '1',
 132                  'answer' => '',
 133                  'timestamp' => '1185289572',
 134                  'event' => '8',
 135                  'grade' => '0',
 136                  'raw_grade' => '0',
 137                  'penalty' => '0',
 138                  'id' => 297740,
 139              ),
 140          );
 141  
 142          $qa = $this->updater->convert_question_attempt($quiz, $attempt, $question, $qsession, $qstates);
 143  
 144          $expectedqa = (object) array(
 145              'behaviour' => 'informationitem',
 146              'questionid' => 4940,
 147              'variant' => 1,
 148              'maxmark' => 1,
 149              'minfraction' => 0,
 150              'maxfraction' => 1,
 151              'flagged' => 0,
 152              'questionsummary' => 'The following questions are based on the Northampton Art Gallery case study and associated web links. The questions cover artists and works that were available during the study weeks for Block 3. Some items may no longer be available on websites but will be available in the readings for Block 3.',
 153              'rightanswer' => '',
 154              'responsesummary' => '',
 155              'timemodified' => 1185289572,
 156              'steps' => array(
 157                  0 => (object) array(
 158                      'sequencenumber' => 0,
 159                      'state' => 'todo',
 160                      'fraction' => null,
 161                      'timecreated' => 1185289572,
 162                      'userid' => 13,
 163                      'data' => array(),
 164                  ),
 165                  1 => (object) array(
 166                      'sequencenumber' => 1,
 167                      'state' => 'finished',
 168                      'fraction' => null,
 169                      'timecreated' => 1185289572,
 170                      'userid' => 13,
 171                      'data' => array('-finish' => 1),
 172                  ),
 173              ),
 174          );
 175  
 176          $this->compare_qas($expectedqa, $qa);
 177      }
 178  
 179      public function test_description_deferredfeedback_history70() {
 180          $quiz = (object) array(
 181              'id' => '442',
 182              'course' => '2591',
 183              'name' => 'Needs Analysis (online version)',
 184              'intro' => '<h3>Information </h3>The purpose of the Needs Analysis is to help you identify your professional development needs and those programme modules which will best address them. <br /><br />This Needs Analysis will form the basis of a discussion with your mentor from which will emerge your Professional Development Plan (PDP). Identifying professional development needs is an integral part of the process of professional development. The PDP and the subsequent professional development opportunities it identifies will be effective only if the Needs Analysis is completed fully and accurately. You will get much more out of the programme if you give plenty of time at this early stage to the Needs Analysis. <br /><br /><h3>1. Personal and Professional Information</h3>In addition to personal information you will be asked to outline any professional qualifications and experience to date. <br /><br /><h3>2. Professional and Musical Skills</h3>In this section you will be asked to record your skills, knowledge and experience against a range of professional activities which closely relate to the focus of the music CPD programme. You will be asked to provide brief examples of evidence of those areas in which you have significant experience. <br /><br /><h3>3. Issues in Music Teaching and Learning</h3>This section is organised under three areas: Learning Musically, Teaching Musically and Making Music. <br /><br />In this section we ask you to audit your knowledge, skills and understanding against the key issues covered by the online and face-to-face module units. You will be invited to identify your strengths and provide evidence of your experience and understanding. <br /><br />',
 185              'introformat' => FORMAT_HTML,
 186              'questiondecimalpoints' => '-1',
 187              'showuserpicture' => '1',
 188              'showblocks' => '1',
 189              'timeopen' => '0',
 190              'timeclose' => '0',
 191              'preferredbehaviour' => 'deferredfeedback',
 192              'attempts' => '1',
 193              'attemptonlast' => '0',
 194              'grademethod' => '1',
 195              'decimalpoints' => '2',
 196              'review' => '71719269',
 197              'questionsperpage' => '1',
 198              'shufflequestions' => '0',
 199              'shuffleanswers' => '0',
 200              'sumgrades' => '0',
 201              'grade' => '10',
 202              'timecreated' => '0',
 203              'timemodified' => '1202212400',
 204              'password' => '',
 205              'subnet' => '',
 206              'popup' => '0',
 207              'delay1' => '0',
 208              'delay2' => '0',
 209              'timelimit' => '0',
 210          );
 211          $attempt = (object) array(
 212              'id' => '11230',
 213              'uniqueid' => '11230',
 214              'quiz' => '442',
 215              'userid' => '193184',
 216              'attempt' => '1',
 217              'sumgrades' => '0',
 218              'timestart' => '1192648793',
 219              'timefinish' => '1192742609',
 220              'timemodified' => '1192742300',
 221              'layout' => '8492,0,8487,8488,8489,8490,0,8441,0,8443,0,8486,0,8444,0,8445,0,8494,0,8446,8429,0,8447,8430,0,8448,8431,0,8449,8432,0,8450,8433,0,8451,8434,0,8452,8435,0,8453,8436,0,8454,8437,0,8493,0,8455,8456,8457,0,8458,8459,8460,0,8461,8462,8463,8438,0,8464,8465,8466,0,8467,8468,8469,0,8470,8471,8472,8439,0,8473,8440,0,8474,8475,8476,0,8477,8478,8479,0,8480,8481,8482,0,8483,8484,8485,8442,0',
 222              'preview' => '0',
 223          );
 224          $question = (object) array(
 225              'id' => '8492',
 226              'category' => '131',
 227              'parent' => '0',
 228              'name' => 'Personal and Professional Information',
 229              'questiontext' => '<h3>Personal and Professional Information</h3><br />Here we want you to enter personal information and outline your professional qualifications and experience to date.',
 230              'questiontextformat' => '1',
 231              'defaultmark' => '0',
 232              'penalty' => '0',
 233              'qtype' => 'description',
 234              'length' => '0',
 235              'stamp' => 'learn.open.ac.uk+070808083925+qTmPpB',
 236              'version' => 'learn.open.ac.uk+070907143809+3ltY7I',
 237              'hidden' => '0',
 238              'generalfeedback' => '',
 239              'generalfeedbackformat' => '1',
 240              'timecreated' => '0',
 241              'timemodified' => '0',
 242              'createdby' => null,
 243              'modifiedby' => null,
 244              'unlimited' => null,
 245              'maxmark' => '0',
 246          );
 247          $qsession = (object) array(
 248              'id' => '206424',
 249              'attemptid' => '11230',
 250              'questionid' => '8492',
 251              'newest' => '480877',
 252              'newgraded' => '476039',
 253              'sumpenalty' => '0',
 254              'manualcomment' => '',
 255              'manualcommentformat' => '1',
 256              'flagged' => '1',
 257          );
 258          $qstates = array(
 259              476039 => (object) array(
 260                  'attempt' => '11230',
 261                  'question' => '8492',
 262                  'originalquestion' => '0',
 263                  'seq_number' => '0',
 264                  'answer' => '',
 265                  'timestamp' => '1192648793',
 266                  'event' => '0',
 267                  'grade' => '0',
 268                  'raw_grade' => '0',
 269                  'penalty' => '0',
 270                  'id' => 476039,
 271              ),
 272              480877 => (object) array(
 273                  'attempt' => '11230',
 274                  'question' => '8492',
 275                  'originalquestion' => '0',
 276                  'seq_number' => '1',
 277                  'answer' => '',
 278                  'timestamp' => '1192648793',
 279                  'event' => '7',
 280                  'grade' => '0',
 281                  'raw_grade' => '0',
 282                  'penalty' => '0',
 283                  'id' => 480877,
 284              ),
 285          );
 286  
 287          $qa = $this->updater->convert_question_attempt($quiz, $attempt, $question, $qsession, $qstates);
 288  
 289          $expectedqa = (object) array(
 290              'behaviour' => 'informationitem',
 291              'questionid' => 8492,
 292              'variant' => 1,
 293              'maxmark' => 0,
 294              'minfraction' => 0,
 295              'maxfraction' => 1,
 296              'flagged' => 0,
 297              'questionsummary' => "PERSONAL AND PROFESSIONAL INFORMATION\n\nHere we want you to enter personal information and outline your professional qualifications and experience to date.",
 298              'rightanswer' => '',
 299              'responsesummary' => '',
 300              'timemodified' => 1192648793,
 301              'steps' => array(
 302                  0 => (object) array(
 303                      'sequencenumber' => 0,
 304                      'state' => 'todo',
 305                      'fraction' => null,
 306                      'timecreated' => 1192648793,
 307                      'userid' => 193184,
 308                      'data' => array(),
 309                  ),
 310                  1 => (object) array(
 311                      'sequencenumber' => 1,
 312                      'state' => 'finished',
 313                      'fraction' => null,
 314                      'timecreated' => 1192648793,
 315                      'userid' => 193184,
 316                      'data' => array('-finish' => 1),
 317                  ),
 318              ),
 319          );
 320  
 321          $this->compare_qas($expectedqa, $qa);
 322      }
 323  
 324      public function test_description_deferredfeedback_history0() {
 325          $quiz = (object) array(
 326              'id' => '466',
 327              'course' => '3464',
 328              'name' => 'Music CPD Needs Analysis',
 329              'intro' => '<h3>Information </h3>The purpose of the Needs Analysis is to help you identify your professional development needs and those programme modules which will best address them. <br /><br />This Needs Analysis will form the basis of a discussion with your mentor from which will emerge your Professional Development Plan (PDP). Identifying professional development needs is an integral part of the process of professional development. The PDP and the subsequent professional development opportunities it identifies will be effective only if the Needs Analysis is completed fully and accurately. You will get much more out of the programme if you give plenty of time at this early stage to the Needs Analysis. <br /><br />
 330          <h3>1. Personal and Professional Information</h3>In addition to personal information you will be asked to outline any professional qualifications and experience to date. <br /><br />
 331          <h3>2. Professional and Musical Skills</h3>In this section you will be asked to record your skills, knowledge and experience against a range of professional activities which closely relate to the focus of the music CPD programme. You will be asked to provide brief examples of evidence of those areas in which you have significant experience. <br /><br />
 332          <h3>3. Issues in Music Teaching and Learning</h3>This section is organised under three areas: Learning Musically, Teaching Musically and Making Music. <br /><br />In this section we ask you to audit your knowledge, skills and understanding against the key issues covered by the online and face-to-face module units. You will be invited to identify your strengths and provide evidence of your experience and understanding. <br /> <br />',
 333              'introformat' => FORMAT_HTML,
 334              'questiondecimalpoints' => '-1',
 335              'showuserpicture' => '1',
 336              'showblocks' => '1',
 337              'timeopen' => '0',
 338              'timeclose' => '0',
 339              'preferredbehaviour' => 'deferredfeedback',
 340              'attempts' => '1',
 341              'attemptonlast' => '0',
 342              'grademethod' => '1',
 343              'decimalpoints' => '2',
 344              'review' => '71719269',
 345              'questionsperpage' => '1',
 346              'shufflequestions' => '0',
 347              'shuffleanswers' => '0',
 348              'sumgrades' => '0',
 349              'grade' => '10',
 350              'timecreated' => '0',
 351              'timemodified' => '1184685800',
 352              'password' => '',
 353              'subnet' => '',
 354              'popup' => '0',
 355              'delay1' => '0',
 356              'delay2' => '0',
 357              'timelimit' => '0',
 358          );
 359          $attempt = (object) array(
 360              'id' => '7401',
 361              'uniqueid' => '7401',
 362              'quiz' => '466',
 363              'userid' => '24474',
 364              'attempt' => '1',
 365              'sumgrades' => '0',
 366              'timestart' => '1187168654',
 367              'timefinish' => '0',
 368              'timemodified' => '1187168769',
 369              'layout' => '8691,0,8690,8692,8693,8694,0,8695,0,8696,0,8697,0,8698,0,8699,0,8700,0,8701,8702,0,8703,8704,0,8705,8706,0,8707,8708,0,8709,8710,0,8711,8712,0,8713,8714,0,8715,8716,0,8717,8718,0,8719,0,8720,8721,8722,0,8723,8724,8725,0,8726,8727,8728,8729,0,8730,8731,8732,0,8733,8734,8735,0,8736,8737,8738,8739,0,8740,8741,0,8742,8743,8744,0,8745,8746,8747,0,8748,8749,8750,0,8752,8751,8753,8754,0',
 370              'preview' => '1',
 371          );
 372          $question = (object) array(
 373              'id' => '8719',
 374              'category' => '427',
 375              'parent' => '0',
 376              'name' => 'Music Teaching and Learning',
 377              'questiontext' => '<h3>Music Teaching and Learning </h3><br />In this section we ask you to audit your knowledge, skills and understanding against the key issues covered by the non-core online and face-to-face module units. You will be invited to identify your strengths and provide evidence of your experience and understanding.<br /><br />In this set of questions, you should select from the drop-down menu ‘None’, ‘Some’, ‘Good’ or ‘Strong’.<br /><br />',
 378              'questiontextformat' => '1',
 379              'defaultmark' => '0',
 380              'penalty' => '0',
 381              'qtype' => 'description',
 382              'length' => '0',
 383              'stamp' => 'learn.open.ac.uk+070430145701+r8LVld',
 384              'version' => 'learn.open.ac.uk+070430145834+FxIAjw',
 385              'hidden' => '0',
 386              'generalfeedback' => '',
 387              'generalfeedbackformat' => '1',
 388              'timecreated' => '0',
 389              'timemodified' => '0',
 390              'createdby' => null,
 391              'modifiedby' => null,
 392              'unlimited' => null,
 393              'maxmark' => '0',
 394          );
 395          $qsession = (object) array(
 396              'id' => '157658',
 397              'attemptid' => '7401',
 398              'questionid' => '8719',
 399              'newest' => '361166',
 400              'newgraded' => '361166',
 401              'sumpenalty' => '0',
 402              'manualcomment' => '',
 403              'manualcommentformat' => '1',
 404              'flagged' => '1',
 405          );
 406          $qstates = array(
 407              361166 => (object) array(
 408                  'attempt' => '7401',
 409                  'question' => '8719',
 410                  'originalquestion' => '0',
 411                  'seq_number' => '0',
 412                  'answer' => '',
 413                  'timestamp' => '1187168654',
 414                  'event' => '0',
 415                  'grade' => '0',
 416                  'raw_grade' => '0',
 417                  'penalty' => '0',
 418                  'id' => 361166,
 419              ),
 420          );
 421  
 422          $qa = $this->updater->convert_question_attempt($quiz, $attempt, $question, $qsession, $qstates);
 423  
 424          $expectedqa = (object) array(
 425              'behaviour' => 'informationitem',
 426              'questionid' => 8719,
 427              'variant' => 1,
 428              'maxmark' => 0,
 429              'minfraction' => 0,
 430              'maxfraction' => 1,
 431              'flagged' => 0,
 432              'questionsummary' => "MUSIC TEACHING AND LEARNING \n\nIn this section we ask you to audit your knowledge, skills and understanding against the key issues covered by the non-core online and face-to-face module units. You will be invited to identify your strengths and provide evidence of your experience and understanding.\n\nIn this set of questions, you should select from the drop-down menu ‘None’, ‘Some’, ‘Good’ or ‘Strong’.",
 433              'rightanswer' => '',
 434              'responsesummary' => '',
 435              'timemodified' => 1187168654,
 436              'steps' => array(
 437                  0 => (object) array(
 438                      'sequencenumber' => 0,
 439                      'state' => 'todo',
 440                      'fraction' => null,
 441                      'timecreated' => 1187168654,
 442                      'userid' => 24474,
 443                      'data' => array(),
 444                  ),
 445              ),
 446          );
 447  
 448          $this->compare_qas($expectedqa, $qa);
 449      }
 450  }