Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/question/type/calculatedsimple/db/simpletest/testupgradelibnewqe.php
Go to the documentation of this file.
00001 <?php
00002 // This file is part of Moodle - http://moodle.org/
00003 //
00004 // Moodle is free software: you can redistribute it and/or modify
00005 // it under the terms of the GNU General Public License as published by
00006 // the Free Software Foundation, either version 3 of the License, or
00007 // (at your option) any later version.
00008 //
00009 // Moodle is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00016 
00028 defined('MOODLE_INTERNAL') || die();
00029 
00030 require_once($CFG->dirroot . '/question/engine/upgrade/simpletest/helper.php');
00031 
00032 
00039 class qtype_calculatedsimple_attempt_upgrader_test extends question_attempt_upgrader_test_base {
00040     public function test_calculatedsimple_adaptive_qsession95() {
00041         $quiz = (object) array(
00042             'id' => '4',
00043             'course' => '2',
00044             'name' => 'Calculated quiz',
00045             'intro' => '',
00046             'introformat' => '1',
00047             'timeopen' => '0',
00048             'timeclose' => '0',
00049             'attempts' => '0',
00050             'attemptonlast' => '0',
00051             'grademethod' => '1',
00052             'decimalpoints' => '2',
00053             'questiondecimalpoints' => '-1',
00054             'questionsperpage' => '1',
00055             'shufflequestions' => '0',
00056             'shuffleanswers' => '1',
00057             'questions' => '16,0,17,0,18,0',
00058             'sumgrades' => '3.00000',
00059             'grade' => '10.00000',
00060             'timecreated' => '0',
00061             'timemodified' => '1305648351',
00062             'timelimit' => '0',
00063             'password' => '',
00064             'subnet' => '',
00065             'popup' => '0',
00066             'delay1' => '0',
00067             'delay2' => '0',
00068             'showuserpicture' => '0',
00069             'showblocks' => '0',
00070             'preferredbehaviour' => 'adaptive',
00071             'reviewattempt' => '69888',
00072             'reviewcorrectness' => '69888',
00073             'reviewmarks' => '69888',
00074             'reviewspecificfeedback' => '69888',
00075             'reviewgeneralfeedback' => '69888',
00076             'reviewrightanswer' => '69888',
00077             'reviewoverallfeedback' => '4352',
00078         );
00079         $attempt = (object) array(
00080             'id' => '13',
00081             'uniqueid' => '13',
00082             'quiz' => '4',
00083             'userid' => '4',
00084             'attempt' => '1',
00085             'sumgrades' => '0.00000',
00086             'timestart' => '1305830650',
00087             'timefinish' => '1305830656',
00088             'timemodified' => '1305830656',
00089             'layout' => '16,0,17,0,18,0',
00090             'preview' => '0',
00091             'needsupgradetonewqe' => 1,
00092         );
00093         $question = (object) array(
00094             'id' => '16',
00095             'category' => '2',
00096             'parent' => '0',
00097             'name' => 'Calculated simple',
00098             'questiontext' => '<p>What is {={a}} + {={b}} ?</p>',
00099             'questiontextformat' => '1',
00100             'generalfeedback' => '',
00101             'generalfeedbackformat' => '1',
00102             'defaultmark' => '1.0000000',
00103             'penalty' => '0.1',
00104             'qtype' => 'calculatedsimple',
00105             'length' => '1',
00106             'stamp' => 'tjh238.vledev2.open.ac.uk+110517161007+2Barhu',
00107             'version' => 'tjh238.vledev2.open.ac.uk+110517161008+Mu6OQu',
00108             'hidden' => '0',
00109             'timecreated' => '1305648607',
00110             'timemodified' => '1305648607',
00111             'createdby' => '2',
00112             'modifiedby' => '2',
00113             'maxmark' => '1.0000000',
00114             'options' => (object) array(
00115                 'synchronize' => 0,
00116                 'single' => 0,
00117                 'answernumbering' => 'abc',
00118                 'shuffleanswers' => 0,
00119                 'correctfeedback' => '',
00120                 'partiallycorrectfeedback' => '',
00121                 'incorrectfeedback' => '',
00122                 'correctfeedbackformat' => 0,
00123                 'partiallycorrectfeedbackformat' => 0,
00124                 'incorrectfeedbackformat' => 0,
00125                 'answers' => array(
00126                     23 => (object) array(
00127                         'id' => '23',
00128                         'question' => '16',
00129                         'answer' => '{a} + {b}',
00130                         'answerformat' => '0',
00131                         'fraction' => '1.0000000',
00132                         'feedback' => '<p>Well done!</p>',
00133                         'feedbackformat' => '1',
00134                         'tolerance' => '0.01',
00135                         'tolerancetype' => '1',
00136                         'correctanswerlength' => '2',
00137                         'correctanswerformat' => '1',
00138                     ),
00139                 ),
00140                 'units' => array(
00141                 ),
00142                 'unitgradingtype' => '0',
00143                 'unitpenalty' => '0.1000000',
00144                 'showunits' => '3',
00145                 'unitsleft' => '0',
00146             ),
00147             'hints' => array(
00148             ),
00149         );
00150         $qsession = (object) array(
00151             'id' => '95',
00152             'attemptid' => '13',
00153             'questionid' => '16',
00154             'newest' => '256',
00155             'newgraded' => '256',
00156             'sumpenalty' => '0.1000000',
00157             'manualcomment' => '',
00158             'manualcommentformat' => '1',
00159             'flagged' => '0',
00160         );
00161         $qstates = array(
00162             253 => (object) array(
00163                 'id' => '253',
00164                 'attempt' => '13',
00165                 'question' => '16',
00166                 'seq_number' => '0',
00167                 'answer' => 'dataset7-|||||',
00168                 'timestamp' => '1305830650',
00169                 'event' => '0',
00170                 'grade' => '0.0000000',
00171                 'raw_grade' => '0.0000000',
00172                 'penalty' => '0.0000000',
00173             ),
00174             256 => (object) array(
00175                 'id' => '256',
00176                 'attempt' => '13',
00177                 'question' => '16',
00178                 'seq_number' => '1',
00179                 'answer' => 'dataset7-|||||',
00180                 'timestamp' => '1305830650',
00181                 'event' => '6',
00182                 'grade' => '0.0000000',
00183                 'raw_grade' => '0.0000000',
00184                 'penalty' => '0.1000000',
00185             ),
00186         );
00187         $this->loader->put_dataset_in_cache($question->id, 7, array('a' => '3', 'b' => '6'));
00188 
00189         $qa = $this->updater->convert_question_attempt($quiz, $attempt, $question, $qsession, $qstates);
00190 
00191         $expectedqa = (object) array(
00192             'behaviour' => 'adaptive',
00193             'questionid' => 16,
00194             'variant' => 7,
00195             'maxmark' => 1.0000000,
00196             'minfraction' => 0,
00197             'flagged' => 0,
00198             'questionsummary' => 'What is 3 + 6 ?',
00199             'rightanswer' => '9',
00200             'responsesummary' => '',
00201             'timemodified' => 1305830650,
00202             'steps' => array(
00203                 0 => (object) array(
00204                     'sequencenumber' => 0,
00205                     'state' => 'todo',
00206                     'fraction' => null,
00207                     'timecreated' => 1305830650,
00208                     'userid' => 4,
00209                     'data' => array('_separators' => '.$,',
00210                             '_var_a' => '3', '_var_b' => '6'),
00211                 ),
00212                 1 => (object) array(
00213                     'sequencenumber' => 1,
00214                     'state' => 'gradedwrong',
00215                     'fraction' => 0,
00216                     'timecreated' => 1305830650,
00217                     'userid' => 4,
00218                     'data' => array('answer' => '', '-finish' => 1, '-_try' => 1, '-_rawfraction' => 0),
00219                 ),
00220             ),
00221         );
00222 
00223         $this->compare_qas($expectedqa, $qa);
00224     }
00225 
00226     public function test_calculatedsimple_adaptive_qsession98() {
00227         $quiz = (object) array(
00228             'id' => '4',
00229             'course' => '2',
00230             'name' => 'Calculated quiz',
00231             'intro' => '',
00232             'introformat' => '1',
00233             'timeopen' => '0',
00234             'timeclose' => '0',
00235             'attempts' => '0',
00236             'attemptonlast' => '0',
00237             'grademethod' => '1',
00238             'decimalpoints' => '2',
00239             'questiondecimalpoints' => '-1',
00240             'questionsperpage' => '1',
00241             'shufflequestions' => '0',
00242             'shuffleanswers' => '1',
00243             'questions' => '16,0,17,0,18,0',
00244             'sumgrades' => '3.00000',
00245             'grade' => '10.00000',
00246             'timecreated' => '0',
00247             'timemodified' => '1305648351',
00248             'timelimit' => '0',
00249             'password' => '',
00250             'subnet' => '',
00251             'popup' => '0',
00252             'delay1' => '0',
00253             'delay2' => '0',
00254             'showuserpicture' => '0',
00255             'showblocks' => '0',
00256             'preferredbehaviour' => 'adaptive',
00257             'reviewattempt' => '69888',
00258             'reviewcorrectness' => '69888',
00259             'reviewmarks' => '69888',
00260             'reviewspecificfeedback' => '69888',
00261             'reviewgeneralfeedback' => '69888',
00262             'reviewrightanswer' => '69888',
00263             'reviewoverallfeedback' => '4352',
00264         );
00265         $attempt = (object) array(
00266             'id' => '14',
00267             'uniqueid' => '14',
00268             'quiz' => '4',
00269             'userid' => '4',
00270             'attempt' => '2',
00271             'sumgrades' => '2.80000',
00272             'timestart' => '1305830661',
00273             'timefinish' => '1305830729',
00274             'timemodified' => '1305830729',
00275             'layout' => '16,0,17,0,18,0',
00276             'preview' => '0',
00277             'needsupgradetonewqe' => 1,
00278         );
00279         $question = (object) array(
00280             'id' => '16',
00281             'category' => '2',
00282             'parent' => '0',
00283             'name' => 'Calculated simple',
00284             'questiontext' => '<p>What is {={a}} + {={b}} ?</p>',
00285             'questiontextformat' => '1',
00286             'generalfeedback' => '',
00287             'generalfeedbackformat' => '1',
00288             'defaultmark' => '1.0000000',
00289             'penalty' => '0.1',
00290             'qtype' => 'calculatedsimple',
00291             'length' => '1',
00292             'stamp' => 'tjh238.vledev2.open.ac.uk+110517161007+2Barhu',
00293             'version' => 'tjh238.vledev2.open.ac.uk+110517161008+Mu6OQu',
00294             'hidden' => '0',
00295             'timecreated' => '1305648607',
00296             'timemodified' => '1305648607',
00297             'createdby' => '2',
00298             'modifiedby' => '2',
00299             'maxmark' => '1.0000000',
00300             'options' => (object) array(
00301                 'synchronize' => 0,
00302                 'single' => 0,
00303                 'answernumbering' => 'abc',
00304                 'shuffleanswers' => 0,
00305                 'correctfeedback' => '',
00306                 'partiallycorrectfeedback' => '',
00307                 'incorrectfeedback' => '',
00308                 'correctfeedbackformat' => 0,
00309                 'partiallycorrectfeedbackformat' => 0,
00310                 'incorrectfeedbackformat' => 0,
00311                 'answers' => array(
00312                     23 => (object) array(
00313                         'id' => '23',
00314                         'question' => '16',
00315                         'answer' => '{a} + {b}',
00316                         'answerformat' => '0',
00317                         'fraction' => '1.0000000',
00318                         'feedback' => '<p>Well done!</p>',
00319                         'feedbackformat' => '1',
00320                         'tolerance' => '0.01',
00321                         'tolerancetype' => '1',
00322                         'correctanswerlength' => '2',
00323                         'correctanswerformat' => '1',
00324                     ),
00325                 ),
00326                 'units' => array(
00327                 ),
00328                 'unitgradingtype' => '0',
00329                 'unitpenalty' => '0.1000000',
00330                 'showunits' => '3',
00331                 'unitsleft' => '0',
00332             ),
00333             'hints' => array(
00334             ),
00335         );
00336         $qsession = (object) array(
00337             'id' => '98',
00338             'attemptid' => '14',
00339             'questionid' => '16',
00340             'newest' => '267',
00341             'newgraded' => '267',
00342             'sumpenalty' => '0.3000000',
00343             'manualcomment' => '',
00344             'manualcommentformat' => '1',
00345             'flagged' => '0',
00346         );
00347         $qstates = array(
00348             259 => (object) array(
00349                 'id' => '259',
00350                 'attempt' => '14',
00351                 'question' => '16',
00352                 'seq_number' => '0',
00353                 'answer' => 'dataset4-|||||',
00354                 'timestamp' => '1305830661',
00355                 'event' => '0',
00356                 'grade' => '0.0000000',
00357                 'raw_grade' => '0.0000000',
00358                 'penalty' => '0.0000000',
00359             ),
00360             262 => (object) array(
00361                 'id' => '262',
00362                 'attempt' => '14',
00363                 'question' => '16',
00364                 'seq_number' => '1',
00365                 'answer' => 'dataset4-9.00|||||',
00366                 'timestamp' => '1305830668',
00367                 'event' => '3',
00368                 'grade' => '0.0000000',
00369                 'raw_grade' => '0.0000000',
00370                 'penalty' => '0.1000000',
00371             ),
00372             263 => (object) array(
00373                 'id' => '263',
00374                 'attempt' => '14',
00375                 'question' => '16',
00376                 'seq_number' => '2',
00377                 'answer' => 'dataset4-15.40|||||',
00378                 'timestamp' => '1305830679',
00379                 'event' => '3',
00380                 'grade' => '0.9000000',
00381                 'raw_grade' => '1.0000000',
00382                 'penalty' => '0.1000000',
00383             ),
00384             267 => (object) array(
00385                 'id' => '267',
00386                 'attempt' => '14',
00387                 'question' => '16',
00388                 'seq_number' => '3',
00389                 'answer' => 'dataset4-15.40|||||',
00390                 'timestamp' => '1305830679',
00391                 'event' => '6',
00392                 'grade' => '0.9000000',
00393                 'raw_grade' => '1.0000000',
00394                 'penalty' => '0.1000000',
00395             ),
00396         );
00397         $this->loader->put_dataset_in_cache($question->id, 4, array('a' => '6.4', 'b' => '9'));
00398 
00399         $qa = $this->updater->convert_question_attempt($quiz, $attempt, $question, $qsession, $qstates);
00400 
00401         $expectedqa = (object) array(
00402             'behaviour' => 'adaptive',
00403             'questionid' => 16,
00404             'variant' => 4,
00405             'maxmark' => 1.0000000,
00406             'minfraction' => 0,
00407             'flagged' => 0,
00408             'questionsummary' => 'What is 6.4 + 9 ?',
00409             'rightanswer' => '15.4',
00410             'responsesummary' => '15.40',
00411             'timemodified' => 1305830679,
00412             'steps' => array(
00413                 0 => (object) array(
00414                     'sequencenumber' => 0,
00415                     'state' => 'todo',
00416                     'fraction' => null,
00417                     'timecreated' => 1305830661,
00418                     'userid' => 4,
00419                     'data' => array('_separators' => '.$,',
00420                             '_var_a' => '6.4', '_var_b' => '9'),
00421                 ),
00422                 1 => (object) array(
00423                     'sequencenumber' => 1,
00424                     'state' => 'todo',
00425                     'fraction' => 0,
00426                     'timecreated' => 1305830668,
00427                     'userid' => 4,
00428                     'data' => array('answer' => '9.00', '-submit' => 1, '-_try' => 1, '-_rawfraction' => 0),
00429                 ),
00430                 2 => (object) array(
00431                     'sequencenumber' => 2,
00432                     'state' => 'todo',
00433                     'fraction' => 0.9,
00434                     'timecreated' => 1305830679,
00435                     'userid' => 4,
00436                     'data' => array('answer' => '15.40', '-submit' => 1, '-_try' => 2, '-_rawfraction' => 1),
00437                 ),
00438                 3 => (object) array(
00439                     'sequencenumber' => 3,
00440                     'state' => 'gradedright',
00441                     'fraction' => 0.9,
00442                     'timecreated' => 1305830679,
00443                     'userid' => 4,
00444                     'data' => array('answer' => '15.40', '-finish' => 1, '-_try' => 2, '-_rawfraction' => 1),
00445                 ),
00446             ),
00447         );
00448 
00449         $this->compare_qas($expectedqa, $qa);
00450     }
00451 
00452     public function test_calculatedsimple_adaptive_qsession101() {
00453         $quiz = (object) array(
00454             'id' => '4',
00455             'course' => '2',
00456             'name' => 'Calculated quiz',
00457             'intro' => '',
00458             'introformat' => '1',
00459             'timeopen' => '0',
00460             'timeclose' => '0',
00461             'attempts' => '0',
00462             'attemptonlast' => '0',
00463             'grademethod' => '1',
00464             'decimalpoints' => '2',
00465             'questiondecimalpoints' => '-1',
00466             'questionsperpage' => '1',
00467             'shufflequestions' => '0',
00468             'shuffleanswers' => '1',
00469             'questions' => '16,0,17,0,18,0',
00470             'sumgrades' => '3.00000',
00471             'grade' => '10.00000',
00472             'timecreated' => '0',
00473             'timemodified' => '1305648351',
00474             'timelimit' => '0',
00475             'password' => '',
00476             'subnet' => '',
00477             'popup' => '0',
00478             'delay1' => '0',
00479             'delay2' => '0',
00480             'showuserpicture' => '0',
00481             'showblocks' => '0',
00482             'preferredbehaviour' => 'adaptive',
00483             'reviewattempt' => '69888',
00484             'reviewcorrectness' => '69888',
00485             'reviewmarks' => '69888',
00486             'reviewspecificfeedback' => '69888',
00487             'reviewgeneralfeedback' => '69888',
00488             'reviewrightanswer' => '69888',
00489             'reviewoverallfeedback' => '4352',
00490         );
00491         $attempt = (object) array(
00492             'id' => '15',
00493             'uniqueid' => '15',
00494             'quiz' => '4',
00495             'userid' => '3',
00496             'attempt' => '1',
00497             'sumgrades' => '0.70000',
00498             'timestart' => '1305830744',
00499             'timefinish' => '0',
00500             'timemodified' => '1305830792',
00501             'layout' => '16,0,17,0,18,0',
00502             'preview' => '0',
00503             'needsupgradetonewqe' => 1,
00504         );
00505         $question = (object) array(
00506             'id' => '16',
00507             'category' => '2',
00508             'parent' => '0',
00509             'name' => 'Calculated simple',
00510             'questiontext' => '<p>What is {={a}} + {={b}} ?</p>',
00511             'questiontextformat' => '1',
00512             'generalfeedback' => '',
00513             'generalfeedbackformat' => '1',
00514             'defaultmark' => '1.0000000',
00515             'penalty' => '0.1',
00516             'qtype' => 'calculatedsimple',
00517             'length' => '1',
00518             'stamp' => 'tjh238.vledev2.open.ac.uk+110517161007+2Barhu',
00519             'version' => 'tjh238.vledev2.open.ac.uk+110517161008+Mu6OQu',
00520             'hidden' => '0',
00521             'timecreated' => '1305648607',
00522             'timemodified' => '1305648607',
00523             'createdby' => '2',
00524             'modifiedby' => '2',
00525             'maxmark' => '1.0000000',
00526             'options' => (object) array(
00527                 'synchronize' => 0,
00528                 'single' => 0,
00529                 'answernumbering' => 'abc',
00530                 'shuffleanswers' => 0,
00531                 'correctfeedback' => '',
00532                 'partiallycorrectfeedback' => '',
00533                 'incorrectfeedback' => '',
00534                 'correctfeedbackformat' => 0,
00535                 'partiallycorrectfeedbackformat' => 0,
00536                 'incorrectfeedbackformat' => 0,
00537                 'answers' => array(
00538                     23 => (object) array(
00539                         'id' => '23',
00540                         'question' => '16',
00541                         'answer' => '{a} + {b}',
00542                         'answerformat' => '0',
00543                         'fraction' => '1.0000000',
00544                         'feedback' => '<p>Well done!</p>',
00545                         'feedbackformat' => '1',
00546                         'tolerance' => '0.01',
00547                         'tolerancetype' => '1',
00548                         'correctanswerlength' => '2',
00549                         'correctanswerformat' => '1',
00550                     ),
00551                 ),
00552                 'units' => array(
00553                 ),
00554                 'unitgradingtype' => '0',
00555                 'unitpenalty' => '0.1000000',
00556                 'showunits' => '3',
00557                 'unitsleft' => '0',
00558             ),
00559             'hints' => array(
00560             ),
00561         );
00562         $qsession = (object) array(
00563             'id' => '101',
00564             'attemptid' => '15',
00565             'questionid' => '16',
00566             'newest' => '273',
00567             'newgraded' => '270',
00568             'sumpenalty' => '0.0000000',
00569             'manualcomment' => '',
00570             'manualcommentformat' => '1',
00571             'flagged' => '0',
00572         );
00573         $qstates = array(
00574             270 => (object) array(
00575                 'id' => '270',
00576                 'attempt' => '15',
00577                 'question' => '16',
00578                 'seq_number' => '0',
00579                 'answer' => 'dataset6-|||||',
00580                 'timestamp' => '1305830744',
00581                 'event' => '0',
00582                 'grade' => '0.0000000',
00583                 'raw_grade' => '0.0000000',
00584                 'penalty' => '0.0000000',
00585             ),
00586             273 => (object) array(
00587                 'id' => '273',
00588                 'attempt' => '15',
00589                 'question' => '16',
00590                 'seq_number' => '1',
00591                 'answer' => 'dataset6-13.1|||||',
00592                 'timestamp' => '1305830755',
00593                 'event' => '2',
00594                 'grade' => '0.0000000',
00595                 'raw_grade' => '1.0000000',
00596                 'penalty' => '0.1000000',
00597             ),
00598         );
00599         $this->loader->put_dataset_in_cache($question->id, 6, array('a' => '6.1', 'b' => '7'));
00600 
00601         $qa = $this->updater->convert_question_attempt($quiz, $attempt, $question, $qsession, $qstates);
00602 
00603         $expectedqa = (object) array(
00604             'behaviour' => 'adaptive',
00605             'questionid' => 16,
00606             'variant' => 6,
00607             'maxmark' => 1.0000000,
00608             'minfraction' => 0,
00609             'flagged' => 0,
00610             'questionsummary' => 'What is 6.1 + 7 ?',
00611             'rightanswer' => '13.1',
00612             'responsesummary' => '13.1',
00613             'timemodified' => 1305830755,
00614             'steps' => array(
00615                 0 => (object) array(
00616                     'sequencenumber' => 0,
00617                     'state' => 'todo',
00618                     'fraction' => null,
00619                     'timecreated' => 1305830744,
00620                     'userid' => 3,
00621                     'data' => array('_separators' => '.$,',
00622                             '_var_a' => '6.1', '_var_b' => '7'),
00623                 ),
00624                 1 => (object) array(
00625                     'sequencenumber' => 1,
00626                     'state' => 'complete',
00627                     'fraction' => null,
00628                     'timecreated' => 1305830755,
00629                     'userid' => 3,
00630                     'data' => array('answer' => 13.1),
00631                 ),
00632             ),
00633         );
00634 
00635         $this->compare_qas($expectedqa, $qa);
00636     }
00637 }
 All Data Structures Namespaces Files Functions Variables Enumerations