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_media;
20
 
21
use advanced_testcase;
22
 
23
/**
24
 * Unit tests for the \tiny_media\plugininfo class.
25
 *
26
 * @package     tiny_media
27
 * @covers      \tiny_media\plugininfo::is_enabled_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 is_enabled_for_external method.
43
     *
44
     * @dataProvider is_enabled_for_external_provider
45
     * @param bool $guest True to use guest user.
46
     * @param bool $expectedenabled Expected result.
47
     * @return void
48
     */
49
    public function test_is_enabled_for_external(bool $guest, bool $expectedenabled): void {
50
        global $CFG;
51
 
52
        $generator = $this->getDataGenerator();
53
        if ($guest) {
54
            $this->setGuestUser();
55
        } else {
56
            $user = $generator->create_user();
57
            $this->setUser($user);
58
        }
59
        $context = \context_system::instance();
60
 
61
        $this->assertEquals($expectedenabled, plugininfo::is_enabled_for_external($context, ['pluginname' => 'media']));
62
    }
63
 
64
    /**
65
     * Data provider for test_is_enabled_for_external.
66
     *
67
     * @return array
68
     */
69
    public static function is_enabled_for_external_provider(): array {
70
        return [
71
            ['guest' => false, 'expectedenabled' => true],
72
            ['guest' => true, 'expectedenabled' => false],
73
        ];
74
    }
75
}