1441 |
ariadna |
1 |
<?php
|
|
|
2 |
// This file is part of Moodle - https://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 <https://www.gnu.org/licenses/>.
|
|
|
16 |
|
|
|
17 |
namespace core\tests;
|
|
|
18 |
|
|
|
19 |
// phpcs:disable moodle.PHPUnit.TestCaseProvider.dataProviderSyntaxMethodNotFound
|
|
|
20 |
|
|
|
21 |
/**
|
|
|
22 |
* Base class for general testing of plugin features and APIs.
|
|
|
23 |
* The test must not modify database or any global state.
|
|
|
24 |
*
|
|
|
25 |
* Following is required to allow filtering of test by Frankenstyle plugin name:
|
|
|
26 |
* - all providers used in the tests must use components as keys of provider data
|
|
|
27 |
* - all tests must include group "plugin_checks"
|
|
|
28 |
*
|
|
|
29 |
* @package core
|
|
|
30 |
* @copyright 2025 Petr Skoda
|
|
|
31 |
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
32 |
*/
|
|
|
33 |
abstract class plugin_checks_testcase extends \basic_testcase {
|
|
|
34 |
/**
|
|
|
35 |
* Data provider for testing of all available plugins.
|
|
|
36 |
*
|
|
|
37 |
* @return array as array of [component, plugintype, pluginname, dir]
|
|
|
38 |
*/
|
|
|
39 |
public static function all_plugins_provider(): array {
|
|
|
40 |
$result = [];
|
|
|
41 |
foreach (\core_component::get_plugin_types() as $plugintype => $unused) {
|
|
|
42 |
foreach (\core_component::get_plugin_list($plugintype) as $pluginname => $dir) {
|
|
|
43 |
$component = $plugintype . '_' . $pluginname;
|
|
|
44 |
$result[$component] = [$component, $plugintype, $pluginname, $dir];
|
|
|
45 |
}
|
|
|
46 |
}
|
|
|
47 |
return $result;
|
|
|
48 |
}
|
|
|
49 |
|
|
|
50 |
/**
|
|
|
51 |
* Include file and return an array variable defined in its global scope.
|
|
|
52 |
* This is intended primarily for files inside plugin /db/ subdirectory.
|
|
|
53 |
*
|
|
|
54 |
* @param string $phpfile
|
|
|
55 |
* @param string $variablename
|
|
|
56 |
* @return array|null NULL means file does not exist
|
|
|
57 |
*/
|
|
|
58 |
protected function fetch_array_from_file(string $phpfile, string $variablename): ?array {
|
|
|
59 |
if (!file_exists($phpfile)) {
|
|
|
60 |
return null;
|
|
|
61 |
}
|
|
|
62 |
require($phpfile);
|
|
|
63 |
return $$variablename;
|
|
|
64 |
}
|
|
|
65 |
}
|