Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
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_h5p;
20
 
21
use advanced_testcase;
22
 
23
/**
24
 * Unit tests for the \tiny_h5p\plugininfo class.
25
 *
26
 * @package     tiny_h5p
27
 * @covers      \tiny_h5p\plugininfo::get_plugin_configuration_for_external
28
 * @copyright   2025 Moodle Pty Ltd
29
 * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
30
 */
31
final class plugininfo_test extends advanced_testcase {
32
 
33
    /**
34
     * Basic setup for tests.
35
     */
36
    public function setUp(): void {
37
        parent::setUp();
38
        $this->resetAfterTest(true);
39
    }
40
 
41
    /**
42
     * Test the get_plugin_configuration_for_external method.
43
     *
44
     * @dataProvider get_plugin_configuration_for_external_provider
45
     * @param ?string $role Role name to assign to the user. If null, no role is assigned.
46
     * @param array $expectedconfiguration Expected configuration.
47
     * @return void
48
     */
49
    public function test_get_plugin_configuration_for_external(?string $role, array $expectedconfiguration): void {
50
        global $CFG;
51
 
52
        $generator = $this->getDataGenerator();
53
        $user = $generator->create_user();
54
        $course = $generator->create_course();
55
        $context = \context_course::instance($course->id);
56
        if ($role) {
57
            $generator->enrol_user($user->id, $course->id, $role);
58
        }
59
        $this->setUser($user);
60
 
61
        $this->assertEquals($expectedconfiguration, plugininfo::get_plugin_configuration_for_external($context));
62
    }
63
 
64
    /**
65
     * Data provider for test_get_plugin_configuration_for_external.
66
     *
67
     * @return array
68
     */
69
    public static function get_plugin_configuration_for_external_provider(): array {
70
        return [
71
            [
72
                'role' => null,
73
                'expectedconfiguration' => ['embedallowed' => '0', 'uploadallowed' => '0'],
74
            ],
75
            [
76
                'role' => 'guest',
77
                'expectedconfiguration' => ['embedallowed' => '0', 'uploadallowed' => '0'],
78
            ],
79
            [
80
                'role' => 'student',
81
                'expectedconfiguration' => ['embedallowed' => '0', 'uploadallowed' => '0'],
82
            ],
83
            [
84
                'role' => 'teacher',
85
                'expectedconfiguration' => ['embedallowed' => '0', 'uploadallowed' => '0'],
86
            ],
87
            [
88
                'role' => 'editingteacher',
89
                'expectedconfiguration' => ['embedallowed' => '1', 'uploadallowed' => '1'],
90
            ],
91
        ];
92
    }
93
}