first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-09-30 18:11:26 -04:00
commit e592ca6823
27270 changed files with 5002257 additions and 0 deletions
+112
View File
@@ -0,0 +1,112 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
declare(strict_types=1);
namespace core_admin\external;
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot . '/webservice/tests/helpers.php');
/**
* Unit tests to test block protection changes.
*
* @package core
* @covers \core_admin\external\set_block_protection
* @copyright 2023 Andrew Lyons <andrew@nicols.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class set_block_protection_test extends \externallib_advanced_testcase {
/**
* Test execute method with no login.
*/
public function test_execute_no_login(): void {
$this->expectException(\require_login_exception::class);
set_block_protection::execute('block_login', 1);
}
/**
* Test execute method with no login.
*/
public function test_execute_no_capability(): void {
$this->resetAfterTest();
$user = $this->getDataGenerator()->create_user();
$this->setUser($user);
$this->expectException(\required_capability_exception::class);
set_block_protection::execute('block_login', 1);
}
/**
* Test the execute function with a range of parameters.
*
* @dataProvider execute_provider
* @param string $block
* @param int $targetstate
* @param bool $isundeletable
*/
public function test_execute(
string $block,
int $targetstate,
bool $isundeletable,
): void {
$this->resetAfterTest();
$this->setAdminUser();
set_block_protection::execute($block, $targetstate);
$undeletable = \block_manager::get_undeletable_block_types();
[, $pluginname] = explode('_', $block, 2);
if ($isundeletable) {
$this->assertNotFalse(array_search($pluginname, $undeletable));
} else {
$this->assertFalse(array_search($pluginname, $undeletable));
}
$this->assertCount(1, \core\notification::fetch());
}
/**
* Data provider for test_execute.
*
* @return array
*/
public function execute_provider(): array {
return [
[
'block_login',
1,
true,
],
[
'block_login',
0,
false,
],
];
}
/**
* Assert that an exception is thrown when the block does not exist.
*/
public function execute_block_does_not_exist(): void {
$this->expectException(\dml_missing_record_exception::class);
set_block_protection::execute('fake_block', 1);
$this->assertDebuggingCalledCount(1);
}
}
+172
View File
@@ -0,0 +1,172 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
declare(strict_types=1);
namespace core_admin\external;
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot . '/webservice/tests/helpers.php');
/**
* Unit tests to configure the plugin order.
*
* Note: Not all plugins can be ordered, so this test is limited to those which support it.
*
* @package core
* @covers \core_admin\external\set_plugin_state
* @copyright 2023 Andrew Lyons <andrew@nicols.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class set_plugin_order_test extends \externallib_advanced_testcase {
/**
* Text execute method for editor plugins, which support ordering.
*
* @dataProvider execute_editor_provider
* @param string $initialstate The initial state of the plugintype
* @param string $plugin The name of the plugin
* @param int $direction
* @param array $neworder
* @param string $newstate
*/
public function test_execute_editors(
string $initialstate,
string $plugin,
int $direction,
array $neworder,
string $newstate,
): void {
global $CFG;
$this->resetAfterTest();
$this->setAdminUser();
$CFG->texteditors = $initialstate;
set_plugin_order::execute($plugin, $direction);
$this->assertSame(
$neworder,
array_keys(\core\plugininfo\editor::get_sorted_plugins()),
);
$this->assertSame($newstate, $CFG->texteditors);
}
/**
* Data provider for base tests of the execute method.
*
* @return array
*/
public function execute_editor_provider(): array {
$pluginmanager = \core_plugin_manager::instance();
$allplugins = array_keys($pluginmanager->get_plugins_of_type('editor'));
// Disabled editors are listed alphabetically at the end.
$getorder = function (array $plugins) use ($allplugins) {
return array_merge(
$plugins,
array_diff($allplugins, array_values($plugins)),
);
};
return [
[
'initialstate' => 'textarea,tiny',
'pluginname' => 'editor_textarea',
'direction' => 1, // DOWN.
'expected' => $getorder([
'tiny',
'textarea',
]),
'newtexteditors' => 'tiny,textarea',
],
[
'initialstate' => 'textarea,tiny',
'pluginname' => 'editor_textarea',
'direction' => -1, // UP.
'expected' => $getorder([
'textarea',
'tiny',
]),
'newtexteditors' => 'textarea,tiny',
],
[
'initialstate' => 'textarea,tiny',
'pluginname' => 'editor_tiny',
'direction' => 1, // DOWN.
// Tiny is already at the bottom of the list of enabled plugins.
'expected' => $getorder([
'textarea',
'tiny',
]),
'newtexteditors' => 'textarea,tiny',
],
[
'initialstate' => 'textarea,tiny',
'pluginname' => 'editor_atto',
'direction' => 1, // DOWN.
// Atto is not enabled. Disabled editors are listed lexically after enabled editors.
'expected' => $getorder([
'textarea',
'tiny',
]),
'newtexteditors' => 'textarea,tiny',
],
];
}
/**
* Text execute method for plugins which do not support ordering.
*
* @dataProvider execute_non_orderable_provider
* @param string $plugin
*/
public function test_execute_editors_non_orderable(string $plugin): void {
$this->resetAfterTest();
$this->setAdminUser();
$this->assertIsArray(set_plugin_order::execute($plugin, 1));
}
public function execute_non_orderable_provider(): array {
return [
// Activities do not support ordering.
['mod_assign'],
// Nor to blocks.
['block_login'],
];
}
/**
* Test execute method with no login.
*/
public function test_execute_no_login(): void {
$this->expectException(\require_login_exception::class);
set_plugin_order::execute('editor_tiny', 1);
}
/**
* Test execute method with no login.
*/
public function test_execute_no_capability(): void {
$this->resetAfterTest();
$user = $this->getDataGenerator()->create_user();
$this->setUser($user);
$this->expectException(\required_capability_exception::class);
set_plugin_order::execute('editor_tiny', 1);
}
}
+131
View File
@@ -0,0 +1,131 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
declare(strict_types=1);
namespace core_admin\external;
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot . '/webservice/tests/helpers.php');
/**
* Unit tests to configure the enabled/disabled state of a plugin.
*
* @package core
* @covers \core_admin\external\set_plugin_state
* @copyright 2023 Andrew Lyons <andrew@nicols.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class set_plugin_state_test extends \externallib_advanced_testcase {
/**
* Text execute method.
*
* @dataProvider execute_standard_provider
* @param string $plugin The name of the plugin
* @param int|null $initialstate The initial state of the plugin
* @param int $newstate The target state
* @param int $notificationcount The number of notifications expected
*/
public function test_execute(
string $plugin,
?int $initialstate,
int $newstate,
int $notificationcount,
): void {
$this->resetAfterTest();
$this->setAdminUser();
if ($initialstate !== null) {
[$plugintype, $pluginname] = \core_component::normalize_component($plugin);
$manager = \core_plugin_manager::resolve_plugininfo_class($plugintype);
$manager::enable_plugin($pluginname, $initialstate);
\core\notification::fetch();
}
set_plugin_state::execute($plugin, $newstate);
$this->assertCount($notificationcount, \core\notification::fetch());
}
/**
* Data provider for base tests of the execute method.
*
* @return array
*/
public function execute_standard_provider(): array {
$generatetestsfor = function (string $plugin): array {
return [
[
'plugin' => $plugin,
'initialstate' => null,
'newstate' => 0,
'notificationcount' => 1,
],
[
'plugin' => $plugin,
'initialstate' => 1,
'newstate' => 0,
'notificationcount' => 1,
],
[
'plugin' => $plugin,
'initialstate' => 1,
'newstate' => 1,
'notificationcount' => 0,
],
[
'plugin' => $plugin,
'initialstate' => 0,
'newstate' => 0,
'notificationcount' => 0,
],
[
'plugin' => $plugin,
'initialstate' => 0,
'newstate' => 1,
'notificationcount' => 1,
],
];
};
return array_merge(
$generatetestsfor('mod_assign'),
$generatetestsfor('editor_tiny'),
$generatetestsfor('tiny_h5p'),
$generatetestsfor('block_badges'),
);
}
/**
* Test execute method with no login.
*/
public function test_execute_no_login(): void {
$this->expectException(\require_login_exception::class);
set_plugin_state::execute('mod_assign', 1);
}
/**
* Test execute method with no login.
*/
public function test_execute_no_capability(): void {
$this->resetAfterTest();
$user = $this->getDataGenerator()->create_user();
$this->setUser($user);
$this->expectException(\required_capability_exception::class);
set_plugin_state::execute('mod_assign', 1);
}
}