Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/question/engine/upgrade/simpletest/helper.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 
00029 defined('MOODLE_INTERNAL') || die();
00030 
00031 require_once(dirname(__FILE__) . '/../upgradelib.php');
00032 
00033 
00040 class test_question_engine_attempt_upgrader extends question_engine_attempt_upgrader {
00041     public function prevent_timeout() {
00042     }
00043 
00044     public function __construct($loader, $logger) {
00045         $this->questionloader = $loader;
00046         $this->logger = $logger;
00047     }
00048 }
00049 
00050 
00057 class test_question_engine_upgrade_question_loader extends question_engine_upgrade_question_loader {
00058     public function put_question_in_cache($question) {
00059         $this->cache[$question->id] = $question;
00060     }
00061 
00062     public function load_question($questionid, $quizid) {
00063         global $CFG;
00064 
00065         if (isset($this->cache[$questionid])) {
00066             return $this->cache[$questionid];
00067         }
00068 
00069         return null;
00070     }
00071 
00072     public function put_dataset_in_cache($questionid, $selecteditem, $dataset) {
00073         $this->datasetcache[$questionid][$selecteditem] = $dataset;
00074     }
00075 
00076     public function load_dataset($questionid, $selecteditem) {
00077         global $DB;
00078 
00079         if (isset($this->datasetcache[$questionid][$selecteditem])) {
00080             return $this->datasetcache[$questionid][$selecteditem];
00081         }
00082 
00083         throw new coding_exception('Test dataset not loaded.');
00084     }
00085 }
00086 
00087 
00095 class question_attempt_upgrader_test_base extends UnitTestCase {
00096     protected $updater;
00097     protected $loader;
00098 
00099     public function setUp() {
00100         $logger = new dummy_question_engine_assumption_logger();
00101         $this->loader = new test_question_engine_upgrade_question_loader($logger);
00102         $this->updater = new test_question_engine_attempt_upgrader($this->loader, $logger);
00103     }
00104 
00105     public function tearDown() {
00106         $this->updater = null;
00107     }
00108 
00117     protected function clear_html2text_dependencies($qa) {
00118         // Cleaning all whitespace should be enough to ignore any html2text dependency
00119         if (property_exists($qa, 'responsesummary')) {
00120             $qa->responsesummary = preg_replace('/\s/', '', $qa->responsesummary);
00121         }
00122         if (property_exists($qa, 'questionsummary')) {
00123             $qa->questionsummary = preg_replace('/\s/', '', $qa->questionsummary);
00124         }
00125     }
00126 
00132     protected function compare_qas($expectedqa, $qa) {
00133         $this->clear_html2text_dependencies($expectedqa);
00134         $this->clear_html2text_dependencies($qa);
00135         $this->assertEqual($expectedqa, $qa);
00136     }
00137 }
 All Data Structures Namespaces Files Functions Variables Enumerations