mirror of
https://github.com/moodle/moodle.git
synced 2025-06-01 05:35:55 +02: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 {
|
public function delete_preset(int $presetid): void {
|
||||||
global $DB;
|
global $DB;
|
||||||
|
|
||||||
// Check the preset exists.
|
// Check the preset exists (cannot delete the pre-installed core "Starter" and "Full" presets).
|
||||||
$preset = $DB->get_record('adminpresets', ['id' => $presetid]);
|
$preset = $DB->get_record('adminpresets', ['id' => $presetid, 'iscore' => self::NONCORE_PRESET]);
|
||||||
if (!$preset) {
|
if (!$preset) {
|
||||||
throw new moodle_exception('errordeleting', 'core_adminpresets');
|
throw new moodle_exception('errordeleting', 'core_adminpresets');
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
namespace core_adminpresets;
|
namespace core_adminpresets;
|
||||||
|
|
||||||
|
use moodle_exception;
|
||||||
use stdClass;
|
use stdClass;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -599,10 +600,28 @@ class manager_test extends \advanced_testcase {
|
|||||||
|
|
||||||
$manager = new manager();
|
$manager = new manager();
|
||||||
|
|
||||||
$this->expectException(\moodle_exception::class);
|
$this->expectException(moodle_exception::class);
|
||||||
|
$this->expectExceptionMessage('Error deleting from database');
|
||||||
$manager->delete_preset($unexistingid);
|
$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.
|
* Test the behaviour of delete_preset() method.
|
||||||
*
|
*
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
namespace tool_admin_presets\local\action;
|
namespace tool_admin_presets\local\action;
|
||||||
|
|
||||||
|
use core_adminpresets\manager;
|
||||||
use moodle_exception;
|
use moodle_exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -34,8 +35,8 @@ class delete extends base {
|
|||||||
public function show(): void {
|
public function show(): void {
|
||||||
global $DB, $OUTPUT;
|
global $DB, $OUTPUT;
|
||||||
|
|
||||||
// Getting the preset name.
|
// Check the preset exists (cannot delete the pre-installed core "Starter" and "Full" presets).
|
||||||
$presetdata = $DB->get_record('adminpresets', ['id' => $this->id], 'name');
|
$presetdata = $DB->get_record('adminpresets', ['id' => $this->id, 'iscore' => manager::NONCORE_PRESET], 'name');
|
||||||
|
|
||||||
if ($presetdata) {
|
if ($presetdata) {
|
||||||
$deletetext = get_string('deletepreset', 'tool_admin_presets', $presetdata->name);
|
$deletetext = get_string('deletepreset', 'tool_admin_presets', $presetdata->name);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user