See Release Notes
Long Term Support Release
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 repository plugin manager class. 19 * 20 * @package core 21 * @copyright 2021 Amaia Anabitarte <amaia@moodle.com> 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 declare(strict_types = 1); 26 namespace core\plugininfo; 27 28 /** 29 * Tests of the repository plugin manager. 30 */ 31 class repository_test extends \advanced_testcase { 32 33 /** 34 * Test the enable_plugin function to check that it enables and disables repository plugins properly. 35 * 36 * @dataProvider enable_plugin_provider 37 * @param string $pluginname Repository to enable. 38 * @param int|null $initialvisibility Initialvalue for visibility field. 39 * @param int $newstatus New enabled status for the plugin. 40 * @param bool $result Wether the repository is part of enabled plugin list or not. 41 */ 42 public function test_enable_plugin(string $pluginname, ?int $initialvisibility, int $newstatus, bool $result): void { 43 global $DB; 44 45 $this->resetAfterTest(); 46 47 $DB->set_field('repository', 'visible', $initialvisibility, ['type' => $pluginname]); 48 repository::enable_plugin($pluginname, $newstatus); 49 50 $enableplugins = repository::get_enabled_plugins(); 51 $this->assertSame($result, in_array($pluginname, $enableplugins)); 52 } 53 54 /** 55 * Data provider for the load_disk_version tests for testing with invalid supported fields. 56 * 57 * @return array 58 */ 59 public function enable_plugin_provider(): array { 60 return [ 61 'Disable an enable and visible repository' => [ 62 'pluginname' => 'contentbank', 63 'initialvisibility' => repository::REPOSITORY_ON, 64 'newstatus' => repository::REPOSITORY_DISABLED, 65 'result' => false, 66 ], 67 'Disable an enable and hidden repository' => [ 68 'pluginname' => 'contentbank', 69 'initialvisibility' => repository::REPOSITORY_OFF, 70 'newstatus' => repository::REPOSITORY_DISABLED, 71 'result' => false, 72 ], 73 'Disable a disabled repository' => [ 74 'pluginname' => 'coursefiles', 75 'initialvisibility' => null, 76 'newstatus' => repository::REPOSITORY_DISABLED, 77 'result' => false 78 ], 79 'Enable an enable and visible repository' => [ 80 'pluginname' => 'contentbank', 81 'initialvisibility' => repository::REPOSITORY_ON, 82 'newstatus' => repository::REPOSITORY_ON, 83 'result' => true, 84 ], 85 'Enable an enable and hidden repository' => [ 86 'pluginname' => 'contentbank', 87 'initialvisibility' => repository::REPOSITORY_OFF, 88 'newstatus' => repository::REPOSITORY_ON, 89 'result' => true, 90 ], 91 'Enable a disabled repository' => [ 92 'pluginname' => 'coursefiles', 93 'initialvisibility' => null, 94 'newstatus' => repository::REPOSITORY_ON, 95 'result' => true, 96 ], 97 'Enable but hide an enable and visible repository' => [ 98 'pluginname' => 'contentbank', 99 'initialvisibility' => repository::REPOSITORY_ON, 100 'newstatus' => repository::REPOSITORY_OFF, 101 'result' => true, 102 ], 103 'Enable but hide an enable and hidden repository' => [ 104 'pluginname' => 'contentbank', 105 'initialvisibility' => repository::REPOSITORY_OFF, 106 'newstatus' => repository::REPOSITORY_OFF, 107 'result' => true, 108 ], 109 'Enable but hide a disabled repository' => [ 110 'pluginname' => 'coursefiles', 111 'initialvisibility' => null, 112 'newstatus' => repository::REPOSITORY_OFF, 113 'result' => true, 114 ], 115 ]; 116 } 117 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body