Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
// This file is part of Moodle - https://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
 * Provides {@see mod_subcourse_external_testcase} class.
19
 *
20
 * @copyright   2020 David Mudrák <david@moodle.com>
21
 * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
22
 */
23
 
24
defined('MOODLE_INTERNAL') || die();
25
 
26
global $CFG;
27
require_once($CFG->dirroot . '/webservice/tests/helpers.php');
28
 
29
/**
30
 * Unit tests for the external functions provided by the plugin.
31
 *
32
 * @package   mod_subcourse
33
 * @category  test
34
 * @copyright 2020 David Mudrák <david@moodle.com>
35
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
36
 */
37
class mod_subcourse_external_testcase extends externallib_advanced_testcase {
38
 
39
    /**
40
     * Test the external function mod_subcourse_view_subcourse.
41
     */
42
    public function test_view_subcourse() {
43
        global $USER;
44
 
45
        $this->resetAfterTest();
46
        $this->setAdminUser();
47
 
48
        $generator = $this->getDataGenerator();
49
 
50
        $metacourse = $generator->create_course();
51
        $student = $generator->create_user();
52
        $subcourse = $generator->create_module('subcourse', [
53
            'course' => $metacourse->id,
54
        ]);
55
        $generator->enrol_user($student->id, $metacourse->id, 'student');
56
 
57
        list($course, $cm) = get_course_and_cm_from_instance($subcourse->id, 'subcourse');
58
        $context = context_module::instance($cm->id);
59
 
60
        $returnvalue = \mod_subcourse\external\view_subcourse::execute($subcourse->id);
61
 
62
        // Clean value to simulate the web service server.
63
        $returnvalue = external_api::clean_returnvalue(\mod_subcourse\external\view_subcourse::execute_returns(), $returnvalue);
64
 
65
        $this->assertEquals(true, $returnvalue['status']);
66
    }
67
}