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_numerical;
  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 numerical question attempts.
  27   *
  28   * @package    qtype_numerical
  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_numerical_deferredfeedback_history620() {
  35          $quiz = (object) array(
  36              'id' => '221',
  37              'course' => '187',
  38              'name' => 'Practice CTMA04',
  39              'intro' => 'This is the Practice CTMA04. Your mark for this CTMA <span style="font-style: italic">does not </span>contribute to your continuous assessment mark for B680.<br /><br />This CTMA covers material primarily in Books 10 and 11, however some of the questions may return to material you covered in Books 0 to 9. There are 100 questions in total.<br /><br />It is a function of this testing software that it cannot provide for every possible spelling error that you make. The onus is therefore on you, the student, to ensure that your spelling is correct. ',
  40              'introformat' => FORMAT_HTML,
  41              'questiondecimalpoints' => '-1',
  42              'showuserpicture' => '1',
  43              'showblocks' => '1',
  44              'timeopen' => '1178492400',
  45              'timeclose' => '1193875200',
  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' => '0',
  55              'sumgrades' => '100',
  56              'grade' => '100',
  57              'timecreated' => '0',
  58              'timemodified' => '1195232889',
  59              'password' => '',
  60              'subnet' => '',
  61              'popup' => '0',
  62              'delay1' => '0',
  63              'delay2' => '0',
  64              'timelimit' => '0',
  65          );
  66          $attempt = (object) array(
  67              'id' => '4034',
  68              'uniqueid' => '4034',
  69              'quiz' => '221',
  70              'userid' => '405',
  71              'attempt' => '1',
  72              'sumgrades' => '59',
  73              'timestart' => '1178564323',
  74              'timefinish' => '1178575685',
  75              'timemodified' => '1178571037',
  76              'layout' => '4184,0,4185,0,4154,0,4186,0,4187,0,4188,0,4189,0,4190,0,4162,0,4191,0,4192,0,4193,0,4254,0,4195,0,4196,0,4163,0,4197,0,4198,0,4199,0,4164,0,4200,0,4165,0,4201,0,4202,0,4166,0,4203,0,4204,0,4205,0,4167,0,4155,0,4168,0,4206,0,4207,0,4208,0,4209,0,4210,0,4211,0,4212,0,4213,0,4214,0,4156,0,4215,0,4216,0,4217,0,4169,0,4170,0,4157,0,4218,0,4219,0,4220,0,4171,0,4221,0,4172,0,4222,0,4223,0,4224,0,4225,0,4226,0,4227,0,4228,0,4173,0,4229,0,4230,0,4231,0,4232,0,4174,0,4233,0,4234,0,4235,0,4236,0,4237,0,4238,0,4239,0,4240,0,4241,0,4242,0,4158,0,4243,0,4244,0,4245,0,4246,0,4159,0,4175,0,4247,0,4176,0,4248,0,4177,0,4160,0,4249,0,4178,0,4250,0,4161,0,4251,0,4179,0,4252,0,4180,0,4181,0,4182,0,4253,0,4183,0',
  77              'preview' => '0',
  78          );
  79          $question = (object) array(
  80              'id' => '4165',
  81              'category' => '204',
  82              'parent' => '0',
  83              'name' => '4ccP22 Book 11 Electronic Activity 6.3 Screen F2 NPV calcn(7)',
  84              'questiontext' => 'Calculate your answer to the nearest WHOLE £ and enter it in the blank space provided.
  85          <p>[Note: Please <b><i>DO NOT</i></b> enter commas, spaces or £ signs within the number you enter.] </p>
  86          <p>The cash flows of a project are set out below: </p>
  87          <p>
  88              <table width="500" border="1"><tbody>
  89                  <tr>
  90                      <th valign="top" width="50%" halign="CENTER">year
  91                      </th>
  92                      <th valign="top" width="50%">£
  93                      </th>
  94                  </tr>
  95                  <tr>
  96                      <td>Year 0
  97                      </td>
  98                      <td>(28,000)
  99                      </td>
 100                  </tr>
 101                  <tr>
 102                      <td>Year 1
 103                      </td>
 104                      <td>18,000
 105                      </td>
 106                  </tr>
 107                  <tr>
 108                      <td>Year 2
 109                      </td>
 110                      <td>16,000
 111                      </td>
 112                  </tr></tbody>
 113              </table></p>
 114          <p>Using the Table in Book 11, what is the project\'s net present value using a discount rate of 10%? </p>
 115          <p>If it is negative, put a minus sign before the number you enter. </p>
 116          <p>£ </p>',
 117              'questiontextformat' => '1',
 118              'defaultmark' => '1',
 119              'penalty' => '1',
 120              'qtype' => 'numerical',
 121              'length' => '1',
 122              'stamp' => 'learn.open.ac.uk+070417143727+5hOqJ8',
 123              'version' => 'learn.open.ac.uk+070417154843+o0iHPi',
 124              'hidden' => '0',
 125              'generalfeedback' => '',
 126              'generalfeedbackformat' => '1',
 127              'timecreated' => '0',
 128              'timemodified' => '0',
 129              'createdby' => null,
 130              'modifiedby' => null,
 131              'unlimited' => null,
 132              'maxmark' => '1',
 133              'options' => (object) array(
 134                  'answers' => array(
 135                      12729 => (object) array(
 136                          'question' => '4165',
 137                          'answer' => '1586',
 138                          'fraction' => '1',
 139                          'feedback' => 'Yes, the correct answer is £1,586. Well done!
 140          <p>Note to the answer:<br />£(18,000 x 0.9091) + (£16,000 x 0.8264) - £28,000 = £1,586.2 (the factors are found in the Table 1 of the Appendix to Book 11) </p>
 141          <p>Book 11 Electronic Activity 6.3 Screen F2 </p>',
 142                          'tolerance' => '0',
 143                          'id' => 12729,
 144                      ),
 145                      12730 => (object) array(
 146                          'question' => '4165',
 147                          'answer' => '*',
 148                          'fraction' => '0',
 149                          'feedback' => 'The correct answer is £1,586.
 150          <p>Note to the answer:<br />£(18,000 x 0.9091) + (£16,000 x 0.8264) - £28,000 = £1,586.2 (the factors are found in the Table 1 of the Appendix to Book 11) </p>
 151          <p>Book 11 Electronic Activity 6.3 Screen F2 </p>',
 152                          'tolerance' => '0',
 153                          'id' => 12730,
 154                      ),
 155                  ),
 156                  'units' => array(
 157                  ),
 158              ),
 159              'hints' => false,
 160          );
 161          $qsession = (object) array(
 162              'id' => '39882',
 163              'attemptid' => '4034',
 164              'questionid' => '4165',
 165              'newest' => '92971',
 166              'newgraded' => '92971',
 167              'sumpenalty' => '1',
 168              'manualcomment' => '',
 169              'manualcommentformat' => '1',
 170              'flagged' => '1',
 171          );
 172          $qstates = array(
 173              92694 => (object) array(
 174                  'attempt' => '4034',
 175                  'question' => '4165',
 176                  'originalquestion' => '0',
 177                  'seq_number' => '0',
 178                  'answer' => '',
 179                  'timestamp' => '1178564323',
 180                  'event' => '0',
 181                  'grade' => '0',
 182                  'raw_grade' => '0',
 183                  'penalty' => '0',
 184                  'id' => 92694,
 185              ),
 186              92764 => (object) array(
 187                  'attempt' => '4034',
 188                  'question' => '4165',
 189                  'originalquestion' => '0',
 190                  'seq_number' => '1',
 191                  'answer' => '17520',
 192                  'timestamp' => '1178567143',
 193                  'event' => '2',
 194                  'grade' => '0',
 195                  'raw_grade' => '0',
 196                  'penalty' => '1',
 197                  'id' => 92764,
 198              ),
 199              92971 => (object) array(
 200                  'attempt' => '4034',
 201                  'question' => '4165',
 202                  'originalquestion' => '0',
 203                  'seq_number' => '2',
 204                  'answer' => '17520',
 205                  'timestamp' => '1178567143',
 206                  'event' => '6',
 207                  'grade' => '0',
 208                  'raw_grade' => '0',
 209                  'penalty' => '1',
 210                  'id' => 92971,
 211              ),
 212          );
 213  
 214          $qa = $this->updater->convert_question_attempt($quiz, $attempt, $question, $qsession, $qstates);
 215  
 216          $expectedqa = (object) array(
 217              'behaviour' => 'deferredfeedback',
 218              'questionid' => 4165,
 219              'variant' => 1,
 220              'maxmark' => 1,
 221              'minfraction' => 0,
 222              'maxfraction' => 1,
 223              'flagged' => 0,
 224              'questionsummary' => "Calculate your answer to the nearest WHOLE £ and enter it in the blank space provided. \n\n[Note: Please _DO NOT_ enter commas, spaces or £ signs within the number you enter.]  \n\nThe cash flows of a project are set out below: \n\n \t\tYEAR \n \t\t£ \n\n \t\tYear 0 \n \t\t(28,000) \n\n \t\tYear 1 \n \t\t18,000 \n\n \t\tYear 2 \n \t\t16,000 \n\nUsing the Table in Book 11, what is the project's net present value using a discount rate of 10%?  \n\nIf it is negative, put a minus sign before the number you enter.  \n\n£",
 225              'rightanswer' => '1586',
 226              'responsesummary' => '17520',
 227              'timemodified' => 1178567143,
 228              'steps' => array(
 229                  0 => (object) array(
 230                      'sequencenumber' => 0,
 231                      'state' => 'todo',
 232                      'fraction' => null,
 233                      'timecreated' => 1178564323,
 234                      'userid' => 405,
 235                      'data' => array('_separators' => '.$,'),
 236                  ),
 237                  1 => (object) array(
 238                      'sequencenumber' => 1,
 239                      'state' => 'complete',
 240                      'fraction' => null,
 241                      'timecreated' => 1178567143,
 242                      'userid' => 405,
 243                      'data' => array('answer' => 17520),
 244                  ),
 245                  2 => (object) array(
 246                      'sequencenumber' => 2,
 247                      'state' => 'gradedwrong',
 248                      'fraction' => 0,
 249                      'timecreated' => 1178567143,
 250                      'userid' => 405,
 251                      'data' => array('answer' => 17520, '-finish' => 1),
 252                  ),
 253              ),
 254          );
 255  
 256          $this->compare_qas($expectedqa, $qa);
 257      }
 258  
 259      public function test_numerical_deferredfeedback_required_units() {
 260          $quiz = (object) array(
 261              'id' => '2',
 262              'course' => '2',
 263              'name' => 'Numerical quiz',
 264              'intro' => '',
 265              'introformat' => '1',
 266              'timeopen' => '0',
 267              'timeclose' => '0',
 268              'attempts' => '0',
 269              'attemptonlast' => '0',
 270              'grademethod' => '1',
 271              'decimalpoints' => '2',
 272              'questiondecimalpoints' => '-1',
 273              'review' => '4459503',
 274              'questionsperpage' => '1',
 275              'shufflequestions' => '0',
 276              'shuffleanswers' => '1',
 277              'sumgrades' => '5.00000',
 278              'grade' => '10.00000',
 279              'timecreated' => '0',
 280              'timemodified' => '1305273177',
 281              'timelimit' => '0',
 282              'password' => '',
 283              'subnet' => '',
 284              'popup' => '0',
 285              'delay1' => '0',
 286              'delay2' => '0',
 287              'showuserpicture' => '0',
 288              'showblocks' => '0',
 289              'preferredbehaviour' => 'deferredfeedback',
 290          );
 291          $attempt = (object) array(
 292              'id' => '6',
 293              'uniqueid' => '6',
 294              'quiz' => '2',
 295              'userid' => '2',
 296              'attempt' => '1',
 297              'sumgrades' => '4.00000',
 298              'timestart' => '1305273566',
 299              'timefinish' => '1305273600',
 300              'timemodified' => '1305273600',
 301              'layout' => '6,12,13,15,14,0',
 302              'preview' => '1',
 303          );
 304          $question = (object) array(
 305              'id' => '15',
 306              'category' => '2',
 307              'parent' => '0',
 308              'name' => 'Required units',
 309              'questiontext' => '<p>What is twice 1.5 m?</p>',
 310              'questiontextformat' => '1',
 311              'generalfeedback' => '',
 312              'generalfeedbackformat' => '1',
 313              'penalty' => '0.1000000',
 314              'qtype' => 'numerical',
 315              'length' => '1',
 316              'stamp' => 'tjh238.vledev2.open.ac.uk+110513075857+rrvakr',
 317              'version' => 'tjh238.vledev2.open.ac.uk+110513075857+PH0loi',
 318              'hidden' => '0',
 319              'timecreated' => '1305273537',
 320              'timemodified' => '1305273537',
 321              'createdby' => '2',
 322              'modifiedby' => '2',
 323              'maxmark' => '1.0000000',
 324              'options' => (object) array(
 325                  'answers' => array(
 326                      22 => (object) array(
 327                          'id' => '22',
 328                          'question' => '15',
 329                          'answer' => '3',
 330                          'answerformat' => '0',
 331                          'fraction' => '1.0000000',
 332                          'feedback' => '',
 333                          'feedbackformat' => '1',
 334                          'tolerance' => '',
 335                      ),
 336                  ),
 337                  'units' => array(
 338                      0 => (object) array(
 339                          'id' => '7',
 340                          'question' => '15',
 341                          'multiplier' => 1,
 342                          'unit' => 'm',
 343                      ),
 344                      1 => (object) array(
 345                          'id' => '8',
 346                          'question' => '15',
 347                          'multiplier' => 100,
 348                          'unit' => 'cm',
 349                      ),
 350                  ),
 351                  'unitgradingtype' => '2',
 352                  'unitpenalty' => '0.5000000',
 353                  'showunits' => '0',
 354                  'unitsleft' => '0',
 355                  'instructions' => '<p>Write an answer like 3 m.</p>',
 356                  'instructionsformat' => '1',
 357              ),
 358              'defaultmark' => '1.0000000',
 359          );
 360          $qsession = (object) array(
 361              'id' => '49',
 362              'attemptid' => '6',
 363              'questionid' => '15',
 364              'newest' => '139',
 365              'newgraded' => '139',
 366              'sumpenalty' => '0.1000000',
 367              'manualcomment' => '',
 368              'manualcommentformat' => '1',
 369              'flagged' => '0',
 370          );
 371          $qstates = array(
 372              129 => (object) array(
 373                  'id' => '129',
 374                  'attempt' => '6',
 375                  'question' => '15',
 376                  'seq_number' => '0',
 377                  'answer' => '|||||',
 378                  'timestamp' => '1305273566',
 379                  'event' => '0',
 380                  'grade' => '0.0000000',
 381                  'raw_grade' => '0.0000000',
 382                  'penalty' => '0.0000000',
 383              ),
 384              134 => (object) array(
 385                  'id' => '134',
 386                  'attempt' => '6',
 387                  'question' => '15',
 388                  'seq_number' => '1',
 389                  'answer' => '3|||||m',
 390                  'timestamp' => '1305273595',
 391                  'event' => '2',
 392                  'grade' => '0.0000000',
 393                  'raw_grade' => '1.0000000',
 394                  'penalty' => '0.1000000',
 395              ),
 396              139 => (object) array(
 397                  'id' => '139',
 398                  'attempt' => '6',
 399                  'question' => '15',
 400                  'seq_number' => '2',
 401                  'answer' => '3|||||m',
 402                  'timestamp' => '1305273595',
 403                  'event' => '6',
 404                  'grade' => '1.0000000',
 405                  'raw_grade' => '1.0000000',
 406                  'penalty' => '0.1000000',
 407              ),
 408          );
 409  
 410          $qa = $this->updater->convert_question_attempt($quiz, $attempt, $question, $qsession, $qstates);
 411  
 412          $expectedqa = (object) array(
 413              'behaviour' => 'deferredfeedback',
 414              'questionid' => 15,
 415              'variant' => 1,
 416              'maxmark' => 1.0000000,
 417              'minfraction' => 0,
 418              'maxfraction' => 1,
 419              'flagged' => 0,
 420              'questionsummary' => 'What is twice 1.5 m?',
 421              'rightanswer' => '3 m',
 422              'responsesummary' => '3 m',
 423              'timemodified' => 1305273595,
 424              'steps' => array(
 425                  0 => (object) array(
 426                      'sequencenumber' => 0,
 427                      'state' => 'todo',
 428                      'fraction' => null,
 429                      'timecreated' => 1305273566,
 430                      'userid' => 2,
 431                      'data' => array('_separators' => '.$,'),
 432                  ),
 433                  1 => (object) array(
 434                      'sequencenumber' => 1,
 435                      'state' => 'complete',
 436                      'fraction' => null,
 437                      'timecreated' => 1305273595,
 438                      'userid' => 2,
 439                      'data' => array('answer' => '3 m'),
 440                  ),
 441                  2 => (object) array(
 442                      'sequencenumber' => 2,
 443                      'state' => 'gradedright',
 444                      'fraction' => 1,
 445                      'timecreated' => 1305273595,
 446                      'userid' => 2,
 447                      'data' => array('answer' => '3 m', '-finish' => '1'),
 448                  ),
 449              ),
 450          );
 451  
 452          $this->compare_qas($expectedqa, $qa);
 453      }
 454  }