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 - 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 tiny_premium;
18
 
19
/**
20
 * Manager tests class for tiny_premium.
21
 *
22
 * @package    tiny_premium
23
 * @category   test
24
 * @copyright  2024 David Woloszyn <david.woloszyn@moodle.com>
25
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26
 */
27
final class manager_test extends \advanced_testcase {
28
 
29
    /**
30
     * Test the getting of all available Tiny Premium plugins.
31
     *
32
     * @covers \tiny_premium\manager
33
     */
34
    public function test_get_plugins(): void {
35
        $this->resetAfterTest();
36
        $this->setAdminUser();
37
 
38
        // Check all Tiny Premium plugins are returned.
39
        $premiumplugins = manager::get_plugins();
40
        $this->assertCount(15, $premiumplugins);
41
    }
42
 
43
    /**
44
     * Test the getting and setting of enabled Tiny Premium plugins.
45
     *
46
     * @covers \tiny_premium\manager
47
     */
48
    public function test_get_and_set_enabled_plugins(): void {
49
        $this->resetAfterTest();
50
        $this->setAdminUser();
51
 
52
        // Check all enabled Tiny Premium plugins are returned (all disabled by default).
53
        $enabledpremiumplugins = manager::get_enabled_plugins();
54
        $this->assertCount(0, $enabledpremiumplugins);
55
 
56
        // Enable a couple premium plugins.
57
        manager::set_plugin_config(['enabled' => 1], 'advtable');
58
        manager::set_plugin_config(['enabled' => 1], 'formatpainter');
59
        // Check the premium plugins are enabled.
60
        $enabledpremiumplugins = manager::get_enabled_plugins();
61
        $this->assertCount(2, $enabledpremiumplugins);
62
        $this->assertTrue(manager::is_plugin_enabled('advtable'));
63
        $this->assertTrue(manager::is_plugin_enabled('formatpainter'));
64
 
65
        // Disable a premium plugin.
66
        manager::set_plugin_config(['enabled' => 0], 'advtable');
67
        // Check the correct premium plugins are enabled.
68
        $enabledpremiumplugins = manager::get_enabled_plugins();
69
        $this->assertCount(1, $enabledpremiumplugins);
70
        $this->assertFalse(manager::is_plugin_enabled('advtable'));
71
        $this->assertTrue(manager::is_plugin_enabled('formatpainter'));
72
    }
73
}