mirror of
https://github.com/moodle/moodle.git
synced 2025-01-29 19:50:14 +01:00
Merge branch 'MDL-80124' of https://github.com/paulholden/moodle
This commit is contained in:
commit
9ad941c565
@ -761,8 +761,8 @@ class manager {
|
||||
public function delete_preset(int $presetid): void {
|
||||
global $DB;
|
||||
|
||||
// Check the preset exists.
|
||||
$preset = $DB->get_record('adminpresets', ['id' => $presetid]);
|
||||
// Check the preset exists (cannot delete the pre-installed core "Starter" and "Full" presets).
|
||||
$preset = $DB->get_record('adminpresets', ['id' => $presetid, 'iscore' => self::NONCORE_PRESET]);
|
||||
if (!$preset) {
|
||||
throw new moodle_exception('errordeleting', 'core_adminpresets');
|
||||
}
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
namespace core_adminpresets;
|
||||
|
||||
use moodle_exception;
|
||||
use stdClass;
|
||||
|
||||
/**
|
||||
@ -599,10 +600,28 @@ class manager_test extends \advanced_testcase {
|
||||
|
||||
$manager = new manager();
|
||||
|
||||
$this->expectException(\moodle_exception::class);
|
||||
$this->expectException(moodle_exception::class);
|
||||
$this->expectExceptionMessage('Error deleting from database');
|
||||
$manager->delete_preset($unexistingid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test trying to delete the core/pre-defined presets
|
||||
*
|
||||
* @covers ::delete_preset
|
||||
*/
|
||||
public function test_delete_preset_core(): void {
|
||||
global $DB;
|
||||
|
||||
$this->resetAfterTest();
|
||||
|
||||
$starterpreset = $DB->get_record('adminpresets', ['iscore' => manager::STARTER_PRESET]);
|
||||
|
||||
$this->expectException(moodle_exception::class);
|
||||
$this->expectExceptionMessage('Error deleting from database');
|
||||
(new manager())->delete_preset($starterpreset->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the behaviour of delete_preset() method.
|
||||
*
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
namespace tool_admin_presets\local\action;
|
||||
|
||||
use core_adminpresets\manager;
|
||||
use moodle_exception;
|
||||
|
||||
/**
|
||||
@ -34,8 +35,8 @@ class delete extends base {
|
||||
public function show(): void {
|
||||
global $DB, $OUTPUT;
|
||||
|
||||
// Getting the preset name.
|
||||
$presetdata = $DB->get_record('adminpresets', ['id' => $this->id], 'name');
|
||||
// Check the preset exists (cannot delete the pre-installed core "Starter" and "Full" presets).
|
||||
$presetdata = $DB->get_record('adminpresets', ['id' => $this->id, 'iscore' => manager::NONCORE_PRESET], 'name');
|
||||
|
||||
if ($presetdata) {
|
||||
$deletetext = get_string('deletepreset', 'tool_admin_presets', $presetdata->name);
|
||||
|
Loading…
x
Reference in New Issue
Block a user