MDL-27408 question engine upgrade, change to update the quiz settings in config_plugins.

Also start creating the unit tests for the upgrade.
This commit is contained in:
Tim Hunt 2011-05-09 18:58:49 +01:00
parent cd300cf34c
commit 38d42fc476
4 changed files with 739 additions and 29 deletions

View file

@ -261,7 +261,20 @@ abstract class question_behaviour_attempt_updater {
* @return qtype_updater
*/
protected function make_qtype_updater() {
$class = 'qtype_' . $this->question->qtype . '_updater';
global $CFG;
$path = $CFG->dirroot . '/question/type/' . $this->question->qtype . '/db/upgradelib.php';
if (!is_readable($path)) {
throw new coding_exception("Question type {$this->question->qtype}
is missing important code (the file {$path})
required to run the upgrade to the new question engine.");
}
include_once($path);
$class = 'qtype_' . $this->question->qtype . '_qe2_attempt_updater';
if (!class_exists($class)) {
throw new coding_exception("Question type {$this->question->qtype}
is missing important code (the class {$class})
required to run the upgrade to the new question engine.");
}
return new $class($this, $this->question, $this->logger);
}

View file

@ -0,0 +1,114 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This file contains test helper code for testing the upgrade to the new
* question engine. The acutal tests are organised by question type in files
* like question/type/truefalse/db/simpletest/testupgradelibnewqe.php.
*
* @package moodlecore
* @subpackage questionengine
* @copyright 2009 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
require_once(dirname(__FILE__) . '/../upgradelib.php');
/**
* Subclass of question_engine_attempt_upgrader to help with testing.
*
* @copyright 2009 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class test_question_engine_attempt_upgrader extends question_engine_attempt_upgrader {
public function prevent_timeout() {
}
public function __construct($loader, $logger) {
$this->questionloader = $loader;
$this->logger = $logger;
}
}
/**
* Subclass of question_engine_assumption_logger that does nothing, for testing.
*
* @copyright 2009 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class dummy_question_engine_assumption_logger extends question_engine_assumption_logger {
protected $attemptid;
public function __construct() {
}
public function log_assumption($description, $quizattemptid = null) {
}
public function __destruct() {
}
}
/**
* Subclass of question_engine_upgrade_question_loader for unit testing.
*
* @copyright 2009 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class test_question_engine_upgrade_question_loader extends question_engine_upgrade_question_loader {
public function put_question_in_cache($question) {
$this->cache[$question->id] = $question;
}
public function load_question($questionid, $quizid) {
global $CFG, $QTYPES;
if (isset($this->cache[$questionid])) {
return $this->cache[$questionid];
}
return null;
}
}
/**
* Base class for tests that thest the upgrade of one particular attempt and
* one question.
*
* @copyright 2009 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class question_attempt_upgrader_test_base extends UnitTestCase {
protected $updater;
protected $loader;
public function setUp() {
$logger = new dummy_question_engine_assumption_logger();
$this->loader = new test_question_engine_upgrade_question_loader($logger);
$this->updater = new test_question_engine_attempt_upgrader($this->loader, $logger);
}
public function tearDown() {
$this->updater = null;
}
}