Proyectos de Subversion Moodle

Rev

Rev 11 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 11 Rev 1441
Línea 26... Línea 26...
26
 *
26
 *
27
 * @package    qtype_essay
27
 * @package    qtype_essay
28
 * @copyright  2019 The Open University
28
 * @copyright  2019 The Open University
29
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
29
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
30
 */
30
 */
31
class restore_test extends \restore_date_testcase {
31
final class restore_test extends \restore_date_testcase {
Línea 32... Línea 32...
32
 
32
 
33
    /**
33
    /**
34
     * Test missing qtype_essay_options creation.
34
     * Test missing qtype_essay_options creation.
35
     *
35
     *
Línea 41... Línea 41...
41
        global $DB;
41
        global $DB;
Línea 42... Línea 42...
42
 
42
 
43
        // Create a course with one essay question in its question bank.
43
        // Create a course with one essay question in its question bank.
44
        $generator = $this->getDataGenerator();
44
        $generator = $this->getDataGenerator();
45
        $course = $generator->create_course();
45
        $course = $generator->create_course();
-
 
46
        $qbank = $generator->create_module('qbank', ['course' => $course->id]);
46
        $contexts = new \core_question\local\bank\question_edit_contexts(\context_course::instance($course->id));
47
        $context = \context_module::instance($qbank->cmid);
47
        $category = question_make_default_categories($contexts->all());
48
        $category = question_get_default_category($context->id, true);
48
        $questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question');
49
        $questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question');
Línea 49... Línea 50...
49
        $essay = $questiongenerator->create_question('essay', null, array('category' => $category->id));
50
        $essay = $questiongenerator->create_question('essay', null, array('category' => $category->id));
50
 
51
 
Línea 51... Línea 52...
51
        // Remove the options record, which means that the backup will look like a backup made in an old Moodle.
52
        // Remove the options record, which means that the backup will look like a backup made in an old Moodle.
52
        $DB->delete_records('qtype_essay_options', ['questionid' => $essay->id]);
53
        $DB->delete_records('qtype_essay_options', ['questionid' => $essay->id]);
Línea -... Línea 54...
-
 
54
 
-
 
55
        // Do backup and restore.
-
 
56
        $newcourseid = $this->backup_and_restore($course);
-
 
57
 
-
 
58
        $modinfo = get_fast_modinfo($newcourseid);
-
 
59
        $newqbanks = array_filter(
-
 
60
            $modinfo->get_instances_of('qbank'),
53
 
61
            static fn($qbank) => $qbank->get_name() === 'Question bank 1'
54
        // Do backup and restore.
-
 
55
        $newcourseid = $this->backup_and_restore($course);
62
        );
56
 
63
        $newqbank = reset($newqbanks);
57
        // Verify that the restored question has options.
64
 
58
        $contexts = new \core_question\local\bank\question_edit_contexts(\context_course::instance($newcourseid));
65
        // Verify that the restored question has options.
59
        $newcategory = question_make_default_categories($contexts->all());
66
        $newcategory = question_get_default_category(\context_module::instance($newqbank->id)->id, true);
60
        $newessay = $DB->get_record_sql('SELECT q.*
67
        $newessay = $DB->get_record_sql('SELECT q.*