Proyectos de Subversion Moodle

Rev

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

Rev 11 Rev 1441
Línea 28... Línea 28...
28
 * @copyright  2022 Catalyst IT Australia Pty Ltd
28
 * @copyright  2022 Catalyst IT Australia Pty Ltd
29
 * @author     Safat Shahin <safatshahin@catalyst-au.net>
29
 * @author     Safat Shahin <safatshahin@catalyst-au.net>
30
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
30
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
31
 * @coversDefaultClass \qbank_history\question_history_view
31
 * @coversDefaultClass \qbank_history\question_history_view
32
 */
32
 */
33
class question_history_view_test extends \advanced_testcase {
33
final class question_history_view_test extends \advanced_testcase {
Línea 34... Línea 34...
34
 
34
 
35
    /**
35
    /**
36
     * Test that the history page shows all the versions of a question.
36
     * Test that the history page shows all the versions of a question.
37
     *
37
     *
Línea 43... Línea 43...
43
        $generator = $this->getDataGenerator();
43
        $generator = $this->getDataGenerator();
44
        $questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question');
44
        $questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question');
Línea 45... Línea 45...
45
 
45
 
46
        // Create a course.
46
        // Create a course.
-
 
47
        $course = $generator->create_course();
-
 
48
        $qbank = $generator->create_module('qbank', ['course' => $course->id]);
47
        $course = $generator->create_course();
49
        $cm = get_coursemodule_from_id('qbank', $qbank->cmid);
Línea 48... Línea 50...
48
        $context = \context_course::instance($course->id);
50
        $context = \context_module::instance($qbank->cmid);
49
 
51
 
50
        // Create a question in the default category.
52
        // Create a question in the default category.
51
        $contexts = new \core_question\local\bank\question_edit_contexts($context);
53
        $contexts = new \core_question\local\bank\question_edit_contexts($context);
52
        $cat = $questiongenerator->create_question_category();
54
        $cat = $questiongenerator->create_question_category(['contextid' => $context->id]);
Línea 53... Línea 55...
53
        $questiondata1 = $questiongenerator->create_question('numerical', null,
55
        $questiondata1 = $questiongenerator->create_question('numerical', null,
54
            ['name' => 'Example question', 'category' => $cat->id]);
56
            ['name' => 'Example question', 'category' => $cat->id]);
Línea 70... Línea 72...
70
        $extraparams = [
72
        $extraparams = [
71
            'view' => $viewclass,
73
            'view' => $viewclass,
72
            'entryid' => $entry->id,
74
            'entryid' => $entry->id,
73
            'returnurl' => "/",
75
            'returnurl' => "/",
74
        ];
76
        ];
75
        $view = new $viewclass($contexts, new \moodle_url('/'), $course, null, $pagevars, $extraparams);
77
        $view = new $viewclass($contexts, new \moodle_url('/'), $course, $cm, $pagevars, $extraparams);
76
        ob_start();
78
        ob_start();
77
        $view->display();
79
        $view->display();
78
        $html = ob_get_clean();
80
        $html = ob_get_clean();
Línea 79... Línea 81...
79
 
81
 
Línea 95... Línea 97...
95
        $generator = $this->getDataGenerator();
97
        $generator = $this->getDataGenerator();
96
        $questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question');
98
        $questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question');
Línea 97... Línea 99...
97
 
99
 
98
        // Create a course.
100
        // Create a course.
-
 
101
        $course = $generator->create_course();
-
 
102
        $qbank = $generator->create_module('qbank', ['course' => $course->id]);
99
        $course = $generator->create_course();
103
        $cm = get_coursemodule_from_id('qbank', $qbank->cmid);
Línea 100... Línea 104...
100
        $context = \context_course::instance($course->id);
104
        $context = \context_module::instance($cm->id);
101
 
105
 
102
        // Create a question in the default category.
106
        // Create a question in the default category.
103
        $contexts = new \core_question\local\bank\question_edit_contexts($context);
107
        $contexts = new \core_question\local\bank\question_edit_contexts($context);
Línea 117... Línea 121...
117
        $extraparams = [
121
        $extraparams = [
118
            'view' => $viewclass,
122
            'view' => $viewclass,
119
            'entryid' => $entry->id,
123
            'entryid' => $entry->id,
120
            'returnurl' => "/",
124
            'returnurl' => "/",
121
        ];
125
        ];
122
        $view = new $viewclass($contexts, new \moodle_url('/'), $course,  null, $pagevars, $extraparams);
126
        $view = new $viewclass($contexts, new \moodle_url('/'), $course, $cm, $pagevars, $extraparams);
123
        ob_start();
127
        ob_start();
124
        $view->display_question_bank_header();
128
        $view->display_question_bank_header();
125
        $headerhtml = ob_get_clean();
129
        $headerhtml = ob_get_clean();
126
        // Verify the output includes the latest version.
130
        // Verify the output includes the latest version.
127
        $this->assertStringContainsString($questiondata1->name, $headerhtml);
131
        $this->assertStringContainsString($questiondata1->name, $headerhtml);
Línea 128... Línea 132...
128
 
132
 
129
        $questiondata2 = $questiongenerator->update_question($questiondata1, null,
133
        $questiondata2 = $questiongenerator->update_question($questiondata1, null,
130
            ['name' => 'Second version']);
134
            ['name' => 'Second version']);
131
        $view = new $viewclass($contexts, new \moodle_url('/'), $course,  null, $pagevars, $extraparams);
135
        $view = new $viewclass($contexts, new \moodle_url('/'), $course, $cm, $pagevars, $extraparams);
132
        ob_start();
136
        ob_start();
133
        $view->display_question_bank_header();
137
        $view->display_question_bank_header();
Línea 134... Línea 138...
134
        $headerhtml = ob_get_clean();
138
        $headerhtml = ob_get_clean();