Proyectos de Subversion Moodle

Rev

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

Rev 11 Rev 1441
Línea 25... Línea 25...
25
 * @copyright  2022 Catalyst IT Australia Pty Ltd
25
 * @copyright  2022 Catalyst IT Australia Pty Ltd
26
 * @author     Safat Shahin <safatshahin@catalyst-au.net>
26
 * @author     Safat Shahin <safatshahin@catalyst-au.net>
27
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28
 * @coversDefaultClass \qbank_history\helper
28
 * @coversDefaultClass \qbank_history\helper
29
 */
29
 */
30
class helper_test extends \advanced_testcase {
30
final class helper_test extends \advanced_testcase {
31
    /**
31
    /**
32
     * @var bool|\context|\context_course $context
32
     * @var bool|\context|\context_course $context
33
     */
33
     */
34
    public $context;
34
    public $context;
Línea 52... Línea 52...
52
     * Test set up.
52
     * Test set up.
53
     *
53
     *
54
     * This is executed before running any test in this file.
54
     * This is executed before running any test in this file.
55
     */
55
     */
56
    public function setUp(): void {
56
    public function setUp(): void {
-
 
57
        parent::setUp();
57
        $this->setAdminUser();
58
        $this->setAdminUser();
58
        $generator = $this->getDataGenerator();
59
        $generator = $this->getDataGenerator();
59
        $questiongenerator = $generator->get_plugin_generator('core_question');
60
        $questiongenerator = $generator->get_plugin_generator('core_question');
60
        // Create a course.
61
        // Create a course.
61
        $course = $generator->create_course();
62
        $course = $generator->create_course();
-
 
63
        $qbank = self::getDataGenerator()->create_module('qbank', ['course' => $course->id]);
62
        $this->courseid = $course->id;
64
        $this->courseid = $course->id;
63
        $this->context = \context_course::instance($course->id);
65
        $this->context = \context_module::instance($qbank->cmid);
64
        // Create a question in the default category.
66
        // Create a question in the default category.
65
        $contexts = new \core_question\local\bank\question_edit_contexts($this->context);
67
        $contexts = new \core_question\local\bank\question_edit_contexts($this->context);
66
        $cat = question_make_default_categories($contexts->all());
68
        $cat = question_get_default_category($contexts->lowest()->id, true);
67
        $question = $questiongenerator->create_question('numerical', null,
69
        $question = $questiongenerator->create_question('numerical', null,
68
            ['name' => 'Example question', 'category' => $cat->id]);
70
            ['name' => 'Example question', 'category' => $cat->id]);
69
        $this->questiondata = question_bank::load_question($question->id);
71
        $this->questiondata = question_bank::load_question($question->id);
70
        $this->returnurl = new \moodle_url('/question/edit.php');
72
        $this->returnurl = new \moodle_url('/question/edit.php');
71
    }
73
    }
Línea 76... Línea 78...
76
     * @covers ::question_history_url
78
     * @covers ::question_history_url
77
     */
79
     */
78
    public function test_question_history_url(): void {
80
    public function test_question_history_url(): void {
79
        $this->resetAfterTest();
81
        $this->resetAfterTest();
80
        $filter = urlencode('filters[]');
82
        $filter = urlencode('filters[]');
81
        $actionurl = helper::question_history_url(
83
        $actionurl = helper::get_question_history_url(
82
            $this->questiondata->questionbankentryid,
84
            $this->questiondata->questionbankentryid,
83
            $this->returnurl,
85
            $this->returnurl,
84
            $this->courseid,
86
            $this->context->instanceid,
85
            $filter,
87
            $filter,
86
        );
88
        );
87
        $params = [
89
        $params = [
88
            'entryid' => $this->questiondata->questionbankentryid,
90
            'entryid' => $this->questiondata->questionbankentryid,
89
            'returnurl' => $this->returnurl,
91
            'returnurl' => $this->returnurl,
90
            'courseid' => $this->courseid,
92
            'cmid' => $this->context->instanceid,
91
            'filter' => $filter,
93
            'filter' => $filter,
92
        ];
94
        ];
93
        $expectedurl = new \moodle_url('/question/bank/history/history.php', $params);
95
        $expectedurl = new \moodle_url('/question/bank/history/history.php', $params);
94
        $this->assertEquals($expectedurl, $actionurl);
96
        $this->assertEquals($expectedurl, $actionurl);
95
    }
97
    }
Línea 99... Línea 101...
99
     *
101
     *
100
     * @covers ::question_history_url
102
     * @covers ::question_history_url
101
     */
103
     */
102
    public function test_question_history_url_null_filter(): void {
104
    public function test_question_history_url_null_filter(): void {
103
        $this->resetAfterTest();
105
        $this->resetAfterTest();
104
        $actionurl = helper::question_history_url(
106
        $actionurl = helper::get_question_history_url(
105
            $this->questiondata->questionbankentryid,
107
            $this->questiondata->questionbankentryid,
106
            $this->returnurl,
108
            $this->returnurl,
107
            $this->courseid,
109
            $this->context->instanceid,
108
            null,
110
            null,
109
        );
111
        );
110
        $params = [
112
        $params = [
111
            'entryid' => $this->questiondata->questionbankentryid,
113
            'entryid' => $this->questiondata->questionbankentryid,
112
            'returnurl' => $this->returnurl,
114
            'returnurl' => $this->returnurl,
113
            'courseid' => $this->courseid,
115
            'cmid' => $this->context->instanceid,
114
        ];
116
        ];
115
        $expectedurl = new \moodle_url('/question/bank/history/history.php', $params);
117
        $expectedurl = new \moodle_url('/question/bank/history/history.php', $params);
116
        $this->assertEquals($expectedurl, $actionurl);
118
        $this->assertEquals($expectedurl, $actionurl);
117
    }
119
    }
118
}
120
}