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
namespace mod_bigbluebuttonbn\external;
18
 
19
use core_external\external_api;
20
use mod_bigbluebuttonbn\instance;
21
use mod_bigbluebuttonbn\test\testcase_helper_trait;
22
use require_login_exception;
23
 
24
defined('MOODLE_INTERNAL') || die();
25
 
26
global $CFG;
27
require_once($CFG->dirroot . '/webservice/tests/helpers.php');
28
 
29
/**
30
 * Tests for the view_bigbluebuttonbn class.
31
 *
32
 * @package    mod_bigbluebuttonbn
33
 * @category   test
34
 * @copyright  2021 - present, Blindside Networks Inc
35
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
36
 * @author    Laurent David (laurent@call-learning.fr)
37
 * @covers \mod_bigbluebuttonbn\external\view_bigbluebuttonbn
38
 */
39
class view_bigbluebuttonbn_test extends \externallib_advanced_testcase {
40
    use testcase_helper_trait;
41
 
42
    /**
43
     * Setup for test
44
     */
45
    public function setUp(): void {
46
        parent::setUp();
47
        $this->initialise_mock_server();
48
    }
49
 
50
    /**
51
     * Helper
52
     *
53
     * @param mixed ...$params
54
     * @return mixed
55
     */
56
    protected function view_bigbluebuttonbn(...$params) {
57
        $returnvalue = view_bigbluebuttonbn::execute(...$params);
58
 
59
        return external_api::clean_returnvalue(view_bigbluebuttonbn::execute_returns(), $returnvalue);
60
    }
61
 
62
    /**
63
     * Test execute API CALL with no instance
64
     */
65
    public function test_execute_no_instance() {
66
        $this->resetAfterTest();
67
        $bbbactivities = $this->view_bigbluebuttonbn(1234);
68
 
69
        $this->assertIsArray($bbbactivities);
70
        $this->assertArrayHasKey('status', $bbbactivities);
71
        $this->assertArrayHasKey('warnings', $bbbactivities);
72
        $this->assertFalse($bbbactivities['status']);
73
    }
74
 
75
    /**
76
     * Test execute API CALL without login
77
     */
78
    public function test_execute_without_login() {
79
        $this->resetAfterTest();
80
 
81
        $course = $this->getDataGenerator()->create_course();
82
        $record = $this->getDataGenerator()->create_module('bigbluebuttonbn', ['course' => $course->id]);
83
        $instance = instance::get_from_instanceid($record->id);
84
        $this->expectException(require_login_exception::class);
85
        $this->view_bigbluebuttonbn($instance->get_instance_id());
86
    }
87
 
88
    /**
89
     * Test execute API CALL with invalid login
90
     */
91
    public function test_execute_with_invalid_login() {
92
        $this->resetAfterTest();
93
 
94
        $generator = $this->getDataGenerator();
95
        $course = $generator->create_course();
96
        $record = $generator->create_module('bigbluebuttonbn', ['course' => $course->id]);
97
        $instance = instance::get_from_instanceid($record->id);
98
 
99
        $user = $generator->create_user($course);
100
        $this->setUser($user);
101
        $this->expectException(require_login_exception::class);
102
        $this->view_bigbluebuttonbn($instance->get_instance_id());
103
    }
104
 
105
    /**
106
     * When login as a student
107
     */
108
    public function test_execute_with_valid_login() {
109
        $this->resetAfterTest();
110
 
111
        $generator = $this->getDataGenerator();
112
        $course = $generator->create_course();
113
        $record = $generator->create_module('bigbluebuttonbn', ['course' => $course->id]);
114
        $instance = instance::get_from_instanceid($record->id);
115
 
116
        $user = $generator->create_and_enrol($course, 'student');
117
        $this->setUser($user);
118
 
119
        $returnvalue = $this->view_bigbluebuttonbn($instance->get_instance_id());
120
 
121
        $this->assertArrayHasKey('status', $returnvalue);
122
        $this->assertArrayHasKey('warnings', $returnvalue);
123
        $this->assertTrue($returnvalue['status']);
124
    }
125
}
126