Proyectos de Subversion Moodle

Rev

Rev 11 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
// This file is part of Moodle - http://moodle.org/
3
//
4
// Moodle is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// Moodle is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16
 
17
namespace qbank_history;
18
 
19
use question_bank;
20
 
21
/**
22
 * Helper class test.
23
 *
24
 * @package    qbank_history
25
 * @copyright  2022 Catalyst IT Australia Pty Ltd
26
 * @author     Safat Shahin <safatshahin@catalyst-au.net>
27
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28
 * @coversDefaultClass \qbank_history\helper
29
 */
1441 ariadna 30
final class helper_test extends \advanced_testcase {
1 efrain 31
    /**
32
     * @var bool|\context|\context_course $context
33
     */
34
    public $context;
35
 
36
    /**
37
     * @var object $questiondata;
38
     */
39
    public $questiondata;
40
 
41
    /**
42
     * @var \moodle_url $returnurl
43
     */
44
    public $returnurl;
45
 
46
    /**
47
     * @var int $courseid
48
     */
49
    public $courseid;
50
 
51
    /**
52
     * Test set up.
53
     *
54
     * This is executed before running any test in this file.
55
     */
56
    public function setUp(): void {
1441 ariadna 57
        parent::setUp();
1 efrain 58
        $this->setAdminUser();
59
        $generator = $this->getDataGenerator();
60
        $questiongenerator = $generator->get_plugin_generator('core_question');
61
        // Create a course.
62
        $course = $generator->create_course();
1441 ariadna 63
        $qbank = self::getDataGenerator()->create_module('qbank', ['course' => $course->id]);
1 efrain 64
        $this->courseid = $course->id;
1441 ariadna 65
        $this->context = \context_module::instance($qbank->cmid);
1 efrain 66
        // Create a question in the default category.
67
        $contexts = new \core_question\local\bank\question_edit_contexts($this->context);
1441 ariadna 68
        $cat = question_get_default_category($contexts->lowest()->id, true);
1 efrain 69
        $question = $questiongenerator->create_question('numerical', null,
70
            ['name' => 'Example question', 'category' => $cat->id]);
71
        $this->questiondata = question_bank::load_question($question->id);
72
        $this->returnurl = new \moodle_url('/question/edit.php');
73
    }
74
 
75
    /**
76
     * Test the history action url from the helper class.
77
     *
78
     * @covers ::question_history_url
79
     */
11 efrain 80
    public function test_question_history_url(): void {
1 efrain 81
        $this->resetAfterTest();
82
        $filter = urlencode('filters[]');
1441 ariadna 83
        $actionurl = helper::get_question_history_url(
1 efrain 84
            $this->questiondata->questionbankentryid,
85
            $this->returnurl,
1441 ariadna 86
            $this->context->instanceid,
1 efrain 87
            $filter,
88
        );
89
        $params = [
90
            'entryid' => $this->questiondata->questionbankentryid,
91
            'returnurl' => $this->returnurl,
1441 ariadna 92
            'cmid' => $this->context->instanceid,
1 efrain 93
            'filter' => $filter,
94
        ];
95
        $expectedurl = new \moodle_url('/question/bank/history/history.php', $params);
96
        $this->assertEquals($expectedurl, $actionurl);
97
    }
98
 
99
    /**
100
     * Test the history action url when the filter parameter is null.
101
     *
102
     * @covers ::question_history_url
103
     */
11 efrain 104
    public function test_question_history_url_null_filter(): void {
1 efrain 105
        $this->resetAfterTest();
1441 ariadna 106
        $actionurl = helper::get_question_history_url(
1 efrain 107
            $this->questiondata->questionbankentryid,
108
            $this->returnurl,
1441 ariadna 109
            $this->context->instanceid,
1 efrain 110
            null,
111
        );
112
        $params = [
113
            'entryid' => $this->questiondata->questionbankentryid,
114
            'returnurl' => $this->returnurl,
1441 ariadna 115
            'cmid' => $this->context->instanceid,
1 efrain 116
        ];
117
        $expectedurl = new \moodle_url('/question/bank/history/history.php', $params);
118
        $this->assertEquals($expectedurl, $actionurl);
119
    }
120
}