Skip to content

Commit

Permalink
MDL-27408 question engine upgrade, change to update the quiz settings…
Browse files Browse the repository at this point in the history
… in config_plugins.

Also start creating the unit tests for the upgrade.
  • Loading branch information
timhunt committed May 11, 2011
1 parent cd300cf commit 38d42fc
Show file tree
Hide file tree
Showing 4 changed files with 739 additions and 29 deletions.
56 changes: 28 additions & 28 deletions local/qedatabase/db/install.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@ function xmldb_local_qedatabase_install() {
global $DB;
$dbman = $DB->get_manager();

// TODO quiz default settings are now in config_plugins.

// Bit of a hack to prevent errors like "Cannot downgrade local_qedatabase from ... to ...".
$oldversion = 2008000000;
$DB->set_field('config_plugins', 'value', $oldversion,
array('plugin' => 'local_qedatabase', 'name' => 'version'));

// Add new preferredbehaviour column to the quiz table.
if ($oldversion < 2008000100) {
$table = new xmldb_table('quiz');
Expand All @@ -33,8 +26,8 @@ function xmldb_local_qedatabase_install() {
$DB->set_field_select('quiz', 'preferredbehaviour', 'adaptivenopenalty',
'optionflags <> 0 AND penaltyscheme = 0');

set_config('quiz_preferredbehaviour', 'deferredfeedback');
set_config('quiz_fix_preferredbehaviour', 0);
set_config('preferredbehaviour', 'deferredfeedback', 'quiz');
set_config('fix_preferredbehaviour', 0, 'quiz');

// quiz savepoint reached
upgrade_plugin_savepoint(true, 2008000101, 'local', 'qedatabase');
Expand All @@ -58,8 +51,8 @@ function xmldb_local_qedatabase_install() {
$field = new xmldb_field('optionflags');
$dbman->drop_field($table, $field);

unset_config('quiz_optionflags');
unset_config('quiz_fix_optionflags');
unset_config('optionflags', 'quiz');
unset_config('fix_optionflags', 'quiz');

// quiz savepoint reached
upgrade_plugin_savepoint(true, 2008000103, 'local', 'qedatabase');
Expand All @@ -71,8 +64,8 @@ function xmldb_local_qedatabase_install() {
$field = new xmldb_field('penaltyscheme');
$dbman->drop_field($table, $field);

unset_config('quiz_penaltyscheme');
unset_config('quiz_fix_penaltyscheme');
unset_config('penaltyscheme', 'quiz');
unset_config('fix_penaltyscheme', 'quiz');

// quiz savepoint reached
upgrade_plugin_savepoint(true, 2008000104, 'local', 'qedatabase');
Expand Down Expand Up @@ -355,47 +348,54 @@ function xmldb_local_qedatabase_install() {
$CFG->quiz_review = 0;
}

set_config('quiz_reviewattempt',
set_config('reviewattempt',
QUIZ_NEW_DURING |
($CFG->quiz_review & QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_RESPONSES ? QUIZ_NEW_IMMEDIATELY_AFTER : 0) |
($CFG->quiz_review & QUIZ_OLD_OPEN & QUIZ_OLD_RESPONSES ? QUIZ_NEW_LATER_WHILE_OPEN : 0) |
($CFG->quiz_review & QUIZ_OLD_CLOSED & QUIZ_OLD_RESPONSES ? QUIZ_NEW_AFTER_CLOSE : 0));
($CFG->quiz_review & QUIZ_OLD_CLOSED & QUIZ_OLD_RESPONSES ? QUIZ_NEW_AFTER_CLOSE : 0),
'quiz');

set_config('quiz_reviewcorrectness',
set_config('reviewcorrectness',
QUIZ_NEW_DURING |
($CFG->quiz_review & QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_SCORES ? QUIZ_NEW_IMMEDIATELY_AFTER : 0) |
($CFG->quiz_review & QUIZ_OLD_OPEN & QUIZ_OLD_SCORES ? QUIZ_NEW_LATER_WHILE_OPEN : 0) |
($CFG->quiz_review & QUIZ_OLD_CLOSED & QUIZ_OLD_SCORES ? QUIZ_NEW_AFTER_CLOSE : 0));
($CFG->quiz_review & QUIZ_OLD_CLOSED & QUIZ_OLD_SCORES ? QUIZ_NEW_AFTER_CLOSE : 0),
'quiz');

set_config('quiz_reviewmarks',
set_config('reviewmarks',
QUIZ_NEW_DURING |
($CFG->quiz_review & QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_SCORES ? QUIZ_NEW_IMMEDIATELY_AFTER : 0) |
($CFG->quiz_review & QUIZ_OLD_OPEN & QUIZ_OLD_SCORES ? QUIZ_NEW_LATER_WHILE_OPEN : 0) |
($CFG->quiz_review & QUIZ_OLD_CLOSED & QUIZ_OLD_SCORES ? QUIZ_NEW_AFTER_CLOSE : 0));
($CFG->quiz_review & QUIZ_OLD_CLOSED & QUIZ_OLD_SCORES ? QUIZ_NEW_AFTER_CLOSE : 0),
'quiz');

set_config('quiz_reviewspecificfeedback',
set_config('reviewspecificfeedback',
($CFG->quiz_review & QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_FEEDBACK ? QUIZ_NEW_DURING : 0) |
($CFG->quiz_review & QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_FEEDBACK ? QUIZ_NEW_IMMEDIATELY_AFTER : 0) |
($CFG->quiz_review & QUIZ_OLD_OPEN & QUIZ_OLD_FEEDBACK ? QUIZ_NEW_LATER_WHILE_OPEN : 0) |
($CFG->quiz_review & QUIZ_OLD_CLOSED & QUIZ_OLD_FEEDBACK ? QUIZ_NEW_AFTER_CLOSE : 0));
($CFG->quiz_review & QUIZ_OLD_CLOSED & QUIZ_OLD_FEEDBACK ? QUIZ_NEW_AFTER_CLOSE : 0),
'quiz');

set_config('quiz_reviewgeneralfeedback',
set_config('reviewgeneralfeedback',
($CFG->quiz_review & QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_GENERALFEEDBACK ? QUIZ_NEW_DURING : 0) |
($CFG->quiz_review & QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_GENERALFEEDBACK ? QUIZ_NEW_IMMEDIATELY_AFTER : 0) |
($CFG->quiz_review & QUIZ_OLD_OPEN & QUIZ_OLD_GENERALFEEDBACK ? QUIZ_NEW_LATER_WHILE_OPEN : 0) |
($CFG->quiz_review & QUIZ_OLD_CLOSED & QUIZ_OLD_GENERALFEEDBACK ? QUIZ_NEW_AFTER_CLOSE : 0));
($CFG->quiz_review & QUIZ_OLD_CLOSED & QUIZ_OLD_GENERALFEEDBACK ? QUIZ_NEW_AFTER_CLOSE : 0),
'quiz');

set_config('quiz_reviewrightanswer',
set_config('reviewrightanswer',
($CFG->quiz_review & QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_ANSWERS ? QUIZ_NEW_DURING : 0) |
($CFG->quiz_review & QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_ANSWERS ? QUIZ_NEW_IMMEDIATELY_AFTER : 0) |
($CFG->quiz_review & QUIZ_OLD_OPEN & QUIZ_OLD_ANSWERS ? QUIZ_NEW_LATER_WHILE_OPEN : 0) |
($CFG->quiz_review & QUIZ_OLD_CLOSED & QUIZ_OLD_ANSWERS ? QUIZ_NEW_AFTER_CLOSE : 0));
($CFG->quiz_review & QUIZ_OLD_CLOSED & QUIZ_OLD_ANSWERS ? QUIZ_NEW_AFTER_CLOSE : 0),
'quiz');

set_config('quiz_reviewoverallfeedback',
set_config('reviewoverallfeedback',
0 |
($CFG->quiz_review & QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_OVERALLFEEDBACK ? QUIZ_NEW_IMMEDIATELY_AFTER : 0) |
($CFG->quiz_review & QUIZ_OLD_OPEN & QUIZ_OLD_OVERALLFEEDBACK ? QUIZ_NEW_LATER_WHILE_OPEN : 0) |
($CFG->quiz_review & QUIZ_OLD_CLOSED & QUIZ_OLD_OVERALLFEEDBACK ? QUIZ_NEW_AFTER_CLOSE : 0));
($CFG->quiz_review & QUIZ_OLD_CLOSED & QUIZ_OLD_OVERALLFEEDBACK ? QUIZ_NEW_AFTER_CLOSE : 0),
'quiz');

// quiz savepoint reached
upgrade_plugin_savepoint(true, 2008000217, 'local', 'qedatabase');
Expand All @@ -415,7 +415,7 @@ function xmldb_local_qedatabase_install() {
}

if ($oldversion < 2008000221) {
unset_config('quiz_review');
unset_config('review', 'quiz');

// quiz savepoint reached
upgrade_plugin_savepoint(true, 2008000221, 'local', 'qedatabase');
Expand Down
15 changes: 14 additions & 1 deletion question/engine/upgrade/behaviourconverters.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,20 @@ protected function process10($step, $state) {
* @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);
}

Expand Down
114 changes: 114 additions & 0 deletions question/engine/upgrade/simpletest/helper.php
Original file line number Diff line number Diff line change
@@ -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;
}
}
Loading

0 comments on commit 38d42fc

Please sign in to comment.