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 |
/**
|
|
|
18 |
* Unit tests for general unilabel features.
|
|
|
19 |
*
|
|
|
20 |
* @package mod_unilabel
|
|
|
21 |
* @category test
|
|
|
22 |
* @author Andreas Grabs <info@grabs-edv.de>
|
|
|
23 |
* @copyright 2018 onwards Grabs EDV {@link https://www.grabs-edv.de}
|
|
|
24 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
25 |
*/
|
|
|
26 |
|
|
|
27 |
namespace mod_unilabel;
|
|
|
28 |
|
|
|
29 |
/**
|
|
|
30 |
* Unit tests for general unilabel features.
|
|
|
31 |
*
|
|
|
32 |
* @package mod_unilabel
|
|
|
33 |
* @category test
|
|
|
34 |
* @author Andreas Grabs <info@grabs-edv.de>
|
|
|
35 |
* @copyright 2018 onwards Grabs EDV {@link https://www.grabs-edv.de}
|
|
|
36 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
37 |
*/
|
|
|
38 |
final class lib_test extends \advanced_testcase {
|
|
|
39 |
/**
|
|
|
40 |
* Test create an instance.
|
|
|
41 |
*
|
|
|
42 |
* @covers \mod_unilabel\factory
|
|
|
43 |
* @return void
|
|
|
44 |
*/
|
|
|
45 |
public function test_get_only_active_unilabeltypes(): void {
|
|
|
46 |
global $DB;
|
|
|
47 |
$this->resetAfterTest();
|
|
|
48 |
$this->setAdminUser();
|
|
|
49 |
|
|
|
50 |
// Prepare the settings and activate all unilabeltypes.
|
|
|
51 |
// The unilabeltype "simpletext" is an exception. This type always is active.
|
|
|
52 |
$plugins = \core_component::get_plugin_list('unilabeltype');
|
|
|
53 |
$countallplugins = count($plugins);
|
|
|
54 |
foreach ($plugins as $name => $notused) {
|
|
|
55 |
if ($name == 'simpletext') {
|
|
|
56 |
continue;
|
|
|
57 |
}
|
|
|
58 |
set_config('active', true, 'unilabeltype_' . $name);
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
$unilabeltypes = \mod_unilabel\factory::get_plugin_list();
|
|
|
62 |
$countactiveplugins = count($unilabeltypes);
|
|
|
63 |
|
|
|
64 |
// Do we have found plugins at all?
|
|
|
65 |
$this->assertTrue(count($unilabeltypes) > 0, 'no unilabeltypes found');
|
|
|
66 |
// Do we have found all plugins?
|
|
|
67 |
$this->assertTrue($countactiveplugins == $countallplugins);
|
|
|
68 |
|
|
|
69 |
if (empty($unilabeltypes)) {
|
|
|
70 |
return;
|
|
|
71 |
}
|
|
|
72 |
|
|
|
73 |
foreach ($unilabeltypes as $unilabeltype => $typestring) {
|
|
|
74 |
$typeinstance = \mod_unilabel\factory::get_plugin($unilabeltype);
|
|
|
75 |
$this->assertNotEmpty($typeinstance);
|
|
|
76 |
if (empty($typeinstance)) {
|
|
|
77 |
continue;
|
|
|
78 |
}
|
|
|
79 |
$this->assertTrue($typestring == $typeinstance->get_name());
|
|
|
80 |
$this->assertTrue($typeinstance->is_active());
|
|
|
81 |
}
|
|
|
82 |
|
|
|
83 |
// Now we set all plugins inactive.
|
|
|
84 |
foreach ($plugins as $name => $notused) {
|
|
|
85 |
if ($name == 'simpletext') {
|
|
|
86 |
continue;
|
|
|
87 |
}
|
|
|
88 |
set_config('active', false, 'unilabeltype_' . $name);
|
|
|
89 |
}
|
|
|
90 |
|
|
|
91 |
$unilabeltypes = \mod_unilabel\factory::get_plugin_list();
|
|
|
92 |
$countactiveplugins = count($unilabeltypes);
|
|
|
93 |
$this->assertEquals(1, $countactiveplugins);
|
|
|
94 |
}
|
|
|
95 |
}
|