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
+320
View File
@@ -0,0 +1,320 @@
<?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\plugininfo;
use testable_core_plugin_manager;
use testable_plugininfo_base;
/**
* Unit tests for plugin base class.
*
* @package core
* @copyright 2019 Andrew Nicols
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class base_test extends \advanced_testcase {
/**
* Setup to ensure that fixtures are loaded.
*/
public static function setUpBeforeClass(): void {
global $CFG;
require_once($CFG->dirroot.'/lib/tests/fixtures/testable_plugin_manager.php');
require_once($CFG->dirroot.'/lib/tests/fixtures/testable_plugininfo_base.php');
}
/**
* Tear down the testable plugin manager singleton between tests.
*/
public function tearDown(): void {
// The caches of the testable singleton must be reset explicitly. It is
// safer to kill the whole testable singleton at the end of every test.
testable_core_plugin_manager::reset_caches();
}
/**
* Test the load_disk_version function to check that it handles a variety of invalid supported fields.
*
* @dataProvider load_disk_version_invalid_supported_version_provider
* @param array|null $supported Supported versions to inject
* @param string|int|null $incompatible Incompatible version to inject.
* @param int $version Version to test
*/
public function test_load_disk_version_invalid_supported_version($supported, $incompatible, $version): void {
$pluginman = testable_core_plugin_manager::instance();
// Prepare a fake plugininfo instance.
$plugininfo = new testable_plugininfo_base();
$plugininfo->type = 'fake';
$plugininfo->typerootdir = '/dev/null';
$plugininfo->name = 'example';
$plugininfo->rootdir = '/dev/null/fake';
$plugininfo->pluginman = $pluginman;
$plugininfo->versiondisk = 2015060600;
$plugininfo->supported = $supported;
$plugininfo->incompatible = $incompatible;
$pluginman->add_fake_plugin_info($plugininfo);
$this->expectException(\coding_exception::class);
$this->expectExceptionMessage('Incorrect syntax in plugin supported declaration in example');
$plugininfo->load_disk_version();
}
/**
* Data provider for the load_disk_version tests for testing with invalid supported fields.
*
* @return array
*/
public function load_disk_version_invalid_supported_version_provider(): array {
return [
'Invalid supported range.' => [
'supported' => [31, 29],
'incompatible' => null,
'version' => 32,
],
'Explicit list, low' => [
'supported' => [29, 30, 31, 32],
'incompatible' => null,
'version' => 28,
],
'Explicit list, high' => [
'supported' => [29, 30, 31, 32],
'incompatible' => null,
'version' => 33,
],
'Explicit list, in list' => [
'supported' => [29, 30, 31, 32, 33],
'incompatible' => null,
'version' => 31,
],
'Explicit list, missing value, unsupported' => [
'supported' => [29, 30, 32],
'incompatible' => null,
'version' => 31,
],
'Explicit list, missing value, supported' => [
'supported' => [29, 30, 32],
'incompatible' => null,
'version' => 30,
],
];
}
/**
* Test the load_disk_version function to check that it handles a variety of invalid incompatible fields.
*
* @dataProvider load_disk_version_invalid_incompatible_version_provider
* @param mixed $incompatible
*/
public function test_load_disk_version_invalid_incompatible_version($incompatible): void {
$pluginman = testable_core_plugin_manager::instance();
// Prepare a fake plugininfo instance.
$plugininfo = new testable_plugininfo_base();
$plugininfo->type = 'fake';
$plugininfo->typerootdir = '/dev/null';
$plugininfo->name = 'example';
$plugininfo->rootdir = '/dev/null/fake';
$plugininfo->pluginman = $pluginman;
$plugininfo->versiondisk = 2015060600;
$plugininfo->incompatible = $incompatible;
$pluginman->add_fake_plugin_info($plugininfo);
$this->expectException(\coding_exception::class);
$this->expectExceptionMessage('Incorrect syntax in plugin incompatible declaration in example');
$plugininfo->load_disk_version();
}
/**
* Data provider for the load_disk_version tests for testing with invalid incompatible fields.
*
* @return array
*/
public function load_disk_version_invalid_incompatible_version_provider(): array {
return [
[[38]],
[['38']],
[3.8],
['3.8'],
[''],
['somestring'],
];
}
/**
* Test the load_disk_version function to check that it handles a range of correct supported and incompatible field
* definitions.
*
* @dataProvider load_disk_version_branch_supports_provider
* @param array|null $supported Supported versions to inject
* @param string|int|null $incompatible Incompatible version to inject.
* @param int $version Version to test
*/
public function test_load_disk_version_branch_supports($supported, $incompatible, $version): void {
$pluginman = testable_core_plugin_manager::instance();
// Prepare a fake plugininfo instance.
$plugininfo = new testable_plugininfo_base();
$plugininfo->type = 'fake';
$plugininfo->typerootdir = '/dev/null';
$plugininfo->name = 'example';
$plugininfo->rootdir = '/dev/null/fake';
$plugininfo->pluginman = $pluginman;
$plugininfo->versiondisk = 2015060600;
$plugininfo->supported = $supported;
$plugininfo->incompatible = $incompatible;
$pluginman->add_fake_plugin_info($plugininfo);
$plugininfo->load_disk_version();
$this->assertEquals($supported, $plugininfo->supported);
$this->assertEquals($incompatible, $plugininfo->incompatible);
}
/**
* Test cases for tests of load_disk_version for testing the supported/incompatible fields.
*
* @return array
*/
public function load_disk_version_branch_supports_provider(): array {
return [
'Range, branch in support, lowest' => [
'supported' => [29, 31],
'incompatible' => null,
'version' => 29,
],
'Range, branch in support, mid' => [
'supported' => [29, 31],
'incompatible' => null,
'version' => 30,
],
'Range, branch in support, highest' => [
'supported' => [29, 31],
'incompatible' => null,
'version' => 31,
],
'Range, branch not in support, high' => [
'supported' => [29, 31],
'incompatible' => null,
'version' => 32,
],
'Range, branch not in support, low' => [
'supported' => [29, 31],
'incompatible' => null,
'version' => 28,
],
'Range, incompatible, high.' => [
'supported' => [29, 31],
'incompatible' => 32,
'version' => 33,
],
'Range, incompatible, low.' => [
'supported' => [29, 31],
'incompatible' => 32,
'version' => 31,
],
'Range, incompatible, equal.' => [
'supported' => [29, 31],
'incompatible' => 32,
'version' => 32,
],
'No supports' => [
'supported' => null,
'incompatible' => null,
'version' => 32,
],
'No supports, but incompatible, older' => [
'supported' => null,
'incompatible' => 30,
'version' => 32,
],
'No supports, but incompatible, equal' => [
'supported' => null,
'incompatible' => 32,
'version' => 32,
],
'No supports, but incompatible, newer' => [
'supported' => null,
'incompatible' => 34,
'version' => 32,
],
'String incompatible' => [
'supported' => null,
'incompatible' => '34',
'version' => 32,
],
'Empty incompatible' => [
'supported' => null,
'incompatible' => null,
'version' => 32,
],
];
}
/**
* Ensure that plugintype_supports_ordering() returns true.
* @covers ::plugintype_supports_ordering
*/
public function test_plugintype_supports_ordering(): void {
$this->assertFalse(base::plugintype_supports_ordering());
}
/**
* Ensure that the base implementation is used for plugins not supporting ordering.
*
* @dataProvider plugins_not_supporting_ordering
* @param string $plugin
* @coversNothing
*
* Note: This test cannot declare coverage because it covers the various plugin implementations.
*/
public function test_get_sorted_plugins(
string $plugin,
): void {
[$plugintype, $pluginname] = explode('_', $plugin, 2);
$classname = \core_plugin_manager::resolve_plugininfo_class($plugintype);
$this->assertFalse($classname::plugintype_supports_ordering());
$this->assertNull($classname::get_sorted_plugins());
$this->assertNull($classname::get_sorted_plugins(true));
$this->assertNull($classname::get_sorted_plugins(false));
$this->assertFalse($classname::change_plugin_order($pluginname, base::MOVE_UP));
$this->assertFalse($classname::change_plugin_order($pluginname, base::MOVE_DOWN));
}
/**
* Data provider for plugins_not_supporting_ordering.
*
* @return string[]
*/
public function plugins_not_supporting_ordering(): array {
return [
['mod_assign'],
['block_login'],
];
}
}
+86
View File
@@ -0,0 +1,86 @@
<?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\plugininfo;
use advanced_testcase;
/**
* Unit tests for the mod plugininfo class
*
* @package core
* @covers \core\plugininfo\block
* @copyright 2023 Andrew Lyons <andrew@nicols.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class block_test extends advanced_testcase {
/**
* Test the get_enabled_plugins method.
*
* @covers ::get_enabled_plugins
*/
public function test_get_enabled_plugins(): void {
$this->resetAfterTest();
// The bigbluebuttonbn plugin is disabled by default.
// Check all default formats.
$plugins = block::get_enabled_plugins();
$this->assertArrayHasKey('badges', $plugins);
$this->assertArrayHasKey('timeline', $plugins);
$this->assertArrayHasKey('admin_bookmarks', $plugins);
// Disable a plugin.
block::enable_plugin('timeline', 0);
$plugins = block::get_enabled_plugins();
$this->assertArrayHasKey('badges', $plugins);
$this->assertArrayNotHasKey('timeline', $plugins);
$this->assertArrayHasKey('admin_bookmarks', $plugins);
}
/**
* Test the is_uninstall_allowed method.
*
* @dataProvider is_uninstall_allowed_provider
* @param string $plugin
* @param bool $expected
*/
public function test_is_uninstall_allowed(
string $plugin,
bool $expected,
): void {
$pluginmanager = \core_plugin_manager::instance();
$plugininfo = $pluginmanager->get_plugin_info("block_{$plugin}");
$this->assertEquals($expected, $plugininfo->is_uninstall_allowed());
}
public function is_uninstall_allowed_provider(): array {
$plugins = block::get_enabled_plugins();
return array_map(function ($plugin) {
$expected = true;
if ($plugin === 'settings' || $plugin === 'navigation') {
$expected = false;
}
return [
'plugin' => $plugin,
'expected' => $expected,
];
}, array_keys($plugins));
}
}
+94
View File
@@ -0,0 +1,94 @@
<?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\plugininfo;
use advanced_testcase;
/**
* Unit tests for the dataformat plugininfo class
*
* @package core
* @covers \core\plugininfo\dataformat
* @copyright 2022 Paul Holden <paulh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class dataformat_test extends advanced_testcase {
/**
* Helper method, to allow easy filtering of default formats in order to perform assertions without any third-party
* formats affecting expected results
*
* @param string $format
* @return bool
*/
private function filter_default_plugins(string $format): bool {
$defaultformats = ['csv', 'excel', 'html', 'json', 'ods', 'pdf'];
return in_array($format, $defaultformats);
}
/**
* Test getting enabled plugins
*/
public function test_get_enabled_plugins(): void {
$this->resetAfterTest();
// Check all default formats.
$plugins = array_filter(dataformat::get_enabled_plugins(), [$this, 'filter_default_plugins']);
$this->assertEquals([
'csv' => 'csv',
'excel' => 'excel',
'html' => 'html',
'json' => 'json',
'ods' => 'ods',
'pdf' => 'pdf',
], $plugins);
// Disable excel & html.
dataformat::enable_plugin('excel', 0);
dataformat::enable_plugin('html', 0);
$plugins = array_filter(dataformat::get_enabled_plugins(), [$this, 'filter_default_plugins']);
$this->assertEquals([
'csv' => 'csv',
'json' => 'json',
'ods' => 'ods',
'pdf' => 'pdf',
], $plugins);
}
/**
* Test getting enabled plugins obeys configured sortorder
*/
public function test_get_enabled_plugins_sorted(): void {
$this->resetAfterTest();
set_config('dataformat_plugins_sortorder', 'csv,pdf,excel,json,html,ods');
$plugins = array_filter(dataformat::get_enabled_plugins(), [$this, 'filter_default_plugins']);
$this->assertEquals([
'csv' => 'csv',
'pdf' => 'pdf',
'excel' => 'excel',
'json' => 'json',
'html' => 'html',
'ods' => 'ods',
], $plugins);
}
}
+298
View File
@@ -0,0 +1,298 @@
<?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\plugininfo;
use advanced_testcase;
/**
* Unit tests for the editor plugininfo class
*
* @package core
* @covers \core\plugininfo\editor
* @copyright 2023 Andrew Lyons <andrew@nicols.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class editor_test extends advanced_testcase {
/**
* Test that editor::get_enabled_plugins() returns the correct list of enabled plugins.
*/
public function test_get_enabled_plugins(): void {
$this->resetAfterTest();
// All plugins are enabled by default.
$plugins = editor::get_enabled_plugins();
$this->assertArrayHasKey('tiny', $plugins);
$this->assertArrayHasKey('textarea', $plugins);
// Disable tiny.
editor::enable_plugin('textarea', 0);
$plugins = editor::get_enabled_plugins();
$this->assertArrayHasKey('tiny', $plugins);
$this->assertArrayNotHasKey('textarea', $plugins);
}
/**
* Test that editor::enable_plugin set to disable all plugins will leave the textarea enabled.
*/
public function test_enable_plugin_all(): void {
$this->resetAfterTest();
// All plugins are enabled by default.
$plugins = editor::get_enabled_plugins();
foreach ($plugins as $plugin) {
editor::enable_plugin($plugin, 0);
}
$plugins = editor::get_enabled_plugins();
$this->assertCount(1, $plugins);
$this->assertArrayHasKey('textarea', $plugins);
}
/**
* Ensure that plugintype_supports_ordering() returns true.
*/
public function test_plugintype_supports_ordering(): void {
$this->assertTrue(editor::plugintype_supports_ordering());
}
/**
* Ensure that get_sorted_plugins() returns the correct list of plugins.
*
* @dataProvider get_sorted_plugins_provider
* @param string $texteditors The $CFG->texteditors value to use as a base
* @param bool $enabledonly
* @param array $expected The expected order
*/
public function test_get_sorted_plugins(
string $texteditors,
bool $enabledonly,
array $expected,
): void {
global $CFG;
$this->resetAfterTest(true);
$CFG->texteditors = $texteditors;
$this->assertSame(
$expected,
array_keys(editor::get_sorted_plugins($enabledonly)),
);
}
/**
* Data provider for the get_sorted_plugins tests.
*
* @return array
*/
public function get_sorted_plugins_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 [
[
'texteditors' => 'textarea,tiny',
'enabledonly' => true,
'expected' => [
'textarea',
'tiny',
],
],
[
'texteditors' => 'tiny,textarea',
'enabledonly' => true,
'expected' => [
'tiny',
'textarea',
],
],
[
'texteditors' => 'tiny',
'enabledonly' => true,
'expected' => [
'tiny',
],
],
'Phantom values are removed from the list' => [
'texteditors' => 'fakeeditor',
'enabledonly' => true,
'expected' => [
],
],
[
'texteditors' => 'textarea,tiny',
'enabledonly' => false,
'expected' => $getorder([
'textarea',
'tiny',
]),
],
[
'texteditors' => 'tiny',
'enabledonly' => false,
'expected' => $getorder([
'tiny',
]),
],
];
}
/**
* Ensure that change_plugin_order() changes the order of the plugins.
*
* @dataProvider change_plugin_order_provider
* @param string $texteditors
* @param string $pluginname
* @param int $direction
* @param array $neworder
* @param string $newtexteditors
*/
public function test_change_plugin_order(
string $texteditors,
string $pluginname,
int $direction,
array $neworder,
string $newtexteditors,
): void {
global $CFG;
$this->resetAfterTest(true);
$CFG->texteditors = $texteditors;
editor::change_plugin_order($pluginname, $direction);
$this->assertSame(
$neworder,
array_keys(editor::get_sorted_plugins()),
);
$this->assertSame($newtexteditors, $CFG->texteditors);
}
/**
* Data provider fro the change_plugin_order() tests.
*
* @return array
*/
public function change_plugin_order_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 [
[
'texteditors' => 'textarea,tiny',
'pluginname' => 'textarea',
'direction' => base::MOVE_DOWN,
'expected' => $getorder([
'tiny',
'textarea',
]),
'newtexteditors' => 'tiny,textarea',
],
[
'texteditors' => 'textarea,tiny',
'pluginname' => 'tiny',
'direction' => base::MOVE_DOWN,
// Tiny is already at the bottom of the enabled plugins.
'expected' => $getorder([
'textarea',
'tiny',
]),
'newtexteditors' => 'textarea,tiny',
],
[
'texteditors' => 'textarea,tiny',
'pluginname' => 'atto',
'direction' => base::MOVE_DOWN,
// Atto is not enabled. No change expected.
'expected' => $getorder([
'textarea',
'tiny',
]),
'newtexteditors' => 'textarea,tiny',
],
[
'texteditors' => 'textarea,tiny',
'pluginname' => 'tiny',
'direction' => base::MOVE_UP,
'expected' => $getorder([
'tiny',
'textarea',
]),
'newtexteditors' => 'tiny,textarea',
],
[
'texteditors' => 'textarea,tiny',
'pluginname' => 'tiny',
'direction' => base::MOVE_UP,
// Tiny is already at the top of the enabled plugins.
'expected' => $getorder([
'tiny',
'textarea',
]),
'newtexteditors' => 'tiny,textarea',
],
[
'texteditors' => 'textarea,tiny',
'pluginname' => 'atto',
'direction' => base::MOVE_UP,
// Atto is not enabled. No change expected.
'expected' => $getorder([
'textarea',
'tiny',
]),
'newtexteditors' => 'textarea,tiny',
],
[
'texteditors' => 'textarea,tiny',
'pluginname' => 'atto',
'direction' => base::MOVE_UP,
// Atto is not enabled. No change expected.
'expected' => $getorder([
'textarea',
'tiny',
]),
'newtexteditors' => 'textarea,tiny',
],
[
'texteditors' => 'textarea,tiny',
'pluginname' => 'fakeeditor',
'direction' => base::MOVE_UP,
// The fakeeditor plugin does not exist. No change expected.
'expected' => $getorder([
'textarea',
'tiny',
]),
'newtexteditors' => 'textarea,tiny',
],
];
}
}
+199
View File
@@ -0,0 +1,199 @@
<?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\plugininfo;
use advanced_testcase;
/**
* Unit tests for the media plugininfo class.
*
* @package core
* @covers \core\plugininfo\media
* @copyright 2023 Andrew Lyons <andrew@nicols.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class media_test extends advanced_testcase {
/**
* Test the get_enabled_plugins method.
*
* @covers ::get_enabled_plugins
*/
public function test_get_enabled_plugins(): void {
$this->resetAfterTest();
$plugins = media::get_enabled_plugins();
$this->assertArrayHasKey('videojs', $plugins);
$this->assertArrayHasKey('youtube', $plugins);
// Disable a plugin.
media::enable_plugin('youtube', 0);
$plugins = media::get_enabled_plugins();
$this->assertArrayNotHasKey('youtube', $plugins);
$this->assertArrayHasKey('videojs', $plugins);
}
/**
* Test the is_uninstall_allowed method.
*
* @dataProvider is_uninstall_allowed_provider
* @param string $plugin
*/
public function test_is_uninstall_allowed(
string $plugin,
): void {
$pluginmanager = \core_plugin_manager::instance();
$plugininfo = $pluginmanager->get_plugin_info("media_{$plugin}");
$this->assertTrue($plugininfo->is_uninstall_allowed());
}
/**
* Data provider for the is_uninstall_allowed tests.
*
* @return array
*/
public function is_uninstall_allowed_provider(): array {
$plugins = media::get_enabled_plugins();
return array_map(function ($plugin) {
return [
'plugin' => $plugin,
];
}, array_keys($plugins));
}
/**
* Ensure that change_plugin_order() changes the order of the plugins.
*
* @dataProvider change_plugin_order_provider
* @param string $initialorder
* @param string $pluginname
* @param int $direction
* @param array $neworder
*/
public function test_change_plugin_order(
array $initialorder,
string $pluginname,
int $direction,
array $neworder,
): void {
$this->resetAfterTest(true);
media::set_enabled_plugins($initialorder);
media::change_plugin_order($pluginname, $direction);
$this->assertSame(
$neworder,
array_keys(media::get_sorted_plugins()),
);
}
public function change_plugin_order_provider(): array {
$pluginmanager = \core_plugin_manager::instance();
$allplugins = $pluginmanager->get_plugins_of_type('media');
\core_collator::asort_objects_by_method($allplugins, 'get_rank', \core_collator::SORT_NUMERIC);
$getorder = function (array $plugins) use ($allplugins) {
return array_merge(
$plugins,
array_diff(array_reverse(array_keys($allplugins)), array_values($plugins)),
);
};
return [
'Top item down one' => [
'initialorder' => [
'videojs',
'html5audio',
'html5video',
'youtube',
],
'pluginname' => 'videojs',
'direction' => base::MOVE_DOWN,
'expected' => $getorder([
'html5audio',
'videojs',
'html5video',
'youtube',
]),
],
'Bottom item down one' => [
'initialorder' => [
'videojs',
'html5audio',
'html5video',
'youtube',
],
'pluginname' => 'youtube',
'direction' => base::MOVE_DOWN,
'expected' => $getorder([
'videojs',
'html5audio',
'html5video',
'youtube',
]),
],
'Top item up' => [
'initialorder' => [
'videojs',
'html5audio',
'html5video',
'youtube',
],
'pluginname' => 'videojs',
'direction' => base::MOVE_UP,
'expected' => $getorder([
'videojs',
'html5audio',
'html5video',
'youtube',
]),
],
'Disabled plugin' => [
'initialorder' => [
'videojs',
'html5audio',
'html5video',
],
'pluginname' => 'youtube',
'direction' => base::MOVE_UP,
'expected' => $getorder([
'videojs',
'html5audio',
'html5video',
]),
],
'Non-existent plugin' => [
'initialorder' => [
'videojs',
'html5audio',
'html5video',
'youtube',
],
'pluginname' => 'moodletube',
'direction' => base::MOVE_UP,
'expected' => $getorder([
'videojs',
'html5audio',
'html5video',
'youtube',
]),
],
];
}
}
+52
View File
@@ -0,0 +1,52 @@
<?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\plugininfo;
use advanced_testcase;
/**
* Unit tests for the mod plugininfo class
*
* @package core
* @covers \core\plugininfo\mod
* @copyright 2023 Andrew Lyons <andrew@nicols.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_test extends advanced_testcase {
public function test_get_enabled_plugins(): void {
$this->resetAfterTest();
// The bigbluebuttonbn and chat plugins are disabled by default.
// Check all default formats.
$plugins = mod::get_enabled_plugins();
$this->assertArrayHasKey('assign', $plugins);
$this->assertArrayHasKey('forum', $plugins);
$this->assertArrayNotHasKey('chat', $plugins);
$this->assertArrayNotHasKey('bigbluebuttonbn', $plugins);
// Disable assignment.
mod::enable_plugin('assign', 0);
$plugins = mod::get_enabled_plugins();
$this->assertArrayHasKey('forum', $plugins);
$this->assertArrayNotHasKey('assign', $plugins);
$this->assertArrayNotHasKey('chat', $plugins);
$this->assertArrayNotHasKey('bigbluebuttonbn', $plugins);
}
}
+117
View File
@@ -0,0 +1,117 @@
<?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/>.
/**
* Unit tests for repository plugin manager class.
*
* @package core
* @copyright 2021 Amaia Anabitarte <amaia@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
declare(strict_types = 1);
namespace core\plugininfo;
/**
* Tests of the repository plugin manager.
*/
class repository_test extends \advanced_testcase {
/**
* Test the enable_plugin function to check that it enables and disables repository plugins properly.
*
* @dataProvider enable_plugin_provider
* @param string $pluginname Repository to enable.
* @param int|null $initialvisibility Initialvalue for visibility field.
* @param int $newstatus New enabled status for the plugin.
* @param bool $result Wether the repository is part of enabled plugin list or not.
*/
public function test_enable_plugin(string $pluginname, ?int $initialvisibility, int $newstatus, bool $result): void {
global $DB;
$this->resetAfterTest();
$DB->set_field('repository', 'visible', $initialvisibility, ['type' => $pluginname]);
repository::enable_plugin($pluginname, $newstatus);
$enableplugins = repository::get_enabled_plugins();
$this->assertSame($result, in_array($pluginname, $enableplugins));
}
/**
* Data provider for the load_disk_version tests for testing with invalid supported fields.
*
* @return array
*/
public function enable_plugin_provider(): array {
return [
'Disable an enable and visible repository' => [
'pluginname' => 'contentbank',
'initialvisibility' => repository::REPOSITORY_ON,
'newstatus' => repository::REPOSITORY_DISABLED,
'result' => false,
],
'Disable an enable and hidden repository' => [
'pluginname' => 'contentbank',
'initialvisibility' => repository::REPOSITORY_OFF,
'newstatus' => repository::REPOSITORY_DISABLED,
'result' => false,
],
'Disable a disabled repository' => [
'pluginname' => 'coursefiles',
'initialvisibility' => null,
'newstatus' => repository::REPOSITORY_DISABLED,
'result' => false
],
'Enable an enable and visible repository' => [
'pluginname' => 'contentbank',
'initialvisibility' => repository::REPOSITORY_ON,
'newstatus' => repository::REPOSITORY_ON,
'result' => true,
],
'Enable an enable and hidden repository' => [
'pluginname' => 'contentbank',
'initialvisibility' => repository::REPOSITORY_OFF,
'newstatus' => repository::REPOSITORY_ON,
'result' => true,
],
'Enable a disabled repository' => [
'pluginname' => 'coursefiles',
'initialvisibility' => null,
'newstatus' => repository::REPOSITORY_ON,
'result' => true,
],
'Enable but hide an enable and visible repository' => [
'pluginname' => 'contentbank',
'initialvisibility' => repository::REPOSITORY_ON,
'newstatus' => repository::REPOSITORY_OFF,
'result' => true,
],
'Enable but hide an enable and hidden repository' => [
'pluginname' => 'contentbank',
'initialvisibility' => repository::REPOSITORY_OFF,
'newstatus' => repository::REPOSITORY_OFF,
'result' => true,
],
'Enable but hide a disabled repository' => [
'pluginname' => 'coursefiles',
'initialvisibility' => null,
'newstatus' => repository::REPOSITORY_OFF,
'result' => true,
],
];
}
}