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 tool_brickfield\local\areas\core_question;
18
 
19
/**
20
 * Tests for questionanswer.
21
 *
22
 * @package     tool_brickfield
23
 * @copyright   2020 onward: Brickfield Education Labs, https://www.brickfield.ie
24
 * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25
 */
1441 ariadna 26
final class questionanswers_test extends \advanced_testcase {
1 efrain 27
 
28
    /**
29
     * Set up before class.
30
     */
31
    public static function setUpBeforeClass(): void {
32
        global $CFG;
33
        require_once($CFG->dirroot . '/mod/quiz/locallib.php');
1441 ariadna 34
        parent::setUpBeforeClass();
1 efrain 35
    }
36
 
37
    /**
38
     * Test find relevant areas.
39
     */
11 efrain 40
    public function test_find_relevant_areas(): void {
1 efrain 41
        $this->resetAfterTest();
42
        $this->setAdminUser();
43
 
44
        $course = $this->getDataGenerator()->create_course();
1441 ariadna 45
        $qbank = $this->getDataGenerator()->create_module('qbank', ['course' => $course->id]);
46
        $qbankcontext = \context_module::instance($qbank->cmid);
1 efrain 47
        $generator = $this->getDataGenerator()->get_plugin_generator('core_question');
1441 ariadna 48
        $cat1 = $generator->create_question_category(['contextid' => $qbankcontext->id]);
1 efrain 49
        $question1 = $generator->create_question('multichoice', null, ['category' => $cat1->id]);
50
        $question2 = $generator->create_question('multichoice', null, ['category' => $cat1->id]);
51
        $questionanswers = new questionanswers();
52
        $event = \core\event\question_updated::create_from_question_instance($question1,
53
            \context_course::instance($course->id));
54
        $rs = $questionanswers->find_relevant_areas($event);
55
        $this->assertNotNull($rs);
56
 
57
        // Each multichoice question generated has four answers.
58
        $count = 0;
59
        foreach ($rs as $rec) {
60
            $count++;
1441 ariadna 61
            $this->assertEquals($qbankcontext->id, $rec->contextid);
1 efrain 62
            $this->assertEquals($course->id, $rec->courseid);
63
            $this->assertEquals($question1->id, $rec->refid);
64
        }
65
        $rs->close();
66
        $this->assertEquals(4, $count);
67
    }
68
}