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_equation;
|
|
|
20 |
|
|
|
21 |
use advanced_testcase;
|
|
|
22 |
|
|
|
23 |
/**
|
|
|
24 |
* Unit tests for the \tiny_equation\plugininfo class.
|
|
|
25 |
*
|
|
|
26 |
* @package tiny_equation
|
|
|
27 |
* @covers \tiny_equation\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 bool $enabled True if the filter must be enabled.
|
|
|
46 |
* @param array $expectedconfiguration Expected configuration.
|
|
|
47 |
* @return void
|
|
|
48 |
*/
|
|
|
49 |
public function test_get_plugin_configuration_for_external(bool $enabled, array $expectedconfiguration): void {
|
|
|
50 |
global $CFG;
|
|
|
51 |
|
|
|
52 |
$filtermanager = \core_plugin_manager::resolve_plugininfo_class('filter');
|
|
|
53 |
$filtermanager::enable_plugin('mathjaxloader', $enabled ? TEXTFILTER_ON : TEXTFILTER_OFF);
|
|
|
54 |
|
|
|
55 |
$generator = $this->getDataGenerator();
|
|
|
56 |
$user = $generator->create_user();
|
|
|
57 |
$context = \context_system::instance();
|
|
|
58 |
$this->setUser($user);
|
|
|
59 |
|
|
|
60 |
$this->assertEquals($expectedconfiguration, plugininfo::get_plugin_configuration_for_external($context));
|
|
|
61 |
}
|
|
|
62 |
|
|
|
63 |
/**
|
|
|
64 |
* Data provider for test_get_plugin_configuration_for_external.
|
|
|
65 |
*
|
|
|
66 |
* @return array
|
|
|
67 |
*/
|
|
|
68 |
public static function get_plugin_configuration_for_external_provider(): array {
|
|
|
69 |
$settings = [
|
|
|
70 |
'libraries' => json_encode([
|
|
|
71 |
[
|
|
|
72 |
'key' => 'group1',
|
|
|
73 |
'groupname' => get_string('librarygroup1', 'tiny_equation'),
|
|
|
74 |
'elements' => explode("\n", trim(get_config('tiny_equation', 'librarygroup1'))),
|
|
|
75 |
'active' => true,
|
|
|
76 |
],
|
|
|
77 |
[
|
|
|
78 |
'key' => 'group2',
|
|
|
79 |
'groupname' => get_string('librarygroup2', 'tiny_equation'),
|
|
|
80 |
'elements' => explode("\n", trim(get_config('tiny_equation', 'librarygroup2'))),
|
|
|
81 |
],
|
|
|
82 |
[
|
|
|
83 |
'key' => 'group3',
|
|
|
84 |
'groupname' => get_string('librarygroup3', 'tiny_equation'),
|
|
|
85 |
'elements' => explode("\n", trim(get_config('tiny_equation', 'librarygroup3'))),
|
|
|
86 |
],
|
|
|
87 |
[
|
|
|
88 |
'key' => 'group4',
|
|
|
89 |
'groupname' => get_string('librarygroup4', 'tiny_equation'),
|
|
|
90 |
'elements' => explode("\n", trim(get_config('tiny_equation', 'librarygroup4'))),
|
|
|
91 |
],
|
|
|
92 |
]),
|
|
|
93 |
'texdocsurl' => get_docs_url('Using_TeX_Notation'),
|
|
|
94 |
];
|
|
|
95 |
|
|
|
96 |
return [
|
|
|
97 |
[
|
|
|
98 |
'enabled' => true,
|
|
|
99 |
'expectedconfiguration' => ['texfilter' => '1', ...$settings],
|
|
|
100 |
],
|
|
|
101 |
[
|
|
|
102 |
'enabled' => false,
|
|
|
103 |
'expectedconfiguration' => ['texfilter' => '0', ...$settings],
|
|
|
104 |
],
|
|
|
105 |
];
|
|
|
106 |
}
|
|
|
107 |
}
|