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 |
namespace tool_brickfield\local\areas\core_question;
|
|
|
17 |
|
|
|
18 |
defined('MOODLE_INTERNAL') || die();
|
|
|
19 |
|
|
|
20 |
global $CFG;
|
|
|
21 |
require_once($CFG->dirroot . '/admin/tool/brickfield/tests/area_test_base.php');
|
|
|
22 |
|
|
|
23 |
use tool_brickfield\area_test_base;
|
|
|
24 |
|
|
|
25 |
/**
|
|
|
26 |
* Tests for questiontext.
|
|
|
27 |
*
|
|
|
28 |
* @package tool_brickfield
|
|
|
29 |
* @copyright 2020 onward: Brickfield Education Labs, https://www.brickfield.ie
|
|
|
30 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
31 |
* @coversDefaultClass \tool_brickfield\local\areas\core_question\base
|
|
|
32 |
*/
|
1441 |
ariadna |
33 |
final class questiontext_test extends area_test_base {
|
1 |
efrain |
34 |
/**
|
|
|
35 |
* Set up before class.
|
|
|
36 |
*/
|
|
|
37 |
public static function setUpBeforeClass(): void {
|
|
|
38 |
global $CFG;
|
|
|
39 |
require_once($CFG->dirroot . '/mod/quiz/locallib.php');
|
1441 |
ariadna |
40 |
parent::setUpBeforeClass();
|
1 |
efrain |
41 |
}
|
|
|
42 |
|
|
|
43 |
/**
|
|
|
44 |
* Test find relevant areas.
|
|
|
45 |
*/
|
11 |
efrain |
46 |
public function test_find_relevant_areas(): void {
|
1 |
efrain |
47 |
$this->resetAfterTest();
|
|
|
48 |
$this->setAdminUser();
|
|
|
49 |
|
|
|
50 |
$course = $this->getDataGenerator()->create_course();
|
1441 |
ariadna |
51 |
$qbank = $this->getDataGenerator()->create_module('qbank', ['course' => $course->id]);
|
|
|
52 |
$qbankcontext = \context_module::instance($qbank->cmid);
|
1 |
efrain |
53 |
$generator = $this->getDataGenerator()->get_plugin_generator('core_question');
|
1441 |
ariadna |
54 |
$cat1 = $generator->create_question_category(['contextid' => $qbankcontext->id]);
|
1 |
efrain |
55 |
$question1 = $generator->create_question('multichoice', null, ['category' => $cat1->id]);
|
|
|
56 |
$question2 = $generator->create_question('multichoice', null, ['category' => $cat1->id]);
|
|
|
57 |
$questiontext = new questiontext();
|
|
|
58 |
$event = \core\event\question_updated::create_from_question_instance($question1,
|
|
|
59 |
\context_course::instance($course->id));
|
|
|
60 |
$rs = $questiontext->find_relevant_areas($event);
|
|
|
61 |
$this->assertNotNull($rs);
|
|
|
62 |
|
|
|
63 |
$count = 0;
|
|
|
64 |
foreach ($rs as $rec) {
|
|
|
65 |
$count++;
|
1441 |
ariadna |
66 |
$this->assertEquals($qbankcontext->id, $rec->contextid);
|
1 |
efrain |
67 |
$this->assertEquals($course->id, $rec->courseid);
|
|
|
68 |
$this->assertEquals($question1->id, $rec->itemid);
|
|
|
69 |
}
|
|
|
70 |
$rs->close();
|
|
|
71 |
$this->assertEquals(1, $count);
|
|
|
72 |
}
|
|
|
73 |
|
|
|
74 |
/**
|
|
|
75 |
* Test get course and category.
|
|
|
76 |
*
|
|
|
77 |
* @covers ::get_course_and_category
|
|
|
78 |
*/
|
11 |
efrain |
79 |
public function test_get_course_and_category(): void {
|
1 |
efrain |
80 |
$this->resetAfterTest();
|
|
|
81 |
$this->setAdminUser();
|
|
|
82 |
|
|
|
83 |
$course = $this->getDataGenerator()->create_course();
|
1441 |
ariadna |
84 |
$qbank = $this->getDataGenerator()->create_module('qbank', ['course' => $course->id]);
|
|
|
85 |
$qbankcontext = \context_module::instance($qbank->cmid);
|
1 |
efrain |
86 |
$generator = $this->getDataGenerator()->get_plugin_generator('core_question');
|
1441 |
ariadna |
87 |
$cat1 = $generator->create_question_category(['contextid' => $qbankcontext->id]);
|
1 |
efrain |
88 |
$question1 = $generator->create_question('multichoice', null, ['category' => $cat1->id]);
|
1441 |
ariadna |
89 |
$event = \core\event\question_updated::create_from_question_instance($question1, $qbankcontext);
|
|
|
90 |
$rs = base::get_course_and_category(CONTEXT_MODULE, $event->objectid);
|
1 |
efrain |
91 |
$this->assertNotNull($rs);
|
1441 |
ariadna |
92 |
$this->assertEquals(CONTEXT_MODULE, $rs->contextlevel);
|
|
|
93 |
// Invalid objectid and contextlevel.
|
1 |
efrain |
94 |
$rs = base::get_course_and_category(CONTEXT_COURSE, 0);
|
|
|
95 |
$this->assertFalse($rs);
|
1441 |
ariadna |
96 |
$this->assertDebuggingCalled();
|
1 |
efrain |
97 |
}
|
|
|
98 |
}
|