Proyectos de Subversion Moodle

Rev

Ir a la última revisión | | 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
/**
18
 * Unit test for mod_survey searching.
19
 *
20
 * This is needed because the activity.php class overrides default behaviour.
21
 *
22
 * @package mod_survey
23
 * @category test
24
 * @copyright 2017 The Open University
25
 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26
 */
27
 
28
namespace mod_survey\search;
29
 
30
/**
31
 * Unit test for mod_survey searching.
32
 *
33
 * This is needed because the activity.php class overrides default behaviour.
34
 *
35
 * @package mod_survey
36
 * @category test
37
 * @copyright 2017 The Open University
38
 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
39
 */
40
class search_test extends \advanced_testcase {
41
 
42
    /**
43
     * Setup testcase.
44
     */
45
    public function setUp(): void {
46
        // Survey module is disabled by default, enable it for testing.
47
        $manager = \core_plugin_manager::resolve_plugininfo_class('mod');
48
        $manager::enable_plugin('survey', 1);
49
    }
50
 
51
    /**
52
     * Test survey_view
53
     * @return void
54
     */
55
    public function test_survey_indexing() {
56
        global $CFG;
57
 
58
        $this->resetAfterTest();
59
 
60
        require_once($CFG->dirroot . '/search/tests/fixtures/testable_core_search.php');
61
        \testable_core_search::instance();
62
        $area = \core_search\manager::get_search_area('mod_survey-activity');
63
 
64
        // Setup test data.
65
        $generator = $this->getDataGenerator();
66
        $course = $generator->create_course();
67
        $survey1 = $generator->create_module('survey', ['course' => $course->id]);
68
        $survey2 = $generator->create_module('survey', ['course' => $course->id]);
69
 
70
        // Get all surveys for indexing - note that there are special entries in the table with
71
        // course zero which should not be returned.
72
        $rs = $area->get_document_recordset();
73
        $this->assertEquals(2, iterator_count($rs));
74
        $rs->close();
75
 
76
        // Test specific context and course context.
77
        $rs = $area->get_document_recordset(0, \context_module::instance($survey1->cmid));
78
        $this->assertEquals(1, iterator_count($rs));
79
        $rs->close();
80
        $rs = $area->get_document_recordset(0, \context_course::instance($course->id));
81
        $this->assertEquals(2, iterator_count($rs));
82
        $rs->close();
83
    }
84
}