1441 |
ariadna |
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 |
declare(strict_types=1);
|
|
|
18 |
|
|
|
19 |
namespace tiny_recordrtc;
|
|
|
20 |
|
|
|
21 |
use advanced_testcase;
|
|
|
22 |
|
|
|
23 |
/**
|
|
|
24 |
* Unit tests for the \tiny_recordrtc\plugininfo class.
|
|
|
25 |
*
|
|
|
26 |
* @package tiny_recordrtc
|
|
|
27 |
* @covers \tiny_recordrtc\plugininfo::is_enabled_for_external
|
|
|
28 |
* @covers \tiny_recordrtc\plugininfo::get_plugin_configuration_for_external
|
|
|
29 |
* @copyright 2025 Moodle Pty Ltd
|
|
|
30 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
31 |
*/
|
|
|
32 |
final class plugininfo_test extends advanced_testcase {
|
|
|
33 |
|
|
|
34 |
/**
|
|
|
35 |
* Basic setup for tests.
|
|
|
36 |
*/
|
|
|
37 |
public function setUp(): void {
|
|
|
38 |
parent::setUp();
|
|
|
39 |
$this->resetAfterTest(true);
|
|
|
40 |
}
|
|
|
41 |
|
|
|
42 |
/**
|
|
|
43 |
* Test the is_enabled_for_external and get_plugin_configuration_for_external methods.
|
|
|
44 |
*
|
|
|
45 |
* @dataProvider for_external_provider
|
|
|
46 |
* @param bool $guest Use a guest user.
|
|
|
47 |
* @param bool $expectedenabled Expected result for is_enabled_for_external.
|
|
|
48 |
* @param array $expectedconfiguration Expected result for get_plugin_configuration_for_external.
|
|
|
49 |
* @return void
|
|
|
50 |
*/
|
|
|
51 |
public function test_for_external(bool $guest, bool $expectedenabled, array $expectedconfiguration): void {
|
|
|
52 |
global $CFG;
|
|
|
53 |
|
|
|
54 |
$generator = $this->getDataGenerator();
|
|
|
55 |
$user = $generator->create_user();
|
|
|
56 |
$context = \context_system::instance();
|
|
|
57 |
if ($guest) {
|
|
|
58 |
$this->setUser($user);
|
|
|
59 |
} else {
|
|
|
60 |
$this->setGuestUser();
|
|
|
61 |
}
|
|
|
62 |
|
|
|
63 |
$this->assertEquals($expectedenabled, plugininfo::is_enabled_for_external($context, ['pluginname' => 'recordrtc']));
|
|
|
64 |
$this->assertEquals($expectedconfiguration, plugininfo::get_plugin_configuration_for_external($context));
|
|
|
65 |
}
|
|
|
66 |
|
|
|
67 |
/**
|
|
|
68 |
* Data provider for test_for_external.
|
|
|
69 |
*
|
|
|
70 |
* @return array
|
|
|
71 |
*/
|
|
|
72 |
public static function for_external_provider(): array {
|
|
|
73 |
$settings = [
|
|
|
74 |
'pausingallowed' => get_config('tiny_recordrtc', 'allowedpausing'),
|
|
|
75 |
'allowedtypes' => get_config('tiny_recordrtc', 'allowedtypes'),
|
|
|
76 |
'audiobitrate' => get_config('tiny_recordrtc', 'audiobitrate'),
|
|
|
77 |
'videobitrate' => get_config('tiny_recordrtc', 'videobitrate'),
|
|
|
78 |
'screenbitrate' => get_config('tiny_recordrtc', 'screenbitrate'),
|
|
|
79 |
'audiotimelimit' => get_config('tiny_recordrtc', 'audiotimelimit'),
|
|
|
80 |
'videotimelimit' => get_config('tiny_recordrtc', 'videotimelimit'),
|
|
|
81 |
'screentimelimit' => get_config('tiny_recordrtc', 'screentimelimit'),
|
|
|
82 |
'maxrecsize' => (string) get_max_upload_file_size(),
|
|
|
83 |
'videoscreenwidth' => explode(',', get_config('tiny_recordrtc', 'screensize'))[0],
|
|
|
84 |
'videoscreenheight' => explode(',', get_config('tiny_recordrtc', 'screensize'))[1],
|
|
|
85 |
'audiortcformat' => (string) get_config('tiny_recordrtc', 'audiortcformat'),
|
|
|
86 |
];
|
|
|
87 |
$allowedtypes = explode(',', $settings['allowedtypes']);
|
|
|
88 |
|
|
|
89 |
return [
|
|
|
90 |
[
|
|
|
91 |
'guest' => false,
|
|
|
92 |
'expectedenabled' => false,
|
|
|
93 |
'expectedconfiguration' => [
|
|
|
94 |
'videoallowed' => '0',
|
|
|
95 |
'audioallowed' => '0',
|
|
|
96 |
'screenallowed' => '0',
|
|
|
97 |
...$settings,
|
|
|
98 |
],
|
|
|
99 |
],
|
|
|
100 |
[
|
|
|
101 |
'guest' => true,
|
|
|
102 |
'expectedenabled' => true,
|
|
|
103 |
'expectedconfiguration' => [
|
|
|
104 |
'videoallowed' => in_array('video', $allowedtypes) ? '1' : '0',
|
|
|
105 |
'audioallowed' => in_array('audio', $allowedtypes) ? '1' : '0',
|
|
|
106 |
'screenallowed' => in_array('screen', $allowedtypes) ? '1' : '0',
|
|
|
107 |
...$settings,
|
|
|
108 |
],
|
|
|
109 |
],
|
|
|
110 |
];
|
|
|
111 |
}
|
|
|
112 |
}
|